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
|
|---|---|---|---|---|---|---|---|---|
amitsela/incubator-beam
|
sdks/python/apache_beam/examples/cookbook/coders.py
|
9
|
3380
|
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""A workflow using custom JSON-based coders for text sources and sinks.
The input file contains a JSON string on each line describing a match
record using the following schema:
{'guest': [TEAM_NAME, GOALS], 'host': [TEAM_NAME, GOALS]}
The output file will contain the computed points for each team with one team
per line in the following format:
[TEAM_NAME, POINTS]
"""
from __future__ import absolute_import
import argparse
import json
import logging
import apache_beam as beam
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
from apache_beam.utils.pipeline_options import PipelineOptions
from apache_beam.utils.pipeline_options import SetupOptions
class JsonCoder(object):
"""A JSON coder interpreting each line as a JSON string."""
def encode(self, x):
return json.dumps(x)
def decode(self, x):
return json.loads(x)
def compute_points(record):
"""Compute points based on the record containing the match result.
The function assigns 3 points for a win, 1 point for a draw, and 0 points for
a loss (see http://en.wikipedia.org/wiki/Three_points_for_a_win).
"""
host_name, host_goals = record['host']
guest_name, guest_goals = record['guest']
if host_goals == guest_goals:
yield host_name, 1
yield guest_name, 1
elif host_goals > guest_goals:
yield host_name, 3
yield guest_name, 0
else:
yield host_name, 0
yield guest_name, 3
def run(argv=None):
"""Runs the workflow computing total points from a collection of matches."""
parser = argparse.ArgumentParser()
parser.add_argument('--input',
required=True,
help='Input file to process.')
parser.add_argument('--output',
required=True,
help='Output file to write results to.')
known_args, pipeline_args = parser.parse_known_args(argv)
# We use the save_main_session option because one or more DoFn's in this
# workflow rely on global context (e.g., a module imported at module level).
pipeline_options = PipelineOptions(pipeline_args)
pipeline_options.view_as(SetupOptions).save_main_session = True
p = beam.Pipeline(options=pipeline_options)
p = beam.Pipeline(argv=pipeline_args)
(p # pylint: disable=expression-not-assigned
| 'read' >> ReadFromText(known_args.input, coder=JsonCoder())
| 'points' >> beam.FlatMap(compute_points)
| beam.CombinePerKey(sum)
| 'write' >> WriteToText(known_args.output, coder=JsonCoder()))
p.run()
if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
run()
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
33,
10431,
1808,
3537,
4840,
13,
6788,
1233,
2393,
367,
1318,
5274,
436,
19241,
83,
14,
199,
199,
1918,
1324,
570,
3509,
282,
4840,
1059,
641,
1924,
1004,
13660,
282,
1336,
199,
3059,
1808,
314,
2569,
4177,
26,
819,
791,
10409,
356,
359,
3727,
1156,
63,
2339,
12,
598,
47,
748,
51,
467,
283,
1102,
356,
359,
3727,
1156,
63,
2339,
12,
598,
47,
748,
51,
9420,
199,
199,
1918,
1072,
570,
911,
1395,
314,
9235,
4501,
367,
1924,
8099,
543,
1373,
8099,
199,
529,
1004,
315,
314,
2569,
1475,
26,
819,
359,
3727,
1156,
63,
2339,
12,
3625,
2919,
51,
61,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
7534,
199,
646,
2022,
199,
646,
2050,
199,
199,
646,
17098,
63,
14529,
465,
17453,
199,
504,
17098,
63,
14529,
14,
2308,
492,
5574,
2532,
1872,
199,
504,
17098,
63,
14529,
14,
2308,
492,
6990,
1378,
1872,
199,
504,
17098,
63,
14529,
14,
1208,
14,
7379,
63,
1419,
492,
19090,
4558,
199,
504,
17098,
63,
14529,
14,
1208,
14,
7379,
63,
1419,
492,
12439,
4558,
421,
199,
533,
14587,
3034,
82,
8,
785,
304,
523,
408,
33,
4840,
1233,
82,
6421,
1337,
1924,
1004,
465,
282,
4840,
1059,
1041,
819,
347,
3752,
8,
277,
12,
671,
304,
272,
372,
2022,
14,
4180,
8,
88,
9,
819,
347,
4849,
8,
277,
12,
671,
304,
272,
372,
2022,
14,
3640,
8,
88,
9,
421,
199,
318,
4526,
63,
3438,
8,
3059,
304,
523,
408,
8564,
4501,
4079,
641,
314,
2777,
3035,
314,
1336,
754,
14,
819,
710,
805,
465,
20440,
650,
4501,
367,
282,
4747,
12,
413,
2376,
367,
282,
5954,
12,
436,
378,
4501,
367,
523,
282,
5621,
334,
3239,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
21485,
63,
3438,
63,
509,
63,
65,
63,
2676,
680,
523,
408,
523,
1591,
63,
354,
12,
1591,
63,
30970,
275,
2777,
459,
1102,
418,
523,
13980,
63,
354,
12,
13980,
63,
30970,
275,
2777,
459,
10409,
418,
523,
340,
1591,
63,
30970,
508,
13980,
63,
30970,
26,
272,
1995,
1591,
63,
354,
12,
413,
272,
1995,
13980,
63,
354,
12,
413,
523,
916,
1591,
63,
30970,
690,
13980,
63,
30970,
26,
272,
1995,
1591,
63,
354,
12,
650,
272,
1995,
13980,
63,
354,
12,
378,
523,
587,
26,
272,
1995,
1591,
63,
354,
12,
378,
272,
1995,
13980,
63,
354,
12,
650,
421,
199,
318,
1255,
8,
3020,
29,
403,
304,
523,
408,
16291,
314,
10431,
17226,
3141,
4501,
687,
282,
3245,
402,
4450,
1041,
819,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
4517,
1210,
297,
1993,
1415,
29,
549,
12,
1993,
1720,
534,
3205,
570,
370,
2112,
2659,
523,
1798,
14,
525,
63,
2094,
4517,
1199,
297,
1993,
1415,
29,
549,
12,
1993,
1720,
534,
2959,
570,
370,
2218,
2058,
370,
2659,
523,
6040,
63,
589,
12,
7679,
63,
589,
275,
1798,
14,
1122,
63,
3159,
63,
589,
8,
3020,
9,
523,
327,
2136,
675,
314,
3354,
63,
973,
63,
1730,
945,
2952,
1373,
503,
1655,
4226,
9656,
1159,
315,
642,
523,
327,
10431,
19687,
641,
2288,
1067,
334,
69,
14,
71,
2020,
282,
859,
8439,
737,
859,
2166,
680,
523,
7679,
63,
1419,
275,
19090,
4558,
8,
7379,
63,
589,
9,
523,
7679,
63,
1419,
14,
1345,
63,
305,
8,
8555,
4558,
680,
2117,
63,
973,
63,
1730,
275,
715,
523,
299,
275,
17453,
14,
17562,
8,
1419,
29,
7379,
63,
1419,
9,
819,
299,
275,
17453,
14,
17562,
8,
3020,
29,
7379,
63,
589,
9,
523,
334,
80,
221,
327,
4287,
26,
3507,
29,
5599,
13,
1397,
13,
12941,
2043,
1204,
283,
739,
7,
4331,
5574,
2532,
1872,
8,
3159,
63,
589,
14,
1210,
12,
1233,
82,
29,
9653,
3034,
82,
1012,
2043,
1204,
283,
3438,
7,
4331,
17453,
14,
17271,
2956,
8,
3357,
63,
3438,
9,
2043,
1204,
17453,
14,
23163,
2623,
1197,
8,
1838,
9,
2043,
1204,
283,
952,
7,
4331,
6990,
1378,
1872,
8,
3159,
63,
589,
14,
1199,
12,
1233,
82,
29,
9653,
3034,
82,
4059,
523,
299,
14,
1065,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
523,
1255,
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
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
33,
10431,
1808,
3537,
4840,
13,
6788,
1233,
2393,
367,
1318,
5274,
436,
19241,
83,
14,
199,
199,
1918,
1324,
570,
3509,
282,
4840,
1059,
641,
1924,
1004,
13660,
282,
1336,
199,
3059,
1808,
314,
2569,
4177,
26,
819,
791,
10409,
356,
359,
3727,
1156,
63,
2339,
12,
598,
47,
748,
51,
467,
283,
1102,
356,
359,
3727,
1156,
63,
2339,
12,
598,
47,
748,
51,
9420,
199,
199,
1918,
1072,
570,
911,
1395,
314,
9235,
4501,
367,
1924,
8099,
543,
1373,
8099,
199,
529,
1004,
315,
314,
2569,
1475,
26,
819,
359,
3727,
1156,
63,
2339,
12,
3625,
2919,
51,
61,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
7534,
199,
646,
2022,
199,
646,
2050,
199,
199,
646,
17098,
63,
14529,
465,
17453,
199,
504,
17098,
63,
14529,
14,
2308,
492,
5574,
2532,
1872,
199,
504,
17098,
63,
14529,
14,
2308,
492,
6990,
1378,
1872,
199,
504,
17098,
63,
14529,
14,
1208,
14,
7379,
63,
1419,
492,
19090,
4558,
199,
504,
17098,
63,
14529,
14,
1208,
14,
7379,
63,
1419,
492,
12439,
4558,
421,
199,
533,
14587,
3034,
82,
8,
785,
304,
523,
408,
33,
4840,
1233,
82,
6421,
1337,
1924,
1004,
465,
282,
4840,
1059,
1041,
819,
347,
3752,
8,
277,
12,
671,
304,
272,
372,
2022,
14,
4180,
8,
88,
9,
819,
347,
4849,
8,
277,
12,
671,
304,
272,
372,
2022,
14,
3640,
8,
88,
9,
421,
199,
318,
4526,
63,
3438,
8,
3059,
304,
523,
408,
8564,
4501,
4079,
641,
314,
2777,
3035,
314,
1336,
754,
14,
819,
710,
805,
465,
20440,
650,
4501,
367,
282,
4747,
12,
413,
2376,
367,
282,
5954,
12,
436,
378,
4501,
367,
523,
282,
5621,
334,
3239,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
21485,
63,
3438,
63,
509,
63,
65,
63,
2676,
680,
523,
408,
523,
1591,
63,
354,
12,
1591,
63,
30970,
275,
2777,
459,
1102,
418,
523,
13980,
63,
354,
12,
13980,
63,
30970,
275,
2777,
459,
10409,
418,
523,
340,
1591,
63,
30970,
508,
13980,
63,
30970,
26,
272,
1995,
1591,
63,
354,
12,
413,
272,
1995,
13980,
63,
354,
12,
413,
523,
916,
1591,
63,
30970,
690,
13980,
63,
30970,
26,
272,
1995,
1591,
63,
354,
12,
650,
272,
1995,
13980,
63,
354,
12,
378,
523,
587,
26,
272,
1995,
1591,
63,
354,
12,
378,
272,
1995,
13980,
63,
354,
12,
650,
421,
199,
318,
1255,
8,
3020,
29,
403,
304,
523,
408,
16291,
314,
10431,
17226,
3141,
4501,
687,
282,
3245,
402,
4450,
1041,
819,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
4517,
1210,
297,
1993,
1415,
29,
549,
12,
1993,
1720,
534,
3205,
570,
370,
2112,
2659,
523,
1798,
14,
525,
63,
2094,
4517,
1199,
297,
1993,
1415,
29,
549,
12,
1993,
1720,
534,
2959,
570,
370,
2218,
2058,
370,
2659,
523,
6040,
63,
589,
12,
7679,
63,
589,
275,
1798,
14,
1122,
63,
3159,
63,
589,
8,
3020,
9,
523,
327,
2136,
675,
314,
3354,
63,
973,
63,
1730,
945,
2952,
1373,
503,
1655,
4226,
9656,
1159,
315,
642,
523,
327,
10431,
19687,
641,
2288,
1067,
334,
69,
14,
71,
2020,
282,
859,
8439,
737,
859,
2166,
680,
523,
7679,
63,
1419,
275,
19090,
4558,
8,
7379,
63,
589,
9,
523,
7679,
63,
1419,
14,
1345,
63,
305,
8,
8555,
4558,
680,
2117,
63,
973,
63,
1730,
275,
715,
523,
299,
275,
17453,
14,
17562,
8,
1419,
29,
7379,
63,
1419,
9,
819,
299,
275,
17453,
14,
17562,
8,
3020,
29,
7379,
63,
589,
9,
523,
334,
80,
221,
327,
4287,
26,
3507,
29,
5599,
13,
1397,
13,
12941,
2043,
1204,
283,
739,
7,
4331,
5574,
2532,
1872,
8,
3159,
63,
589,
14,
1210,
12,
1233,
82,
29,
9653,
3034,
82,
1012,
2043,
1204,
283,
3438,
7,
4331,
17453,
14,
17271,
2956,
8,
3357,
63,
3438,
9,
2043,
1204,
17453,
14,
23163,
2623,
1197,
8,
1838,
9,
2043,
1204,
283,
952,
7,
4331,
6990,
1378,
1872,
8,
3159,
63,
589,
14,
1199,
12,
1233,
82,
29,
9653,
3034,
82,
4059,
523,
299,
14,
1065,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
523,
1255,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jscott413/maidsinharlem
|
flask/lib/python2.7/site-packages/migrate/tests/versioning/test_script.py
|
63
|
10322
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import imp
import os
import sys
import shutil
import six
from migrate import exceptions
from migrate.versioning import version, repository
from migrate.versioning.script import *
from migrate.versioning.util import *
from migrate.tests import fixture
from migrate.tests.fixture.models import tmp_sql_table
class TestBaseScript(fixture.Pathed):
def test_all(self):
"""Testing all basic BaseScript operations"""
# verify / source / run
src = self.tmp()
open(src, 'w').close()
bscript = BaseScript(src)
BaseScript.verify(src)
self.assertEqual(bscript.source(), '')
self.assertRaises(NotImplementedError, bscript.run, 'foobar')
class TestPyScript(fixture.Pathed, fixture.DB):
cls = PythonScript
def test_create(self):
"""We can create a migration script"""
path = self.tmp_py()
# Creating a file that doesn't exist should succeed
self.cls.create(path)
self.assertTrue(os.path.exists(path))
# Created file should be a valid script (If not, raises an error)
self.cls.verify(path)
# Can't create it again: it already exists
self.assertRaises(exceptions.PathFoundError,self.cls.create,path)
@fixture.usedb(supported='sqlite')
def test_run(self):
script_path = self.tmp_py()
pyscript = PythonScript.create(script_path)
pyscript.run(self.engine, 1)
pyscript.run(self.engine, -1)
self.assertRaises(exceptions.ScriptError, pyscript.run, self.engine, 0)
self.assertRaises(exceptions.ScriptError, pyscript._func, 'foobar')
# clean pyc file
if six.PY3:
os.remove(imp.cache_from_source(script_path))
else:
os.remove(script_path + 'c')
# test deprecated upgrade/downgrade with no arguments
contents = open(script_path, 'r').read()
f = open(script_path, 'w')
f.write(contents.replace("upgrade(migrate_engine)", "upgrade()"))
f.close()
pyscript = PythonScript(script_path)
pyscript._module = None
try:
pyscript.run(self.engine, 1)
pyscript.run(self.engine, -1)
except exceptions.ScriptError:
pass
else:
self.fail()
def test_verify_notfound(self):
"""Correctly verify a python migration script: nonexistant file"""
path = self.tmp_py()
self.assertFalse(os.path.exists(path))
# Fails on empty path
self.assertRaises(exceptions.InvalidScriptError,self.cls.verify,path)
self.assertRaises(exceptions.InvalidScriptError,self.cls,path)
def test_verify_invalidpy(self):
"""Correctly verify a python migration script: invalid python file"""
path=self.tmp_py()
# Create empty file
f = open(path,'w')
f.write("def fail")
f.close()
self.assertRaises(Exception,self.cls.verify_module,path)
# script isn't verified on creation, but on module reference
py = self.cls(path)
self.assertRaises(Exception,(lambda x: x.module),py)
def test_verify_nofuncs(self):
"""Correctly verify a python migration script: valid python file; no upgrade func"""
path = self.tmp_py()
# Create empty file
f = open(path, 'w')
f.write("def zergling():\n\tprint('rush')")
f.close()
self.assertRaises(exceptions.InvalidScriptError, self.cls.verify_module, path)
# script isn't verified on creation, but on module reference
py = self.cls(path)
self.assertRaises(exceptions.InvalidScriptError,(lambda x: x.module),py)
@fixture.usedb(supported='sqlite')
def test_preview_sql(self):
"""Preview SQL abstract from ORM layer (sqlite)"""
path = self.tmp_py()
f = open(path, 'w')
content = '''
from migrate import *
from sqlalchemy import *
metadata = MetaData()
UserGroup = Table('Link', metadata,
Column('link1ID', Integer),
Column('link2ID', Integer),
UniqueConstraint('link1ID', 'link2ID'))
def upgrade(migrate_engine):
metadata.create_all(migrate_engine)
'''
f.write(content)
f.close()
pyscript = self.cls(path)
SQL = pyscript.preview_sql(self.url, 1)
self.assertEqualIgnoreWhitespace("""
CREATE TABLE "Link"
("link1ID" INTEGER,
"link2ID" INTEGER,
UNIQUE ("link1ID", "link2ID"))
""", SQL)
# TODO: test: No SQL should be executed!
def test_verify_success(self):
"""Correctly verify a python migration script: success"""
path = self.tmp_py()
# Succeeds after creating
self.cls.create(path)
self.cls.verify(path)
# test for PythonScript.make_update_script_for_model
@fixture.usedb()
def test_make_update_script_for_model(self):
"""Construct script source from differences of two models"""
self.setup_model_params()
self.write_file(self.first_model_path, self.base_source)
self.write_file(self.second_model_path, self.base_source + self.model_source)
source_script = self.pyscript.make_update_script_for_model(
engine=self.engine,
oldmodel=load_model('testmodel_first:meta'),
model=load_model('testmodel_second:meta'),
repository=self.repo_path,
)
self.assertTrue("['User'].create()" in source_script)
self.assertTrue("['User'].drop()" in source_script)
@fixture.usedb()
def test_make_update_script_for_equal_models(self):
"""Try to make update script from two identical models"""
self.setup_model_params()
self.write_file(self.first_model_path, self.base_source + self.model_source)
self.write_file(self.second_model_path, self.base_source + self.model_source)
source_script = self.pyscript.make_update_script_for_model(
engine=self.engine,
oldmodel=load_model('testmodel_first:meta'),
model=load_model('testmodel_second:meta'),
repository=self.repo_path,
)
self.assertFalse('User.create()' in source_script)
self.assertFalse('User.drop()' in source_script)
@fixture.usedb()
def test_make_update_script_direction(self):
"""Check update scripts go in the right direction"""
self.setup_model_params()
self.write_file(self.first_model_path, self.base_source)
self.write_file(self.second_model_path, self.base_source + self.model_source)
source_script = self.pyscript.make_update_script_for_model(
engine=self.engine,
oldmodel=load_model('testmodel_first:meta'),
model=load_model('testmodel_second:meta'),
repository=self.repo_path,
)
self.assertTrue(0
< source_script.find('upgrade')
< source_script.find("['User'].create()")
< source_script.find('downgrade')
< source_script.find("['User'].drop()"))
def setup_model_params(self):
self.script_path = self.tmp_py()
self.repo_path = self.tmp()
self.first_model_path = os.path.join(self.temp_usable_dir, 'testmodel_first.py')
self.second_model_path = os.path.join(self.temp_usable_dir, 'testmodel_second.py')
self.base_source = """from sqlalchemy import *\nmeta = MetaData()\n"""
self.model_source = """
User = Table('User', meta,
Column('id', Integer, primary_key=True),
Column('login', Unicode(40)),
Column('passwd', String(40)),
)"""
self.repo = repository.Repository.create(self.repo_path, 'repo')
self.pyscript = PythonScript.create(self.script_path)
sys.modules.pop('testmodel_first', None)
sys.modules.pop('testmodel_second', None)
def write_file(self, path, contents):
f = open(path, 'w')
f.write(contents)
f.close()
class TestSqlScript(fixture.Pathed, fixture.DB):
@fixture.usedb()
def test_error(self):
"""Test if exception is raised on wrong script source"""
src = self.tmp()
f = open(src, 'w')
f.write("""foobar""")
f.close()
sqls = SqlScript(src)
self.assertRaises(Exception, sqls.run, self.engine)
@fixture.usedb()
def test_success(self):
"""Test sucessful SQL execution"""
# cleanup and prepare python script
tmp_sql_table.metadata.drop_all(self.engine, checkfirst=True)
script_path = self.tmp_py()
pyscript = PythonScript.create(script_path)
# populate python script
contents = open(script_path, 'r').read()
contents = contents.replace("pass", "tmp_sql_table.create(migrate_engine)")
contents = 'from migrate.tests.fixture.models import tmp_sql_table\n' + contents
f = open(script_path, 'w')
f.write(contents)
f.close()
# write SQL script from python script preview
pyscript = PythonScript(script_path)
src = self.tmp()
f = open(src, 'w')
f.write(pyscript.preview_sql(self.url, 1))
f.close()
# run the change
sqls = SqlScript(src)
sqls.run(self.engine)
tmp_sql_table.metadata.drop_all(self.engine, checkfirst=True)
@fixture.usedb()
def test_transaction_management_statements(self):
"""
Test that we can successfully execute SQL scripts with transaction
management statements.
"""
for script_pattern in (
"BEGIN TRANSACTION; %s; COMMIT;",
"BEGIN; %s; END TRANSACTION;",
"/* comment */BEGIN TRANSACTION; %s; /* comment */COMMIT;",
"/* comment */ BEGIN TRANSACTION; %s; /* comment */ COMMIT;",
"""
-- comment
BEGIN TRANSACTION;
%s;
-- comment
COMMIT;""",
):
test_statement = ("CREATE TABLE TEST1 (field1 int); "
"DROP TABLE TEST1")
script = script_pattern % test_statement
src = self.tmp()
with open(src, 'wt') as f:
f.write(script)
sqls = SqlScript(src)
sqls.run(self.engine)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
1742,
199,
646,
747,
199,
646,
984,
199,
646,
5145,
199,
199,
646,
3816,
199,
504,
12810,
492,
4967,
199,
504,
12810,
14,
30968,
492,
1015,
12,
7611,
199,
504,
12810,
14,
30968,
14,
1579,
492,
627,
199,
504,
12810,
14,
30968,
14,
1974,
492,
627,
199,
199,
504,
12810,
14,
2219,
492,
10949,
199,
504,
12810,
14,
2219,
14,
5997,
14,
992,
492,
3529,
63,
3009,
63,
1224,
421,
199,
533,
1379,
1563,
5229,
8,
5997,
14,
2042,
379,
304,
339,
347,
511,
63,
452,
8,
277,
304,
267,
408,
9029,
1006,
5678,
3523,
5229,
5331,
624,
267,
327,
4911,
1182,
1350,
1182,
1255,
267,
2928,
275,
291,
14,
2791,
342,
267,
1551,
8,
2164,
12,
283,
87,
1959,
1600,
342,
267,
330,
1579,
275,
3523,
5229,
8,
2164,
9,
267,
3523,
5229,
14,
4712,
8,
2164,
9,
267,
291,
14,
629,
8,
66,
1579,
14,
1365,
1062,
4074,
267,
291,
14,
1855,
8,
18097,
12,
330,
1579,
14,
1065,
12,
283,
9664,
358,
421,
199,
533,
1379,
2713,
5229,
8,
5997,
14,
2042,
379,
12,
10949,
14,
2846,
304,
272,
843,
275,
2018,
5229,
272,
347,
511,
63,
981,
8,
277,
304,
267,
408,
6004,
883,
1218,
282,
8367,
2884,
624,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
267,
327,
20507,
282,
570,
626,
3181,
1133,
2187,
1077,
17961,
267,
291,
14,
1886,
14,
981,
8,
515,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
515,
430,
267,
327,
18208,
570,
1077,
506,
282,
1686,
2884,
334,
3917,
440,
12,
6534,
376,
1125,
9,
267,
291,
14,
1886,
14,
4712,
8,
515,
9,
267,
327,
6855,
1133,
1218,
652,
4020,
26,
652,
2575,
3495,
267,
291,
14,
1855,
8,
3924,
14,
2042,
3601,
547,
12,
277,
14,
1886,
14,
981,
12,
515,
9,
339,
768,
5997,
14,
1180,
697,
8,
4946,
534,
10659,
358,
272,
347,
511,
63,
1065,
8,
277,
304,
267,
2884,
63,
515,
275,
291,
14,
2791,
63,
647,
342,
267,
1134,
1579,
275,
2018,
5229,
14,
981,
8,
1579,
63,
515,
9,
267,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
413,
9,
267,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
446,
17,
9,
398,
291,
14,
1855,
8,
3924,
14,
5229,
547,
12,
1134,
1579,
14,
1065,
12,
291,
14,
3908,
12,
378,
9,
267,
291,
14,
1855,
8,
3924,
14,
5229,
547,
12,
1134,
1579,
423,
1532,
12,
283,
9664,
358,
398,
327,
3633,
28968,
570,
267,
340,
3816,
14,
4521,
19,
26,
288,
747,
14,
2168,
8,
3236,
14,
1637,
63,
504,
63,
1365,
8,
1579,
63,
515,
430,
267,
587,
26,
288,
747,
14,
2168,
8,
1579,
63,
515,
435,
283,
67,
358,
398,
327,
511,
5906,
10754,
15,
2110,
4523,
543,
949,
2368,
267,
4072,
275,
1551,
8,
1579,
63,
515,
12,
283,
82,
1959,
739,
342,
267,
289,
275,
1551,
8,
1579,
63,
515,
12,
283,
87,
358,
267,
289,
14,
952,
8,
4407,
14,
1814,
480,
9375,
8,
8462,
63,
3908,
4186,
298,
9375,
342,
2237,
267,
289,
14,
1600,
342,
398,
1134,
1579,
275,
2018,
5229,
8,
1579,
63,
515,
9,
267,
1134,
1579,
423,
578,
275,
488,
267,
862,
26,
288,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
413,
9,
288,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
446,
17,
9,
267,
871,
4967,
14,
5229,
547,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
342,
339,
347,
511,
63,
4712,
63,
32353,
8,
277,
304,
267,
408,
19993,
590,
4911,
282,
2366,
8367,
2884,
26,
7179,
88,
631,
867,
570,
624,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
267,
291,
14,
3334,
8,
736,
14,
515,
14,
2444,
8,
515,
430,
267,
327,
12176,
83,
641,
2701,
931,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12,
277,
14,
1886,
14,
4712,
12,
515,
9,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12,
277,
14,
1886,
12,
515,
9,
339,
347,
511,
63,
4712,
63,
3197,
647,
8,
277,
304,
267,
408,
19993,
590,
4911,
282,
2366,
8367,
2884,
26,
3866,
2366,
570,
624,
267,
931,
29,
277,
14,
2791,
63,
647,
342,
267,
327,
2790,
2701,
570,
267,
289,
275,
1551,
8,
515,
2584,
87,
358,
267,
289,
14,
952,
480,
318,
2449,
531,
267,
289,
14,
1600,
342,
267,
291,
14,
1855,
8,
1726,
12,
277,
14,
1886,
14,
4712,
63,
578,
12,
515,
9,
267,
327,
2884,
5712,
1133,
16317,
641,
7143,
12,
1325,
641,
859,
3659,
267,
1134,
275,
291,
14,
1886,
8,
515,
9,
267,
291,
14,
1855,
8,
1726,
12803,
2734,
671,
26,
671,
14,
578,
395,
647,
9,
339,
347,
511,
63,
4712,
63,
889,
9204,
8,
277,
304,
267,
408,
19993,
590,
4911,
282,
2366,
8367,
2884,
26,
1686,
2366,
570,
27,
949,
10754,
2562,
624,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
267,
327,
2790,
2701,
570,
267,
289,
275,
1551,
8,
515,
12,
283,
87,
358,
267,
289,
14,
952,
480,
318,
8043,
71,
2983,
837,
60,
78,
60,
683,
672,
360,
82,
2084,
26530,
267,
289,
14,
1600,
342,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12,
291,
14,
1886,
14,
4712,
63,
578,
12,
931,
9,
267,
327,
2884,
5712,
1133,
16317,
641,
7143,
12,
1325,
641,
859,
3659,
267,
1134,
275,
291,
14,
1886,
8,
515,
9,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12803,
2734,
671,
26,
671,
14,
578,
395,
647,
9,
339,
768,
5997,
14,
1180,
697,
8,
4946,
534,
10659,
358,
272,
347,
511,
63,
7780,
63,
3009,
8,
277,
304,
267,
408,
27116,
5385,
9006,
687,
23383,
4045,
334,
10659,
9471,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
398,
289,
275,
1551,
8,
515,
12,
283,
87,
358,
267,
1564,
275,
1449,
199,
504,
12810,
492,
627,
199,
504,
8335,
492,
627,
199,
199,
2343,
275,
24905,
342,
199,
199,
1899,
2448,
275,
6957,
360,
3834,
297,
3341,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
1742,
199,
646,
747,
199,
646,
984,
199,
646,
5145,
199,
199,
646,
3816,
199,
504,
12810,
492,
4967,
199,
504,
12810,
14,
30968,
492,
1015,
12,
7611,
199,
504,
12810,
14,
30968,
14,
1579,
492,
627,
199,
504,
12810,
14,
30968,
14,
1974,
492,
627,
199,
199,
504,
12810,
14,
2219,
492,
10949,
199,
504,
12810,
14,
2219,
14,
5997,
14,
992,
492,
3529,
63,
3009,
63,
1224,
421,
199,
533,
1379,
1563,
5229,
8,
5997,
14,
2042,
379,
304,
339,
347,
511,
63,
452,
8,
277,
304,
267,
408,
9029,
1006,
5678,
3523,
5229,
5331,
624,
267,
327,
4911,
1182,
1350,
1182,
1255,
267,
2928,
275,
291,
14,
2791,
342,
267,
1551,
8,
2164,
12,
283,
87,
1959,
1600,
342,
267,
330,
1579,
275,
3523,
5229,
8,
2164,
9,
267,
3523,
5229,
14,
4712,
8,
2164,
9,
267,
291,
14,
629,
8,
66,
1579,
14,
1365,
1062,
4074,
267,
291,
14,
1855,
8,
18097,
12,
330,
1579,
14,
1065,
12,
283,
9664,
358,
421,
199,
533,
1379,
2713,
5229,
8,
5997,
14,
2042,
379,
12,
10949,
14,
2846,
304,
272,
843,
275,
2018,
5229,
272,
347,
511,
63,
981,
8,
277,
304,
267,
408,
6004,
883,
1218,
282,
8367,
2884,
624,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
267,
327,
20507,
282,
570,
626,
3181,
1133,
2187,
1077,
17961,
267,
291,
14,
1886,
14,
981,
8,
515,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
515,
430,
267,
327,
18208,
570,
1077,
506,
282,
1686,
2884,
334,
3917,
440,
12,
6534,
376,
1125,
9,
267,
291,
14,
1886,
14,
4712,
8,
515,
9,
267,
327,
6855,
1133,
1218,
652,
4020,
26,
652,
2575,
3495,
267,
291,
14,
1855,
8,
3924,
14,
2042,
3601,
547,
12,
277,
14,
1886,
14,
981,
12,
515,
9,
339,
768,
5997,
14,
1180,
697,
8,
4946,
534,
10659,
358,
272,
347,
511,
63,
1065,
8,
277,
304,
267,
2884,
63,
515,
275,
291,
14,
2791,
63,
647,
342,
267,
1134,
1579,
275,
2018,
5229,
14,
981,
8,
1579,
63,
515,
9,
267,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
413,
9,
267,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
446,
17,
9,
398,
291,
14,
1855,
8,
3924,
14,
5229,
547,
12,
1134,
1579,
14,
1065,
12,
291,
14,
3908,
12,
378,
9,
267,
291,
14,
1855,
8,
3924,
14,
5229,
547,
12,
1134,
1579,
423,
1532,
12,
283,
9664,
358,
398,
327,
3633,
28968,
570,
267,
340,
3816,
14,
4521,
19,
26,
288,
747,
14,
2168,
8,
3236,
14,
1637,
63,
504,
63,
1365,
8,
1579,
63,
515,
430,
267,
587,
26,
288,
747,
14,
2168,
8,
1579,
63,
515,
435,
283,
67,
358,
398,
327,
511,
5906,
10754,
15,
2110,
4523,
543,
949,
2368,
267,
4072,
275,
1551,
8,
1579,
63,
515,
12,
283,
82,
1959,
739,
342,
267,
289,
275,
1551,
8,
1579,
63,
515,
12,
283,
87,
358,
267,
289,
14,
952,
8,
4407,
14,
1814,
480,
9375,
8,
8462,
63,
3908,
4186,
298,
9375,
342,
2237,
267,
289,
14,
1600,
342,
398,
1134,
1579,
275,
2018,
5229,
8,
1579,
63,
515,
9,
267,
1134,
1579,
423,
578,
275,
488,
267,
862,
26,
288,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
413,
9,
288,
1134,
1579,
14,
1065,
8,
277,
14,
3908,
12,
446,
17,
9,
267,
871,
4967,
14,
5229,
547,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
342,
339,
347,
511,
63,
4712,
63,
32353,
8,
277,
304,
267,
408,
19993,
590,
4911,
282,
2366,
8367,
2884,
26,
7179,
88,
631,
867,
570,
624,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
267,
291,
14,
3334,
8,
736,
14,
515,
14,
2444,
8,
515,
430,
267,
327,
12176,
83,
641,
2701,
931,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12,
277,
14,
1886,
14,
4712,
12,
515,
9,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12,
277,
14,
1886,
12,
515,
9,
339,
347,
511,
63,
4712,
63,
3197,
647,
8,
277,
304,
267,
408,
19993,
590,
4911,
282,
2366,
8367,
2884,
26,
3866,
2366,
570,
624,
267,
931,
29,
277,
14,
2791,
63,
647,
342,
267,
327,
2790,
2701,
570,
267,
289,
275,
1551,
8,
515,
2584,
87,
358,
267,
289,
14,
952,
480,
318,
2449,
531,
267,
289,
14,
1600,
342,
267,
291,
14,
1855,
8,
1726,
12,
277,
14,
1886,
14,
4712,
63,
578,
12,
515,
9,
267,
327,
2884,
5712,
1133,
16317,
641,
7143,
12,
1325,
641,
859,
3659,
267,
1134,
275,
291,
14,
1886,
8,
515,
9,
267,
291,
14,
1855,
8,
1726,
12803,
2734,
671,
26,
671,
14,
578,
395,
647,
9,
339,
347,
511,
63,
4712,
63,
889,
9204,
8,
277,
304,
267,
408,
19993,
590,
4911,
282,
2366,
8367,
2884,
26,
1686,
2366,
570,
27,
949,
10754,
2562,
624,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
267,
327,
2790,
2701,
570,
267,
289,
275,
1551,
8,
515,
12,
283,
87,
358,
267,
289,
14,
952,
480,
318,
8043,
71,
2983,
837,
60,
78,
60,
683,
672,
360,
82,
2084,
26530,
267,
289,
14,
1600,
342,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12,
291,
14,
1886,
14,
4712,
63,
578,
12,
931,
9,
267,
327,
2884,
5712,
1133,
16317,
641,
7143,
12,
1325,
641,
859,
3659,
267,
1134,
275,
291,
14,
1886,
8,
515,
9,
267,
291,
14,
1855,
8,
3924,
14,
3364,
5229,
547,
12803,
2734,
671,
26,
671,
14,
578,
395,
647,
9,
339,
768,
5997,
14,
1180,
697,
8,
4946,
534,
10659,
358,
272,
347,
511,
63,
7780,
63,
3009,
8,
277,
304,
267,
408,
27116,
5385,
9006,
687,
23383,
4045,
334,
10659,
9471,
267,
931,
275,
291,
14,
2791,
63,
647,
342,
398,
289,
275,
1551,
8,
515,
12,
283,
87,
358,
267,
1564,
275,
1449,
199,
504,
12810,
492,
627,
199,
504,
8335,
492,
627,
199,
199,
2343,
275,
24905,
342,
199,
199,
1899,
2448,
275,
6957,
360,
3834,
297,
3341,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
hamzehd/edx-platform
|
openedx/core/djangoapps/course_groups/tests/test_cohorts.py
|
12
|
33673
|
"""
Tests for cohorts
"""
# pylint: disable=no-member
import ddt
from mock import call, patch
import before_after
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.http import Http404
from django.test import TestCase
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE, ModuleStoreTestCase
from ..models import CourseUserGroup, CourseCohort, CourseUserGroupPartitionGroup
from .. import cohorts
from ..tests.helpers import (
topic_name_to_id, config_course_cohorts, config_course_cohorts_legacy,
CohortFactory, CourseCohortFactory, CourseCohortSettingsFactory
)
@patch("openedx.core.djangoapps.course_groups.cohorts.tracker")
class TestCohortSignals(TestCase):
"""
Test cases to validate event emissions for various cohort-related workflows
"""
def setUp(self):
super(TestCohortSignals, self).setUp()
self.course_key = SlashSeparatedCourseKey("dummy", "dummy", "dummy")
def test_cohort_added(self, mock_tracker):
# Add cohort
cohort = CourseUserGroup.objects.create(
name="TestCohort",
course_id=self.course_key,
group_type=CourseUserGroup.COHORT
)
mock_tracker.emit.assert_called_with(
"edx.cohort.created",
{"cohort_id": cohort.id, "cohort_name": cohort.name}
)
mock_tracker.reset_mock()
# Modify existing cohort
cohort.name = "NewName"
cohort.save()
self.assertFalse(mock_tracker.called)
# Add non-cohort group
CourseUserGroup.objects.create(
name="TestOtherGroupType",
course_id=self.course_key,
group_type="dummy"
)
self.assertFalse(mock_tracker.called)
def test_cohort_membership_changed(self, mock_tracker):
cohort_list = [CohortFactory() for _ in range(2)]
non_cohort = CourseUserGroup.objects.create(
name="dummy",
course_id=self.course_key,
group_type="dummy"
)
user_list = [UserFactory() for _ in range(2)]
mock_tracker.reset_mock()
def assert_events(event_name_suffix, user_list, cohort_list):
"""
Confirms the presence of the specifed event for each user in the specified list of cohorts
"""
mock_tracker.emit.assert_has_calls([
call(
"edx.cohort.user_" + event_name_suffix,
{
"user_id": user.id,
"cohort_id": cohort.id,
"cohort_name": cohort.name,
}
)
for user in user_list for cohort in cohort_list
])
# Add users to cohort
cohort_list[0].users.add(*user_list)
assert_events("added", user_list, cohort_list[:1])
mock_tracker.reset_mock()
# Remove users from cohort
cohort_list[0].users.remove(*user_list)
assert_events("removed", user_list, cohort_list[:1])
mock_tracker.reset_mock()
# Clear users from cohort
cohort_list[0].users.add(*user_list)
cohort_list[0].users.clear()
assert_events("removed", user_list, cohort_list[:1])
mock_tracker.reset_mock()
# Clear users from non-cohort group
non_cohort.users.add(*user_list)
non_cohort.users.clear()
self.assertFalse(mock_tracker.emit.called)
# Add cohorts to user
user_list[0].course_groups.add(*cohort_list)
assert_events("added", user_list[:1], cohort_list)
mock_tracker.reset_mock()
# Remove cohorts from user
user_list[0].course_groups.remove(*cohort_list)
assert_events("removed", user_list[:1], cohort_list)
mock_tracker.reset_mock()
# Clear cohorts from user
user_list[0].course_groups.add(*cohort_list)
user_list[0].course_groups.clear()
assert_events("removed", user_list[:1], cohort_list)
mock_tracker.reset_mock()
# Clear non-cohort groups from user
user_list[0].course_groups.add(non_cohort)
user_list[0].course_groups.clear()
self.assertFalse(mock_tracker.emit.called)
@ddt.ddt
class TestCohorts(ModuleStoreTestCase):
"""
Test the cohorts feature
"""
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
def setUp(self):
"""
Make sure that course is reloaded every time--clear out the modulestore.
"""
super(TestCohorts, self).setUp()
self.toy_course_key = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")
def _create_cohort(self, course_id, cohort_name, assignment_type):
"""
Create a cohort for testing.
"""
cohort = CohortFactory(course_id=course_id, name=cohort_name)
CourseCohortFactory(course_user_group=cohort, assignment_type=assignment_type)
return cohort
def test_is_course_cohorted(self):
"""
Make sure cohorts.is_course_cohorted() correctly reports if a course is cohorted or not.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
config_course_cohorts(course, is_cohorted=True)
self.assertTrue(cohorts.is_course_cohorted(course.id))
# Make sure we get a Http404 if there's no course
fake_key = SlashSeparatedCourseKey('a', 'b', 'c')
self.assertRaises(Http404, lambda: cohorts.is_course_cohorted(fake_key))
def test_get_cohort_id(self):
"""
Make sure that cohorts.get_cohort_id() correctly returns the cohort id, or raises a ValueError when given an
invalid course key.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
user = UserFactory(username="test", email="a@b.com")
self.assertIsNone(cohorts.get_cohort_id(user, course.id))
config_course_cohorts(course, is_cohorted=True)
cohort = CohortFactory(course_id=course.id, name="TestCohort")
cohort.users.add(user)
self.assertEqual(cohorts.get_cohort_id(user, course.id), cohort.id)
self.assertRaises(
Http404,
lambda: cohorts.get_cohort_id(user, SlashSeparatedCourseKey("course", "does_not", "exist"))
)
def test_assignment_type(self):
"""
Make sure that cohorts.set_assignment_type() and cohorts.get_assignment_type() works correctly.
"""
course = modulestore().get_course(self.toy_course_key)
# We are creating two random cohorts because we can't change assignment type of
# random cohort if it is the only random cohort present.
cohort1 = self._create_cohort(course.id, "TestCohort1", CourseCohort.RANDOM)
self._create_cohort(course.id, "TestCohort2", CourseCohort.RANDOM)
cohort3 = self._create_cohort(course.id, "TestCohort3", CourseCohort.MANUAL)
self.assertEqual(cohorts.get_assignment_type(cohort1), CourseCohort.RANDOM)
cohorts.set_assignment_type(cohort1, CourseCohort.MANUAL)
self.assertEqual(cohorts.get_assignment_type(cohort1), CourseCohort.MANUAL)
cohorts.set_assignment_type(cohort3, CourseCohort.RANDOM)
self.assertEqual(cohorts.get_assignment_type(cohort3), CourseCohort.RANDOM)
def test_cannot_set_assignment_type(self):
"""
Make sure that we can't change the assignment type of a random cohort if it is the only random cohort present.
"""
course = modulestore().get_course(self.toy_course_key)
cohort = self._create_cohort(course.id, "TestCohort", CourseCohort.RANDOM)
self.assertEqual(cohorts.get_assignment_type(cohort), CourseCohort.RANDOM)
exception_msg = "There must be one cohort to which students can automatically be assigned."
with self.assertRaises(ValueError) as context_manager:
cohorts.set_assignment_type(cohort, CourseCohort.MANUAL)
self.assertEqual(exception_msg, str(context_manager.exception))
def test_get_cohort(self):
"""
Make sure cohorts.get_cohort() does the right thing when the course is cohorted
"""
course = modulestore().get_course(self.toy_course_key)
self.assertEqual(course.id, self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
user = UserFactory(username="test", email="a@b.com")
other_user = UserFactory(username="test2", email="a2@b.com")
self.assertIsNone(cohorts.get_cohort(user, course.id), "No cohort created yet")
cohort = CohortFactory(course_id=course.id, name="TestCohort")
cohort.users.add(user)
self.assertIsNone(
cohorts.get_cohort(user, course.id),
"Course isn't cohorted, so shouldn't have a cohort"
)
# Make the course cohorted...
config_course_cohorts(course, is_cohorted=True)
self.assertEquals(
cohorts.get_cohort(user, course.id).id,
cohort.id,
"user should be assigned to the correct cohort"
)
self.assertEquals(
cohorts.get_cohort(other_user, course.id).id,
cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).id,
"other_user should be assigned to the default cohort"
)
@ddt.data(
(True, 2),
(False, 6),
)
@ddt.unpack
def test_get_cohort_sql_queries(self, use_cached, num_sql_queries):
"""
Test number of queries by cohorts.get_cohort() with and without caching.
"""
course = modulestore().get_course(self.toy_course_key)
config_course_cohorts(course, is_cohorted=True)
cohort = CohortFactory(course_id=course.id, name="TestCohort")
user = UserFactory(username="test", email="a@b.com")
cohort.users.add(user)
with self.assertNumQueries(num_sql_queries):
for __ in range(3):
cohorts.get_cohort(user, course.id, use_cached=use_cached)
def test_get_cohort_with_assign(self):
"""
Make sure cohorts.get_cohort() returns None if no group is already
assigned to a user instead of assigning/creating a group automatically
"""
course = modulestore().get_course(self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
user = UserFactory(username="test", email="a@b.com")
# Add an auto_cohort_group to the course...
config_course_cohorts(
course,
is_cohorted=True,
auto_cohorts=["AutoGroup"]
)
# get_cohort should return None as no group is assigned to user
self.assertIsNone(cohorts.get_cohort(user, course.id, assign=False))
# get_cohort should return a group for user
self.assertEquals(cohorts.get_cohort(user, course.id).name, "AutoGroup")
def test_cohorting_with_auto_cohorts(self):
"""
Make sure cohorts.get_cohort() does the right thing.
If there are auto cohort groups then a user should be assigned one.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
user1 = UserFactory(username="test", email="a@b.com")
user2 = UserFactory(username="test2", email="a2@b.com")
cohort = CohortFactory(course_id=course.id, name="TestCohort")
# user1 manually added to a cohort
cohort.users.add(user1)
# Add an auto_cohort_group to the course...
config_course_cohorts(
course,
is_cohorted=True,
auto_cohorts=["AutoGroup"]
)
self.assertEquals(cohorts.get_cohort(user1, course.id).id, cohort.id, "user1 should stay put")
self.assertEquals(cohorts.get_cohort(user2, course.id).name, "AutoGroup", "user2 should be auto-cohorted")
def test_cohorting_with_migrations_done(self):
"""
Verifies that cohort config changes on studio/moduletore side will
not be reflected on lms after the migrations are done.
"""
course = modulestore().get_course(self.toy_course_key)
user1 = UserFactory(username="test", email="a@b.com")
user2 = UserFactory(username="test2", email="a2@b.com")
# Add an auto_cohort_group to the course...
config_course_cohorts(
course,
is_cohorted=True,
auto_cohorts=["AutoGroup"]
)
self.assertEquals(cohorts.get_cohort(user1, course.id).name, "AutoGroup", "user1 should be auto-cohorted")
# Now set the auto_cohort_group to something different
# This will have no effect on lms side as we are already done with migrations
config_course_cohorts_legacy(
course,
discussions=[],
cohorted=True,
auto_cohort_groups=["OtherGroup"]
)
self.assertEquals(
cohorts.get_cohort(user2, course.id).name, "AutoGroup", "user2 should be assigned to AutoGroups"
)
self.assertEquals(
cohorts.get_cohort(user1, course.id).name, "AutoGroup", "user1 should still be in originally placed cohort"
)
def test_cohorting_with_no_auto_cohorts(self):
"""
Make sure cohorts.get_cohort() does the right thing.
If there are not auto cohorts then a user should be assigned to Default Cohort Group.
Also verifies that cohort config changes on studio/moduletore side will
not be reflected on lms after the migrations are done.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
user1 = UserFactory(username="test", email="a@b.com")
user2 = UserFactory(username="test2", email="a2@b.com")
# Make the auto_cohort_group list empty
config_course_cohorts(
course,
is_cohorted=True,
auto_cohorts=[]
)
self.assertEquals(
cohorts.get_cohort(user1, course.id).id,
cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).id,
"No groups->default cohort for user1"
)
# Add an auto_cohort_group to the course
# This will have no effect on lms side as we are already done with migrations
config_course_cohorts_legacy(
course,
discussions=[],
cohorted=True,
auto_cohort_groups=["AutoGroup"]
)
self.assertEquals(
cohorts.get_cohort(user1, course.id).name,
cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).name,
"user1 should still be in the default cohort"
)
self.assertEquals(
cohorts.get_cohort(user2, course.id).id,
cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).id,
"No groups->default cohort for user2"
)
def test_auto_cohorting_randomization(self):
"""
Make sure cohorts.get_cohort() randomizes properly.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertFalse(cohorts.is_course_cohorted(course.id))
groups = ["group_{0}".format(n) for n in range(5)]
config_course_cohorts(
course, is_cohorted=True, auto_cohorts=groups
)
# Assign 100 users to cohorts
for i in range(100):
user = UserFactory(
username="test_{0}".format(i),
email="a@b{0}.com".format(i)
)
cohorts.get_cohort(user, course.id)
# Now make sure that the assignment was at least vaguely random:
# each cohort should have at least 1, and fewer than 50 students.
# (with 5 groups, probability of 0 users in any group is about
# .8**100= 2.0e-10)
for cohort_name in groups:
cohort = cohorts.get_cohort_by_name(course.id, cohort_name)
num_users = cohort.users.count()
self.assertGreater(num_users, 1)
self.assertLess(num_users, 50)
def test_get_course_cohorts_noop(self):
"""
Tests get_course_cohorts returns an empty list when no cohorts exist.
"""
course = modulestore().get_course(self.toy_course_key)
config_course_cohorts(course, is_cohorted=True)
self.assertEqual([], cohorts.get_course_cohorts(course))
def test_get_course_cohorts(self):
"""
Tests that get_course_cohorts returns all cohorts, including auto cohorts.
"""
course = modulestore().get_course(self.toy_course_key)
config_course_cohorts(
course,
is_cohorted=True,
auto_cohorts=["AutoGroup1", "AutoGroup2"]
)
# add manual cohorts to course 1
CohortFactory(course_id=course.id, name="ManualCohort")
CohortFactory(course_id=course.id, name="ManualCohort2")
cohort_set = {c.name for c in cohorts.get_course_cohorts(course)}
self.assertEqual(cohort_set, {"AutoGroup1", "AutoGroup2", "ManualCohort", "ManualCohort2"})
def test_get_cohort_names(self):
course = modulestore().get_course(self.toy_course_key)
cohort1 = CohortFactory(course_id=course.id, name="Cohort1")
cohort2 = CohortFactory(course_id=course.id, name="Cohort2")
self.assertEqual(
cohorts.get_cohort_names(course),
{cohort1.id: cohort1.name, cohort2.id: cohort2.name}
)
def test_get_cohorted_commentables(self):
"""
Make sure cohorts.get_cohorted_commentables() correctly returns a list of strings representing cohorted
commentables. Also verify that we can't get the cohorted commentables from a course which does not exist.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertEqual(cohorts.get_cohorted_commentables(course.id), set())
config_course_cohorts(course, is_cohorted=True)
self.assertEqual(cohorts.get_cohorted_commentables(course.id), set())
config_course_cohorts(
course,
is_cohorted=True,
discussion_topics=["General", "Feedback"],
cohorted_discussions=["Feedback"]
)
self.assertItemsEqual(
cohorts.get_cohorted_commentables(course.id),
set([topic_name_to_id(course, "Feedback")])
)
config_course_cohorts(
course,
is_cohorted=True,
discussion_topics=["General", "Feedback"],
cohorted_discussions=["General", "Feedback"]
)
self.assertItemsEqual(
cohorts.get_cohorted_commentables(course.id),
set([topic_name_to_id(course, "General"), topic_name_to_id(course, "Feedback")])
)
self.assertRaises(
Http404,
lambda: cohorts.get_cohorted_commentables(SlashSeparatedCourseKey("course", "does_not", "exist"))
)
def test_get_cohort_by_name(self):
"""
Make sure cohorts.get_cohort_by_name() properly finds a cohort by name for a given course. Also verify that it
raises an error when the cohort is not found.
"""
course = modulestore().get_course(self.toy_course_key)
self.assertRaises(
CourseUserGroup.DoesNotExist,
lambda: cohorts.get_cohort_by_name(course.id, "CohortDoesNotExist")
)
cohort = CohortFactory(course_id=course.id, name="MyCohort")
self.assertEqual(cohorts.get_cohort_by_name(course.id, "MyCohort"), cohort)
self.assertRaises(
CourseUserGroup.DoesNotExist,
lambda: cohorts.get_cohort_by_name(SlashSeparatedCourseKey("course", "does_not", "exist"), cohort)
)
def test_get_cohort_by_id(self):
"""
Make sure cohorts.get_cohort_by_id() properly finds a cohort by id for a given
course.
"""
course = modulestore().get_course(self.toy_course_key)
cohort = CohortFactory(course_id=course.id, name="MyCohort")
self.assertEqual(cohorts.get_cohort_by_id(course.id, cohort.id), cohort)
cohort.delete()
self.assertRaises(
CourseUserGroup.DoesNotExist,
lambda: cohorts.get_cohort_by_id(course.id, cohort.id)
)
@patch("openedx.core.djangoapps.course_groups.cohorts.tracker")
def test_add_cohort(self, mock_tracker):
"""
Make sure cohorts.add_cohort() properly adds a cohort to a course and handles
errors.
"""
assignment_type = CourseCohort.RANDOM
course = modulestore().get_course(self.toy_course_key)
added_cohort = cohorts.add_cohort(course.id, "My Cohort", assignment_type)
mock_tracker.emit.assert_any_call(
"edx.cohort.creation_requested",
{"cohort_name": added_cohort.name, "cohort_id": added_cohort.id}
)
self.assertEqual(added_cohort.name, "My Cohort")
self.assertRaises(
ValueError,
lambda: cohorts.add_cohort(course.id, "My Cohort", assignment_type)
)
does_not_exist_course_key = SlashSeparatedCourseKey("course", "does_not", "exist")
self.assertRaises(
ValueError,
lambda: cohorts.add_cohort(does_not_exist_course_key, "My Cohort", assignment_type)
)
@patch("openedx.core.djangoapps.course_groups.cohorts.tracker")
def test_add_user_to_cohort(self, mock_tracker):
"""
Make sure cohorts.add_user_to_cohort() properly adds a user to a cohort and
handles errors.
"""
course_user = UserFactory(username="Username", email="a@b.com")
UserFactory(username="RandomUsername", email="b@b.com")
course = modulestore().get_course(self.toy_course_key)
CourseEnrollment.enroll(course_user, self.toy_course_key)
first_cohort = CohortFactory(course_id=course.id, name="FirstCohort")
second_cohort = CohortFactory(course_id=course.id, name="SecondCohort")
# Success cases
# We shouldn't get back a previous cohort, since the user wasn't in one
self.assertEqual(
cohorts.add_user_to_cohort(first_cohort, "Username"),
(course_user, None)
)
mock_tracker.emit.assert_any_call(
"edx.cohort.user_add_requested",
{
"user_id": course_user.id,
"cohort_id": first_cohort.id,
"cohort_name": first_cohort.name,
"previous_cohort_id": None,
"previous_cohort_name": None,
}
)
# Should get (user, previous_cohort_name) when moved from one cohort to
# another
self.assertEqual(
cohorts.add_user_to_cohort(second_cohort, "Username"),
(course_user, "FirstCohort")
)
mock_tracker.emit.assert_any_call(
"edx.cohort.user_add_requested",
{
"user_id": course_user.id,
"cohort_id": second_cohort.id,
"cohort_name": second_cohort.name,
"previous_cohort_id": first_cohort.id,
"previous_cohort_name": first_cohort.name,
}
)
# Error cases
# Should get ValueError if user already in cohort
self.assertRaises(
ValueError,
lambda: cohorts.add_user_to_cohort(second_cohort, "Username")
)
# UserDoesNotExist if user truly does not exist
self.assertRaises(
User.DoesNotExist,
lambda: cohorts.add_user_to_cohort(first_cohort, "non_existent_username")
)
@patch("openedx.core.djangoapps.course_groups.cohorts.tracker")
def add_user_to_cohorts_race_condition(self, mock_tracker):
"""
Makes use of before_after to force a race condition, in order to
confirm handling of such conditions is done correctly.
"""
course_user = UserFactory(username="Username", email="a@b.com")
course = modulestore().get_course(self.toy_course_key)
CourseEnrollment.enroll(course_user, self.toy_course_key)
first_cohort = CohortFactory(course_id=course.id, name="FirstCohort")
second_cohort = CohortFactory(course_id=course.id, name="SecondCohort")
# This before_after contextmanager allows for reliable reproduction of a race condition.
# It will break before the first save() call creates an entry, and then run add_user_to_cohort again.
# Because this second call will write before control is returned, the first call will be writing stale data.
# This test confirms that the first add_user_to_cohort call can handle this stale read condition properly.
# Proper handling is defined as treating calls as sequential, with write time deciding the order.
with before_after.before_after(
'django.db.models.Model.save',
after_ftn=cohorts.add_user_to_cohort(second_cohort, course_user.username),
autospec=True
):
# This method will read, then break, then try to write stale data.
# It should fail at that, then retry with refreshed data
cohorts.add_user_to_cohort(first_cohort, course_user.username)
mock_tracker.emit.assert_any_call(
"edx.cohort.user_add_requested",
{
"user_id": course_user.id,
"cohort_id": first_cohort.id,
"cohort_name": first_cohort.name,
"previous_cohort_id": second_cohort.id,
"previous_cohort_name": second_cohort.name,
}
)
# Note that the following get() will fail with MultipleObjectsReturned if race condition is not handled.
self.assertEqual(first_cohort.users.get(), course_user)
def test_get_course_cohort_settings(self):
"""
Test that cohorts.get_course_cohort_settings is working as expected.
"""
course = modulestore().get_course(self.toy_course_key)
course_cohort_settings = cohorts.get_course_cohort_settings(course.id)
self.assertFalse(course_cohort_settings.is_cohorted)
self.assertEqual(course_cohort_settings.cohorted_discussions, [])
self.assertTrue(course_cohort_settings.always_cohort_inline_discussions)
def test_update_course_cohort_settings(self):
"""
Test that cohorts.set_course_cohort_settings is working as expected.
"""
course = modulestore().get_course(self.toy_course_key)
CourseCohortSettingsFactory(course_id=course.id)
cohorts.set_course_cohort_settings(
course.id,
is_cohorted=False,
cohorted_discussions=['topic a id', 'topic b id'],
always_cohort_inline_discussions=False
)
course_cohort_settings = cohorts.get_course_cohort_settings(course.id)
self.assertFalse(course_cohort_settings.is_cohorted)
self.assertEqual(course_cohort_settings.cohorted_discussions, ['topic a id', 'topic b id'])
self.assertFalse(course_cohort_settings.always_cohort_inline_discussions)
def test_update_course_cohort_settings_with_invalid_data_type(self):
"""
Test that cohorts.set_course_cohort_settings raises exception if fields have incorrect data type.
"""
course = modulestore().get_course(self.toy_course_key)
CourseCohortSettingsFactory(course_id=course.id)
exception_msg_tpl = "Incorrect field type for `{}`. Type must be `{}`"
fields = [
{'name': 'is_cohorted', 'type': bool},
{'name': 'always_cohort_inline_discussions', 'type': bool},
{'name': 'cohorted_discussions', 'type': list}
]
for field in fields:
with self.assertRaises(ValueError) as value_error:
cohorts.set_course_cohort_settings(course.id, **{field['name']: ''})
self.assertEqual(
value_error.exception.message,
exception_msg_tpl.format(field['name'], field['type'].__name__)
)
@ddt.ddt
class TestCohortsAndPartitionGroups(ModuleStoreTestCase):
"""
Test Cohorts and Partitions Groups.
"""
MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE
def setUp(self):
"""
Regenerate a test course and cohorts for each test
"""
super(TestCohortsAndPartitionGroups, self).setUp()
self.test_course_key = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")
self.course = modulestore().get_course(self.test_course_key)
self.first_cohort = CohortFactory(course_id=self.course.id, name="FirstCohort")
self.second_cohort = CohortFactory(course_id=self.course.id, name="SecondCohort")
self.partition_id = 1
self.group1_id = 10
self.group2_id = 20
def _link_cohort_partition_group(self, cohort, partition_id, group_id):
"""
Utility to create cohort -> partition group assignments in the database.
"""
link = CourseUserGroupPartitionGroup(
course_user_group=cohort,
partition_id=partition_id,
group_id=group_id,
)
link.save()
return link
def test_get_group_info_for_cohort(self):
"""
Basic test of the partition_group_info accessor function
"""
# api should return nothing for an unmapped cohort
self.assertEqual(
cohorts.get_group_info_for_cohort(self.first_cohort),
(None, None),
)
# create a link for the cohort in the db
link = self._link_cohort_partition_group(
self.first_cohort,
self.partition_id,
self.group1_id
)
# api should return the specified partition and group
self.assertEqual(
cohorts.get_group_info_for_cohort(self.first_cohort),
(self.group1_id, self.partition_id)
)
# delete the link in the db
link.delete()
# api should return nothing again
self.assertEqual(
cohorts.get_group_info_for_cohort(self.first_cohort),
(None, None),
)
@ddt.data(
(True, 1),
(False, 3),
)
@ddt.unpack
def test_get_group_info_for_cohort_queries(self, use_cached, num_sql_queries):
"""
Basic test of the partition_group_info accessor function
"""
# create a link for the cohort in the db
self._link_cohort_partition_group(
self.first_cohort,
self.partition_id,
self.group1_id
)
with self.assertNumQueries(num_sql_queries):
for __ in range(3):
self.assertIsNotNone(cohorts.get_group_info_for_cohort(self.first_cohort, use_cached=use_cached))
def test_multiple_cohorts(self):
"""
Test that multiple cohorts can be linked to the same partition group
"""
self._link_cohort_partition_group(
self.first_cohort,
self.partition_id,
self.group1_id,
)
self._link_cohort_partition_group(
self.second_cohort,
self.partition_id,
self.group1_id,
)
self.assertEqual(
cohorts.get_group_info_for_cohort(self.first_cohort),
(self.group1_id, self.partition_id),
)
self.assertEqual(
cohorts.get_group_info_for_cohort(self.second_cohort),
cohorts.get_group_info_for_cohort(self.first_cohort),
)
def test_multiple_partition_groups(self):
"""
Test that a cohort cannot be mapped to more than one partition group
"""
self._link_cohort_partition_group(
self.first_cohort,
self.partition_id,
self.group1_id,
)
with self.assertRaises(IntegrityError):
self._link_cohort_partition_group(
self.first_cohort,
self.partition_id,
self.group2_id,
)
def test_delete_cascade(self):
"""
Test that cohort -> partition group links are automatically deleted
when their parent cohort is deleted.
"""
self._link_cohort_partition_group(
self.first_cohort,
self.partition_id,
self.group1_id
)
self.assertEqual(
cohorts.get_group_info_for_cohort(self.first_cohort),
(self.group1_id, self.partition_id)
)
# delete the link
self.first_cohort.delete()
# api should return nothing at that point
self.assertEqual(
cohorts.get_group_info_for_cohort(self.first_cohort),
(None, None),
)
# link should no longer exist because of delete cascade
with self.assertRaises(CourseUserGroupPartitionGroup.DoesNotExist):
CourseUserGroupPartitionGroup.objects.get(
course_user_group_id=self.first_cohort.id
)
|
agpl-3.0
|
[
624,
199,
2925,
367,
15690,
83,
199,
624,
199,
3,
4287,
26,
3507,
29,
889,
13,
1114,
199,
646,
366,
3583,
199,
504,
1683,
492,
1240,
12,
3371,
199,
646,
2544,
63,
4399,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
697,
492,
26864,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
7393,
63,
3998,
63,
25543,
1149,
63,
2566,
57,
63,
27011,
12,
17996,
1746,
199,
199,
504,
2508,
992,
492,
5531,
1899,
2448,
12,
5531,
32512,
12,
5531,
1899,
2448,
13068,
2448,
199,
504,
2508,
492,
15690,
83,
199,
504,
2508,
2219,
14,
7546,
492,
334,
272,
7482,
63,
354,
63,
475,
63,
344,
12,
1101,
63,
1972,
63,
10403,
83,
12,
1101,
63,
1972,
63,
10403,
83,
63,
10000,
12,
272,
1849,
7222,
2927,
12,
5531,
32512,
2927,
12,
5531,
32512,
5268,
2927,
199,
9,
421,
199,
32,
2068,
480,
1490,
8268,
14,
1018,
14,
16432,
14,
1972,
63,
2634,
14,
10403,
83,
14,
8877,
531,
199,
533,
1379,
32512,
28536,
8,
1746,
304,
272,
408,
272,
1379,
5560,
370,
4107,
1566,
325,
2554,
367,
7750,
15690,
13,
2407,
10431,
83,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
32512,
28536,
12,
291,
680,
5996,
342,
267,
291,
14,
1972,
63,
498,
275,
30687,
480,
5869,
401,
298,
5869,
401,
298,
5869,
531,
339,
347,
511,
63,
10403,
63,
3270,
8,
277,
12,
1683,
63,
8877,
304,
267,
327,
2654,
15690,
267,
15690,
275,
5531,
1899,
2448,
14,
1462,
14,
981,
8,
288,
536,
628,
774,
32512,
401,
288,
2518,
63,
344,
29,
277,
14,
1972,
63,
498,
12,
288,
1572,
63,
466,
29,
6979,
1899,
2448,
14,
1439,
40,
2596,
267,
776,
267,
1683,
63,
8877,
14,
8159,
14,
479,
63,
3527,
63,
1045,
8,
288,
298,
8268,
14,
10403,
14,
3966,
401,
288,
2420,
10403,
63,
344,
582,
15690,
14,
344,
12,
298,
10403,
63,
354,
582,
15690,
14,
354,
93,
267,
776,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
22520,
3411,
15690,
267,
15690,
14,
354,
275,
298,
4665,
985,
2,
267,
15690,
14,
2117,
342,
267,
291,
14,
3334,
8,
1805,
63,
8877,
14,
3527,
9,
398,
327,
2654,
2222,
13,
10403,
1572,
267,
5531,
1899,
2448,
14,
1462,
14,
981,
8,
288,
536,
628,
774,
8632,
2448,
804,
401,
288,
2518,
63,
344,
29,
277,
14,
1972,
63,
498,
12,
288,
1572,
63,
466,
628,
5869,
2,
267,
776,
267,
291,
14,
3334,
8,
1805,
63,
8877,
14,
3527,
9,
339,
347,
511,
63,
10403,
63,
13105,
63,
2489,
8,
277,
12,
1683,
63,
8877,
304,
267,
15690,
63,
513,
275,
359,
32512,
2927,
342,
367,
485,
315,
1425,
8,
18,
1874,
267,
2222,
63,
10403,
275,
5531,
1899,
2448,
14,
1462,
14,
981,
8,
288,
536,
628,
5869,
401,
288,
2518,
63,
344,
29,
277,
14,
1972,
63,
498,
12,
288,
1572,
63,
466,
628,
5869,
2,
267,
776,
267,
922,
63,
513,
275,
359,
24594,
342,
367,
485,
315,
1425,
8,
18,
1874,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
347,
702,
63,
4368,
8,
1430,
63,
354,
63,
4511,
12,
922,
63,
513,
12,
15690,
63,
513,
304,
288,
408,
288,
1448,
1795,
706,
314,
20024,
402,
314,
1106,
15800,
1566,
367,
1924,
922,
315,
314,
2013,
769,
402,
15690,
83,
288,
408,
288,
1683,
63,
8877,
14,
8159,
14,
479,
63,
1989,
63,
5352,
779,
355,
1240,
8,
490,
298,
8268,
14,
10403,
14,
751,
12172,
435,
1566,
63,
354,
63,
4511,
12,
490,
469,
717,
298,
751,
63,
344,
582,
922,
14,
344,
12,
717,
298,
10403,
63,
344,
582,
15690,
14,
344,
12,
717,
298,
10403,
63,
354,
582,
15690,
14,
354,
12,
490,
789,
355,
776,
355,
367,
922,
315,
922,
63,
513,
367,
15690,
315,
15690,
63,
513,
288,
4794,
398,
327,
2654,
4390,
370,
15690,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
525,
2031,
751,
63,
513,
9,
267,
702,
63,
4368,
480,
3270,
401,
922,
63,
513,
12,
15690,
63,
513,
1491,
17,
566,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
5852,
4390,
687,
15690,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
2168,
2031,
751,
63,
513,
9,
267,
702,
63,
4368,
480,
10649,
401,
922,
63,
513,
12,
15690,
63,
513,
1491,
17,
566,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
14836,
4390,
687,
15690,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
525,
2031,
751,
63,
513,
9,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
3584,
342,
267,
702,
63,
4368,
480,
10649,
401,
922,
63,
513,
12,
15690,
63,
513,
1491,
17,
566,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
14836,
4390,
687,
2222,
13,
10403,
1572,
267,
2222,
63,
10403,
14,
3707,
14,
525,
2031,
751,
63,
513,
9,
267,
2222,
63,
10403,
14,
3707,
14,
3584,
342,
267,
291,
14,
3334,
8,
1805,
63,
8877,
14,
8159,
14,
3527,
9,
398,
327,
2654,
15690,
83,
370,
922,
267,
922,
63,
513,
59,
16,
1055,
1972,
63,
2634,
14,
525,
2031,
10403,
63,
513,
9,
267,
702,
63,
4368,
480,
3270,
401,
922,
63,
513,
1491,
17,
467,
15690,
63,
513,
9,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
5852,
15690,
83,
687,
922,
267,
922,
63,
513,
59,
16,
1055,
1972,
63,
2634,
14,
2168,
2031,
10403,
63,
513,
9,
267,
702,
63,
4368,
480,
10649,
401,
922,
63,
513,
1491,
17,
467,
15690,
63,
513,
9,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
14836,
15690,
83,
687,
922,
267,
922,
63,
513,
59,
16,
1055,
1972,
63,
2634,
14,
525,
2031,
10403,
63,
513,
9,
267,
922,
63
] |
[
199,
2925,
367,
15690,
83,
199,
624,
199,
3,
4287,
26,
3507,
29,
889,
13,
1114,
199,
646,
366,
3583,
199,
504,
1683,
492,
1240,
12,
3371,
199,
646,
2544,
63,
4399,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
697,
492,
26864,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
7393,
63,
3998,
63,
25543,
1149,
63,
2566,
57,
63,
27011,
12,
17996,
1746,
199,
199,
504,
2508,
992,
492,
5531,
1899,
2448,
12,
5531,
32512,
12,
5531,
1899,
2448,
13068,
2448,
199,
504,
2508,
492,
15690,
83,
199,
504,
2508,
2219,
14,
7546,
492,
334,
272,
7482,
63,
354,
63,
475,
63,
344,
12,
1101,
63,
1972,
63,
10403,
83,
12,
1101,
63,
1972,
63,
10403,
83,
63,
10000,
12,
272,
1849,
7222,
2927,
12,
5531,
32512,
2927,
12,
5531,
32512,
5268,
2927,
199,
9,
421,
199,
32,
2068,
480,
1490,
8268,
14,
1018,
14,
16432,
14,
1972,
63,
2634,
14,
10403,
83,
14,
8877,
531,
199,
533,
1379,
32512,
28536,
8,
1746,
304,
272,
408,
272,
1379,
5560,
370,
4107,
1566,
325,
2554,
367,
7750,
15690,
13,
2407,
10431,
83,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
32512,
28536,
12,
291,
680,
5996,
342,
267,
291,
14,
1972,
63,
498,
275,
30687,
480,
5869,
401,
298,
5869,
401,
298,
5869,
531,
339,
347,
511,
63,
10403,
63,
3270,
8,
277,
12,
1683,
63,
8877,
304,
267,
327,
2654,
15690,
267,
15690,
275,
5531,
1899,
2448,
14,
1462,
14,
981,
8,
288,
536,
628,
774,
32512,
401,
288,
2518,
63,
344,
29,
277,
14,
1972,
63,
498,
12,
288,
1572,
63,
466,
29,
6979,
1899,
2448,
14,
1439,
40,
2596,
267,
776,
267,
1683,
63,
8877,
14,
8159,
14,
479,
63,
3527,
63,
1045,
8,
288,
298,
8268,
14,
10403,
14,
3966,
401,
288,
2420,
10403,
63,
344,
582,
15690,
14,
344,
12,
298,
10403,
63,
354,
582,
15690,
14,
354,
93,
267,
776,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
22520,
3411,
15690,
267,
15690,
14,
354,
275,
298,
4665,
985,
2,
267,
15690,
14,
2117,
342,
267,
291,
14,
3334,
8,
1805,
63,
8877,
14,
3527,
9,
398,
327,
2654,
2222,
13,
10403,
1572,
267,
5531,
1899,
2448,
14,
1462,
14,
981,
8,
288,
536,
628,
774,
8632,
2448,
804,
401,
288,
2518,
63,
344,
29,
277,
14,
1972,
63,
498,
12,
288,
1572,
63,
466,
628,
5869,
2,
267,
776,
267,
291,
14,
3334,
8,
1805,
63,
8877,
14,
3527,
9,
339,
347,
511,
63,
10403,
63,
13105,
63,
2489,
8,
277,
12,
1683,
63,
8877,
304,
267,
15690,
63,
513,
275,
359,
32512,
2927,
342,
367,
485,
315,
1425,
8,
18,
1874,
267,
2222,
63,
10403,
275,
5531,
1899,
2448,
14,
1462,
14,
981,
8,
288,
536,
628,
5869,
401,
288,
2518,
63,
344,
29,
277,
14,
1972,
63,
498,
12,
288,
1572,
63,
466,
628,
5869,
2,
267,
776,
267,
922,
63,
513,
275,
359,
24594,
342,
367,
485,
315,
1425,
8,
18,
1874,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
347,
702,
63,
4368,
8,
1430,
63,
354,
63,
4511,
12,
922,
63,
513,
12,
15690,
63,
513,
304,
288,
408,
288,
1448,
1795,
706,
314,
20024,
402,
314,
1106,
15800,
1566,
367,
1924,
922,
315,
314,
2013,
769,
402,
15690,
83,
288,
408,
288,
1683,
63,
8877,
14,
8159,
14,
479,
63,
1989,
63,
5352,
779,
355,
1240,
8,
490,
298,
8268,
14,
10403,
14,
751,
12172,
435,
1566,
63,
354,
63,
4511,
12,
490,
469,
717,
298,
751,
63,
344,
582,
922,
14,
344,
12,
717,
298,
10403,
63,
344,
582,
15690,
14,
344,
12,
717,
298,
10403,
63,
354,
582,
15690,
14,
354,
12,
490,
789,
355,
776,
355,
367,
922,
315,
922,
63,
513,
367,
15690,
315,
15690,
63,
513,
288,
4794,
398,
327,
2654,
4390,
370,
15690,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
525,
2031,
751,
63,
513,
9,
267,
702,
63,
4368,
480,
3270,
401,
922,
63,
513,
12,
15690,
63,
513,
1491,
17,
566,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
5852,
4390,
687,
15690,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
2168,
2031,
751,
63,
513,
9,
267,
702,
63,
4368,
480,
10649,
401,
922,
63,
513,
12,
15690,
63,
513,
1491,
17,
566,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
14836,
4390,
687,
15690,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
525,
2031,
751,
63,
513,
9,
267,
15690,
63,
513,
59,
16,
1055,
3707,
14,
3584,
342,
267,
702,
63,
4368,
480,
10649,
401,
922,
63,
513,
12,
15690,
63,
513,
1491,
17,
566,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
14836,
4390,
687,
2222,
13,
10403,
1572,
267,
2222,
63,
10403,
14,
3707,
14,
525,
2031,
751,
63,
513,
9,
267,
2222,
63,
10403,
14,
3707,
14,
3584,
342,
267,
291,
14,
3334,
8,
1805,
63,
8877,
14,
8159,
14,
3527,
9,
398,
327,
2654,
15690,
83,
370,
922,
267,
922,
63,
513,
59,
16,
1055,
1972,
63,
2634,
14,
525,
2031,
10403,
63,
513,
9,
267,
702,
63,
4368,
480,
3270,
401,
922,
63,
513,
1491,
17,
467,
15690,
63,
513,
9,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
5852,
15690,
83,
687,
922,
267,
922,
63,
513,
59,
16,
1055,
1972,
63,
2634,
14,
2168,
2031,
10403,
63,
513,
9,
267,
702,
63,
4368,
480,
10649,
401,
922,
63,
513,
1491,
17,
467,
15690,
63,
513,
9,
267,
1683,
63,
8877,
14,
3958,
63,
1805,
342,
398,
327,
14836,
15690,
83,
687,
922,
267,
922,
63,
513,
59,
16,
1055,
1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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
asiersarasua/QGIS
|
python/plugins/processing/algs/grass7/ext/i_landsat_acca.py
|
12
|
1561
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
i_landsat_acca.py
-----------------
Date : March 2016
Copyright : (C) 2016 by Médéric Ribreux
Email : medspx at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Médéric Ribreux'
__date__ = 'March 2016'
__copyright__ = '(C) 2016, Médéric Ribreux'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from .i import verifyRasterNum, orderedInput
def checkParameterValuesBeforeExecuting(alg, parameters, context):
return verifyRasterNum(alg, parameters, context, 'rasters', 5, 5)
def processInputs(alg, parameters, context, feedback):
orderedInput(alg, parameters, context, 'rasters', 'input',
[2, 3, 4, 5, 61])
def processCommand(alg, parameters, context, feedback):
alg.processCommand(parameters, context, feedback)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
284,
63,
31813,
292,
63,
645,
696,
14,
647,
272,
10652,
13,
272,
6148,
463,
520,
603,
1047,
7800,
272,
1898,
3322,
520,
334,
35,
9,
7800,
701,
603,
5741,
68,
5741,
1567,
820,
1892,
264,
2521,
272,
11426,
4483,
520,
562,
68,
681,
88,
737,
562,
68,
681,
88,
6308,
9513,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
45,
5741,
68,
5741,
1567,
820,
1892,
264,
2521,
7,
199,
363,
602,
363,
275,
283,
45,
1047,
7800,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
7800,
12,
603,
5741,
68,
5741,
1567,
820,
1892,
264,
2521,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
1275,
73,
492,
4911,
13284,
5667,
12,
7741,
3205,
421,
199,
318,
1104,
4720,
6550,
13569,
4858,
4655,
8,
6731,
12,
2633,
12,
1067,
304,
272,
372,
4911,
13284,
5667,
8,
6731,
12,
2633,
12,
1067,
12,
283,
6360,
878,
297,
959,
12,
959,
9,
421,
199,
318,
2112,
15124,
8,
6731,
12,
2633,
12,
1067,
12,
17145,
304,
272,
7741,
3205,
8,
6731,
12,
2633,
12,
1067,
12,
283,
6360,
878,
297,
283,
1210,
297,
326,
359,
18,
12,
650,
12,
841,
12,
959,
12,
17017,
566,
421,
199,
318,
2112,
3110,
8,
6731,
12,
2633,
12,
1067,
12,
17145,
304,
272,
15760,
14,
1412,
3110,
8,
3214,
12,
1067,
12,
17145,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
284,
63,
31813,
292,
63,
645,
696,
14,
647,
272,
10652,
13,
272,
6148,
463,
520,
603,
1047,
7800,
272,
1898,
3322,
520,
334,
35,
9,
7800,
701,
603,
5741,
68,
5741,
1567,
820,
1892,
264,
2521,
272,
11426,
4483,
520,
562,
68,
681,
88,
737,
562,
68,
681,
88,
6308,
9513,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
45,
5741,
68,
5741,
1567,
820,
1892,
264,
2521,
7,
199,
363,
602,
363,
275,
283,
45,
1047,
7800,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
7800,
12,
603,
5741,
68,
5741,
1567,
820,
1892,
264,
2521,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
1275,
73,
492,
4911,
13284,
5667,
12,
7741,
3205,
421,
199,
318,
1104,
4720,
6550,
13569,
4858,
4655,
8,
6731,
12,
2633,
12,
1067,
304,
272,
372,
4911,
13284,
5667,
8,
6731,
12,
2633,
12,
1067,
12,
283,
6360,
878,
297,
959,
12,
959,
9,
421,
199,
318,
2112,
15124,
8,
6731,
12,
2633,
12,
1067,
12,
17145,
304,
272,
7741,
3205,
8,
6731,
12,
2633,
12,
1067,
12,
283,
6360,
878,
297,
283,
1210,
297,
326,
359,
18,
12,
650,
12,
841,
12,
959,
12,
17017,
566,
421,
199,
318,
2112,
3110,
8,
6731,
12,
2633,
12,
1067,
12,
17145,
304,
272,
15760,
14,
1412,
3110,
8,
3214,
12,
1067,
12,
17145,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
m2candre/ansible-modules-extras
|
system/gluster_volume.py
|
76
|
14777
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Taneli Leppä <taneli@crasman.fi>
#
# This file is part of Ansible (sort of)
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = """
module: gluster_volume
short_description: Manage GlusterFS volumes
description:
- Create, remove, start, stop and tune GlusterFS volumes
version_added: "1.9"
options:
name:
required: true
description:
- The volume name
state:
required: true
choices: [ 'present', 'absent', 'started', 'stopped' ]
description:
- Use present/absent ensure if a volume exists or not,
use started/stopped to control it's availability.
cluster:
required: false
default: null
description:
- List of hosts to use for probing and brick setup
host:
required: false
default: null
description:
- Override local hostname (for peer probing purposes)
replicas:
required: false
default: null
description:
- Replica count for volume
stripes:
required: false
default: null
description:
- Stripe count for volume
transport:
required: false
choices: [ 'tcp', 'rdma', 'tcp,rdma' ]
default: 'tcp'
description:
- Transport type for volume
bricks:
required: false
default: null
description:
- Brick paths on servers. Multiple brick paths can be separated by commas
aliases: ['brick']
start_on_create:
choices: [ 'yes', 'no']
required: false
description:
- Controls whether the volume is started after creation or not, defaults to yes
rebalance:
choices: [ 'yes', 'no']
required: false
default: 'no'
description:
- Controls whether the cluster is rebalanced after changes
directory:
required: false
default: null
description:
- Directory for limit-usage
options:
required: false
default: null
description:
- A dictionary/hash with options/settings for the volume
quota:
required: false
default: null
description:
- Quota value for limit-usage (be sure to use 10.0MB instead of 10MB, see quota list)
force:
required: false
default: null
description:
- If brick is being created in the root partition, module will fail.
Set force to true to override this behaviour
notes:
- "Requires cli tools for GlusterFS on servers"
- "Will add new bricks, but not remove them"
author: "Taneli Leppä (@rosmo)"
"""
EXAMPLES = """
- name: create gluster volume
gluster_volume: state=present name=test1 bricks=/bricks/brick1/g1 rebalance=yes cluster="192.168.1.10,192.168.1.11"
run_once: true
- name: tune
gluster_volume: state=present name=test1 options='{performance.cache-size: 256MB}'
- name: start gluster volume
gluster_volume: state=started name=test1
- name: limit usage
gluster_volume: state=present name=test1 directory=/foo quota=20.0MB
- name: stop gluster volume
gluster_volume: state=stopped name=test1
- name: remove gluster volume
gluster_volume: state=absent name=test1
- name: create gluster volume with multiple bricks
gluster_volume: state=present name=test2 bricks="/bricks/brick1/g2,/bricks/brick2/g2" cluster="192.168.1.10,192.168.1.11"
run_once: true
"""
import shutil
import time
import socket
glusterbin = ''
def run_gluster(gargs, **kwargs):
global glusterbin
global module
args = [glusterbin]
args.extend(gargs)
try:
rc, out, err = module.run_command(args, **kwargs)
if rc != 0:
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out or err))
except Exception, e:
module.fail_json(msg='error running gluster (%s) command: %s' % (' '.join(args), str(e)))
return out
def run_gluster_nofail(gargs, **kwargs):
global glusterbin
global module
args = [glusterbin]
args.extend(gargs)
rc, out, err = module.run_command(args, **kwargs)
if rc != 0:
return None
return out
def run_gluster_yes(gargs):
global glusterbin
global module
args = [glusterbin]
args.extend(gargs)
rc, out, err = module.run_command(args, data='y\n')
if rc != 0:
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out or err))
return out
def get_peers():
out = run_gluster([ 'peer', 'status'])
i = 0
peers = {}
hostname = None
uuid = None
state = None
for row in out.split('\n'):
if ': ' in row:
key, value = row.split(': ')
if key.lower() == 'hostname':
hostname = value
if key.lower() == 'uuid':
uuid = value
if key.lower() == 'state':
state = value
peers[hostname] = [ uuid, state ]
return peers
def get_volumes():
out = run_gluster([ 'volume', 'info' ])
volumes = {}
volume = {}
for row in out.split('\n'):
if ': ' in row:
key, value = row.split(': ')
if key.lower() == 'volume name':
volume['name'] = value
volume['options'] = {}
volume['quota'] = False
if key.lower() == 'volume id':
volume['id'] = value
if key.lower() == 'status':
volume['status'] = value
if key.lower() == 'transport-type':
volume['transport'] = value
if key.lower() != 'bricks' and key.lower()[:5] == 'brick':
if not 'bricks' in volume:
volume['bricks'] = []
volume['bricks'].append(value)
# Volume options
if '.' in key:
if not 'options' in volume:
volume['options'] = {}
volume['options'][key] = value
if key == 'features.quota' and value == 'on':
volume['quota'] = True
else:
if row.lower() != 'bricks:' and row.lower() != 'options reconfigured:':
if len(volume) > 0:
volumes[volume['name']] = volume
volume = {}
return volumes
def get_quotas(name, nofail):
quotas = {}
if nofail:
out = run_gluster_nofail([ 'volume', 'quota', name, 'list' ])
if not out:
return quotas
else:
out = run_gluster([ 'volume', 'quota', name, 'list' ])
for row in out.split('\n'):
if row[:1] == '/':
q = re.split('\s+', row)
quotas[q[0]] = q[1]
return quotas
def wait_for_peer(host):
for x in range(0, 4):
peers = get_peers()
if host in peers and peers[host][1].lower().find('peer in cluster') != -1:
return True
time.sleep(1)
return False
def probe(host, myhostname):
global module
run_gluster([ 'peer', 'probe', host ])
if not wait_for_peer(host):
module.fail_json(msg='failed to probe peer %s on %s' % (host, myhostname))
changed = True
def probe_all_peers(hosts, peers, myhostname):
for host in hosts:
host = host.strip() # Clean up any extra space for exact comparison
if host not in peers:
# dont probe ourselves
if myhostname != host:
probe(host, myhostname)
def create_volume(name, stripe, replica, transport, hosts, bricks, force):
args = [ 'volume', 'create' ]
args.append(name)
if stripe:
args.append('stripe')
args.append(str(stripe))
if replica:
args.append('replica')
args.append(str(replica))
args.append('transport')
args.append(transport)
for brick in bricks:
for host in hosts:
args.append(('%s:%s' % (host, brick)))
if force:
args.append('force')
run_gluster(args)
def start_volume(name):
run_gluster([ 'volume', 'start', name ])
def stop_volume(name):
run_gluster_yes([ 'volume', 'stop', name ])
def set_volume_option(name, option, parameter):
run_gluster([ 'volume', 'set', name, option, parameter ])
def add_brick(name, brick, force):
args = [ 'volume', 'add-brick', name, brick ]
if force:
args.append('force')
run_gluster(args)
def do_rebalance(name):
run_gluster([ 'volume', 'rebalance', name, 'start' ])
def enable_quota(name):
run_gluster([ 'volume', 'quota', name, 'enable' ])
def set_quota(name, directory, value):
run_gluster([ 'volume', 'quota', name, 'limit-usage', directory, value ])
def main():
### MAIN ###
global module
module = AnsibleModule(
argument_spec=dict(
name=dict(required=True, default=None, aliases=['volume']),
state=dict(required=True, choices=[ 'present', 'absent', 'started', 'stopped', 'rebalanced' ]),
cluster=dict(required=False, default=None, type='list'),
host=dict(required=False, default=None),
stripes=dict(required=False, default=None, type='int'),
replicas=dict(required=False, default=None, type='int'),
transport=dict(required=False, default='tcp', choices=[ 'tcp', 'rdma', 'tcp,rdma' ]),
bricks=dict(required=False, default=None, aliases=['brick']),
start_on_create=dict(required=False, default=True, type='bool'),
rebalance=dict(required=False, default=False, type='bool'),
options=dict(required=False, default={}, type='dict'),
quota=dict(required=False),
directory=dict(required=False, default=None),
force=dict(required=False, default=False, type='bool'),
)
)
global glusterbin
glusterbin = module.get_bin_path('gluster', True)
changed = False
action = module.params['state']
volume_name = module.params['name']
cluster= module.params['cluster']
brick_paths = module.params['bricks']
stripes = module.params['stripes']
replicas = module.params['replicas']
transport = module.params['transport']
myhostname = module.params['host']
start_on_create = module.boolean(module.params['start_on_create'])
rebalance = module.boolean(module.params['rebalance'])
force = module.boolean(module.params['force'])
if not myhostname:
myhostname = socket.gethostname()
# Clean up if last element is empty. Consider that yml can look like this:
# cluster="{% for host in groups['glusterfs'] %}{{ hostvars[host]['private_ip'] }},{% endfor %}"
if cluster != None and cluster[-1] == '':
cluster = cluster[0:-1]
if brick_paths != None and "," in brick_paths:
brick_paths = brick_paths.split(",")
else:
brick_paths = [brick_paths]
options = module.params['options']
quota = module.params['quota']
directory = module.params['directory']
# get current state info
peers = get_peers()
volumes = get_volumes()
quotas = {}
if volume_name in volumes and volumes[volume_name]['quota'] and volumes[volume_name]['status'].lower() == 'started':
quotas = get_quotas(volume_name, True)
# do the work!
if action == 'absent':
if volume_name in volumes:
if volumes[volume_name]['status'].lower() != 'stopped':
stop_volume(volume_name)
run_gluster_yes([ 'volume', 'delete', volume_name ])
changed = True
if action == 'present':
probe_all_peers(cluster, peers, myhostname)
# create if it doesn't exist
if volume_name not in volumes:
create_volume(volume_name, stripes, replicas, transport, cluster, brick_paths, force)
volumes = get_volumes()
changed = True
if volume_name in volumes:
if volumes[volume_name]['status'].lower() != 'started' and start_on_create:
start_volume(volume_name)
changed = True
# switch bricks
new_bricks = []
removed_bricks = []
all_bricks = []
for node in cluster:
for brick_path in brick_paths:
brick = '%s:%s' % (node, brick_path)
all_bricks.append(brick)
if brick not in volumes[volume_name]['bricks']:
new_bricks.append(brick)
# this module does not yet remove bricks, but we check those anyways
for brick in volumes[volume_name]['bricks']:
if brick not in all_bricks:
removed_bricks.append(brick)
for brick in new_bricks:
add_brick(volume_name, brick, force)
changed = True
# handle quotas
if quota:
if not volumes[volume_name]['quota']:
enable_quota(volume_name)
quotas = get_quotas(volume_name, False)
if directory not in quotas or quotas[directory] != quota:
set_quota(volume_name, directory, quota)
changed = True
# set options
for option in options.keys():
if option not in volumes[volume_name]['options'] or volumes[volume_name]['options'][option] != options[option]:
set_volume_option(volume_name, option, options[option])
changed = True
else:
module.fail_json(msg='failed to create volume %s' % volume_name)
if volume_name not in volumes:
module.fail_json(msg='volume not found %s' % volume_name)
if action == 'started':
if volumes[volume_name]['status'].lower() != 'started':
start_volume(volume_name)
changed = True
if action == 'stopped':
if volumes[volume_name]['status'].lower() != 'stopped':
stop_volume(volume_name)
changed = True
if changed:
volumes = get_volumes()
if rebalance:
do_rebalance(volume_name)
facts = {}
facts['glusterfs'] = { 'peers': peers, 'volumes': volumes, 'quotas': quotas }
module.exit_json(changed=changed, ansible_facts=facts)
# import module snippets
from ansible.module_utils.basic import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6927,
12,
377,
5865,
317,
7005,
802,
13733,
665,
84,
5865,
317,
32,
1556,
305,
1237,
14,
329,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
334,
3191,
402,
9,
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,
421,
199,
8948,
275,
408,
199,
578,
26,
6482,
2413,
63,
2405,
199,
3612,
63,
1802,
26,
14944,
598,
76,
2413,
7079,
12158,
199,
1802,
26,
523,
446,
2790,
12,
2813,
12,
1343,
12,
3631,
436,
307,
11474,
598,
76,
2413,
7079,
12158,
199,
1023,
63,
3270,
26,
298,
17,
14,
25,
2,
199,
1419,
26,
523,
536,
26,
272,
1415,
26,
2549,
272,
1369,
26,
489,
446,
710,
3301,
536,
523,
1174,
26,
272,
1415,
26,
2549,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
297,
283,
8924,
297,
283,
14661,
7,
1622,
272,
1369,
26,
489,
446,
3645,
3451,
15,
5575,
4868,
340,
282,
3301,
3495,
503,
440,
12,
267,
675,
8239,
15,
14661,
370,
3304,
652,
1159,
14962,
14,
523,
4350,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
3820,
402,
7057,
370,
675,
367,
5128,
316,
436,
20611,
346,
3272,
523,
1591,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
11041,
2257,
6246,
334,
509,
9104,
5128,
316,
12901,
9,
523,
22413,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
16000,
7518,
2338,
367,
3301,
523,
4024,
22020,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
31309,
321,
2338,
367,
3301,
523,
7773,
26,
272,
1415,
26,
3055,
272,
3415,
26,
359,
283,
8815,
297,
283,
6883,
391,
297,
283,
8815,
12,
6883,
391,
7,
1622,
272,
849,
26,
283,
8815,
7,
272,
1369,
26,
489,
446,
27018,
730,
367,
3301,
523,
20611,
5618,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
699,
27091,
3792,
641,
8037,
14,
14326,
20611,
346,
3792,
883,
506,
11673,
701,
24476,
272,
5481,
26,
788,
29541,
418,
523,
1343,
63,
265,
63,
981,
26,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
418,
272,
1415,
26,
3055,
272,
1369,
26,
489,
446,
29001,
3775,
314,
3301,
365,
8239,
2410,
7143,
503,
440,
12,
4243,
370,
9456,
523,
295,
7358,
26,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
418,
272,
1415,
26,
3055,
272,
849,
26,
283,
889,
7,
272,
1369,
26,
489,
446,
29001,
3775,
314,
4350,
365,
295,
18923,
2410,
4493,
523,
2082,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
15191,
367,
2304,
13,
3807,
523,
1511,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
437,
2600,
15,
2227,
543,
1511,
15,
1751,
367,
314,
3301,
523,
12132,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
5843,
12041,
574,
367,
2304,
13,
3807,
334,
1235,
3238,
370,
675,
1616,
14,
16,
4567,
3140,
402,
1616,
4567,
12,
1937,
12132,
769,
9,
523,
3542,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
982,
20611,
346,
365,
3769,
2737,
315,
314,
1738,
6484,
12,
859,
911,
2449,
14,
267,
2494,
3542,
370,
2549,
370,
4278,
642,
13942,
199,
5983,
26,
523,
446,
298,
18153,
5053,
7249,
367,
598,
76,
2413,
7079,
641,
8037,
2,
523,
446,
298,
20326,
1050,
892,
20611,
5618,
12,
1325,
440,
2813,
3062,
2,
199,
2502,
26,
298,
52,
5865,
317,
7005,
802,
13733,
8593,
4796,
573,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1218,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
17,
20611,
5618,
13043,
30855,
15,
29541,
17,
15,
71,
17,
295,
7358,
29,
5066,
4350,
628,
5756,
14,
6568,
14,
17,
14,
709,
12,
5756,
14,
6568,
14,
17,
14,
845,
2,
523,
1255,
63,
5089,
26,
2549,
199,
199,
13,
536,
26,
307,
11474,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
17,
1511,
32134,
20576,
14,
1637,
13,
890,
26,
7633,
4567,
6834,
199,
199,
13,
536,
26,
1343,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
8924,
536,
29,
396,
17,
199,
199,
13,
536,
26,
2304,
4503,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
17,
2082,
13043,
1421,
12132,
29,
1165,
14,
16,
4567,
199,
199,
13,
536,
26,
3631,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
14661,
536,
29,
396,
17,
199,
199,
13,
536,
26,
2813,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
5575,
536,
29,
396,
17,
199,
199,
13,
536,
26,
1218,
6482,
2413,
3301,
543,
3663,
20611,
5618,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
18,
20611,
5618,
9555,
30855,
15,
29541,
17,
15,
71,
18,
12,
15,
30855,
15,
29541,
18,
15,
71,
18,
2,
4350,
628,
5756,
14,
6568,
14,
17,
14,
709,
12,
5756,
14,
6568,
14,
17,
14,
845,
2,
523,
1255,
63,
5089,
26,
2549,
199,
624,
199,
199,
646,
5145,
199,
646,
900,
199
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6927,
12,
377,
5865,
317,
7005,
802,
13733,
665,
84,
5865,
317,
32,
1556,
305,
1237,
14,
329,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
334,
3191,
402,
9,
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,
421,
199,
8948,
275,
408,
199,
578,
26,
6482,
2413,
63,
2405,
199,
3612,
63,
1802,
26,
14944,
598,
76,
2413,
7079,
12158,
199,
1802,
26,
523,
446,
2790,
12,
2813,
12,
1343,
12,
3631,
436,
307,
11474,
598,
76,
2413,
7079,
12158,
199,
1023,
63,
3270,
26,
298,
17,
14,
25,
2,
199,
1419,
26,
523,
536,
26,
272,
1415,
26,
2549,
272,
1369,
26,
489,
446,
710,
3301,
536,
523,
1174,
26,
272,
1415,
26,
2549,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
297,
283,
8924,
297,
283,
14661,
7,
1622,
272,
1369,
26,
489,
446,
3645,
3451,
15,
5575,
4868,
340,
282,
3301,
3495,
503,
440,
12,
267,
675,
8239,
15,
14661,
370,
3304,
652,
1159,
14962,
14,
523,
4350,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
3820,
402,
7057,
370,
675,
367,
5128,
316,
436,
20611,
346,
3272,
523,
1591,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
11041,
2257,
6246,
334,
509,
9104,
5128,
316,
12901,
9,
523,
22413,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
16000,
7518,
2338,
367,
3301,
523,
4024,
22020,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
31309,
321,
2338,
367,
3301,
523,
7773,
26,
272,
1415,
26,
3055,
272,
3415,
26,
359,
283,
8815,
297,
283,
6883,
391,
297,
283,
8815,
12,
6883,
391,
7,
1622,
272,
849,
26,
283,
8815,
7,
272,
1369,
26,
489,
446,
27018,
730,
367,
3301,
523,
20611,
5618,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
699,
27091,
3792,
641,
8037,
14,
14326,
20611,
346,
3792,
883,
506,
11673,
701,
24476,
272,
5481,
26,
788,
29541,
418,
523,
1343,
63,
265,
63,
981,
26,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
418,
272,
1415,
26,
3055,
272,
1369,
26,
489,
446,
29001,
3775,
314,
3301,
365,
8239,
2410,
7143,
503,
440,
12,
4243,
370,
9456,
523,
295,
7358,
26,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
418,
272,
1415,
26,
3055,
272,
849,
26,
283,
889,
7,
272,
1369,
26,
489,
446,
29001,
3775,
314,
4350,
365,
295,
18923,
2410,
4493,
523,
2082,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
15191,
367,
2304,
13,
3807,
523,
1511,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
437,
2600,
15,
2227,
543,
1511,
15,
1751,
367,
314,
3301,
523,
12132,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
5843,
12041,
574,
367,
2304,
13,
3807,
334,
1235,
3238,
370,
675,
1616,
14,
16,
4567,
3140,
402,
1616,
4567,
12,
1937,
12132,
769,
9,
523,
3542,
26,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
982,
20611,
346,
365,
3769,
2737,
315,
314,
1738,
6484,
12,
859,
911,
2449,
14,
267,
2494,
3542,
370,
2549,
370,
4278,
642,
13942,
199,
5983,
26,
523,
446,
298,
18153,
5053,
7249,
367,
598,
76,
2413,
7079,
641,
8037,
2,
523,
446,
298,
20326,
1050,
892,
20611,
5618,
12,
1325,
440,
2813,
3062,
2,
199,
2502,
26,
298,
52,
5865,
317,
7005,
802,
13733,
8593,
4796,
573,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1218,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
17,
20611,
5618,
13043,
30855,
15,
29541,
17,
15,
71,
17,
295,
7358,
29,
5066,
4350,
628,
5756,
14,
6568,
14,
17,
14,
709,
12,
5756,
14,
6568,
14,
17,
14,
845,
2,
523,
1255,
63,
5089,
26,
2549,
199,
199,
13,
536,
26,
307,
11474,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
17,
1511,
32134,
20576,
14,
1637,
13,
890,
26,
7633,
4567,
6834,
199,
199,
13,
536,
26,
1343,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
8924,
536,
29,
396,
17,
199,
199,
13,
536,
26,
2304,
4503,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
17,
2082,
13043,
1421,
12132,
29,
1165,
14,
16,
4567,
199,
199,
13,
536,
26,
3631,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
14661,
536,
29,
396,
17,
199,
199,
13,
536,
26,
2813,
6482,
2413,
3301,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
5575,
536,
29,
396,
17,
199,
199,
13,
536,
26,
1218,
6482,
2413,
3301,
543,
3663,
20611,
5618,
523,
6482,
2413,
63,
2405,
26,
1174,
29,
1881,
536,
29,
396,
18,
20611,
5618,
9555,
30855,
15,
29541,
17,
15,
71,
18,
12,
15,
30855,
15,
29541,
18,
15,
71,
18,
2,
4350,
628,
5756,
14,
6568,
14,
17,
14,
709,
12,
5756,
14,
6568,
14,
17,
14,
845,
2,
523,
1255,
63,
5089,
26,
2549,
199,
624,
199,
199,
646,
5145,
199,
646,
900,
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,
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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
] |
pakesson/rednotebook
|
rednotebook/gui/clouds.py
|
1
|
8443
|
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------
# Copyright (c) 2009 Jendrik Seipp
#
# RedNotebook 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.
#
# RedNotebook 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 RedNotebook; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# -----------------------------------------------------------------------
from __future__ import division
import logging
import gtk
from rednotebook.gui.browser import HtmlView
from rednotebook.util import unicode
def word_count_dict_to_html(word_count_dict, type, ignore_list, include_list):
logging.debug('Turning the word_count_dict into html')
logging.debug('Length word_count_dict: %s' % len(word_count_dict))
sorted_dict = sorted(word_count_dict.items(), key=lambda (word, freq): freq)
if type == 'word':
# filter short words
include_list = map(lambda word: word.lower(), include_list)
get_long_words = lambda (word, freq): len(word) > 4 or word.lower() in include_list
sorted_dict = filter(get_long_words, sorted_dict)
logging.debug('Filtered short words. Length word_count_dict: %s' % len(sorted_dict))
# filter words in ignore_list
sorted_dict = filter(lambda (word, freq): word.lower() not in ignore_list, sorted_dict)
logging.debug('Filtered blacklist words. Length word_count_dict: %s' % len(sorted_dict))
often_used_words = []
number_of_words = 42
'''
only take the longest words. If there are less words than n,
len(sorted_dict) words are returned
'''
cloud_words = sorted_dict[-number_of_words:]
logging.debug('Selected most frequent words. Length CloudWords: %s' % len(cloud_words))
if len(cloud_words) < 1:
return [], ''
min_count = cloud_words[0][1]
max_count = cloud_words[-1][1]
logging.debug('Min word count: %s, Max word count: %s' % (min_count, max_count))
delta_count = max_count - min_count
if delta_count == 0:
delta_count = 1
min_font_size = 10
max_font_size = 50
font_delta = max_font_size - min_font_size
# sort words with unicode sort function
cloud_words.sort(key=lambda (word, count): unicode.coll(word))
logging.debug('Sorted cloud words. Length CloudWords: %s' % len(cloud_words))
html_elements = []
css = '''\
<style type="text/css">
body {
font-family: sans-serif;
text-align: center;
}
a:link { color:black; text-decoration:none; }
a:visited { color:black; text-decoration:none; }
a:focus { color:black; text-decoration:none; }
a:hover { color:black; text-decoration:none; }
a:active { color:black; text-decoration:none; }
</style>'''
for index, (word, count) in enumerate(cloud_words):
font_factor = (count - min_count) / delta_count
font_size = int(min_font_size + font_factor * font_delta)
html_elements.append('<a href="search/%s">'
'<span style="font-size:%spx">%s</span></a>'
% (index, font_size, word) +
#Add some whitespace
' ')
#random.shuffle(html_elements)
html_body = '<body>' + '\n'.join(html_elements) + '\n</body>\n'
html_doc = '<html><head>' + css + '</head>' + html_body + '</html>'
return (cloud_words, html_doc)
class Cloud(HtmlView):
def __init__(self, journal):
HtmlView.__init__(self)
self.journal = journal
self.update_lists()
self.webview.connect("hovering-over-link", self.on_hovering_over_link)
self.webview.connect('populate-popup', self.on_populate_popup)
self.set_type(0, init=True)
self.last_hovered_word = None
def set_type(self, type_int, init=False):
self.type_int = type_int
self.type = ['word', 'category', 'tag'][type_int]
if not init:
self.update(force_update=True)
def update_lists(self):
config = self.journal.config
default_ignore_list = _('filter, these, comma, separated, words')
self.ignore_list = config.read_list('cloudIgnoreList', default_ignore_list)
self.ignore_list = map(lambda word: word.lower(), self.ignore_list)
logging.info('Cloud ignore list: %s' % self.ignore_list)
default_include_list = _('mtv, spam, work, job, play')
self.include_list = config.read_list('cloudIncludeList', default_include_list)
self.include_list = map(lambda word: word.lower(), self.include_list)
logging.info('Cloud include list: %s' % self.include_list)
def update(self, force_update=False):
if self.journal.frame is None:
return
logging.debug('Update the cloud (Type: %s, Force: %s)' % (self.type, force_update))
# Do not update the cloud with words as it requires a lot of searching
if self.type == 'word' and not force_update:
return
self.journal.save_old_day()
word_count_dict = self.journal.get_word_count_dict(self.type)
logging.debug('Retrieved WordCountDict. Length: %s' % len(word_count_dict))
self.tag_cloud_words, html = word_count_dict_to_html(word_count_dict,
self.type, self.ignore_list, self.include_list)
logging.debug('%s cloud words found' % len(self.tag_cloud_words))
self.load_html(html)
self.last_hovered_word = None
logging.debug('Cloud updated')
def on_navigate(self, webview, frame, request):
'''
Called when user clicks on a cloud word
'''
if self.loading_html:
# Keep processing
return False
uri = request.get_uri()
logging.info('Clicked URI "%s"' % uri)
self.journal.save_old_day()
# uri has the form "something/somewhere/search/search_index"
if 'search' in uri:
# search_index is the part after last slash
search_index = int(uri.split('/')[-1])
search_text, count = self.tag_cloud_words[search_index]
self.journal.frame.search_type_box.set_active(self.type_int)
self.journal.frame.search_box.set_active_text(search_text)
self.journal.frame.search_notebook.set_current_page(0)
# returning True here stops loading the document
return True
def on_button_press(self, webview, event):
'''
Here we want the context menus
'''
# keep processing
return False
def on_hovering_over_link(self, webview, title, uri):
'''
We want to save the last hovered link to be able to add it
to the context menu when the user right-clicks the next time
'''
if uri:
search_index = int(uri.split('/')[-1])
search_text, count = self.tag_cloud_words[search_index]
self.last_hovered_word = search_text
def on_populate_popup(self, webview, menu):
'''
Called when the cloud's popup menu is created
'''
# remove normal menu items
children = menu.get_children()
for child in children:
menu.remove(child)
if self.last_hovered_word:
label = _('Hide "%s" from clouds') % self.last_hovered_word
ignore_menu_item = gtk.MenuItem(label)
ignore_menu_item.show()
menu.prepend(ignore_menu_item)
ignore_menu_item.connect('activate', self.on_ignore_menu_activate, self.last_hovered_word)
def on_ignore_menu_activate(self, menu_item, selected_word):
logging.info('"%s" will be hidden from clouds' % selected_word)
self.ignore_list.append(selected_word)
self.journal.config.write_list('cloudIgnoreList', self.ignore_list)
self.update(force_update=True)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
5620,
12797,
199,
3,
1898,
334,
67,
9,
8937,
221,
1603,
500,
25844,
3240,
31112,
199,
3,
199,
3,
9572,
20114,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
9572,
20114,
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,
3180,
199,
3,
543,
9572,
20114,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
5620,
12797,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2050,
199,
199,
646,
8116,
199,
199,
504,
8992,
19174,
14,
5885,
14,
5750,
492,
20880,
2768,
199,
504,
8992,
19174,
14,
1974,
492,
2649,
421,
199,
318,
4349,
63,
835,
63,
807,
63,
475,
63,
1360,
8,
1027,
63,
835,
63,
807,
12,
730,
12,
3686,
63,
513,
12,
2387,
63,
513,
304,
272,
2050,
14,
1757,
360,
16838,
316,
314,
4349,
63,
835,
63,
807,
1901,
3517,
358,
272,
2050,
14,
1757,
360,
4625,
4349,
63,
835,
63,
807,
26,
450,
83,
7,
450,
822,
8,
1027,
63,
835,
63,
807,
430,
339,
3355,
63,
807,
275,
3355,
8,
1027,
63,
835,
63,
807,
14,
1744,
1062,
790,
29,
2734,
334,
1027,
12,
9220,
304,
9220,
9,
339,
340,
730,
508,
283,
1027,
356,
267,
327,
2457,
3974,
5932,
267,
2387,
63,
513,
275,
2341,
8,
2734,
4349,
26,
4349,
14,
2325,
1062,
2387,
63,
513,
9,
267,
664,
63,
2809,
63,
3148,
275,
2400,
334,
1027,
12,
9220,
304,
822,
8,
1027,
9,
690,
841,
503,
4349,
14,
2325,
342,
315,
2387,
63,
513,
267,
3355,
63,
807,
275,
2457,
8,
362,
63,
2809,
63,
3148,
12,
3355,
63,
807,
9,
267,
2050,
14,
1757,
360,
13079,
3014,
3974,
5932,
14,
19893,
4349,
63,
835,
63,
807,
26,
450,
83,
7,
450,
822,
8,
5917,
63,
807,
430,
339,
327,
2457,
5932,
315,
3686,
63,
513,
272,
3355,
63,
807,
275,
2457,
8,
2734,
334,
1027,
12,
9220,
304,
4349,
14,
2325,
342,
440,
315,
3686,
63,
513,
12,
3355,
63,
807,
9,
272,
2050,
14,
1757,
360,
13079,
3014,
23180,
5932,
14,
19893,
4349,
63,
835,
63,
807,
26,
450,
83,
7,
450,
822,
8,
5917,
63,
807,
430,
339,
14115,
63,
2972,
63,
3148,
275,
942,
272,
1329,
63,
1618,
63,
3148,
275,
5685,
339,
1449,
272,
1454,
5452,
314,
21303,
5932,
14,
982,
2337,
787,
6656,
5932,
2419,
302,
12,
272,
822,
8,
5917,
63,
807,
9,
5932,
787,
2138,
272,
1449,
272,
8002,
63,
3148,
275,
3355,
63,
807,
1988,
1955,
63,
1618,
63,
3148,
2938,
272,
2050,
14,
1757,
360,
12461,
4750,
28914,
5932,
14,
19893,
8142,
23759,
26,
450,
83,
7,
450,
822,
8,
4091,
63,
3148,
430,
339,
340,
822,
8,
4091,
63,
3148,
9,
665,
413,
26,
267,
372,
990,
2125,
339,
1748,
63,
835,
275,
8002,
63,
3148,
59,
16,
1527,
17,
61,
272,
1390,
63,
835,
275,
8002,
63,
3148,
1988,
17,
1527,
17,
61,
339,
2050,
14,
1757,
360,
4649,
4349,
2338,
26,
450,
83,
12,
8228,
4349,
2338,
26,
450,
83,
7,
450,
334,
827,
63,
835,
12,
1390,
63,
835,
430,
339,
5762,
63,
835,
275,
1390,
63,
835,
446,
1748,
63,
835,
272,
340,
5762,
63,
835,
508,
378,
26,
267,
5762,
63,
835,
275,
413,
339,
1748,
63,
4246,
63,
890,
275,
1616,
272,
1390,
63,
4246,
63,
890,
275,
5238,
339,
5023,
63,
3136,
275,
1390,
63,
4246,
63,
890,
446,
1748,
63,
4246,
63,
890,
339,
327,
4069,
5932,
543,
2649,
4069,
805,
272,
8002,
63,
3148,
14,
3191,
8,
498,
29,
2734,
334,
1027,
12,
2338,
304,
2649,
14,
15772,
8,
1027,
430,
339,
2050,
14,
1757,
360,
22861,
8002,
5932,
14,
19893,
8142,
23759,
26,
450,
83,
7,
450,
822,
8,
4091,
63,
3148,
430,
339,
3517,
63,
5527,
275,
942,
2378,
11431,
275,
18087,
272,
665,
2487,
730,
628,
505,
15,
3919,
1743,
267,
2396,
469,
288,
5023,
13,
6606,
26,
308,
796,
13,
24977,
27,
288,
1318,
13,
5743,
26,
8126,
27,
267,
789,
267,
282,
26,
1073,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
21736,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
12283,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
22797,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
2682,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
272,
3068,
2487,
26934,
339,
367,
1478,
12,
334,
1027,
12,
2338,
9,
315,
3874,
8,
4091,
63,
3148,
304,
267,
5023,
63,
4778,
275,
334,
835,
446,
1748,
63,
835,
9,
1182,
5762,
63,
835,
267,
5023,
63,
890,
275,
1109,
8,
827,
63,
4246,
63,
890,
435,
5023,
63,
4778,
627,
5023,
63,
3136,
9,
398,
3517,
63,
5527,
14,
740,
4827,
65,
4369,
628,
1733,
3149,
83,
15603,
1169,
2650,
3751,
3449,
628,
4246,
13,
890,
2689,
681,
88,
14423,
83,
1108,
3751,
2957,
65,
3524,
1169,
450,
334,
1080,
12,
5023,
63,
890,
12,
4349,
9,
435,
1169,
327,
1123,
2005,
8139,
1169,
7673,
3,
7471,
16,
10784,
339,
327,
2355,
14,
11777,
8,
1360,
63,
5527,
9,
339,
3517,
63,
2030,
275,
2650,
2030,
3524,
435,
1557,
78,
1370,
904,
8,
1360,
63,
5527,
9,
435,
1557,
78,
1108,
2030,
3072,
78
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
5620,
12797,
199,
3,
1898,
334,
67,
9,
8937,
221,
1603,
500,
25844,
3240,
31112,
199,
3,
199,
3,
9572,
20114,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
9572,
20114,
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,
3180,
199,
3,
543,
9572,
20114,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
5620,
12797,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2050,
199,
199,
646,
8116,
199,
199,
504,
8992,
19174,
14,
5885,
14,
5750,
492,
20880,
2768,
199,
504,
8992,
19174,
14,
1974,
492,
2649,
421,
199,
318,
4349,
63,
835,
63,
807,
63,
475,
63,
1360,
8,
1027,
63,
835,
63,
807,
12,
730,
12,
3686,
63,
513,
12,
2387,
63,
513,
304,
272,
2050,
14,
1757,
360,
16838,
316,
314,
4349,
63,
835,
63,
807,
1901,
3517,
358,
272,
2050,
14,
1757,
360,
4625,
4349,
63,
835,
63,
807,
26,
450,
83,
7,
450,
822,
8,
1027,
63,
835,
63,
807,
430,
339,
3355,
63,
807,
275,
3355,
8,
1027,
63,
835,
63,
807,
14,
1744,
1062,
790,
29,
2734,
334,
1027,
12,
9220,
304,
9220,
9,
339,
340,
730,
508,
283,
1027,
356,
267,
327,
2457,
3974,
5932,
267,
2387,
63,
513,
275,
2341,
8,
2734,
4349,
26,
4349,
14,
2325,
1062,
2387,
63,
513,
9,
267,
664,
63,
2809,
63,
3148,
275,
2400,
334,
1027,
12,
9220,
304,
822,
8,
1027,
9,
690,
841,
503,
4349,
14,
2325,
342,
315,
2387,
63,
513,
267,
3355,
63,
807,
275,
2457,
8,
362,
63,
2809,
63,
3148,
12,
3355,
63,
807,
9,
267,
2050,
14,
1757,
360,
13079,
3014,
3974,
5932,
14,
19893,
4349,
63,
835,
63,
807,
26,
450,
83,
7,
450,
822,
8,
5917,
63,
807,
430,
339,
327,
2457,
5932,
315,
3686,
63,
513,
272,
3355,
63,
807,
275,
2457,
8,
2734,
334,
1027,
12,
9220,
304,
4349,
14,
2325,
342,
440,
315,
3686,
63,
513,
12,
3355,
63,
807,
9,
272,
2050,
14,
1757,
360,
13079,
3014,
23180,
5932,
14,
19893,
4349,
63,
835,
63,
807,
26,
450,
83,
7,
450,
822,
8,
5917,
63,
807,
430,
339,
14115,
63,
2972,
63,
3148,
275,
942,
272,
1329,
63,
1618,
63,
3148,
275,
5685,
339,
1449,
272,
1454,
5452,
314,
21303,
5932,
14,
982,
2337,
787,
6656,
5932,
2419,
302,
12,
272,
822,
8,
5917,
63,
807,
9,
5932,
787,
2138,
272,
1449,
272,
8002,
63,
3148,
275,
3355,
63,
807,
1988,
1955,
63,
1618,
63,
3148,
2938,
272,
2050,
14,
1757,
360,
12461,
4750,
28914,
5932,
14,
19893,
8142,
23759,
26,
450,
83,
7,
450,
822,
8,
4091,
63,
3148,
430,
339,
340,
822,
8,
4091,
63,
3148,
9,
665,
413,
26,
267,
372,
990,
2125,
339,
1748,
63,
835,
275,
8002,
63,
3148,
59,
16,
1527,
17,
61,
272,
1390,
63,
835,
275,
8002,
63,
3148,
1988,
17,
1527,
17,
61,
339,
2050,
14,
1757,
360,
4649,
4349,
2338,
26,
450,
83,
12,
8228,
4349,
2338,
26,
450,
83,
7,
450,
334,
827,
63,
835,
12,
1390,
63,
835,
430,
339,
5762,
63,
835,
275,
1390,
63,
835,
446,
1748,
63,
835,
272,
340,
5762,
63,
835,
508,
378,
26,
267,
5762,
63,
835,
275,
413,
339,
1748,
63,
4246,
63,
890,
275,
1616,
272,
1390,
63,
4246,
63,
890,
275,
5238,
339,
5023,
63,
3136,
275,
1390,
63,
4246,
63,
890,
446,
1748,
63,
4246,
63,
890,
339,
327,
4069,
5932,
543,
2649,
4069,
805,
272,
8002,
63,
3148,
14,
3191,
8,
498,
29,
2734,
334,
1027,
12,
2338,
304,
2649,
14,
15772,
8,
1027,
430,
339,
2050,
14,
1757,
360,
22861,
8002,
5932,
14,
19893,
8142,
23759,
26,
450,
83,
7,
450,
822,
8,
4091,
63,
3148,
430,
339,
3517,
63,
5527,
275,
942,
2378,
11431,
275,
18087,
272,
665,
2487,
730,
628,
505,
15,
3919,
1743,
267,
2396,
469,
288,
5023,
13,
6606,
26,
308,
796,
13,
24977,
27,
288,
1318,
13,
5743,
26,
8126,
27,
267,
789,
267,
282,
26,
1073,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
21736,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
12283,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
22797,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
267,
282,
26,
2682,
469,
3164,
26,
8399,
27,
1318,
13,
6518,
425,
26,
3592,
27,
789,
272,
3068,
2487,
26934,
339,
367,
1478,
12,
334,
1027,
12,
2338,
9,
315,
3874,
8,
4091,
63,
3148,
304,
267,
5023,
63,
4778,
275,
334,
835,
446,
1748,
63,
835,
9,
1182,
5762,
63,
835,
267,
5023,
63,
890,
275,
1109,
8,
827,
63,
4246,
63,
890,
435,
5023,
63,
4778,
627,
5023,
63,
3136,
9,
398,
3517,
63,
5527,
14,
740,
4827,
65,
4369,
628,
1733,
3149,
83,
15603,
1169,
2650,
3751,
3449,
628,
4246,
13,
890,
2689,
681,
88,
14423,
83,
1108,
3751,
2957,
65,
3524,
1169,
450,
334,
1080,
12,
5023,
63,
890,
12,
4349,
9,
435,
1169,
327,
1123,
2005,
8139,
1169,
7673,
3,
7471,
16,
10784,
339,
327,
2355,
14,
11777,
8,
1360,
63,
5527,
9,
339,
3517,
63,
2030,
275,
2650,
2030,
3524,
435,
1557,
78,
1370,
904,
8,
1360,
63,
5527,
9,
435,
1557,
78,
1108,
2030,
3072,
78,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kmoocdev2/edx-platform
|
lms/djangoapps/ccx/migrations/0004_seed_forum_roles_in_ccx_courses.py
|
38
|
3489
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
from ccx_keys.locator import CCXLocator
from courseware.courses import get_course_by_id
from django.db import migrations
from django.http import Http404
from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, \
FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_STUDENT
from django_comment_common.utils import STUDENT_ROLE_PERMISSIONS, MODERATOR_ROLE_PERMISSIONS, \
ADMINISTRATOR_ROLE_PERMISSIONS
log = logging.getLogger("edx.ccx")
def seed_forum_roles_for_existing_ccx(apps, schema_editor):
"""
Seed forum roles and make CCX coach forum admin for respective CCX(s).
Arguments:
apps (Applications): Apps in edX platform.
schema_editor (SchemaEditor): For editing database schema i.e create, delete field (column)
"""
CustomCourseForEdX = apps.get_model("ccx", "CustomCourseForEdX")
Role = apps.get_model("django_comment_common", "Role")
Permission = apps.get_model("django_comment_common", "Permission")
db_alias = schema_editor.connection.alias
# This will need to be changed if ccx gets moved out of the default db for some reason.
if db_alias != 'default':
log.info("Skipping CCX migration on non-default database.")
return
for ccx in CustomCourseForEdX.objects.all():
if not ccx.course_id or ccx.course_id.deprecated:
# prevent migration for deprecated course ids or invalid ids.
log.warning(
"Skipping CCX %s due to invalid or deprecated course_id: %s.",
ccx.id,
ccx.course_id
)
continue
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, unicode(ccx.id))
# Create forum roles.
admin_role, _ = Role.objects.get_or_create(name=FORUM_ROLE_ADMINISTRATOR, course_id=ccx_locator)
moderator_role, _ = Role.objects.get_or_create(name=FORUM_ROLE_MODERATOR, course_id=ccx_locator)
community_ta_role, _ = Role.objects.get_or_create(name=FORUM_ROLE_COMMUNITY_TA, course_id=ccx_locator)
student_role, _ = Role.objects.get_or_create(name=FORUM_ROLE_STUDENT, course_id=ccx_locator)
# Add permissions for each role.
for name in ADMINISTRATOR_ROLE_PERMISSIONS:
admin_role.permissions.add(Permission.objects.get_or_create(name=name)[0])
for name in MODERATOR_ROLE_PERMISSIONS:
moderator_role.permissions.add(Permission.objects.get_or_create(name=name)[0])
for name in STUDENT_ROLE_PERMISSIONS:
student_role.permissions.add(Permission.objects.get_or_create(name=name)[0])
for permission in student_role.permissions.all():
moderator_role.permissions.add(permission)
for permission in moderator_role.permissions.all():
community_ta_role.permissions.add(permission)
for permission in moderator_role.permissions.all():
admin_role.permissions.add(permission)
# Make CCX coach forum admin.
ccx.coach.roles.add(admin_role)
log.info("Seeded forum permissions for CCX %s", ccx_locator)
class Migration(migrations.Migration):
dependencies = [
('ccx', '0003_add_master_course_staff_in_ccx'),
('django_comment_common', '0002_forumsconfig'),
]
operations = [
migrations.RunPython(code=seed_forum_roles_for_existing_ccx, reverse_code=migrations.RunPython.noop)
]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
199,
504,
7429,
88,
63,
1612,
14,
6354,
492,
17586,
56,
10725,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
63,
991,
63,
344,
199,
504,
1639,
14,
697,
492,
6180,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
199,
504,
1639,
63,
3349,
63,
2330,
14,
992,
492,
2381,
2639,
63,
15468,
63,
14288,
21340,
6467,
12,
2381,
2639,
63,
15468,
63,
8816,
540,
6467,
12,
971,
272,
2381,
2639,
63,
15468,
63,
5378,
1734,
1922,
63,
6166,
12,
2381,
2639,
63,
15468,
63,
840,
29317,
199,
504,
1639,
63,
3349,
63,
2330,
14,
1208,
492,
4384,
29317,
63,
15468,
63,
4227,
31978,
12,
221,
10362,
11733,
6467,
63,
15468,
63,
4227,
31978,
12,
971,
272,
29948,
21340,
6467,
63,
15468,
63,
4227,
31978,
199,
199,
793,
275,
2050,
14,
5572,
480,
8268,
14,
19541,
531,
421,
199,
318,
6347,
63,
10044,
63,
8050,
63,
509,
63,
5952,
63,
19541,
8,
5181,
12,
4177,
63,
7515,
304,
272,
408,
272,
3240,
379,
21575,
11689,
436,
1852,
17586,
56,
512,
1225,
21575,
4628,
367,
26820,
17586,
56,
8,
83,
680,
339,
7628,
26,
267,
8686,
334,
31907,
304,
4693,
83,
315,
3988,
56,
4298,
14,
267,
4177,
63,
7515,
334,
6700,
10423,
304,
2104,
20401,
3050,
4177,
284,
14,
69,
1218,
12,
3145,
901,
334,
2301,
9,
339,
408,
272,
8388,
6979,
1858,
8751,
56,
275,
8686,
14,
362,
63,
1238,
480,
19541,
401,
298,
7223,
6979,
1858,
8751,
56,
531,
272,
18033,
275,
8686,
14,
362,
63,
1238,
480,
1176,
63,
3349,
63,
2330,
401,
298,
7422,
531,
272,
8779,
275,
8686,
14,
362,
63,
1238,
480,
1176,
63,
3349,
63,
2330,
401,
298,
7980,
531,
272,
1592,
63,
3620,
275,
4177,
63,
7515,
14,
2105,
14,
3620,
272,
327,
961,
911,
1929,
370,
506,
2896,
340,
7429,
88,
7545,
12155,
734,
402,
314,
849,
1592,
367,
2005,
4499,
14,
272,
340,
1592,
63,
3620,
1137,
283,
885,
356,
267,
943,
14,
815,
480,
18297,
17586,
56,
8367,
641,
2222,
13,
885,
3050,
2685,
267,
372,
339,
367,
7429,
88,
315,
8388,
6979,
1858,
8751,
56,
14,
1462,
14,
452,
837,
267,
340,
440,
7429,
88,
14,
1972,
63,
344,
503,
7429,
88,
14,
1972,
63,
344,
14,
6667,
26,
288,
327,
7981,
8367,
367,
5906,
2518,
2762,
503,
3866,
2762,
14,
288,
943,
14,
3764,
8,
355,
298,
18297,
17586,
56,
450,
83,
7037,
370,
3866,
503,
5906,
2518,
63,
344,
26,
450,
83,
4765,
355,
7429,
88,
14,
344,
12,
355,
7429,
88,
14,
1972,
63,
344,
288,
776,
288,
1980,
398,
7429,
88,
63,
6354,
275,
17586,
56,
10725,
14,
504,
63,
1972,
63,
6354,
8,
19541,
14,
1972,
63,
344,
12,
2649,
8,
19541,
14,
344,
430,
398,
327,
2790,
21575,
11689,
14,
267,
4628,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
14288,
21340,
6467,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
267,
818,
9043,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
8816,
540,
6467,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
267,
23633,
63,
502,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
5378,
1734,
1922,
63,
6166,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
267,
6474,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
840,
29317,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
398,
327,
2654,
3443,
367,
1924,
4719,
14,
267,
367,
536,
315,
29948,
21340,
6467,
63,
15468,
63,
4227,
31978,
26,
288,
4628,
63,
3756,
14,
6060,
14,
525,
8,
7980,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
267,
367,
536,
315,
10362,
11733,
6467,
63,
15468,
63,
4227,
31978,
26,
288,
818,
9043,
63,
3756,
14,
6060,
14,
525,
8,
7980,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
267,
367,
536,
315,
4384,
29317,
63,
15468,
63,
4227,
31978,
26,
288,
6474,
63,
3756,
14,
6060,
14,
525,
8,
7980,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
267,
367,
4983,
315,
6474,
63,
3756,
14,
6060,
14,
452,
837,
288,
818,
9043,
63,
3756,
14,
6060,
14,
525,
8,
5693,
9,
267,
367,
4983,
315,
818,
9043,
63,
3756,
14,
6060,
14,
452,
837,
288,
23633,
63,
502,
63,
3756,
14,
6060,
14,
525,
8,
5693,
9,
267,
367,
4983,
315,
818,
9043,
63,
3756,
14,
6060,
14,
452,
837,
288,
4628,
63,
3756,
14,
6060,
14,
525,
8,
5693,
9,
398,
327,
4155,
17586,
56,
512,
1225,
21575,
4628,
14,
267,
7429,
88,
14,
331,
1225,
14,
8050,
14,
525,
8,
2113,
63,
3756,
9,
398,
943,
14,
815,
480,
51,
4063,
21575,
3443,
367,
17586,
56,
450,
83,
401,
7429,
88,
63,
6354,
9,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
19541,
297,
283,
16861,
63,
525,
63,
4133,
63,
1972,
63,
7018,
63,
262,
63,
19541,
659,
267,
661,
1176,
63,
3349,
63,
2330,
297,
283,
9425,
63,
10044,
83,
888,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
2540,
4718,
8,
600,
29,
5176,
63,
10044,
63,
8050,
63,
509,
63,
5952,
63,
19541,
12,
3837,
63,
600,
29,
7685,
14,
2540,
4718,
14,
12921,
9,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
199,
504,
7429,
88,
63,
1612,
14,
6354,
492,
17586,
56,
10725,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
63,
991,
63,
344,
199,
504,
1639,
14,
697,
492,
6180,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
199,
504,
1639,
63,
3349,
63,
2330,
14,
992,
492,
2381,
2639,
63,
15468,
63,
14288,
21340,
6467,
12,
2381,
2639,
63,
15468,
63,
8816,
540,
6467,
12,
971,
272,
2381,
2639,
63,
15468,
63,
5378,
1734,
1922,
63,
6166,
12,
2381,
2639,
63,
15468,
63,
840,
29317,
199,
504,
1639,
63,
3349,
63,
2330,
14,
1208,
492,
4384,
29317,
63,
15468,
63,
4227,
31978,
12,
221,
10362,
11733,
6467,
63,
15468,
63,
4227,
31978,
12,
971,
272,
29948,
21340,
6467,
63,
15468,
63,
4227,
31978,
199,
199,
793,
275,
2050,
14,
5572,
480,
8268,
14,
19541,
531,
421,
199,
318,
6347,
63,
10044,
63,
8050,
63,
509,
63,
5952,
63,
19541,
8,
5181,
12,
4177,
63,
7515,
304,
272,
408,
272,
3240,
379,
21575,
11689,
436,
1852,
17586,
56,
512,
1225,
21575,
4628,
367,
26820,
17586,
56,
8,
83,
680,
339,
7628,
26,
267,
8686,
334,
31907,
304,
4693,
83,
315,
3988,
56,
4298,
14,
267,
4177,
63,
7515,
334,
6700,
10423,
304,
2104,
20401,
3050,
4177,
284,
14,
69,
1218,
12,
3145,
901,
334,
2301,
9,
339,
408,
272,
8388,
6979,
1858,
8751,
56,
275,
8686,
14,
362,
63,
1238,
480,
19541,
401,
298,
7223,
6979,
1858,
8751,
56,
531,
272,
18033,
275,
8686,
14,
362,
63,
1238,
480,
1176,
63,
3349,
63,
2330,
401,
298,
7422,
531,
272,
8779,
275,
8686,
14,
362,
63,
1238,
480,
1176,
63,
3349,
63,
2330,
401,
298,
7980,
531,
272,
1592,
63,
3620,
275,
4177,
63,
7515,
14,
2105,
14,
3620,
272,
327,
961,
911,
1929,
370,
506,
2896,
340,
7429,
88,
7545,
12155,
734,
402,
314,
849,
1592,
367,
2005,
4499,
14,
272,
340,
1592,
63,
3620,
1137,
283,
885,
356,
267,
943,
14,
815,
480,
18297,
17586,
56,
8367,
641,
2222,
13,
885,
3050,
2685,
267,
372,
339,
367,
7429,
88,
315,
8388,
6979,
1858,
8751,
56,
14,
1462,
14,
452,
837,
267,
340,
440,
7429,
88,
14,
1972,
63,
344,
503,
7429,
88,
14,
1972,
63,
344,
14,
6667,
26,
288,
327,
7981,
8367,
367,
5906,
2518,
2762,
503,
3866,
2762,
14,
288,
943,
14,
3764,
8,
355,
298,
18297,
17586,
56,
450,
83,
7037,
370,
3866,
503,
5906,
2518,
63,
344,
26,
450,
83,
4765,
355,
7429,
88,
14,
344,
12,
355,
7429,
88,
14,
1972,
63,
344,
288,
776,
288,
1980,
398,
7429,
88,
63,
6354,
275,
17586,
56,
10725,
14,
504,
63,
1972,
63,
6354,
8,
19541,
14,
1972,
63,
344,
12,
2649,
8,
19541,
14,
344,
430,
398,
327,
2790,
21575,
11689,
14,
267,
4628,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
14288,
21340,
6467,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
267,
818,
9043,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
8816,
540,
6467,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
267,
23633,
63,
502,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
5378,
1734,
1922,
63,
6166,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
267,
6474,
63,
3756,
12,
485,
275,
18033,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
2707,
2639,
63,
15468,
63,
840,
29317,
12,
2518,
63,
344,
29,
19541,
63,
6354,
9,
398,
327,
2654,
3443,
367,
1924,
4719,
14,
267,
367,
536,
315,
29948,
21340,
6467,
63,
15468,
63,
4227,
31978,
26,
288,
4628,
63,
3756,
14,
6060,
14,
525,
8,
7980,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
267,
367,
536,
315,
10362,
11733,
6467,
63,
15468,
63,
4227,
31978,
26,
288,
818,
9043,
63,
3756,
14,
6060,
14,
525,
8,
7980,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
267,
367,
536,
315,
4384,
29317,
63,
15468,
63,
4227,
31978,
26,
288,
6474,
63,
3756,
14,
6060,
14,
525,
8,
7980,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
267,
367,
4983,
315,
6474,
63,
3756,
14,
6060,
14,
452,
837,
288,
818,
9043,
63,
3756,
14,
6060,
14,
525,
8,
5693,
9,
267,
367,
4983,
315,
818,
9043,
63,
3756,
14,
6060,
14,
452,
837,
288,
23633,
63,
502,
63,
3756,
14,
6060,
14,
525,
8,
5693,
9,
267,
367,
4983,
315,
818,
9043,
63,
3756,
14,
6060,
14,
452,
837,
288,
4628,
63,
3756,
14,
6060,
14,
525,
8,
5693,
9,
398,
327,
4155,
17586,
56,
512,
1225,
21575,
4628,
14,
267,
7429,
88,
14,
331,
1225,
14,
8050,
14,
525,
8,
2113,
63,
3756,
9,
398,
943,
14,
815,
480,
51,
4063,
21575,
3443,
367,
17586,
56,
450,
83,
401,
7429,
88,
63,
6354,
9,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
19541,
297,
283,
16861,
63,
525,
63,
4133,
63,
1972,
63,
7018,
63,
262,
63,
19541,
659,
267,
661,
1176,
63,
3349,
63,
2330,
297,
283,
9425,
63,
10044,
83,
888,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
2540,
4718,
8,
600,
29,
5176,
63,
10044,
63,
8050,
63,
509,
63,
5952,
63,
19541,
12,
3837,
63,
600,
29,
7685,
14,
2540,
4718,
14,
12921,
9,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jack-song/evolving-life
|
mainsite/settings.py
|
1
|
2624
|
"""
Django settings for mainsite project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['localhost', 'evolving-life.herokuapp.com']
# Application definition
DEFAULTS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
LIBS = (
)
APPS = (
'mainsite.apps.evolvinglife',
'mainsite.sitetemplates',
)
INSTALLED_APPS = DEFAULTS + LIBS + APPS
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mainsite.urls'
WSGI_APPLICATION = 'mainsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Parse database configuration from $DATABASE_URL
DATABASES['default']=dj_database_url.config(default='jack:@evolvinglife')
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
mit
|
[
624,
199,
9323,
2202,
367,
2446,
2124,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
646,
747,
199,
646,
366,
74,
63,
4659,
63,
633,
199,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
747,
14,
2314,
459,
12961,
63,
3078,
418,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
756,
199,
199,
7433,
63,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
788,
5967,
297,
283,
69,
5650,
4007,
13,
13602,
14,
2523,
745,
85,
571,
14,
957,
418,
421,
199,
3,
13515,
5492,
199,
199,
30773,
275,
334,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
199,
9,
199,
199,
25161,
275,
334,
199,
9,
199,
199,
14219,
275,
334,
272,
283,
973,
2124,
14,
5181,
14,
69,
5650,
4007,
13602,
297,
272,
283,
973,
2124,
14,
2124,
5876,
297,
199,
9,
199,
199,
15942,
63,
14219,
275,
6186,
51,
435,
25764,
51,
435,
10319,
5067,
199,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
4434,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
5441,
63,
18125,
275,
283,
973,
2124,
14,
3603,
7,
199,
199,
16828,
63,
24051,
275,
283,
973,
2124,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
199,
199,
3,
6077,
3050,
2897,
687,
2672,
17873,
63,
2632,
199,
27260,
459,
885,
13784,
18256,
63,
4659,
63,
633,
14,
888,
8,
885,
534,
19193,
26,
32,
69,
5650,
4007,
13602,
358,
199,
27260,
459,
885,
2545,
15956,
418,
275,
283,
1176,
14,
697,
14,
7765,
14,
15437,
63,
20270,
18,
7,
199,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
11288,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
10449,
63,
5441,
275,
283,
18373,
7,
199,
199,
10449,
9472,
63,
14455,
275,
334,
272,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
1986,
659,
221,
199,
9,
199,
199,
3,
869,
15034,
314,
283,
56,
13,
1858,
15295,
13,
8548,
7,
1406,
367,
1056,
14,
374,
63,
7817,
342,
199,
20696,
63,
20026,
63,
5413,
63,
7311,
275,
661,
2856,
63,
56,
63,
22371,
8280,
63,
7459,
297,
283,
2859,
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
] |
[
199,
9323,
2202,
367,
2446,
2124,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
646,
747,
199,
646,
366,
74,
63,
4659,
63,
633,
199,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
747,
14,
2314,
459,
12961,
63,
3078,
418,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
756,
199,
199,
7433,
63,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
788,
5967,
297,
283,
69,
5650,
4007,
13,
13602,
14,
2523,
745,
85,
571,
14,
957,
418,
421,
199,
3,
13515,
5492,
199,
199,
30773,
275,
334,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
199,
9,
199,
199,
25161,
275,
334,
199,
9,
199,
199,
14219,
275,
334,
272,
283,
973,
2124,
14,
5181,
14,
69,
5650,
4007,
13602,
297,
272,
283,
973,
2124,
14,
2124,
5876,
297,
199,
9,
199,
199,
15942,
63,
14219,
275,
6186,
51,
435,
25764,
51,
435,
10319,
5067,
199,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
4434,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
5441,
63,
18125,
275,
283,
973,
2124,
14,
3603,
7,
199,
199,
16828,
63,
24051,
275,
283,
973,
2124,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
199,
199,
3,
6077,
3050,
2897,
687,
2672,
17873,
63,
2632,
199,
27260,
459,
885,
13784,
18256,
63,
4659,
63,
633,
14,
888,
8,
885,
534,
19193,
26,
32,
69,
5650,
4007,
13602,
358,
199,
27260,
459,
885,
2545,
15956,
418,
275,
283,
1176,
14,
697,
14,
7765,
14,
15437,
63,
20270,
18,
7,
199,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
11288,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
23,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
10449,
63,
5441,
275,
283,
18373,
7,
199,
199,
10449,
9472,
63,
14455,
275,
334,
272,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
1986,
659,
221,
199,
9,
199,
199,
3,
869,
15034,
314,
283,
56,
13,
1858,
15295,
13,
8548,
7,
1406,
367,
1056,
14,
374,
63,
7817,
342,
199,
20696,
63,
20026,
63,
5413,
63,
7311,
275,
661,
2856,
63,
56,
63,
22371,
8280,
63,
7459,
297,
283,
2859,
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,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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
] |
DrMeers/django
|
django/contrib/gis/gdal/prototypes/errcheck.py
|
12
|
4140
|
"""
This module houses the error-checking routines used by the GDAL
ctypes prototypes.
"""
from ctypes import c_void_p, string_at
from django.contrib.gis.gdal.error import check_err, OGRException, SRSException
from django.contrib.gis.gdal.libgdal import lgdal
from django.utils import six
# Helper routines for retrieving pointers and/or values from
# arguments passed in by reference.
def arg_byref(args, offset=-1):
"Returns the pointer argument's by-refernece value."
return args[offset]._obj.value
def ptr_byref(args, offset=-1):
"Returns the pointer argument passed in by-reference."
return args[offset]._obj
### String checking Routines ###
def check_const_string(result, func, cargs, offset=None):
"""
Similar functionality to `check_string`, but does not free the pointer.
"""
if offset:
check_err(result)
ptr = ptr_byref(cargs, offset)
return ptr.value
else:
return result
def check_string(result, func, cargs, offset=-1, str_result=False):
"""
Checks the string output returned from the given function, and frees
the string pointer allocated by OGR. The `str_result` keyword
may be used when the result is the string pointer, otherwise
the OGR error code is assumed. The `offset` keyword may be used
to extract the string pointer passed in by-reference at the given
slice offset in the function arguments.
"""
if str_result:
# For routines that return a string.
ptr = result
if not ptr:
s = None
else:
s = string_at(result)
else:
# Error-code return specified.
check_err(result)
ptr = ptr_byref(cargs, offset)
# Getting the string value
s = ptr.value
# Correctly freeing the allocated memory beind GDAL pointer
# w/the VSIFree routine.
if ptr:
lgdal.VSIFree(ptr)
return s
### DataSource, Layer error-checking ###
### Envelope checking ###
def check_envelope(result, func, cargs, offset=-1):
"Checks a function that returns an OGR Envelope by reference."
env = ptr_byref(cargs, offset)
return env
### Geometry error-checking routines ###
def check_geom(result, func, cargs):
"Checks a function that returns a geometry."
# OGR_G_Clone may return an integer, even though the
# restype is set to c_void_p
if isinstance(result, six.integer_types):
result = c_void_p(result)
if not result:
raise OGRException('Invalid geometry pointer returned from "%s".' % func.__name__)
return result
def check_geom_offset(result, func, cargs, offset=-1):
"Chcks the geometry at the given offset in the C parameter list."
check_err(result)
geom = ptr_byref(cargs, offset=offset)
return check_geom(geom, func, cargs)
### Spatial Reference error-checking routines ###
def check_srs(result, func, cargs):
if isinstance(result, six.integer_types):
result = c_void_p(result)
if not result:
raise SRSException('Invalid spatial reference pointer returned from "%s".' % func.__name__)
return result
### Other error-checking routines ###
def check_arg_errcode(result, func, cargs):
"""
The error code is returned in the last argument, by reference.
Check its value with `check_err` before returning the result.
"""
check_err(arg_byref(cargs))
return result
def check_errcode(result, func, cargs):
"""
Check the error code returned (c_int).
"""
check_err(result)
def check_pointer(result, func, cargs):
"Makes sure the result pointer is valid."
if isinstance(result, six.integer_types):
result = c_void_p(result)
if result:
return result
else:
raise OGRException('Invalid pointer returned from "%s"' % func.__name__)
def check_str_arg(result, func, cargs):
"""
This is for the OSRGet[Angular|Linear]Units functions, which
require that the returned string pointer not be freed. This
returns both the double and tring values.
"""
dbl = result
ptr = cargs[-1]._obj
return dbl, ptr.value.decode()
|
bsd-3-clause
|
[
624,
199,
961,
859,
394,
810,
874,
314,
1125,
13,
19527,
14975,
1202,
701,
314,
15801,
199,
5577,
19393,
83,
14,
199,
624,
199,
504,
5577,
492,
286,
63,
1647,
63,
80,
12,
1059,
63,
292,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
1104,
63,
1508,
12,
19746,
907,
16010,
12,
12765,
21686,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
773,
11600,
492,
634,
11600,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
3,
11642,
14975,
367,
23812,
21116,
436,
15,
269,
1338,
687,
199,
3,
2368,
3032,
315,
701,
3659,
14,
199,
318,
1680,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
1159,
701,
13,
21928,
685,
301,
574,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
14,
585,
421,
199,
318,
12448,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
3032,
315,
701,
13,
4443,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
421,
199,
5680,
2624,
7907,
30790,
3746,
6754,
199,
318,
1104,
63,
1297,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
29,
403,
304,
272,
408,
272,
20046,
9330,
370,
658,
1074,
63,
875,
3559,
1325,
1630,
440,
2867,
314,
7849,
14,
272,
408,
272,
340,
3268,
26,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
372,
12448,
14,
585,
272,
587,
26,
267,
372,
754,
421,
199,
318,
1104,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
12,
620,
63,
1099,
29,
797,
304,
272,
408,
272,
13813,
314,
1059,
1072,
2138,
687,
314,
1627,
805,
12,
436,
289,
5710,
272,
314,
1059,
7849,
17659,
701,
10904,
14,
221,
710,
658,
495,
63,
1099,
64,
4252,
272,
1443,
506,
1202,
1380,
314,
754,
365,
314,
1059,
7849,
12,
4257,
272,
314,
10904,
1125,
1233,
365,
10826,
14,
221,
710,
658,
2743,
64,
4252,
1443,
506,
1202,
272,
370,
5536,
314,
1059,
7849,
3032,
315,
701,
13,
4443,
737,
314,
1627,
272,
6014,
3268,
315,
314,
805,
2368,
14,
272,
408,
272,
340,
620,
63,
1099,
26,
267,
327,
2104,
14975,
626,
372,
282,
1059,
14,
267,
12448,
275,
754,
267,
340,
440,
12448,
26,
288,
308,
275,
488,
267,
587,
26,
288,
308,
275,
1059,
63,
292,
8,
1099,
9,
272,
587,
26,
267,
327,
4520,
13,
600,
372,
2013,
14,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
327,
20703,
314,
1059,
574,
267,
308,
275,
12448,
14,
585,
272,
327,
31057,
590,
2867,
316,
314,
17659,
4402,
506,
688,
15801,
7849,
272,
327,
336,
15,
1589,
812,
2684,
10146,
12981,
14,
272,
340,
12448,
26,
267,
634,
11600,
14,
54,
2684,
10146,
8,
4695,
9,
272,
372,
308,
199,
199,
5680,
24300,
12,
11915,
1125,
13,
19527,
6754,
421,
199,
5680,
29143,
7907,
6754,
199,
318,
1104,
63,
19707,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
11834,
282,
805,
626,
2529,
376,
10904,
29143,
701,
3659,
2122,
272,
2589,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
272,
372,
2589,
421,
199,
5680,
10579,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
6481,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
11834,
282,
805,
626,
2529,
282,
3400,
2122,
272,
327,
10904,
63,
39,
63,
21222,
1443,
372,
376,
3000,
12,
2755,
10617,
314,
272,
327,
4618,
514,
365,
663,
370,
286,
63,
1647,
63,
80,
272,
340,
1228,
8,
1099,
12,
3816,
14,
4115,
63,
1313,
304,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
267,
746,
19746,
907,
16010,
360,
3364,
3400,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
421,
199,
318,
1104,
63,
6481,
63,
2743,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
1049,
5618,
314,
3400,
737,
314,
1627,
3268,
315,
314,
445,
2725,
769,
2122,
272,
1104,
63,
1508,
8,
1099,
9,
272,
9671,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
29,
2743,
9,
272,
372,
1104,
63,
6481,
8,
6481,
12,
2562,
12,
286,
589,
9,
421,
199,
5680,
13423,
10944,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
12722,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
340,
1228,
8,
1099,
12,
3816,
14,
4115,
63,
1313,
304,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
267,
746,
12765,
21686,
360,
3364,
11469,
3659,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
421,
199,
5680,
5439,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
1273,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
710,
1125,
1233,
365,
2138,
315,
314,
2061,
1423,
12,
701,
3659,
14,
272,
2670,
2399,
574,
543,
658,
1074,
63,
1508,
64,
2544,
8152,
314,
754,
14,
272,
408,
272,
1104,
63,
1508,
8,
1273,
63,
20447,
8,
67,
589,
430,
272,
372,
754,
421,
199,
318,
1104,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
2670,
314,
1125,
1233,
2138,
334,
67,
63,
442,
680,
272,
408,
272,
1104,
63,
1508,
8,
1099,
9,
421,
199,
318,
1104,
63,
3929,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
27142,
3238,
314,
754,
7849,
365,
1686,
2122,
272,
340,
1228,
8,
1099,
12,
3816,
14,
4115,
63,
1313,
304,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
754,
26,
267,
372,
754,
272,
587,
26,
267,
746,
19746,
907,
16010,
360,
3364,
7849,
2138,
687,
2071,
83,
4507,
450,
2562,
855,
354,
3368,
421,
199,
318,
1104,
63,
495,
63,
1273,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
961,
365,
367,
314,
4403,
50,
1002,
59,
2493,
71,
2238,
92,
10608,
61,
15121,
3423,
12,
1314,
272,
4409,
626,
314,
2138,
1059,
7849
] |
[
199,
961,
859,
394,
810,
874,
314,
1125,
13,
19527,
14975,
1202,
701,
314,
15801,
199,
5577,
19393,
83,
14,
199,
624,
199,
504,
5577,
492,
286,
63,
1647,
63,
80,
12,
1059,
63,
292,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
1104,
63,
1508,
12,
19746,
907,
16010,
12,
12765,
21686,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
773,
11600,
492,
634,
11600,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
3,
11642,
14975,
367,
23812,
21116,
436,
15,
269,
1338,
687,
199,
3,
2368,
3032,
315,
701,
3659,
14,
199,
318,
1680,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
1159,
701,
13,
21928,
685,
301,
574,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
14,
585,
421,
199,
318,
12448,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
3032,
315,
701,
13,
4443,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
421,
199,
5680,
2624,
7907,
30790,
3746,
6754,
199,
318,
1104,
63,
1297,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
29,
403,
304,
272,
408,
272,
20046,
9330,
370,
658,
1074,
63,
875,
3559,
1325,
1630,
440,
2867,
314,
7849,
14,
272,
408,
272,
340,
3268,
26,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
372,
12448,
14,
585,
272,
587,
26,
267,
372,
754,
421,
199,
318,
1104,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
12,
620,
63,
1099,
29,
797,
304,
272,
408,
272,
13813,
314,
1059,
1072,
2138,
687,
314,
1627,
805,
12,
436,
289,
5710,
272,
314,
1059,
7849,
17659,
701,
10904,
14,
221,
710,
658,
495,
63,
1099,
64,
4252,
272,
1443,
506,
1202,
1380,
314,
754,
365,
314,
1059,
7849,
12,
4257,
272,
314,
10904,
1125,
1233,
365,
10826,
14,
221,
710,
658,
2743,
64,
4252,
1443,
506,
1202,
272,
370,
5536,
314,
1059,
7849,
3032,
315,
701,
13,
4443,
737,
314,
1627,
272,
6014,
3268,
315,
314,
805,
2368,
14,
272,
408,
272,
340,
620,
63,
1099,
26,
267,
327,
2104,
14975,
626,
372,
282,
1059,
14,
267,
12448,
275,
754,
267,
340,
440,
12448,
26,
288,
308,
275,
488,
267,
587,
26,
288,
308,
275,
1059,
63,
292,
8,
1099,
9,
272,
587,
26,
267,
327,
4520,
13,
600,
372,
2013,
14,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
327,
20703,
314,
1059,
574,
267,
308,
275,
12448,
14,
585,
272,
327,
31057,
590,
2867,
316,
314,
17659,
4402,
506,
688,
15801,
7849,
272,
327,
336,
15,
1589,
812,
2684,
10146,
12981,
14,
272,
340,
12448,
26,
267,
634,
11600,
14,
54,
2684,
10146,
8,
4695,
9,
272,
372,
308,
199,
199,
5680,
24300,
12,
11915,
1125,
13,
19527,
6754,
421,
199,
5680,
29143,
7907,
6754,
199,
318,
1104,
63,
19707,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
11834,
282,
805,
626,
2529,
376,
10904,
29143,
701,
3659,
2122,
272,
2589,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
272,
372,
2589,
421,
199,
5680,
10579,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
6481,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
11834,
282,
805,
626,
2529,
282,
3400,
2122,
272,
327,
10904,
63,
39,
63,
21222,
1443,
372,
376,
3000,
12,
2755,
10617,
314,
272,
327,
4618,
514,
365,
663,
370,
286,
63,
1647,
63,
80,
272,
340,
1228,
8,
1099,
12,
3816,
14,
4115,
63,
1313,
304,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
267,
746,
19746,
907,
16010,
360,
3364,
3400,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
421,
199,
318,
1104,
63,
6481,
63,
2743,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
1049,
5618,
314,
3400,
737,
314,
1627,
3268,
315,
314,
445,
2725,
769,
2122,
272,
1104,
63,
1508,
8,
1099,
9,
272,
9671,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
29,
2743,
9,
272,
372,
1104,
63,
6481,
8,
6481,
12,
2562,
12,
286,
589,
9,
421,
199,
5680,
13423,
10944,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
12722,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
340,
1228,
8,
1099,
12,
3816,
14,
4115,
63,
1313,
304,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
267,
746,
12765,
21686,
360,
3364,
11469,
3659,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
421,
199,
5680,
5439,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
1273,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
710,
1125,
1233,
365,
2138,
315,
314,
2061,
1423,
12,
701,
3659,
14,
272,
2670,
2399,
574,
543,
658,
1074,
63,
1508,
64,
2544,
8152,
314,
754,
14,
272,
408,
272,
1104,
63,
1508,
8,
1273,
63,
20447,
8,
67,
589,
430,
272,
372,
754,
421,
199,
318,
1104,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
2670,
314,
1125,
1233,
2138,
334,
67,
63,
442,
680,
272,
408,
272,
1104,
63,
1508,
8,
1099,
9,
421,
199,
318,
1104,
63,
3929,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
27142,
3238,
314,
754,
7849,
365,
1686,
2122,
272,
340,
1228,
8,
1099,
12,
3816,
14,
4115,
63,
1313,
304,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
754,
26,
267,
372,
754,
272,
587,
26,
267,
746,
19746,
907,
16010,
360,
3364,
7849,
2138,
687,
2071,
83,
4507,
450,
2562,
855,
354,
3368,
421,
199,
318,
1104,
63,
495,
63,
1273,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
961,
365,
367,
314,
4403,
50,
1002,
59,
2493,
71,
2238,
92,
10608,
61,
15121,
3423,
12,
1314,
272,
4409,
626,
314,
2138,
1059,
7849,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
boegel/easybuild-easyblocks
|
easybuild/easyblocks/t/trilinos.py
|
1
|
14884
|
##
# Copyright 2009-2020 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild 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 v2.
#
# EasyBuild 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 EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for Trilinos, implemented as an easyblock
@author: Kenneth Hoste (Ghent University)
"""
import os
import random
import re
from distutils.version import LooseVersion
import easybuild.tools.toolchain as toolchain
from easybuild.easyblocks.generic.cmakemake import CMakeMake
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_path
from easybuild.tools.filetools import mkdir, remove_dir, symlink
from easybuild.tools.modules import get_software_root
from easybuild.tools.py2vs3 import ascii_letters
from easybuild.tools.systemtools import get_shared_lib_ext
class EB_Trilinos(CMakeMake):
"""Support for building Trilinos."""
# see http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt
@staticmethod
def extra_options():
"""Add extra config options specific to Trilinos."""
extra_vars = {
'shared_libs': [None, "Deprecated. Use build_shared_libs", CUSTOM],
'openmp': [True, "Enable OpenMP support", CUSTOM],
'all_exts': [True, "Enable all Trilinos packages", CUSTOM],
'skip_exts': [[], "List of Trilinos packages to skip", CUSTOM],
'verbose': [False, "Configure for verbose output", CUSTOM],
}
return CMakeMake.extra_options(extra_vars)
def __init__(self, *args, **kwargs):
"""Constructor of custom easyblock for Trilinos."""
super(EB_Trilinos, self).__init__(*args, **kwargs)
if self.cfg['shared_libs'] is not None:
self.log.deprecated("Use 'build_shared_libs' instead of 'shared_libs' easyconfig parameter", '5.0')
self.cfg['build_shared_libs'] = self.cfg['shared_libs']
def configure_step(self):
"""Set some extra environment variables before configuring."""
# enable verbose output if desired
if self.cfg['verbose']:
for x in ["CONFIGURE", "MAKEFILE"]:
self.cfg.update('configopts', "-DTrilinos_VERBOSE_%s:BOOL=ON" % x)
# compiler flags
cflags = [os.getenv('CFLAGS')]
cxxflags = [os.getenv('CXXFLAGS')]
fflags = [os.getenv('FFLAGS')]
ignore_cxx_seek_mpis = [toolchain.INTELMPI, toolchain.MPICH,
toolchain.MPICH2, toolchain.MVAPICH2] # @UndefinedVariable
ignore_cxx_seek_flag = "-DMPICH_IGNORE_CXX_SEEK"
if self.toolchain.mpi_family() in ignore_cxx_seek_mpis:
cflags.append(ignore_cxx_seek_flag)
cxxflags.append(ignore_cxx_seek_flag)
fflags.append(ignore_cxx_seek_flag)
self.cfg.update('configopts', '-DCMAKE_C_FLAGS="%s"' % ' '.join(cflags))
self.cfg.update('configopts', '-DCMAKE_CXX_FLAGS="%s"' % ' '.join(cxxflags))
self.cfg.update('configopts', '-DCMAKE_Fortran_FLAGS="%s"' % ' '.join(fflags))
# Make sure Tpetra/Kokkos Serial mode is enabled regardless of OpenMP
self.cfg.update('configopts', "-DKokkos_ENABLE_Serial:BOOL=ON")
self.cfg.update('configopts', "-DTpetra_INST_SERIAL:BOOL=ON")
# OpenMP
if self.cfg['openmp']:
self.cfg.update('configopts', "-DTrilinos_ENABLE_OpenMP:BOOL=ON")
self.cfg.update('configopts', "-DKokkos_ENABLE_OpenMP:BOOL=ON")
# MPI
if self.toolchain.options.get('usempi', None):
self.cfg.update('configopts', "-DTPL_ENABLE_MPI:BOOL=ON")
# enable full testing
self.cfg.update('configopts', "-DTrilinos_ENABLE_TESTS:BOOL=ON")
self.cfg.update('configopts', "-DTrilinos_ENABLE_ALL_FORWARD_DEP_PACKAGES:BOOL=ON")
lib_re = re.compile("^lib(.*).a$")
# BLAS, LAPACK
for dep in ["BLAS", "LAPACK"]:
self.cfg.update('configopts', '-DTPL_ENABLE_%s:BOOL=ON' % dep)
libdirs = os.getenv('%s_LIB_DIR' % dep)
if self.toolchain.comp_family() == toolchain.GCC: # @UndefinedVariable
libdirs += ";%s/lib64" % get_software_root('GCC')
self.cfg.update('configopts', '-D%s_LIBRARY_DIRS="%s"' % (dep, libdirs))
if self.cfg['openmp']:
libs = os.getenv('%s_MT_STATIC_LIBS' % dep).split(',')
else:
libs = os.getenv('%s_STATIC_LIBS' % dep).split(',')
lib_names = ';'.join([lib_re.search(x).group(1) for x in libs])
if self.toolchain.comp_family() == toolchain.GCC: # @UndefinedVariable
# explicitely specify static lib!
lib_names += ";libgfortran.a"
self.cfg.update('configopts', '-D%s_LIBRARY_NAMES="%s"' % (dep, lib_names))
# MKL
if get_software_root('imkl') and LooseVersion(self.version) >= LooseVersion('12.12'):
self.cfg.update('configopts', "-DTPL_ENABLE_MKL:BOOL=ON")
self.cfg.update('configopts', '-DMKL_LIBRARY_DIRS:PATH="%s/lib/intel64"' % os.getenv('MKLROOT'))
self.cfg.update('configopts', '-DMKL_INCLUDE_DIRS:PATH="%s/include"' % os.getenv('MKLROOT'))
# UMFPACK is part of SuiteSparse
suitesparse = get_software_root('SuiteSparse')
if suitesparse:
self.cfg.update('configopts', "-DTPL_ENABLE_UMFPACK:BOOL=ON")
self.cfg.update('configopts', "-DTPL_ENABLE_Cholmod:BOOL=ON")
incdirs, libdirs, libnames = [], [], []
for lib in ["UMFPACK", "CHOLMOD", "COLAMD", "AMD", "CCOLAMD", "CAMD"]:
incdirs.append(os.path.join(suitesparse, lib, "Include"))
libdirs.append(os.path.join(suitesparse, lib, "Lib"))
libnames.append(lib.lower())
# add SuiteSparse config lib, it is in recent versions of suitesparse
libdirs.append(os.path.join(suitesparse, 'SuiteSparse_config'))
libnames.append('suitesparseconfig')
# because of "SuiteSparse_config.c:function SuiteSparse_tic: error: undefined reference to 'clock_gettime'"
libnames.append('rt')
# required to resolve METIS symbols in SuiteSparse's libcholmod.a
# doesn't need to be full location, probably because it can be found via $LIBRARY_PATH
# not easy to know whether it should come from METIS or ParMETIS...
# see https://answers.launchpad.net/dorsal/+question/223167
libnames.append('libmetis.a')
self.cfg.update('configopts', '-DUMFPACK_INCLUDE_DIRS:PATH="%s"' % ';'.join(incdirs))
self.cfg.update('configopts', '-DUMFPACK_LIBRARY_DIRS:PATH="%s"' % ';'.join(libdirs))
self.cfg.update('configopts', '-DUMFPACK_LIBRARY_NAMES:STRING="%s"' % ';'.join(libnames))
self.cfg.update('configopts', '-DCholmod_INCLUDE_DIRS:PATH="%s"' % ';'.join(incdirs))
self.cfg.update('configopts', '-DCholmod_LIBRARY_DIRS:PATH="%s"' % ';'.join(libdirs))
self.cfg.update('configopts', '-DCholmod_LIBRARY_NAMES:STRING="%s"' % ';'.join(libnames))
# BLACS
if get_software_root('BLACS'):
self.cfg.update('configopts', "-DTPL_ENABLE_BLACS:BOOL=ON")
self.cfg.update('configopts', '-DBLACS_INCLUDE_DIRS:PATH="%s"' % os.getenv('BLACS_INC_DIR'))
self.cfg.update('configopts', '-DBLACS_LIBRARY_DIRS:PATH="%s"' % os.getenv('BLACS_LIB_DIR'))
blacs_lib_names = os.getenv('BLACS_STATIC_LIBS').split(',')
blacs_lib_names = [lib_re.search(x).group(1) for x in blacs_lib_names]
self.cfg.update('configopts', '-DBLACS_LIBRARY_NAMES:STRING="%s"' % (';'.join(blacs_lib_names)))
# ScaLAPACK
if get_software_root('ScaLAPACK'):
self.cfg.update('configopts', "-DTPL_ENABLE_SCALAPACK:BOOL=ON")
self.cfg.update('configopts', '-DSCALAPACK_INCLUDE_DIRS:PATH="%s"' % os.getenv('SCALAPACK_INC_DIR'))
self.cfg.update('configopts', '-DSCALAPACK_LIBRARY_DIRS:PATH="%s;%s"' % (os.getenv('SCALAPACK_LIB_DIR'),
os.getenv('BLACS_LIB_DIR')))
# PETSc
petsc = get_software_root('PETSc')
if petsc:
self.cfg.update('configopts', "-DTPL_ENABLE_PETSC:BOOL=ON")
incdirs = [os.path.join(petsc, "include")]
self.cfg.update('configopts', '-DPETSC_INCLUDE_DIRS:PATH="%s"' % ';'.join(incdirs))
petsc_libdirs = [
os.path.join(petsc, "lib"),
os.path.join(suitesparse, "UMFPACK", "Lib"),
os.path.join(suitesparse, "CHOLMOD", "Lib"),
os.path.join(suitesparse, "COLAMD", "Lib"),
os.path.join(suitesparse, "AMD", "Lib"),
os.getenv('FFTW_LIB_DIR'),
os.path.join(get_software_root('ParMETIS'), "Lib")
]
self.cfg.update('configopts', '-DPETSC_LIBRARY_DIRS:PATH="%s"' % ';'.join(petsc_libdirs))
petsc_libnames = ["petsc", "umfpack", "cholmod", "colamd", "amd", "parmetis", "metis"]
petsc_libnames += [lib_re.search(x).group(1) for x in os.getenv('FFTW_STATIC_LIBS').split(',')]
self.cfg.update('configopts', '-DPETSC_LIBRARY_NAMES:STRING="%s"' % ';'.join(petsc_libnames))
# other Third-Party Libraries (TPLs)
deps = self.cfg.dependencies()
builddeps = self.cfg.builddependencies() + ["SuiteSparse"]
deps = [dep['name'] for dep in deps if not dep['name'] in builddeps]
for dep in deps:
deproot = get_software_root(dep)
if deproot:
depmap = {
'SCOTCH': 'Scotch',
}
dep = depmap.get(dep, dep)
self.cfg.update('configopts', "-DTPL_ENABLE_%s:BOOL=ON" % dep)
incdir = os.path.join(deproot, "include")
self.cfg.update('configopts', '-D%s_INCLUDE_DIRS:PATH="%s"' % (dep, incdir))
libdir = os.path.join(deproot, "lib")
self.cfg.update('configopts', '-D%s_LIBRARY_DIRS:PATH="%s"' % (dep, libdir))
# extensions_step
if self.cfg['all_exts']:
self.cfg.update('configopts', "-DTrilinos_ENABLE_ALL_PACKAGES:BOOL=ON")
else:
for ext in self.cfg['exts_list']:
self.cfg.update('configopts', "-DTrilinos_ENABLE_%s=ON" % ext)
# packages to skip
skip_exts = self.cfg['skip_exts']
if skip_exts:
for ext in skip_exts:
self.cfg.update('configopts', "-DTrilinos_ENABLE_%s:BOOL=OFF" % ext)
# building in source dir not supported
# + if the build directory is a long path, problems like "Argument list too long" may occur
# cfr. https://github.com/trilinos/Trilinos/issues/2434
# so, try to create build directory with shorter path length to build in
salt = ''.join(random.choice(ascii_letters) for _ in range(5))
self.short_start_dir = os.path.join(build_path(), self.name + '-' + salt)
if os.path.exists(self.short_start_dir):
raise EasyBuildError("Short start directory %s for Trilinos already exists?!", self.short_start_dir)
self.log.info("Length of path to original start directory: %s", len(self.start_dir))
self.log.info("Short start directory: %s (length: %d)", self.short_start_dir, len(self.short_start_dir))
mkdir(self.short_start_dir)
short_src_dir = os.path.join(self.short_start_dir, 'src')
symlink(self.start_dir, short_src_dir)
short_build_dir = os.path.join(self.short_start_dir, 'obj')
obj_dir = os.path.join(self.builddir, 'obj')
mkdir(obj_dir)
symlink(obj_dir, short_build_dir)
# configure using cmake
super(EB_Trilinos, self).configure_step(srcdir=short_src_dir, builddir=short_build_dir)
def build_step(self):
"""Build with make (verbose logging enabled)."""
super(EB_Trilinos, self).build_step(verbose=True)
def sanity_check_step(self):
"""Custom sanity check for Trilinos."""
# selection of libraries
libs = ["Amesos", "Anasazi", "AztecOO", "Belos", "Epetra", "Galeri",
"GlobiPack", "Ifpack", "Intrepid", "Isorropia", "Kokkos",
"Komplex", "LOCA", "Mesquite", "ML", "Moertel", "MOOCHO", "NOX",
"Pamgen", "RTOp", "Rythmos", "Sacado", "Shards", "Stratimikos",
"Teuchos", "Tpetra", "Triutils", "Zoltan"]
libs = [x for x in libs if x not in self.cfg['skip_exts']]
# Teuchos was refactored in 11.2
if LooseVersion(self.version) >= LooseVersion('11.2') and 'Teuchos' in libs:
libs.remove('Teuchos')
libs.extend(['teuchoscomm', 'teuchoscore', 'teuchosnumerics', 'teuchosparameterlist', 'teuchosremainder'])
# Kokkos was refactored in 12.x, check for libkokkoscore.a rather than libkokkos.a
if LooseVersion(self.version) >= LooseVersion('12') and 'Kokkos' in libs:
libs.remove('Kokkos')
libs.append('kokkoscore')
# libgaleri was split into libgaleri-epetra & libgaleri-xpetra
if LooseVersion(self.version) >= LooseVersion('12.6'):
libs.remove('Galeri')
libs.extend(['galeri-epetra', 'galeri-xpetra'])
# Get the library extension
if self.cfg['build_shared_libs']:
lib_ext = get_shared_lib_ext()
else:
lib_ext = 'a'
custom_paths = {
'files': [os.path.join('lib', 'lib%s.%s' % (x.lower(), lib_ext)) for x in libs],
'dirs': ['bin', 'include']
}
super(EB_Trilinos, self).sanity_check_step(custom_paths=custom_paths)
def cleanup_step(self):
"""Complete cleanup by also removing custom created short build directory."""
remove_dir(self.short_start_dir)
|
gpl-2.0
|
[
309,
199,
3,
1898,
8937,
13,
13934,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
30025,
12,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
1544,
14,
86,
10845,
454,
453,
14,
1235,
395,
199,
3,
481,
274,
1292,
72,
26993,
2752,
334,
38,
11325,
9,
334,
1014,
921,
1544,
14,
70,
2027,
14,
1235,
15,
287,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
4178,
921,
5031,
14,
957,
15,
13581,
20968,
15,
13581,
1506,
199,
3,
199,
3,
30025,
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,
373,
18,
14,
199,
3,
199,
3,
30025,
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,
30025,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
624,
199,
28326,
3425,
2291,
367,
12480,
472,
736,
12,
6366,
465,
376,
8837,
1457,
199,
199,
32,
2502,
26,
1804,
287,
685,
273,
869,
736,
266,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
646,
747,
199,
646,
2196,
199,
646,
295,
199,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
646,
8837,
1506,
14,
2537,
14,
22572,
465,
22689,
199,
504,
8837,
1506,
14,
13581,
4166,
14,
6767,
14,
16472,
1875,
492,
21355,
5483,
199,
504,
8837,
1506,
14,
4857,
14,
13581,
888,
492,
445,
7698,
7474,
199,
504,
8837,
1506,
14,
2537,
14,
1506,
63,
793,
492,
30025,
547,
199,
504,
8837,
1506,
14,
2537,
14,
888,
492,
1900,
63,
515,
199,
504,
8837,
1506,
14,
2537,
14,
493,
2537,
492,
20366,
12,
2813,
63,
694,
12,
15296,
199,
504,
8837,
1506,
14,
2537,
14,
3112,
492,
664,
63,
15619,
63,
1231,
199,
504,
8837,
1506,
14,
2537,
14,
647,
18,
3122,
19,
492,
13294,
63,
16415,
199,
504,
8837,
1506,
14,
2537,
14,
2253,
2537,
492,
664,
63,
5555,
63,
773,
63,
832,
421,
199,
533,
662,
34,
63,
6948,
472,
736,
8,
27984,
5483,
304,
272,
408,
11532,
367,
10015,
12480,
472,
736,
1041,
272,
327,
1937,
1455,
921,
599,
472,
736,
14,
18904,
2391,
14,
16294,
15,
6948,
472,
736,
709,
27984,
19684,
928,
14,
2424,
339,
768,
4639,
272,
347,
2402,
63,
1419,
837,
267,
408,
1123,
2402,
1101,
1511,
2488,
370,
12480,
472,
736,
1041,
267,
2402,
63,
2936,
275,
469,
288,
283,
5555,
63,
8450,
356,
359,
403,
12,
298,
19727,
14,
3645,
1900,
63,
5555,
63,
8450,
401,
445,
7698,
7474,
467,
288,
283,
1490,
311,
356,
359,
549,
12,
298,
6476,
3232,
1658,
2291,
401,
445,
7698,
7474,
467,
288,
283,
452,
63,
25752,
356,
359,
549,
12,
298,
6476,
1006,
12480,
472,
736,
6117,
401,
445,
7698,
7474,
467,
288,
283,
2759,
63,
25752,
356,
3474,
467,
298,
1296,
402,
12480,
472,
736,
6117,
370,
3372,
401,
445,
7698,
7474,
467,
288,
283,
3832,
356,
359,
797,
12,
298,
17324,
367,
3376,
1072,
401,
445,
7698,
7474,
467,
267,
789,
267,
372,
21355,
5483,
14,
2911,
63,
1419,
8,
2911,
63,
2936,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
11447,
402,
3537,
8837,
1457,
367,
12480,
472,
736,
1041,
267,
1613,
8,
14138,
63,
6948,
472,
736,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
340,
291,
14,
4128,
459,
5555,
63,
8450,
418,
365,
440,
488,
26,
288,
291,
14,
793,
14,
6667,
480,
6119,
283,
1506,
63,
5555,
63,
8450,
7,
3140,
402,
283,
5555,
63,
8450,
7,
8837,
888,
2725,
401,
283,
21,
14,
16,
358,
288,
291,
14,
4128,
459,
1506,
63,
5555,
63,
8450,
418,
275,
291,
14,
4128,
459,
5555,
63,
8450,
418,
339,
347,
7908,
63,
2926,
8,
277,
304,
267,
408,
1084,
2005,
2402,
3734,
2860,
2544,
1101,
4039,
1041,
398,
327,
4756,
3376,
1072,
340,
6387,
267,
340,
291,
14,
4128,
459,
3832,
2565,
288,
367,
671,
315,
2097,
5569,
3942,
401,
298,
18421,
3817,
6229,
355,
291,
14,
4128,
14,
873,
360,
888,
3291,
297,
3905,
36,
6948,
472,
736,
63,
16075,
4970,
83,
26,
16026,
29,
615,
2,
450,
671,
9,
398,
327,
6365,
3285,
267,
13426,
275,
359,
736,
14,
12959,
360,
14804,
5440,
267,
17280,
1949,
1550,
275,
359,
736,
14,
12959,
360,
26180,
5440,
267,
289,
2469,
275,
359,
736,
14,
12959,
360,
1665,
44,
1254,
51,
5440,
398,
3686,
63,
9634,
63,
5507,
63,
311,
374,
275,
359,
22572,
14,
28859,
28983,
12,
22689,
14,
1658,
948,
40,
12,
1816,
22689,
14,
1658,
948,
40,
18,
12,
22689,
14,
25875,
1282,
948,
40,
18,
61,
221,
327,
768,
16283,
2773,
267,
3686,
63,
9634,
63,
5507,
63,
4173,
275,
3905,
36,
1658,
948,
40,
63,
11209,
63,
12206,
63,
18439,
2,
267,
340,
291,
14,
22572,
14,
13213,
63,
6606,
342,
315,
3686,
63,
9634,
63,
5507,
63,
311,
374,
26,
288,
13426,
14,
740,
8,
4247,
63,
9634,
63,
5507,
63,
4173,
9,
288,
17280,
1949,
1550,
14,
740,
8,
4247,
63,
9634,
63,
5507,
63,
4173,
9,
288,
289,
2469,
14,
740,
8,
4247,
63,
9634,
63,
5507,
63,
4173,
9,
398,
291,
14
] |
[
199,
3,
1898,
8937,
13,
13934,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
30025,
12,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
1544,
14,
86,
10845,
454,
453,
14,
1235,
395,
199,
3,
481,
274,
1292,
72,
26993,
2752,
334,
38,
11325,
9,
334,
1014,
921,
1544,
14,
70,
2027,
14,
1235,
15,
287,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
4178,
921,
5031,
14,
957,
15,
13581,
20968,
15,
13581,
1506,
199,
3,
199,
3,
30025,
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,
373,
18,
14,
199,
3,
199,
3,
30025,
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,
30025,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
624,
199,
28326,
3425,
2291,
367,
12480,
472,
736,
12,
6366,
465,
376,
8837,
1457,
199,
199,
32,
2502,
26,
1804,
287,
685,
273,
869,
736,
266,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
646,
747,
199,
646,
2196,
199,
646,
295,
199,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
646,
8837,
1506,
14,
2537,
14,
22572,
465,
22689,
199,
504,
8837,
1506,
14,
13581,
4166,
14,
6767,
14,
16472,
1875,
492,
21355,
5483,
199,
504,
8837,
1506,
14,
4857,
14,
13581,
888,
492,
445,
7698,
7474,
199,
504,
8837,
1506,
14,
2537,
14,
1506,
63,
793,
492,
30025,
547,
199,
504,
8837,
1506,
14,
2537,
14,
888,
492,
1900,
63,
515,
199,
504,
8837,
1506,
14,
2537,
14,
493,
2537,
492,
20366,
12,
2813,
63,
694,
12,
15296,
199,
504,
8837,
1506,
14,
2537,
14,
3112,
492,
664,
63,
15619,
63,
1231,
199,
504,
8837,
1506,
14,
2537,
14,
647,
18,
3122,
19,
492,
13294,
63,
16415,
199,
504,
8837,
1506,
14,
2537,
14,
2253,
2537,
492,
664,
63,
5555,
63,
773,
63,
832,
421,
199,
533,
662,
34,
63,
6948,
472,
736,
8,
27984,
5483,
304,
272,
408,
11532,
367,
10015,
12480,
472,
736,
1041,
272,
327,
1937,
1455,
921,
599,
472,
736,
14,
18904,
2391,
14,
16294,
15,
6948,
472,
736,
709,
27984,
19684,
928,
14,
2424,
339,
768,
4639,
272,
347,
2402,
63,
1419,
837,
267,
408,
1123,
2402,
1101,
1511,
2488,
370,
12480,
472,
736,
1041,
267,
2402,
63,
2936,
275,
469,
288,
283,
5555,
63,
8450,
356,
359,
403,
12,
298,
19727,
14,
3645,
1900,
63,
5555,
63,
8450,
401,
445,
7698,
7474,
467,
288,
283,
1490,
311,
356,
359,
549,
12,
298,
6476,
3232,
1658,
2291,
401,
445,
7698,
7474,
467,
288,
283,
452,
63,
25752,
356,
359,
549,
12,
298,
6476,
1006,
12480,
472,
736,
6117,
401,
445,
7698,
7474,
467,
288,
283,
2759,
63,
25752,
356,
3474,
467,
298,
1296,
402,
12480,
472,
736,
6117,
370,
3372,
401,
445,
7698,
7474,
467,
288,
283,
3832,
356,
359,
797,
12,
298,
17324,
367,
3376,
1072,
401,
445,
7698,
7474,
467,
267,
789,
267,
372,
21355,
5483,
14,
2911,
63,
1419,
8,
2911,
63,
2936,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
11447,
402,
3537,
8837,
1457,
367,
12480,
472,
736,
1041,
267,
1613,
8,
14138,
63,
6948,
472,
736,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
340,
291,
14,
4128,
459,
5555,
63,
8450,
418,
365,
440,
488,
26,
288,
291,
14,
793,
14,
6667,
480,
6119,
283,
1506,
63,
5555,
63,
8450,
7,
3140,
402,
283,
5555,
63,
8450,
7,
8837,
888,
2725,
401,
283,
21,
14,
16,
358,
288,
291,
14,
4128,
459,
1506,
63,
5555,
63,
8450,
418,
275,
291,
14,
4128,
459,
5555,
63,
8450,
418,
339,
347,
7908,
63,
2926,
8,
277,
304,
267,
408,
1084,
2005,
2402,
3734,
2860,
2544,
1101,
4039,
1041,
398,
327,
4756,
3376,
1072,
340,
6387,
267,
340,
291,
14,
4128,
459,
3832,
2565,
288,
367,
671,
315,
2097,
5569,
3942,
401,
298,
18421,
3817,
6229,
355,
291,
14,
4128,
14,
873,
360,
888,
3291,
297,
3905,
36,
6948,
472,
736,
63,
16075,
4970,
83,
26,
16026,
29,
615,
2,
450,
671,
9,
398,
327,
6365,
3285,
267,
13426,
275,
359,
736,
14,
12959,
360,
14804,
5440,
267,
17280,
1949,
1550,
275,
359,
736,
14,
12959,
360,
26180,
5440,
267,
289,
2469,
275,
359,
736,
14,
12959,
360,
1665,
44,
1254,
51,
5440,
398,
3686,
63,
9634,
63,
5507,
63,
311,
374,
275,
359,
22572,
14,
28859,
28983,
12,
22689,
14,
1658,
948,
40,
12,
1816,
22689,
14,
1658,
948,
40,
18,
12,
22689,
14,
25875,
1282,
948,
40,
18,
61,
221,
327,
768,
16283,
2773,
267,
3686,
63,
9634,
63,
5507,
63,
4173,
275,
3905,
36,
1658,
948,
40,
63,
11209,
63,
12206,
63,
18439,
2,
267,
340,
291,
14,
22572,
14,
13213,
63,
6606,
342,
315,
3686,
63,
9634,
63,
5507,
63,
311,
374,
26,
288,
13426,
14,
740,
8,
4247,
63,
9634,
63,
5507,
63,
4173,
9,
288,
17280,
1949,
1550,
14,
740,
8,
4247,
63,
9634,
63,
5507,
63,
4173,
9,
288,
289,
2469,
14,
740,
8,
4247,
63,
9634,
63,
5507,
63,
4173,
9,
398,
291,
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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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
] |
zhujianwei31415/dcnnfold
|
scripts/evaluation/evaluate_spec_sens_three_levels.py
|
2
|
1892
|
#! /usr/bin/env python
#
# Copyright
# Author: zhujianwei@ict.ac.cn (Jianwei Zhu)
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import sys
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import average_precision_score
# read in score function
def read_score(score_file):
labels, values = [], []
with open(score_file, 'r') as fin:
for line in fin:
cols = line.split()
labels.append(0 if cols[0] == '-1' else 1)
values.append(float(cols[1]))
return np.array(labels), np.array(values)
# calculate specificity and sensitivity
def cal_spec_sens(y_test, y_score):
spec, sens, _ = precision_recall_curve(y_test, y_score)
return spec, sens
# write specificity and sensitivity
def write_spect_sens(spec, sens, outfile):
with open(outfile, 'w') as fout:
for j, _ in enumerate(spec):
print('%10.8f %10.8f' % (spec[j], sens[j]), file=fout)
def main(family_score, superfamily_score, fold_score):
# calculate family level
y_test, y_score = read_score(family_score)
spec, sens = cal_spec_sens(y_test, y_score)
write_spect_sens(spec, sens, 'spec-sens-family')
# calculate superfamily level
y_test, y_score = read_score(superfamily_score)
spec, sens = cal_spec_sens(y_test, y_score)
write_spect_sens(spec, sens, 'spec-sens-superfamily')
# calculate fold level
y_test, y_score = read_score(fold_score)
spec, sens = cal_spec_sens(y_test, y_score)
write_spect_sens(spec, sens, 'spec-sens-fold')
if __name__ == '__main__':
if len(sys.argv) != 4:
sys.exit('Usage: %s <value-family> <value-superfamily> <value-fold>' % sys.argv[0])
family_score, superfamily_score, fold_score = sys.argv[1:]
main(family_score, superfamily_score, fold_score)
|
gpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
199,
3,
6529,
26,
1315,
10616,
74,
5653,
21431,
32,
73,
319,
14,
645,
14,
6413,
334,
42,
5653,
21431,
3107,
10616,
9,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
646,
984,
199,
504,
6357,
14,
6759,
492,
7151,
63,
19183,
63,
11895,
199,
504,
6357,
14,
6759,
492,
8095,
63,
6833,
63,
3397,
199,
199,
3,
1586,
315,
5396,
805,
199,
318,
1586,
63,
3397,
8,
3397,
63,
493,
304,
272,
3628,
12,
1338,
275,
990,
942,
272,
543,
1551,
8,
3397,
63,
493,
12,
283,
82,
358,
465,
2583,
26,
267,
367,
1004,
315,
2583,
26,
288,
8850,
275,
1004,
14,
1294,
342,
288,
3628,
14,
740,
8,
16,
340,
8850,
59,
16,
61,
508,
2475,
17,
7,
587,
413,
9,
288,
1338,
14,
740,
8,
1609,
8,
4574,
59,
17,
2459,
272,
372,
980,
14,
1144,
8,
3512,
395,
980,
14,
1144,
8,
1459,
9,
199,
199,
3,
8671,
1106,
329,
3690,
436,
4334,
20635,
199,
318,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
304,
272,
3158,
12,
542,
561,
12,
485,
275,
7151,
63,
19183,
63,
11895,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
372,
3158,
12,
542,
561,
199,
199,
3,
2218,
1106,
329,
3690,
436,
4334,
20635,
199,
318,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
4386,
304,
272,
543,
1551,
8,
4984,
12,
283,
87,
358,
465,
17863,
26,
267,
367,
1335,
12,
485,
315,
3874,
8,
1650,
304,
288,
870,
3508,
709,
14,
24,
70,
221,
450,
709,
14,
24,
70,
7,
450,
334,
1650,
59,
74,
467,
542,
561,
59,
74,
2522,
570,
29,
30762,
9,
199,
199,
318,
2446,
8,
6606,
63,
3397,
12,
1613,
6606,
63,
3397,
12,
20675,
63,
3397,
304,
272,
327,
8671,
9614,
2166,
272,
612,
63,
396,
12,
612,
63,
3397,
275,
1586,
63,
3397,
8,
6606,
63,
3397,
9,
272,
3158,
12,
542,
561,
275,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
283,
1650,
13,
22891,
13,
6606,
358,
272,
327,
8671,
1613,
6606,
2166,
272,
612,
63,
396,
12,
612,
63,
3397,
275,
1586,
63,
3397,
8,
4792,
6606,
63,
3397,
9,
272,
3158,
12,
542,
561,
275,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
283,
1650,
13,
22891,
13,
4792,
6606,
358,
272,
327,
8671,
20675,
2166,
272,
612,
63,
396,
12,
612,
63,
3397,
275,
1586,
63,
3397,
8,
14011,
63,
3397,
9,
272,
3158,
12,
542,
561,
275,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
283,
1650,
13,
22891,
13,
14011,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
841,
26,
267,
984,
14,
2224,
360,
7692,
26,
450,
83,
665,
585,
13,
6606,
30,
665,
585,
13,
4792,
6606,
30,
665,
585,
13,
14011,
3524,
450,
984,
14,
3020,
59,
16,
566,
272,
9614,
63,
3397,
12,
1613,
6606,
63,
3397,
12,
20675,
63,
3397,
275,
984,
14,
3020,
59,
17,
2938,
2286,
2446,
8,
6606,
63,
3397,
12,
1613,
6606,
63,
3397,
12,
20675,
63,
3397,
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
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
199,
3,
6529,
26,
1315,
10616,
74,
5653,
21431,
32,
73,
319,
14,
645,
14,
6413,
334,
42,
5653,
21431,
3107,
10616,
9,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
646,
984,
199,
504,
6357,
14,
6759,
492,
7151,
63,
19183,
63,
11895,
199,
504,
6357,
14,
6759,
492,
8095,
63,
6833,
63,
3397,
199,
199,
3,
1586,
315,
5396,
805,
199,
318,
1586,
63,
3397,
8,
3397,
63,
493,
304,
272,
3628,
12,
1338,
275,
990,
942,
272,
543,
1551,
8,
3397,
63,
493,
12,
283,
82,
358,
465,
2583,
26,
267,
367,
1004,
315,
2583,
26,
288,
8850,
275,
1004,
14,
1294,
342,
288,
3628,
14,
740,
8,
16,
340,
8850,
59,
16,
61,
508,
2475,
17,
7,
587,
413,
9,
288,
1338,
14,
740,
8,
1609,
8,
4574,
59,
17,
2459,
272,
372,
980,
14,
1144,
8,
3512,
395,
980,
14,
1144,
8,
1459,
9,
199,
199,
3,
8671,
1106,
329,
3690,
436,
4334,
20635,
199,
318,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
304,
272,
3158,
12,
542,
561,
12,
485,
275,
7151,
63,
19183,
63,
11895,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
372,
3158,
12,
542,
561,
199,
199,
3,
2218,
1106,
329,
3690,
436,
4334,
20635,
199,
318,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
4386,
304,
272,
543,
1551,
8,
4984,
12,
283,
87,
358,
465,
17863,
26,
267,
367,
1335,
12,
485,
315,
3874,
8,
1650,
304,
288,
870,
3508,
709,
14,
24,
70,
221,
450,
709,
14,
24,
70,
7,
450,
334,
1650,
59,
74,
467,
542,
561,
59,
74,
2522,
570,
29,
30762,
9,
199,
199,
318,
2446,
8,
6606,
63,
3397,
12,
1613,
6606,
63,
3397,
12,
20675,
63,
3397,
304,
272,
327,
8671,
9614,
2166,
272,
612,
63,
396,
12,
612,
63,
3397,
275,
1586,
63,
3397,
8,
6606,
63,
3397,
9,
272,
3158,
12,
542,
561,
275,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
283,
1650,
13,
22891,
13,
6606,
358,
272,
327,
8671,
1613,
6606,
2166,
272,
612,
63,
396,
12,
612,
63,
3397,
275,
1586,
63,
3397,
8,
4792,
6606,
63,
3397,
9,
272,
3158,
12,
542,
561,
275,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
283,
1650,
13,
22891,
13,
4792,
6606,
358,
272,
327,
8671,
20675,
2166,
272,
612,
63,
396,
12,
612,
63,
3397,
275,
1586,
63,
3397,
8,
14011,
63,
3397,
9,
272,
3158,
12,
542,
561,
275,
3213,
63,
1650,
63,
22891,
8,
89,
63,
396,
12,
612,
63,
3397,
9,
272,
2218,
63,
20865,
63,
22891,
8,
1650,
12,
542,
561,
12,
283,
1650,
13,
22891,
13,
14011,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
841,
26,
267,
984,
14,
2224,
360,
7692,
26,
450,
83,
665,
585,
13,
6606,
30,
665,
585,
13,
4792,
6606,
30,
665,
585,
13,
14011,
3524,
450,
984,
14,
3020,
59,
16,
566,
272,
9614,
63,
3397,
12,
1613,
6606,
63,
3397,
12,
20675,
63,
3397,
275,
984,
14,
3020,
59,
17,
2938,
2286,
2446,
8,
6606,
63,
3397,
12,
1613,
6606,
63,
3397,
12,
20675,
63,
3397,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ndonegan/oz
|
oz/Fedora.py
|
1
|
6739
|
# Copyright (C) 2010,2011 Chris Lalancette <clalance@redhat.com>
# Copyright (C) 2012-2017 Chris Lalancette <clalancette@gmail.com>
# 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;
# version 2.1 of the License.
# 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
"""
Fedora installation
"""
import os
import oz.ozutil
import oz.RedHat
import oz.OzException
class FedoraGuest(oz.RedHat.RedHatLinuxCDYumGuest):
"""
Class for Fedora 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, and 25 installation.
"""
def __init__(self, tdl, config, auto, nicmodel, haverepo, diskbus,
brokenisomethod, output_disk=None, macaddress=None,
assumed_update=None):
directkernel = "cpio"
if tdl.update in ["16", "17"]:
directkernel = None
self.assumed_update = assumed_update
# Prior to Fedora-22, we use yum; on F-22 and later, we use dnf.
# Express that preference here.
use_yum = True
if tdl.update in ["22", "23", "24", "25"]:
use_yum = False
oz.RedHat.RedHatLinuxCDYumGuest.__init__(self, tdl, config, auto,
output_disk, nicmodel, diskbus,
True, True, directkernel,
macaddress, use_yum)
if self.assumed_update is not None:
self.log.warning("==== WARN: TDL contains Fedora update %s, which is newer than Oz knows about; pretending this is Fedora %s, but this may fail ====", tdl.update, assumed_update)
self.haverepo = haverepo
self.brokenisomethod = brokenisomethod
if self.tdl.update in ["14", "15", "16", "17", "18", "19", "20", "21",
"22", "23", "24", "25"]:
self.virtio_channel_name = 'org.fedoraproject.anaconda.log.0'
def _modify_iso(self):
"""
Method to modify the ISO for autoinstallation.
"""
self._copy_kickstart(os.path.join(self.iso_contents, "ks.cfg"))
if self.tdl.update in ["17", "18", "19", "20", "21", "22", "23", "24", "25"]:
initrdline = " append initrd=initrd.img ks=cdrom:/dev/cdrom:/ks.cfg"
else:
initrdline = " append initrd=initrd.img ks=cdrom:/ks.cfg"
if self.tdl.installtype == "url":
if self.haverepo:
initrdline += " repo="
else:
initrdline += " method="
initrdline += self.url + "\n"
else:
# if the installtype is iso, then due to a bug in anaconda we leave
# out the method completely
if not self.brokenisomethod:
initrdline += " method=cdrom:/dev/cdrom"
initrdline += "\n"
self._modify_isolinux(initrdline)
def generate_diskimage(self, size=10, force=False):
"""
Method to generate a diskimage. By default, a blank diskimage of
10GB will be created; the caller can override this with the size
parameter, specified in GB. If force is False (the default), then
a diskimage will not be created if a cached JEOS is found. If
force is True, a diskimage will be created regardless of whether a
cached JEOS exists. See the oz-install man page for more
information about JEOS caching.
"""
createpart = False
if self.tdl.update in ["11", "12"]:
# If given a blank diskimage, Fedora 11/12 stops very early in
# install with a message about losing all of your data on the
# drive (it differs between them).
#
# To avoid that message, just create a partition table that spans
# the entire disk
createpart = True
return self._internal_generate_diskimage(size, force, createpart)
def get_auto_path(self):
"""
Method to create the correct path to the Fedora kickstart files.
"""
# If we are doing our best with an unknown Fedora update, use the
# newest known auto file; otherwise, do the usual thing.
if self.assumed_update is not None:
return oz.ozutil.generate_full_auto_path(self.tdl.distro + self.assumed_update + ".auto")
else:
return oz.ozutil.generate_full_auto_path(self.tdl.distro + self.tdl.update + ".auto")
def get_class(tdl, config, auto, output_disk=None, netdev=None, diskbus=None,
macaddress=None):
"""
Factory method for Fedora installs.
"""
# The newer_distros list is actually a list of distros that have similar
# installation requirements. Thus, even if the particular distro isn't
# supported anymore, it should not be removed from the list.
newer_distros = ["19", "20", "21", "22", "23", "24", "25"]
if tdl.update == 'rawhide' or int(tdl.update) > int(newer_distros[-1]):
if netdev is None:
netdev = 'virtio'
if diskbus is None:
diskbus = 'virtio'
return FedoraGuest(tdl, config, auto, netdev, True, diskbus, False,
output_disk, macaddress, newer_distros[-1])
if tdl.update in newer_distros:
if netdev is None:
netdev = 'virtio'
if diskbus is None:
diskbus = 'virtio'
return FedoraGuest(tdl, config, auto, netdev, True, diskbus, False,
output_disk, macaddress, None)
if tdl.update in ["9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]:
if netdev is None:
netdev = 'virtio'
if diskbus is None:
diskbus = 'virtio'
return FedoraGuest(tdl, config, auto, netdev, True, diskbus, True,
output_disk, macaddress, None)
if tdl.update in ["7", "8"]:
return FedoraGuest(tdl, config, auto, netdev, False, diskbus, False,
output_disk, macaddress, None)
def get_supported_string():
"""
Return supported versions as a string.
"""
return "Fedora: 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25"
|
lgpl-2.1
|
[
3,
1898,
334,
35,
9,
7129,
12,
8128,
221,
2799,
5719,
491,
279,
554,
14586,
665,
429,
279,
554,
32,
17164,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6029,
13,
10680,
221,
2799,
5719,
491,
279,
554,
14586,
665,
429,
279,
554,
14586,
32,
6799,
14,
957,
30,
199,
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,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
14,
199,
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,
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,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
624,
199,
38,
379,
11131,
12096,
199,
624,
199,
199,
646,
747,
199,
199,
646,
312,
90,
14,
26051,
1974,
199,
646,
312,
90,
14,
10858,
40,
292,
199,
646,
312,
90,
14,
47,
90,
1726,
199,
199,
533,
481,
379,
11131,
16022,
8,
26051,
14,
10858,
40,
292,
14,
10858,
40,
292,
14091,
7695,
57,
453,
16022,
304,
272,
408,
272,
8089,
367,
481,
379,
11131,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
3144,
12,
4944,
12,
4329,
12,
4114,
12,
3193,
12,
5557,
12,
6155,
12,
5851,
12,
3388,
12,
7829,
12,
6928,
12,
6546,
12,
5504,
12,
436,
5661,
12096,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
307,
5030,
12,
1101,
12,
2599,
12,
14304,
1238,
12,
1172,
3417,
12,
4543,
5610,
12,
326,
10529,
4595,
765,
12,
1072,
63,
4032,
29,
403,
12,
4497,
1562,
29,
403,
12,
326,
10826,
63,
873,
29,
403,
304,
267,
4125,
4989,
275,
298,
67,
13937,
2,
267,
340,
307,
5030,
14,
873,
315,
2097,
975,
401,
298,
1196,
6229,
288,
4125,
4989,
275,
488,
267,
291,
14,
21946,
68,
63,
873,
275,
10826,
63,
873,
398,
327,
8538,
269,
370,
481,
379,
11131,
13,
1081,
12,
781,
675,
24717,
27,
641,
481,
13,
1081,
436,
2945,
12,
781,
675,
28215,
14,
267,
327,
1316,
2915,
626,
16705,
2348,
14,
267,
675,
63,
22108,
275,
715,
267,
340,
307,
5030,
14,
873,
315,
2097,
1081,
401,
298,
1789,
401,
298,
1194,
401,
298,
821,
6229,
288,
675,
63,
22108,
275,
756,
267,
312,
90,
14,
10858,
40,
292,
14,
10858,
40,
292,
14091,
7695,
57,
453,
16022,
855,
826,
721,
277,
12,
307,
5030,
12,
1101,
12,
2599,
12,
1740,
1072,
63,
4032,
12,
14304,
1238,
12,
4543,
5610,
12,
1740,
715,
12,
715,
12,
4125,
4989,
12,
1740,
4497,
1562,
12,
675,
63,
22108,
9,
398,
340,
291,
14,
21946,
68,
63,
873,
365,
440,
488,
26,
288,
291,
14,
793,
14,
3764,
480,
532,
13253,
46,
26,
377,
8045,
3509,
481,
379,
11131,
1678,
450,
83,
12,
1314,
365,
15666,
2419,
593,
90,
19428,
3595,
27,
876,
724,
1098,
642,
365,
481,
379,
11131,
450,
83,
12,
1325,
642,
1443,
2449,
275,
5918,
401,
307,
5030,
14,
873,
12,
10826,
63,
873,
9,
398,
291,
14,
7804,
3417,
275,
1172,
3417,
267,
291,
14,
15697,
4595,
765,
275,
10529,
4595,
765,
267,
340,
291,
14,
2076,
76,
14,
873,
315,
2097,
1079,
401,
298,
1046,
401,
298,
975,
401,
298,
1196,
401,
298,
1085,
401,
298,
1167,
401,
298,
1165,
401,
298,
2025,
401,
3044,
298,
1081,
401,
298,
1789,
401,
298,
1194,
401,
298,
821,
6229,
288,
291,
14,
1042,
4538,
63,
2775,
63,
354,
275,
283,
1308,
14,
15800,
269,
30204,
963,
14,
28299,
14,
793,
14,
16,
7,
339,
347,
485,
8951,
63,
4595,
8,
277,
304,
267,
408,
267,
9075,
370,
2811,
314,
9055,
367,
2599,
23048,
14,
267,
408,
267,
291,
423,
1574,
63,
30784,
8,
736,
14,
515,
14,
904,
8,
277,
14,
4595,
63,
4407,
12,
298,
6080,
14,
4128,
2237,
398,
340,
291,
14,
2076,
76,
14,
873,
315,
2097,
1196,
401,
298,
1085,
401,
298,
1167,
401,
298,
1165,
401,
298,
2025,
401,
298,
1081,
401,
298,
1789,
401,
298,
1194,
401,
298,
821,
6229,
288,
4205,
6883,
604,
275,
298,
221,
5666,
4205,
6883,
29,
826,
6883,
14,
4060,
15357,
29,
2866,
417,
11254,
2374,
15,
2866,
417,
11254,
6080,
14,
4128,
2,
267,
587,
26,
288,
4205,
6883,
604,
275,
298,
221,
5666,
4205,
6883,
29,
826,
6883,
14,
4060,
15357,
29,
2866,
417,
11254,
6080,
14,
4128,
2,
267,
340,
291,
14,
2076,
76,
14,
3174,
466,
508,
298,
633,
582,
288,
340,
291,
14,
7804,
3417,
26,
355,
4205,
6883,
604,
847,
298,
3831,
628,
288,
587,
26,
355,
4205,
6883,
604,
847,
298,
1083,
628,
288,
4205,
6883,
604,
847,
291,
14,
633,
435,
1867,
78,
2,
267,
587,
26,
288,
327,
340,
314,
3907,
466,
365,
11601,
12,
2066,
7037,
370,
282,
6519,
315,
376,
16928,
983,
781,
10137,
288,
327,
734,
314,
1083,
14793,
288,
340,
440,
291,
14,
15697,
4595,
765,
26,
355,
4205,
6883,
604,
847,
298,
1083,
29,
2866,
417,
11254,
2374,
15,
2866,
417,
2,
288,
4205,
6883,
604,
847,
1867,
78,
2,
267,
291,
423,
8951,
63,
374,
393,
7226,
8,
826,
6883,
604,
9,
339,
347,
3550,
63,
4032,
1569,
8,
277,
12,
1568,
29,
709,
12,
3542,
29,
797,
304,
267,
408,
267,
9075,
370,
3550,
282,
4543,
1569,
14,
221,
4885,
849,
12,
282,
4596,
4543,
1569,
402,
267,
1616,
6487,
911,
506,
2737,
27,
314,
8025,
883,
4278,
642,
543,
314,
1568,
267,
2725,
12,
2013,
315,
18553,
14,
221,
982,
3542,
365,
756,
334,
1589,
849,
395,
2066,
267,
282,
4543,
1569,
911,
440,
506,
2737,
340,
282,
6328,
1603,
37,
3100
] |
[
1898,
334,
35,
9,
7129,
12,
8128,
221,
2799,
5719,
491,
279,
554,
14586,
665,
429,
279,
554,
32,
17164,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6029,
13,
10680,
221,
2799,
5719,
491,
279,
554,
14586,
665,
429,
279,
554,
14586,
32,
6799,
14,
957,
30,
199,
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,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
14,
199,
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,
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,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
624,
199,
38,
379,
11131,
12096,
199,
624,
199,
199,
646,
747,
199,
199,
646,
312,
90,
14,
26051,
1974,
199,
646,
312,
90,
14,
10858,
40,
292,
199,
646,
312,
90,
14,
47,
90,
1726,
199,
199,
533,
481,
379,
11131,
16022,
8,
26051,
14,
10858,
40,
292,
14,
10858,
40,
292,
14091,
7695,
57,
453,
16022,
304,
272,
408,
272,
8089,
367,
481,
379,
11131,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
3144,
12,
4944,
12,
4329,
12,
4114,
12,
3193,
12,
5557,
12,
6155,
12,
5851,
12,
3388,
12,
7829,
12,
6928,
12,
6546,
12,
5504,
12,
436,
5661,
12096,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
307,
5030,
12,
1101,
12,
2599,
12,
14304,
1238,
12,
1172,
3417,
12,
4543,
5610,
12,
326,
10529,
4595,
765,
12,
1072,
63,
4032,
29,
403,
12,
4497,
1562,
29,
403,
12,
326,
10826,
63,
873,
29,
403,
304,
267,
4125,
4989,
275,
298,
67,
13937,
2,
267,
340,
307,
5030,
14,
873,
315,
2097,
975,
401,
298,
1196,
6229,
288,
4125,
4989,
275,
488,
267,
291,
14,
21946,
68,
63,
873,
275,
10826,
63,
873,
398,
327,
8538,
269,
370,
481,
379,
11131,
13,
1081,
12,
781,
675,
24717,
27,
641,
481,
13,
1081,
436,
2945,
12,
781,
675,
28215,
14,
267,
327,
1316,
2915,
626,
16705,
2348,
14,
267,
675,
63,
22108,
275,
715,
267,
340,
307,
5030,
14,
873,
315,
2097,
1081,
401,
298,
1789,
401,
298,
1194,
401,
298,
821,
6229,
288,
675,
63,
22108,
275,
756,
267,
312,
90,
14,
10858,
40,
292,
14,
10858,
40,
292,
14091,
7695,
57,
453,
16022,
855,
826,
721,
277,
12,
307,
5030,
12,
1101,
12,
2599,
12,
1740,
1072,
63,
4032,
12,
14304,
1238,
12,
4543,
5610,
12,
1740,
715,
12,
715,
12,
4125,
4989,
12,
1740,
4497,
1562,
12,
675,
63,
22108,
9,
398,
340,
291,
14,
21946,
68,
63,
873,
365,
440,
488,
26,
288,
291,
14,
793,
14,
3764,
480,
532,
13253,
46,
26,
377,
8045,
3509,
481,
379,
11131,
1678,
450,
83,
12,
1314,
365,
15666,
2419,
593,
90,
19428,
3595,
27,
876,
724,
1098,
642,
365,
481,
379,
11131,
450,
83,
12,
1325,
642,
1443,
2449,
275,
5918,
401,
307,
5030,
14,
873,
12,
10826,
63,
873,
9,
398,
291,
14,
7804,
3417,
275,
1172,
3417,
267,
291,
14,
15697,
4595,
765,
275,
10529,
4595,
765,
267,
340,
291,
14,
2076,
76,
14,
873,
315,
2097,
1079,
401,
298,
1046,
401,
298,
975,
401,
298,
1196,
401,
298,
1085,
401,
298,
1167,
401,
298,
1165,
401,
298,
2025,
401,
3044,
298,
1081,
401,
298,
1789,
401,
298,
1194,
401,
298,
821,
6229,
288,
291,
14,
1042,
4538,
63,
2775,
63,
354,
275,
283,
1308,
14,
15800,
269,
30204,
963,
14,
28299,
14,
793,
14,
16,
7,
339,
347,
485,
8951,
63,
4595,
8,
277,
304,
267,
408,
267,
9075,
370,
2811,
314,
9055,
367,
2599,
23048,
14,
267,
408,
267,
291,
423,
1574,
63,
30784,
8,
736,
14,
515,
14,
904,
8,
277,
14,
4595,
63,
4407,
12,
298,
6080,
14,
4128,
2237,
398,
340,
291,
14,
2076,
76,
14,
873,
315,
2097,
1196,
401,
298,
1085,
401,
298,
1167,
401,
298,
1165,
401,
298,
2025,
401,
298,
1081,
401,
298,
1789,
401,
298,
1194,
401,
298,
821,
6229,
288,
4205,
6883,
604,
275,
298,
221,
5666,
4205,
6883,
29,
826,
6883,
14,
4060,
15357,
29,
2866,
417,
11254,
2374,
15,
2866,
417,
11254,
6080,
14,
4128,
2,
267,
587,
26,
288,
4205,
6883,
604,
275,
298,
221,
5666,
4205,
6883,
29,
826,
6883,
14,
4060,
15357,
29,
2866,
417,
11254,
6080,
14,
4128,
2,
267,
340,
291,
14,
2076,
76,
14,
3174,
466,
508,
298,
633,
582,
288,
340,
291,
14,
7804,
3417,
26,
355,
4205,
6883,
604,
847,
298,
3831,
628,
288,
587,
26,
355,
4205,
6883,
604,
847,
298,
1083,
628,
288,
4205,
6883,
604,
847,
291,
14,
633,
435,
1867,
78,
2,
267,
587,
26,
288,
327,
340,
314,
3907,
466,
365,
11601,
12,
2066,
7037,
370,
282,
6519,
315,
376,
16928,
983,
781,
10137,
288,
327,
734,
314,
1083,
14793,
288,
340,
440,
291,
14,
15697,
4595,
765,
26,
355,
4205,
6883,
604,
847,
298,
1083,
29,
2866,
417,
11254,
2374,
15,
2866,
417,
2,
288,
4205,
6883,
604,
847,
1867,
78,
2,
267,
291,
423,
8951,
63,
374,
393,
7226,
8,
826,
6883,
604,
9,
339,
347,
3550,
63,
4032,
1569,
8,
277,
12,
1568,
29,
709,
12,
3542,
29,
797,
304,
267,
408,
267,
9075,
370,
3550,
282,
4543,
1569,
14,
221,
4885,
849,
12,
282,
4596,
4543,
1569,
402,
267,
1616,
6487,
911,
506,
2737,
27,
314,
8025,
883,
4278,
642,
543,
314,
1568,
267,
2725,
12,
2013,
315,
18553,
14,
221,
982,
3542,
365,
756,
334,
1589,
849,
395,
2066,
267,
282,
4543,
1569,
911,
440,
506,
2737,
340,
282,
6328,
1603,
37,
3100,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Nehmulos/knight-game
|
cocos2d/tools/bindings-generator/backup/clang-llvm-3.3-pybinding/enumerations.py
|
307
|
1077
|
#===- enumerations.py - Python Enumerations ------------------*- python -*--===#
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
"""
Clang Enumerations
==================
This module provides static definitions of enumerations that exist in libclang.
Enumerations are typically defined as a list of tuples. The exported values are
typically munged into other types or classes at module load time.
All enumerations are centrally defined in this file so they are all grouped
together and easier to audit. And, maybe even one day this file will be
automatically generated by scanning the libclang headers!
"""
# Maps to CXTokenKind. Note that libclang maintains a separate set of token
# enumerations from the C++ API.
TokenKinds = [
('PUNCTUATION', 0),
('KEYWORD', 1),
('IDENTIFIER', 2),
('LITERAL', 3),
('COMMENT', 4),
]
__all__ = ['TokenKinds']
|
gpl-3.0
|
[
3,
389,
4022,
3720,
3801,
14,
647,
446,
2018,
3447,
940,
3801,
10652,
306,
1837,
2366,
446,
10,
306,
5918,
3,
199,
3,
199,
3,
9326,
710,
491,
28631,
27154,
1010,
21844,
6976,
199,
3,
199,
3,
961,
570,
365,
1854,
1334,
314,
15904,
402,
473,
76,
472,
79,
374,
3232,
5800,
199,
3,
844,
14,
1666,
5113,
14,
17715,
367,
2436,
14,
199,
3,
199,
3,
5918,
3606,
518,
5918,
3,
199,
199,
624,
199,
1968,
621,
3447,
940,
3801,
199,
1280,
389,
199,
199,
2765,
859,
6571,
2955,
10269,
402,
3720,
3801,
626,
2187,
315,
1973,
16066,
14,
199,
199,
28858,
3801,
787,
13609,
3247,
465,
282,
769,
402,
6346,
14,
710,
16629,
1338,
787,
199,
32251,
333,
324,
3046,
1901,
1163,
2943,
503,
3992,
737,
859,
2248,
900,
14,
199,
199,
2422,
3720,
3801,
787,
9679,
454,
1183,
3247,
315,
642,
570,
880,
2985,
787,
1006,
16251,
199,
6314,
436,
14905,
370,
13968,
14,
6061,
12,
11703,
2755,
1373,
5382,
642,
570,
911,
506,
199,
2495,
17174,
4046,
701,
24928,
314,
1973,
16066,
2323,
1,
199,
624,
199,
199,
3,
23673,
370,
445,
56,
3264,
13028,
14,
3390,
626,
1973,
16066,
11075,
83,
282,
7396,
663,
402,
1526,
199,
3,
3720,
3801,
687,
314,
445,
4176,
3261,
14,
199,
3264,
13028,
83,
275,
359,
272,
661,
48,
1734,
1028,
53,
2594,
297,
378,
395,
272,
661,
17714,
297,
413,
395,
272,
661,
22698,
297,
499,
395,
272,
661,
21692,
297,
650,
395,
272,
661,
10973,
297,
841,
395,
199,
61,
199,
199,
363,
452,
363,
275,
788,
3264,
13028,
83,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
389,
4022,
3720,
3801,
14,
647,
446,
2018,
3447,
940,
3801,
10652,
306,
1837,
2366,
446,
10,
306,
5918,
3,
199,
3,
199,
3,
9326,
710,
491,
28631,
27154,
1010,
21844,
6976,
199,
3,
199,
3,
961,
570,
365,
1854,
1334,
314,
15904,
402,
473,
76,
472,
79,
374,
3232,
5800,
199,
3,
844,
14,
1666,
5113,
14,
17715,
367,
2436,
14,
199,
3,
199,
3,
5918,
3606,
518,
5918,
3,
199,
199,
624,
199,
1968,
621,
3447,
940,
3801,
199,
1280,
389,
199,
199,
2765,
859,
6571,
2955,
10269,
402,
3720,
3801,
626,
2187,
315,
1973,
16066,
14,
199,
199,
28858,
3801,
787,
13609,
3247,
465,
282,
769,
402,
6346,
14,
710,
16629,
1338,
787,
199,
32251,
333,
324,
3046,
1901,
1163,
2943,
503,
3992,
737,
859,
2248,
900,
14,
199,
199,
2422,
3720,
3801,
787,
9679,
454,
1183,
3247,
315,
642,
570,
880,
2985,
787,
1006,
16251,
199,
6314,
436,
14905,
370,
13968,
14,
6061,
12,
11703,
2755,
1373,
5382,
642,
570,
911,
506,
199,
2495,
17174,
4046,
701,
24928,
314,
1973,
16066,
2323,
1,
199,
624,
199,
199,
3,
23673,
370,
445,
56,
3264,
13028,
14,
3390,
626,
1973,
16066,
11075,
83,
282,
7396,
663,
402,
1526,
199,
3,
3720,
3801,
687,
314,
445,
4176,
3261,
14,
199,
3264,
13028,
83,
275,
359,
272,
661,
48,
1734,
1028,
53,
2594,
297,
378,
395,
272,
661,
17714,
297,
413,
395,
272,
661,
22698,
297,
499,
395,
272,
661,
21692,
297,
650,
395,
272,
661,
10973,
297,
841,
395,
199,
61,
199,
199,
363,
452,
363,
275,
788,
3264,
13028,
83,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
Jandersolutions/jander777-ghost
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/build-3.3/pygments/formatters/terminal.py
|
363
|
4065
|
# -*- coding: utf-8 -*-
"""
pygments.formatters.terminal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Formatter for terminal output with ANSI sequences.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import sys
from pygments.formatter import Formatter
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Token, Whitespace
from pygments.console import ansiformat
from pygments.util import get_choice_opt
__all__ = ['TerminalFormatter']
#: Map token types to a tuple of color values for light and dark
#: backgrounds.
TERMINAL_COLORS = {
Token: ('', ''),
Whitespace: ('lightgray', 'darkgray'),
Comment: ('lightgray', 'darkgray'),
Comment.Preproc: ('teal', 'turquoise'),
Keyword: ('darkblue', 'blue'),
Keyword.Type: ('teal', 'turquoise'),
Operator.Word: ('purple', 'fuchsia'),
Name.Builtin: ('teal', 'turquoise'),
Name.Function: ('darkgreen', 'green'),
Name.Namespace: ('_teal_', '_turquoise_'),
Name.Class: ('_darkgreen_', '_green_'),
Name.Exception: ('teal', 'turquoise'),
Name.Decorator: ('darkgray', 'lightgray'),
Name.Variable: ('darkred', 'red'),
Name.Constant: ('darkred', 'red'),
Name.Attribute: ('teal', 'turquoise'),
Name.Tag: ('blue', 'blue'),
String: ('brown', 'brown'),
Number: ('darkblue', 'blue'),
Generic.Deleted: ('red', 'red'),
Generic.Inserted: ('darkgreen', 'green'),
Generic.Heading: ('**', '**'),
Generic.Subheading: ('*purple*', '*fuchsia*'),
Generic.Error: ('red', 'red'),
Error: ('_red_', '_red_'),
}
class TerminalFormatter(Formatter):
r"""
Format tokens with ANSI color sequences, for output in a text console.
Color sequences are terminated at newlines, so that paging the output
works correctly.
The `get_style_defs()` method doesn't do anything special since there is
no support for common styles.
Options accepted:
`bg`
Set to ``"light"`` or ``"dark"`` depending on the terminal's background
(default: ``"light"``).
`colorscheme`
A dictionary mapping token types to (lightbg, darkbg) color names or
``None`` (default: ``None`` = use builtin colorscheme).
"""
name = 'Terminal'
aliases = ['terminal', 'console']
filenames = []
def __init__(self, **options):
Formatter.__init__(self, **options)
self.darkbg = get_choice_opt(options, 'bg',
['light', 'dark'], 'light') == 'dark'
self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS
def format(self, tokensource, outfile):
# hack: if the output is a terminal and has an encoding set,
# use that to avoid unicode encode problems
if not self.encoding and hasattr(outfile, "encoding") and \
hasattr(outfile, "isatty") and outfile.isatty() and \
sys.version_info < (3,):
self.encoding = outfile.encoding
return Formatter.format(self, tokensource, outfile)
def format_unencoded(self, tokensource, outfile):
for ttype, value in tokensource:
color = self.colorscheme.get(ttype)
while color is None:
ttype = ttype[:-1]
color = self.colorscheme.get(ttype)
if color:
color = color[self.darkbg]
spl = value.split('\n')
for line in spl[:-1]:
if line:
outfile.write(ansiformat(color, line))
outfile.write('\n')
if spl[-1]:
outfile.write(ansiformat(color, spl[-1]))
else:
outfile.write(value)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
14,
12010,
272,
18294,
22935,
339,
31084,
367,
11167,
1072,
543,
25600,
8013,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
984,
199,
199,
504,
13277,
14,
8911,
492,
31084,
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,
199,
504,
13277,
14,
6614,
492,
376,
338,
908,
199,
504,
13277,
14,
1974,
492,
664,
63,
5095,
63,
2992,
421,
199,
363,
452,
363,
275,
788,
22015,
7772,
418,
421,
199,
12573,
9672,
1526,
2943,
370,
282,
2008,
402,
3164,
1338,
367,
10540,
436,
23531,
199,
12573,
8020,
83,
14,
199,
28376,
748,
63,
25671,
275,
469,
272,
8767,
26,
4519,
13134,
3322,
9929,
339,
24403,
26,
260,
661,
4040,
12150,
297,
257,
283,
13625,
12150,
659,
272,
6819,
26,
3322,
661,
4040,
12150,
297,
257,
283,
13625,
12150,
659,
272,
6819,
14,
19285,
26,
259,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
6431,
26,
3322,
661,
13625,
6304,
297,
259,
283,
6304,
659,
272,
6431,
14,
804,
26,
755,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
11013,
14,
10155,
26,
420,
661,
6653,
11045,
297,
420,
283,
70,
2133,
10971,
659,
272,
2812,
14,
12306,
26,
755,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
2812,
14,
3481,
26,
420,
661,
13625,
7731,
297,
257,
283,
7731,
659,
272,
2812,
14,
8814,
26,
258,
12331,
266,
279,
14474,
420,
2513,
16218,
14209,
572,
63,
659,
272,
2812,
14,
2543,
26,
260,
12331,
13625,
7731,
14474,
2513,
7731,
63,
659,
272,
2812,
14,
1726,
26,
258,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
2812,
14,
14946,
26,
258,
661,
13625,
12150,
297,
259,
283,
4040,
12150,
659,
272,
2812,
14,
2773,
26,
420,
661,
13625,
581,
297,
258,
283,
581,
659,
272,
2812,
14,
9737,
26,
420,
661,
13625,
581,
297,
258,
283,
581,
659,
272,
2812,
14,
1646,
26,
258,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
2812,
14,
1931,
26,
3698,
661,
6304,
297,
263,
283,
6304,
659,
272,
2624,
26,
3777,
661,
27133,
297,
755,
283,
27133,
659,
272,
4860,
26,
3777,
661,
13625,
6304,
297,
259,
283,
6304,
659,
339,
8307,
14,
17735,
26,
259,
661,
581,
297,
263,
283,
581,
659,
272,
8307,
14,
607,
9449,
26,
257,
661,
13625,
7731,
297,
221,
283,
7731,
659,
272,
8307,
14,
23818,
26,
259,
661,
538,
297,
260,
23940,
659,
272,
8307,
14,
2610,
13983,
26,
661,
10,
6653,
11045,
7693,
257,
6438,
70,
2133,
10971,
10,
659,
272,
8307,
14,
547,
26,
420,
661,
581,
297,
263,
283,
581,
659,
339,
4520,
26,
4519,
12331,
581,
14474,
420,
2513,
581,
63,
659,
199,
93,
421,
199,
533,
20429,
279,
7772,
8,
7772,
304,
272,
519,
624,
272,
9701,
4645,
543,
25600,
3164,
8013,
12,
367,
1072,
315,
282,
1318,
8559,
14,
272,
11581,
8013,
787,
15745,
737,
14930,
12,
880,
626,
299,
7407,
314,
1072,
272,
5419,
6657,
14,
339,
710,
658,
362,
63,
2487,
63,
8710,
11995,
1083,
3181,
1133,
886,
7003,
4539,
3967,
2337,
365,
272,
949,
2291,
367,
2863,
15725,
14,
339,
8394,
10226,
26,
339,
658,
6856,
64,
267,
2494,
370,
25916,
4040,
31002,
503,
25916,
13625,
31002,
10298,
641,
314,
11167,
1159,
8020,
267,
334,
885,
26,
25916,
4040,
2,
20008,
339,
658,
7120,
3453,
64,
267,
437,
2600,
4412,
1526,
2943,
370,
334,
4040,
6856,
12,
23531,
6856,
9,
3164,
1561,
503,
267,
1124,
403,
1040,
334,
885,
26,
1124,
403,
1040,
275,
675,
6762,
9229,
3453,
680,
272,
408,
272,
536,
275,
283,
22015,
7,
272,
5481,
275,
788,
12010,
297,
283,
6614,
418,
272,
6203,
275,
942,
339,
347,
636,
826,
721,
277,
12,
1011,
1419,
304,
267,
31084,
855,
826,
721,
277,
12,
1011,
1419,
9,
267,
291,
14,
13625,
6856,
275,
664,
63,
5095,
63,
2992,
8,
1419,
12,
283,
6856,
297,
3660,
788,
4040,
297,
283,
13625,
995,
283,
4040,
358,
508,
283,
13625,
7,
267,
291,
14,
7120,
3453,
275,
1511,
14,
362,
360,
7120,
3453,
297,
488,
9,
503,
31510,
4896,
748,
63,
25671,
339,
347,
1475,
8,
277,
12,
1526,
1365,
12,
4386,
304,
267,
327,
11176,
26,
340,
314,
1072,
365,
282,
11167,
436,
965,
376,
2644,
663,
12,
267,
327,
675,
626,
370,
5126,
2649,
3752,
8826,
267,
340,
440,
291,
14,
2991,
436,
2688,
8,
4984,
12,
298,
2991,
531,
436,
971,
1779,
2688,
8,
4984,
12,
298,
21122,
531,
436,
4386,
14,
21122,
342,
436,
971,
1779,
984,
14,
1023,
63,
815,
665,
334,
19,
16095,
288,
291,
14,
2991,
275,
4386,
14,
2991,
267,
372,
31084,
14,
908,
8,
277,
12,
1526,
1365,
12,
4386,
9,
339,
347,
1475,
63,
324,
8167,
8,
277,
12,
1526,
1365,
12,
4386,
304,
267,
367,
17860,
12,
574,
315,
1526,
1365,
26,
288,
3164,
275,
291,
14,
7120,
3453,
14,
362,
8,
21002,
9,
288,
1830,
3164,
365,
488,
26,
355,
17860,
275,
17860,
4439,
17,
61,
355,
3164,
275,
291,
14,
7120,
3453,
14,
362,
8,
21002,
9,
288,
340,
3164,
26,
355,
3164,
275,
3164,
59,
277,
14,
13625,
6856,
61,
355,
23168,
275,
574,
14,
1294,
2258,
78,
358,
355,
367,
1004,
315,
23168,
4439,
17,
2189,
490,
340,
1004,
26,
717,
4386,
14,
952,
8,
22204,
908,
8,
2326,
12,
1004,
430,
490,
4386,
14,
952,
2258,
78,
358,
355,
340,
23168,
1988,
17,
2189,
490,
4386,
14,
952,
8,
22204,
908,
8,
2326,
12,
23168,
1988,
17,
2459,
288,
587,
26,
355,
4386,
14,
952,
8,
585,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
14,
12010,
272,
18294,
22935,
339,
31084,
367,
11167,
1072,
543,
25600,
8013,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
984,
199,
199,
504,
13277,
14,
8911,
492,
31084,
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,
199,
504,
13277,
14,
6614,
492,
376,
338,
908,
199,
504,
13277,
14,
1974,
492,
664,
63,
5095,
63,
2992,
421,
199,
363,
452,
363,
275,
788,
22015,
7772,
418,
421,
199,
12573,
9672,
1526,
2943,
370,
282,
2008,
402,
3164,
1338,
367,
10540,
436,
23531,
199,
12573,
8020,
83,
14,
199,
28376,
748,
63,
25671,
275,
469,
272,
8767,
26,
4519,
13134,
3322,
9929,
339,
24403,
26,
260,
661,
4040,
12150,
297,
257,
283,
13625,
12150,
659,
272,
6819,
26,
3322,
661,
4040,
12150,
297,
257,
283,
13625,
12150,
659,
272,
6819,
14,
19285,
26,
259,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
6431,
26,
3322,
661,
13625,
6304,
297,
259,
283,
6304,
659,
272,
6431,
14,
804,
26,
755,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
11013,
14,
10155,
26,
420,
661,
6653,
11045,
297,
420,
283,
70,
2133,
10971,
659,
272,
2812,
14,
12306,
26,
755,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
2812,
14,
3481,
26,
420,
661,
13625,
7731,
297,
257,
283,
7731,
659,
272,
2812,
14,
8814,
26,
258,
12331,
266,
279,
14474,
420,
2513,
16218,
14209,
572,
63,
659,
272,
2812,
14,
2543,
26,
260,
12331,
13625,
7731,
14474,
2513,
7731,
63,
659,
272,
2812,
14,
1726,
26,
258,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
2812,
14,
14946,
26,
258,
661,
13625,
12150,
297,
259,
283,
4040,
12150,
659,
272,
2812,
14,
2773,
26,
420,
661,
13625,
581,
297,
258,
283,
581,
659,
272,
2812,
14,
9737,
26,
420,
661,
13625,
581,
297,
258,
283,
581,
659,
272,
2812,
14,
1646,
26,
258,
661,
266,
279,
297,
263,
283,
16218,
14209,
572,
659,
272,
2812,
14,
1931,
26,
3698,
661,
6304,
297,
263,
283,
6304,
659,
272,
2624,
26,
3777,
661,
27133,
297,
755,
283,
27133,
659,
272,
4860,
26,
3777,
661,
13625,
6304,
297,
259,
283,
6304,
659,
339,
8307,
14,
17735,
26,
259,
661,
581,
297,
263,
283,
581,
659,
272,
8307,
14,
607,
9449,
26,
257,
661,
13625,
7731,
297,
221,
283,
7731,
659,
272,
8307,
14,
23818,
26,
259,
661,
538,
297,
260,
23940,
659,
272,
8307,
14,
2610,
13983,
26,
661,
10,
6653,
11045,
7693,
257,
6438,
70,
2133,
10971,
10,
659,
272,
8307,
14,
547,
26,
420,
661,
581,
297,
263,
283,
581,
659,
339,
4520,
26,
4519,
12331,
581,
14474,
420,
2513,
581,
63,
659,
199,
93,
421,
199,
533,
20429,
279,
7772,
8,
7772,
304,
272,
519,
624,
272,
9701,
4645,
543,
25600,
3164,
8013,
12,
367,
1072,
315,
282,
1318,
8559,
14,
272,
11581,
8013,
787,
15745,
737,
14930,
12,
880,
626,
299,
7407,
314,
1072,
272,
5419,
6657,
14,
339,
710,
658,
362,
63,
2487,
63,
8710,
11995,
1083,
3181,
1133,
886,
7003,
4539,
3967,
2337,
365,
272,
949,
2291,
367,
2863,
15725,
14,
339,
8394,
10226,
26,
339,
658,
6856,
64,
267,
2494,
370,
25916,
4040,
31002,
503,
25916,
13625,
31002,
10298,
641,
314,
11167,
1159,
8020,
267,
334,
885,
26,
25916,
4040,
2,
20008,
339,
658,
7120,
3453,
64,
267,
437,
2600,
4412,
1526,
2943,
370,
334,
4040,
6856,
12,
23531,
6856,
9,
3164,
1561,
503,
267,
1124,
403,
1040,
334,
885,
26,
1124,
403,
1040,
275,
675,
6762,
9229,
3453,
680,
272,
408,
272,
536,
275,
283,
22015,
7,
272,
5481,
275,
788,
12010,
297,
283,
6614,
418,
272,
6203,
275,
942,
339,
347,
636,
826,
721,
277,
12,
1011,
1419,
304,
267,
31084,
855,
826,
721,
277,
12,
1011,
1419,
9,
267,
291,
14,
13625,
6856,
275,
664,
63,
5095,
63,
2992,
8,
1419,
12,
283,
6856,
297,
3660,
788,
4040,
297,
283,
13625,
995,
283,
4040,
358,
508,
283,
13625,
7,
267,
291,
14,
7120,
3453,
275,
1511,
14,
362,
360,
7120,
3453,
297,
488,
9,
503,
31510,
4896,
748,
63,
25671,
339,
347,
1475,
8,
277,
12,
1526,
1365,
12,
4386,
304,
267,
327,
11176,
26,
340,
314,
1072,
365,
282,
11167,
436,
965,
376,
2644,
663,
12,
267,
327,
675,
626,
370,
5126,
2649,
3752,
8826,
267,
340,
440,
291,
14,
2991,
436,
2688,
8,
4984,
12,
298,
2991,
531,
436,
971,
1779,
2688,
8,
4984,
12,
298,
21122,
531,
436,
4386,
14,
21122,
342,
436,
971,
1779,
984,
14,
1023,
63,
815,
665,
334,
19,
16095,
288,
291,
14,
2991,
275,
4386,
14,
2991,
267,
372,
31084,
14,
908,
8,
277,
12,
1526,
1365,
12,
4386,
9,
339,
347,
1475,
63,
324,
8167,
8,
277,
12,
1526,
1365,
12,
4386,
304,
267,
367,
17860,
12,
574,
315,
1526,
1365,
26,
288,
3164,
275,
291,
14,
7120,
3453,
14,
362,
8,
21002,
9,
288,
1830,
3164,
365,
488,
26,
355,
17860,
275,
17860,
4439,
17,
61,
355,
3164,
275,
291,
14,
7120,
3453,
14,
362,
8,
21002,
9,
288,
340,
3164,
26,
355,
3164,
275,
3164,
59,
277,
14,
13625,
6856,
61,
355,
23168,
275,
574,
14,
1294,
2258,
78,
358,
355,
367,
1004,
315,
23168,
4439,
17,
2189,
490,
340,
1004,
26,
717,
4386,
14,
952,
8,
22204,
908,
8,
2326,
12,
1004,
430,
490,
4386,
14,
952,
2258,
78,
358,
355,
340,
23168,
1988,
17,
2189,
490,
4386,
14,
952,
8,
22204,
908,
8,
2326,
12,
23168,
1988,
17,
2459,
288,
587,
26,
355,
4386,
14,
952,
8,
585,
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,
0
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,
0
] |
alejo8591/maker
|
core/dashboard/urls.py
|
1
|
1121
|
# encoding: utf-8
# Copyright 2013 maker
# License
"""
Core module Dashboard URLs
"""
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('maker.core.dashboard.views',
url(r'^(\.(?P<response_format>\w+))?$', 'index', name='core_dashboard_index'),
# Widgets
url(r'^widget/add(\.(?P<response_format>\w+))?$',
'dashboard_widget_add', name='core_dashboard_widget_add'),
url(r'^widget/add/(?P<module_name>[a-z\.]+)/(?P<widget_name>\w+)(\.(?P<response_format>\w+))?$',
'dashboard_widget_add', name='core_dashboard_widget_add_selected'),
url(r'^widget/edit/(?P<widget_id>\d+)(\.(?P<response_format>\w+))?$',
'dashboard_widget_edit', name='core_dashboard_widget_edit'),
url(r'^widget/delete/(?P<widget_id>\d+)(\.(?P<response_format>\w+))?$',
'dashboard_widget_delete', name='core_dashboard_widget_delete'),
url(r'^widget/arrange/(?P<panel>\w+)?(\.(?P<response_format>\w+))?$',
'dashboard_widget_arrange', name='core_dashboard_widget_arrange'),
)
|
mit
|
[
3,
2644,
26,
2774,
13,
24,
199,
3,
1898,
6171,
610,
2570,
199,
3,
844,
199,
199,
624,
272,
11672,
859,
577,
1119,
3576,
10867,
199,
624,
199,
199,
504,
1639,
14,
2190,
14,
3603,
14,
4322,
492,
7970,
12,
1166,
199,
199,
20050,
275,
7970,
360,
14367,
14,
1018,
14,
9743,
14,
4196,
297,
267,
1166,
8,
82,
31344,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
283,
1080,
297,
536,
534,
1018,
63,
9743,
63,
1080,
659,
2728,
327,
16905,
83,
267,
1166,
8,
82,
4289,
3440,
15,
525,
2961,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
525,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
525,
659,
267,
1166,
8,
82,
4289,
3440,
15,
525,
9448,
48,
28,
578,
63,
354,
9514,
65,
13,
90,
4537,
24598,
2229,
48,
28,
3440,
63,
354,
3072,
87,
27860,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
525,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
525,
63,
5511,
659,
267,
1166,
8,
82,
4289,
3440,
15,
3773,
9448,
48,
28,
3440,
63,
344,
3072,
68,
27860,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
3773,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
3773,
659,
267,
1166,
8,
82,
4289,
3440,
15,
1807,
9448,
48,
28,
3440,
63,
344,
3072,
68,
27860,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
1807,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
1807,
659,
2728,
1166,
8,
82,
4289,
3440,
15,
285,
1842,
9448,
48,
28,
7885,
3072,
87,
19544,
2961,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
285,
1842,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
285,
1842,
659,
1467,
199,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2644,
26,
2774,
13,
24,
199,
3,
1898,
6171,
610,
2570,
199,
3,
844,
199,
199,
624,
272,
11672,
859,
577,
1119,
3576,
10867,
199,
624,
199,
199,
504,
1639,
14,
2190,
14,
3603,
14,
4322,
492,
7970,
12,
1166,
199,
199,
20050,
275,
7970,
360,
14367,
14,
1018,
14,
9743,
14,
4196,
297,
267,
1166,
8,
82,
31344,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
283,
1080,
297,
536,
534,
1018,
63,
9743,
63,
1080,
659,
2728,
327,
16905,
83,
267,
1166,
8,
82,
4289,
3440,
15,
525,
2961,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
525,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
525,
659,
267,
1166,
8,
82,
4289,
3440,
15,
525,
9448,
48,
28,
578,
63,
354,
9514,
65,
13,
90,
4537,
24598,
2229,
48,
28,
3440,
63,
354,
3072,
87,
27860,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
525,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
525,
63,
5511,
659,
267,
1166,
8,
82,
4289,
3440,
15,
3773,
9448,
48,
28,
3440,
63,
344,
3072,
68,
27860,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
3773,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
3773,
659,
267,
1166,
8,
82,
4289,
3440,
15,
1807,
9448,
48,
28,
3440,
63,
344,
3072,
68,
27860,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
1807,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
1807,
659,
2728,
1166,
8,
82,
4289,
3440,
15,
285,
1842,
9448,
48,
28,
7885,
3072,
87,
19544,
2961,
14,
2229,
48,
28,
1310,
63,
908,
3072,
87,
11,
22119,
4268,
7205,
283,
9743,
63,
3440,
63,
285,
1842,
297,
536,
534,
1018,
63,
9743,
63,
3440,
63,
285,
1842,
659,
1467,
199,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
blacktear23/django
|
django/contrib/localflavor/id/id_choices.py
|
439
|
3217
|
import warnings
from django.utils.translation import ugettext_lazy as _
# Reference: http://id.wikipedia.org/wiki/Daftar_provinsi_Indonesia
# Indonesia does not have an official Province code standard.
# I decided to use unambiguous and consistent (some are common) 3-letter codes.
warnings.warn(
'There have been recent changes to the ID localflavor. See the release notes for details',
RuntimeWarning
)
PROVINCE_CHOICES = (
('ACE', _('Aceh')),
('BLI', _('Bali')),
('BTN', _('Banten')),
('BKL', _('Bengkulu')),
('DIY', _('Yogyakarta')),
('JKT', _('Jakarta')),
('GOR', _('Gorontalo')),
('JMB', _('Jambi')),
('JBR', _('Jawa Barat')),
('JTG', _('Jawa Tengah')),
('JTM', _('Jawa Timur')),
('KBR', _('Kalimantan Barat')),
('KSL', _('Kalimantan Selatan')),
('KTG', _('Kalimantan Tengah')),
('KTM', _('Kalimantan Timur')),
('BBL', _('Kepulauan Bangka-Belitung')),
('KRI', _('Kepulauan Riau')),
('LPG', _('Lampung')),
('MLK', _('Maluku')),
('MUT', _('Maluku Utara')),
('NTB', _('Nusa Tenggara Barat')),
('NTT', _('Nusa Tenggara Timur')),
('PPA', _('Papua')),
('PPB', _('Papua Barat')),
('RIU', _('Riau')),
('SLB', _('Sulawesi Barat')),
('SLS', _('Sulawesi Selatan')),
('SLT', _('Sulawesi Tengah')),
('SLR', _('Sulawesi Tenggara')),
('SLU', _('Sulawesi Utara')),
('SMB', _('Sumatera Barat')),
('SMS', _('Sumatera Selatan')),
('SMU', _('Sumatera Utara')),
)
LICENSE_PLATE_PREFIX_CHOICES = (
('A', _('Banten')),
('AA', _('Magelang')),
('AB', _('Yogyakarta')),
('AD', _('Surakarta - Solo')),
('AE', _('Madiun')),
('AG', _('Kediri')),
('B', _('Jakarta')),
('BA', _('Sumatera Barat')),
('BB', _('Tapanuli')),
('BD', _('Bengkulu')),
('BE', _('Lampung')),
('BG', _('Sumatera Selatan')),
('BH', _('Jambi')),
('BK', _('Sumatera Utara')),
('BL', _('Nanggroe Aceh Darussalam')),
('BM', _('Riau')),
('BN', _('Kepulauan Bangka Belitung')),
('BP', _('Kepulauan Riau')),
('CC', _('Corps Consulate')),
('CD', _('Corps Diplomatic')),
('D', _('Bandung')),
('DA', _('Kalimantan Selatan')),
('DB', _('Sulawesi Utara Daratan')),
('DC', _('Sulawesi Barat')),
('DD', _('Sulawesi Selatan')),
('DE', _('Maluku')),
('DG', _('Maluku Utara')),
('DH', _('NTT - Timor')),
('DK', _('Bali')),
('DL', _('Sulawesi Utara Kepulauan')),
('DM', _('Gorontalo')),
('DN', _('Sulawesi Tengah')),
('DR', _('NTB - Lombok')),
('DS', _('Papua dan Papua Barat')),
('DT', _('Sulawesi Tenggara')),
('E', _('Cirebon')),
('EA', _('NTB - Sumbawa')),
('EB', _('NTT - Flores')),
('ED', _('NTT - Sumba')),
('F', _('Bogor')),
('G', _('Pekalongan')),
('H', _('Semarang')),
('K', _('Pati')),
('KB', _('Kalimantan Barat')),
('KH', _('Kalimantan Tengah')),
('KT', _('Kalimantan Timur')),
('L', _('Surabaya')),
('M', _('Madura')),
('N', _('Malang')),
('P', _('Jember')),
('R', _('Banyumas')),
('RI', _('Federal Government')),
('S', _('Bojonegoro')),
('T', _('Purwakarta')),
('W', _('Sidoarjo')),
('Z', _('Garut')),
)
|
bsd-3-clause
|
[
646,
3598,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
3,
10944,
26,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
25014,
856,
285,
63,
496,
11908,
338,
63,
607,
4456,
10971,
199,
199,
3,
473,
977,
368,
10971,
1630,
440,
1172,
376,
25410,
2165,
86,
2855,
1233,
4465,
14,
199,
3,
473,
12985,
770,
370,
675,
625,
26465,
436,
12137,
334,
3972,
787,
2863,
9,
650,
13,
9269,
9479,
14,
199,
199,
5451,
14,
4050,
8,
272,
283,
10924,
1172,
2757,
8058,
4493,
370,
314,
2870,
560,
696,
276,
4271,
14,
1666,
314,
4683,
12681,
367,
2436,
297,
272,
25178,
199,
9,
199,
199,
2514,
54,
568,
2089,
63,
16236,
275,
334,
272,
661,
4121,
297,
4018,
33,
301,
72,
3855,
272,
661,
34,
2673,
297,
4018,
34,
10874,
3855,
272,
661,
19162,
46,
297,
4018,
28018,
724,
3855,
272,
661,
34,
14307,
297,
4018,
34,
7420,
75,
348,
85,
3855,
272,
661,
1914,
57,
297,
4018,
57,
974,
89,
1151,
29549,
3855,
272,
661,
42,
12362,
297,
4018,
42,
1151,
29549,
3855,
272,
661,
39,
726,
297,
4018,
39,
269,
1888,
12201,
3855,
272,
661,
42,
4567,
297,
4018,
42,
455,
4492,
3855,
272,
661,
42,
7184,
297,
4018,
42,
65,
758,
12377,
292,
3855,
272,
661,
42,
6332,
297,
4018,
42,
65,
758,
377,
287,
5294,
72,
3855,
272,
661,
42,
20690,
297,
4018,
42,
65,
758,
26244,
300,
3855,
272,
661,
43,
7184,
297,
4018,
43,
279,
1017,
867,
290,
12377,
292,
3855,
272,
661,
43,
4929,
297,
4018,
43,
279,
1017,
867,
290,
428,
352,
16080,
3855,
272,
661,
43,
6332,
297,
4018,
43,
279,
1017,
867,
290,
377,
287,
5294,
72,
3855,
272,
661,
12362,
45,
297,
4018,
43,
279,
1017,
867,
290,
26244,
300,
3855,
272,
661,
5342,
44,
297,
4018,
1136,
80,
348,
3844,
290,
699,
621,
7351,
13,
3655,
1051,
10335,
3855,
272,
661,
43,
6129,
297,
4018,
1136,
80,
348,
3844,
290,
820,
73,
3844,
3855,
272,
661,
9257,
39,
297,
4018,
44,
5282,
10335,
3855,
272,
661,
1698,
43,
297,
4018,
31147,
3210,
85,
3855,
272,
661,
25890,
297,
4018,
31147,
3210,
85,
738,
5369,
65,
3855,
272,
661,
12460,
34,
297,
4018,
46,
527,
65,
377,
287,
2721,
17956,
12377,
292,
3855,
272,
661,
46,
1481,
297,
4018,
46,
527,
65,
377,
287,
2721,
17956,
26244,
300,
3855,
272,
661,
7701,
33,
297,
4018,
48,
439,
1458,
3855,
272,
661,
7701,
34,
297,
4018,
48,
439,
1458,
12377,
292,
3855,
272,
661,
6129,
53,
297,
4018,
28522,
3844,
3855,
272,
661,
4929,
34,
297,
4018,
51,
7586,
1129,
338,
12377,
292,
3855,
272,
661,
4929,
51,
297,
4018,
51,
7586,
1129,
338,
428,
352,
16080,
3855,
272,
661,
4929,
52,
297,
4018,
51,
7586,
1129,
338,
377,
287,
5294,
72,
3855,
272,
661,
4929,
50,
297,
4018,
51,
7586,
1129,
338,
377,
287,
2721,
17956,
3855,
272,
661,
4929,
53,
297,
4018,
51,
7586,
1129,
338,
738,
5369,
65,
3855,
272,
661,
23304,
297,
4018,
6959,
323,
345,
12377,
292,
3855,
272,
661,
51,
3053,
297,
4018,
6959,
323,
345,
428,
352,
16080,
3855,
272,
661,
4029,
53,
297,
4018,
6959,
323,
345,
738,
5369,
65,
3855,
199,
9,
199,
199,
3961,
63,
2749,
1951,
63,
6351,
63,
16236,
275,
334,
272,
661,
33,
297,
4018,
28018,
724,
3855,
272,
661,
2276,
297,
4018,
45,
474,
4159,
3855,
272,
661,
1217,
297,
4018,
57,
974,
89,
1151,
29549,
3855,
272,
661,
1554,
297,
4018,
11762,
1151,
29549,
446,
2002,
320,
3855,
272,
661,
12500,
297,
4018,
11903,
328,
324,
3855,
272,
661,
1254,
297,
4018,
1136,
328,
322,
3855,
272,
661,
34,
297,
4018,
42,
1151,
29549,
3855,
272,
661,
4134,
297,
4018,
6959,
323,
345,
12377,
292,
3855,
272,
661,
5342,
297,
4018,
27746,
290,
13987,
3855,
272,
661,
11156,
297,
4018,
34,
7420,
75,
348,
85,
3855,
272,
661,
6773,
297,
4018,
44,
5282,
10335,
3855,
272,
661,
18998,
297,
4018,
6959,
323,
345,
428,
352,
16080,
3855,
272,
661,
29931,
297,
4018,
42,
455,
4492,
3855,
272,
661,
17672,
297,
4018,
6959,
323,
345,
738,
5369,
65,
3855,
272,
661,
7847,
297,
4018,
46,
621,
23260,
69,
437,
301,
72,
577,
285,
27678,
279,
455,
3855,
272,
661,
15225,
297,
4018,
28522,
3844,
3855,
272,
661,
18273,
297,
4018,
1136,
80,
348,
3844,
290,
699,
621,
7351,
6423,
1051,
10335,
3855,
272,
661,
24408,
297,
4018,
1136,
80,
348,
3844,
290,
820,
73,
3844,
3855,
272,
661,
2571,
297,
4018,
8380,
1190,
1448,
83,
5434,
3855,
272,
661,
7695,
297,
4018,
8380,
1190,
577,
711,
320,
3889,
3855,
272,
661,
36,
297,
4018,
11675,
10335,
3855,
272,
661,
8980,
297,
4018,
43,
279,
1017,
867,
290,
428,
352,
16080,
3855,
272,
661,
2846,
297,
4018,
51,
7586,
1129,
338,
738,
5369,
65,
577,
285,
16080,
3855,
272,
661,
5196,
297,
4018,
51,
7586,
1129,
338,
12377,
292,
3855,
272,
661,
5745,
297,
4018,
51,
7586,
1129,
338,
428,
352,
16080,
3855,
272,
661,
1093,
297,
4018,
31147,
3210,
85,
3855,
272,
661,
29173,
297,
4018,
31147,
3210,
85,
738,
5369,
65,
3855,
272,
661,
13860,
297,
4018,
46,
1481,
446,
26244,
269,
3855,
272,
661,
10892,
297,
4018,
34,
10874,
3855,
272,
661,
8045,
297,
4018,
51,
7586,
1129,
338,
738,
5369,
65,
25645,
80,
348,
3844,
290,
3855,
272,
661,
17751,
297,
4018,
39,
269,
1888,
12201,
3855,
272,
661,
10872,
297,
4018,
51,
7586,
1129,
338,
377,
287,
5294,
72,
3855,
272,
661,
4564,
297,
4018,
12460,
34,
446,
491,
676,
656,
75,
3855,
272,
661,
3177,
297,
4018,
48,
439,
1458,
366,
290,
510,
439,
1458,
12377,
292,
3855,
272,
661,
7438,
297,
4018,
51,
7586,
1129,
338,
377,
287,
2721,
17956,
3855,
272,
661,
37,
297,
4018,
35,
3621,
13520,
3855,
272,
661,
11765,
297,
4018,
12460,
34,
446,
12094,
2470,
758,
3855,
272,
661,
14138,
297,
4018,
46,
1481,
446,
481,
320,
470,
3855,
272,
661,
1149,
297,
4018,
46,
1481,
446,
12094,
2470,
3855,
272,
661,
38,
297,
4018,
34,
974,
269,
3855,
272,
661,
39,
297,
4018,
48,
5711,
21632,
290,
3855,
272
] |
[
3598,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
3,
10944,
26,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
25014,
856,
285,
63,
496,
11908,
338,
63,
607,
4456,
10971,
199,
199,
3,
473,
977,
368,
10971,
1630,
440,
1172,
376,
25410,
2165,
86,
2855,
1233,
4465,
14,
199,
3,
473,
12985,
770,
370,
675,
625,
26465,
436,
12137,
334,
3972,
787,
2863,
9,
650,
13,
9269,
9479,
14,
199,
199,
5451,
14,
4050,
8,
272,
283,
10924,
1172,
2757,
8058,
4493,
370,
314,
2870,
560,
696,
276,
4271,
14,
1666,
314,
4683,
12681,
367,
2436,
297,
272,
25178,
199,
9,
199,
199,
2514,
54,
568,
2089,
63,
16236,
275,
334,
272,
661,
4121,
297,
4018,
33,
301,
72,
3855,
272,
661,
34,
2673,
297,
4018,
34,
10874,
3855,
272,
661,
19162,
46,
297,
4018,
28018,
724,
3855,
272,
661,
34,
14307,
297,
4018,
34,
7420,
75,
348,
85,
3855,
272,
661,
1914,
57,
297,
4018,
57,
974,
89,
1151,
29549,
3855,
272,
661,
42,
12362,
297,
4018,
42,
1151,
29549,
3855,
272,
661,
39,
726,
297,
4018,
39,
269,
1888,
12201,
3855,
272,
661,
42,
4567,
297,
4018,
42,
455,
4492,
3855,
272,
661,
42,
7184,
297,
4018,
42,
65,
758,
12377,
292,
3855,
272,
661,
42,
6332,
297,
4018,
42,
65,
758,
377,
287,
5294,
72,
3855,
272,
661,
42,
20690,
297,
4018,
42,
65,
758,
26244,
300,
3855,
272,
661,
43,
7184,
297,
4018,
43,
279,
1017,
867,
290,
12377,
292,
3855,
272,
661,
43,
4929,
297,
4018,
43,
279,
1017,
867,
290,
428,
352,
16080,
3855,
272,
661,
43,
6332,
297,
4018,
43,
279,
1017,
867,
290,
377,
287,
5294,
72,
3855,
272,
661,
12362,
45,
297,
4018,
43,
279,
1017,
867,
290,
26244,
300,
3855,
272,
661,
5342,
44,
297,
4018,
1136,
80,
348,
3844,
290,
699,
621,
7351,
13,
3655,
1051,
10335,
3855,
272,
661,
43,
6129,
297,
4018,
1136,
80,
348,
3844,
290,
820,
73,
3844,
3855,
272,
661,
9257,
39,
297,
4018,
44,
5282,
10335,
3855,
272,
661,
1698,
43,
297,
4018,
31147,
3210,
85,
3855,
272,
661,
25890,
297,
4018,
31147,
3210,
85,
738,
5369,
65,
3855,
272,
661,
12460,
34,
297,
4018,
46,
527,
65,
377,
287,
2721,
17956,
12377,
292,
3855,
272,
661,
46,
1481,
297,
4018,
46,
527,
65,
377,
287,
2721,
17956,
26244,
300,
3855,
272,
661,
7701,
33,
297,
4018,
48,
439,
1458,
3855,
272,
661,
7701,
34,
297,
4018,
48,
439,
1458,
12377,
292,
3855,
272,
661,
6129,
53,
297,
4018,
28522,
3844,
3855,
272,
661,
4929,
34,
297,
4018,
51,
7586,
1129,
338,
12377,
292,
3855,
272,
661,
4929,
51,
297,
4018,
51,
7586,
1129,
338,
428,
352,
16080,
3855,
272,
661,
4929,
52,
297,
4018,
51,
7586,
1129,
338,
377,
287,
5294,
72,
3855,
272,
661,
4929,
50,
297,
4018,
51,
7586,
1129,
338,
377,
287,
2721,
17956,
3855,
272,
661,
4929,
53,
297,
4018,
51,
7586,
1129,
338,
738,
5369,
65,
3855,
272,
661,
23304,
297,
4018,
6959,
323,
345,
12377,
292,
3855,
272,
661,
51,
3053,
297,
4018,
6959,
323,
345,
428,
352,
16080,
3855,
272,
661,
4029,
53,
297,
4018,
6959,
323,
345,
738,
5369,
65,
3855,
199,
9,
199,
199,
3961,
63,
2749,
1951,
63,
6351,
63,
16236,
275,
334,
272,
661,
33,
297,
4018,
28018,
724,
3855,
272,
661,
2276,
297,
4018,
45,
474,
4159,
3855,
272,
661,
1217,
297,
4018,
57,
974,
89,
1151,
29549,
3855,
272,
661,
1554,
297,
4018,
11762,
1151,
29549,
446,
2002,
320,
3855,
272,
661,
12500,
297,
4018,
11903,
328,
324,
3855,
272,
661,
1254,
297,
4018,
1136,
328,
322,
3855,
272,
661,
34,
297,
4018,
42,
1151,
29549,
3855,
272,
661,
4134,
297,
4018,
6959,
323,
345,
12377,
292,
3855,
272,
661,
5342,
297,
4018,
27746,
290,
13987,
3855,
272,
661,
11156,
297,
4018,
34,
7420,
75,
348,
85,
3855,
272,
661,
6773,
297,
4018,
44,
5282,
10335,
3855,
272,
661,
18998,
297,
4018,
6959,
323,
345,
428,
352,
16080,
3855,
272,
661,
29931,
297,
4018,
42,
455,
4492,
3855,
272,
661,
17672,
297,
4018,
6959,
323,
345,
738,
5369,
65,
3855,
272,
661,
7847,
297,
4018,
46,
621,
23260,
69,
437,
301,
72,
577,
285,
27678,
279,
455,
3855,
272,
661,
15225,
297,
4018,
28522,
3844,
3855,
272,
661,
18273,
297,
4018,
1136,
80,
348,
3844,
290,
699,
621,
7351,
6423,
1051,
10335,
3855,
272,
661,
24408,
297,
4018,
1136,
80,
348,
3844,
290,
820,
73,
3844,
3855,
272,
661,
2571,
297,
4018,
8380,
1190,
1448,
83,
5434,
3855,
272,
661,
7695,
297,
4018,
8380,
1190,
577,
711,
320,
3889,
3855,
272,
661,
36,
297,
4018,
11675,
10335,
3855,
272,
661,
8980,
297,
4018,
43,
279,
1017,
867,
290,
428,
352,
16080,
3855,
272,
661,
2846,
297,
4018,
51,
7586,
1129,
338,
738,
5369,
65,
577,
285,
16080,
3855,
272,
661,
5196,
297,
4018,
51,
7586,
1129,
338,
12377,
292,
3855,
272,
661,
5745,
297,
4018,
51,
7586,
1129,
338,
428,
352,
16080,
3855,
272,
661,
1093,
297,
4018,
31147,
3210,
85,
3855,
272,
661,
29173,
297,
4018,
31147,
3210,
85,
738,
5369,
65,
3855,
272,
661,
13860,
297,
4018,
46,
1481,
446,
26244,
269,
3855,
272,
661,
10892,
297,
4018,
34,
10874,
3855,
272,
661,
8045,
297,
4018,
51,
7586,
1129,
338,
738,
5369,
65,
25645,
80,
348,
3844,
290,
3855,
272,
661,
17751,
297,
4018,
39,
269,
1888,
12201,
3855,
272,
661,
10872,
297,
4018,
51,
7586,
1129,
338,
377,
287,
5294,
72,
3855,
272,
661,
4564,
297,
4018,
12460,
34,
446,
491,
676,
656,
75,
3855,
272,
661,
3177,
297,
4018,
48,
439,
1458,
366,
290,
510,
439,
1458,
12377,
292,
3855,
272,
661,
7438,
297,
4018,
51,
7586,
1129,
338,
377,
287,
2721,
17956,
3855,
272,
661,
37,
297,
4018,
35,
3621,
13520,
3855,
272,
661,
11765,
297,
4018,
12460,
34,
446,
12094,
2470,
758,
3855,
272,
661,
14138,
297,
4018,
46,
1481,
446,
481,
320,
470,
3855,
272,
661,
1149,
297,
4018,
46,
1481,
446,
12094,
2470,
3855,
272,
661,
38,
297,
4018,
34,
974,
269,
3855,
272,
661,
39,
297,
4018,
48,
5711,
21632,
290,
3855,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
braintree/braintree_python
|
tests/unit/test_us_bank_account.py
|
1
|
2169
|
from tests.test_helper import *
from datetime import date
from braintree.us_bank_account import UsBankAccount
from braintree.us_bank_account_verification import UsBankAccountVerification
class TestUsBankAccount(unittest.TestCase):
def test_constructor(self):
attributes = {
"last_four": "1234",
"routing_number": "55555",
"account_type": "fake-account",
"account_holder_name": "John Doe",
"token": "7777-7777",
"image_url": "some.png",
"bank_name": "Chase",
"ach_mandate": None,
}
us_bank_account = UsBankAccount({}, attributes)
self.assertEqual(us_bank_account.last_four, "1234")
self.assertEqual(us_bank_account.routing_number, "55555")
self.assertEqual(us_bank_account.account_type, "fake-account")
self.assertEqual(us_bank_account.account_holder_name, "John Doe")
self.assertEqual(us_bank_account.token, "7777-7777")
self.assertEqual(us_bank_account.image_url, "some.png")
self.assertEqual(us_bank_account.bank_name, "Chase")
self.assertEqual(us_bank_account.ach_mandate, None)
attributes["ach_mandate"] = {"text":"Some mandate", "accepted_at": date(2013, 4, 10)}
us_bank_account_mandated = UsBankAccount({}, attributes)
self.assertEqual(us_bank_account_mandated.ach_mandate.text, "Some mandate")
self.assertEqual(us_bank_account_mandated.ach_mandate.accepted_at, date(2013, 4, 10))
def test_converts_verifications_to_objects(self):
attributes = {
"verifications": [
{
"status": "verified",
"verification_method": "network_check",
},
],
}
us_bank_account = UsBankAccount({}, attributes)
self.assertEqual(len(us_bank_account.verifications), 1)
verification = us_bank_account.verifications[0]
self.assertEqual(verification.status, UsBankAccountVerification.Status.Verified)
self.assertEqual(verification.verification_method, UsBankAccountVerification.VerificationMethod.NetworkCheck)
|
mit
|
[
504,
2295,
14,
396,
63,
3676,
492,
627,
199,
504,
2197,
492,
1434,
199,
504,
330,
3156,
850,
14,
527,
63,
9860,
63,
2048,
492,
18482,
14814,
6009,
199,
504,
330,
3156,
850,
14,
527,
63,
9860,
63,
2048,
63,
16257,
492,
18482,
14814,
6009,
22595,
199,
199,
533,
1379,
23642,
14814,
6009,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1880,
8,
277,
304,
267,
3004,
275,
469,
288,
298,
2019,
63,
13672,
582,
298,
4321,
401,
288,
298,
9492,
63,
1955,
582,
298,
1229,
15722,
401,
288,
298,
2048,
63,
466,
582,
298,
3183,
13,
2048,
401,
288,
298,
2048,
63,
4302,
63,
354,
582,
298,
12923,
30795,
401,
288,
298,
1418,
582,
298,
16713,
13,
16713,
401,
288,
298,
1569,
63,
633,
582,
298,
3972,
14,
4524,
401,
288,
298,
9860,
63,
354,
582,
298,
1049,
482,
401,
288,
298,
1225,
63,
10333,
323,
582,
488,
12,
267,
789,
398,
2739,
63,
9860,
63,
2048,
275,
18482,
14814,
6009,
16037,
3004,
9,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
2019,
63,
13672,
12,
298,
4321,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
9492,
63,
1955,
12,
298,
1229,
15722,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
2048,
63,
466,
12,
298,
3183,
13,
2048,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
2048,
63,
4302,
63,
354,
12,
298,
12923,
30795,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
1418,
12,
298,
16713,
13,
16713,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
1569,
63,
633,
12,
298,
3972,
14,
4524,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
9860,
63,
354,
12,
298,
1049,
482,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
1225,
63,
10333,
323,
12,
488,
9,
398,
3004,
905,
1225,
63,
10333,
323,
937,
275,
2420,
505,
5122,
7700,
333,
460,
323,
401,
298,
16121,
63,
292,
582,
1434,
8,
6965,
12,
841,
12,
1616,
6769,
267,
2739,
63,
9860,
63,
2048,
63,
10333,
972,
275,
18482,
14814,
6009,
16037,
3004,
9,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
63,
10333,
972,
14,
1225,
63,
10333,
323,
14,
505,
12,
298,
7700,
333,
460,
323,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
63,
10333,
972,
14,
1225,
63,
10333,
323,
14,
16121,
63,
292,
12,
1434,
8,
6965,
12,
841,
12,
1616,
430,
339,
347,
511,
63,
28392,
63,
16257,
83,
63,
475,
63,
1462,
8,
277,
304,
267,
3004,
275,
469,
288,
298,
16257,
83,
582,
359,
355,
469,
490,
298,
1205,
582,
298,
12949,
401,
490,
298,
16257,
63,
765,
582,
298,
1200,
63,
1074,
401,
355,
1660,
288,
2156,
267,
789,
398,
2739,
63,
9860,
63,
2048,
275,
18482,
14814,
6009,
16037,
3004,
9,
267,
291,
14,
629,
8,
552,
8,
527,
63,
9860,
63,
2048,
14,
16257,
83,
395,
413,
9,
398,
14786,
275,
2739,
63,
9860,
63,
2048,
14,
16257,
83,
59,
16,
61,
398,
291,
14,
629,
8,
16257,
14,
1205,
12,
18482,
14814,
6009,
22595,
14,
3694,
14,
3673,
4541,
9,
267,
291,
14,
629,
8,
16257,
14,
16257,
63,
765,
12,
18482,
14814,
6009,
22595,
14,
22595,
3767,
14,
4491,
1799,
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
] |
[
2295,
14,
396,
63,
3676,
492,
627,
199,
504,
2197,
492,
1434,
199,
504,
330,
3156,
850,
14,
527,
63,
9860,
63,
2048,
492,
18482,
14814,
6009,
199,
504,
330,
3156,
850,
14,
527,
63,
9860,
63,
2048,
63,
16257,
492,
18482,
14814,
6009,
22595,
199,
199,
533,
1379,
23642,
14814,
6009,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1880,
8,
277,
304,
267,
3004,
275,
469,
288,
298,
2019,
63,
13672,
582,
298,
4321,
401,
288,
298,
9492,
63,
1955,
582,
298,
1229,
15722,
401,
288,
298,
2048,
63,
466,
582,
298,
3183,
13,
2048,
401,
288,
298,
2048,
63,
4302,
63,
354,
582,
298,
12923,
30795,
401,
288,
298,
1418,
582,
298,
16713,
13,
16713,
401,
288,
298,
1569,
63,
633,
582,
298,
3972,
14,
4524,
401,
288,
298,
9860,
63,
354,
582,
298,
1049,
482,
401,
288,
298,
1225,
63,
10333,
323,
582,
488,
12,
267,
789,
398,
2739,
63,
9860,
63,
2048,
275,
18482,
14814,
6009,
16037,
3004,
9,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
2019,
63,
13672,
12,
298,
4321,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
9492,
63,
1955,
12,
298,
1229,
15722,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
2048,
63,
466,
12,
298,
3183,
13,
2048,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
2048,
63,
4302,
63,
354,
12,
298,
12923,
30795,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
1418,
12,
298,
16713,
13,
16713,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
1569,
63,
633,
12,
298,
3972,
14,
4524,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
9860,
63,
354,
12,
298,
1049,
482,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
14,
1225,
63,
10333,
323,
12,
488,
9,
398,
3004,
905,
1225,
63,
10333,
323,
937,
275,
2420,
505,
5122,
7700,
333,
460,
323,
401,
298,
16121,
63,
292,
582,
1434,
8,
6965,
12,
841,
12,
1616,
6769,
267,
2739,
63,
9860,
63,
2048,
63,
10333,
972,
275,
18482,
14814,
6009,
16037,
3004,
9,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
63,
10333,
972,
14,
1225,
63,
10333,
323,
14,
505,
12,
298,
7700,
333,
460,
323,
531,
267,
291,
14,
629,
8,
527,
63,
9860,
63,
2048,
63,
10333,
972,
14,
1225,
63,
10333,
323,
14,
16121,
63,
292,
12,
1434,
8,
6965,
12,
841,
12,
1616,
430,
339,
347,
511,
63,
28392,
63,
16257,
83,
63,
475,
63,
1462,
8,
277,
304,
267,
3004,
275,
469,
288,
298,
16257,
83,
582,
359,
355,
469,
490,
298,
1205,
582,
298,
12949,
401,
490,
298,
16257,
63,
765,
582,
298,
1200,
63,
1074,
401,
355,
1660,
288,
2156,
267,
789,
398,
2739,
63,
9860,
63,
2048,
275,
18482,
14814,
6009,
16037,
3004,
9,
267,
291,
14,
629,
8,
552,
8,
527,
63,
9860,
63,
2048,
14,
16257,
83,
395,
413,
9,
398,
14786,
275,
2739,
63,
9860,
63,
2048,
14,
16257,
83,
59,
16,
61,
398,
291,
14,
629,
8,
16257,
14,
1205,
12,
18482,
14814,
6009,
22595,
14,
3694,
14,
3673,
4541,
9,
267,
291,
14,
629,
8,
16257,
14,
16257,
63,
765,
12,
18482,
14814,
6009,
22595,
14,
22595,
3767,
14,
4491,
1799,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
elParaguayo/RPi-InfoScreen-Kivy
|
screens/londonbus/londonbus.py
|
4
|
5544
|
"""This script demonstrates how to retrieve bus countdown information
from the TfL website and turn it into a structure that can then be used by
other python codes.
Unfortunately, the bus countdown information is not true JSON so, as you'll
see from the code below, we need to play with it a bit first in order to
parse it successfully.
Please note, if you use TfL data in your application you should
acknowledge the source of your data as appropriate.
"""
# Simple way of submitting web requests (easier to use than urllib2)
import requests
# We need json to turn the JSON response into a python dict/list
import json
# We need datetime to calculate the amount of time until the bus is departure
from datetime import datetime
# This is the address used for the bus stop information.
# We'll need the bus stop ID (5 number code) but we'll set this when calling
# out lookup function so, for now, we leave a placeholder for it.
BASE_URL = ("http://countdown.api.tfl.gov.uk/interfaces/"
"ura/instant_V1?StopCode1={stopcode}"
"&ReturnList=LineName,DestinationText,EstimatedTime")
def __getBusData(stopcode):
# Add the stop code to the web address and get the page
r = requests.get(BASE_URL.format(stopcode=stopcode))
# If the request was ok
if r.status_code == 200:
# try and load the response into JSON
# However, the TFL data is not true JSON so we need a bit of
# hackery first. The response is a string representing a list
# on each line.
# So first, we split the response into a list of lines
rawdata = r.content.split("\r\n")
# Then we turn this into a single line of list strings separated
# by commas
rawdata = ",".join(rawdata)
# Lastly we wrap the string in list symbols so we have a string
# representing a single list
rawdata = "[{data}]".format(data=rawdata)
# And now we can load into JSON to give us an actual list of lists
return json.loads(rawdata)
else:
return None
def __getBusTime(epoch):
"""Function to convert the arrival time into something a bit more
meaningful.
Takes a UTC epoch time argument and returns the number of minutes until
that time.
"""
# The bus arrival time is in milliseconds but we want seconds.
epoch = epoch / 1000
# Convert the epoch time number into a datetime object
bustime = datetime.utcfromtimestamp(epoch)
# Calculate the difference between now and the arrival time
# The difference is a timedelta object.
diff = bustime - datetime.utcnow()
# Unpack this into minutes and seconds (but we will discard the seconds)
minutes, _ = divmod(diff.total_seconds(), 60)
if minutes == 0:
arrival = "Due"
elif minutes == 1:
arrival = "1 minute"
else:
arrival = "{m:.0f} minutes".format(m=minutes)
# return both the formatted string and the timedelta object
return arrival, diff
def BusLookup(stopcode, filterbuses=None):
"""Method to look up bus arrival times at a given bus stop.
Takes two parameters:
stopcode: 5 digit ID code of desired stop
filterbuses: list of bus routes to filter by. If omitted, all bus routes
at the stop will be shown.
If filterbuses receives anything other than a list then a TypeError will
be raised.
Returns a list of dictionaries representing a bus:
route: String representing the bus route number
time: String representing the due time of the bus
delta: Timedelta object representing the time until arrival
The list is sorted in order of arrival time with the nearest bus first.
"""
# filterbuses should be a list, if it's not then we need to alert the
# user.
if filterbuses is not None and type(filterbuses) != list:
raise TypeError("filterbuses parameter must be a list.")
buslist = __getBusData(stopcode)
# Remove the first item from the list as it doesn't represent a bus
buslist.pop(0)
buses = []
# Loop through the buses in our response
for bus in buslist:
# Create an empty dictionary for the details
b = {}
# Set the route number of the bus
b["route"] = bus[1]
# Set the destination of the bus
b["destination"] = bus[2]
# Get the string time and timedelta object of the bus
b["time"], b["delta"] = __getBusTime(bus[3])
# Add the bus to our list
buses.append(b)
# We sort the buses in order of their arrival time (the raw response is
# not always provided in time order)
# To do this we sort by the timedelta object as this is the most accurate
# information we have on the buses
buses = sorted(buses, key=lambda x: x["delta"])
# If the user has provided a list of buses then we filter our list so that
# our result only includes the desired routes.
if filterbuses:
# Let's be nice to users, if they provide a list of integers (not
# unreasonable for a bus route number) then we'll convert it into a
# string to match what's stored in the dictionary
# NB string is more appropriate here is as the number represents the
# name of the route.
filterbuses = [str(x) for x in filterbuses]
# Just include buses that our in our list of requested routes
buses = [x for x in buses if x["route"] in filterbuses]
return buses
|
gpl-3.0
|
[
624,
2765,
2884,
23789,
31216,
4212,
370,
8044,
10414,
2338,
2110,
2556,
199,
504,
314,
377,
70,
44,
10691,
436,
7485,
652,
1901,
282,
5523,
626,
883,
2066,
506,
1202,
701,
199,
1848,
2366,
9479,
14,
199,
199,
1358,
21839,
12,
314,
10414,
2338,
2110,
2556,
365,
440,
2549,
4840,
880,
12,
465,
1265,
7171,
199,
3239,
687,
314,
1233,
5084,
12,
781,
1929,
370,
5232,
543,
652,
282,
4546,
1642,
315,
1865,
370,
199,
1122,
652,
8792,
14,
199,
199,
8254,
5317,
12,
340,
1265,
675,
377,
70,
44,
666,
315,
2195,
4223,
1265,
1077,
199,
564,
23504,
314,
1350,
402,
2195,
666,
465,
5827,
14,
199,
624,
199,
199,
3,
5870,
4340,
402,
11482,
1337,
3330,
4145,
334,
69,
305,
4446,
370,
675,
2419,
4011,
18,
9,
199,
646,
4145,
199,
199,
3,
2136,
1929,
2022,
370,
7485,
314,
4840,
1177,
1901,
282,
2366,
1211,
15,
513,
199,
646,
2022,
199,
199,
3,
2136,
1929,
2197,
370,
8671,
314,
5982,
402,
900,
5133,
314,
10414,
365,
21124,
608,
199,
504,
2197,
492,
2197,
199,
199,
3,
961,
365,
314,
2287,
1202,
367,
314,
10414,
3631,
2556,
14,
199,
3,
2136,
7171,
1929,
314,
10414,
3631,
2870,
334,
21,
1329,
1233,
9,
1325,
781,
7171,
663,
642,
1380,
6358,
199,
3,
734,
4237,
805,
880,
12,
367,
3063,
12,
781,
10137,
282,
10069,
367,
652,
14,
199,
5825,
63,
2632,
275,
1689,
1014,
921,
835,
2110,
14,
1246,
14,
84,
2327,
14,
16294,
14,
3210,
15,
7436,
6687,
288,
298,
12417,
15,
3615,
867,
63,
54,
17,
31,
6293,
3034,
17,
3126,
2379,
600,
7063,
288,
11746,
1767,
1296,
29,
3049,
985,
12,
13151,
1872,
12,
9169,
12754,
1366,
531,
421,
199,
318,
636,
362,
12106,
1451,
8,
2379,
600,
304,
272,
327,
2654,
314,
3631,
1233,
370,
314,
3330,
2287,
436,
664,
314,
2034,
272,
519,
275,
4145,
14,
362,
8,
5825,
63,
2632,
14,
908,
8,
2379,
600,
29,
2379,
600,
430,
339,
327,
982,
314,
1056,
1990,
4112,
272,
340,
519,
14,
1205,
63,
600,
508,
1926,
26,
953,
327,
862,
436,
2248,
314,
1177,
1901,
4840,
288,
327,
9738,
12,
314,
377,
3143,
666,
365,
440,
2549,
4840,
880,
781,
1929,
282,
4546,
402,
288,
327,
11176,
994,
1642,
14,
710,
1177,
365,
282,
1059,
6144,
282,
769,
288,
327,
641,
1924,
1004,
14,
288,
327,
2002,
1642,
12,
781,
3715,
314,
1177,
1901,
282,
769,
402,
2385,
288,
15705,
275,
519,
14,
1317,
14,
1294,
4582,
82,
60,
78,
531,
288,
327,
9442,
781,
7485,
642,
1901,
282,
2849,
1004,
402,
769,
3326,
11673,
288,
327,
701,
24476,
288,
15705,
275,
19089,
904,
8,
14901,
9,
288,
327,
15237,
590,
781,
4816,
314,
1059,
315,
769,
6698,
880,
781,
1172,
282,
1059,
288,
327,
6144,
282,
2849,
769,
288,
15705,
275,
7369,
91,
576,
11049,
1674,
908,
8,
576,
29,
14901,
9,
288,
327,
6061,
3063,
781,
883,
2248,
1901,
4840,
370,
8120,
2739,
376,
3503,
769,
402,
5548,
288,
372,
2022,
14,
3640,
8,
14901,
9,
339,
587,
26,
267,
372,
488,
421,
199,
318,
636,
362,
12106,
1366,
8,
7367,
304,
272,
408,
3481,
370,
3957,
314,
601,
26976,
900,
1901,
6020,
282,
4546,
1655,
272,
26562,
14,
339,
17415,
282,
12174,
9463,
900,
1423,
436,
2529,
314,
1329,
402,
9395,
5133,
272,
626,
900,
14,
272,
408,
272,
327,
710,
10414,
601,
26976,
900,
365,
315,
21131,
1325,
781,
2934,
4696,
14,
272,
9463,
275,
9463,
1182,
5198,
272,
327,
7905,
314,
9463,
900,
1329,
1901,
282,
2197,
909,
272,
330,
833,
1036,
275,
2197,
14,
5834,
18531,
8,
7367,
9,
272,
327,
12707,
314,
8865,
3382,
3063,
436,
314,
601,
26976,
900,
272,
327,
710,
8865,
365,
282,
6871,
909,
14,
272,
3915,
275,
330,
833,
1036,
446,
2197,
14,
10779,
342,
272,
327,
31017,
642,
1901,
9395,
436,
4696,
334,
7911,
781,
911,
16895,
314,
4696,
9,
272,
9395,
12,
485,
275,
16438,
8,
3028,
14,
2923,
63,
4515,
1062,
5212,
9,
272,
340,
9395,
508,
378,
26,
267,
601,
26976,
275,
298,
36,
310,
2,
272,
916,
9395,
508,
413,
26,
267,
601,
26976,
275,
298,
17,
12709,
2,
272,
587,
26,
267,
601,
26976,
275,
5310,
77,
14010,
16,
70,
93,
9395,
1674,
908,
8,
77,
29,
10430,
9,
339,
327,
372,
3865,
314,
7871,
1059,
436,
314,
6871,
909,
272,
372,
601,
26976,
12,
3915,
421,
199,
318,
18573,
7521,
8,
2379,
600,
12,
2457,
464,
874,
29,
403,
304,
272,
408,
3767,
370,
3648,
1536,
10414,
601,
26976,
5431,
737,
282,
1627,
10414,
3631,
14,
339,
17415,
2877,
2633,
26,
2541,
3631,
600,
26,
259,
959,
10964,
2870,
1233,
402,
6387,
3631,
489,
2457,
464,
874,
26,
769,
402,
10414,
15777,
370,
2457,
701,
14,
982,
11684,
12,
1006,
10414,
15777,
673,
737,
314,
3631,
911,
506,
9164,
14,
339,
982,
2457,
464,
874,
23192,
7003,
1163,
2419,
282,
769,
2066,
282,
3146,
911,
272,
506,
4915,
14,
339,
1803,
282,
769,
402,
11196,
6144,
282,
10414,
26,
2541,
7475,
26,
2624,
6144,
314,
10414,
7475,
1329,
489,
900,
26,
221,
2624,
6144,
314,
7037,
900,
402,
314,
10414,
489,
5762,
26,
4703,
3136,
909,
6144,
314,
900,
5133,
601,
26976,
339,
710,
769,
365,
3355,
315,
1865,
402,
601,
26976,
900,
543,
314,
17173,
10414,
1642,
14,
272,
408,
272,
327,
2457,
464,
874,
1077,
506,
282,
769,
12,
340,
652,
1159,
440,
2066,
781,
1929,
370,
10459,
314,
272,
327,
922,
14,
272,
340,
2457,
464,
874,
365,
440,
488,
436,
730,
8,
1541,
464,
874,
9,
1137,
769,
26,
267,
746,
3146,
480,
1541,
464,
874,
2725,
1471,
506,
282,
769,
2685,
339,
10414,
513,
275,
636,
362,
12106,
1451,
8,
2379,
600,
9,
339,
327,
5852,
314,
1642,
1242,
687,
314,
769,
465,
652,
3181,
1133,
2954,
282,
10414,
272,
10414,
513,
14,
1935,
8,
16,
9,
339,
1032,
874,
275,
942,
339,
327,
18175,
4012,
314,
1032,
874,
315,
4154,
1177,
272,
367,
10414,
315,
10414,
513,
26,
267,
327,
2790,
376,
2701,
2600,
367,
314,
2436,
267,
330,
275,
1052,
267,
327,
2494,
314,
7475,
1329,
402,
314,
10414,
267,
330,
905,
4449
] |
[
2765,
2884,
23789,
31216,
4212,
370,
8044,
10414,
2338,
2110,
2556,
199,
504,
314,
377,
70,
44,
10691,
436,
7485,
652,
1901,
282,
5523,
626,
883,
2066,
506,
1202,
701,
199,
1848,
2366,
9479,
14,
199,
199,
1358,
21839,
12,
314,
10414,
2338,
2110,
2556,
365,
440,
2549,
4840,
880,
12,
465,
1265,
7171,
199,
3239,
687,
314,
1233,
5084,
12,
781,
1929,
370,
5232,
543,
652,
282,
4546,
1642,
315,
1865,
370,
199,
1122,
652,
8792,
14,
199,
199,
8254,
5317,
12,
340,
1265,
675,
377,
70,
44,
666,
315,
2195,
4223,
1265,
1077,
199,
564,
23504,
314,
1350,
402,
2195,
666,
465,
5827,
14,
199,
624,
199,
199,
3,
5870,
4340,
402,
11482,
1337,
3330,
4145,
334,
69,
305,
4446,
370,
675,
2419,
4011,
18,
9,
199,
646,
4145,
199,
199,
3,
2136,
1929,
2022,
370,
7485,
314,
4840,
1177,
1901,
282,
2366,
1211,
15,
513,
199,
646,
2022,
199,
199,
3,
2136,
1929,
2197,
370,
8671,
314,
5982,
402,
900,
5133,
314,
10414,
365,
21124,
608,
199,
504,
2197,
492,
2197,
199,
199,
3,
961,
365,
314,
2287,
1202,
367,
314,
10414,
3631,
2556,
14,
199,
3,
2136,
7171,
1929,
314,
10414,
3631,
2870,
334,
21,
1329,
1233,
9,
1325,
781,
7171,
663,
642,
1380,
6358,
199,
3,
734,
4237,
805,
880,
12,
367,
3063,
12,
781,
10137,
282,
10069,
367,
652,
14,
199,
5825,
63,
2632,
275,
1689,
1014,
921,
835,
2110,
14,
1246,
14,
84,
2327,
14,
16294,
14,
3210,
15,
7436,
6687,
288,
298,
12417,
15,
3615,
867,
63,
54,
17,
31,
6293,
3034,
17,
3126,
2379,
600,
7063,
288,
11746,
1767,
1296,
29,
3049,
985,
12,
13151,
1872,
12,
9169,
12754,
1366,
531,
421,
199,
318,
636,
362,
12106,
1451,
8,
2379,
600,
304,
272,
327,
2654,
314,
3631,
1233,
370,
314,
3330,
2287,
436,
664,
314,
2034,
272,
519,
275,
4145,
14,
362,
8,
5825,
63,
2632,
14,
908,
8,
2379,
600,
29,
2379,
600,
430,
339,
327,
982,
314,
1056,
1990,
4112,
272,
340,
519,
14,
1205,
63,
600,
508,
1926,
26,
953,
327,
862,
436,
2248,
314,
1177,
1901,
4840,
288,
327,
9738,
12,
314,
377,
3143,
666,
365,
440,
2549,
4840,
880,
781,
1929,
282,
4546,
402,
288,
327,
11176,
994,
1642,
14,
710,
1177,
365,
282,
1059,
6144,
282,
769,
288,
327,
641,
1924,
1004,
14,
288,
327,
2002,
1642,
12,
781,
3715,
314,
1177,
1901,
282,
769,
402,
2385,
288,
15705,
275,
519,
14,
1317,
14,
1294,
4582,
82,
60,
78,
531,
288,
327,
9442,
781,
7485,
642,
1901,
282,
2849,
1004,
402,
769,
3326,
11673,
288,
327,
701,
24476,
288,
15705,
275,
19089,
904,
8,
14901,
9,
288,
327,
15237,
590,
781,
4816,
314,
1059,
315,
769,
6698,
880,
781,
1172,
282,
1059,
288,
327,
6144,
282,
2849,
769,
288,
15705,
275,
7369,
91,
576,
11049,
1674,
908,
8,
576,
29,
14901,
9,
288,
327,
6061,
3063,
781,
883,
2248,
1901,
4840,
370,
8120,
2739,
376,
3503,
769,
402,
5548,
288,
372,
2022,
14,
3640,
8,
14901,
9,
339,
587,
26,
267,
372,
488,
421,
199,
318,
636,
362,
12106,
1366,
8,
7367,
304,
272,
408,
3481,
370,
3957,
314,
601,
26976,
900,
1901,
6020,
282,
4546,
1655,
272,
26562,
14,
339,
17415,
282,
12174,
9463,
900,
1423,
436,
2529,
314,
1329,
402,
9395,
5133,
272,
626,
900,
14,
272,
408,
272,
327,
710,
10414,
601,
26976,
900,
365,
315,
21131,
1325,
781,
2934,
4696,
14,
272,
9463,
275,
9463,
1182,
5198,
272,
327,
7905,
314,
9463,
900,
1329,
1901,
282,
2197,
909,
272,
330,
833,
1036,
275,
2197,
14,
5834,
18531,
8,
7367,
9,
272,
327,
12707,
314,
8865,
3382,
3063,
436,
314,
601,
26976,
900,
272,
327,
710,
8865,
365,
282,
6871,
909,
14,
272,
3915,
275,
330,
833,
1036,
446,
2197,
14,
10779,
342,
272,
327,
31017,
642,
1901,
9395,
436,
4696,
334,
7911,
781,
911,
16895,
314,
4696,
9,
272,
9395,
12,
485,
275,
16438,
8,
3028,
14,
2923,
63,
4515,
1062,
5212,
9,
272,
340,
9395,
508,
378,
26,
267,
601,
26976,
275,
298,
36,
310,
2,
272,
916,
9395,
508,
413,
26,
267,
601,
26976,
275,
298,
17,
12709,
2,
272,
587,
26,
267,
601,
26976,
275,
5310,
77,
14010,
16,
70,
93,
9395,
1674,
908,
8,
77,
29,
10430,
9,
339,
327,
372,
3865,
314,
7871,
1059,
436,
314,
6871,
909,
272,
372,
601,
26976,
12,
3915,
421,
199,
318,
18573,
7521,
8,
2379,
600,
12,
2457,
464,
874,
29,
403,
304,
272,
408,
3767,
370,
3648,
1536,
10414,
601,
26976,
5431,
737,
282,
1627,
10414,
3631,
14,
339,
17415,
2877,
2633,
26,
2541,
3631,
600,
26,
259,
959,
10964,
2870,
1233,
402,
6387,
3631,
489,
2457,
464,
874,
26,
769,
402,
10414,
15777,
370,
2457,
701,
14,
982,
11684,
12,
1006,
10414,
15777,
673,
737,
314,
3631,
911,
506,
9164,
14,
339,
982,
2457,
464,
874,
23192,
7003,
1163,
2419,
282,
769,
2066,
282,
3146,
911,
272,
506,
4915,
14,
339,
1803,
282,
769,
402,
11196,
6144,
282,
10414,
26,
2541,
7475,
26,
2624,
6144,
314,
10414,
7475,
1329,
489,
900,
26,
221,
2624,
6144,
314,
7037,
900,
402,
314,
10414,
489,
5762,
26,
4703,
3136,
909,
6144,
314,
900,
5133,
601,
26976,
339,
710,
769,
365,
3355,
315,
1865,
402,
601,
26976,
900,
543,
314,
17173,
10414,
1642,
14,
272,
408,
272,
327,
2457,
464,
874,
1077,
506,
282,
769,
12,
340,
652,
1159,
440,
2066,
781,
1929,
370,
10459,
314,
272,
327,
922,
14,
272,
340,
2457,
464,
874,
365,
440,
488,
436,
730,
8,
1541,
464,
874,
9,
1137,
769,
26,
267,
746,
3146,
480,
1541,
464,
874,
2725,
1471,
506,
282,
769,
2685,
339,
10414,
513,
275,
636,
362,
12106,
1451,
8,
2379,
600,
9,
339,
327,
5852,
314,
1642,
1242,
687,
314,
769,
465,
652,
3181,
1133,
2954,
282,
10414,
272,
10414,
513,
14,
1935,
8,
16,
9,
339,
1032,
874,
275,
942,
339,
327,
18175,
4012,
314,
1032,
874,
315,
4154,
1177,
272,
367,
10414,
315,
10414,
513,
26,
267,
327,
2790,
376,
2701,
2600,
367,
314,
2436,
267,
330,
275,
1052,
267,
327,
2494,
314,
7475,
1329,
402,
314,
10414,
267,
330,
905,
4449,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tanmaykm/edx-platform
|
common/lib/capa/capa/customrender.py
|
60
|
5603
|
"""
This has custom renderers: classes that know how to render certain problem tags (e.g. <math> and
<solution>) to html.
These tags do not have state, so they just get passed the system (for access to render_template),
and the xml element.
"""
import logging
import re
from cgi import escape as cgi_escape
from lxml import etree
import xml.sax.saxutils as saxutils
from .registry import TagRegistry
log = logging.getLogger(__name__)
registry = TagRegistry()
#-----------------------------------------------------------------------------
class MathRenderer(object):
tags = ['math']
def __init__(self, system, xml):
r"""
Render math using latex-like formatting.
Examples:
<math>$\displaystyle U(r)=4 U_0 $</math>
<math>$r_0$</math>
We convert these to [mathjax]...[/mathjax] and [mathjaxinline]...[/mathjaxinline]
TODO: use shorter tags (but this will require converting problem XML files!)
"""
self.system = system
self.xml = xml
mathstr = re.sub(r'\$(.*)\$', r'[mathjaxinline]\1[/mathjaxinline]', xml.text)
mtag = 'mathjax'
if r'\displaystyle' not in mathstr:
mtag += 'inline'
else:
mathstr = mathstr.replace(r'\displaystyle', '')
self.mathstr = mathstr.replace('mathjaxinline]', '%s]' % mtag)
def get_html(self):
"""
Return the contents of this tag, rendered to html, as an etree element.
"""
# TODO: why are there nested html tags here?? Why are there html tags at all, in fact?
html = '<html><html>%s</html><html>%s</html></html>' % (
self.mathstr, saxutils.escape(self.xml.tail))
try:
xhtml = etree.XML(html)
except Exception as err:
if self.system.DEBUG:
msg = '<html><div class="inline-error"><p>Error %s</p>' % (
str(err).replace('<', '<'))
msg += ('<p>Failed to construct math expression from <pre>%s</pre></p>' %
html.replace('<', '<'))
msg += "</div></html>"
log.error(msg)
return etree.XML(msg)
else:
raise
return xhtml
registry.register(MathRenderer)
#-----------------------------------------------------------------------------
class SolutionRenderer(object):
"""
A solution is just a <span>...</span> which is given an ID, that is used for displaying an
extended answer (a problem "solution") after "show answers" is pressed.
Note that the solution content is NOT rendered and returned in the HTML. It is obtained by an
ajax call.
"""
tags = ['solution']
def __init__(self, system, xml):
self.system = system
self.id = xml.get('id')
def get_html(self):
context = {'id': self.id}
html = self.system.render_template("solutionspan.html", context)
return etree.XML(html)
registry.register(SolutionRenderer)
#-----------------------------------------------------------------------------
class TargetedFeedbackRenderer(object):
"""
A targeted feedback is just a <span>...</span> that is used for displaying an
extended piece of feedback to students if they incorrectly answered a question.
"""
tags = ['targetedfeedback']
def __init__(self, system, xml):
self.system = system
self.xml = xml
def get_html(self):
"""
Return the contents of this tag, rendered to html, as an etree element.
"""
html = '<section class="targeted-feedback-span"><span>{}</span></section>'.format(etree.tostring(self.xml))
try:
xhtml = etree.XML(html)
except Exception as err: # pylint: disable=broad-except
if self.system.DEBUG:
msg = """
<html>
<div class="inline-error">
<p>Error {err}</p>
<p>Failed to construct targeted feedback from <pre>{html}</pre></p>
</div>
</html>
""".format(err=cgi_escape(err), html=cgi_escape(html))
log.error(msg)
return etree.XML(msg)
else:
raise
return xhtml
registry.register(TargetedFeedbackRenderer)
#-----------------------------------------------------------------------------
class ClarificationRenderer(object):
"""
A clarification appears as an inline icon which reveals more information when the user
hovers over it.
e.g. <p>Enter the ROA <clarification>Return on Assets</clarification> for 2015:</p>
"""
tags = ['clarification']
def __init__(self, system, xml):
self.system = system
# Get any text content found inside this tag prior to the first child tag. It may be a string or None type.
initial_text = xml.text if xml.text else ''
self.inner_html = initial_text + ''.join(etree.tostring(element) for element in xml)
self.tail = xml.tail
def get_html(self):
"""
Return the contents of this tag, rendered to html, as an etree element.
"""
context = {'clarification': self.inner_html}
html = self.system.render_template("clarification.html", context)
xml = etree.XML(html)
# We must include any text that was following our original <clarification>...</clarification> XML node.:
xml.tail = self.tail
return xml
registry.register(ClarificationRenderer)
|
agpl-3.0
|
[
624,
199,
2765,
965,
3537,
2903,
26529,
26,
3992,
626,
5715,
4212,
370,
3795,
9842,
5160,
3762,
334,
69,
14,
71,
14,
665,
3442,
30,
436,
199,
28,
14458,
18956,
370,
3517,
14,
199,
199,
20676,
3762,
886,
440,
1172,
1174,
12,
880,
2985,
2951,
664,
3032,
314,
2656,
334,
509,
2879,
370,
3795,
63,
1160,
395,
199,
460,
314,
2748,
1819,
14,
199,
624,
199,
199,
646,
2050,
199,
646,
295,
199,
199,
504,
16004,
492,
4772,
465,
16004,
63,
3765,
199,
504,
14490,
492,
7559,
199,
646,
2748,
14,
14338,
14,
14338,
1208,
465,
308,
1219,
1208,
199,
504,
1275,
5189,
492,
8053,
10899,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5189,
275,
8053,
10899,
342,
199,
199,
18045,
421,
199,
533,
21066,
11355,
8,
785,
304,
272,
3762,
275,
788,
3442,
418,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
2748,
304,
267,
519,
624,
267,
17769,
3473,
1808,
15571,
13,
2930,
10803,
14,
398,
6058,
26,
398,
665,
3442,
30,
16827,
2918,
2487,
738,
8,
82,
23397,
20,
738,
63,
16,
2672,
1108,
3442,
30,
267,
665,
3442,
30,
4,
82,
63,
16,
4,
1108,
3442,
30,
398,
2136,
3957,
3520,
370,
359,
3442,
15863,
61,
1396,
28787,
3442,
15863,
61,
436,
359,
3442,
15863,
6460,
61,
1396,
28787,
3442,
15863,
6460,
61,
398,
3254,
26,
675,
18299,
3762,
334,
7911,
642,
911,
4409,
13806,
5160,
4692,
1584,
21866,
267,
408,
267,
291,
14,
2253,
275,
2656,
267,
291,
14,
1652,
275,
2748,
398,
3473,
495,
275,
295,
14,
954,
8,
82,
1154,
6629,
2795,
2862,
4268,
519,
3894,
3442,
15863,
6460,
7272,
17,
28787,
3442,
15863,
6460,
4300,
2748,
14,
505,
9,
267,
333,
1450,
275,
283,
3442,
15863,
7,
267,
340,
519,
1154,
2918,
2487,
7,
440,
315,
3473,
495,
26,
288,
333,
1450,
847,
283,
6460,
7,
267,
587,
26,
288,
3473,
495,
275,
3473,
495,
14,
1814,
8,
82,
1154,
2918,
2487,
297,
4074,
267,
291,
14,
3442,
495,
275,
3473,
495,
14,
1814,
360,
3442,
15863,
6460,
4300,
1543,
83,
6616,
450,
333,
1450,
9,
339,
347,
664,
63,
1360,
8,
277,
304,
267,
408,
267,
1432,
314,
4072,
402,
642,
1947,
12,
8018,
370,
3517,
12,
465,
376,
7559,
1819,
14,
267,
408,
267,
327,
3254,
26,
10842,
787,
2337,
6032,
3517,
3762,
2348,
10674,
221,
6827,
787,
2337,
3517,
3762,
737,
1006,
12,
315,
10572,
31,
267,
3517,
275,
2650,
1360,
2535,
1360,
6598,
83,
1108,
1360,
2535,
1360,
6598,
83,
1108,
1360,
2957,
1360,
3524,
450,
334,
288,
291,
14,
3442,
495,
12,
308,
1219,
1208,
14,
3765,
8,
277,
14,
1652,
14,
1521,
430,
267,
862,
26,
288,
671,
1360,
275,
7559,
14,
4317,
8,
1360,
9,
267,
871,
2186,
465,
2329,
26,
288,
340,
291,
14,
2253,
14,
5287,
26,
355,
1499,
275,
2650,
1360,
2535,
3015,
1021,
628,
6460,
13,
705,
8186,
80,
30,
547,
450,
83,
1108,
80,
3524,
450,
334,
490,
620,
8,
1508,
680,
1814,
4827,
297,
7673,
4116,
27,
1333,
355,
1499,
847,
19990,
80,
30,
4276,
370,
6982,
3473,
3965,
687,
665,
657,
6598,
83,
1108,
657,
2957,
80,
3524,
450,
717,
3517,
14,
1814,
4827,
297,
7673,
4116,
27,
1333,
355,
1499,
847,
15683,
3015,
2957,
1360,
4335,
355,
943,
14,
705,
8,
1328,
9,
355,
372,
7559,
14,
4317,
8,
1328,
9,
288,
587,
26,
355,
746,
267,
372,
671,
1360,
421,
199,
5189,
14,
2683,
8,
18568,
11355,
9,
199,
199,
18045,
421,
199,
533,
9274,
11355,
8,
785,
304,
272,
408,
272,
437,
8744,
365,
2951,
282,
665,
3751,
30,
1396,
1108,
3751,
30,
1314,
365,
1627,
376,
2870,
12,
626,
365,
1202,
367,
20589,
376,
272,
9243,
6385,
334,
65,
5160,
298,
14458,
531,
2410,
298,
2384,
17133,
2,
365,
25167,
14,
339,
3390,
626,
314,
8744,
1564,
365,
2845,
8018,
436,
2138,
315,
314,
4163,
14,
2779,
365,
15884,
701,
376,
272,
25930,
1240,
14,
272,
408,
272,
3762,
275,
788,
14458,
418,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
2748,
304,
267,
291,
14,
2253,
275,
2656,
267,
291,
14,
344,
275,
2748,
14,
362,
360,
344,
358,
339,
347,
664,
63,
1360,
8,
277,
304,
267,
1067,
275,
791,
344,
356,
291,
14,
344,
93,
267,
3517,
275,
291,
14,
2253,
14,
3352,
63,
1160,
480,
14458,
3751,
14,
1360,
401,
1067,
9,
267,
372,
7559,
14,
4317,
8,
1360,
9,
199,
199,
5189,
14,
2683,
8,
24277,
11355,
9,
199,
199,
18045,
421,
199,
533,
377,
20174,
28687,
11355,
8,
785,
304,
272,
408,
272,
437,
307,
20174,
17145,
365,
2951,
282,
665,
3751,
30,
1396,
1108,
3751,
30,
626,
365,
1202,
367,
20589,
376,
272,
9243,
14854,
402,
17145,
370,
18557,
340,
2985,
22743,
4987,
21221,
282,
7894,
14,
272,
408,
272,
3762,
275,
788,
84,
20174,
13485,
418,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
2748,
304,
267,
291,
14,
2253,
275,
2656,
267,
291,
14,
1652,
275,
2748,
339,
347,
664,
63,
1360,
8,
277,
304,
267,
408,
267,
1432,
314,
4072,
402,
642,
1947,
12,
8018,
370,
3517,
12,
465,
376,
7559,
1819,
14,
267,
408,
267,
3517,
275,
2650,
2792,
1021,
628,
84,
20174,
13,
13485,
13,
3751,
8186,
3751,
30,
2440,
1108,
3751,
2957,
2792,
22936,
908,
8,
9464,
14,
14028,
8,
277,
14,
1652,
430,
267,
862,
26,
288,
671,
1360,
275,
7559,
14,
4317,
8,
1360,
9,
267,
871,
2186,
465,
2329,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
288,
340,
291,
14,
2253,
14,
5287,
26,
355,
1499,
275,
408,
490,
665,
1360,
30,
1993,
665,
3015,
1021,
628,
6460,
13,
705,
1743,
717,
665,
80,
30,
547,
469,
1508,
17890,
80,
30,
717,
665,
80,
30,
4276,
370,
6982,
307,
20174,
17145,
687,
665,
657,
22266,
1360,
17890,
657,
2957,
80,
30,
1993,
3068,
3015,
30,
490,
3068,
1360,
30,
355,
30512,
908,
8,
1508,
29,
13814,
63,
3765,
8,
1508,
395,
3517,
29,
13814,
63,
3765,
8,
1360,
430,
355,
943,
14,
705,
8,
1328,
9,
355,
372,
7559,
14,
4317,
8,
1328,
9,
288,
587,
26,
355,
746,
267,
372
] |
[
199,
2765,
965,
3537,
2903,
26529,
26,
3992,
626,
5715,
4212,
370,
3795,
9842,
5160,
3762,
334,
69,
14,
71,
14,
665,
3442,
30,
436,
199,
28,
14458,
18956,
370,
3517,
14,
199,
199,
20676,
3762,
886,
440,
1172,
1174,
12,
880,
2985,
2951,
664,
3032,
314,
2656,
334,
509,
2879,
370,
3795,
63,
1160,
395,
199,
460,
314,
2748,
1819,
14,
199,
624,
199,
199,
646,
2050,
199,
646,
295,
199,
199,
504,
16004,
492,
4772,
465,
16004,
63,
3765,
199,
504,
14490,
492,
7559,
199,
646,
2748,
14,
14338,
14,
14338,
1208,
465,
308,
1219,
1208,
199,
504,
1275,
5189,
492,
8053,
10899,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5189,
275,
8053,
10899,
342,
199,
199,
18045,
421,
199,
533,
21066,
11355,
8,
785,
304,
272,
3762,
275,
788,
3442,
418,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
2748,
304,
267,
519,
624,
267,
17769,
3473,
1808,
15571,
13,
2930,
10803,
14,
398,
6058,
26,
398,
665,
3442,
30,
16827,
2918,
2487,
738,
8,
82,
23397,
20,
738,
63,
16,
2672,
1108,
3442,
30,
267,
665,
3442,
30,
4,
82,
63,
16,
4,
1108,
3442,
30,
398,
2136,
3957,
3520,
370,
359,
3442,
15863,
61,
1396,
28787,
3442,
15863,
61,
436,
359,
3442,
15863,
6460,
61,
1396,
28787,
3442,
15863,
6460,
61,
398,
3254,
26,
675,
18299,
3762,
334,
7911,
642,
911,
4409,
13806,
5160,
4692,
1584,
21866,
267,
408,
267,
291,
14,
2253,
275,
2656,
267,
291,
14,
1652,
275,
2748,
398,
3473,
495,
275,
295,
14,
954,
8,
82,
1154,
6629,
2795,
2862,
4268,
519,
3894,
3442,
15863,
6460,
7272,
17,
28787,
3442,
15863,
6460,
4300,
2748,
14,
505,
9,
267,
333,
1450,
275,
283,
3442,
15863,
7,
267,
340,
519,
1154,
2918,
2487,
7,
440,
315,
3473,
495,
26,
288,
333,
1450,
847,
283,
6460,
7,
267,
587,
26,
288,
3473,
495,
275,
3473,
495,
14,
1814,
8,
82,
1154,
2918,
2487,
297,
4074,
267,
291,
14,
3442,
495,
275,
3473,
495,
14,
1814,
360,
3442,
15863,
6460,
4300,
1543,
83,
6616,
450,
333,
1450,
9,
339,
347,
664,
63,
1360,
8,
277,
304,
267,
408,
267,
1432,
314,
4072,
402,
642,
1947,
12,
8018,
370,
3517,
12,
465,
376,
7559,
1819,
14,
267,
408,
267,
327,
3254,
26,
10842,
787,
2337,
6032,
3517,
3762,
2348,
10674,
221,
6827,
787,
2337,
3517,
3762,
737,
1006,
12,
315,
10572,
31,
267,
3517,
275,
2650,
1360,
2535,
1360,
6598,
83,
1108,
1360,
2535,
1360,
6598,
83,
1108,
1360,
2957,
1360,
3524,
450,
334,
288,
291,
14,
3442,
495,
12,
308,
1219,
1208,
14,
3765,
8,
277,
14,
1652,
14,
1521,
430,
267,
862,
26,
288,
671,
1360,
275,
7559,
14,
4317,
8,
1360,
9,
267,
871,
2186,
465,
2329,
26,
288,
340,
291,
14,
2253,
14,
5287,
26,
355,
1499,
275,
2650,
1360,
2535,
3015,
1021,
628,
6460,
13,
705,
8186,
80,
30,
547,
450,
83,
1108,
80,
3524,
450,
334,
490,
620,
8,
1508,
680,
1814,
4827,
297,
7673,
4116,
27,
1333,
355,
1499,
847,
19990,
80,
30,
4276,
370,
6982,
3473,
3965,
687,
665,
657,
6598,
83,
1108,
657,
2957,
80,
3524,
450,
717,
3517,
14,
1814,
4827,
297,
7673,
4116,
27,
1333,
355,
1499,
847,
15683,
3015,
2957,
1360,
4335,
355,
943,
14,
705,
8,
1328,
9,
355,
372,
7559,
14,
4317,
8,
1328,
9,
288,
587,
26,
355,
746,
267,
372,
671,
1360,
421,
199,
5189,
14,
2683,
8,
18568,
11355,
9,
199,
199,
18045,
421,
199,
533,
9274,
11355,
8,
785,
304,
272,
408,
272,
437,
8744,
365,
2951,
282,
665,
3751,
30,
1396,
1108,
3751,
30,
1314,
365,
1627,
376,
2870,
12,
626,
365,
1202,
367,
20589,
376,
272,
9243,
6385,
334,
65,
5160,
298,
14458,
531,
2410,
298,
2384,
17133,
2,
365,
25167,
14,
339,
3390,
626,
314,
8744,
1564,
365,
2845,
8018,
436,
2138,
315,
314,
4163,
14,
2779,
365,
15884,
701,
376,
272,
25930,
1240,
14,
272,
408,
272,
3762,
275,
788,
14458,
418,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
2748,
304,
267,
291,
14,
2253,
275,
2656,
267,
291,
14,
344,
275,
2748,
14,
362,
360,
344,
358,
339,
347,
664,
63,
1360,
8,
277,
304,
267,
1067,
275,
791,
344,
356,
291,
14,
344,
93,
267,
3517,
275,
291,
14,
2253,
14,
3352,
63,
1160,
480,
14458,
3751,
14,
1360,
401,
1067,
9,
267,
372,
7559,
14,
4317,
8,
1360,
9,
199,
199,
5189,
14,
2683,
8,
24277,
11355,
9,
199,
199,
18045,
421,
199,
533,
377,
20174,
28687,
11355,
8,
785,
304,
272,
408,
272,
437,
307,
20174,
17145,
365,
2951,
282,
665,
3751,
30,
1396,
1108,
3751,
30,
626,
365,
1202,
367,
20589,
376,
272,
9243,
14854,
402,
17145,
370,
18557,
340,
2985,
22743,
4987,
21221,
282,
7894,
14,
272,
408,
272,
3762,
275,
788,
84,
20174,
13485,
418,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
2748,
304,
267,
291,
14,
2253,
275,
2656,
267,
291,
14,
1652,
275,
2748,
339,
347,
664,
63,
1360,
8,
277,
304,
267,
408,
267,
1432,
314,
4072,
402,
642,
1947,
12,
8018,
370,
3517,
12,
465,
376,
7559,
1819,
14,
267,
408,
267,
3517,
275,
2650,
2792,
1021,
628,
84,
20174,
13,
13485,
13,
3751,
8186,
3751,
30,
2440,
1108,
3751,
2957,
2792,
22936,
908,
8,
9464,
14,
14028,
8,
277,
14,
1652,
430,
267,
862,
26,
288,
671,
1360,
275,
7559,
14,
4317,
8,
1360,
9,
267,
871,
2186,
465,
2329,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
288,
340,
291,
14,
2253,
14,
5287,
26,
355,
1499,
275,
408,
490,
665,
1360,
30,
1993,
665,
3015,
1021,
628,
6460,
13,
705,
1743,
717,
665,
80,
30,
547,
469,
1508,
17890,
80,
30,
717,
665,
80,
30,
4276,
370,
6982,
307,
20174,
17145,
687,
665,
657,
22266,
1360,
17890,
657,
2957,
80,
30,
1993,
3068,
3015,
30,
490,
3068,
1360,
30,
355,
30512,
908,
8,
1508,
29,
13814,
63,
3765,
8,
1508,
395,
3517,
29,
13814,
63,
3765,
8,
1360,
430,
355,
943,
14,
705,
8,
1328,
9,
355,
372,
7559,
14,
4317,
8,
1328,
9,
288,
587,
26,
355,
746,
267,
372,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
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_tests/default_auto.py
|
101
|
1236
|
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
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 sys import stdout
class DefaultAuto():
""" Simple, basic host test's test runner waiting for serial port
output from MUT, no supervision over test running in MUT is executed.
"""
def test(self, selftest):
result = selftest.RESULT_SUCCESS
try:
while True:
c = selftest.mbed.serial_read(512)
if c is None:
return selftest.RESULT_IO_SERIAL
stdout.write(c)
stdout.flush()
except KeyboardInterrupt, _:
selftest.notify("\r\n[CTRL+C] exit")
result = selftest.RESULT_ERROR
return result
|
apache-2.0
|
[
624,
199,
3665,
15610,
199,
7384,
334,
67,
9,
7760,
13,
6965,
27155,
23954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
504,
984,
492,
3839,
199,
199,
533,
3758,
3358,
837,
272,
408,
5870,
12,
5678,
1591,
511,
1159,
511,
7876,
10923,
367,
3012,
1844,
267,
1072,
687,
603,
934,
12,
949,
1613,
2317,
1806,
511,
3879,
315,
603,
934,
365,
7934,
14,
272,
408,
272,
347,
511,
8,
277,
12,
291,
396,
304,
267,
754,
275,
291,
396,
14,
9517,
63,
12779,
267,
862,
26,
288,
1830,
715,
26,
355,
286,
275,
291,
396,
14,
3665,
14,
2171,
63,
739,
8,
7736,
9,
355,
340,
286,
365,
488,
26,
490,
372,
291,
396,
14,
9517,
63,
2090,
63,
19637,
355,
3839,
14,
952,
8,
67,
9,
355,
3839,
14,
4939,
342,
267,
871,
13483,
12,
24700,
288,
291,
396,
14,
6814,
4582,
82,
60,
78,
59,
22584,
11,
35,
61,
4458,
531,
288,
754,
275,
291,
396,
14,
9517,
63,
3170,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3665,
15610,
199,
7384,
334,
67,
9,
7760,
13,
6965,
27155,
23954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
504,
984,
492,
3839,
199,
199,
533,
3758,
3358,
837,
272,
408,
5870,
12,
5678,
1591,
511,
1159,
511,
7876,
10923,
367,
3012,
1844,
267,
1072,
687,
603,
934,
12,
949,
1613,
2317,
1806,
511,
3879,
315,
603,
934,
365,
7934,
14,
272,
408,
272,
347,
511,
8,
277,
12,
291,
396,
304,
267,
754,
275,
291,
396,
14,
9517,
63,
12779,
267,
862,
26,
288,
1830,
715,
26,
355,
286,
275,
291,
396,
14,
3665,
14,
2171,
63,
739,
8,
7736,
9,
355,
340,
286,
365,
488,
26,
490,
372,
291,
396,
14,
9517,
63,
2090,
63,
19637,
355,
3839,
14,
952,
8,
67,
9,
355,
3839,
14,
4939,
342,
267,
871,
13483,
12,
24700,
288,
291,
396,
14,
6814,
4582,
82,
60,
78,
59,
22584,
11,
35,
61,
4458,
531,
288,
754,
275,
291,
396,
14,
9517,
63,
3170,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
GreatFruitOmsk/screenly-ose
|
lib/backup_helper.py
|
1
|
1182
|
import tarfile
from datetime import datetime
from os import path, getenv, remove
import sh
directories = ['.screenly', 'screenly_assets']
default_archive_name = "screenly-backup"
static_dir = "screenly/static"
def create_backup(name=default_archive_name):
home = getenv('HOME')
archive_name = "{}-{}.tar.gz".format(
name if name else default_archive_name,
datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
)
file_path = path.join(home, static_dir, archive_name)
if path.isfile(file_path):
remove(file_path)
try:
with tarfile.open(file_path, "w:gz") as tar:
for directory in directories:
path_to_dir = path.join(home, directory)
tar.add(path_to_dir, arcname=directory)
except IOError as e:
remove(file_path)
raise e
return archive_name
def recover(file_path):
with tarfile.open(file_path, "r:gz") as tar:
for directory in directories:
if directory not in tar.getnames():
raise Exception("Archive is wrong.")
sh.sudo('/usr/local/bin/screenly_utils.sh', 'recover', path.abspath(file_path))
remove(file_path)
|
gpl-2.0
|
[
646,
13608,
199,
504,
2197,
492,
2197,
199,
504,
747,
492,
931,
12,
29626,
12,
2813,
199,
646,
1033,
199,
199,
12629,
275,
18953,
5410,
590,
297,
283,
5410,
590,
63,
12186,
418,
199,
885,
63,
6404,
63,
354,
275,
298,
5410,
590,
13,
5751,
2,
199,
1986,
63,
694,
275,
298,
5410,
590,
15,
1986,
2,
421,
199,
318,
1218,
63,
5751,
8,
354,
29,
885,
63,
6404,
63,
354,
304,
272,
5629,
275,
29626,
360,
9524,
358,
272,
6359,
63,
354,
275,
11491,
13,
31270,
5369,
14,
6838,
1674,
908,
8,
267,
536,
340,
536,
587,
849,
63,
6404,
63,
354,
12,
267,
2197,
14,
2131,
1252,
6205,
3647,
57,
3295,
77,
3295,
19772,
5,
40,
3295,
45,
3295,
51,
531,
272,
776,
272,
570,
63,
515,
275,
931,
14,
904,
8,
4219,
12,
2955,
63,
694,
12,
6359,
63,
354,
9,
272,
340,
931,
14,
6292,
8,
493,
63,
515,
304,
267,
2813,
8,
493,
63,
515,
9,
339,
862,
26,
267,
543,
13608,
14,
1490,
8,
493,
63,
515,
12,
298,
87,
26,
6838,
531,
465,
5330,
26,
953,
367,
2082,
315,
6602,
26,
355,
931,
63,
475,
63,
694,
275,
931,
14,
904,
8,
4219,
12,
2082,
9,
355,
5330,
14,
525,
8,
515,
63,
475,
63,
694,
12,
22177,
29,
3619,
9,
272,
871,
5925,
465,
325,
26,
267,
2813,
8,
493,
63,
515,
9,
267,
746,
325,
339,
372,
6359,
63,
354,
421,
199,
318,
22803,
8,
493,
63,
515,
304,
272,
543,
13608,
14,
1490,
8,
493,
63,
515,
12,
298,
82,
26,
6838,
531,
465,
5330,
26,
267,
367,
2082,
315,
6602,
26,
288,
340,
2082,
440,
315,
5330,
14,
362,
1247,
837,
355,
746,
2186,
480,
13042,
365,
6835,
2685,
339,
1033,
14,
12095,
2336,
2647,
15,
1832,
15,
1393,
15,
5410,
590,
63,
1208,
14,
609,
297,
283,
23131,
297,
931,
14,
4832,
8,
493,
63,
515,
430,
339,
2813,
8,
493,
63,
515,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13608,
199,
504,
2197,
492,
2197,
199,
504,
747,
492,
931,
12,
29626,
12,
2813,
199,
646,
1033,
199,
199,
12629,
275,
18953,
5410,
590,
297,
283,
5410,
590,
63,
12186,
418,
199,
885,
63,
6404,
63,
354,
275,
298,
5410,
590,
13,
5751,
2,
199,
1986,
63,
694,
275,
298,
5410,
590,
15,
1986,
2,
421,
199,
318,
1218,
63,
5751,
8,
354,
29,
885,
63,
6404,
63,
354,
304,
272,
5629,
275,
29626,
360,
9524,
358,
272,
6359,
63,
354,
275,
11491,
13,
31270,
5369,
14,
6838,
1674,
908,
8,
267,
536,
340,
536,
587,
849,
63,
6404,
63,
354,
12,
267,
2197,
14,
2131,
1252,
6205,
3647,
57,
3295,
77,
3295,
19772,
5,
40,
3295,
45,
3295,
51,
531,
272,
776,
272,
570,
63,
515,
275,
931,
14,
904,
8,
4219,
12,
2955,
63,
694,
12,
6359,
63,
354,
9,
272,
340,
931,
14,
6292,
8,
493,
63,
515,
304,
267,
2813,
8,
493,
63,
515,
9,
339,
862,
26,
267,
543,
13608,
14,
1490,
8,
493,
63,
515,
12,
298,
87,
26,
6838,
531,
465,
5330,
26,
953,
367,
2082,
315,
6602,
26,
355,
931,
63,
475,
63,
694,
275,
931,
14,
904,
8,
4219,
12,
2082,
9,
355,
5330,
14,
525,
8,
515,
63,
475,
63,
694,
12,
22177,
29,
3619,
9,
272,
871,
5925,
465,
325,
26,
267,
2813,
8,
493,
63,
515,
9,
267,
746,
325,
339,
372,
6359,
63,
354,
421,
199,
318,
22803,
8,
493,
63,
515,
304,
272,
543,
13608,
14,
1490,
8,
493,
63,
515,
12,
298,
82,
26,
6838,
531,
465,
5330,
26,
267,
367,
2082,
315,
6602,
26,
288,
340,
2082,
440,
315,
5330,
14,
362,
1247,
837,
355,
746,
2186,
480,
13042,
365,
6835,
2685,
339,
1033,
14,
12095,
2336,
2647,
15,
1832,
15,
1393,
15,
5410,
590,
63,
1208,
14,
609,
297,
283,
23131,
297,
931,
14,
4832,
8,
493,
63,
515,
430,
339,
2813,
8,
493,
63,
515,
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,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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
] |
boundarydevices/android_external_chromium_org
|
tools/json_schema_compiler/schema_util.py
|
139
|
1125
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Utilies for the processing of schema python structures.
"""
def CapitalizeFirstLetter(value):
return value[0].capitalize() + value[1:]
def GetNamespace(ref):
return SplitNamespace(ref)[0]
def StripNamespace(ref):
return SplitNamespace(ref)[1]
def SplitNamespace(ref):
"""Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow ->
(app.window, AppWindow). If |ref| isn't qualified then returns (None, ref).
"""
if '.' in ref:
return tuple(ref.rsplit('.', 1))
return (None, ref)
def JsFunctionNameToClassName(namespace_name, function_name):
"""Transform a fully qualified function name like foo.bar.baz into FooBarBaz
Also strips any leading 'Experimental' prefix."""
parts = []
full_name = namespace_name + "." + function_name
for part in full_name.split("."):
parts.append(CapitalizeFirstLetter(part))
if parts[0] == "Experimental":
del parts[0]
class_name = "".join(parts)
return class_name
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
53,
280,
6528,
367,
314,
6661,
402,
4177,
2366,
13955,
14,
199,
624,
199,
199,
318,
22516,
6910,
794,
7147,
23496,
8,
585,
304,
523,
372,
574,
59,
16,
1055,
18351,
342,
435,
574,
59,
17,
2938,
421,
199,
318,
2372,
8814,
8,
1121,
304,
523,
372,
11740,
8814,
8,
1121,
2788,
16,
61,
421,
199,
318,
19828,
8814,
8,
1121,
304,
523,
372,
11740,
8814,
8,
1121,
2788,
17,
61,
421,
199,
318,
11740,
8814,
8,
1121,
304,
523,
408,
3407,
334,
3251,
12,
4642,
9,
687,
1204,
1121,
18712,
325,
14,
71,
14,
1145,
14,
3806,
14,
2640,
4301,
1035,
523,
334,
571,
14,
3806,
12,
4693,
4301,
680,
982,
1204,
1121,
92,
5712,
1133,
12313,
2066,
2529,
334,
403,
12,
2984,
680,
523,
408,
523,
340,
7815,
315,
2984,
26,
272,
372,
2008,
8,
1121,
14,
13490,
14078,
413,
430,
523,
372,
334,
403,
12,
2984,
9,
421,
199,
318,
26231,
3481,
985,
1378,
23200,
8,
3251,
63,
354,
12,
805,
63,
354,
304,
523,
408,
6939,
282,
9999,
12313,
805,
536,
2839,
3925,
14,
1700,
14,
6185,
1901,
8024,
5281,
19726,
819,
6121,
32384,
1263,
9186,
283,
20781,
279,
7,
2403,
1041,
523,
4184,
275,
942,
523,
2615,
63,
354,
275,
3231,
63,
354,
435,
14530,
435,
805,
63,
354,
523,
367,
1777,
315,
2615,
63,
354,
14,
1294,
480,
30946,
272,
4184,
14,
740,
8,
9155,
6910,
794,
7147,
23496,
8,
2064,
430,
523,
340,
4184,
59,
16,
61,
508,
298,
20781,
279,
582,
272,
2150,
4184,
59,
16,
61,
523,
1021,
63,
354,
275,
10587,
904,
8,
4181,
9,
523,
372,
1021,
63,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
53,
280,
6528,
367,
314,
6661,
402,
4177,
2366,
13955,
14,
199,
624,
199,
199,
318,
22516,
6910,
794,
7147,
23496,
8,
585,
304,
523,
372,
574,
59,
16,
1055,
18351,
342,
435,
574,
59,
17,
2938,
421,
199,
318,
2372,
8814,
8,
1121,
304,
523,
372,
11740,
8814,
8,
1121,
2788,
16,
61,
421,
199,
318,
19828,
8814,
8,
1121,
304,
523,
372,
11740,
8814,
8,
1121,
2788,
17,
61,
421,
199,
318,
11740,
8814,
8,
1121,
304,
523,
408,
3407,
334,
3251,
12,
4642,
9,
687,
1204,
1121,
18712,
325,
14,
71,
14,
1145,
14,
3806,
14,
2640,
4301,
1035,
523,
334,
571,
14,
3806,
12,
4693,
4301,
680,
982,
1204,
1121,
92,
5712,
1133,
12313,
2066,
2529,
334,
403,
12,
2984,
680,
523,
408,
523,
340,
7815,
315,
2984,
26,
272,
372,
2008,
8,
1121,
14,
13490,
14078,
413,
430,
523,
372,
334,
403,
12,
2984,
9,
421,
199,
318,
26231,
3481,
985,
1378,
23200,
8,
3251,
63,
354,
12,
805,
63,
354,
304,
523,
408,
6939,
282,
9999,
12313,
805,
536,
2839,
3925,
14,
1700,
14,
6185,
1901,
8024,
5281,
19726,
819,
6121,
32384,
1263,
9186,
283,
20781,
279,
7,
2403,
1041,
523,
4184,
275,
942,
523,
2615,
63,
354,
275,
3231,
63,
354,
435,
14530,
435,
805,
63,
354,
523,
367,
1777,
315,
2615,
63,
354,
14,
1294,
480,
30946,
272,
4184,
14,
740,
8,
9155,
6910,
794,
7147,
23496,
8,
2064,
430,
523,
340,
4184,
59,
16,
61,
508,
298,
20781,
279,
582,
272,
2150,
4184,
59,
16,
61,
523,
1021,
63,
354,
275,
10587,
904,
8,
4181,
9,
523,
372,
1021,
63,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jcrist/blaze
|
blaze/compute/tests/test_bcolz_compute.py
|
9
|
5874
|
from __future__ import absolute_import, division, print_function
import pytest
bcolz = pytest.importorskip('bcolz')
from datashape import discover, dshape
import numpy as np
import pandas.util.testing as tm
from odo import into
from blaze import by
from blaze.expr import symbol
from blaze.compute.core import compute, pre_compute
from blaze.compute.bcolz import get_chunksize
b = bcolz.ctable(np.array([(1, 1., np.datetime64('2010-01-01')),
(2, 2., np.datetime64('NaT')),
(3, 3., np.datetime64('2010-01-03'))],
dtype=[('a', 'i8'),
('b', 'f8'),
('date', 'datetime64[D]')]))
t = symbol('t', 'var * {a: int64, b: float64, date: ?date}')
to = symbol('to', 'var * {a: int64, b: float64}')
bo = bcolz.ctable(np.array([(1, 1.), (2, 2.), (3, np.nan)],
dtype=[('a', 'i8'), ('b', 'f8')]))
def test_discover():
assert discover(b) == dshape('3 * {a: int64, b: float64, date: date}')
assert discover(b['a']) == dshape('3 * int64')
def test_reductions():
assert compute(t.a.sum(), b) == 6
assert compute(t.a.min(), b) == 1
assert compute(t.a.max(), b) == 3
assert compute(t.a.mean(), b) == 2.0
assert abs(compute(t.a.std(), b) - np.std([1, 2, 3])) < 1e-5
assert abs(compute(t.a.var(), b) - np.var([1, 2, 3])) < 1e-5
assert abs(compute(t.a.std(unbiased=True), b) - np.std([1, 2, 3],
ddof=1)) < 1e-5
assert abs(compute(t.a.var(unbiased=True), b) - np.var([1, 2, 3],
ddof=1)) < 1e-5
assert len(list(compute(t.distinct(), b))) == 3
assert len(list(compute(t.a.distinct(), b))) == 3
assert compute(t.a.nunique(), b) == 3
assert isinstance(compute(t.a.nunique(), b), np.integer)
assert compute(t.a.count(), b) == 3
assert isinstance(compute(t.date.count(), b), np.integer)
assert compute(t.date.nunique(), b) == 2
assert isinstance(compute(t.date.nunique(), b), np.integer)
assert compute(t.date.count(), b) == 2
assert isinstance(compute(t.a.count(), b), np.integer)
assert compute(t.a[0], b) == 1
assert compute(t.a[-1], b) == 3
assert compute(t[0], b) == compute(t[0], b)
assert compute(t[-1], b) == compute(t[-1], b)
def test_nunique():
assert compute(t.a.nunique(), b) == 3
assert compute(t.nunique(), b) == 3
def test_selection_head():
ds = dshape('var * {a: int32, b: int32, c: float64}')
b = into(bcolz.ctable,
[(i, i + 1, float(i) ** 2) for i in range(10)],
dshape=ds)
t = symbol('t', ds)
# numpy reductions return numpy scalars
assert compute((t.a < t.b).all(), b).item() is True
assert list(compute(t[t.a < t.b].a.head(10), b)) == list(range(10))
assert list(compute(t[t.a > t.b].a.head(10), b)) == []
assert into([], compute(t[t.a + t.b > t.c], b)) == [(0, 1, 0),
(1, 2, 1),
(2, 3, 4)]
assert len(compute(t[t.a + t.b > t.c].head(10), b)) # non-empty
assert len(compute(t[t.a + t.b < t.c].head(10), b)) # non-empty
def test_selection_isnan():
b = bcolz.ctable([[1, np.nan, 3], [1., 2., np.nan]], names=['a', 'b'])
t = symbol('t', discover(b))
lhs = compute(t[t.a.isnan()], b)
rhs = np.array([(np.nan, 2.0)], dtype=b.dtype)
for n in b.dtype.names:
assert np.isclose(lhs[n], rhs[n], equal_nan=True).all()
assert np.isclose(compute(t[~t.b.isnan()], b)[n],
np.array(
[(1, 1.0), (np.nan, 2.0)], dtype=b.dtype)[n],
equal_nan=True).all()
def test_count_isnan():
assert compute(to.a[~to.b.isnan()].count(), bo) == 2
def test_count_isnan_object():
assert compute(to.a[~to.b.isnan()].count(), bo) == 2
def test_count_isnan_struct():
assert compute(t[~t.b.isnan()].count(), b) == 3
def test_nrows():
assert compute(t.nrows, b) == len(b)
def test_nelements():
assert compute(t.nelements(axis=0), b) == len(b)
assert compute(t.nelements(), b) == len(b)
# This is no longer desired. Handled by compute_up
def dont_test_pre_compute():
b = bcolz.ctable(np.array([(1, 1., 10.), (2, 2., 20.), (3, 3., 30.)],
dtype=[('a', 'i8'), ('b', 'f8'), ('c', 'f8')]))
s = symbol('s', discover(b))
result = pre_compute(s[['a', 'b']], b)
assert result.names == ['a', 'b']
def eq(a, b):
return np.array_equal(a, b)
def test_unicode_field_names():
b = bcolz.ctable(np.array([(1, 1., 10.), (2, 2., 20.), (3, 3., 30.)],
dtype=[('a', 'i8'), ('b', 'f8'), ('c', 'f8')]))
s = symbol('s', discover(b))
assert eq(compute(s[u'a'], b)[:], compute(s['a'], b)[:])
assert eq(compute(s[[u'a', u'c']], b)[:], compute(s[['a', 'c']], b)[:])
assert eq(compute(s[u'a'], b)[:],
compute(s['a'], b)[:])
assert eq(compute(s[[u'a', u'c']], b)[:],
compute(s[['a', 'c']], b)[:])
def test_chunksize_inference():
b = bcolz.ctable(np.array([(1, 1., 10.), (2, 2., 20.), (3, 3., 30.)],
dtype=[('a', 'i8'), ('b', 'f8'), ('c', 'f8')]),
chunklen=2)
assert get_chunksize(b) == 2
def test_notnull():
with pytest.raises(AttributeError):
t.b.notnull
def test_by_with_single_row():
ct = bcolz.ctable([[1, 1, 3, 3], [1, 2, 3, 4]], names=list('ab'))
t = symbol('t', discover(ct))
subset = t[t.a == 3]
expr = by(subset.a, b_sum=subset.b.sum())
result = compute(expr, ct)
expected = compute(expr, ct, optimize=False)
tm.assert_frame_equal(result, expected)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
4613,
199,
66,
761,
90,
275,
4613,
14,
646,
269,
2759,
360,
66,
761,
90,
358,
199,
199,
504,
6394,
1119,
924,
492,
20131,
12,
366,
1392,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
10634,
14,
1974,
14,
4776,
465,
7352,
199,
199,
504,
312,
1117,
492,
1901,
199,
504,
330,
416,
806,
492,
701,
199,
504,
330,
416,
806,
14,
3684,
492,
5272,
199,
504,
330,
416,
806,
14,
3357,
14,
1018,
492,
4526,
12,
876,
63,
3357,
199,
504,
330,
416,
806,
14,
3357,
14,
66,
761,
90,
492,
664,
63,
30617,
421,
199,
66,
275,
330,
761,
90,
14,
319,
461,
8,
1590,
14,
1144,
7694,
17,
12,
413,
2020,
980,
14,
2083,
772,
360,
6542,
13,
614,
13,
614,
3855,
2574,
334,
18,
12,
499,
2020,
980,
14,
2083,
772,
360,
25638,
3855,
2574,
334,
19,
12,
650,
2020,
980,
14,
2083,
772,
360,
6542,
13,
614,
13,
1644,
1333,
467,
2079,
2152,
11699,
65,
297,
283,
73,
24,
659,
639,
661,
66,
297,
283,
70,
24,
659,
639,
661,
602,
297,
283,
2083,
772,
59,
36,
10374,
2459,
199,
199,
84,
275,
5272,
360,
84,
297,
283,
1391,
627,
469,
65,
26,
1109,
772,
12,
330,
26,
2069,
772,
12,
1434,
26,
5805,
602,
12216,
199,
199,
475,
275,
5272,
360,
475,
297,
283,
1391,
627,
469,
65,
26,
1109,
772,
12,
330,
26,
2069,
772,
12216,
199,
656,
275,
330,
761,
90,
14,
319,
461,
8,
1590,
14,
1144,
7694,
17,
12,
413,
15631,
334,
18,
12,
499,
15631,
334,
19,
12,
980,
14,
4304,
4360,
2574,
2152,
11699,
65,
297,
283,
73,
24,
659,
661,
66,
297,
283,
70,
24,
358,
2459,
421,
199,
318,
511,
63,
18861,
837,
272,
702,
20131,
8,
66,
9,
508,
366,
1392,
360,
19,
627,
469,
65,
26,
1109,
772,
12,
330,
26,
2069,
772,
12,
1434,
26,
1434,
12216,
272,
702,
20131,
8,
66,
459,
65,
1105,
508,
366,
1392,
360,
19,
627,
1109,
772,
358,
421,
199,
318,
511,
63,
19493,
2452,
837,
272,
702,
4526,
8,
84,
14,
65,
14,
1838,
1062,
330,
9,
508,
1227,
272,
702,
4526,
8,
84,
14,
65,
14,
827,
1062,
330,
9,
508,
413,
272,
702,
4526,
8,
84,
14,
65,
14,
988,
1062,
330,
9,
508,
650,
272,
702,
4526,
8,
84,
14,
65,
14,
3670,
1062,
330,
9,
508,
499,
14,
16,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1516,
1062,
330,
9,
446,
980,
14,
1516,
779,
17,
12,
499,
12,
650,
2459,
665,
413,
69,
13,
21,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1391,
1062,
330,
9,
446,
980,
14,
1391,
779,
17,
12,
499,
12,
650,
2459,
665,
413,
69,
13,
21,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1516,
8,
324,
4492,
11185,
29,
549,
395,
330,
9,
446,
980,
14,
1516,
779,
17,
12,
499,
12,
650,
467,
15491,
29180,
29,
17,
430,
665,
413,
69,
13,
21,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1391,
8,
324,
4492,
11185,
29,
549,
395,
330,
9,
446,
980,
14,
1391,
779,
17,
12,
499,
12,
650,
467,
15491,
29180,
29,
17,
430,
665,
413,
69,
13,
21,
272,
702,
822,
8,
513,
8,
3357,
8,
84,
14,
12926,
1062,
330,
1724,
508,
650,
272,
702,
822,
8,
513,
8,
3357,
8,
84,
14,
65,
14,
12926,
1062,
330,
1724,
508,
650,
339,
702,
4526,
8,
84,
14,
65,
14,
78,
3235,
1062,
330,
9,
508,
650,
272,
702,
1228,
8,
3357,
8,
84,
14,
65,
14,
78,
3235,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
65,
14,
835,
1062,
330,
9,
508,
650,
272,
702,
1228,
8,
3357,
8,
84,
14,
602,
14,
835,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
602,
14,
78,
3235,
1062,
330,
9,
508,
499,
272,
702,
1228,
8,
3357,
8,
84,
14,
602,
14,
78,
3235,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
602,
14,
835,
1062,
330,
9,
508,
499,
272,
702,
1228,
8,
3357,
8,
84,
14,
65,
14,
835,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
65,
59,
16,
467,
330,
9,
508,
413,
272,
702,
4526,
8,
84,
14,
65,
1988,
17,
467,
330,
9,
508,
650,
272,
702,
4526,
8,
84,
59,
16,
467,
330,
9,
508,
4526,
8,
84,
59,
16,
467,
330,
9,
272,
702,
4526,
8,
84,
1988,
17,
467,
330,
9,
508,
4526,
8,
84,
1988,
17,
467,
330,
9,
421,
199,
318,
511,
63,
78,
3235,
837,
272,
702,
4526,
8,
84,
14,
65,
14,
78,
3235,
1062,
330,
9,
508,
650,
272,
702,
4526,
8,
84,
14,
78,
3235,
1062,
330,
9,
508,
650,
421,
199,
318,
511,
63,
5592,
63,
2993,
837,
272,
6364,
275,
366,
1392,
360,
1391,
627,
469,
65,
26,
1109,
708,
12,
330,
26,
1109,
708,
12,
286,
26,
2069,
772,
12216,
272,
330,
275,
1901,
8,
66,
761,
90,
14,
319,
461,
12,
1467,
3842,
73,
12,
284,
435,
413,
12,
2069,
8,
73,
9,
1011,
499,
9,
367,
284,
315,
1425,
8,
709,
4360,
1467,
366,
1392,
29,
795,
9,
272,
307,
275,
5272,
360,
84,
297,
6364,
9,
339,
327,
2680,
295,
18311,
372,
2680,
19945,
272,
702,
4526,
1332,
84,
14,
65,
665,
307,
14,
66,
680,
452,
1062,
330,
680,
1053,
342,
365,
715,
272,
702,
769,
8,
3357,
8,
84,
59,
84,
14,
65,
665,
307,
14,
66,
1055,
65,
14,
2993,
8,
709,
395,
330,
430,
508,
769,
8,
1842,
8,
709,
430,
272,
702,
769,
8,
3357,
8,
84,
59,
84,
14,
65,
690,
307,
14,
66,
1055,
65,
14,
2993,
8,
709,
395,
330,
430,
508,
942,
339,
702,
1901,
8798,
4526,
8,
84,
59,
84,
14,
65,
435,
307,
14,
66,
690,
307,
14,
67,
467,
330,
430,
508,
3842,
16,
12,
413,
12,
378,
395,
9144,
334
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
4613,
199,
66,
761,
90,
275,
4613,
14,
646,
269,
2759,
360,
66,
761,
90,
358,
199,
199,
504,
6394,
1119,
924,
492,
20131,
12,
366,
1392,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
10634,
14,
1974,
14,
4776,
465,
7352,
199,
199,
504,
312,
1117,
492,
1901,
199,
504,
330,
416,
806,
492,
701,
199,
504,
330,
416,
806,
14,
3684,
492,
5272,
199,
504,
330,
416,
806,
14,
3357,
14,
1018,
492,
4526,
12,
876,
63,
3357,
199,
504,
330,
416,
806,
14,
3357,
14,
66,
761,
90,
492,
664,
63,
30617,
421,
199,
66,
275,
330,
761,
90,
14,
319,
461,
8,
1590,
14,
1144,
7694,
17,
12,
413,
2020,
980,
14,
2083,
772,
360,
6542,
13,
614,
13,
614,
3855,
2574,
334,
18,
12,
499,
2020,
980,
14,
2083,
772,
360,
25638,
3855,
2574,
334,
19,
12,
650,
2020,
980,
14,
2083,
772,
360,
6542,
13,
614,
13,
1644,
1333,
467,
2079,
2152,
11699,
65,
297,
283,
73,
24,
659,
639,
661,
66,
297,
283,
70,
24,
659,
639,
661,
602,
297,
283,
2083,
772,
59,
36,
10374,
2459,
199,
199,
84,
275,
5272,
360,
84,
297,
283,
1391,
627,
469,
65,
26,
1109,
772,
12,
330,
26,
2069,
772,
12,
1434,
26,
5805,
602,
12216,
199,
199,
475,
275,
5272,
360,
475,
297,
283,
1391,
627,
469,
65,
26,
1109,
772,
12,
330,
26,
2069,
772,
12216,
199,
656,
275,
330,
761,
90,
14,
319,
461,
8,
1590,
14,
1144,
7694,
17,
12,
413,
15631,
334,
18,
12,
499,
15631,
334,
19,
12,
980,
14,
4304,
4360,
2574,
2152,
11699,
65,
297,
283,
73,
24,
659,
661,
66,
297,
283,
70,
24,
358,
2459,
421,
199,
318,
511,
63,
18861,
837,
272,
702,
20131,
8,
66,
9,
508,
366,
1392,
360,
19,
627,
469,
65,
26,
1109,
772,
12,
330,
26,
2069,
772,
12,
1434,
26,
1434,
12216,
272,
702,
20131,
8,
66,
459,
65,
1105,
508,
366,
1392,
360,
19,
627,
1109,
772,
358,
421,
199,
318,
511,
63,
19493,
2452,
837,
272,
702,
4526,
8,
84,
14,
65,
14,
1838,
1062,
330,
9,
508,
1227,
272,
702,
4526,
8,
84,
14,
65,
14,
827,
1062,
330,
9,
508,
413,
272,
702,
4526,
8,
84,
14,
65,
14,
988,
1062,
330,
9,
508,
650,
272,
702,
4526,
8,
84,
14,
65,
14,
3670,
1062,
330,
9,
508,
499,
14,
16,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1516,
1062,
330,
9,
446,
980,
14,
1516,
779,
17,
12,
499,
12,
650,
2459,
665,
413,
69,
13,
21,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1391,
1062,
330,
9,
446,
980,
14,
1391,
779,
17,
12,
499,
12,
650,
2459,
665,
413,
69,
13,
21,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1516,
8,
324,
4492,
11185,
29,
549,
395,
330,
9,
446,
980,
14,
1516,
779,
17,
12,
499,
12,
650,
467,
15491,
29180,
29,
17,
430,
665,
413,
69,
13,
21,
272,
702,
2853,
8,
3357,
8,
84,
14,
65,
14,
1391,
8,
324,
4492,
11185,
29,
549,
395,
330,
9,
446,
980,
14,
1391,
779,
17,
12,
499,
12,
650,
467,
15491,
29180,
29,
17,
430,
665,
413,
69,
13,
21,
272,
702,
822,
8,
513,
8,
3357,
8,
84,
14,
12926,
1062,
330,
1724,
508,
650,
272,
702,
822,
8,
513,
8,
3357,
8,
84,
14,
65,
14,
12926,
1062,
330,
1724,
508,
650,
339,
702,
4526,
8,
84,
14,
65,
14,
78,
3235,
1062,
330,
9,
508,
650,
272,
702,
1228,
8,
3357,
8,
84,
14,
65,
14,
78,
3235,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
65,
14,
835,
1062,
330,
9,
508,
650,
272,
702,
1228,
8,
3357,
8,
84,
14,
602,
14,
835,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
602,
14,
78,
3235,
1062,
330,
9,
508,
499,
272,
702,
1228,
8,
3357,
8,
84,
14,
602,
14,
78,
3235,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
602,
14,
835,
1062,
330,
9,
508,
499,
272,
702,
1228,
8,
3357,
8,
84,
14,
65,
14,
835,
1062,
330,
395,
980,
14,
4115,
9,
339,
702,
4526,
8,
84,
14,
65,
59,
16,
467,
330,
9,
508,
413,
272,
702,
4526,
8,
84,
14,
65,
1988,
17,
467,
330,
9,
508,
650,
272,
702,
4526,
8,
84,
59,
16,
467,
330,
9,
508,
4526,
8,
84,
59,
16,
467,
330,
9,
272,
702,
4526,
8,
84,
1988,
17,
467,
330,
9,
508,
4526,
8,
84,
1988,
17,
467,
330,
9,
421,
199,
318,
511,
63,
78,
3235,
837,
272,
702,
4526,
8,
84,
14,
65,
14,
78,
3235,
1062,
330,
9,
508,
650,
272,
702,
4526,
8,
84,
14,
78,
3235,
1062,
330,
9,
508,
650,
421,
199,
318,
511,
63,
5592,
63,
2993,
837,
272,
6364,
275,
366,
1392,
360,
1391,
627,
469,
65,
26,
1109,
708,
12,
330,
26,
1109,
708,
12,
286,
26,
2069,
772,
12216,
272,
330,
275,
1901,
8,
66,
761,
90,
14,
319,
461,
12,
1467,
3842,
73,
12,
284,
435,
413,
12,
2069,
8,
73,
9,
1011,
499,
9,
367,
284,
315,
1425,
8,
709,
4360,
1467,
366,
1392,
29,
795,
9,
272,
307,
275,
5272,
360,
84,
297,
6364,
9,
339,
327,
2680,
295,
18311,
372,
2680,
19945,
272,
702,
4526,
1332,
84,
14,
65,
665,
307,
14,
66,
680,
452,
1062,
330,
680,
1053,
342,
365,
715,
272,
702,
769,
8,
3357,
8,
84,
59,
84,
14,
65,
665,
307,
14,
66,
1055,
65,
14,
2993,
8,
709,
395,
330,
430,
508,
769,
8,
1842,
8,
709,
430,
272,
702,
769,
8,
3357,
8,
84,
59,
84,
14,
65,
690,
307,
14,
66,
1055,
65,
14,
2993,
8,
709,
395,
330,
430,
508,
942,
339,
702,
1901,
8798,
4526,
8,
84,
59,
84,
14,
65,
435,
307,
14,
66,
690,
307,
14,
67,
467,
330,
430,
508,
3842,
16,
12,
413,
12,
378,
395,
9144,
334,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
philippegabriel/xen
|
tools/python/xen/migration/libxc.py
|
11
|
14641
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Libxc Migration v2 streams
Record structures as per docs/specs/libxc-migration-stream.pandoc, and
verification routines.
"""
import sys
from struct import calcsize, unpack
from xen.migration.verify import StreamError, RecordError, VerifyBase
# Image Header
IHDR_FORMAT = "!QIIHHI"
IHDR_MARKER = 0xffffffffffffffff
IHDR_IDENT = 0x58454E46 # "XENF" in ASCII
IHDR_VERSION = 2
IHDR_OPT_BIT_ENDIAN = 0
IHDR_OPT_LE = (0 << IHDR_OPT_BIT_ENDIAN)
IHDR_OPT_BE = (1 << IHDR_OPT_BIT_ENDIAN)
IHDR_OPT_RESZ_MASK = 0xfffe
# Domain Header
DHDR_FORMAT = "IHHII"
DHDR_TYPE_x86_pv = 0x00000001
DHDR_TYPE_x86_hvm = 0x00000002
DHDR_TYPE_x86_pvh = 0x00000003
DHDR_TYPE_arm = 0x00000004
dhdr_type_to_str = {
DHDR_TYPE_x86_pv : "x86 PV",
DHDR_TYPE_x86_hvm : "x86 HVM",
DHDR_TYPE_x86_pvh : "x86 PVH",
DHDR_TYPE_arm : "ARM",
}
# Records
RH_FORMAT = "II"
REC_TYPE_end = 0x00000000
REC_TYPE_page_data = 0x00000001
REC_TYPE_x86_pv_info = 0x00000002
REC_TYPE_x86_pv_p2m_frames = 0x00000003
REC_TYPE_x86_pv_vcpu_basic = 0x00000004
REC_TYPE_x86_pv_vcpu_extended = 0x00000005
REC_TYPE_x86_pv_vcpu_xsave = 0x00000006
REC_TYPE_shared_info = 0x00000007
REC_TYPE_tsc_info = 0x00000008
REC_TYPE_hvm_context = 0x00000009
REC_TYPE_hvm_params = 0x0000000a
REC_TYPE_toolstack = 0x0000000b
REC_TYPE_x86_pv_vcpu_msrs = 0x0000000c
REC_TYPE_verify = 0x0000000d
REC_TYPE_checkpoint = 0x0000000e
rec_type_to_str = {
REC_TYPE_end : "End",
REC_TYPE_page_data : "Page data",
REC_TYPE_x86_pv_info : "x86 PV info",
REC_TYPE_x86_pv_p2m_frames : "x86 PV P2M frames",
REC_TYPE_x86_pv_vcpu_basic : "x86 PV vcpu basic",
REC_TYPE_x86_pv_vcpu_extended : "x86 PV vcpu extended",
REC_TYPE_x86_pv_vcpu_xsave : "x86 PV vcpu xsave",
REC_TYPE_shared_info : "Shared info",
REC_TYPE_tsc_info : "TSC info",
REC_TYPE_hvm_context : "HVM context",
REC_TYPE_hvm_params : "HVM params",
REC_TYPE_toolstack : "Toolstack",
REC_TYPE_x86_pv_vcpu_msrs : "x86 PV vcpu msrs",
REC_TYPE_verify : "Verify",
REC_TYPE_checkpoint : "Checkpoint",
}
# page_data
PAGE_DATA_FORMAT = "II"
PAGE_DATA_PFN_MASK = (1L << 52) - 1
PAGE_DATA_PFN_RESZ_MASK = ((1L << 60) - 1) & ~((1L << 52) - 1)
# flags from xen/public/domctl.h: XEN_DOMCTL_PFINFO_* shifted by 32 bits
PAGE_DATA_TYPE_SHIFT = 60
PAGE_DATA_TYPE_LTABTYPE_MASK = (0x7L << PAGE_DATA_TYPE_SHIFT)
PAGE_DATA_TYPE_LTAB_MASK = (0xfL << PAGE_DATA_TYPE_SHIFT)
PAGE_DATA_TYPE_LPINTAB = (0x8L << PAGE_DATA_TYPE_SHIFT) # Pinned pagetable
PAGE_DATA_TYPE_NOTAB = (0x0L << PAGE_DATA_TYPE_SHIFT) # Regular page
PAGE_DATA_TYPE_L1TAB = (0x1L << PAGE_DATA_TYPE_SHIFT) # L1 pagetable
PAGE_DATA_TYPE_L2TAB = (0x2L << PAGE_DATA_TYPE_SHIFT) # L2 pagetable
PAGE_DATA_TYPE_L3TAB = (0x3L << PAGE_DATA_TYPE_SHIFT) # L3 pagetable
PAGE_DATA_TYPE_L4TAB = (0x4L << PAGE_DATA_TYPE_SHIFT) # L4 pagetable
PAGE_DATA_TYPE_BROKEN = (0xdL << PAGE_DATA_TYPE_SHIFT) # Broken
PAGE_DATA_TYPE_XALLOC = (0xeL << PAGE_DATA_TYPE_SHIFT) # Allocate-only
PAGE_DATA_TYPE_XTAB = (0xfL << PAGE_DATA_TYPE_SHIFT) # Invalid
# x86_pv_info
X86_PV_INFO_FORMAT = "BBHI"
X86_PV_P2M_FRAMES_FORMAT = "II"
# x86_pv_vcpu_{basic,extended,xsave,msrs}
X86_PV_VCPU_HDR_FORMAT = "II"
# tsc_info
TSC_INFO_FORMAT = "IIQII"
# hvm_params
HVM_PARAMS_ENTRY_FORMAT = "QQ"
HVM_PARAMS_FORMAT = "II"
class VerifyLibxc(VerifyBase):
""" Verify a Libxc v2 stream """
def __init__(self, info, read):
VerifyBase.__init__(self, info, read)
self.squashed_pagedata_records = 0
def verify(self):
""" Verity a libxc stream """
self.verify_ihdr()
self.verify_dhdr()
while self.verify_record() != REC_TYPE_end:
pass
def verify_ihdr(self):
""" Verify an Image Header """
marker, ident, version, options, res1, res2 = \
self.unpack_exact(IHDR_FORMAT)
if marker != IHDR_MARKER:
raise StreamError("Bad image marker: Expected 0x%x, got 0x%x"
% (IHDR_MARKER, marker))
if ident != IHDR_IDENT:
raise StreamError("Bad image id: Expected 0x%x, got 0x%x"
% (IHDR_IDENT, ident))
if version != IHDR_VERSION:
raise StreamError("Unknown image version: Expected %d, got %d"
% (IHDR_VERSION, version))
if options & IHDR_OPT_RESZ_MASK:
raise StreamError("Reserved bits set in image options field: 0x%x"
% (options & IHDR_OPT_RESZ_MASK))
if res1 != 0 or res2 != 0:
raise StreamError("Reserved bits set in image header: 0x%04x:0x%08x"
% (res1, res2))
if ( (sys.byteorder == "little") and
((options & IHDR_OPT_BIT_ENDIAN) != IHDR_OPT_LE) ):
raise StreamError(
"Stream is not native endianess - unable to validate")
endian = ["little", "big"][options & IHDR_OPT_LE]
self.info("Libxc Image Header: %s endian" % (endian, ))
def verify_dhdr(self):
""" Verify a domain header """
gtype, page_shift, res1, major, minor = \
self.unpack_exact(DHDR_FORMAT)
if gtype not in dhdr_type_to_str:
raise StreamError("Unrecognised domain type 0x%x" % (gtype, ))
if res1 != 0:
raise StreamError("Reserved bits set in domain header 0x%04x"
% (res1, ))
if page_shift != 12:
raise StreamError("Page shift expected to be 12. Got %d"
% (page_shift, ))
if major == 0:
self.info("Domain Header: legacy converted %s"
% (dhdr_type_to_str[gtype], ))
else:
self.info("Domain Header: %s from Xen %d.%d"
% (dhdr_type_to_str[gtype], major, minor))
def verify_record(self):
""" Verify an individual record """
rtype, length = self.unpack_exact(RH_FORMAT)
if rtype not in rec_type_to_str:
raise StreamError("Unrecognised record type 0x%x" % (rtype, ))
contentsz = (length + 7) & ~7
content = self.rdexact(contentsz)
if rtype != REC_TYPE_page_data:
if self.squashed_pagedata_records > 0:
self.info("Squashed %d Page Data records together"
% (self.squashed_pagedata_records, ))
self.squashed_pagedata_records = 0
self.info("Libxc Record: %s, length %d"
% (rec_type_to_str[rtype], length))
else:
self.squashed_pagedata_records += 1
padding = content[length:]
if padding != "\x00" * len(padding):
raise StreamError("Padding containing non0 bytes found")
if rtype not in record_verifiers:
raise RuntimeError("No verification function for libxc record '%s'"
% rec_type_to_str[rtype])
else:
record_verifiers[rtype](self, content[:length])
return rtype
def verify_record_end(self, content):
""" End record """
if len(content) != 0:
raise RecordError("End record with non-zero length")
def verify_record_page_data(self, content):
""" Page Data record """
minsz = calcsize(PAGE_DATA_FORMAT)
if len(content) <= minsz:
raise RecordError("PAGE_DATA record must be at least %d bytes long"
% (minsz, ))
count, res1 = unpack(PAGE_DATA_FORMAT, content[:minsz])
if res1 != 0:
raise StreamError("Reserved bits set in PAGE_DATA record 0x%04x"
% (res1, ))
pfnsz = count * 8
if (len(content) - minsz) < pfnsz:
raise RecordError("PAGE_DATA record must contain a pfn record for "
"each count")
pfns = list(unpack("=%dQ" % (count,), content[minsz:minsz + pfnsz]))
nr_pages = 0
for idx, pfn in enumerate(pfns):
if pfn & PAGE_DATA_PFN_RESZ_MASK:
raise RecordError("Reserved bits set in pfn[%d]: 0x%016x",
idx, pfn & PAGE_DATA_PFN_RESZ_MASK)
if pfn >> PAGE_DATA_TYPE_SHIFT in (5, 6, 7, 8):
raise RecordError("Invalid type value in pfn[%d]: 0x%016x",
idx, pfn & PAGE_DATA_TYPE_LTAB_MASK)
# We expect page data for each normal page or pagetable
if PAGE_DATA_TYPE_NOTAB <= (pfn & PAGE_DATA_TYPE_LTABTYPE_MASK) \
<= PAGE_DATA_TYPE_L4TAB:
nr_pages += 1
pagesz = nr_pages * 4096
if len(content) != minsz + pfnsz + pagesz:
raise RecordError("Expected %u + %u + %u, got %u"
% (minsz, pfnsz, pagesz, len(content)))
def verify_record_x86_pv_info(self, content):
""" x86 PV Info record """
expectedsz = calcsize(X86_PV_INFO_FORMAT)
if len(content) != expectedsz:
raise RecordError("x86_pv_info: expected length of %d, got %d"
% (expectedsz, len(content)))
width, levels, res1, res2 = unpack(X86_PV_INFO_FORMAT, content)
if width not in (4, 8):
raise RecordError("Expected width of 4 or 8, got %d" % (width, ))
if levels not in (3, 4):
raise RecordError("Expected levels of 3 or 4, got %d" % (levels, ))
if res1 != 0 or res2 != 0:
raise StreamError("Reserved bits set in X86_PV_INFO: 0x%04x 0x%08x"
% (res1, res2))
bitness = {4:32, 8:64}[width]
self.info(" %sbit guest, %d levels of pagetables" % (bitness, levels))
def verify_record_x86_pv_p2m_frames(self, content):
""" x86 PV p2m frames record """
if len(content) % 8 != 0:
raise RecordError("Length expected to be a multiple of 8, not %d"
% (len(content), ))
start, end = unpack("=II", content[:8])
self.info(" Start pfn 0x%x, End 0x%x" % (start, end))
def verify_record_x86_pv_vcpu_generic(self, content, name):
""" Generic for all REC_TYPE_x86_pv_vcpu_{basic,extended,xsave,msrs} """
minsz = calcsize(X86_PV_VCPU_HDR_FORMAT)
if len(content) <= minsz:
raise RecordError("X86_PV_VCPU_%s record length must be at least %d"
" bytes long" % (name, minsz))
vcpuid, res1 = unpack(X86_PV_VCPU_HDR_FORMAT, content[:minsz])
if res1 != 0:
raise StreamError(
"Reserved bits set in x86_pv_vcpu_%s record 0x%04x"
% (name, res1))
self.info(" vcpu%d %s context, %d bytes"
% (vcpuid, name, len(content) - minsz))
def verify_record_shared_info(self, content):
""" shared info record """
if len(content) != 4096:
raise RecordError("Length expected to be 4906 bytes, not %d"
% (len(content), ))
def verify_record_tsc_info(self, content):
""" tsc info record """
sz = calcsize(TSC_INFO_FORMAT)
if len(content) != sz:
raise RecordError("Length should be %u bytes" % (sz, ))
mode, khz, nsec, incarn, res1 = unpack(TSC_INFO_FORMAT, content)
if res1 != 0:
raise StreamError("Reserved bits set in TSC_INFO: 0x%08x"
% (res1, ))
self.info(" Mode %u, %u kHz, %u ns, incarnation %d"
% (mode, khz, nsec, incarn))
def verify_record_hvm_context(self, content):
""" hvm context record """
if len(content) == 0:
raise RecordError("Zero length HVM context")
def verify_record_hvm_params(self, content):
""" hvm params record """
sz = calcsize(HVM_PARAMS_FORMAT)
if len(content) < sz:
raise RecordError("Length should be at least %u bytes" % (sz, ))
count, rsvd = unpack(HVM_PARAMS_FORMAT, content[:sz])
if rsvd != 0:
raise RecordError("Reserved field not zero (0x%04x)" % (rsvd, ))
sz += count * calcsize(HVM_PARAMS_ENTRY_FORMAT)
if len(content) != sz:
raise RecordError("Length should be %u bytes" % (sz, ))
def verify_record_toolstack(self, _):
""" toolstack record """
raise DeprecationWarning("Found Toolstack record in stream")
def verify_record_verify(self, content):
""" verify record """
if len(content) != 0:
raise RecordError("Verify record with non-zero length")
def verify_record_checkpoint(self, content):
""" checkpoint record """
if len(content) != 0:
raise RecordError("Checkpoint record with non-zero length")
record_verifiers = {
REC_TYPE_end:
VerifyLibxc.verify_record_end,
REC_TYPE_page_data:
VerifyLibxc.verify_record_page_data,
REC_TYPE_x86_pv_info:
VerifyLibxc.verify_record_x86_pv_info,
REC_TYPE_x86_pv_p2m_frames:
VerifyLibxc.verify_record_x86_pv_p2m_frames,
REC_TYPE_x86_pv_vcpu_basic:
lambda s, x:
VerifyLibxc.verify_record_x86_pv_vcpu_generic(s, x, "basic"),
REC_TYPE_x86_pv_vcpu_extended:
lambda s, x:
VerifyLibxc.verify_record_x86_pv_vcpu_generic(s, x, "extended"),
REC_TYPE_x86_pv_vcpu_xsave:
lambda s, x:
VerifyLibxc.verify_record_x86_pv_vcpu_generic(s, x, "xsave"),
REC_TYPE_x86_pv_vcpu_msrs:
lambda s, x:
VerifyLibxc.verify_record_x86_pv_vcpu_generic(s, x, "msrs"),
REC_TYPE_shared_info:
VerifyLibxc.verify_record_shared_info,
REC_TYPE_tsc_info:
VerifyLibxc.verify_record_tsc_info,
REC_TYPE_hvm_context:
VerifyLibxc.verify_record_hvm_context,
REC_TYPE_hvm_params:
VerifyLibxc.verify_record_hvm_params,
REC_TYPE_toolstack:
VerifyLibxc.verify_record_toolstack,
REC_TYPE_verify:
VerifyLibxc.verify_record_verify,
REC_TYPE_checkpoint:
VerifyLibxc.verify_record_checkpoint,
}
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
4728,
1812,
12090,
373,
18,
13788,
199,
199,
5433,
13955,
465,
1126,
9149,
15,
7273,
15,
773,
1812,
13,
8998,
13,
1745,
14,
80,
460,
679,
12,
436,
199,
16257,
14975,
14,
199,
624,
199,
199,
646,
984,
199,
199,
504,
2702,
492,
12831,
890,
12,
7787,
199,
199,
504,
20388,
14,
8998,
14,
4712,
492,
8271,
547,
12,
12651,
547,
12,
7635,
1563,
199,
199,
3,
6047,
10240,
199,
19824,
4564,
63,
4807,
275,
19724,
49,
8921,
10213,
41,
2,
199,
199,
19824,
4564,
63,
18997,
221,
275,
378,
3581,
15798,
12596,
199,
19824,
4564,
63,
7466,
257,
275,
378,
88,
12248,
1477,
37,
2466,
327,
298,
56,
742,
38,
2,
315,
10485,
199,
19824,
4564,
63,
4612,
275,
499,
199,
199,
19824,
4564,
63,
5123,
63,
11970,
63,
21046,
275,
378,
199,
19824,
4564,
63,
5123,
63,
906,
275,
334,
16,
5213,
473,
40,
4564,
63,
5123,
63,
11970,
63,
21046,
9,
199,
19824,
4564,
63,
5123,
63,
6773,
275,
334,
17,
5213,
473,
40,
4564,
63,
5123,
63,
11970,
63,
21046,
9,
199,
199,
19824,
4564,
63,
5123,
63,
3830,
58,
63,
12880,
275,
378,
3581,
771,
199,
199,
3,
14061,
10240,
199,
13860,
4564,
63,
4807,
275,
298,
41,
10213,
8921,
2,
199,
199,
13860,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
221,
275,
378,
88,
23848,
199,
13860,
4564,
63,
2711,
63,
88,
1184,
63,
72,
2611,
275,
378,
88,
32764,
199,
13860,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
72,
275,
378,
88,
9084,
19,
199,
13860,
4564,
63,
2711,
63,
5362,
258,
275,
378,
88,
3273,
966,
199,
199,
7821,
5012,
63,
466,
63,
475,
63,
495,
275,
469,
272,
23427,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
221,
520,
298,
88,
1184,
510,
54,
401,
272,
23427,
4564,
63,
2711,
63,
88,
1184,
63,
72,
2611,
520,
298,
88,
1184,
869,
6849,
401,
272,
23427,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
72,
520,
298,
88,
1184,
510,
54,
40,
401,
272,
23427,
4564,
63,
2711,
63,
5362,
258,
520,
298,
12482,
401,
199,
93,
199,
199,
3,
799,
3692,
199,
31809,
63,
4807,
275,
298,
8921,
2,
199,
199,
9481,
63,
2711,
63,
500,
8295,
275,
378,
88,
3607,
199,
9481,
63,
2711,
63,
1606,
63,
576,
3322,
275,
378,
88,
23848,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
815,
3515,
275,
378,
88,
32764,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
80,
18,
77,
63,
8444,
259,
275,
378,
88,
9084,
19,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
4316,
259,
275,
378,
88,
3273,
966,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
10525,
275,
378,
88,
9084,
21,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
88,
2117,
259,
275,
378,
88,
9084,
22,
199,
9481,
63,
2711,
63,
5555,
63,
815,
3515,
275,
378,
88,
9084,
23,
199,
9481,
63,
2711,
63,
84,
551,
63,
815,
3777,
275,
378,
88,
9084,
24,
199,
9481,
63,
2711,
63,
72,
2611,
63,
1100,
3515,
275,
378,
88,
9084,
25,
199,
9481,
63,
2711,
63,
72,
2611,
63,
1162,
3698,
275,
378,
88,
9084,
65,
199,
9481,
63,
2711,
63,
3557,
2340,
3322,
275,
378,
88,
9084,
66,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
706,
2393,
258,
275,
378,
88,
9084,
67,
199,
9481,
63,
2711,
63,
4712,
5185,
275,
378,
88,
9084,
68,
199,
9481,
63,
2711,
63,
10109,
3698,
275,
378,
88,
9084,
69,
199,
199,
2761,
63,
466,
63,
475,
63,
495,
275,
469,
272,
19461,
63,
2711,
63,
500,
8295,
520,
298,
3005,
401,
272,
19461,
63,
2711,
63,
1606,
63,
576,
3322,
520,
298,
3276,
666,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
815,
3515,
520,
298,
88,
1184,
510,
54,
2256,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
80,
18,
77,
63,
8444,
259,
520,
298,
88,
1184,
510,
54,
510,
18,
45,
11223,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
4316,
259,
520,
298,
88,
1184,
510,
54,
373,
3541,
5678,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
10525,
520,
298,
88,
1184,
510,
54,
373,
3541,
9243,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
88,
2117,
259,
520,
298,
88,
1184,
510,
54,
373,
3541,
671,
2117,
401,
272,
19461,
63,
2711,
63,
5555,
63,
815,
3515,
520,
298,
12197,
2256,
401,
272,
19461,
63,
2711,
63,
84,
551,
63,
815,
3777,
520,
298,
52,
5153,
2256,
401,
272,
19461,
63,
2711,
63,
72,
2611,
63,
1100,
3515,
520,
298,
40,
6849,
1067,
401,
272,
19461,
63,
2711,
63,
72,
2611,
63,
1162,
3698,
520,
298,
40,
6849,
1862,
401,
272,
19461,
63,
2711,
63,
3557,
2340,
3322,
520,
298,
5157,
2340,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
706,
2393,
258,
520,
298,
88,
1184,
510,
54,
373,
3541,
6605,
2393,
401,
272,
19461,
63,
2711,
63,
4712,
5185,
520,
298,
7496,
401,
272,
19461,
63,
2711,
63,
10109,
3698,
520,
298,
22005,
401,
199,
93,
199,
199,
3,
2034,
63,
576,
199,
12898,
63,
3998,
63,
4807,
3777,
275,
298,
8921,
2,
199,
12898,
63,
3998,
63,
8714,
63,
12880,
3698,
275,
334,
17,
44,
5213,
14589,
9,
446,
413,
199,
12898,
63,
3998,
63,
8714,
63,
3830,
58,
63,
12880,
420,
275,
3666,
17,
44,
5213,
5212,
9,
446,
413,
9,
1253,
6146,
1332,
17,
44,
5213,
14589,
9,
446,
413,
9,
199,
199,
3,
3285,
687,
20388,
15,
3455,
15,
4556,
8077,
14,
72,
26,
1323,
742,
63,
10462,
23745,
63,
10966,
4531,
15192,
31915,
701,
4337,
5821,
199,
12898,
63,
3998,
63,
2711,
63,
18013,
260,
275,
5212,
199,
12898,
63,
3998,
63,
2711,
63,
44,
10129,
2711,
63,
12880,
275,
334,
16,
88,
23,
44,
5213,
510,
2962,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
4728,
1812,
12090,
373,
18,
13788,
199,
199,
5433,
13955,
465,
1126,
9149,
15,
7273,
15,
773,
1812,
13,
8998,
13,
1745,
14,
80,
460,
679,
12,
436,
199,
16257,
14975,
14,
199,
624,
199,
199,
646,
984,
199,
199,
504,
2702,
492,
12831,
890,
12,
7787,
199,
199,
504,
20388,
14,
8998,
14,
4712,
492,
8271,
547,
12,
12651,
547,
12,
7635,
1563,
199,
199,
3,
6047,
10240,
199,
19824,
4564,
63,
4807,
275,
19724,
49,
8921,
10213,
41,
2,
199,
199,
19824,
4564,
63,
18997,
221,
275,
378,
3581,
15798,
12596,
199,
19824,
4564,
63,
7466,
257,
275,
378,
88,
12248,
1477,
37,
2466,
327,
298,
56,
742,
38,
2,
315,
10485,
199,
19824,
4564,
63,
4612,
275,
499,
199,
199,
19824,
4564,
63,
5123,
63,
11970,
63,
21046,
275,
378,
199,
19824,
4564,
63,
5123,
63,
906,
275,
334,
16,
5213,
473,
40,
4564,
63,
5123,
63,
11970,
63,
21046,
9,
199,
19824,
4564,
63,
5123,
63,
6773,
275,
334,
17,
5213,
473,
40,
4564,
63,
5123,
63,
11970,
63,
21046,
9,
199,
199,
19824,
4564,
63,
5123,
63,
3830,
58,
63,
12880,
275,
378,
3581,
771,
199,
199,
3,
14061,
10240,
199,
13860,
4564,
63,
4807,
275,
298,
41,
10213,
8921,
2,
199,
199,
13860,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
221,
275,
378,
88,
23848,
199,
13860,
4564,
63,
2711,
63,
88,
1184,
63,
72,
2611,
275,
378,
88,
32764,
199,
13860,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
72,
275,
378,
88,
9084,
19,
199,
13860,
4564,
63,
2711,
63,
5362,
258,
275,
378,
88,
3273,
966,
199,
199,
7821,
5012,
63,
466,
63,
475,
63,
495,
275,
469,
272,
23427,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
221,
520,
298,
88,
1184,
510,
54,
401,
272,
23427,
4564,
63,
2711,
63,
88,
1184,
63,
72,
2611,
520,
298,
88,
1184,
869,
6849,
401,
272,
23427,
4564,
63,
2711,
63,
88,
1184,
63,
1381,
72,
520,
298,
88,
1184,
510,
54,
40,
401,
272,
23427,
4564,
63,
2711,
63,
5362,
258,
520,
298,
12482,
401,
199,
93,
199,
199,
3,
799,
3692,
199,
31809,
63,
4807,
275,
298,
8921,
2,
199,
199,
9481,
63,
2711,
63,
500,
8295,
275,
378,
88,
3607,
199,
9481,
63,
2711,
63,
1606,
63,
576,
3322,
275,
378,
88,
23848,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
815,
3515,
275,
378,
88,
32764,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
80,
18,
77,
63,
8444,
259,
275,
378,
88,
9084,
19,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
4316,
259,
275,
378,
88,
3273,
966,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
10525,
275,
378,
88,
9084,
21,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
88,
2117,
259,
275,
378,
88,
9084,
22,
199,
9481,
63,
2711,
63,
5555,
63,
815,
3515,
275,
378,
88,
9084,
23,
199,
9481,
63,
2711,
63,
84,
551,
63,
815,
3777,
275,
378,
88,
9084,
24,
199,
9481,
63,
2711,
63,
72,
2611,
63,
1100,
3515,
275,
378,
88,
9084,
25,
199,
9481,
63,
2711,
63,
72,
2611,
63,
1162,
3698,
275,
378,
88,
9084,
65,
199,
9481,
63,
2711,
63,
3557,
2340,
3322,
275,
378,
88,
9084,
66,
199,
9481,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
706,
2393,
258,
275,
378,
88,
9084,
67,
199,
9481,
63,
2711,
63,
4712,
5185,
275,
378,
88,
9084,
68,
199,
9481,
63,
2711,
63,
10109,
3698,
275,
378,
88,
9084,
69,
199,
199,
2761,
63,
466,
63,
475,
63,
495,
275,
469,
272,
19461,
63,
2711,
63,
500,
8295,
520,
298,
3005,
401,
272,
19461,
63,
2711,
63,
1606,
63,
576,
3322,
520,
298,
3276,
666,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
815,
3515,
520,
298,
88,
1184,
510,
54,
2256,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
80,
18,
77,
63,
8444,
259,
520,
298,
88,
1184,
510,
54,
510,
18,
45,
11223,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
4316,
259,
520,
298,
88,
1184,
510,
54,
373,
3541,
5678,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
10525,
520,
298,
88,
1184,
510,
54,
373,
3541,
9243,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
88,
2117,
259,
520,
298,
88,
1184,
510,
54,
373,
3541,
671,
2117,
401,
272,
19461,
63,
2711,
63,
5555,
63,
815,
3515,
520,
298,
12197,
2256,
401,
272,
19461,
63,
2711,
63,
84,
551,
63,
815,
3777,
520,
298,
52,
5153,
2256,
401,
272,
19461,
63,
2711,
63,
72,
2611,
63,
1100,
3515,
520,
298,
40,
6849,
1067,
401,
272,
19461,
63,
2711,
63,
72,
2611,
63,
1162,
3698,
520,
298,
40,
6849,
1862,
401,
272,
19461,
63,
2711,
63,
3557,
2340,
3322,
520,
298,
5157,
2340,
401,
272,
19461,
63,
2711,
63,
88,
1184,
63,
1381,
63,
30863,
63,
706,
2393,
258,
520,
298,
88,
1184,
510,
54,
373,
3541,
6605,
2393,
401,
272,
19461,
63,
2711,
63,
4712,
5185,
520,
298,
7496,
401,
272,
19461,
63,
2711,
63,
10109,
3698,
520,
298,
22005,
401,
199,
93,
199,
199,
3,
2034,
63,
576,
199,
12898,
63,
3998,
63,
4807,
3777,
275,
298,
8921,
2,
199,
12898,
63,
3998,
63,
8714,
63,
12880,
3698,
275,
334,
17,
44,
5213,
14589,
9,
446,
413,
199,
12898,
63,
3998,
63,
8714,
63,
3830,
58,
63,
12880,
420,
275,
3666,
17,
44,
5213,
5212,
9,
446,
413,
9,
1253,
6146,
1332,
17,
44,
5213,
14589,
9,
446,
413,
9,
199,
199,
3,
3285,
687,
20388,
15,
3455,
15,
4556,
8077,
14,
72,
26,
1323,
742,
63,
10462,
23745,
63,
10966,
4531,
15192,
31915,
701,
4337,
5821,
199,
12898,
63,
3998,
63,
2711,
63,
18013,
260,
275,
5212,
199,
12898,
63,
3998,
63,
2711,
63,
44,
10129,
2711,
63,
12880,
275,
334,
16,
88,
23,
44,
5213,
510,
2962,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
zero-ui/miniblink49
|
third_party/WebKit/Tools/Scripts/webkitpy/tool/servers/reflectionhandler.py
|
53
|
5700
|
# Copyright (c) 2011 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import BaseHTTPServer
import cgi
import codecs
import datetime
import fnmatch
import json
import mimetypes
import os.path
import shutil
import threading
import time
import urlparse
import wsgiref.handlers
import BaseHTTPServer
class ReflectionHandler(BaseHTTPServer.BaseHTTPRequestHandler):
STATIC_FILE_EXTENSIONS = ['.js', '.css', '.html']
# Subclasses should override.
STATIC_FILE_DIRECTORY = None
# Setting this flag to True causes the server to send
# Access-Control-Allow-Origin: *
# with every response.
allow_cross_origin_requests = False
def do_GET(self):
self._handle_request()
def do_POST(self):
self._handle_request()
def do_HEAD(self):
self._handle_request()
def read_entity_body(self):
length = int(self.headers.getheader('content-length'))
return self.rfile.read(length)
def _read_entity_body_as_json(self):
return json.loads(self.read_entity_body())
def _handle_request(self):
if "?" in self.path:
path, query_string = self.path.split("?", 1)
self.query = cgi.parse_qs(query_string)
else:
path = self.path
self.query = {}
function_or_file_name = path[1:] or "index.html"
_, extension = os.path.splitext(function_or_file_name)
if extension in self.STATIC_FILE_EXTENSIONS:
self._serve_static_file(function_or_file_name)
return
function_name = function_or_file_name.replace(".", "_")
if not hasattr(self, function_name):
self.send_error(404, "Unknown function %s" % function_name)
return
if function_name[0] == "_":
self.send_error(401, "Not allowed to invoke private or protected methods")
return
function = getattr(self, function_name)
function()
def _serve_static_file(self, static_path):
self._serve_file(os.path.join(self.STATIC_FILE_DIRECTORY, static_path))
def quitquitquit(self):
self._serve_text("Server quit.\n")
# Shutdown has to happen on another thread from the server's thread,
# otherwise there's a deadlock
threading.Thread(target=lambda: self.server.shutdown()).start()
def _send_access_control_header(self):
if self.allow_cross_origin_requests:
self.send_header('Access-Control-Allow-Origin', '*')
def _serve_text(self, text):
self.send_response(200)
self._send_access_control_header()
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(text)
def _serve_json(self, json_object):
self.send_response(200)
self._send_access_control_header()
self.send_header('Content-type', 'application/json')
self.end_headers()
json.dump(json_object, self.wfile)
def _serve_file(self, file_path, cacheable_seconds=0, headers_only=False):
if not os.path.exists(file_path):
self.send_error(404, "File not found")
return
with codecs.open(file_path, "rb") as static_file:
self.send_response(200)
self._send_access_control_header()
self.send_header("Content-Length", os.path.getsize(file_path))
mime_type, encoding = mimetypes.guess_type(file_path)
if mime_type:
self.send_header("Content-type", mime_type)
if cacheable_seconds:
expires_time = (datetime.datetime.now() +
datetime.timedelta(0, cacheable_seconds))
expires_formatted = wsgiref.handlers.format_date_time(
time.mktime(expires_time.timetuple()))
self.send_header("Expires", expires_formatted)
self.end_headers()
if not headers_only:
shutil.copyfileobj(static_file, self.wfile)
def _serve_xml(self, xml):
self.send_response(200)
self._send_access_control_header()
self.send_header("Content-type", "text/xml")
self.end_headers()
xml = xml.encode('utf-8')
self.wfile.write(xml)
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
7760,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
3523,
14938,
199,
199,
646,
16004,
199,
646,
6010,
199,
646,
2197,
199,
646,
15951,
199,
646,
2022,
199,
646,
13290,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
5796,
199,
646,
900,
199,
646,
7097,
199,
646,
12464,
1121,
14,
5586,
199,
646,
3523,
14938,
421,
199,
533,
15397,
1486,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
272,
27815,
63,
3817,
63,
18451,
275,
18953,
3596,
297,
1987,
3919,
297,
1987,
1360,
418,
272,
327,
20196,
1077,
4278,
14,
272,
27815,
63,
3817,
63,
16436,
275,
488,
339,
327,
13510,
642,
3305,
370,
715,
14486,
314,
1654,
370,
3222,
272,
327,
257,
11003,
13,
3717,
13,
7852,
13,
12834,
26,
627,
272,
327,
543,
4036,
1177,
14,
272,
2040,
63,
7925,
63,
6493,
63,
6615,
275,
756,
339,
347,
886,
63,
2970,
8,
277,
304,
267,
291,
423,
2479,
63,
1069,
342,
339,
347,
886,
63,
4030,
8,
277,
304,
267,
291,
423,
2479,
63,
1069,
342,
339,
347,
886,
63,
5211,
8,
277,
304,
267,
291,
423,
2479,
63,
1069,
342,
339,
347,
1586,
63,
4502,
63,
2030,
8,
277,
304,
267,
2582,
275,
1109,
8,
277,
14,
2139,
14,
19958,
360,
1317,
13,
1267,
1333,
267,
372,
291,
14,
23830,
14,
739,
8,
1267,
9,
339,
347,
485,
739,
63,
4502,
63,
2030,
63,
305,
63,
1001,
8,
277,
304,
267,
372,
2022,
14,
3640,
8,
277,
14,
739,
63,
4502,
63,
2030,
1012,
339,
347,
485,
2479,
63,
1069,
8,
277,
304,
267,
340,
29325,
315,
291,
14,
515,
26,
288,
931,
12,
1827,
63,
875,
275,
291,
14,
515,
14,
1294,
480,
15583,
413,
9,
288,
291,
14,
1131,
275,
16004,
14,
1122,
63,
6177,
8,
1131,
63,
875,
9,
267,
587,
26,
288,
931,
275,
291,
14,
515,
288,
291,
14,
1131,
275,
1052,
267,
805,
63,
269,
63,
493,
63,
354,
275,
931,
59,
17,
2938,
503,
298,
1080,
14,
1360,
2,
398,
5501,
3329,
275,
747,
14,
515,
14,
7973,
8,
1593,
63,
269,
63,
493,
63,
354,
9,
267,
340,
3329,
315,
291,
14,
10449,
63,
3817,
63,
18451,
26,
288,
291,
423,
4909,
63,
1986,
63,
493,
8,
1593,
63,
269,
63,
493,
63,
354,
9,
288,
372,
398,
805,
63,
354,
275,
805,
63,
269,
63,
493,
63,
354,
14,
1814,
30381,
2668,
531,
267,
340,
440,
2688,
8,
277,
12,
805,
63,
354,
304,
288,
291,
14,
2254,
63,
705,
8,
5188,
12,
298,
5912,
805,
450,
83,
2,
450,
805,
63,
354,
9,
288,
372,
267,
340,
805,
63,
354,
59,
16,
61,
508,
2668,
582,
288,
291,
14,
2254,
63,
705,
8,
8854,
12,
298,
1763,
4370,
370,
12677,
5726,
503,
17819,
3102,
531,
288,
372,
267,
805,
275,
2519,
8,
277,
12,
805,
63,
354,
9,
267,
805,
342,
339,
347,
485,
4909,
63,
1986,
63,
493,
8,
277,
12,
2955,
63,
515,
304,
267,
291,
423,
4909,
63,
493,
8,
736,
14,
515,
14,
904,
8,
277,
14,
10449,
63,
3817,
63,
16436,
12,
2955,
63,
515,
430,
339,
347,
17242,
10589,
10589,
8,
277,
304,
267,
291,
423,
4909,
63,
505,
480,
3120,
17242,
3134,
78,
531,
267,
327,
5244,
6159,
965,
370,
5992,
641,
4573,
2462,
687,
314,
1654,
1159,
2462,
12,
267,
327,
4257,
2337,
1159,
282,
12314,
831,
267,
5796,
14,
4436,
8,
1375,
29,
2734,
26,
291,
14,
1000,
14,
8831,
8801,
928,
342,
339,
347,
485,
2254,
63,
2732,
63,
2785,
63,
1291,
8,
277,
304,
267,
340,
291,
14,
3306,
63,
7925,
63,
6493,
63,
6615,
26,
288,
291,
14,
2254,
63,
1291,
360,
3946,
13,
3717,
13,
7852,
13,
12834,
297,
6438,
358,
339,
347,
485,
4909,
63,
505,
8,
277,
12,
1318,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
267,
291,
423,
2254,
63,
2732,
63,
2785,
63,
1291,
342,
267,
291,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
505,
15,
6104,
531,
267,
291,
14,
500,
63,
2139,
342,
267,
291,
14,
18076,
14,
952,
8,
505,
9,
339,
347,
485,
4909,
63,
1001,
8,
277,
12,
2022,
63,
785,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
267,
291,
423,
2254,
63,
2732
] |
[
1898,
334,
67,
9,
7760,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
3523,
14938,
199,
199,
646,
16004,
199,
646,
6010,
199,
646,
2197,
199,
646,
15951,
199,
646,
2022,
199,
646,
13290,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
5796,
199,
646,
900,
199,
646,
7097,
199,
646,
12464,
1121,
14,
5586,
199,
646,
3523,
14938,
421,
199,
533,
15397,
1486,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
272,
27815,
63,
3817,
63,
18451,
275,
18953,
3596,
297,
1987,
3919,
297,
1987,
1360,
418,
272,
327,
20196,
1077,
4278,
14,
272,
27815,
63,
3817,
63,
16436,
275,
488,
339,
327,
13510,
642,
3305,
370,
715,
14486,
314,
1654,
370,
3222,
272,
327,
257,
11003,
13,
3717,
13,
7852,
13,
12834,
26,
627,
272,
327,
543,
4036,
1177,
14,
272,
2040,
63,
7925,
63,
6493,
63,
6615,
275,
756,
339,
347,
886,
63,
2970,
8,
277,
304,
267,
291,
423,
2479,
63,
1069,
342,
339,
347,
886,
63,
4030,
8,
277,
304,
267,
291,
423,
2479,
63,
1069,
342,
339,
347,
886,
63,
5211,
8,
277,
304,
267,
291,
423,
2479,
63,
1069,
342,
339,
347,
1586,
63,
4502,
63,
2030,
8,
277,
304,
267,
2582,
275,
1109,
8,
277,
14,
2139,
14,
19958,
360,
1317,
13,
1267,
1333,
267,
372,
291,
14,
23830,
14,
739,
8,
1267,
9,
339,
347,
485,
739,
63,
4502,
63,
2030,
63,
305,
63,
1001,
8,
277,
304,
267,
372,
2022,
14,
3640,
8,
277,
14,
739,
63,
4502,
63,
2030,
1012,
339,
347,
485,
2479,
63,
1069,
8,
277,
304,
267,
340,
29325,
315,
291,
14,
515,
26,
288,
931,
12,
1827,
63,
875,
275,
291,
14,
515,
14,
1294,
480,
15583,
413,
9,
288,
291,
14,
1131,
275,
16004,
14,
1122,
63,
6177,
8,
1131,
63,
875,
9,
267,
587,
26,
288,
931,
275,
291,
14,
515,
288,
291,
14,
1131,
275,
1052,
267,
805,
63,
269,
63,
493,
63,
354,
275,
931,
59,
17,
2938,
503,
298,
1080,
14,
1360,
2,
398,
5501,
3329,
275,
747,
14,
515,
14,
7973,
8,
1593,
63,
269,
63,
493,
63,
354,
9,
267,
340,
3329,
315,
291,
14,
10449,
63,
3817,
63,
18451,
26,
288,
291,
423,
4909,
63,
1986,
63,
493,
8,
1593,
63,
269,
63,
493,
63,
354,
9,
288,
372,
398,
805,
63,
354,
275,
805,
63,
269,
63,
493,
63,
354,
14,
1814,
30381,
2668,
531,
267,
340,
440,
2688,
8,
277,
12,
805,
63,
354,
304,
288,
291,
14,
2254,
63,
705,
8,
5188,
12,
298,
5912,
805,
450,
83,
2,
450,
805,
63,
354,
9,
288,
372,
267,
340,
805,
63,
354,
59,
16,
61,
508,
2668,
582,
288,
291,
14,
2254,
63,
705,
8,
8854,
12,
298,
1763,
4370,
370,
12677,
5726,
503,
17819,
3102,
531,
288,
372,
267,
805,
275,
2519,
8,
277,
12,
805,
63,
354,
9,
267,
805,
342,
339,
347,
485,
4909,
63,
1986,
63,
493,
8,
277,
12,
2955,
63,
515,
304,
267,
291,
423,
4909,
63,
493,
8,
736,
14,
515,
14,
904,
8,
277,
14,
10449,
63,
3817,
63,
16436,
12,
2955,
63,
515,
430,
339,
347,
17242,
10589,
10589,
8,
277,
304,
267,
291,
423,
4909,
63,
505,
480,
3120,
17242,
3134,
78,
531,
267,
327,
5244,
6159,
965,
370,
5992,
641,
4573,
2462,
687,
314,
1654,
1159,
2462,
12,
267,
327,
4257,
2337,
1159,
282,
12314,
831,
267,
5796,
14,
4436,
8,
1375,
29,
2734,
26,
291,
14,
1000,
14,
8831,
8801,
928,
342,
339,
347,
485,
2254,
63,
2732,
63,
2785,
63,
1291,
8,
277,
304,
267,
340,
291,
14,
3306,
63,
7925,
63,
6493,
63,
6615,
26,
288,
291,
14,
2254,
63,
1291,
360,
3946,
13,
3717,
13,
7852,
13,
12834,
297,
6438,
358,
339,
347,
485,
4909,
63,
505,
8,
277,
12,
1318,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
267,
291,
423,
2254,
63,
2732,
63,
2785,
63,
1291,
342,
267,
291,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
505,
15,
6104,
531,
267,
291,
14,
500,
63,
2139,
342,
267,
291,
14,
18076,
14,
952,
8,
505,
9,
339,
347,
485,
4909,
63,
1001,
8,
277,
12,
2022,
63,
785,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
267,
291,
423,
2254,
63,
2732,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tlatzko/spmcluster
|
.tox/2.6-cover/lib/python2.6/site-packages/pip/utils/deprecation.py
|
271
|
2152
|
"""
A module that implments tooling to enable easy warnings about deprecations.
"""
from __future__ import absolute_import
import logging
import warnings
class PipDeprecationWarning(Warning):
pass
class RemovedInPip8Warning(PipDeprecationWarning, PendingDeprecationWarning):
pass
class RemovedInPip9Warning(PipDeprecationWarning, PendingDeprecationWarning):
pass
DEPRECATIONS = [RemovedInPip8Warning, RemovedInPip9Warning]
# Warnings <-> Logging Integration
_warnings_showwarning = None
def _showwarning(message, category, filename, lineno, file=None, line=None):
if file is not None:
if _warnings_showwarning is not None:
_warnings_showwarning(
message, category, filename, lineno, file, line,
)
else:
if issubclass(category, PipDeprecationWarning):
# We use a specially named logger which will handle all of the
# deprecation messages for pip.
logger = logging.getLogger("pip.deprecations")
# This is purposely using the % formatter here instead of letting
# the logging module handle the interpolation. This is because we
# want it to appear as if someone typed this entire message out.
log_message = "DEPRECATION: %s" % message
# Things that are DeprecationWarnings will be removed in the very
# next version of pip. We want these to be more obvious so we
# use the ERROR logging level while the PendingDeprecationWarnings
# are still have at least 2 versions to go until they are removed
# so they can just be warnings.
if issubclass(category, DeprecationWarning):
logger.error(log_message)
else:
logger.warning(log_message)
else:
_warnings_showwarning(
message, category, filename, lineno, file, line,
)
def install_warning_logger():
global _warnings_showwarning
if _warnings_showwarning is None:
_warnings_showwarning = warnings.showwarning
warnings.showwarning = _showwarning
|
bsd-2-clause
|
[
624,
199,
33,
859,
626,
11512,
1470,
4744,
316,
370,
4756,
8837,
3598,
3595,
17831,
83,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
3598,
421,
199,
533,
510,
711,
15561,
8,
3849,
304,
272,
986,
421,
199,
533,
799,
17920,
32457,
24,
3849,
8,
32457,
15561,
12,
29216,
15561,
304,
272,
986,
421,
199,
533,
799,
17920,
32457,
25,
3849,
8,
32457,
15561,
12,
29216,
15561,
304,
272,
986,
421,
199,
1093,
14246,
12969,
275,
359,
497,
17920,
32457,
24,
3849,
12,
799,
17920,
32457,
25,
3849,
61,
421,
199,
3,
644,
2627,
665,
5118,
19928,
27561,
421,
199,
63,
5451,
63,
29109,
275,
488,
421,
199,
318,
485,
29109,
8,
1188,
12,
4637,
12,
1788,
12,
5874,
12,
570,
29,
403,
12,
1004,
29,
403,
304,
272,
340,
570,
365,
440,
488,
26,
267,
340,
485,
5451,
63,
29109,
365,
440,
488,
26,
288,
485,
5451,
63,
29109,
8,
355,
1245,
12,
4637,
12,
1788,
12,
5874,
12,
570,
12,
1004,
12,
288,
776,
272,
587,
26,
267,
340,
11602,
8,
3710,
12,
510,
711,
15561,
304,
288,
327,
2136,
675,
282,
1106,
1183,
4310,
2512,
1314,
911,
2429,
1006,
402,
314,
288,
327,
17831,
3788,
367,
7305,
14,
288,
2512,
275,
2050,
14,
5572,
480,
9983,
14,
15383,
83,
531,
953,
327,
961,
365,
12016,
590,
1808,
314,
450,
9698,
2348,
3140,
402,
4691,
1337,
288,
327,
314,
2050,
859,
2429,
314,
14046,
14,
961,
365,
2952,
781,
288,
327,
2934,
652,
370,
7468,
465,
340,
17122,
20041,
642,
8039,
1245,
734,
14,
288,
943,
63,
1188,
275,
298,
1093,
14246,
2594,
26,
450,
83,
2,
450,
1245,
953,
327,
3868,
780,
626,
787,
1487,
6444,
15921,
911,
506,
4829,
315,
314,
7437,
288,
327,
2163,
1015,
402,
7305,
14,
2136,
2934,
3520,
370,
506,
1655,
25259,
880,
781,
288,
327,
675,
314,
12539,
2050,
2166,
1830,
314,
29216,
872,
6444,
15921,
288,
327,
787,
5139,
1172,
737,
5210,
499,
5459,
370,
2621,
5133,
2985,
787,
4829,
288,
327,
880,
2985,
883,
2951,
506,
3598,
14,
288,
340,
11602,
8,
3710,
12,
13413,
304,
355,
2512,
14,
705,
8,
793,
63,
1188,
9,
288,
587,
26,
355,
2512,
14,
3764,
8,
793,
63,
1188,
9,
267,
587,
26,
288,
485,
5451,
63,
29109,
8,
355,
1245,
12,
4637,
12,
1788,
12,
5874,
12,
570,
12,
1004,
12,
288,
776,
421,
199,
318,
3907,
63,
3764,
63,
2921,
837,
272,
2288,
485,
5451,
63,
29109,
339,
340,
485,
5451,
63,
29109,
365,
488,
26,
267,
485,
5451,
63,
29109,
275,
3598,
14,
29109,
267,
3598,
14,
29109,
275,
485,
29109,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
33,
859,
626,
11512,
1470,
4744,
316,
370,
4756,
8837,
3598,
3595,
17831,
83,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
3598,
421,
199,
533,
510,
711,
15561,
8,
3849,
304,
272,
986,
421,
199,
533,
799,
17920,
32457,
24,
3849,
8,
32457,
15561,
12,
29216,
15561,
304,
272,
986,
421,
199,
533,
799,
17920,
32457,
25,
3849,
8,
32457,
15561,
12,
29216,
15561,
304,
272,
986,
421,
199,
1093,
14246,
12969,
275,
359,
497,
17920,
32457,
24,
3849,
12,
799,
17920,
32457,
25,
3849,
61,
421,
199,
3,
644,
2627,
665,
5118,
19928,
27561,
421,
199,
63,
5451,
63,
29109,
275,
488,
421,
199,
318,
485,
29109,
8,
1188,
12,
4637,
12,
1788,
12,
5874,
12,
570,
29,
403,
12,
1004,
29,
403,
304,
272,
340,
570,
365,
440,
488,
26,
267,
340,
485,
5451,
63,
29109,
365,
440,
488,
26,
288,
485,
5451,
63,
29109,
8,
355,
1245,
12,
4637,
12,
1788,
12,
5874,
12,
570,
12,
1004,
12,
288,
776,
272,
587,
26,
267,
340,
11602,
8,
3710,
12,
510,
711,
15561,
304,
288,
327,
2136,
675,
282,
1106,
1183,
4310,
2512,
1314,
911,
2429,
1006,
402,
314,
288,
327,
17831,
3788,
367,
7305,
14,
288,
2512,
275,
2050,
14,
5572,
480,
9983,
14,
15383,
83,
531,
953,
327,
961,
365,
12016,
590,
1808,
314,
450,
9698,
2348,
3140,
402,
4691,
1337,
288,
327,
314,
2050,
859,
2429,
314,
14046,
14,
961,
365,
2952,
781,
288,
327,
2934,
652,
370,
7468,
465,
340,
17122,
20041,
642,
8039,
1245,
734,
14,
288,
943,
63,
1188,
275,
298,
1093,
14246,
2594,
26,
450,
83,
2,
450,
1245,
953,
327,
3868,
780,
626,
787,
1487,
6444,
15921,
911,
506,
4829,
315,
314,
7437,
288,
327,
2163,
1015,
402,
7305,
14,
2136,
2934,
3520,
370,
506,
1655,
25259,
880,
781,
288,
327,
675,
314,
12539,
2050,
2166,
1830,
314,
29216,
872,
6444,
15921,
288,
327,
787,
5139,
1172,
737,
5210,
499,
5459,
370,
2621,
5133,
2985,
787,
4829,
288,
327,
880,
2985,
883,
2951,
506,
3598,
14,
288,
340,
11602,
8,
3710,
12,
13413,
304,
355,
2512,
14,
705,
8,
793,
63,
1188,
9,
288,
587,
26,
355,
2512,
14,
3764,
8,
793,
63,
1188,
9,
267,
587,
26,
288,
485,
5451,
63,
29109,
8,
355,
1245,
12,
4637,
12,
1788,
12,
5874,
12,
570,
12,
1004,
12,
288,
776,
421,
199,
318,
3907,
63,
3764,
63,
2921,
837,
272,
2288,
485,
5451,
63,
29109,
339,
340,
485,
5451,
63,
29109,
365,
488,
26,
267,
485,
5451,
63,
29109,
275,
3598,
14,
29109,
267,
3598,
14,
29109,
275,
485,
29109,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
safwanrahman/mozillians
|
vendor-local/lib/python/markdown/extensions/abbr.py
|
11
|
3057
|
'''
Abbreviation Extension for Python-Markdown
==========================================
This extension adds abbreviation handling to Python-Markdown.
Simple Usage:
>>> import markdown
>>> text = """
... Some text with an ABBR and a REF. Ignore REFERENCE and ref.
...
... *[ABBR]: Abbreviation
... *[REF]: Abbreviation Reference
... """
>>> print markdown.markdown(text, ['abbr'])
<p>Some text with an <abbr title="Abbreviation">ABBR</abbr> and a <abbr title="Abbreviation Reference">REF</abbr>. Ignore REFERENCE and ref.</p>
Copyright 2007-2008
* [Waylan Limberg](http://achinghead.com/)
* [Seemant Kulleen](http://www.kulleen.org/)
'''
from __future__ import absolute_import
from __future__ import unicode_literals
from . import Extension
from ..preprocessors import Preprocessor
from ..inlinepatterns import Pattern
from ..util import etree, AtomicString
import re
# Global Vars
ABBR_REF_RE = re.compile(r'[*]\[(?P<abbr>[^\]]*)\][ ]?:\s*(?P<title>.*)')
class AbbrExtension(Extension):
""" Abbreviation Extension for Python-Markdown. """
def extendMarkdown(self, md, md_globals):
""" Insert AbbrPreprocessor before ReferencePreprocessor. """
md.preprocessors.add('abbr', AbbrPreprocessor(md), '<reference')
class AbbrPreprocessor(Preprocessor):
""" Abbreviation Preprocessor - parse text for abbr references. """
def run(self, lines):
'''
Find and remove all Abbreviation references from the text.
Each reference is set as a new AbbrPattern in the markdown instance.
'''
new_text = []
for line in lines:
m = ABBR_REF_RE.match(line)
if m:
abbr = m.group('abbr').strip()
title = m.group('title').strip()
self.markdown.inlinePatterns['abbr-%s'%abbr] = \
AbbrPattern(self._generate_pattern(abbr), title)
else:
new_text.append(line)
return new_text
def _generate_pattern(self, text):
'''
Given a string, returns an regex pattern to match that string.
'HTML' -> r'(?P<abbr>[H][T][M][L])'
Note: we force each char as a literal match (in brackets) as we don't
know what they will be beforehand.
'''
chars = list(text)
for i in range(len(chars)):
chars[i] = r'[%s]' % chars[i]
return r'(?P<abbr>\b%s\b)' % (r''.join(chars))
class AbbrPattern(Pattern):
""" Abbreviation inline pattern. """
def __init__(self, pattern, title):
super(AbbrPattern, self).__init__(pattern)
self.title = title
def handleMatch(self, m):
abbr = etree.Element('abbr')
abbr.text = AtomicString(m.group('abbr'))
abbr.set('title', self.title)
return abbr
def makeExtension(configs=None):
return AbbrExtension(configs=configs)
|
bsd-3-clause
|
[
2344,
202,
199,
33,
2501,
264,
12337,
13282,
367,
2018,
13,
30916,
202,
199,
2486,
17575,
2999,
199,
2765,
3329,
9584,
2236,
30369,
7252,
370,
2018,
13,
30916,
14,
2999,
199,
3184,
11028,
26,
2958,
1306,
492,
18502,
1128,
1306,
1318,
275,
408,
1128,
2263,
6601,
1318,
543,
376,
437,
5342,
50,
436,
282,
5363,
38,
14,
14092,
26901,
6013,
436,
2984,
14,
1128,
2263,
1128,
2263,
627,
59,
1217,
7184,
2189,
437,
2501,
264,
12337,
1128,
2263,
627,
59,
8279,
2189,
437,
2501,
264,
12337,
10944,
1128,
2263,
408,
1128,
1306,
870,
18502,
14,
15653,
8,
505,
12,
788,
20787,
1105,
1128,
665,
80,
30,
7700,
1318,
543,
376,
665,
20787,
2538,
628,
33,
2501,
264,
12337,
1743,
1217,
7184,
1108,
20787,
30,
436,
282,
665,
20787,
2538,
628,
33,
2501,
264,
12337,
10944,
1743,
8279,
1108,
20787,
10827,
14092,
26901,
6013,
436,
2984,
9758,
80,
30,
2999,
199,
7384,
10219,
13,
9300,
202,
199,
10,
359,
25544,
1502,
24157,
976,
71,
8738,
1014,
921,
23302,
2993,
14,
957,
24793,
202,
199,
10,
359,
9295,
77,
867,
1804,
348,
274,
287,
8738,
1014,
921,
1544,
14,
75,
348,
274,
287,
14,
1308,
24793,
4122,
2999,
199,
2344,
2999,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
202,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
202,
199,
504,
1275,
492,
13282,
202,
199,
504,
2508,
657,
10547,
492,
5543,
6459,
202,
199,
504,
2508,
6460,
7435,
492,
27019,
202,
199,
504,
2508,
1974,
492,
7559,
12,
18840,
530,
1558,
202,
199,
646,
295,
2999,
199,
3,
13641,
812,
4291,
202,
199,
1217,
7184,
63,
8279,
63,
907,
275,
295,
14,
2014,
8,
82,
3894,
10,
7272,
59,
2229,
48,
28,
20787,
13489,
60,
2677,
10,
2862,
1527,
1622,
31,
3427,
83,
30957,
48,
28,
1213,
23742,
5942,
2999,
199,
533,
437,
2501,
82,
6382,
8,
6382,
304,
1128,
408,
437,
2501,
264,
12337,
13282,
367,
2018,
13,
30916,
14,
408,
2958,
347,
12247,
30916,
8,
277,
12,
6128,
12,
6128,
63,
8473,
304,
1039,
408,
15496,
437,
2501,
82,
16482,
2544,
10944,
16482,
14,
408,
1039,
6128,
14,
657,
10547,
14,
525,
360,
20787,
297,
437,
2501,
82,
16482,
8,
1064,
395,
2650,
4443,
358,
8740,
1675,
202,
199,
533,
437,
2501,
82,
16482,
8,
16482,
304,
1128,
408,
437,
2501,
264,
12337,
5543,
6459,
446,
2198,
1318,
367,
2236,
3289,
6941,
14,
408,
2958,
347,
1255,
8,
277,
12,
2385,
304,
1039,
1449,
1039,
6668,
436,
2813,
1006,
437,
2501,
264,
12337,
6941,
687,
314,
1318,
14,
1039,
7048,
3659,
365,
663,
465,
282,
892,
437,
2501,
82,
9959,
315,
314,
18502,
1256,
14,
13594,
1449,
1039,
892,
63,
505,
275,
942,
1039,
367,
1004,
315,
2385,
26,
1675,
333,
275,
437,
5342,
50,
63,
8279,
63,
907,
14,
1431,
8,
604,
9,
1675,
340,
333,
26,
2628,
2236,
3289,
275,
333,
14,
923,
360,
20787,
1959,
1913,
342,
2628,
2538,
275,
333,
14,
923,
360,
1213,
1959,
1913,
342,
2628,
291,
14,
15653,
14,
6460,
25662,
459,
20787,
3295,
83,
5956,
20787,
61,
275,
971,
4906,
437,
2501,
82,
9959,
8,
277,
423,
4208,
63,
3401,
8,
20787,
395,
2538,
9,
1675,
587,
26,
2628,
892,
63,
505,
14,
740,
8,
604,
9,
1039,
372,
892,
63,
505,
11787,
347,
485,
4208,
63,
3401,
8,
277,
12,
1318,
304,
1039,
1449,
1039,
9138,
282,
1059,
12,
2529,
376,
5163,
3851,
370,
1336,
626,
1059,
14,
221,
13594,
283,
4943,
7,
1035,
519,
10120,
48,
28,
20787,
9514,
40,
1527,
52,
1527,
45,
1527,
44,
566,
7,
221,
13594,
3390,
26,
781,
3542,
1924,
1495,
465,
282,
8785,
1336,
334,
262,
21873,
9,
465,
781,
2793,
1133,
30199,
5715,
4052,
2985,
911,
506,
2544,
6868,
14,
4341,
1449,
1039,
8365,
275,
769,
8,
505,
9,
1039,
367,
284,
315,
1425,
8,
552,
8,
6574,
2298,
1675,
8365,
59,
73,
61,
275,
519,
3894,
5,
83,
6616,
450,
8365,
59,
73,
61,
1039,
372,
519,
10120,
48,
28,
20787,
3072,
66,
5,
83,
60,
66,
3171,
450,
334,
82,
17067,
904,
8,
6574,
430,
8065,
199,
533,
437,
2501,
82,
9959,
8,
9959,
304,
1128,
408,
437,
2501,
264,
12337,
8308,
3851,
14,
408,
2958,
347,
636,
826,
721,
277,
12,
3851,
12,
2538,
304,
1039,
1613,
8,
33,
2501,
82,
9959,
12,
291,
2843,
826,
721,
3401,
9,
1039,
291,
14,
1213,
275,
2538,
2958,
347,
2429,
4486,
8,
277,
12,
333,
304,
1039,
2236,
3289,
275,
7559,
14,
2162,
360,
20787,
358,
1039,
2236,
3289,
14,
505,
275,
18840,
530,
1558,
8,
77,
14,
923,
360,
20787,
1333,
1039,
2236,
3289,
14,
409,
360,
1213,
297,
291,
14,
1213,
9,
1039,
372,
2236,
3289,
2999,
199,
318,
1852,
6382,
8,
7532,
29,
403,
304,
1128,
372,
437,
2501,
82,
6382,
8,
7532,
29,
7532,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
202,
199,
33,
2501,
264,
12337,
13282,
367,
2018,
13,
30916,
202,
199,
2486,
17575,
2999,
199,
2765,
3329,
9584,
2236,
30369,
7252,
370,
2018,
13,
30916,
14,
2999,
199,
3184,
11028,
26,
2958,
1306,
492,
18502,
1128,
1306,
1318,
275,
408,
1128,
2263,
6601,
1318,
543,
376,
437,
5342,
50,
436,
282,
5363,
38,
14,
14092,
26901,
6013,
436,
2984,
14,
1128,
2263,
1128,
2263,
627,
59,
1217,
7184,
2189,
437,
2501,
264,
12337,
1128,
2263,
627,
59,
8279,
2189,
437,
2501,
264,
12337,
10944,
1128,
2263,
408,
1128,
1306,
870,
18502,
14,
15653,
8,
505,
12,
788,
20787,
1105,
1128,
665,
80,
30,
7700,
1318,
543,
376,
665,
20787,
2538,
628,
33,
2501,
264,
12337,
1743,
1217,
7184,
1108,
20787,
30,
436,
282,
665,
20787,
2538,
628,
33,
2501,
264,
12337,
10944,
1743,
8279,
1108,
20787,
10827,
14092,
26901,
6013,
436,
2984,
9758,
80,
30,
2999,
199,
7384,
10219,
13,
9300,
202,
199,
10,
359,
25544,
1502,
24157,
976,
71,
8738,
1014,
921,
23302,
2993,
14,
957,
24793,
202,
199,
10,
359,
9295,
77,
867,
1804,
348,
274,
287,
8738,
1014,
921,
1544,
14,
75,
348,
274,
287,
14,
1308,
24793,
4122,
2999,
199,
2344,
2999,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
202,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
202,
199,
504,
1275,
492,
13282,
202,
199,
504,
2508,
657,
10547,
492,
5543,
6459,
202,
199,
504,
2508,
6460,
7435,
492,
27019,
202,
199,
504,
2508,
1974,
492,
7559,
12,
18840,
530,
1558,
202,
199,
646,
295,
2999,
199,
3,
13641,
812,
4291,
202,
199,
1217,
7184,
63,
8279,
63,
907,
275,
295,
14,
2014,
8,
82,
3894,
10,
7272,
59,
2229,
48,
28,
20787,
13489,
60,
2677,
10,
2862,
1527,
1622,
31,
3427,
83,
30957,
48,
28,
1213,
23742,
5942,
2999,
199,
533,
437,
2501,
82,
6382,
8,
6382,
304,
1128,
408,
437,
2501,
264,
12337,
13282,
367,
2018,
13,
30916,
14,
408,
2958,
347,
12247,
30916,
8,
277,
12,
6128,
12,
6128,
63,
8473,
304,
1039,
408,
15496,
437,
2501,
82,
16482,
2544,
10944,
16482,
14,
408,
1039,
6128,
14,
657,
10547,
14,
525,
360,
20787,
297,
437,
2501,
82,
16482,
8,
1064,
395,
2650,
4443,
358,
8740,
1675,
202,
199,
533,
437,
2501,
82,
16482,
8,
16482,
304,
1128,
408,
437,
2501,
264,
12337,
5543,
6459,
446,
2198,
1318,
367,
2236,
3289,
6941,
14,
408,
2958,
347,
1255,
8,
277,
12,
2385,
304,
1039,
1449,
1039,
6668,
436,
2813,
1006,
437,
2501,
264,
12337,
6941,
687,
314,
1318,
14,
1039,
7048,
3659,
365,
663,
465,
282,
892,
437,
2501,
82,
9959,
315,
314,
18502,
1256,
14,
13594,
1449,
1039,
892,
63,
505,
275,
942,
1039,
367,
1004,
315,
2385,
26,
1675,
333,
275,
437,
5342,
50,
63,
8279,
63,
907,
14,
1431,
8,
604,
9,
1675,
340,
333,
26,
2628,
2236,
3289,
275,
333,
14,
923,
360,
20787,
1959,
1913,
342,
2628,
2538,
275,
333,
14,
923,
360,
1213,
1959,
1913,
342,
2628,
291,
14,
15653,
14,
6460,
25662,
459,
20787,
3295,
83,
5956,
20787,
61,
275,
971,
4906,
437,
2501,
82,
9959,
8,
277,
423,
4208,
63,
3401,
8,
20787,
395,
2538,
9,
1675,
587,
26,
2628,
892,
63,
505,
14,
740,
8,
604,
9,
1039,
372,
892,
63,
505,
11787,
347,
485,
4208,
63,
3401,
8,
277,
12,
1318,
304,
1039,
1449,
1039,
9138,
282,
1059,
12,
2529,
376,
5163,
3851,
370,
1336,
626,
1059,
14,
221,
13594,
283,
4943,
7,
1035,
519,
10120,
48,
28,
20787,
9514,
40,
1527,
52,
1527,
45,
1527,
44,
566,
7,
221,
13594,
3390,
26,
781,
3542,
1924,
1495,
465,
282,
8785,
1336,
334,
262,
21873,
9,
465,
781,
2793,
1133,
30199,
5715,
4052,
2985,
911,
506,
2544,
6868,
14,
4341,
1449,
1039,
8365,
275,
769,
8,
505,
9,
1039,
367,
284,
315,
1425,
8,
552,
8,
6574,
2298,
1675,
8365,
59,
73,
61,
275,
519,
3894,
5,
83,
6616,
450,
8365,
59,
73,
61,
1039,
372,
519,
10120,
48,
28,
20787,
3072,
66,
5,
83,
60,
66,
3171,
450,
334,
82,
17067,
904,
8,
6574,
430,
8065,
199,
533,
437,
2501,
82,
9959,
8,
9959,
304,
1128,
408,
437,
2501,
264,
12337,
8308,
3851,
14,
408,
2958,
347,
636,
826,
721,
277,
12,
3851,
12,
2538,
304,
1039,
1613,
8,
33,
2501,
82,
9959,
12,
291,
2843,
826,
721,
3401,
9,
1039,
291,
14,
1213,
275,
2538,
2958,
347,
2429,
4486,
8,
277,
12,
333,
304,
1039,
2236,
3289,
275,
7559,
14,
2162,
360,
20787,
358,
1039,
2236,
3289,
14,
505,
275,
18840,
530,
1558,
8,
77,
14,
923,
360,
20787,
1333,
1039,
2236,
3289,
14,
409,
360,
1213,
297,
291,
14,
1213,
9,
1039,
372,
2236,
3289,
2999,
199,
318,
1852,
6382,
8,
7532,
29,
403,
304,
1128,
372,
437,
2501,
82,
6382,
8,
7532,
29,
7532,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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bin/env python
# this script outputs coverage per strain in a file that can be merged with T_kin_C_matrix_full.txt
# USE: cov_fix.py
import re
infile="/lscr2/andersenlab/kml436/git_repos2/Transposons2/results/kinship/T_kin_C_matrix_full.txt"
cov_file="/lscr2/andersenlab/kml436/git_repos2/Transposons2/results/kinship/coverage_and_te_counts.txt"
outfile="/lscr2/andersenlab/kml436/git_repos2/Transposons2/results/kinship/T_coverage.txt"
coverages={}
with open(cov_file, 'r') as IN:
for line in IN:
line = line.rstrip('\n')
items = re.split("[\t]",line)
sample,absence,insertion,reference,coverage=items[0:len(items)]
coverages[sample]=coverage
strains=list()
with open(infile, 'r') as IN:
header = next(IN)
header = header .rstrip('\n')
items = re.split("[\t]", header )
for i in items[1:len(items)]:
strains.append(i)
OUT=open(outfile, 'w')
OUT.write("trait")
for i in strains:
OUT.write("\t" + i)
OUT.write('\ncoverage')
for i in strains:
coverage=coverages[i]
OUT.write("\t" + coverage)
OUT.write("\n")
OUT.close()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
642,
2884,
4704,
11745,
1126,
410,
6322,
315,
282,
570,
626,
883,
506,
9545,
543,
377,
63,
19269,
63,
35,
63,
3642,
63,
2861,
14,
2424,
199,
3,
4815,
26,
13786,
63,
970,
14,
647,
199,
199,
646,
295,
199,
199,
13880,
9555,
478,
1556,
18,
15,
11438,
2464,
5561,
15,
21351,
26319,
15,
3187,
63,
11857,
18,
15,
3188,
555,
834,
83,
18,
15,
2604,
15,
19269,
3319,
15,
52,
63,
19269,
63,
35,
63,
3642,
63,
2861,
14,
2424,
2,
199,
8695,
63,
493,
9555,
478,
1556,
18,
15,
11438,
2464,
5561,
15,
21351,
26319,
15,
3187,
63,
11857,
18,
15,
3188,
555,
834,
83,
18,
15,
2604,
15,
19269,
3319,
15,
10828,
63,
460,
63,
266,
63,
6851,
14,
2424,
2,
199,
4984,
9555,
478,
1556,
18,
15,
11438,
2464,
5561,
15,
21351,
26319,
15,
3187,
63,
11857,
18,
15,
3188,
555,
834,
83,
18,
15,
2604,
15,
19269,
3319,
15,
52,
63,
10828,
14,
2424,
2,
421,
199,
10828,
83,
7622,
199,
1045,
1551,
8,
8695,
63,
493,
12,
283,
82,
358,
465,
1621,
26,
199,
198,
509,
1004,
315,
1621,
26,
507,
198,
604,
275,
1004,
14,
6735,
2258,
78,
358,
507,
198,
1744,
275,
295,
14,
1294,
480,
7023,
84,
11472,
604,
9,
507,
198,
3271,
12,
371,
14073,
12,
14739,
12,
4443,
12,
10828,
29,
1744,
59,
16,
26,
552,
8,
1744,
1874,
507,
198,
10828,
83,
59,
3271,
10404,
10828,
421,
199,
14183,
3617,
29,
513,
342,
199,
1045,
1551,
8,
13880,
12,
283,
82,
358,
465,
1621,
26,
199,
198,
1291,
275,
2163,
8,
568,
9,
199,
198,
1291,
275,
1406,
1275,
6735,
2258,
78,
358,
199,
198,
1744,
275,
295,
14,
1294,
480,
7023,
84,
11472,
1406,
776,
199,
198,
509,
284,
315,
2974,
59,
17,
26,
552,
8,
1744,
19532,
507,
198,
14183,
3617,
14,
740,
8,
73,
9,
421,
199,
1877,
29,
1490,
8,
4984,
12,
283,
87,
358,
199,
1877,
14,
952,
480,
22687,
531,
199,
199,
509,
284,
315,
20370,
3617,
26,
199,
198,
1877,
14,
952,
4582,
84,
2,
435,
284,
9,
199,
1877,
14,
952,
2258,
78,
10828,
358,
199,
199,
509,
284,
315,
20370,
3617,
26,
199,
198,
10828,
29,
10828,
83,
59,
73,
61,
199,
198,
1877,
14,
952,
4582,
84,
2,
435,
11745,
9,
199,
199,
1877,
14,
952,
4582,
78,
531,
199,
1877,
14,
1600,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
642,
2884,
4704,
11745,
1126,
410,
6322,
315,
282,
570,
626,
883,
506,
9545,
543,
377,
63,
19269,
63,
35,
63,
3642,
63,
2861,
14,
2424,
199,
3,
4815,
26,
13786,
63,
970,
14,
647,
199,
199,
646,
295,
199,
199,
13880,
9555,
478,
1556,
18,
15,
11438,
2464,
5561,
15,
21351,
26319,
15,
3187,
63,
11857,
18,
15,
3188,
555,
834,
83,
18,
15,
2604,
15,
19269,
3319,
15,
52,
63,
19269,
63,
35,
63,
3642,
63,
2861,
14,
2424,
2,
199,
8695,
63,
493,
9555,
478,
1556,
18,
15,
11438,
2464,
5561,
15,
21351,
26319,
15,
3187,
63,
11857,
18,
15,
3188,
555,
834,
83,
18,
15,
2604,
15,
19269,
3319,
15,
10828,
63,
460,
63,
266,
63,
6851,
14,
2424,
2,
199,
4984,
9555,
478,
1556,
18,
15,
11438,
2464,
5561,
15,
21351,
26319,
15,
3187,
63,
11857,
18,
15,
3188,
555,
834,
83,
18,
15,
2604,
15,
19269,
3319,
15,
52,
63,
10828,
14,
2424,
2,
421,
199,
10828,
83,
7622,
199,
1045,
1551,
8,
8695,
63,
493,
12,
283,
82,
358,
465,
1621,
26,
199,
198,
509,
1004,
315,
1621,
26,
507,
198,
604,
275,
1004,
14,
6735,
2258,
78,
358,
507,
198,
1744,
275,
295,
14,
1294,
480,
7023,
84,
11472,
604,
9,
507,
198,
3271,
12,
371,
14073,
12,
14739,
12,
4443,
12,
10828,
29,
1744,
59,
16,
26,
552,
8,
1744,
1874,
507,
198,
10828,
83,
59,
3271,
10404,
10828,
421,
199,
14183,
3617,
29,
513,
342,
199,
1045,
1551,
8,
13880,
12,
283,
82,
358,
465,
1621,
26,
199,
198,
1291,
275,
2163,
8,
568,
9,
199,
198,
1291,
275,
1406,
1275,
6735,
2258,
78,
358,
199,
198,
1744,
275,
295,
14,
1294,
480,
7023,
84,
11472,
1406,
776,
199,
198,
509,
284,
315,
2974,
59,
17,
26,
552,
8,
1744,
19532,
507,
198,
14183,
3617,
14,
740,
8,
73,
9,
421,
199,
1877,
29,
1490,
8,
4984,
12,
283,
87,
358,
199,
1877,
14,
952,
480,
22687,
531,
199,
199,
509,
284,
315,
20370,
3617,
26,
199,
198,
1877,
14,
952,
4582,
84,
2,
435,
284,
9,
199,
1877,
14,
952,
2258,
78,
10828,
358,
199,
199,
509,
284,
315,
20370,
3617,
26,
199,
198,
10828,
29,
10828,
83,
59,
73,
61,
199,
198,
1877,
14,
952,
4582,
84,
2,
435,
11745,
9,
199,
199,
1877,
14,
952,
4582,
78,
531,
199,
1877,
14,
1600,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
|
OpenNI2-master-2.2.0.33/Wrappers/java/OpenNI.jni/CreateMethods.py
|
32
|
2398
|
#/****************************************************************************
#* *
#* OpenNI 1.x Alpha *
#* Copyright (C) 2012 PrimeSense Ltd. *
#* *
#* This file is part of OpenNI. *
#* *
#* Licensed under the Apache License, Version 2.0 (the "License"); *
#* you may not use this file except in compliance with the License. *
#* You may obtain a copy of the License at *
#* *
#* http://www.apache.org/licenses/LICENSE-2.0 *
#* *
#* Unless required by applicable law or agreed to in writing, software *
#* distributed under the License is distributed on an "AS IS" BASIS, *
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
#* See the License for the specific language governing permissions and *
#* limitations under the License. *
#* *
#****************************************************************************/
import os
import re
# ----------------------- MAIN -------------------------
java_header = open("org_openni_NativeMethods.h")
cont = java_header.read()
java_header.close()
result = open("methods.inl", "w")
result.write("static JNINativeMethod methods[] = {\n")
while True:
match = re.search("Method:\s*(\w*)", cont)
if match is None:
break
method_name = match.group(1)
match = re.search("Signature:\s*([\w\(\)\[;/]*)", cont)
if match is None:
break
signature = match.group(1)
match = re.search("JNIEXPORT.*JNICALL (\w*)", cont)
if match is None:
break
method = match.group(1)
result.write('\t{ "' + method_name + '", "' + signature + '", (void*)&' + method + ' },\n')
cont = cont[match.end():];
result.write('};\n');
result.close()
|
gpl-2.0
|
[
3,
15,
14355,
1116,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
3232,
16730,
413,
14,
88,
32657,
2476,
12793,
627,
199,
15002,
221,
1898,
334,
35,
9,
6029,
8538,
278,
51,
677,
12126,
14,
2476,
755,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
961,
570,
365,
1777,
402,
3232,
16730,
14,
2476,
3777,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
3515,
627,
199,
15002,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
260,
627,
199,
15002,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
22456,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
13235,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
420,
627,
199,
15002,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
263,
627,
199,
15002,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
627,
199,
15002,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
420,
627,
199,
15002,
221,
4204,
1334,
314,
844,
14,
2476,
3698,
627,
199,
15002,
6208,
3698,
627,
199,
3,
14355,
1116,
15,
199,
646,
747,
199,
646,
295,
199,
199,
3,
10652,
12797,
4828,
568,
10652,
9960,
199,
6138,
63,
1291,
275,
1551,
480,
1308,
63,
1490,
8445,
63,
19675,
10385,
14,
72,
531,
199,
11096,
275,
12120,
63,
1291,
14,
739,
342,
199,
6138,
63,
1291,
14,
1600,
342,
199,
1099,
275,
1551,
480,
2474,
14,
262,
76,
401,
298,
87,
531,
199,
1099,
14,
952,
480,
1986,
1603,
46,
568,
1905,
3767,
3102,
8607,
275,
9459,
78,
531,
199,
199,
6710,
715,
26,
272,
1336,
275,
295,
14,
1733,
480,
3767,
3427,
83,
22588,
87,
10,
4186,
13770,
9,
272,
340,
1336,
365,
488,
26,
267,
2059,
272,
1083,
63,
354,
275,
1336,
14,
923,
8,
17,
9,
2286,
1336,
275,
295,
14,
1733,
480,
10014,
3427,
83,
10,
16510,
87,
29323,
2862,
59,
22352,
3672,
4186,
13770,
9,
272,
340,
1336,
365,
488,
26,
267,
2059,
272,
4955,
275,
1336,
14,
923,
8,
17,
9,
5493,
1336,
275,
295,
14,
1733,
480,
42,
16730,
18341,
2795,
42,
30374,
1761,
14749,
87,
10,
4186,
13770,
9,
272,
340,
1336,
365,
488,
26,
267,
2059,
272,
1083,
275,
1336,
14,
923,
8,
17,
9,
339,
754,
14,
952,
2258,
84,
91,
3546,
435,
1083,
63,
354,
435,
283,
401,
3546,
435,
4955,
435,
283,
401,
334,
1647,
13278,
6,
7,
435,
1083,
435,
283,
1660,
60,
78,
358,
272,
13770,
275,
13770,
59,
1431,
14,
500,
837,
11566,
199,
199,
1099,
14,
952,
360,
16055,
78,
11339,
199,
1099,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
15,
14355,
1116,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
3232,
16730,
413,
14,
88,
32657,
2476,
12793,
627,
199,
15002,
221,
1898,
334,
35,
9,
6029,
8538,
278,
51,
677,
12126,
14,
2476,
755,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
961,
570,
365,
1777,
402,
3232,
16730,
14,
2476,
3777,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
3515,
627,
199,
15002,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
260,
627,
199,
15002,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
22456,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
13235,
627,
199,
15002,
6208,
3698,
627,
199,
15002,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
420,
627,
199,
15002,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
263,
627,
199,
15002,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
627,
199,
15002,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
420,
627,
199,
15002,
221,
4204,
1334,
314,
844,
14,
2476,
3698,
627,
199,
15002,
6208,
3698,
627,
199,
3,
14355,
1116,
15,
199,
646,
747,
199,
646,
295,
199,
199,
3,
10652,
12797,
4828,
568,
10652,
9960,
199,
6138,
63,
1291,
275,
1551,
480,
1308,
63,
1490,
8445,
63,
19675,
10385,
14,
72,
531,
199,
11096,
275,
12120,
63,
1291,
14,
739,
342,
199,
6138,
63,
1291,
14,
1600,
342,
199,
1099,
275,
1551,
480,
2474,
14,
262,
76,
401,
298,
87,
531,
199,
1099,
14,
952,
480,
1986,
1603,
46,
568,
1905,
3767,
3102,
8607,
275,
9459,
78,
531,
199,
199,
6710,
715,
26,
272,
1336,
275,
295,
14,
1733,
480,
3767,
3427,
83,
22588,
87,
10,
4186,
13770,
9,
272,
340,
1336,
365,
488,
26,
267,
2059,
272,
1083,
63,
354,
275,
1336,
14,
923,
8,
17,
9,
2286,
1336,
275,
295,
14,
1733,
480,
10014,
3427,
83,
10,
16510,
87,
29323,
2862,
59,
22352,
3672,
4186,
13770,
9,
272,
340,
1336,
365,
488,
26,
267,
2059,
272,
4955,
275,
1336,
14,
923,
8,
17,
9,
5493,
1336,
275,
295,
14,
1733,
480,
42,
16730,
18341,
2795,
42,
30374,
1761,
14749,
87,
10,
4186,
13770,
9,
272,
340,
1336,
365,
488,
26,
267,
2059,
272,
1083,
275,
1336,
14,
923,
8,
17,
9,
339,
754,
14,
952,
2258,
84,
91,
3546,
435,
1083,
63,
354,
435,
283,
401,
3546,
435,
4955,
435,
283,
401,
334,
1647,
13278,
6,
7,
435,
1083,
435,
283,
1660,
60,
78,
358,
272,
13770,
275,
13770,
59,
1431,
14,
500,
837,
11566,
199,
199,
1099,
14,
952,
360,
16055,
78,
11339,
199,
1099,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
donK23/pyData-Projects
|
EventDec/event_dec/main.py
|
1
|
4294
|
#!/usr/bin/python
import numpy as np
import pickle
import os
from model import Model
def get_input():
"""
Ask user for inputs about event: Title, Main Topic, Distance to Location.
Checks for correct types and value ranges. If not correct, restarts asking 5 times.
:return: Tuple(Str, Int, Int) => "Title", [0|1], [0,infinity[ OR None (to quit App)
"""
attempt = 0
title, topic, distance = None, None, None
while True:
""" Here be dragons """
if attempt >= 5: # Stop asking, if too many false inputs
print("Too many false inputs. Stopping application.")
return None
break
else: # Title of Event?
title = input("Title of event: ")
if not title:
print("No valid title entered. Try again!")
attempt += 1
continue
else:
try: # Main Topic Data?
topic = int(input("Is the main topic of event 'Data'? (0=no | 1=yes): "))
if topic not in {0, 1}:
print("Input must be 0 or 1. Try again!")
attempt += 1
continue
except ValueError:
print("Input must be an Integer (0 or 1). Try again!")
attempt += 1
continue
try: # Distance to Location?
distance = int(float(input("How far away is the location? (km): ")))
if distance < 0:
print("Input must be a positive number. Try again!")
attempt += 1
continue
except ValueError:
print("Input must be an Integer (distance in km). Try again!")
attempt += 1
continue
break
return title, topic, distance
def process_input(raw_input):
"""
Process title field - check if title contains buzzword.
Process distance field - bins distance value in bins=[10, 40, 120, 180], which correspond to distances from
homelocation to Steyr, Linz, Salzburg, Vienna, >Vienna
Convert to correct input format for model.
:param raw_input: Tuple(Str, Int, Int) => "Title", [0|1], [0,infinity[
:return: np.array([[Int, Int, Int]]) => [0|1], [0|1], [0,4]
"""
input = np.zeros(shape=(1, 3), dtype=np.int)
input[0, 0] = 0 # default not buzzwordy
input[0, 1] = int(raw_input[1])
distance_raw = int(raw_input[2])
# Process title
title_str = raw_input[0]
actual_filepath = os.path.dirname(os.path.realpath(__file__))
buzzword_file = os.path.join(actual_filepath, "data/buzzword_list.pkl")
with open(buzzword_file, "rb") as f:
buzzword_list = pickle.load(f)
for buzzword in buzzword_list:
if buzzword.lower() in title_str.lower():
input[0, 0] = 1 # buzzwordy
break
# Process distance
distance_bins = [10, 40, 120, 180] # SR, LNZ, SZG, VIE, >VIE
input[0, 2] = np.digitize(distance_raw, bins=distance_bins)
return input
def print_output(pred):
"""
Takes predicted Value (0="should not attend" | 1="should attend") from Model and prints a recommendation to stdout.
:param pred: np.ndarray([Int]) => [0] "should not attend" | [1] "should attend"
:return: -
"""
if pred == np.array([0]):
print("Predicted Class: {}. You shouldn't attend this event, it'll probably be a waste of time.".format(str(pred)))
elif pred == np.array([1]):
print("Predicted Class: {}. You should attend the event, it'll probably be worth the time.".format(str(pred)))
else: # shouldn't happen
print("Sorry, something went wrong with your prediction. Try again.")
def main():
"""
Main Loop
:return: -
"""
raw_input = get_input()
if raw_input:
input = process_input(raw_input)
try:
""" Here be dragons """
model = Model()
pred = model.predict(input=input)
print_output(pred=pred)
except:
print("Couldn't predict value. Quit Application.")
else:
print("Quit Application")
if __name__ == "__main__":
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
2680,
465,
980,
199,
646,
5927,
199,
646,
747,
199,
199,
504,
1402,
492,
5822,
199,
199,
318,
664,
63,
1210,
837,
272,
408,
272,
30481,
922,
367,
4153,
3595,
1566,
26,
16881,
12,
11298,
32166,
12,
21892,
370,
12625,
14,
272,
13813,
367,
3211,
2943,
436,
574,
12271,
14,
982,
440,
3211,
12,
11004,
83,
7198,
316,
959,
5431,
14,
272,
520,
1107,
26,
11634,
8,
2848,
12,
9805,
12,
9805,
9,
9265,
298,
6888,
401,
359,
16,
92,
17,
467,
359,
16,
12,
262,
9693,
59,
1549,
488,
334,
475,
17242,
4693,
9,
272,
408,
272,
7427,
275,
378,
272,
2538,
12,
7482,
12,
6033,
275,
488,
12,
488,
12,
488,
339,
1830,
715,
26,
267,
408,
11842,
506,
18981,
4654,
408,
267,
340,
7427,
2356,
959,
26,
327,
8015,
7198,
316,
12,
340,
4634,
5002,
3055,
4153,
288,
870,
480,
13749,
5002,
3055,
4153,
14,
8015,
4073,
4223,
2685,
288,
372,
488,
288,
2059,
267,
587,
26,
327,
16881,
402,
6763,
31,
288,
2538,
275,
1324,
480,
6888,
402,
1566,
26,
6099,
288,
340,
440,
2538,
26,
355,
870,
480,
1944,
1686,
2538,
19138,
14,
7649,
4020,
9124,
355,
7427,
847,
413,
355,
1980,
288,
587,
26,
355,
862,
26,
327,
11298,
32166,
3918,
31,
490,
7482,
275,
1109,
8,
1210,
480,
1831,
314,
2446,
7482,
402,
1566,
283,
1451,
27716,
334,
16,
29,
889,
1204,
413,
29,
5066,
304,
26725,
490,
340,
7482,
440,
315,
469,
16,
12,
413,
9160,
717,
870,
480,
3205,
1471,
506,
378,
503,
413,
14,
7649,
4020,
9124,
717,
7427,
847,
413,
717,
1980,
355,
871,
1722,
26,
490,
870,
480,
3205,
1471,
506,
376,
7225,
334,
16,
503,
413,
680,
7649,
4020,
9124,
490,
7427,
847,
413,
490,
1980,
355,
862,
26,
327,
21892,
370,
12625,
31,
490,
6033,
275,
1109,
8,
1609,
8,
1210,
480,
18335,
12474,
13437,
365,
314,
2909,
31,
334,
14595,
304,
298,
1724,
490,
340,
6033,
665,
378,
26,
717,
870,
480,
3205,
1471,
506,
282,
7317,
1329,
14,
7649,
4020,
9124,
717,
7427,
847,
413,
717,
1980,
355,
871,
1722,
26,
490,
870,
480,
3205,
1471,
506,
376,
7225,
334,
5590,
315,
16155,
680,
7649,
4020,
9124,
490,
7427,
847,
413,
490,
1980,
267,
2059,
339,
372,
2538,
12,
7482,
12,
6033,
421,
199,
318,
2112,
63,
1210,
8,
1773,
63,
1210,
304,
272,
408,
272,
7132,
2538,
901,
446,
1104,
340,
2538,
3509,
1032,
4348,
1027,
14,
272,
7132,
6033,
901,
446,
13341,
6033,
574,
315,
13341,
1524,
709,
12,
6335,
12,
13960,
12,
13576,
467,
1314,
17118,
370,
15108,
687,
4960,
5629,
1985,
370,
17854,
21897,
12,
29730,
90,
12,
428,
279,
20176,
17629,
12,
6561,
287,
3540,
12,
690,
2201,
287,
3540,
272,
7905,
370,
3211,
1324,
1475,
367,
1402,
14,
272,
520,
635,
3066,
63,
1210,
26,
11634,
8,
2848,
12,
9805,
12,
9805,
9,
9265,
298,
6888,
401,
359,
16,
92,
17,
467,
359,
16,
12,
262,
9693,
59,
272,
520,
1107,
26,
980,
14,
1144,
4038,
3241,
12,
9805,
12,
9805,
3934,
9265,
359,
16,
92,
17,
467,
359,
16,
92,
17,
467,
359,
16,
12,
20,
61,
272,
408,
339,
1324,
275,
980,
14,
4250,
8,
1392,
2687,
17,
12,
650,
395,
2152,
29,
1590,
14,
442,
9,
272,
1324,
59,
16,
12,
378,
61,
275,
378,
327,
849,
440,
1032,
4348,
1027,
89,
272,
1324,
59,
16,
12,
413,
61,
275,
1109,
8,
1773,
63,
1210,
59,
17,
566,
272,
6033,
63,
1773,
275,
1109,
8,
1773,
63,
1210,
59,
18,
566,
339,
327,
7132,
2538,
272,
2538,
63,
495,
275,
3066,
63,
1210,
59,
16,
61,
272,
3503,
63,
7218,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
272,
1032,
4348,
1027,
63,
493,
275,
747,
14,
515,
14,
904,
8,
6514,
63,
7218,
12,
298,
576,
15,
464,
4348,
1027,
63,
513,
14,
23947,
531,
339,
543,
1551,
8,
464,
4348,
1027,
63,
493,
12,
298,
4848,
531,
465,
289,
26,
267,
1032,
4348,
1027,
63,
513,
275,
5927,
14,
912,
8,
70,
9,
339,
367,
1032,
4348,
1027,
315,
1032,
4348,
1027,
63,
513,
26,
267,
340,
1032,
4348,
1027,
14,
2325,
342,
315,
2538,
63,
495,
14,
2325,
837,
288,
1324,
59,
16,
12,
378,
61,
275,
413,
327,
1032,
4348,
1027,
89,
288,
2059,
339,
327,
7132,
6033,
272,
6033,
63,
11329,
275,
359,
709,
12,
6335,
12,
13960,
12,
13576,
61,
221,
327,
12765,
12,
491,
19011,
12,
428,
26074,
12,
812,
4332,
12,
690,
54,
4332,
272,
1324,
59,
16,
12,
499,
61,
275,
980,
14,
18367,
5277,
806,
8,
5590,
63,
1773,
12,
13341,
29,
5590,
63,
11329,
9,
339,
372,
1324,
421,
199,
318,
870,
63,
1199,
8,
5991,
304,
272,
408,
272,
17415,
14746,
1594,
334,
16,
628,
5626,
440,
737,
7169,
2,
1204,
413,
628,
5626,
737,
7169,
531,
687,
5822,
436,
14767,
282,
295,
22105,
370,
3839,
14,
272,
520,
635,
8869,
26,
980,
14,
8237,
779,
3241,
566,
9265,
359,
16,
61,
298,
5626,
440,
737,
7169,
2,
1204,
359,
17,
61,
298,
5626,
737,
7169,
2,
272,
520,
1107,
26,
446,
272,
408,
272,
340,
8869,
508,
980,
14,
1144,
779,
16,
4682,
267,
870,
480,
30096,
8089,
26,
30332,
2047,
9296,
1133,
737,
7169,
642,
1566,
12,
652,
7171,
8646,
506,
282,
1990,
266,
402,
900,
15848,
908,
8,
495,
8,
5991,
1724,
272,
916,
8869,
508,
980,
14,
1144,
779,
17,
4682,
267,
870,
480,
30096,
8089,
26,
30332,
2047,
1077,
737,
7169,
314,
1566,
12,
652,
7171,
8646,
506,
25235,
314,
900,
15848,
908,
8,
495,
8,
5991,
1724,
272,
587,
26,
327,
9296,
1133,
5992,
267,
870,
480,
27143,
12,
6020,
22396,
6835,
543,
2195,
12044,
14,
7649,
4020,
2685,
421,
199,
318,
2446,
837,
272,
408,
272,
11298,
18175,
272,
520,
1107,
26,
446,
272,
408,
272,
3066,
63,
1210,
275,
664,
63,
1210,
342,
272,
340,
3066,
63,
1210,
26,
267,
1324,
275,
2112,
63,
1210,
8,
1773,
63,
1210,
9,
267,
862,
26,
288,
408,
11842,
506,
18981,
4654,
408,
288,
1402,
275
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
2680,
465,
980,
199,
646,
5927,
199,
646,
747,
199,
199,
504,
1402,
492,
5822,
199,
199,
318,
664,
63,
1210,
837,
272,
408,
272,
30481,
922,
367,
4153,
3595,
1566,
26,
16881,
12,
11298,
32166,
12,
21892,
370,
12625,
14,
272,
13813,
367,
3211,
2943,
436,
574,
12271,
14,
982,
440,
3211,
12,
11004,
83,
7198,
316,
959,
5431,
14,
272,
520,
1107,
26,
11634,
8,
2848,
12,
9805,
12,
9805,
9,
9265,
298,
6888,
401,
359,
16,
92,
17,
467,
359,
16,
12,
262,
9693,
59,
1549,
488,
334,
475,
17242,
4693,
9,
272,
408,
272,
7427,
275,
378,
272,
2538,
12,
7482,
12,
6033,
275,
488,
12,
488,
12,
488,
339,
1830,
715,
26,
267,
408,
11842,
506,
18981,
4654,
408,
267,
340,
7427,
2356,
959,
26,
327,
8015,
7198,
316,
12,
340,
4634,
5002,
3055,
4153,
288,
870,
480,
13749,
5002,
3055,
4153,
14,
8015,
4073,
4223,
2685,
288,
372,
488,
288,
2059,
267,
587,
26,
327,
16881,
402,
6763,
31,
288,
2538,
275,
1324,
480,
6888,
402,
1566,
26,
6099,
288,
340,
440,
2538,
26,
355,
870,
480,
1944,
1686,
2538,
19138,
14,
7649,
4020,
9124,
355,
7427,
847,
413,
355,
1980,
288,
587,
26,
355,
862,
26,
327,
11298,
32166,
3918,
31,
490,
7482,
275,
1109,
8,
1210,
480,
1831,
314,
2446,
7482,
402,
1566,
283,
1451,
27716,
334,
16,
29,
889,
1204,
413,
29,
5066,
304,
26725,
490,
340,
7482,
440,
315,
469,
16,
12,
413,
9160,
717,
870,
480,
3205,
1471,
506,
378,
503,
413,
14,
7649,
4020,
9124,
717,
7427,
847,
413,
717,
1980,
355,
871,
1722,
26,
490,
870,
480,
3205,
1471,
506,
376,
7225,
334,
16,
503,
413,
680,
7649,
4020,
9124,
490,
7427,
847,
413,
490,
1980,
355,
862,
26,
327,
21892,
370,
12625,
31,
490,
6033,
275,
1109,
8,
1609,
8,
1210,
480,
18335,
12474,
13437,
365,
314,
2909,
31,
334,
14595,
304,
298,
1724,
490,
340,
6033,
665,
378,
26,
717,
870,
480,
3205,
1471,
506,
282,
7317,
1329,
14,
7649,
4020,
9124,
717,
7427,
847,
413,
717,
1980,
355,
871,
1722,
26,
490,
870,
480,
3205,
1471,
506,
376,
7225,
334,
5590,
315,
16155,
680,
7649,
4020,
9124,
490,
7427,
847,
413,
490,
1980,
267,
2059,
339,
372,
2538,
12,
7482,
12,
6033,
421,
199,
318,
2112,
63,
1210,
8,
1773,
63,
1210,
304,
272,
408,
272,
7132,
2538,
901,
446,
1104,
340,
2538,
3509,
1032,
4348,
1027,
14,
272,
7132,
6033,
901,
446,
13341,
6033,
574,
315,
13341,
1524,
709,
12,
6335,
12,
13960,
12,
13576,
467,
1314,
17118,
370,
15108,
687,
4960,
5629,
1985,
370,
17854,
21897,
12,
29730,
90,
12,
428,
279,
20176,
17629,
12,
6561,
287,
3540,
12,
690,
2201,
287,
3540,
272,
7905,
370,
3211,
1324,
1475,
367,
1402,
14,
272,
520,
635,
3066,
63,
1210,
26,
11634,
8,
2848,
12,
9805,
12,
9805,
9,
9265,
298,
6888,
401,
359,
16,
92,
17,
467,
359,
16,
12,
262,
9693,
59,
272,
520,
1107,
26,
980,
14,
1144,
4038,
3241,
12,
9805,
12,
9805,
3934,
9265,
359,
16,
92,
17,
467,
359,
16,
92,
17,
467,
359,
16,
12,
20,
61,
272,
408,
339,
1324,
275,
980,
14,
4250,
8,
1392,
2687,
17,
12,
650,
395,
2152,
29,
1590,
14,
442,
9,
272,
1324,
59,
16,
12,
378,
61,
275,
378,
327,
849,
440,
1032,
4348,
1027,
89,
272,
1324,
59,
16,
12,
413,
61,
275,
1109,
8,
1773,
63,
1210,
59,
17,
566,
272,
6033,
63,
1773,
275,
1109,
8,
1773,
63,
1210,
59,
18,
566,
339,
327,
7132,
2538,
272,
2538,
63,
495,
275,
3066,
63,
1210,
59,
16,
61,
272,
3503,
63,
7218,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
272,
1032,
4348,
1027,
63,
493,
275,
747,
14,
515,
14,
904,
8,
6514,
63,
7218,
12,
298,
576,
15,
464,
4348,
1027,
63,
513,
14,
23947,
531,
339,
543,
1551,
8,
464,
4348,
1027,
63,
493,
12,
298,
4848,
531,
465,
289,
26,
267,
1032,
4348,
1027,
63,
513,
275,
5927,
14,
912,
8,
70,
9,
339,
367,
1032,
4348,
1027,
315,
1032,
4348,
1027,
63,
513,
26,
267,
340,
1032,
4348,
1027,
14,
2325,
342,
315,
2538,
63,
495,
14,
2325,
837,
288,
1324,
59,
16,
12,
378,
61,
275,
413,
327,
1032,
4348,
1027,
89,
288,
2059,
339,
327,
7132,
6033,
272,
6033,
63,
11329,
275,
359,
709,
12,
6335,
12,
13960,
12,
13576,
61,
221,
327,
12765,
12,
491,
19011,
12,
428,
26074,
12,
812,
4332,
12,
690,
54,
4332,
272,
1324,
59,
16,
12,
499,
61,
275,
980,
14,
18367,
5277,
806,
8,
5590,
63,
1773,
12,
13341,
29,
5590,
63,
11329,
9,
339,
372,
1324,
421,
199,
318,
870,
63,
1199,
8,
5991,
304,
272,
408,
272,
17415,
14746,
1594,
334,
16,
628,
5626,
440,
737,
7169,
2,
1204,
413,
628,
5626,
737,
7169,
531,
687,
5822,
436,
14767,
282,
295,
22105,
370,
3839,
14,
272,
520,
635,
8869,
26,
980,
14,
8237,
779,
3241,
566,
9265,
359,
16,
61,
298,
5626,
440,
737,
7169,
2,
1204,
359,
17,
61,
298,
5626,
737,
7169,
2,
272,
520,
1107,
26,
446,
272,
408,
272,
340,
8869,
508,
980,
14,
1144,
779,
16,
4682,
267,
870,
480,
30096,
8089,
26,
30332,
2047,
9296,
1133,
737,
7169,
642,
1566,
12,
652,
7171,
8646,
506,
282,
1990,
266,
402,
900,
15848,
908,
8,
495,
8,
5991,
1724,
272,
916,
8869,
508,
980,
14,
1144,
779,
17,
4682,
267,
870,
480,
30096,
8089,
26,
30332,
2047,
1077,
737,
7169,
314,
1566,
12,
652,
7171,
8646,
506,
25235,
314,
900,
15848,
908,
8,
495,
8,
5991,
1724,
272,
587,
26,
327,
9296,
1133,
5992,
267,
870,
480,
27143,
12,
6020,
22396,
6835,
543,
2195,
12044,
14,
7649,
4020,
2685,
421,
199,
318,
2446,
837,
272,
408,
272,
11298,
18175,
272,
520,
1107,
26,
446,
272,
408,
272,
3066,
63,
1210,
275,
664,
63,
1210,
342,
272,
340,
3066,
63,
1210,
26,
267,
1324,
275,
2112,
63,
1210,
8,
1773,
63,
1210,
9,
267,
862,
26,
288,
408,
11842,
506,
18981,
4654,
408,
288,
1402,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
anaruse/chainer
|
chainer/utils/conv_nd.py
|
3
|
4991
|
import itertools
import numpy
import six
from chainer.backends import cuda
from chainer.utils.conv import get_conv_outsize
from chainer.utils import conv_nd_kernel
def as_tuple(x, n):
if hasattr(x, '__getitem__'):
assert len(x) == n
return tuple(x)
return (x,) * n
def im2col_nd_cpu(img, ksize, stride, pad, pval=0, cover_all=False, dilate=1):
n, c = img.shape[0:2] # (n, c, d_1, d_2, ..., d_N)
dims = img.shape[2:]
ndim = len(dims)
dilate = as_tuple(dilate, ndim)
assert ndim == len(ksize) == len(stride) == len(pad)
outs = tuple(get_conv_outsize(d, k, s, p, cover_all, di)
for (d, k, s, p, di)
in zip(dims, ksize, stride, pad, dilate))
assert all(out > 0 for out in outs), 'Output sizes should be positive.'
# Pad around image.
pad_width = ((0, 0), (0, 0)) + tuple(
(p, p + s - 1) for (s, p) in zip(stride, pad))
img = numpy.pad(img, pad_width, mode='constant', constant_values=(pval,))
# Make patch array with which we will compute correlation with filter.
# shape: (n, c, k_1, k_2, ..., k_N, out_1, out_2, ..., out_N)
shape = (n, c) + ksize + outs
col = numpy.ndarray(shape, dtype=img.dtype)
# Fill the patch array.
colon = slice(None)
for kxs in itertools.product(*[six.moves.range(k) for k in ksize]):
# col[:, :, kx_1, kx_2, ..., kx_N, :, :, ..., :]
col_index = (colon, colon) + kxs + (colon,) * ndim
# img[:, :, kx_1:kx_lim_1:s_1, ..., kx_N:kx_lim_N:s_N]
kx_dilate = tuple(kx * di for (kx, di) in zip(kxs, dilate))
kx_lims = tuple(kx_di + s * out
for (kx_di, s, out) in zip(kx_dilate, stride, outs))
img_index = (colon, colon) + tuple(
slice(kx_di, kx_lim, s)
for (kx_di, kx_lim, s) in zip(kx_dilate, kx_lims, stride))
col[col_index] = img[img_index]
return col
def im2col_nd_gpu(img, ksize, stride, pad, cover_all=False, dilate=1):
n, c = img.shape[0:2] # (n, c, d_1, d_2, ..., d_N)
dims = img.shape[2:]
ndim = len(dims)
dilate = as_tuple(dilate, ndim)
assert ndim == len(ksize) == len(stride) == len(pad)
outs = tuple(get_conv_outsize(d, k, s, p, cover_all, di)
for (d, k, s, p, di)
in zip(dims, ksize, stride, pad, dilate))
assert all(out > 0 for out in outs), 'Output sizes should be positive.'
# col_shape: (n, c, k_1, k_2, ..., k_N, out_1, out_2, ..., out_N)
shape = (n, c) + ksize + outs
col = cuda.cupy.empty(shape, dtype=img.dtype)
in_params, out_params, operation, name = \
conv_nd_kernel.Im2colNDKernel.generate(ndim)
cuda.elementwise(in_params, out_params, operation, name)(
img.reduced_view(),
*(dims + outs + ksize + stride + pad + dilate + (col,)))
return col
def col2im_nd_cpu(col, stride, pad, dims, dilate=1):
n, c = col.shape[:2] # (n, c, kx_1, ..., kx_N, out_1, ..., out_N)
mid = (len(col.shape) - 2) // 2 + 2
ksize = col.shape[2:mid]
outs = col.shape[mid:]
colon = slice(None)
ndim = len(outs)
dilate = as_tuple(dilate, ndim)
assert len(ksize) == len(stride) == len(pad) == len(dims) == ndim
# Image with padded size.
img_shape = (n, c) + tuple(d + 2 * p + s - 1
for (d, p, s) in zip(dims, pad, stride))
img = numpy.zeros(img_shape, dtype=col.dtype)
for kxs in itertools.product(*[six.moves.range(k) for k in ksize]):
# (:, :, kx_1:kx_lim_1:s_1, ..., kx_N:kx_lim_N:s_N)
kx_dilate = tuple(kx * di for (kx, di) in zip(kxs, dilate))
kx_lims = tuple(kx_di + s * out
for (kx_di, s, out) in zip(kx_dilate, stride, outs))
img_index = (colon, colon) + tuple(
slice(kx_di, kx_lim, s)
for (kx_di, kx_lim, s) in zip(kx_dilate, kx_lims, stride))
# (:, :, kx_1, kx_2, ..., kx_N, :, :, ..., :)
col_index = (colon, colon) + kxs + (colon,) * len(outs)
img[img_index] += col[col_index]
# (:, :, p_1:d_1 + p_1, p_2:d_2 + p_2, ..., p_N:d_N + p_N]
img_index = (colon, colon) + tuple(
slice(p, d + p) for (p, d) in zip(pad, dims))
return img[img_index]
def col2im_nd_gpu(col, stride, pad, dims, dilate=1):
n, c = col.shape[:2] # (n, c, k_1, ..., k_N, out_1, ..., out_N)
mid = (len(col.shape) - 2) // 2 + 2
ksize = col.shape[2:mid]
outs = col.shape[mid:]
ndim = len(dims)
dilate = as_tuple(dilate, ndim)
assert len(outs) == len(ksize) == len(stride) == len(pad) == ndim
img_shape = (n, c) + dims # (n, c, d_1, d_2, ..., d_N)
img = cuda.cupy.empty(img_shape, dtype=col.dtype)
in_params, out_params, operation, name = \
conv_nd_kernel.Col2imNDKernel.generate(ndim)
cuda.elementwise(in_params, out_params, operation, name)(
col.reduced_view(),
*(dims + outs + ksize + stride + pad + dilate + (img,)))
return img
|
mit
|
[
646,
7975,
199,
199,
646,
2680,
199,
646,
3816,
199,
199,
504,
20333,
14,
7765,
492,
23123,
199,
504,
20333,
14,
1208,
14,
5598,
492,
664,
63,
5598,
63,
548,
890,
199,
504,
20333,
14,
1208,
492,
8260,
63,
977,
63,
4989,
421,
199,
318,
465,
63,
2960,
8,
88,
12,
302,
304,
272,
340,
2688,
8,
88,
12,
2560,
6095,
12168,
267,
702,
822,
8,
88,
9,
508,
302,
267,
372,
2008,
8,
88,
9,
272,
372,
334,
88,
4258,
627,
302,
421,
199,
318,
3416,
18,
761,
63,
977,
63,
3541,
8,
4060,
12,
30180,
12,
7345,
12,
6567,
12,
299,
637,
29,
16,
12,
8486,
63,
452,
29,
797,
12,
487,
750,
29,
17,
304,
272,
302,
12,
286,
275,
6050,
14,
1392,
59,
16,
26,
18,
61,
755,
327,
334,
78,
12,
286,
12,
366,
63,
17,
12,
366,
63,
18,
12,
14263,
366,
63,
46,
9,
272,
17476,
275,
6050,
14,
1392,
59,
18,
2938,
272,
17951,
275,
822,
8,
5380,
9,
272,
487,
750,
275,
465,
63,
2960,
8,
328,
750,
12,
17951,
9,
272,
702,
17951,
508,
822,
8,
75,
890,
9,
508,
822,
8,
12318,
9,
508,
822,
8,
6226,
9,
272,
31557,
275,
2008,
8,
362,
63,
5598,
63,
548,
890,
8,
68,
12,
1022,
12,
308,
12,
299,
12,
8486,
63,
452,
12,
487,
9,
326,
367,
334,
68,
12,
1022,
12,
308,
12,
299,
12,
487,
9,
326,
315,
3482,
8,
5380,
12,
30180,
12,
7345,
12,
6567,
12,
487,
750,
430,
272,
702,
1006,
8,
548,
690,
378,
367,
734,
315,
31557,
395,
283,
2959,
10627,
1077,
506,
7317,
3530,
339,
327,
510,
350,
6818,
1834,
14,
272,
6567,
63,
2063,
275,
3666,
16,
12,
378,
395,
334,
16,
12,
378,
430,
435,
2008,
8,
267,
334,
80,
12,
299,
435,
308,
446,
413,
9,
367,
334,
83,
12,
299,
9,
315,
3482,
8,
12318,
12,
6567,
430,
272,
6050,
275,
2680,
14,
6226,
8,
4060,
12,
6567,
63,
2063,
12,
818,
534,
4083,
297,
4413,
63,
1459,
2687,
80,
637,
4641,
339,
327,
4155,
3371,
1625,
543,
1314,
781,
911,
4526,
21280,
543,
2457,
14,
272,
327,
2215,
26,
334,
78,
12,
286,
12,
1022,
63,
17,
12,
1022,
63,
18,
12,
14263,
1022,
63,
46,
12,
734,
63,
17,
12,
734,
63,
18,
12,
14263,
734,
63,
46,
9,
272,
2215,
275,
334,
78,
12,
286,
9,
435,
30180,
435,
31557,
272,
1048,
275,
2680,
14,
8237,
8,
1392,
12,
2152,
29,
4060,
14,
2271,
9,
339,
327,
24797,
314,
3371,
1625,
14,
272,
18307,
275,
6014,
8,
403,
9,
272,
367,
1022,
7977,
315,
7975,
14,
2558,
23151,
4174,
14,
4912,
14,
1842,
8,
75,
9,
367,
1022,
315,
30180,
4682,
267,
327,
1048,
3981,
13785,
1022,
88,
63,
17,
12,
1022,
88,
63,
18,
12,
14263,
1022,
88,
63,
46,
12,
13785,
13785,
14263,
12228,
267,
1048,
63,
1080,
275,
334,
12167,
12,
18307,
9,
435,
1022,
7977,
435,
334,
12167,
4258,
627,
17951,
267,
327,
6050,
3981,
13785,
1022,
88,
63,
17,
26,
75,
88,
63,
4175,
63,
17,
26,
83,
63,
17,
12,
14263,
1022,
88,
63,
46,
26,
75,
88,
63,
4175,
63,
46,
26,
83,
63,
46,
61,
267,
1022,
88,
63,
328,
750,
275,
2008,
8,
75,
88,
627,
487,
367,
334,
75,
88,
12,
487,
9,
315,
3482,
8,
75,
7977,
12,
487,
750,
430,
267,
1022,
88,
63,
31689,
275,
2008,
8,
75,
88,
63,
328,
435,
308,
627,
734,
717,
367,
334,
75,
88,
63,
328,
12,
308,
12,
734,
9,
315,
3482,
8,
75,
88,
63,
328,
750,
12,
7345,
12,
31557,
430,
267,
6050,
63,
1080,
275,
334,
12167,
12,
18307,
9,
435,
2008,
8,
288,
6014,
8,
75,
88,
63,
328,
12,
1022,
88,
63,
4175,
12,
308,
9,
288,
367,
334,
75,
88,
63,
328,
12,
1022,
88,
63,
4175,
12,
308,
9,
315,
3482,
8,
75,
88,
63,
328,
750,
12,
1022,
88,
63,
31689,
12,
7345,
430,
267,
1048,
59,
761,
63,
1080,
61,
275,
6050,
59,
4060,
63,
1080,
61,
339,
372,
1048,
421,
199,
318,
3416,
18,
761,
63,
977,
63,
6477,
8,
4060,
12,
30180,
12,
7345,
12,
6567,
12,
8486,
63,
452,
29,
797,
12,
487,
750,
29,
17,
304,
272,
302,
12,
286,
275,
6050,
14,
1392,
59,
16,
26,
18,
61,
755,
327,
334,
78,
12,
286,
12,
366,
63,
17,
12,
366,
63,
18,
12,
14263,
366,
63,
46,
9,
272,
17476,
275,
6050,
14,
1392,
59,
18,
2938,
272,
17951,
275,
822,
8,
5380,
9,
272,
487,
750,
275,
465,
63,
2960,
8,
328,
750,
12,
17951,
9,
272,
702,
17951,
508,
822,
8,
75,
890,
9,
508,
822,
8,
12318,
9,
508,
822,
8,
6226,
9,
272,
31557,
275,
2008,
8,
362,
63,
5598,
63,
548,
890,
8,
68,
12,
1022,
12,
308,
12,
299,
12,
8486,
63,
452,
12,
487,
9,
326,
367,
334,
68,
12,
1022,
12,
308,
12,
299,
12,
487,
9,
326,
315,
3482,
8,
5380,
12,
30180,
12,
7345,
12,
6567,
12,
487,
750,
430,
272,
702,
1006,
8,
548,
690,
378,
367,
734,
315,
31557,
395,
283,
2959,
10627,
1077,
506,
7317,
3530,
339,
327,
1048,
63,
1392,
26,
334,
78,
12,
286,
12,
1022,
63,
17,
12,
1022,
63,
18,
12,
14263,
1022,
63,
46,
12,
734,
63,
17,
12,
734,
63,
18,
12,
14263,
734,
63,
46,
9,
272,
2215,
275,
334,
78,
12,
286,
9,
435,
30180,
435,
31557,
272,
1048,
275,
23123,
14,
17500,
89,
14,
1667,
8,
1392,
12,
2152,
29,
4060,
14,
2271,
9,
339,
315,
63,
1162,
12,
734,
63,
1162,
12,
3439,
12,
536,
275,
971,
267,
8260,
63,
977,
63,
4989,
14,
16221,
18,
761,
8711,
14127,
14,
4208,
8,
8322,
9,
339,
23123,
14,
2108,
2605,
8,
262,
63,
1162,
12,
734,
63,
1162,
12,
3439,
12,
536,
5130,
267,
6050,
14,
19523,
63,
1345,
1062,
267,
26534,
5380,
435,
31557,
435,
30180,
435,
7345,
435,
6567,
435,
487,
750,
435,
334,
761,
20097,
339,
372,
1048,
421,
199,
318,
1048,
18,
1017,
63,
977,
63,
3541,
8,
761
] |
[
7975,
199,
199,
646,
2680,
199,
646,
3816,
199,
199,
504,
20333,
14,
7765,
492,
23123,
199,
504,
20333,
14,
1208,
14,
5598,
492,
664,
63,
5598,
63,
548,
890,
199,
504,
20333,
14,
1208,
492,
8260,
63,
977,
63,
4989,
421,
199,
318,
465,
63,
2960,
8,
88,
12,
302,
304,
272,
340,
2688,
8,
88,
12,
2560,
6095,
12168,
267,
702,
822,
8,
88,
9,
508,
302,
267,
372,
2008,
8,
88,
9,
272,
372,
334,
88,
4258,
627,
302,
421,
199,
318,
3416,
18,
761,
63,
977,
63,
3541,
8,
4060,
12,
30180,
12,
7345,
12,
6567,
12,
299,
637,
29,
16,
12,
8486,
63,
452,
29,
797,
12,
487,
750,
29,
17,
304,
272,
302,
12,
286,
275,
6050,
14,
1392,
59,
16,
26,
18,
61,
755,
327,
334,
78,
12,
286,
12,
366,
63,
17,
12,
366,
63,
18,
12,
14263,
366,
63,
46,
9,
272,
17476,
275,
6050,
14,
1392,
59,
18,
2938,
272,
17951,
275,
822,
8,
5380,
9,
272,
487,
750,
275,
465,
63,
2960,
8,
328,
750,
12,
17951,
9,
272,
702,
17951,
508,
822,
8,
75,
890,
9,
508,
822,
8,
12318,
9,
508,
822,
8,
6226,
9,
272,
31557,
275,
2008,
8,
362,
63,
5598,
63,
548,
890,
8,
68,
12,
1022,
12,
308,
12,
299,
12,
8486,
63,
452,
12,
487,
9,
326,
367,
334,
68,
12,
1022,
12,
308,
12,
299,
12,
487,
9,
326,
315,
3482,
8,
5380,
12,
30180,
12,
7345,
12,
6567,
12,
487,
750,
430,
272,
702,
1006,
8,
548,
690,
378,
367,
734,
315,
31557,
395,
283,
2959,
10627,
1077,
506,
7317,
3530,
339,
327,
510,
350,
6818,
1834,
14,
272,
6567,
63,
2063,
275,
3666,
16,
12,
378,
395,
334,
16,
12,
378,
430,
435,
2008,
8,
267,
334,
80,
12,
299,
435,
308,
446,
413,
9,
367,
334,
83,
12,
299,
9,
315,
3482,
8,
12318,
12,
6567,
430,
272,
6050,
275,
2680,
14,
6226,
8,
4060,
12,
6567,
63,
2063,
12,
818,
534,
4083,
297,
4413,
63,
1459,
2687,
80,
637,
4641,
339,
327,
4155,
3371,
1625,
543,
1314,
781,
911,
4526,
21280,
543,
2457,
14,
272,
327,
2215,
26,
334,
78,
12,
286,
12,
1022,
63,
17,
12,
1022,
63,
18,
12,
14263,
1022,
63,
46,
12,
734,
63,
17,
12,
734,
63,
18,
12,
14263,
734,
63,
46,
9,
272,
2215,
275,
334,
78,
12,
286,
9,
435,
30180,
435,
31557,
272,
1048,
275,
2680,
14,
8237,
8,
1392,
12,
2152,
29,
4060,
14,
2271,
9,
339,
327,
24797,
314,
3371,
1625,
14,
272,
18307,
275,
6014,
8,
403,
9,
272,
367,
1022,
7977,
315,
7975,
14,
2558,
23151,
4174,
14,
4912,
14,
1842,
8,
75,
9,
367,
1022,
315,
30180,
4682,
267,
327,
1048,
3981,
13785,
1022,
88,
63,
17,
12,
1022,
88,
63,
18,
12,
14263,
1022,
88,
63,
46,
12,
13785,
13785,
14263,
12228,
267,
1048,
63,
1080,
275,
334,
12167,
12,
18307,
9,
435,
1022,
7977,
435,
334,
12167,
4258,
627,
17951,
267,
327,
6050,
3981,
13785,
1022,
88,
63,
17,
26,
75,
88,
63,
4175,
63,
17,
26,
83,
63,
17,
12,
14263,
1022,
88,
63,
46,
26,
75,
88,
63,
4175,
63,
46,
26,
83,
63,
46,
61,
267,
1022,
88,
63,
328,
750,
275,
2008,
8,
75,
88,
627,
487,
367,
334,
75,
88,
12,
487,
9,
315,
3482,
8,
75,
7977,
12,
487,
750,
430,
267,
1022,
88,
63,
31689,
275,
2008,
8,
75,
88,
63,
328,
435,
308,
627,
734,
717,
367,
334,
75,
88,
63,
328,
12,
308,
12,
734,
9,
315,
3482,
8,
75,
88,
63,
328,
750,
12,
7345,
12,
31557,
430,
267,
6050,
63,
1080,
275,
334,
12167,
12,
18307,
9,
435,
2008,
8,
288,
6014,
8,
75,
88,
63,
328,
12,
1022,
88,
63,
4175,
12,
308,
9,
288,
367,
334,
75,
88,
63,
328,
12,
1022,
88,
63,
4175,
12,
308,
9,
315,
3482,
8,
75,
88,
63,
328,
750,
12,
1022,
88,
63,
31689,
12,
7345,
430,
267,
1048,
59,
761,
63,
1080,
61,
275,
6050,
59,
4060,
63,
1080,
61,
339,
372,
1048,
421,
199,
318,
3416,
18,
761,
63,
977,
63,
6477,
8,
4060,
12,
30180,
12,
7345,
12,
6567,
12,
8486,
63,
452,
29,
797,
12,
487,
750,
29,
17,
304,
272,
302,
12,
286,
275,
6050,
14,
1392,
59,
16,
26,
18,
61,
755,
327,
334,
78,
12,
286,
12,
366,
63,
17,
12,
366,
63,
18,
12,
14263,
366,
63,
46,
9,
272,
17476,
275,
6050,
14,
1392,
59,
18,
2938,
272,
17951,
275,
822,
8,
5380,
9,
272,
487,
750,
275,
465,
63,
2960,
8,
328,
750,
12,
17951,
9,
272,
702,
17951,
508,
822,
8,
75,
890,
9,
508,
822,
8,
12318,
9,
508,
822,
8,
6226,
9,
272,
31557,
275,
2008,
8,
362,
63,
5598,
63,
548,
890,
8,
68,
12,
1022,
12,
308,
12,
299,
12,
8486,
63,
452,
12,
487,
9,
326,
367,
334,
68,
12,
1022,
12,
308,
12,
299,
12,
487,
9,
326,
315,
3482,
8,
5380,
12,
30180,
12,
7345,
12,
6567,
12,
487,
750,
430,
272,
702,
1006,
8,
548,
690,
378,
367,
734,
315,
31557,
395,
283,
2959,
10627,
1077,
506,
7317,
3530,
339,
327,
1048,
63,
1392,
26,
334,
78,
12,
286,
12,
1022,
63,
17,
12,
1022,
63,
18,
12,
14263,
1022,
63,
46,
12,
734,
63,
17,
12,
734,
63,
18,
12,
14263,
734,
63,
46,
9,
272,
2215,
275,
334,
78,
12,
286,
9,
435,
30180,
435,
31557,
272,
1048,
275,
23123,
14,
17500,
89,
14,
1667,
8,
1392,
12,
2152,
29,
4060,
14,
2271,
9,
339,
315,
63,
1162,
12,
734,
63,
1162,
12,
3439,
12,
536,
275,
971,
267,
8260,
63,
977,
63,
4989,
14,
16221,
18,
761,
8711,
14127,
14,
4208,
8,
8322,
9,
339,
23123,
14,
2108,
2605,
8,
262,
63,
1162,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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
] |
ezhuk/aws-tools
|
autoscale/configure_auto_scaling.py
|
1
|
6244
|
#!/usr/bin/env python
# Copyright (c) 2013 Eugene Zhuk.
# Use of this source code is governed by the MIT license that can be found
# in the LICENSE file.
"""Configures AWS Auto Scaling.
This script is intended to simplify the process of setting up AWS Auto
Scaling to automatically manage system capacity based on average CPU
usage of running instances.
Usage:
./configure_auto_scaling.py [options]
"""
import boto.ec2.autoscale
import boto.ec2.cloudwatch
import optparse
import sys
from boto.ec2.autoscale import LaunchConfiguration
from boto.ec2.autoscale import AutoScalingGroup
from boto.ec2.autoscale import ScalingPolicy
from boto.ec2.cloudwatch import MetricAlarm
import autoscale_settings as s
class Error(Exception):
pass
class Defaults(object):
"""Default settings.
"""
IMAGE = 'ami-a8d3d4ed'
TYPE = 't1.micro'
MIN_INSTANCES = 2
MAX_INSTANCES = 4
MIN_THRESHOLD = 40
MAX_THRESHOLD = 60
ADJUSTMENT = 1
PERIOD = 300
def _create_launch_configuration(c, opts):
lc = LaunchConfiguration(name=opts.name + s.LAUNCH_CONFIG_SUFFIX,
image_id=opts.image,
key_name=opts.key,
security_groups=[opts.group],
instance_type=opts.type)
c.create_launch_configuration(lc)
return lc
def _create_autoscaling_group(c, lc, opts):
g = AutoScalingGroup(name=opts.name + s.GROUP_SUFFIX,
launch_config=lc,
availability_zones=opts.zones,
load_balancers=opts.lbs,
min_size=opts.min,
max_size=opts.max)
c.create_auto_scaling_group(g)
return g
def main():
parser = optparse.OptionParser('Usage: %prog [options]')
parser.add_option('-n', '--name', dest='name',
help='The name of this configuration (e.g., TEST).')
parser.add_option('-i', '--image', dest='image', default=Defaults.IMAGE,
help='The Amazon Machine Image (AMI) ID that will be used to launch '
'EC2 instances. The most recent Amazon Linux AMI 2013.09.2 (ami-'
'a43909e1) is used by default.')
parser.add_option('-t', '--type', dest='type', default=Defaults.TYPE,
help='The type of the Amazon EC2 instance. If not specified, micro '
'instance (t1.micro) type will be used.')
parser.add_option('-k', '--key', dest='key',
help='The name of the key pair to use when creating EC2 instances. '
'This options is required.')
parser.add_option('-g', '--group', dest='group',
help='Security group that will be used when creating EC2 instances. '
'This option is required.')
parser.add_option('-m', '--min', dest='min', default=Defaults.MIN_INSTANCES,
help='The minimum number of EC2 instances in the auto scaling group. '
'By default it is set to 2.')
parser.add_option('-M', '--max', dest='max', default=Defaults.MAX_INSTANCES,
help='The maximum size of the auto scaling group. By default it is '
'set to 4.')
parser.add_option('-z', '--zone', dest='zones', action='append',
help='The availability zone for the auto scaling group. This option '
'is required.')
parser.add_option('-l', '--load-balancer', dest='lbs', action='append',
help='The name of an existing AWS load balancer to use, if any.')
parser.add_option('--min-threshold', dest='min_threshold',
default=Defaults.MIN_THRESHOLD, help='The minimum CPU utilization '
'threshold that triggers an alarm. This option is not required and '
'is set to 40% by default.')
parser.add_option('--max-threshold', dest='max_threshold',
default=Defaults.MAX_THRESHOLD, help='The maximum CPU utilization '
'threshold that triggers an alarm. This option is not required and '
'is set to 60% by default.')
parser.add_option('-a', '--adjustment', dest='adjustment',
default=Defaults.ADJUSTMENT, help='The number of EC2 instances by '
'which to scale up or down. This is set to 1 by default.')
parser.add_option('-p', '--period', dest='period', default=Defaults.PERIOD,
help='The evaluation period in seconds. This is optional and is set '
'to 300 seconds by default.')
(opts, args) = parser.parse_args()
if (0 != len(args) or
opts.name is None or
opts.key is None or
opts.group is None or
opts.zones is None):
parser.print_help()
return 1
try:
c = boto.connect_autoscale()
lc = _create_launch_configuration(c, opts)
g = _create_autoscaling_group(c, lc, opts)
policy_up = ScalingPolicy(name=opts.name + s.POLICY_UP_SUFFIX,
as_name=g.name,
scaling_adjustment=opts.adjustment,
adjustment_type='ChangeInCapacity')
c.create_scaling_policy(policy_up)
cloudwatch = boto.connect_cloudwatch()
alarm_high = MetricAlarm(name=opts.name + s.ALARM_HIGH_SUFFIX,
alarm_actions=[policy_up],
metric='CPUUtilization',
namespace='AWS/EC2',
statistic='Average',
dimensions={'AutoScalingGroupName': g.name},
period=opts.period,
evaluation_periods=1,
threshold=int(opts.max_threshold),
comparison='>')
cloudwatch.create_alarm(alarm_high)
policy_down = ScalingPolicy(name=opts.name + s.POLICY_DOWN_SUFFIX,
as_name=g.name,
scaling_adjustment=-opts.adjustment,
adjustment_type='ChangeInCapacity')
autoscale.create_scaling_policy(policy_down)
alarm_low = MetricAlarm(name=opts.name + s.ALARM_LOW_SUFFIX,
alarm_actions=[policy_down],
metric='CPUUtilization',
namespace='AWS/EC2',
statistic='Average',
dimensions={'AutoScalingGroupName': g.name},
period=opts.period,
evaluation_periods=1,
threshold=int(opts.min_threshold),
comparison='<')
cloudwatch.create_alarm(alarm_low)
except Error, err:
sys.stderr.write('[ERROR] {0}\n'.format(err))
return 1
return 0
if __name__ == '__main__':
sys.exit(main())
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6171,
662,
1518,
6349,
3107,
72,
3210,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
314,
10697,
4190,
626,
883,
506,
1911,
199,
3,
315,
314,
5113,
570,
14,
199,
199,
624,
2028,
1482,
10168,
9195,
17619,
316,
14,
199,
199,
2765,
2884,
365,
11619,
370,
15037,
314,
2112,
402,
4260,
1536,
10168,
9195,
199,
26416,
370,
5847,
9635,
2656,
14893,
4079,
641,
8095,
11952,
199,
3807,
402,
3879,
4454,
14,
199,
199,
7692,
26,
272,
16605,
6472,
63,
2495,
63,
12153,
14,
647,
359,
1419,
61,
199,
624,
199,
199,
646,
6055,
14,
825,
18,
14,
29906,
199,
646,
6055,
14,
825,
18,
14,
4091,
6821,
199,
646,
8691,
199,
646,
984,
199,
199,
504,
6055,
14,
825,
18,
14,
29906,
492,
23615,
5688,
199,
504,
6055,
14,
825,
18,
14,
29906,
492,
9195,
26416,
2448,
199,
504,
6055,
14,
825,
18,
14,
29906,
492,
17619,
316,
4845,
199,
504,
6055,
14,
825,
18,
14,
4091,
6821,
492,
22465,
30655,
199,
199,
646,
2599,
3467,
63,
1751,
465,
308,
421,
199,
533,
4520,
8,
1726,
304,
272,
986,
421,
199,
533,
7827,
8,
785,
304,
272,
408,
2698,
2202,
14,
272,
408,
272,
25228,
275,
283,
13496,
13,
65,
24,
68,
19,
68,
20,
379,
7,
272,
11511,
275,
283,
84,
17,
14,
6453,
7,
272,
15861,
63,
7834,
879,
16734,
275,
499,
272,
9141,
63,
7834,
879,
16734,
275,
841,
272,
15861,
63,
19307,
275,
6335,
272,
9141,
63,
19307,
275,
5212,
272,
16271,
42,
7698,
4479,
275,
413,
272,
13873,
25705,
275,
9601,
421,
199,
318,
485,
981,
63,
9850,
63,
4758,
8,
67,
12,
3999,
304,
272,
16093,
275,
23615,
5688,
8,
354,
29,
3291,
14,
354,
435,
308,
14,
5837,
1734,
1244,
63,
5569,
63,
12273,
12,
288,
1834,
63,
344,
29,
3291,
14,
1569,
12,
288,
790,
63,
354,
29,
3291,
14,
498,
12,
288,
6391,
63,
2634,
1524,
3291,
14,
923,
467,
288,
1256,
63,
466,
29,
3291,
14,
466,
9,
272,
286,
14,
981,
63,
9850,
63,
4758,
8,
10181,
9,
272,
372,
16093,
421,
199,
318,
485,
981,
63,
2495,
12153,
63,
923,
8,
67,
12,
16093,
12,
3999,
304,
272,
486,
275,
9195,
26416,
2448,
8,
354,
29,
3291,
14,
354,
435,
308,
14,
7823,
63,
12273,
12,
288,
10623,
63,
888,
29,
10181,
12,
288,
14962,
63,
13325,
29,
3291,
14,
13325,
12,
288,
2248,
63,
29674,
29,
3291,
14,
76,
1533,
12,
288,
1748,
63,
890,
29,
3291,
14,
827,
12,
288,
1390,
63,
890,
29,
3291,
14,
988,
9,
272,
286,
14,
981,
63,
2495,
63,
12153,
63,
923,
8,
71,
9,
272,
372,
486,
421,
199,
318,
2446,
837,
272,
1798,
275,
8691,
14,
14553,
360,
7692,
26,
450,
6595,
359,
1419,
10374,
272,
1798,
14,
525,
63,
1422,
3654,
78,
297,
2850,
354,
297,
2053,
534,
354,
297,
267,
1720,
534,
1918,
536,
402,
642,
2897,
334,
69,
14,
71,
2020,
7393,
28583,
272,
1798,
14,
525,
63,
1422,
3654,
73,
297,
2850,
1569,
297,
2053,
534,
1569,
297,
849,
29,
16986,
14,
9438,
12,
267,
1720,
534,
1918,
14347,
221,
18722,
221,
6047,
334,
1156,
41,
9,
2870,
626,
911,
506,
1202,
370,
10623,
283,
1467,
283,
4220,
18,
4454,
14,
710,
4750,
8058,
14347,
10130,
31694,
6171,
14,
1643,
14,
18,
334,
13496,
15668,
1467,
283,
65,
28429,
1643,
69,
17,
9,
365,
1202,
701,
849,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
84,
297,
2850,
466,
297,
2053,
534,
466,
297,
849,
29,
16986,
14,
2711,
12,
267,
1720,
534,
1918,
730,
402,
314,
14347,
15352,
18,
1256,
14,
982,
440,
2013,
12,
9967,
283,
1467,
283,
842,
334,
84,
17,
14,
6453,
9,
730,
911,
506,
1202,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
75,
297,
2850,
498,
297,
2053,
534,
498,
297,
267,
1720,
534,
1918,
536,
402,
314,
790,
4092,
370,
675,
1380,
6425,
15352,
18,
4454,
14,
283,
1467,
283,
2765,
1511,
365,
1415,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
71,
297,
2850,
923,
297,
2053,
534,
923,
297,
267,
1720,
534,
7676,
1572,
626,
911,
506,
1202,
1380,
6425,
15352,
18,
4454,
14,
283,
1467,
283,
2765,
945,
365,
1415,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
77,
297,
2850,
827,
297,
2053,
534,
827,
297,
849,
29,
16986,
14,
4896,
63,
7834,
879,
16734,
12,
267,
1720,
534,
1918,
7481,
1329,
402,
15352,
18,
4454,
315,
314,
2599,
13690,
1572,
14,
283,
1467,
283,
2175,
849,
652,
365,
663,
370,
499,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
45,
297,
2850,
988,
297,
2053,
534,
988,
297,
849,
29,
16986,
14,
4283,
63,
7834,
879,
16734,
12,
267,
1720,
534,
1918,
5696,
1568,
402,
314,
2599,
13690,
1572,
14,
4885,
849,
652,
365,
283,
1467,
283,
409,
370,
841,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
90,
297,
2850,
2619,
297,
2053,
534,
13325,
297,
1595,
534,
740,
297,
267,
1720,
534,
1918,
14962,
5718,
367,
314,
2599,
13690,
1572,
14,
961,
945,
283,
1467,
283,
374,
1415,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
76,
297,
2850,
912,
13,
11841,
297,
2053,
534,
76,
1533,
297,
1595,
534,
740,
297,
267,
1720,
534,
1918,
536,
402,
376,
3411,
10168,
2248,
17005,
370,
675,
12,
340,
1263,
2659,
272,
1798,
14,
525,
63,
1422,
4517,
827,
13,
7227,
297,
2053,
534,
827,
63,
7227,
297,
267,
849,
29,
16986,
14,
4896,
63,
19307,
12,
1720,
534,
1918,
7481,
11952,
7678,
25698,
283,
267,
283,
7227,
626,
18899,
376,
17987,
14,
961,
945,
365,
440,
1415,
436,
283,
267,
283,
374,
663,
370,
6335,
5,
701,
849,
2659,
272,
1798,
14,
525,
63,
1422,
4517,
988,
13,
7227,
297,
2053,
534,
988,
63,
7227,
297,
267,
849,
29,
16986,
14,
4283,
63,
19307,
12,
1720,
534,
1918,
5696,
11952,
7678,
25698,
283,
267,
283,
7227,
626,
18899,
376,
17987,
14,
961,
945,
365,
440,
1415,
436,
283,
267,
283,
374,
663,
370,
5212,
5,
701,
849,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
65,
297,
2850
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6171,
662,
1518,
6349,
3107,
72,
3210,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
314,
10697,
4190,
626,
883,
506,
1911,
199,
3,
315,
314,
5113,
570,
14,
199,
199,
624,
2028,
1482,
10168,
9195,
17619,
316,
14,
199,
199,
2765,
2884,
365,
11619,
370,
15037,
314,
2112,
402,
4260,
1536,
10168,
9195,
199,
26416,
370,
5847,
9635,
2656,
14893,
4079,
641,
8095,
11952,
199,
3807,
402,
3879,
4454,
14,
199,
199,
7692,
26,
272,
16605,
6472,
63,
2495,
63,
12153,
14,
647,
359,
1419,
61,
199,
624,
199,
199,
646,
6055,
14,
825,
18,
14,
29906,
199,
646,
6055,
14,
825,
18,
14,
4091,
6821,
199,
646,
8691,
199,
646,
984,
199,
199,
504,
6055,
14,
825,
18,
14,
29906,
492,
23615,
5688,
199,
504,
6055,
14,
825,
18,
14,
29906,
492,
9195,
26416,
2448,
199,
504,
6055,
14,
825,
18,
14,
29906,
492,
17619,
316,
4845,
199,
504,
6055,
14,
825,
18,
14,
4091,
6821,
492,
22465,
30655,
199,
199,
646,
2599,
3467,
63,
1751,
465,
308,
421,
199,
533,
4520,
8,
1726,
304,
272,
986,
421,
199,
533,
7827,
8,
785,
304,
272,
408,
2698,
2202,
14,
272,
408,
272,
25228,
275,
283,
13496,
13,
65,
24,
68,
19,
68,
20,
379,
7,
272,
11511,
275,
283,
84,
17,
14,
6453,
7,
272,
15861,
63,
7834,
879,
16734,
275,
499,
272,
9141,
63,
7834,
879,
16734,
275,
841,
272,
15861,
63,
19307,
275,
6335,
272,
9141,
63,
19307,
275,
5212,
272,
16271,
42,
7698,
4479,
275,
413,
272,
13873,
25705,
275,
9601,
421,
199,
318,
485,
981,
63,
9850,
63,
4758,
8,
67,
12,
3999,
304,
272,
16093,
275,
23615,
5688,
8,
354,
29,
3291,
14,
354,
435,
308,
14,
5837,
1734,
1244,
63,
5569,
63,
12273,
12,
288,
1834,
63,
344,
29,
3291,
14,
1569,
12,
288,
790,
63,
354,
29,
3291,
14,
498,
12,
288,
6391,
63,
2634,
1524,
3291,
14,
923,
467,
288,
1256,
63,
466,
29,
3291,
14,
466,
9,
272,
286,
14,
981,
63,
9850,
63,
4758,
8,
10181,
9,
272,
372,
16093,
421,
199,
318,
485,
981,
63,
2495,
12153,
63,
923,
8,
67,
12,
16093,
12,
3999,
304,
272,
486,
275,
9195,
26416,
2448,
8,
354,
29,
3291,
14,
354,
435,
308,
14,
7823,
63,
12273,
12,
288,
10623,
63,
888,
29,
10181,
12,
288,
14962,
63,
13325,
29,
3291,
14,
13325,
12,
288,
2248,
63,
29674,
29,
3291,
14,
76,
1533,
12,
288,
1748,
63,
890,
29,
3291,
14,
827,
12,
288,
1390,
63,
890,
29,
3291,
14,
988,
9,
272,
286,
14,
981,
63,
2495,
63,
12153,
63,
923,
8,
71,
9,
272,
372,
486,
421,
199,
318,
2446,
837,
272,
1798,
275,
8691,
14,
14553,
360,
7692,
26,
450,
6595,
359,
1419,
10374,
272,
1798,
14,
525,
63,
1422,
3654,
78,
297,
2850,
354,
297,
2053,
534,
354,
297,
267,
1720,
534,
1918,
536,
402,
642,
2897,
334,
69,
14,
71,
2020,
7393,
28583,
272,
1798,
14,
525,
63,
1422,
3654,
73,
297,
2850,
1569,
297,
2053,
534,
1569,
297,
849,
29,
16986,
14,
9438,
12,
267,
1720,
534,
1918,
14347,
221,
18722,
221,
6047,
334,
1156,
41,
9,
2870,
626,
911,
506,
1202,
370,
10623,
283,
1467,
283,
4220,
18,
4454,
14,
710,
4750,
8058,
14347,
10130,
31694,
6171,
14,
1643,
14,
18,
334,
13496,
15668,
1467,
283,
65,
28429,
1643,
69,
17,
9,
365,
1202,
701,
849,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
84,
297,
2850,
466,
297,
2053,
534,
466,
297,
849,
29,
16986,
14,
2711,
12,
267,
1720,
534,
1918,
730,
402,
314,
14347,
15352,
18,
1256,
14,
982,
440,
2013,
12,
9967,
283,
1467,
283,
842,
334,
84,
17,
14,
6453,
9,
730,
911,
506,
1202,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
75,
297,
2850,
498,
297,
2053,
534,
498,
297,
267,
1720,
534,
1918,
536,
402,
314,
790,
4092,
370,
675,
1380,
6425,
15352,
18,
4454,
14,
283,
1467,
283,
2765,
1511,
365,
1415,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
71,
297,
2850,
923,
297,
2053,
534,
923,
297,
267,
1720,
534,
7676,
1572,
626,
911,
506,
1202,
1380,
6425,
15352,
18,
4454,
14,
283,
1467,
283,
2765,
945,
365,
1415,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
77,
297,
2850,
827,
297,
2053,
534,
827,
297,
849,
29,
16986,
14,
4896,
63,
7834,
879,
16734,
12,
267,
1720,
534,
1918,
7481,
1329,
402,
15352,
18,
4454,
315,
314,
2599,
13690,
1572,
14,
283,
1467,
283,
2175,
849,
652,
365,
663,
370,
499,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
45,
297,
2850,
988,
297,
2053,
534,
988,
297,
849,
29,
16986,
14,
4283,
63,
7834,
879,
16734,
12,
267,
1720,
534,
1918,
5696,
1568,
402,
314,
2599,
13690,
1572,
14,
4885,
849,
652,
365,
283,
1467,
283,
409,
370,
841,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
90,
297,
2850,
2619,
297,
2053,
534,
13325,
297,
1595,
534,
740,
297,
267,
1720,
534,
1918,
14962,
5718,
367,
314,
2599,
13690,
1572,
14,
961,
945,
283,
1467,
283,
374,
1415,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
76,
297,
2850,
912,
13,
11841,
297,
2053,
534,
76,
1533,
297,
1595,
534,
740,
297,
267,
1720,
534,
1918,
536,
402,
376,
3411,
10168,
2248,
17005,
370,
675,
12,
340,
1263,
2659,
272,
1798,
14,
525,
63,
1422,
4517,
827,
13,
7227,
297,
2053,
534,
827,
63,
7227,
297,
267,
849,
29,
16986,
14,
4896,
63,
19307,
12,
1720,
534,
1918,
7481,
11952,
7678,
25698,
283,
267,
283,
7227,
626,
18899,
376,
17987,
14,
961,
945,
365,
440,
1415,
436,
283,
267,
283,
374,
663,
370,
6335,
5,
701,
849,
2659,
272,
1798,
14,
525,
63,
1422,
4517,
988,
13,
7227,
297,
2053,
534,
988,
63,
7227,
297,
267,
849,
29,
16986,
14,
4283,
63,
19307,
12,
1720,
534,
1918,
5696,
11952,
7678,
25698,
283,
267,
283,
7227,
626,
18899,
376,
17987,
14,
961,
945,
365,
440,
1415,
436,
283,
267,
283,
374,
663,
370,
5212,
5,
701,
849,
2659,
272,
1798,
14,
525,
63,
1422,
3654,
65,
297,
2850,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JulianEberius/Synonyms.tmbundle
|
Support/bin/pysaurus.py
|
1
|
2343
|
import subprocess, os, sys
class Proposal(object):
def __init__(self, name="", _type=None):
super(Proposal, self).__init__()
self.name = name
self.type = _type
def __repr__(self):
t_string = self.type if self.type else "NoType"
return t_string+": "+self.name
def _filter_and_to_dict(out_lines):
''' dirty code written in 10 minutes to "parse" the dictionary.app's output '''
if not out_lines:
return {}
limits = []
for i, l in enumerate(out_lines):
if l.strip() in ["noun","verb","adjective","adverb"]:
limits.append(i)
parts = []
if len(limits) <= 1:
parts = [(out_lines[0],out_lines[1:])]
else:
for x in range(len(limits)-1):
parts.append(
(out_lines[limits[x]], out_lines[limits[x]+1:limits[x+1]])
)
parts.append(
(out_lines[limits[x+1]], out_lines[limits[x+1]+1:])
)
results = []
for t, p in parts:
p = "".join(p)
for digit in ["1","2","3","4","5","6","7","8","9","0"]:
p = p.replace(digit,"")
p = p.replace(".",",").replace(";",",").strip()[:-1]
antonyms_idx = p.find("ANTONYMS")
if antonyms_idx != -1:
p = p[:antonyms_idx]
words = [w.strip() for w in p.split(",")]
words = filter(lambda x: x!="",words)
results.append((t.strip(),words))
results = dict(results)
return results
def _call_thesaurus(term):
path = os.path.dirname(sys.argv[0])
if path:
os.chdir(path)
popen = subprocess.Popen(
"./thesaurus "+term,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True)
out, _ = popen.communicate()
out_lines = filter(lambda x: x!="", out.split("\n"))
if len(out_lines) == 1 and out_lines[0] == '(null)':
return None
return out_lines
def get_synonyms(term, limit=None):
out_lines = _call_thesaurus(term)
synonyms = _filter_and_to_dict(out_lines)
result = []
if limit:
x = len(synonyms.keys())
if x==0:
return []
y = limit/x
for key in synonyms.keys():
words = synonyms[key]
num_words = min(len(words), y)
for w in words[:num_words]:
result.append(Proposal(w, key))
else:
for key in synonyms.keys():
for w in synonyms[key]:
result.append(Proposal(w, key))
return result
if __name__ == '__main__':
print get_synonyms("object")
|
mit
|
[
646,
3873,
12,
747,
12,
984,
199,
199,
533,
2165,
14506,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
536,
8772,
485,
466,
29,
403,
304,
272,
1613,
8,
919,
14506,
12,
291,
2843,
826,
4533,
272,
291,
14,
354,
275,
536,
272,
291,
14,
466,
275,
485,
466,
12244,
347,
636,
2722,
721,
277,
304,
272,
307,
63,
875,
275,
291,
14,
466,
340,
291,
14,
466,
587,
298,
1944,
804,
2,
272,
372,
307,
63,
875,
11,
582,
7210,
277,
14,
354,
199,
199,
318,
485,
1541,
63,
460,
63,
475,
63,
807,
8,
548,
63,
1278,
304,
523,
1449,
14650,
1233,
5313,
315,
1616,
9395,
370,
298,
1122,
2,
314,
2600,
14,
571,
1159,
1072,
1449,
523,
340,
440,
734,
63,
1278,
26,
272,
372,
1052,
523,
10976,
275,
942,
523,
367,
284,
12,
634,
315,
3874,
8,
548,
63,
1278,
304,
272,
340,
634,
14,
1913,
342,
315,
2097,
889,
324,
2266,
17050,
2266,
12551,
6850,
2266,
350,
17050,
6229,
489,
10976,
14,
740,
8,
73,
9,
523,
4184,
275,
942,
523,
340,
822,
8,
9368,
9,
2695,
413,
26,
272,
4184,
275,
3842,
548,
63,
1278,
59,
16,
467,
548,
63,
1278,
59,
17,
5728,
61,
523,
587,
26,
272,
367,
671,
315,
1425,
8,
552,
8,
9368,
7216,
17,
304,
489,
4184,
14,
740,
8,
267,
334,
548,
63,
1278,
59,
9368,
59,
88,
2365,
734,
63,
1278,
59,
9368,
59,
88,
2807,
17,
26,
9368,
59,
88,
11,
17,
3934,
489,
776,
272,
4184,
14,
740,
8,
489,
334,
548,
63,
1278,
59,
9368,
59,
88,
11,
17,
2365,
734,
63,
1278,
59,
9368,
59,
88,
11,
17,
2807,
17,
5728,
272,
776,
2126,
523,
2058,
275,
942,
16421,
367,
307,
12,
299,
315,
4184,
26,
272,
299,
275,
10587,
904,
8,
80,
9,
272,
367,
10964,
315,
2097,
17,
2266,
18,
2266,
19,
2266,
20,
2266,
21,
2266,
22,
2266,
23,
2266,
24,
2266,
25,
2266,
16,
6229,
489,
299,
275,
299,
14,
1814,
8,
8573,
12,
7230,
272,
299,
275,
299,
14,
1814,
30381,
401,
3471,
1814,
480,
17259,
401,
3471,
1913,
342,
4439,
17,
61,
272,
27384,
5220,
706,
63,
2996,
275,
299,
14,
1623,
480,
1441,
32537,
3053,
531,
272,
340,
27384,
5220,
706,
63,
2996,
1137,
446,
17,
26,
489,
299,
275,
299,
1491,
867,
5220,
706,
63,
2996,
61,
272,
5932,
275,
359,
87,
14,
1913,
342,
367,
336,
315,
299,
14,
1294,
11854,
11323,
272,
5932,
275,
2457,
8,
2734,
671,
26,
671,
1111,
5151,
3148,
9,
272,
2058,
14,
740,
1332,
84,
14,
1913,
1062,
3148,
430,
27404,
2058,
275,
1211,
8,
2604,
9,
523,
372,
2058,
199,
199,
318,
485,
1250,
63,
273,
397,
65,
300,
527,
8,
5125,
304,
523,
931,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
523,
340,
931,
26,
272,
747,
14,
8563,
8,
515,
9,
523,
17758,
275,
3873,
14,
7942,
8,
2049,
26069,
273,
397,
65,
300,
527,
7210,
5125,
12,
2049,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
12,
5641,
29,
549,
9,
523,
734,
12,
485,
275,
17758,
14,
10664,
342,
523,
734,
63,
1278,
275,
2457,
8,
2734,
671,
26,
671,
1111,
5151,
734,
14,
1294,
4582,
78,
2237,
523,
340,
822,
8,
548,
63,
1278,
9,
508,
413,
436,
734,
63,
1278,
59,
16,
61,
508,
8189,
2307,
11862,
272,
372,
488,
523,
372,
734,
63,
1278,
421,
199,
318,
664,
63,
9466,
5220,
706,
8,
5125,
12,
2304,
29,
403,
304,
257,
523,
734,
63,
1278,
275,
485,
1250,
63,
273,
397,
65,
300,
527,
8,
5125,
9,
523,
9560,
5220,
706,
275,
485,
1541,
63,
460,
63,
475,
63,
807,
8,
548,
63,
1278,
9,
523,
754,
275,
942,
16421,
340,
2304,
26,
272,
671,
275,
822,
8,
9466,
5220,
706,
14,
1612,
1012,
272,
340,
671,
389,
16,
26,
489,
372,
942,
2126,
272,
612,
275,
2304,
15,
88,
272,
367,
790,
315,
9560,
5220,
706,
14,
1612,
837,
489,
5932,
275,
9560,
5220,
706,
59,
498,
61,
489,
1967,
63,
3148,
275,
1748,
8,
552,
8,
3148,
395,
612,
9,
489,
367,
336,
315,
5932,
1491,
1507,
63,
3148,
2189,
267,
754,
14,
740,
8,
919,
14506,
8,
87,
12,
790,
430,
523,
587,
26,
272,
367,
790,
315,
9560,
5220,
706,
14,
1612,
837,
489,
367,
336,
315,
9560,
5220,
706,
59,
498,
2189,
267,
754,
14,
740,
8,
919,
14506,
8,
87,
12,
790,
430,
819,
372,
754,
1362,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
870,
664,
63,
9466,
5220,
706,
480,
785,
531,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3873,
12,
747,
12,
984,
199,
199,
533,
2165,
14506,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
536,
8772,
485,
466,
29,
403,
304,
272,
1613,
8,
919,
14506,
12,
291,
2843,
826,
4533,
272,
291,
14,
354,
275,
536,
272,
291,
14,
466,
275,
485,
466,
12244,
347,
636,
2722,
721,
277,
304,
272,
307,
63,
875,
275,
291,
14,
466,
340,
291,
14,
466,
587,
298,
1944,
804,
2,
272,
372,
307,
63,
875,
11,
582,
7210,
277,
14,
354,
199,
199,
318,
485,
1541,
63,
460,
63,
475,
63,
807,
8,
548,
63,
1278,
304,
523,
1449,
14650,
1233,
5313,
315,
1616,
9395,
370,
298,
1122,
2,
314,
2600,
14,
571,
1159,
1072,
1449,
523,
340,
440,
734,
63,
1278,
26,
272,
372,
1052,
523,
10976,
275,
942,
523,
367,
284,
12,
634,
315,
3874,
8,
548,
63,
1278,
304,
272,
340,
634,
14,
1913,
342,
315,
2097,
889,
324,
2266,
17050,
2266,
12551,
6850,
2266,
350,
17050,
6229,
489,
10976,
14,
740,
8,
73,
9,
523,
4184,
275,
942,
523,
340,
822,
8,
9368,
9,
2695,
413,
26,
272,
4184,
275,
3842,
548,
63,
1278,
59,
16,
467,
548,
63,
1278,
59,
17,
5728,
61,
523,
587,
26,
272,
367,
671,
315,
1425,
8,
552,
8,
9368,
7216,
17,
304,
489,
4184,
14,
740,
8,
267,
334,
548,
63,
1278,
59,
9368,
59,
88,
2365,
734,
63,
1278,
59,
9368,
59,
88,
2807,
17,
26,
9368,
59,
88,
11,
17,
3934,
489,
776,
272,
4184,
14,
740,
8,
489,
334,
548,
63,
1278,
59,
9368,
59,
88,
11,
17,
2365,
734,
63,
1278,
59,
9368,
59,
88,
11,
17,
2807,
17,
5728,
272,
776,
2126,
523,
2058,
275,
942,
16421,
367,
307,
12,
299,
315,
4184,
26,
272,
299,
275,
10587,
904,
8,
80,
9,
272,
367,
10964,
315,
2097,
17,
2266,
18,
2266,
19,
2266,
20,
2266,
21,
2266,
22,
2266,
23,
2266,
24,
2266,
25,
2266,
16,
6229,
489,
299,
275,
299,
14,
1814,
8,
8573,
12,
7230,
272,
299,
275,
299,
14,
1814,
30381,
401,
3471,
1814,
480,
17259,
401,
3471,
1913,
342,
4439,
17,
61,
272,
27384,
5220,
706,
63,
2996,
275,
299,
14,
1623,
480,
1441,
32537,
3053,
531,
272,
340,
27384,
5220,
706,
63,
2996,
1137,
446,
17,
26,
489,
299,
275,
299,
1491,
867,
5220,
706,
63,
2996,
61,
272,
5932,
275,
359,
87,
14,
1913,
342,
367,
336,
315,
299,
14,
1294,
11854,
11323,
272,
5932,
275,
2457,
8,
2734,
671,
26,
671,
1111,
5151,
3148,
9,
272,
2058,
14,
740,
1332,
84,
14,
1913,
1062,
3148,
430,
27404,
2058,
275,
1211,
8,
2604,
9,
523,
372,
2058,
199,
199,
318,
485,
1250,
63,
273,
397,
65,
300,
527,
8,
5125,
304,
523,
931,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
523,
340,
931,
26,
272,
747,
14,
8563,
8,
515,
9,
523,
17758,
275,
3873,
14,
7942,
8,
2049,
26069,
273,
397,
65,
300,
527,
7210,
5125,
12,
2049,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
12,
5641,
29,
549,
9,
523,
734,
12,
485,
275,
17758,
14,
10664,
342,
523,
734,
63,
1278,
275,
2457,
8,
2734,
671,
26,
671,
1111,
5151,
734,
14,
1294,
4582,
78,
2237,
523,
340,
822,
8,
548,
63,
1278,
9,
508,
413,
436,
734,
63,
1278,
59,
16,
61,
508,
8189,
2307,
11862,
272,
372,
488,
523,
372,
734,
63,
1278,
421,
199,
318,
664,
63,
9466,
5220,
706,
8,
5125,
12,
2304,
29,
403,
304,
257,
523,
734,
63,
1278,
275,
485,
1250,
63,
273,
397,
65,
300,
527,
8,
5125,
9,
523,
9560,
5220,
706,
275,
485,
1541,
63,
460,
63,
475,
63,
807,
8,
548,
63,
1278,
9,
523,
754,
275,
942,
16421,
340,
2304,
26,
272,
671,
275,
822,
8,
9466,
5220,
706,
14,
1612,
1012,
272,
340,
671,
389,
16,
26,
489,
372,
942,
2126,
272,
612,
275,
2304,
15,
88,
272,
367,
790,
315,
9560,
5220,
706,
14,
1612,
837,
489,
5932,
275,
9560,
5220,
706,
59,
498,
61,
489,
1967,
63,
3148,
275,
1748,
8,
552,
8,
3148,
395,
612,
9,
489,
367,
336,
315,
5932,
1491,
1507,
63,
3148,
2189,
267,
754,
14,
740,
8,
919,
14506,
8,
87,
12,
790,
430,
523,
587,
26,
272,
367,
790,
315,
9560,
5220,
706,
14,
1612,
837,
489,
367,
336,
315,
9560,
5220,
706,
59,
498,
2189,
267,
754,
14,
740,
8,
919,
14506,
8,
87,
12,
790,
430,
819,
372,
754,
1362,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
870,
664,
63,
9466,
5220,
706,
480,
785,
531,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
istresearch/readthedocs.org
|
readthedocs/doc_builder/python_environments.py
|
1
|
8279
|
import logging
import os
import shutil
from django.conf import settings
from readthedocs.builds.constants import LATEST
from readthedocs.doc_builder.config import ConfigWrapper
from readthedocs.doc_builder.loader import get_builder_class
from readthedocs.projects.constants import LOG_TEMPLATE
log = logging.getLogger(__name__)
class PythonEnvironment(object):
def __init__(self, version, build_env, config=None):
self.version = version
self.project = version.project
self.build_env = build_env
if config:
self.config = config
else:
self.config = ConfigWrapper(version=version, yaml_config={})
# Compute here, since it's used a lot
self.checkout_path = self.project.checkout_path(self.version.slug)
def _log(self, msg):
log.info(LOG_TEMPLATE
.format(project=self.project.slug,
version=self.version.slug,
msg=msg))
def delete_existing_build_dir(self):
# Handle deleting old build dir
build_dir = os.path.join(
self.venv_path(version=self.version.slug),
'build')
if os.path.exists(build_dir):
self._log('Removing existing build directory')
shutil.rmtree(build_dir)
def install_package(self):
setup_path = os.path.join(self.checkout_path, 'setup.py')
if os.path.isfile(setup_path) and self.config.install_project:
if getattr(settings, 'USE_PIP_INSTALL', False):
self.build_env.run(
'python',
self.venv_bin(version=self.version.slug, filename='pip'),
'install',
'--ignore-installed',
'--cache-dir',
self.project.pip_cache_path,
'.',
cwd=self.checkout_path,
bin_path=self.venv_bin(version=self.version.slug)
)
else:
self.build_env.run(
'python',
'setup.py',
'install',
'--force',
cwd=self.checkout_path,
bin_path=self.venv_bin(version=self.version.slug)
)
def venv_bin(self, version=LATEST, filename=None):
"""Return path to the virtualenv bin path, or a specific binary
:param version: Version slug to use in path name
:param filename: If specified, add this filename to the path return
:returns: Path to virtualenv bin or filename in virtualenv bin
"""
parts = [self.venv_path(version), 'bin']
if filename is not None:
parts.append(filename)
return os.path.join(*parts)
class Virtualenv(PythonEnvironment):
def venv_path(self, version=LATEST):
return os.path.join(self.project.doc_path, 'envs', version)
def setup_base(self):
site_packages = '--no-site-packages'
if self.config.use_system_site_packages:
site_packages = '--system-site-packages'
env_path = self.venv_path(version=self.version.slug)
self.build_env.run(
self.config.python_interpreter,
'-mvirtualenv',
site_packages,
env_path,
)
def install_core_requirements(self):
requirements = [
'sphinx==1.3.1',
'Pygments==2.0.2',
'setuptools==18.6.1',
'docutils==0.11',
'mkdocs==0.14.0',
'mock==1.0.1',
'pillow==2.6.1',
'readthedocs-sphinx-ext==0.5.4',
'sphinx-rtd-theme==0.1.9',
'alabaster>=0.7,<0.8,!=0.7.5',
'commonmark==0.5.4',
'recommonmark==0.1.1',
]
cmd = [
'python',
self.venv_bin(version=self.version.slug, filename='pip'),
'install',
'--use-wheel',
'-U',
'--cache-dir',
self.project.pip_cache_path,
]
if self.config.use_system_site_packages:
# Other code expects sphinx-build to be installed inside the
# virtualenv. Using the -I option makes sure it gets installed
# even if it is already installed system-wide (and
# --system-site-packages is used)
cmd.append('-I')
cmd.extend(requirements)
self.build_env.run(
*cmd,
bin_path=self.venv_bin(version=self.version.slug)
)
def install_user_requirements(self):
requirements_file_path = self.config.requirements_file
if not requirements_file_path:
builder_class = get_builder_class(self.project.documentation_type)
docs_dir = (builder_class(build_env=self.build_env, python_env=self)
.docs_dir())
for path in [docs_dir, '']:
for req_file in ['pip_requirements.txt', 'requirements.txt']:
test_path = os.path.join(self.checkout_path, path, req_file)
if os.path.exists(test_path):
requirements_file_path = test_path
break
if requirements_file_path:
self.build_env.run(
'python',
self.venv_bin(version=self.version.slug, filename='pip'),
'install',
'--exists-action=w',
'--cache-dir',
self.project.pip_cache_path,
'-r{0}'.format(requirements_file_path),
cwd=self.checkout_path,
bin_path=self.venv_bin(version=self.version.slug)
)
class Conda(PythonEnvironment):
def venv_path(self, version=LATEST):
return os.path.join(self.project.doc_path, 'conda', version)
def setup_base(self):
conda_env_path = os.path.join(self.project.doc_path, 'conda')
version_path = os.path.join(conda_env_path, self.version.slug)
if os.path.exists(version_path):
# Re-create conda directory each time to keep fresh state
self._log('Removing existing conda directory')
shutil.rmtree(version_path)
self.build_env.run(
'conda',
'create',
'--yes',
'--name',
self.version.slug,
'python={python_version}'.format(python_version=self.config.python_version),
environment={'CONDA_ENVS_PATH': conda_env_path}
)
def install_core_requirements(self):
conda_env_path = os.path.join(self.project.doc_path, 'conda')
# Use conda for requirements it packages
requirements = [
'sphinx==1.3.1',
'Pygments==2.0.2',
'docutils==0.11',
'mock==1.0.1',
'pillow==3.0.0',
'sphinx_rtd_theme==0.1.7',
'alabaster>=0.7,<0.8,!=0.7.5',
]
cmd = [
'conda',
'install',
'--yes',
'--name',
self.version.slug,
]
cmd.extend(requirements)
self.build_env.run(
*cmd,
environment={'CONDA_ENVS_PATH': conda_env_path}
)
# Install pip-only things.
pip_requirements = [
'mkdocs==0.14.0',
'readthedocs-sphinx-ext==0.5.4',
'commonmark==0.5.4',
'recommonmark==0.1.1',
]
pip_cmd = [
'python',
self.venv_bin(version=self.version.slug, filename='pip'),
'install',
'-U',
'--cache-dir',
self.project.pip_cache_path,
]
pip_cmd.extend(pip_requirements)
self.build_env.run(
*pip_cmd,
bin_path=self.venv_bin(version=self.version.slug)
)
def install_user_requirements(self):
conda_env_path = os.path.join(self.project.doc_path, 'conda')
self.build_env.run(
'conda',
'env',
'update',
'--name',
self.version.slug,
'--file',
self.config.conda_file,
environment={'CONDA_ENVS_PATH': conda_env_path}
)
|
mit
|
[
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
1586,
22618,
14,
10838,
14,
5559,
492,
491,
619,
1719,
199,
504,
1586,
22618,
14,
1301,
63,
5649,
14,
888,
492,
4094,
4590,
199,
504,
1586,
22618,
14,
1301,
63,
5649,
14,
3422,
492,
664,
63,
5649,
63,
533,
199,
504,
1586,
22618,
14,
6776,
14,
5559,
492,
5051,
63,
7433,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2018,
8263,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1015,
12,
1900,
63,
1813,
12,
1101,
29,
403,
304,
267,
291,
14,
1023,
275,
1015,
267,
291,
14,
1715,
275,
1015,
14,
1715,
267,
291,
14,
1506,
63,
1813,
275,
1900,
63,
1813,
267,
340,
1101,
26,
288,
291,
14,
888,
275,
1101,
267,
587,
26,
288,
291,
14,
888,
275,
4094,
4590,
8,
1023,
29,
1023,
12,
8864,
63,
888,
21146,
267,
327,
8354,
2348,
12,
3967,
652,
1159,
1202,
282,
13918,
267,
291,
14,
12891,
63,
515,
275,
291,
14,
1715,
14,
12891,
63,
515,
8,
277,
14,
1023,
14,
5464,
9,
339,
347,
485,
793,
8,
277,
12,
1499,
304,
267,
943,
14,
815,
8,
4947,
63,
7433,
326,
1275,
908,
8,
1715,
29,
277,
14,
1715,
14,
5464,
12,
586,
1015,
29,
277,
14,
1023,
14,
5464,
12,
586,
1499,
29,
1328,
430,
339,
347,
3145,
63,
5952,
63,
1506,
63,
694,
8,
277,
304,
398,
327,
8690,
13794,
2269,
1900,
2935,
267,
1900,
63,
694,
275,
747,
14,
515,
14,
904,
8,
288,
291,
14,
23195,
63,
515,
8,
1023,
29,
277,
14,
1023,
14,
5464,
395,
288,
283,
1506,
358,
267,
340,
747,
14,
515,
14,
2444,
8,
1506,
63,
694,
304,
288,
291,
423,
793,
360,
23420,
3411,
1900,
2082,
358,
288,
5145,
14,
9242,
8,
1506,
63,
694,
9,
339,
347,
3907,
63,
2491,
8,
277,
304,
267,
3272,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
12891,
63,
515,
12,
283,
2758,
14,
647,
358,
267,
340,
747,
14,
515,
14,
6292,
8,
2758,
63,
515,
9,
436,
291,
14,
888,
14,
3174,
63,
1715,
26,
288,
340,
2519,
8,
1751,
12,
283,
4701,
63,
48,
1772,
63,
16811,
297,
756,
304,
355,
291,
14,
1506,
63,
1813,
14,
1065,
8,
490,
283,
1548,
297,
490,
291,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
12,
1788,
534,
9983,
659,
490,
283,
3174,
297,
490,
2850,
4247,
13,
7657,
297,
490,
2850,
1637,
13,
694,
297,
490,
291,
14,
1715,
14,
9983,
63,
1637,
63,
515,
12,
490,
22608,
490,
8288,
29,
277,
14,
12891,
63,
515,
12,
490,
2517,
63,
515,
29,
277,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
9,
355,
776,
288,
587,
26,
355,
291,
14,
1506,
63,
1813,
14,
1065,
8,
490,
283,
1548,
297,
490,
283,
2758,
14,
647,
297,
490,
283,
3174,
297,
490,
2850,
3990,
297,
490,
8288,
29,
277,
14,
12891,
63,
515,
12,
490,
2517,
63,
515,
29,
277,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
9,
355,
776,
339,
347,
373,
1813,
63,
1393,
8,
277,
12,
1015,
29,
20307,
1719,
12,
1788,
29,
403,
304,
267,
408,
1767,
931,
370,
314,
19128,
2517,
931,
12,
503,
282,
2488,
3366,
398,
520,
635,
1015,
26,
3394,
8889,
370,
675,
315,
931,
536,
267,
520,
635,
1788,
26,
982,
2013,
12,
1050,
642,
1788,
370,
314,
931,
372,
267,
520,
5808,
26,
6912,
370,
19128,
2517,
503,
1788,
315,
19128,
2517,
267,
408,
267,
4184,
275,
359,
277,
14,
23195,
63,
515,
8,
1023,
395,
283,
1393,
418,
267,
340,
1788,
365,
440,
488,
26,
288,
4184,
14,
740,
8,
1501,
9,
267,
372,
747,
14,
515,
14,
904,
2031,
4181,
9,
421,
199,
533,
812,
8401,
13561,
8,
4718,
8263,
304,
339,
347,
373,
1813,
63,
515,
8,
277,
12,
1015,
29,
20307,
1719,
304,
267,
372,
747,
14,
515,
14,
904,
8,
277,
14,
1715,
14,
1301,
63,
515,
12,
283,
27900,
297,
1015,
9,
339,
347,
3272,
63,
1095,
8,
277,
304,
267,
4770,
63,
5154,
275,
2850,
889,
13,
2124,
13,
5154,
7,
267,
340,
291,
14,
888,
14,
1180,
63,
2253,
63,
2124,
63,
5154,
26,
288,
4770,
63,
5154,
275,
2850,
2253,
13,
2124,
13,
5154,
7,
267,
2589,
63,
515,
275,
291,
14,
23195,
63,
515,
8,
1023,
29,
277,
14,
1023,
14,
5464,
9,
267,
291,
14,
1506,
63,
1813,
14,
1065,
8,
288,
291,
14,
888,
14,
1548,
63,
20244,
12,
288,
2475,
77,
21611,
297,
288,
4770,
63,
5154,
12,
288,
2589,
63,
515,
12,
267,
776,
339,
347,
3907,
63,
1018,
63,
7538,
8,
277,
304,
267,
9760,
275,
359,
288,
283,
8008,
389,
17,
14,
19,
14,
17,
297,
288,
283,
2713,
4664,
389,
18,
14,
16,
14,
18,
297,
288,
283,
13623,
389,
1085,
14,
22,
14,
17,
297,
288,
283,
27114,
389,
16,
14,
845,
297,
288,
283,
3880,
4757,
389,
16,
14,
1079,
14,
16,
297,
288,
283,
1805,
389,
17,
14,
16,
14,
17,
297,
288,
283,
80,
382,
674,
389,
18,
14,
22,
14,
17,
297,
288,
283,
25085,
13,
8008,
13,
832,
389,
16,
14,
21,
14,
20,
297,
288,
283,
8008,
13,
29048,
13,
7915,
389,
16,
14,
17,
14,
25,
297,
288,
283,
279,
371,
2311,
8119,
16,
14,
23,
30027,
16,
14,
24,
12,
1111,
16,
14,
23,
14,
21,
297,
288,
283,
2330,
1657,
389,
16,
14,
21,
14,
20,
297,
288,
283,
264,
2330,
1657,
389,
16,
14,
17,
14,
17,
297,
267,
1622,
398,
2088,
275,
359,
288,
283,
1548,
297,
288,
291,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
12,
1788,
534,
9983,
659,
288,
283,
3174,
297,
288,
2850,
1180,
13,
11798,
297,
288,
2475,
53,
297,
288,
2850,
1637,
13,
694,
297,
288,
291,
14,
1715,
14,
9983,
63,
1637,
63,
515,
12,
267,
1622,
267,
340,
291,
14,
888,
14,
1180,
63,
2253,
63,
2124,
63,
5154,
26,
288
] |
[
2050,
199,
646,
747,
199,
646,
5145,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
1586,
22618,
14,
10838,
14,
5559,
492,
491,
619,
1719,
199,
504,
1586,
22618,
14,
1301,
63,
5649,
14,
888,
492,
4094,
4590,
199,
504,
1586,
22618,
14,
1301,
63,
5649,
14,
3422,
492,
664,
63,
5649,
63,
533,
199,
504,
1586,
22618,
14,
6776,
14,
5559,
492,
5051,
63,
7433,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2018,
8263,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1015,
12,
1900,
63,
1813,
12,
1101,
29,
403,
304,
267,
291,
14,
1023,
275,
1015,
267,
291,
14,
1715,
275,
1015,
14,
1715,
267,
291,
14,
1506,
63,
1813,
275,
1900,
63,
1813,
267,
340,
1101,
26,
288,
291,
14,
888,
275,
1101,
267,
587,
26,
288,
291,
14,
888,
275,
4094,
4590,
8,
1023,
29,
1023,
12,
8864,
63,
888,
21146,
267,
327,
8354,
2348,
12,
3967,
652,
1159,
1202,
282,
13918,
267,
291,
14,
12891,
63,
515,
275,
291,
14,
1715,
14,
12891,
63,
515,
8,
277,
14,
1023,
14,
5464,
9,
339,
347,
485,
793,
8,
277,
12,
1499,
304,
267,
943,
14,
815,
8,
4947,
63,
7433,
326,
1275,
908,
8,
1715,
29,
277,
14,
1715,
14,
5464,
12,
586,
1015,
29,
277,
14,
1023,
14,
5464,
12,
586,
1499,
29,
1328,
430,
339,
347,
3145,
63,
5952,
63,
1506,
63,
694,
8,
277,
304,
398,
327,
8690,
13794,
2269,
1900,
2935,
267,
1900,
63,
694,
275,
747,
14,
515,
14,
904,
8,
288,
291,
14,
23195,
63,
515,
8,
1023,
29,
277,
14,
1023,
14,
5464,
395,
288,
283,
1506,
358,
267,
340,
747,
14,
515,
14,
2444,
8,
1506,
63,
694,
304,
288,
291,
423,
793,
360,
23420,
3411,
1900,
2082,
358,
288,
5145,
14,
9242,
8,
1506,
63,
694,
9,
339,
347,
3907,
63,
2491,
8,
277,
304,
267,
3272,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
12891,
63,
515,
12,
283,
2758,
14,
647,
358,
267,
340,
747,
14,
515,
14,
6292,
8,
2758,
63,
515,
9,
436,
291,
14,
888,
14,
3174,
63,
1715,
26,
288,
340,
2519,
8,
1751,
12,
283,
4701,
63,
48,
1772,
63,
16811,
297,
756,
304,
355,
291,
14,
1506,
63,
1813,
14,
1065,
8,
490,
283,
1548,
297,
490,
291,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
12,
1788,
534,
9983,
659,
490,
283,
3174,
297,
490,
2850,
4247,
13,
7657,
297,
490,
2850,
1637,
13,
694,
297,
490,
291,
14,
1715,
14,
9983,
63,
1637,
63,
515,
12,
490,
22608,
490,
8288,
29,
277,
14,
12891,
63,
515,
12,
490,
2517,
63,
515,
29,
277,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
9,
355,
776,
288,
587,
26,
355,
291,
14,
1506,
63,
1813,
14,
1065,
8,
490,
283,
1548,
297,
490,
283,
2758,
14,
647,
297,
490,
283,
3174,
297,
490,
2850,
3990,
297,
490,
8288,
29,
277,
14,
12891,
63,
515,
12,
490,
2517,
63,
515,
29,
277,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
9,
355,
776,
339,
347,
373,
1813,
63,
1393,
8,
277,
12,
1015,
29,
20307,
1719,
12,
1788,
29,
403,
304,
267,
408,
1767,
931,
370,
314,
19128,
2517,
931,
12,
503,
282,
2488,
3366,
398,
520,
635,
1015,
26,
3394,
8889,
370,
675,
315,
931,
536,
267,
520,
635,
1788,
26,
982,
2013,
12,
1050,
642,
1788,
370,
314,
931,
372,
267,
520,
5808,
26,
6912,
370,
19128,
2517,
503,
1788,
315,
19128,
2517,
267,
408,
267,
4184,
275,
359,
277,
14,
23195,
63,
515,
8,
1023,
395,
283,
1393,
418,
267,
340,
1788,
365,
440,
488,
26,
288,
4184,
14,
740,
8,
1501,
9,
267,
372,
747,
14,
515,
14,
904,
2031,
4181,
9,
421,
199,
533,
812,
8401,
13561,
8,
4718,
8263,
304,
339,
347,
373,
1813,
63,
515,
8,
277,
12,
1015,
29,
20307,
1719,
304,
267,
372,
747,
14,
515,
14,
904,
8,
277,
14,
1715,
14,
1301,
63,
515,
12,
283,
27900,
297,
1015,
9,
339,
347,
3272,
63,
1095,
8,
277,
304,
267,
4770,
63,
5154,
275,
2850,
889,
13,
2124,
13,
5154,
7,
267,
340,
291,
14,
888,
14,
1180,
63,
2253,
63,
2124,
63,
5154,
26,
288,
4770,
63,
5154,
275,
2850,
2253,
13,
2124,
13,
5154,
7,
267,
2589,
63,
515,
275,
291,
14,
23195,
63,
515,
8,
1023,
29,
277,
14,
1023,
14,
5464,
9,
267,
291,
14,
1506,
63,
1813,
14,
1065,
8,
288,
291,
14,
888,
14,
1548,
63,
20244,
12,
288,
2475,
77,
21611,
297,
288,
4770,
63,
5154,
12,
288,
2589,
63,
515,
12,
267,
776,
339,
347,
3907,
63,
1018,
63,
7538,
8,
277,
304,
267,
9760,
275,
359,
288,
283,
8008,
389,
17,
14,
19,
14,
17,
297,
288,
283,
2713,
4664,
389,
18,
14,
16,
14,
18,
297,
288,
283,
13623,
389,
1085,
14,
22,
14,
17,
297,
288,
283,
27114,
389,
16,
14,
845,
297,
288,
283,
3880,
4757,
389,
16,
14,
1079,
14,
16,
297,
288,
283,
1805,
389,
17,
14,
16,
14,
17,
297,
288,
283,
80,
382,
674,
389,
18,
14,
22,
14,
17,
297,
288,
283,
25085,
13,
8008,
13,
832,
389,
16,
14,
21,
14,
20,
297,
288,
283,
8008,
13,
29048,
13,
7915,
389,
16,
14,
17,
14,
25,
297,
288,
283,
279,
371,
2311,
8119,
16,
14,
23,
30027,
16,
14,
24,
12,
1111,
16,
14,
23,
14,
21,
297,
288,
283,
2330,
1657,
389,
16,
14,
21,
14,
20,
297,
288,
283,
264,
2330,
1657,
389,
16,
14,
17,
14,
17,
297,
267,
1622,
398,
2088,
275,
359,
288,
283,
1548,
297,
288,
291,
14,
23195,
63,
1393,
8,
1023,
29,
277,
14,
1023,
14,
5464,
12,
1788,
534,
9983,
659,
288,
283,
3174,
297,
288,
2850,
1180,
13,
11798,
297,
288,
2475,
53,
297,
288,
2850,
1637,
13,
694,
297,
288,
291,
14,
1715,
14,
9983,
63,
1637,
63,
515,
12,
267,
1622,
267,
340,
291,
14,
888,
14,
1180,
63,
2253,
63,
2124,
63,
5154,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mingit/mstcpV0.89.4_linux
|
scripts/rt-tester/rt-tester.py
|
11005
|
5307
|
#!/usr/bin/python
#
# rt-mutex tester
#
# (C) 2006 Thomas Gleixner <tglx@linutronix.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
import os
import sys
import getopt
import shutil
import string
# Globals
quiet = 0
test = 0
comments = 0
sysfsprefix = "/sys/devices/system/rttest/rttest"
statusfile = "/status"
commandfile = "/command"
# Command opcodes
cmd_opcodes = {
"schedother" : "1",
"schedfifo" : "2",
"lock" : "3",
"locknowait" : "4",
"lockint" : "5",
"lockintnowait" : "6",
"lockcont" : "7",
"unlock" : "8",
"signal" : "11",
"resetevent" : "98",
"reset" : "99",
}
test_opcodes = {
"prioeq" : ["P" , "eq" , None],
"priolt" : ["P" , "lt" , None],
"priogt" : ["P" , "gt" , None],
"nprioeq" : ["N" , "eq" , None],
"npriolt" : ["N" , "lt" , None],
"npriogt" : ["N" , "gt" , None],
"unlocked" : ["M" , "eq" , 0],
"trylock" : ["M" , "eq" , 1],
"blocked" : ["M" , "eq" , 2],
"blockedwake" : ["M" , "eq" , 3],
"locked" : ["M" , "eq" , 4],
"opcodeeq" : ["O" , "eq" , None],
"opcodelt" : ["O" , "lt" , None],
"opcodegt" : ["O" , "gt" , None],
"eventeq" : ["E" , "eq" , None],
"eventlt" : ["E" , "lt" , None],
"eventgt" : ["E" , "gt" , None],
}
# Print usage information
def usage():
print "rt-tester.py <-c -h -q -t> <testfile>"
print " -c display comments after first command"
print " -h help"
print " -q quiet mode"
print " -t test mode (syntax check)"
print " testfile: read test specification from testfile"
print " otherwise from stdin"
return
# Print progress when not in quiet mode
def progress(str):
if not quiet:
print str
# Analyse a status value
def analyse(val, top, arg):
intval = int(val)
if top[0] == "M":
intval = intval / (10 ** int(arg))
intval = intval % 10
argval = top[2]
elif top[0] == "O":
argval = int(cmd_opcodes.get(arg, arg))
else:
argval = int(arg)
# progress("%d %s %d" %(intval, top[1], argval))
if top[1] == "eq" and intval == argval:
return 1
if top[1] == "lt" and intval < argval:
return 1
if top[1] == "gt" and intval > argval:
return 1
return 0
# Parse the commandline
try:
(options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
except getopt.GetoptError, ex:
usage()
sys.exit(1)
# Parse commandline options
for option, value in options:
if option == "-c":
comments = 1
elif option == "-q":
quiet = 1
elif option == "-t":
test = 1
elif option == '-h':
usage()
sys.exit(0)
# Select the input source
if arguments:
try:
fd = open(arguments[0])
except Exception,ex:
sys.stderr.write("File not found %s\n" %(arguments[0]))
sys.exit(1)
else:
fd = sys.stdin
linenr = 0
# Read the test patterns
while 1:
linenr = linenr + 1
line = fd.readline()
if not len(line):
break
line = line.strip()
parts = line.split(":")
if not parts or len(parts) < 1:
continue
if len(parts[0]) == 0:
continue
if parts[0].startswith("#"):
if comments > 1:
progress(line)
continue
if comments == 1:
comments = 2
progress(line)
cmd = parts[0].strip().lower()
opc = parts[1].strip().lower()
tid = parts[2].strip()
dat = parts[3].strip()
try:
# Test or wait for a status value
if cmd == "t" or cmd == "w":
testop = test_opcodes[opc]
fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
if test:
print fname
continue
while 1:
query = 1
fsta = open(fname, 'r')
status = fsta.readline().strip()
fsta.close()
stat = status.split(",")
for s in stat:
s = s.strip()
if s.startswith(testop[0]):
# Separate status value
val = s[2:].strip()
query = analyse(val, testop, dat)
break
if query or cmd == "t":
break
progress(" " + status)
if not query:
sys.stderr.write("Test failed in line %d\n" %(linenr))
sys.exit(1)
# Issue a command to the tester
elif cmd == "c":
cmdnr = cmd_opcodes[opc]
# Build command string and sys filename
cmdstr = "%s:%s" %(cmdnr, dat)
fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
if test:
print fname
continue
fcmd = open(fname, 'w')
fcmd.write(cmdstr)
fcmd.close()
except Exception,ex:
sys.stderr.write(str(ex))
sys.stderr.write("\nSyntax error in line %d\n" %(linenr))
if not test:
fd.close()
sys.exit(1)
# Normal exit pass
print "Pass"
sys.exit(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
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,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
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,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16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,
1,
1,
1,
1,
1,
1,
1,
1
] |
famnote/pottocoin
|
contrib/spendfrom/spendfrom.py
|
792
|
10053
|
#!/usr/bin/env python
#
# Use the raw transactions API to spend bitcoins received on particular addresses,
# and send any change back to that same address.
#
# Example usage:
# spendfrom.py # Lists available funds
# spendfrom.py --from=ADDRESS --to=ADDRESS --amount=11.00
#
# Assumes it will talk to a bitcoind or Bitcoin-Qt running
# on localhost.
#
# Depends on jsonrpc
#
from decimal import *
import getpass
import math
import os
import os.path
import platform
import sys
import time
from jsonrpc import ServiceProxy, json
BASE_FEE=Decimal("0.001")
def check_json_precision():
"""Make sure json library being used does not lose precision converting BTC values"""
n = Decimal("20000000.00000003")
satoshis = int(json.loads(json.dumps(float(n)))*1.0e8)
if satoshis != 2000000000000003:
raise RuntimeError("JSON encode/decode loses precision")
def determine_db_dir():
"""Return the default location of the bitcoin data directory"""
if platform.system() == "Darwin":
return os.path.expanduser("~/Library/Application Support/Bitcoin/")
elif platform.system() == "Windows":
return os.path.join(os.environ['APPDATA'], "Bitcoin")
return os.path.expanduser("~/.bitcoin")
def read_bitcoin_config(dbdir):
"""Read the bitcoin.conf file from dbdir, returns dictionary of settings"""
from ConfigParser import SafeConfigParser
class FakeSecHead(object):
def __init__(self, fp):
self.fp = fp
self.sechead = '[all]\n'
def readline(self):
if self.sechead:
try: return self.sechead
finally: self.sechead = None
else:
s = self.fp.readline()
if s.find('#') != -1:
s = s[0:s.find('#')].strip() +"\n"
return s
config_parser = SafeConfigParser()
config_parser.readfp(FakeSecHead(open(os.path.join(dbdir, "bitcoin.conf"))))
return dict(config_parser.items("all"))
def connect_JSON(config):
"""Connect to a bitcoin JSON-RPC server"""
testnet = config.get('testnet', '0')
testnet = (int(testnet) > 0) # 0/1 in config file, convert to True/False
if not 'rpcport' in config:
config['rpcport'] = 19332 if testnet else 9332
connect = "http://%s:%s@127.0.0.1:%s"%(config['rpcuser'], config['rpcpassword'], config['rpcport'])
try:
result = ServiceProxy(connect)
# ServiceProxy is lazy-connect, so send an RPC command mostly to catch connection errors,
# but also make sure the bitcoind we're talking to is/isn't testnet:
if result.getmininginfo()['testnet'] != testnet:
sys.stderr.write("RPC server at "+connect+" testnet setting mismatch\n")
sys.exit(1)
return result
except:
sys.stderr.write("Error connecting to RPC server at "+connect+"\n")
sys.exit(1)
def unlock_wallet(bitcoind):
info = bitcoind.getinfo()
if 'unlocked_until' not in info:
return True # wallet is not encrypted
t = int(info['unlocked_until'])
if t <= time.time():
try:
passphrase = getpass.getpass("Wallet is locked; enter passphrase: ")
bitcoind.walletpassphrase(passphrase, 5)
except:
sys.stderr.write("Wrong passphrase\n")
info = bitcoind.getinfo()
return int(info['unlocked_until']) > time.time()
def list_available(bitcoind):
address_summary = dict()
address_to_account = dict()
for info in bitcoind.listreceivedbyaddress(0):
address_to_account[info["address"]] = info["account"]
unspent = bitcoind.listunspent(0)
for output in unspent:
# listunspent doesn't give addresses, so:
rawtx = bitcoind.getrawtransaction(output['txid'], 1)
vout = rawtx["vout"][output['vout']]
pk = vout["scriptPubKey"]
# This code only deals with ordinary pay-to-bitcoin-address
# or pay-to-script-hash outputs right now; anything exotic is ignored.
if pk["type"] != "pubkeyhash" and pk["type"] != "scripthash":
continue
address = pk["addresses"][0]
if address in address_summary:
address_summary[address]["total"] += vout["value"]
address_summary[address]["outputs"].append(output)
else:
address_summary[address] = {
"total" : vout["value"],
"outputs" : [output],
"account" : address_to_account.get(address, "")
}
return address_summary
def select_coins(needed, inputs):
# Feel free to improve this, this is good enough for my simple needs:
outputs = []
have = Decimal("0.0")
n = 0
while have < needed and n < len(inputs):
outputs.append({ "txid":inputs[n]["txid"], "vout":inputs[n]["vout"]})
have += inputs[n]["amount"]
n += 1
return (outputs, have-needed)
def create_tx(bitcoind, fromaddresses, toaddress, amount, fee):
all_coins = list_available(bitcoind)
total_available = Decimal("0.0")
needed = amount+fee
potential_inputs = []
for addr in fromaddresses:
if addr not in all_coins:
continue
potential_inputs.extend(all_coins[addr]["outputs"])
total_available += all_coins[addr]["total"]
if total_available < needed:
sys.stderr.write("Error, only %f BTC available, need %f\n"%(total_available, needed));
sys.exit(1)
#
# Note:
# Python's json/jsonrpc modules have inconsistent support for Decimal numbers.
# Instead of wrestling with getting json.dumps() (used by jsonrpc) to encode
# Decimals, I'm casting amounts to float before sending them to bitcoind.
#
outputs = { toaddress : float(amount) }
(inputs, change_amount) = select_coins(needed, potential_inputs)
if change_amount > BASE_FEE: # don't bother with zero or tiny change
change_address = fromaddresses[-1]
if change_address in outputs:
outputs[change_address] += float(change_amount)
else:
outputs[change_address] = float(change_amount)
rawtx = bitcoind.createrawtransaction(inputs, outputs)
signed_rawtx = bitcoind.signrawtransaction(rawtx)
if not signed_rawtx["complete"]:
sys.stderr.write("signrawtransaction failed\n")
sys.exit(1)
txdata = signed_rawtx["hex"]
return txdata
def compute_amount_in(bitcoind, txinfo):
result = Decimal("0.0")
for vin in txinfo['vin']:
in_info = bitcoind.getrawtransaction(vin['txid'], 1)
vout = in_info['vout'][vin['vout']]
result = result + vout['value']
return result
def compute_amount_out(txinfo):
result = Decimal("0.0")
for vout in txinfo['vout']:
result = result + vout['value']
return result
def sanity_test_fee(bitcoind, txdata_hex, max_fee):
class FeeError(RuntimeError):
pass
try:
txinfo = bitcoind.decoderawtransaction(txdata_hex)
total_in = compute_amount_in(bitcoind, txinfo)
total_out = compute_amount_out(txinfo)
if total_in-total_out > max_fee:
raise FeeError("Rejecting transaction, unreasonable fee of "+str(total_in-total_out))
tx_size = len(txdata_hex)/2
kb = tx_size/1000 # integer division rounds down
if kb > 1 and fee < BASE_FEE:
raise FeeError("Rejecting no-fee transaction, larger than 1000 bytes")
if total_in < 0.01 and fee < BASE_FEE:
raise FeeError("Rejecting no-fee, tiny-amount transaction")
# Exercise for the reader: compute transaction priority, and
# warn if this is a very-low-priority transaction
except FeeError as err:
sys.stderr.write((str(err)+"\n"))
sys.exit(1)
def main():
import optparse
parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option("--from", dest="fromaddresses", default=None,
help="addresses to get bitcoins from")
parser.add_option("--to", dest="to", default=None,
help="address to get send bitcoins to")
parser.add_option("--amount", dest="amount", default=None,
help="amount to send")
parser.add_option("--fee", dest="fee", default="0.0",
help="fee to include")
parser.add_option("--datadir", dest="datadir", default=determine_db_dir(),
help="location of bitcoin.conf file with RPC username/password (default: %default)")
parser.add_option("--testnet", dest="testnet", default=False, action="store_true",
help="Use the test network")
parser.add_option("--dry_run", dest="dry_run", default=False, action="store_true",
help="Don't broadcast the transaction, just create and print the transaction data")
(options, args) = parser.parse_args()
check_json_precision()
config = read_bitcoin_config(options.datadir)
if options.testnet: config['testnet'] = True
bitcoind = connect_JSON(config)
if options.amount is None:
address_summary = list_available(bitcoind)
for address,info in address_summary.iteritems():
n_transactions = len(info['outputs'])
if n_transactions > 1:
print("%s %.8f %s (%d transactions)"%(address, info['total'], info['account'], n_transactions))
else:
print("%s %.8f %s"%(address, info['total'], info['account']))
else:
fee = Decimal(options.fee)
amount = Decimal(options.amount)
while unlock_wallet(bitcoind) == False:
pass # Keep asking for passphrase until they get it right
txdata = create_tx(bitcoind, options.fromaddresses.split(","), options.to, amount, fee)
sanity_test_fee(bitcoind, txdata, amount*Decimal("0.01"))
if options.dry_run:
print(txdata)
else:
txid = bitcoind.sendrawtransaction(txdata)
print(txid)
if __name__ == '__main__':
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
3645,
314,
3066,
15809,
3261,
370,
26387,
4546,
331,
3617,
3086,
641,
6770,
7149,
12,
199,
3,
436,
3222,
1263,
1570,
1771,
370,
626,
2011,
2287,
14,
199,
3,
199,
3,
5679,
4503,
26,
199,
3,
221,
26387,
504,
14,
647,
221,
327,
31289,
2808,
27440,
83,
199,
3,
221,
26387,
504,
14,
647,
1553,
504,
29,
12368,
1553,
475,
29,
12368,
1553,
4606,
29,
845,
14,
383,
199,
3,
199,
3,
30451,
652,
911,
22811,
370,
282,
27902,
503,
21158,
13,
4238,
3879,
199,
3,
641,
11667,
14,
199,
3,
199,
3,
21588,
3198,
641,
2022,
4354,
199,
3,
199,
199,
504,
6107,
492,
627,
199,
646,
18354,
199,
646,
3473,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
4298,
199,
646,
984,
199,
646,
900,
199,
504,
2022,
4354,
492,
7591,
4936,
12,
2022,
199,
199,
5825,
63,
5100,
37,
29,
6745,
480,
16,
14,
4587,
531,
199,
199,
318,
1104,
63,
1001,
63,
6833,
837,
272,
408,
5483,
3238,
2022,
3555,
3769,
1202,
1630,
440,
27332,
7151,
13806,
699,
5708,
1338,
624,
272,
302,
275,
6345,
480,
18,
9084,
14,
9084,
19,
531,
272,
308,
11318,
609,
374,
275,
1109,
8,
1001,
14,
3640,
8,
1001,
14,
4180,
8,
1609,
8,
78,
1724,
10,
17,
14,
16,
69,
24,
9,
272,
340,
308,
11318,
609,
374,
1137,
499,
17994,
19,
26,
267,
746,
6064,
480,
6243,
3752,
15,
2708,
560,
874,
7151,
531,
199,
199,
318,
6705,
63,
697,
63,
694,
837,
272,
408,
1767,
314,
849,
2909,
402,
314,
27214,
666,
2082,
624,
272,
340,
4298,
14,
2253,
342,
508,
298,
31065,
582,
267,
372,
747,
14,
515,
14,
12131,
20793,
15,
7424,
15,
5039,
12502,
15,
4734,
9061,
13589,
272,
916,
4298,
14,
2253,
342,
508,
298,
8647,
582,
267,
372,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
298,
4734,
9061,
531,
272,
372,
747,
14,
515,
14,
12131,
20793,
8083,
22816,
531,
199,
199,
318,
1586,
63,
22816,
63,
888,
8,
697,
694,
304,
272,
408,
3284,
314,
27214,
14,
2190,
570,
687,
1592,
694,
12,
2529,
2600,
402,
2202,
624,
272,
687,
14196,
492,
14969,
15218,
339,
1021,
7777,
4933,
11664,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
4090,
304,
288,
291,
14,
3997,
275,
4090,
288,
291,
14,
261,
595,
350,
275,
6730,
452,
7272,
78,
7,
267,
347,
14441,
8,
277,
304,
288,
340,
291,
14,
261,
595,
350,
26,
355,
862,
26,
372,
291,
14,
261,
595,
350,
355,
3753,
26,
291,
14,
261,
595,
350,
275,
488,
288,
587,
26,
355,
308,
275,
291,
14,
3997,
14,
6407,
342,
355,
340,
308,
14,
1623,
7863,
358,
1137,
446,
17,
26,
490,
308,
275,
308,
59,
16,
26,
83,
14,
1623,
7863,
358,
1055,
1913,
342,
435,
3212,
78,
2,
355,
372,
308,
339,
1101,
63,
2087,
275,
14969,
15218,
342,
272,
1101,
63,
2087,
14,
739,
3997,
8,
8249,
4933,
11664,
8,
1490,
8,
736,
14,
515,
14,
904,
8,
697,
694,
12,
298,
22816,
14,
2190,
2237,
430,
272,
372,
1211,
8,
888,
63,
2087,
14,
1744,
480,
452,
2237,
199,
199,
318,
4907,
63,
6243,
8,
888,
304,
272,
408,
8631,
370,
282,
27214,
4840,
13,
8171,
1654,
624,
272,
511,
846,
275,
1101,
14,
362,
360,
396,
846,
297,
283,
16,
358,
272,
511,
846,
275,
334,
442,
8,
396,
846,
9,
690,
378,
9,
221,
327,
378,
15,
17,
315,
1101,
570,
12,
3957,
370,
715,
15,
797,
272,
340,
440,
283,
4354,
719,
7,
315,
1101,
26,
267,
1101,
459,
4354,
719,
418,
275,
413,
3129,
708,
340,
511,
846,
587,
1749,
9526,
272,
4907,
275,
298,
1014,
13827,
83,
2689,
83,
32,
4195,
14,
16,
14,
16,
14,
17,
2689,
83,
14007,
888,
459,
4354,
751,
995,
1101,
459,
4354,
2060,
995,
1101,
459,
4354,
719,
1105,
272,
862,
26,
267,
754,
275,
7591,
4936,
8,
2242,
9,
267,
327,
7591,
4936,
365,
9617,
13,
2242,
12,
880,
3222,
376,
11785,
1414,
19762,
370,
8579,
1950,
2552,
12,
267,
327,
1325,
2597,
1852,
3238,
314,
27902,
781,
3984,
22811,
316,
370,
365,
15,
374,
78,
1133,
511,
846,
26,
267,
340,
754,
14,
362,
827,
316,
815,
12047,
396,
846,
418,
1137,
511,
846,
26,
288,
984,
14,
3083,
14,
952,
480,
8171,
1654,
737,
7210,
2242,
5207,
511,
846,
4260,
15015,
60,
78,
531,
288,
984,
14,
2224,
8,
17,
9,
267,
372,
754,
272,
871,
26,
267,
984,
14,
3083,
14,
952,
480,
547,
18170,
370,
11785,
1654,
737,
7210,
2242,
25789,
78,
531,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
28451,
63,
13892,
8,
32239,
304,
272,
2256,
275,
27902,
14,
32286,
342,
272,
340,
283,
32489,
63,
8111,
7,
440,
315,
2256,
26,
267,
372,
715,
327,
20534,
365,
440,
14862,
272,
307,
275,
1109,
8,
815,
459,
32489,
63,
8111,
1105,
272,
340,
307,
2695,
900,
14,
521,
837,
267,
862,
26,
288,
22432,
275,
18354,
14,
27481,
480,
55,
9478,
365,
14233,
27,
9509,
22432,
26,
6099,
288,
27902,
14,
87,
4598,
32376,
10906,
8,
25173,
12,
959,
9,
267,
871,
26,
288,
984,
14,
3083,
14,
952,
480,
14858,
22432,
60,
78,
531,
339,
2256,
275,
27902,
14,
32286,
342,
272,
372,
1109,
8,
815,
459,
32489,
63,
8111,
1105,
690,
900,
14,
521,
342,
199,
199,
318,
769,
63,
4561,
8,
32239,
304,
272,
2287,
63,
4705,
275,
1211,
342,
339,
2287,
63,
475,
63,
2048,
275,
1211,
342,
272,
367,
2256,
315,
27902,
14,
513,
30404,
1562,
8,
16,
304,
267,
2287,
63,
475,
63,
2048,
59,
815,
905,
1562,
15261,
275,
2256,
905,
2048,
937,
339,
625,
19435,
275,
27902,
14,
513,
324,
19435,
8,
16,
9,
272,
367,
1072,
315,
625,
19435,
26,
267,
327,
769,
324,
19435,
3181,
1133,
8120,
7149,
12,
880,
26,
267,
3066,
2347,
275,
27902,
14,
362,
16900,
8,
1199,
459,
14113,
995,
413,
9,
267,
373,
548,
275,
3066,
2347,
905,
17853,
9210,
1199,
459,
17853,
6538,
267,
3803,
275,
373,
548,
905,
1579,
29632,
937
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
3645,
314,
3066,
15809,
3261,
370,
26387,
4546,
331,
3617,
3086,
641,
6770,
7149,
12,
199,
3,
436,
3222,
1263,
1570,
1771,
370,
626,
2011,
2287,
14,
199,
3,
199,
3,
5679,
4503,
26,
199,
3,
221,
26387,
504,
14,
647,
221,
327,
31289,
2808,
27440,
83,
199,
3,
221,
26387,
504,
14,
647,
1553,
504,
29,
12368,
1553,
475,
29,
12368,
1553,
4606,
29,
845,
14,
383,
199,
3,
199,
3,
30451,
652,
911,
22811,
370,
282,
27902,
503,
21158,
13,
4238,
3879,
199,
3,
641,
11667,
14,
199,
3,
199,
3,
21588,
3198,
641,
2022,
4354,
199,
3,
199,
199,
504,
6107,
492,
627,
199,
646,
18354,
199,
646,
3473,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
4298,
199,
646,
984,
199,
646,
900,
199,
504,
2022,
4354,
492,
7591,
4936,
12,
2022,
199,
199,
5825,
63,
5100,
37,
29,
6745,
480,
16,
14,
4587,
531,
199,
199,
318,
1104,
63,
1001,
63,
6833,
837,
272,
408,
5483,
3238,
2022,
3555,
3769,
1202,
1630,
440,
27332,
7151,
13806,
699,
5708,
1338,
624,
272,
302,
275,
6345,
480,
18,
9084,
14,
9084,
19,
531,
272,
308,
11318,
609,
374,
275,
1109,
8,
1001,
14,
3640,
8,
1001,
14,
4180,
8,
1609,
8,
78,
1724,
10,
17,
14,
16,
69,
24,
9,
272,
340,
308,
11318,
609,
374,
1137,
499,
17994,
19,
26,
267,
746,
6064,
480,
6243,
3752,
15,
2708,
560,
874,
7151,
531,
199,
199,
318,
6705,
63,
697,
63,
694,
837,
272,
408,
1767,
314,
849,
2909,
402,
314,
27214,
666,
2082,
624,
272,
340,
4298,
14,
2253,
342,
508,
298,
31065,
582,
267,
372,
747,
14,
515,
14,
12131,
20793,
15,
7424,
15,
5039,
12502,
15,
4734,
9061,
13589,
272,
916,
4298,
14,
2253,
342,
508,
298,
8647,
582,
267,
372,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
298,
4734,
9061,
531,
272,
372,
747,
14,
515,
14,
12131,
20793,
8083,
22816,
531,
199,
199,
318,
1586,
63,
22816,
63,
888,
8,
697,
694,
304,
272,
408,
3284,
314,
27214,
14,
2190,
570,
687,
1592,
694,
12,
2529,
2600,
402,
2202,
624,
272,
687,
14196,
492,
14969,
15218,
339,
1021,
7777,
4933,
11664,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
4090,
304,
288,
291,
14,
3997,
275,
4090,
288,
291,
14,
261,
595,
350,
275,
6730,
452,
7272,
78,
7,
267,
347,
14441,
8,
277,
304,
288,
340,
291,
14,
261,
595,
350,
26,
355,
862,
26,
372,
291,
14,
261,
595,
350,
355,
3753,
26,
291,
14,
261,
595,
350,
275,
488,
288,
587,
26,
355,
308,
275,
291,
14,
3997,
14,
6407,
342,
355,
340,
308,
14,
1623,
7863,
358,
1137,
446,
17,
26,
490,
308,
275,
308,
59,
16,
26,
83,
14,
1623,
7863,
358,
1055,
1913,
342,
435,
3212,
78,
2,
355,
372,
308,
339,
1101,
63,
2087,
275,
14969,
15218,
342,
272,
1101,
63,
2087,
14,
739,
3997,
8,
8249,
4933,
11664,
8,
1490,
8,
736,
14,
515,
14,
904,
8,
697,
694,
12,
298,
22816,
14,
2190,
2237,
430,
272,
372,
1211,
8,
888,
63,
2087,
14,
1744,
480,
452,
2237,
199,
199,
318,
4907,
63,
6243,
8,
888,
304,
272,
408,
8631,
370,
282,
27214,
4840,
13,
8171,
1654,
624,
272,
511,
846,
275,
1101,
14,
362,
360,
396,
846,
297,
283,
16,
358,
272,
511,
846,
275,
334,
442,
8,
396,
846,
9,
690,
378,
9,
221,
327,
378,
15,
17,
315,
1101,
570,
12,
3957,
370,
715,
15,
797,
272,
340,
440,
283,
4354,
719,
7,
315,
1101,
26,
267,
1101,
459,
4354,
719,
418,
275,
413,
3129,
708,
340,
511,
846,
587,
1749,
9526,
272,
4907,
275,
298,
1014,
13827,
83,
2689,
83,
32,
4195,
14,
16,
14,
16,
14,
17,
2689,
83,
14007,
888,
459,
4354,
751,
995,
1101,
459,
4354,
2060,
995,
1101,
459,
4354,
719,
1105,
272,
862,
26,
267,
754,
275,
7591,
4936,
8,
2242,
9,
267,
327,
7591,
4936,
365,
9617,
13,
2242,
12,
880,
3222,
376,
11785,
1414,
19762,
370,
8579,
1950,
2552,
12,
267,
327,
1325,
2597,
1852,
3238,
314,
27902,
781,
3984,
22811,
316,
370,
365,
15,
374,
78,
1133,
511,
846,
26,
267,
340,
754,
14,
362,
827,
316,
815,
12047,
396,
846,
418,
1137,
511,
846,
26,
288,
984,
14,
3083,
14,
952,
480,
8171,
1654,
737,
7210,
2242,
5207,
511,
846,
4260,
15015,
60,
78,
531,
288,
984,
14,
2224,
8,
17,
9,
267,
372,
754,
272,
871,
26,
267,
984,
14,
3083,
14,
952,
480,
547,
18170,
370,
11785,
1654,
737,
7210,
2242,
25789,
78,
531,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
28451,
63,
13892,
8,
32239,
304,
272,
2256,
275,
27902,
14,
32286,
342,
272,
340,
283,
32489,
63,
8111,
7,
440,
315,
2256,
26,
267,
372,
715,
327,
20534,
365,
440,
14862,
272,
307,
275,
1109,
8,
815,
459,
32489,
63,
8111,
1105,
272,
340,
307,
2695,
900,
14,
521,
837,
267,
862,
26,
288,
22432,
275,
18354,
14,
27481,
480,
55,
9478,
365,
14233,
27,
9509,
22432,
26,
6099,
288,
27902,
14,
87,
4598,
32376,
10906,
8,
25173,
12,
959,
9,
267,
871,
26,
288,
984,
14,
3083,
14,
952,
480,
14858,
22432,
60,
78,
531,
339,
2256,
275,
27902,
14,
32286,
342,
272,
372,
1109,
8,
815,
459,
32489,
63,
8111,
1105,
690,
900,
14,
521,
342,
199,
199,
318,
769,
63,
4561,
8,
32239,
304,
272,
2287,
63,
4705,
275,
1211,
342,
339,
2287,
63,
475,
63,
2048,
275,
1211,
342,
272,
367,
2256,
315,
27902,
14,
513,
30404,
1562,
8,
16,
304,
267,
2287,
63,
475,
63,
2048,
59,
815,
905,
1562,
15261,
275,
2256,
905,
2048,
937,
339,
625,
19435,
275,
27902,
14,
513,
324,
19435,
8,
16,
9,
272,
367,
1072,
315,
625,
19435,
26,
267,
327,
769,
324,
19435,
3181,
1133,
8120,
7149,
12,
880,
26,
267,
3066,
2347,
275,
27902,
14,
362,
16900,
8,
1199,
459,
14113,
995,
413,
9,
267,
373,
548,
275,
3066,
2347,
905,
17853,
9210,
1199,
459,
17853,
6538,
267,
3803,
275,
373,
548,
905,
1579,
29632,
937,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
battlemidget/juju-charm-dokuwiki
|
reactive/dokuwiki.py
|
1
|
2221
|
from charms.reactive import (
hook,
when,
only_once,
is_state
)
import os.path as path
from charmhelpers.core import hookenv
from charmhelpers.core.host import service_restart
from charmhelpers.core.templating import render
from subprocess import call
from charms.layer import nginx, dokuwiki, php
config = hookenv.config()
# HOOKS -----------------------------------------------------------------------
@hook('config-changed')
def config_changed():
if not is_state('nginx.available'):
return
# Define user
app_path = nginx.get_app_path()
render(source='users.auth.php',
target=path.join(app_path, 'conf/users.auth.php'),
context=config, perms=0o664)
call('chown www-data:www-data -R {}'.format(app_path), shell=True)
call('chmod 775 -R {}/conf'.format(app_path), shell=True)
call('mkdir -p {app_path}/data && chmod 775 -R {app_path}/data'.format(
app_path=app_path), shell=True)
php.restart()
service_restart('nginx')
hookenv.status_set('active', 'Ready')
# REACTORS --------------------------------------------------------------------
@when('nginx.available')
@when('php.ready')
@only_once
def install_app():
""" Performs application installation
"""
hookenv.log('Installing Dokuwiki', 'info')
# Configure NGINX vhost
nginx.configure_site('default', 'vhost.conf',
listen_address=php.socket())
# Update application
dokuwiki.download_archive()
# Needs to set dokuwiki directory permissions for installation
app_path = nginx.get_app_path()
render(source='local.php',
target=path.join(app_path, 'conf/local.php'),
context=config, perms=0o644)
render(source='acl.auth.php',
target=path.join(app_path, 'conf/acl.auth.php'),
context=config, perms=0o644)
render(source='plugins.local.php',
target=path.join(app_path, 'conf/plugins.local.php'),
context=config, perms=0o644)
# Clean up install.php as we don't need it
call("rm -f {}/conf/install.php", shell=True)
php.restart()
service_restart('nginx')
hookenv.status_set('active', 'Dokuwiki is installed!')
|
mit
|
[
504,
1495,
706,
14,
264,
2682,
492,
334,
272,
5759,
12,
272,
1380,
12,
272,
1454,
63,
5089,
12,
272,
365,
63,
929,
199,
9,
199,
199,
646,
747,
14,
515,
465,
931,
199,
504,
1495,
77,
7546,
14,
1018,
492,
21404,
199,
504,
1495,
77,
7546,
14,
1018,
14,
1102,
492,
2435,
63,
10506,
199,
504,
1495,
77,
7546,
14,
1018,
14,
808,
24615,
492,
3795,
199,
504,
3873,
492,
1240,
199,
504,
1495,
706,
14,
1897,
492,
302,
19101,
12,
366,
745,
85,
6797,
12,
3945,
80,
199,
199,
888,
275,
21404,
14,
888,
342,
421,
199,
3,
7781,
3593,
51,
5620,
12797,
199,
32,
3664,
360,
888,
13,
2489,
358,
199,
318,
1101,
63,
2489,
837,
339,
340,
440,
365,
63,
929,
360,
25826,
14,
4561,
735,
267,
372,
339,
327,
13930,
922,
272,
1145,
63,
515,
275,
302,
19101,
14,
362,
63,
571,
63,
515,
342,
272,
3795,
8,
1365,
534,
3707,
14,
1178,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
3707,
14,
1178,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
28169,
9,
272,
1240,
360,
20933,
20732,
13,
576,
26,
1544,
13,
576,
446,
50,
9499,
908,
8,
571,
63,
515,
395,
5218,
29,
549,
9,
272,
1240,
360,
11693,
8375,
21,
446,
50,
1052,
15,
2190,
1370,
908,
8,
571,
63,
515,
395,
5218,
29,
549,
9,
272,
1240,
360,
8215,
446,
80,
469,
571,
63,
515,
5995,
576,
10883,
30106,
8375,
21,
446,
50,
469,
571,
63,
515,
5995,
576,
1370,
908,
8,
267,
1145,
63,
515,
29,
571,
63,
515,
395,
5218,
29,
549,
9,
339,
3945,
80,
14,
10506,
342,
272,
2435,
63,
10506,
360,
25826,
358,
272,
21404,
14,
1205,
63,
409,
360,
2682,
297,
283,
17960,
358,
421,
199,
3,
5363,
3036,
4149,
23567,
199,
32,
6526,
360,
25826,
14,
4561,
358,
199,
32,
6526,
360,
8624,
14,
2179,
358,
199,
32,
2118,
63,
5089,
199,
318,
3907,
63,
571,
837,
272,
408,
29822,
4223,
12096,
272,
408,
339,
21404,
14,
793,
360,
31376,
577,
745,
85,
6797,
297,
283,
815,
358,
339,
327,
15453,
653,
39,
568,
56,
373,
1102,
272,
302,
19101,
14,
6472,
63,
2124,
360,
885,
297,
283,
32071,
14,
2190,
297,
586,
6938,
63,
1562,
29,
8624,
14,
3450,
1012,
339,
327,
6162,
4223,
272,
366,
745,
85,
6797,
14,
4249,
63,
6404,
342,
339,
327,
29613,
370,
663,
366,
745,
85,
6797,
2082,
3443,
367,
12096,
272,
1145,
63,
515,
275,
302,
19101,
14,
362,
63,
571,
63,
515,
342,
339,
3795,
8,
1365,
534,
1832,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
1832,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
10893,
9,
339,
3795,
8,
1365,
534,
5853,
14,
1178,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
5853,
14,
1178,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
10893,
9,
339,
3795,
8,
1365,
534,
5265,
14,
1832,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
5265,
14,
1832,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
10893,
9,
339,
327,
12762,
1536,
3907,
14,
8624,
465,
781,
2793,
1133,
1929,
652,
272,
1240,
480,
5682,
446,
70,
1052,
15,
2190,
15,
3174,
14,
8624,
401,
5218,
29,
549,
9,
339,
3945,
80,
14,
10506,
342,
272,
2435,
63,
10506,
360,
25826,
358,
272,
21404,
14,
1205,
63,
409,
360,
2682,
297,
283,
36,
745,
85,
6797,
365,
4903,
10916,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1495,
706,
14,
264,
2682,
492,
334,
272,
5759,
12,
272,
1380,
12,
272,
1454,
63,
5089,
12,
272,
365,
63,
929,
199,
9,
199,
199,
646,
747,
14,
515,
465,
931,
199,
504,
1495,
77,
7546,
14,
1018,
492,
21404,
199,
504,
1495,
77,
7546,
14,
1018,
14,
1102,
492,
2435,
63,
10506,
199,
504,
1495,
77,
7546,
14,
1018,
14,
808,
24615,
492,
3795,
199,
504,
3873,
492,
1240,
199,
504,
1495,
706,
14,
1897,
492,
302,
19101,
12,
366,
745,
85,
6797,
12,
3945,
80,
199,
199,
888,
275,
21404,
14,
888,
342,
421,
199,
3,
7781,
3593,
51,
5620,
12797,
199,
32,
3664,
360,
888,
13,
2489,
358,
199,
318,
1101,
63,
2489,
837,
339,
340,
440,
365,
63,
929,
360,
25826,
14,
4561,
735,
267,
372,
339,
327,
13930,
922,
272,
1145,
63,
515,
275,
302,
19101,
14,
362,
63,
571,
63,
515,
342,
272,
3795,
8,
1365,
534,
3707,
14,
1178,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
3707,
14,
1178,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
28169,
9,
272,
1240,
360,
20933,
20732,
13,
576,
26,
1544,
13,
576,
446,
50,
9499,
908,
8,
571,
63,
515,
395,
5218,
29,
549,
9,
272,
1240,
360,
11693,
8375,
21,
446,
50,
1052,
15,
2190,
1370,
908,
8,
571,
63,
515,
395,
5218,
29,
549,
9,
272,
1240,
360,
8215,
446,
80,
469,
571,
63,
515,
5995,
576,
10883,
30106,
8375,
21,
446,
50,
469,
571,
63,
515,
5995,
576,
1370,
908,
8,
267,
1145,
63,
515,
29,
571,
63,
515,
395,
5218,
29,
549,
9,
339,
3945,
80,
14,
10506,
342,
272,
2435,
63,
10506,
360,
25826,
358,
272,
21404,
14,
1205,
63,
409,
360,
2682,
297,
283,
17960,
358,
421,
199,
3,
5363,
3036,
4149,
23567,
199,
32,
6526,
360,
25826,
14,
4561,
358,
199,
32,
6526,
360,
8624,
14,
2179,
358,
199,
32,
2118,
63,
5089,
199,
318,
3907,
63,
571,
837,
272,
408,
29822,
4223,
12096,
272,
408,
339,
21404,
14,
793,
360,
31376,
577,
745,
85,
6797,
297,
283,
815,
358,
339,
327,
15453,
653,
39,
568,
56,
373,
1102,
272,
302,
19101,
14,
6472,
63,
2124,
360,
885,
297,
283,
32071,
14,
2190,
297,
586,
6938,
63,
1562,
29,
8624,
14,
3450,
1012,
339,
327,
6162,
4223,
272,
366,
745,
85,
6797,
14,
4249,
63,
6404,
342,
339,
327,
29613,
370,
663,
366,
745,
85,
6797,
2082,
3443,
367,
12096,
272,
1145,
63,
515,
275,
302,
19101,
14,
362,
63,
571,
63,
515,
342,
339,
3795,
8,
1365,
534,
1832,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
1832,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
10893,
9,
339,
3795,
8,
1365,
534,
5853,
14,
1178,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
5853,
14,
1178,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
10893,
9,
339,
3795,
8,
1365,
534,
5265,
14,
1832,
14,
8624,
297,
1779,
1347,
29,
515,
14,
904,
8,
571,
63,
515,
12,
283,
2190,
15,
5265,
14,
1832,
14,
8624,
659,
1779,
1067,
29,
888,
12,
17340,
29,
16,
79,
10893,
9,
339,
327,
12762,
1536,
3907,
14,
8624,
465,
781,
2793,
1133,
1929,
652,
272,
1240,
480,
5682,
446,
70,
1052,
15,
2190,
15,
3174,
14,
8624,
401,
5218,
29,
549,
9,
339,
3945,
80,
14,
10506,
342,
272,
2435,
63,
10506,
360,
25826,
358,
272,
21404,
14,
1205,
63,
409,
360,
2682,
297,
283,
36,
745,
85,
6797,
365,
4903,
10916,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
4doemaster/openembedded
|
contrib/armmon_xfer/armmon_xfer.py
|
45
|
3966
|
#!/usr/bin/python
# Small utility to upload kernel and/or ramdisk to
# the compulab board through the ARMmon firmware.
# Requires pyserial : http://pyserial.sourceforge.net
# author: Tobias Pflug
import sys, os, serial, getopt, atexit, re
# regular expression to match valid IPv4 addresses
ipv4_regex = r"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
def wait_flash_complete():
while 1:
data = s.readline()
if quiet != 1:
print data,
if data.split(" ")[0] == "Finished":
break
def test_armmon():
# write some nonsense to the monitor and
# check if armmon replies accordingly
s.write("nonsense\n")
s.timeout=2
s.read(len("nonsense\n")+1)
data = s.read(len("Illegal"))
if data.split(" ")[0] != "Illegal":
sys.exit("Error: ARMmon not responding. Linux running maybe?")
s.timeout=None
s.flushInput()
s.flushOutput()
def usage():
sys.stderr.write("""USAGE: %s [options] <server ip>
armmon_xfer - data upload tool for cmx270/ARMmon
options:
-p, --port=PORT: serial port, default='/dev/ttyUSB0'
-k, --kernel=KERNEL: upload and flash kernel image KERNEL
-r, --ramdisk=RAMDISK: upload and flash ramdisk image RAMDISK
-b, --bootos: boot Linux
-R, --reboot: reboot cmx270
-q, --quiet be quiet, little output
-h, --help: print this help screen
""" % (sys.argv[0],))
if __name__ == '__main__':
port = "/dev/ttyUSB0"
baud = 38400
kernel = None
ramdisk = None
boot = None
reboot = None
quiet = None
tftp_ip = None
if len(sys.argv) < 2:
usage()
sys.exit(0)
# parse command line
try:
opts, args = getopt.getopt(sys.argv[1:],
"p:k:r:bRhq",
["port=", "kernel=","ramdisk=","bootos","reboot","help","quiet"]
)
except getopt.GetoptError:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-h","--help"):
usage()
sys.exit()
elif o in ("-k","--kernel"):
kernel = a
elif o in ("-r","--ramdisk"):
ramdisk = a
elif o in ("-b","--bootos"):
boot = 1
elif o in ("-R","--reboot"):
reboot = 1
elif o in ("-p","--port"):
port = o
elif o in ("-q","--quiet"):
quiet = 1
# check for arguments and validate IP address
# when required by commands
if len(args)>0 and re.match(ipv4_regex,args[0]):
tftp_ip = args[0]
else:
if kernel or ramdisk:
sys.exit("Error: invalid IP address!")
try:
s = serial.Serial('/dev/ttyUSB0',38400)
except:
sys.stderr.write("Error: Could not open port: %s\n" % (port))
sys.exit(1)
# test if armmon is responding on bogus input
test_armmon()
# carry out commands
if reboot:
print "Rebooting compulab ..."
s.write("reboot\n")
s.write("y\n")
s.write("y\n")
s.close()
sys.exit(0)
if kernel:
print "Downloading kernel ..."
cmd = "download kernel tftp %s %s\n" % (kernel,tftp_ip)
s.write(cmd)
data = s.readline()
data = s.readline()
print "Flashing kernel ..."
cmd = "flash kernel\n"
s.write(cmd)
wait_flash_complete()
if ramdisk:
print "Downloading ramdisk ..."
cmd = "download ramdisk tftp %s %s\n" % (ramdisk,tftp_ip)
s.write(cmd)
s.readline()
s.readline()
print "Flashing ramdisk ..."
cmd = "flash ramdisk\n"
s.write(cmd)
wait_flash_complete()
if boot:
print "Booting Linux ..."
s.write("bootos\n")
s.close()
sys.exit(0)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
23704,
11420,
370,
5802,
5114,
436,
15,
269,
21394,
4032,
370,
199,
3,
314,
1013,
348,
371,
13811,
4012,
314,
27155,
2106,
27969,
14,
199,
3,
15127,
1134,
2171,
520,
1455,
921,
647,
2171,
14,
22943,
14,
846,
199,
3,
4132,
26,
377,
2873,
2241,
510,
2327,
1518,
199,
199,
646,
984,
12,
747,
12,
3012,
12,
12733,
12,
19840,
12,
295,
199,
199,
3,
5578,
3965,
370,
1336,
1686,
6509,
20,
7149,
199,
4774,
20,
63,
3821,
275,
519,
3212,
66,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
31477,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
31477,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
31477,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
2862,
66,
2,
199,
199,
318,
3618,
63,
11331,
63,
4883,
837,
272,
1830,
413,
26,
267,
666,
275,
308,
14,
6407,
342,
267,
340,
11971,
1137,
413,
26,
288,
870,
666,
12,
267,
340,
666,
14,
1294,
480,
298,
2788,
16,
61,
508,
298,
13430,
582,
288,
2059,
199,
199,
318,
511,
63,
285,
596,
265,
837,
272,
327,
2218,
2005,
2222,
16517,
370,
314,
8372,
436,
272,
327,
1104,
340,
601,
596,
265,
1833,
6528,
24137,
272,
308,
14,
952,
480,
2865,
16517,
60,
78,
531,
272,
308,
14,
2593,
29,
18,
272,
308,
14,
739,
8,
552,
480,
2865,
16517,
60,
78,
531,
11,
17,
9,
272,
666,
275,
308,
14,
739,
8,
552,
480,
25501,
2237,
272,
340,
666,
14,
1294,
480,
298,
2788,
16,
61,
1137,
298,
25501,
582,
267,
984,
14,
2224,
480,
547,
26,
27155,
2106,
440,
9163,
1098,
14,
10130,
3879,
11703,
18582,
272,
308,
14,
2593,
29,
403,
272,
308,
14,
4939,
3205,
342,
272,
308,
14,
4939,
2959,
342,
421,
199,
318,
4503,
837,
272,
984,
14,
3083,
14,
952,
4852,
20274,
26,
450,
83,
359,
1419,
61,
665,
1000,
3384,
30,
272,
601,
596,
265,
63,
1949,
281,
446,
666,
5802,
4744,
367,
6904,
88,
13299,
15,
12482,
2106,
339,
1511,
26,
272,
446,
80,
12,
1553,
719,
29,
3657,
26,
263,
3012,
1844,
12,
849,
8805,
2374,
15,
4707,
19919,
16,
7,
272,
446,
75,
12,
1553,
4989,
29,
30142,
26,
259,
5802,
436,
14775,
5114,
1834,
1804,
540,
11301,
272,
446,
82,
12,
1553,
26541,
29,
30839,
20492,
26,
221,
5802,
436,
14775,
21394,
4032,
1834,
30207,
20492,
272,
446,
66,
12,
1553,
4930,
736,
26,
3698,
8498,
10130,
272,
446,
50,
12,
1553,
15051,
26,
3698,
19457,
6904,
88,
13299,
272,
446,
81,
12,
1553,
10243,
3777,
506,
11971,
12,
12050,
1072,
272,
446,
72,
12,
1553,
3437,
26,
3777,
870,
642,
1720,
6426,
199,
199,
624,
450,
334,
1274,
14,
3020,
59,
16,
467,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
1844,
275,
3286,
2374,
15,
4707,
19919,
16,
2,
272,
19325,
1181,
275,
29772,
383,
272,
5114,
275,
488,
272,
21394,
4032,
275,
488,
272,
8498,
275,
488,
272,
19457,
275,
488,
272,
11971,
275,
488,
272,
2833,
683,
63,
711,
275,
488,
339,
340,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
339,
327,
2198,
1414,
1004,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
355,
298,
80,
26,
75,
26,
82,
26,
66,
50,
21550,
401,
355,
2097,
719,
11107,
298,
4989,
29,
2266,
26541,
29,
2266,
4930,
736,
2266,
15051,
2266,
3437,
2266,
10243,
937,
355,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
18,
9,
339,
367,
312,
12,
282,
315,
3999,
26,
267,
340,
312,
315,
19372,
72,
2266,
306,
3437,
2349,
288,
4503,
342,
288,
984,
14,
2224,
342,
267,
916,
312,
315,
19372,
75,
2266,
306,
4989,
2349,
288,
5114,
275,
282,
267,
916,
312,
315,
19372,
82,
2266,
306,
26541,
2349,
288,
21394,
4032,
275,
282,
267,
916,
312,
315,
19372,
66,
2266,
306,
4930,
736,
2349,
288,
8498,
275,
413,
267,
916,
312,
315,
19372,
50,
2266,
306,
15051,
2349,
288,
19457,
275,
413,
267,
916,
312,
315,
19372,
80,
2266,
306,
719,
2349,
288,
1844,
275,
312,
267,
916,
312,
315,
19372,
81,
2266,
306,
10243,
2349,
288,
11971,
275,
413,
339,
327,
1104,
367,
2368,
436,
4107,
3531,
2287,
272,
327,
1380,
1415,
701,
3718,
272,
340,
822,
8,
589,
13032,
16,
436,
295,
14,
1431,
8,
4774,
20,
63,
3821,
12,
589,
59,
16,
4682,
267,
2833,
683,
63,
711,
275,
1249,
59,
16,
61,
272,
587,
26,
4960,
340,
5114,
503,
21394,
4032,
26,
288,
984,
14,
2224,
480,
547,
26,
3866,
3531,
2287,
9124,
339,
862,
26,
268,
308,
275,
3012,
14,
3571,
2336,
2374,
15,
4707,
19919,
16,
297,
8188,
383,
9,
272,
871,
26,
268,
984,
14,
3083,
14,
952,
480,
547,
26,
18615,
440,
1551,
1844,
26,
450,
83,
60,
78,
2,
450,
334,
719,
430,
268,
984,
14,
2224,
8,
17,
9,
339,
327,
511,
340,
601,
596,
265,
365,
9163,
1098,
641,
23703,
1324,
272,
511,
63,
285,
596,
265,
342,
339,
327,
25176,
734,
3718,
420,
339,
340,
19457,
26,
267,
870,
298,
497,
4930,
316,
1013,
348,
371,
21742,
267,
308,
14,
952,
480,
15051,
60,
78,
531,
267,
308,
14,
952,
480,
89,
60,
78,
531,
267,
308,
14,
952,
480,
89,
60,
78,
531,
267,
308,
14,
1600,
342,
267,
984,
14,
2224,
8,
16,
9,
339,
340,
5114,
26,
267,
870,
298,
18085,
5114,
21742,
267,
2088,
275,
298,
4249,
5114,
2833,
683,
450,
83,
450,
83,
60,
78,
2,
450,
334,
4989,
12,
3249,
683,
63,
711
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
23704,
11420,
370,
5802,
5114,
436,
15,
269,
21394,
4032,
370,
199,
3,
314,
1013,
348,
371,
13811,
4012,
314,
27155,
2106,
27969,
14,
199,
3,
15127,
1134,
2171,
520,
1455,
921,
647,
2171,
14,
22943,
14,
846,
199,
3,
4132,
26,
377,
2873,
2241,
510,
2327,
1518,
199,
199,
646,
984,
12,
747,
12,
3012,
12,
12733,
12,
19840,
12,
295,
199,
199,
3,
5578,
3965,
370,
1336,
1686,
6509,
20,
7149,
199,
4774,
20,
63,
3821,
275,
519,
3212,
66,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
31477,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
31477,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
31477,
8,
821,
59,
16,
13,
21,
11752,
18,
59,
16,
13,
20,
1527,
16,
13,
25,
32673,
614,
21852,
16,
13,
25,
1527,
16,
13,
25,
11843,
2862,
66,
2,
199,
199,
318,
3618,
63,
11331,
63,
4883,
837,
272,
1830,
413,
26,
267,
666,
275,
308,
14,
6407,
342,
267,
340,
11971,
1137,
413,
26,
288,
870,
666,
12,
267,
340,
666,
14,
1294,
480,
298,
2788,
16,
61,
508,
298,
13430,
582,
288,
2059,
199,
199,
318,
511,
63,
285,
596,
265,
837,
272,
327,
2218,
2005,
2222,
16517,
370,
314,
8372,
436,
272,
327,
1104,
340,
601,
596,
265,
1833,
6528,
24137,
272,
308,
14,
952,
480,
2865,
16517,
60,
78,
531,
272,
308,
14,
2593,
29,
18,
272,
308,
14,
739,
8,
552,
480,
2865,
16517,
60,
78,
531,
11,
17,
9,
272,
666,
275,
308,
14,
739,
8,
552,
480,
25501,
2237,
272,
340,
666,
14,
1294,
480,
298,
2788,
16,
61,
1137,
298,
25501,
582,
267,
984,
14,
2224,
480,
547,
26,
27155,
2106,
440,
9163,
1098,
14,
10130,
3879,
11703,
18582,
272,
308,
14,
2593,
29,
403,
272,
308,
14,
4939,
3205,
342,
272,
308,
14,
4939,
2959,
342,
421,
199,
318,
4503,
837,
272,
984,
14,
3083,
14,
952,
4852,
20274,
26,
450,
83,
359,
1419,
61,
665,
1000,
3384,
30,
272,
601,
596,
265,
63,
1949,
281,
446,
666,
5802,
4744,
367,
6904,
88,
13299,
15,
12482,
2106,
339,
1511,
26,
272,
446,
80,
12,
1553,
719,
29,
3657,
26,
263,
3012,
1844,
12,
849,
8805,
2374,
15,
4707,
19919,
16,
7,
272,
446,
75,
12,
1553,
4989,
29,
30142,
26,
259,
5802,
436,
14775,
5114,
1834,
1804,
540,
11301,
272,
446,
82,
12,
1553,
26541,
29,
30839,
20492,
26,
221,
5802,
436,
14775,
21394,
4032,
1834,
30207,
20492,
272,
446,
66,
12,
1553,
4930,
736,
26,
3698,
8498,
10130,
272,
446,
50,
12,
1553,
15051,
26,
3698,
19457,
6904,
88,
13299,
272,
446,
81,
12,
1553,
10243,
3777,
506,
11971,
12,
12050,
1072,
272,
446,
72,
12,
1553,
3437,
26,
3777,
870,
642,
1720,
6426,
199,
199,
624,
450,
334,
1274,
14,
3020,
59,
16,
467,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
1844,
275,
3286,
2374,
15,
4707,
19919,
16,
2,
272,
19325,
1181,
275,
29772,
383,
272,
5114,
275,
488,
272,
21394,
4032,
275,
488,
272,
8498,
275,
488,
272,
19457,
275,
488,
272,
11971,
275,
488,
272,
2833,
683,
63,
711,
275,
488,
339,
340,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
339,
327,
2198,
1414,
1004,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
355,
298,
80,
26,
75,
26,
82,
26,
66,
50,
21550,
401,
355,
2097,
719,
11107,
298,
4989,
29,
2266,
26541,
29,
2266,
4930,
736,
2266,
15051,
2266,
3437,
2266,
10243,
937,
355,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
18,
9,
339,
367,
312,
12,
282,
315,
3999,
26,
267,
340,
312,
315,
19372,
72,
2266,
306,
3437,
2349,
288,
4503,
342,
288,
984,
14,
2224,
342,
267,
916,
312,
315,
19372,
75,
2266,
306,
4989,
2349,
288,
5114,
275,
282,
267,
916,
312,
315,
19372,
82,
2266,
306,
26541,
2349,
288,
21394,
4032,
275,
282,
267,
916,
312,
315,
19372,
66,
2266,
306,
4930,
736,
2349,
288,
8498,
275,
413,
267,
916,
312,
315,
19372,
50,
2266,
306,
15051,
2349,
288,
19457,
275,
413,
267,
916,
312,
315,
19372,
80,
2266,
306,
719,
2349,
288,
1844,
275,
312,
267,
916,
312,
315,
19372,
81,
2266,
306,
10243,
2349,
288,
11971,
275,
413,
339,
327,
1104,
367,
2368,
436,
4107,
3531,
2287,
272,
327,
1380,
1415,
701,
3718,
272,
340,
822,
8,
589,
13032,
16,
436,
295,
14,
1431,
8,
4774,
20,
63,
3821,
12,
589,
59,
16,
4682,
267,
2833,
683,
63,
711,
275,
1249,
59,
16,
61,
272,
587,
26,
4960,
340,
5114,
503,
21394,
4032,
26,
288,
984,
14,
2224,
480,
547,
26,
3866,
3531,
2287,
9124,
339,
862,
26,
268,
308,
275,
3012,
14,
3571,
2336,
2374,
15,
4707,
19919,
16,
297,
8188,
383,
9,
272,
871,
26,
268,
984,
14,
3083,
14,
952,
480,
547,
26,
18615,
440,
1551,
1844,
26,
450,
83,
60,
78,
2,
450,
334,
719,
430,
268,
984,
14,
2224,
8,
17,
9,
339,
327,
511,
340,
601,
596,
265,
365,
9163,
1098,
641,
23703,
1324,
272,
511,
63,
285,
596,
265,
342,
339,
327,
25176,
734,
3718,
420,
339,
340,
19457,
26,
267,
870,
298,
497,
4930,
316,
1013,
348,
371,
21742,
267,
308,
14,
952,
480,
15051,
60,
78,
531,
267,
308,
14,
952,
480,
89,
60,
78,
531,
267,
308,
14,
952,
480,
89,
60,
78,
531,
267,
308,
14,
1600,
342,
267,
984,
14,
2224,
8,
16,
9,
339,
340,
5114,
26,
267,
870,
298,
18085,
5114,
21742,
267,
2088,
275,
298,
4249,
5114,
2833,
683,
450,
83,
450,
83,
60,
78,
2,
450,
334,
4989,
12,
3249,
683,
63,
711,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
leighpauls/k2cro4
|
third_party/python_26/Lib/site-packages/pythonwin/pywin/Demos/ocx/demoutils.py
|
68
|
1354
|
# Utilities for the demos
import sys, win32api, win32con, win32ui
NotScriptMsg = """\
This demo program is not designed to be run as a Script, but is
probably used by some other test program. Please try another demo.
"""
NeedGUIMsg = """\
This demo program can only be run from inside of Pythonwin
You must start Pythonwin, and select 'Run' from the toolbar or File menu
"""
NeedAppMsg = """\
This demo program is a 'Pythonwin Application'.
It is more demo code than an example of Pythonwin's capabilities.
To run it, you must execute the command:
pythonwin.exe /app "%s"
Would you like to execute it now?
"""
def NotAScript():
import win32ui
win32ui.MessageBox(NotScriptMsg, "Demos")
def NeedGoodGUI():
from pywin.framework.app import HaveGoodGUI
rc = HaveGoodGUI()
if not rc:
win32ui.MessageBox(NeedGUIMsg, "Demos")
return rc
def NeedApp():
import win32ui
rc = win32ui.MessageBox(NeedAppMsg % sys.argv[0], "Demos", win32con.MB_YESNO)
if rc==win32con.IDYES:
try:
parent = win32ui.GetMainFrame().GetSafeHwnd()
win32api.ShellExecute(parent, None, 'pythonwin.exe', '/app "%s"' % sys.argv[0], None, 1)
except win32api.error, details:
win32ui.MessageBox("Error executing command - %s" % (details), "Demos")
from pywin.framework.app import HaveGoodGUI
if __name__=='__main__':
import demoutils
demoutils.NotAScript()
|
bsd-3-clause
|
[
3,
738,
17933,
367,
314,
14779,
83,
199,
199,
646,
984,
12,
4747,
708,
1246,
12,
4747,
708,
388,
12,
4747,
708,
1907,
199,
199,
1763,
5229,
6173,
275,
9638,
199,
2765,
14779,
2240,
365,
440,
19829,
370,
506,
1255,
465,
282,
14914,
12,
1325,
365,
199,
6101,
6665,
1202,
701,
2005,
1163,
511,
2240,
14,
221,
7754,
862,
4573,
14779,
14,
199,
624,
199,
199,
17809,
17188,
1469,
1226,
275,
9638,
199,
2765,
14779,
2240,
883,
1454,
506,
1255,
687,
6272,
402,
2018,
2676,
199,
199,
5556,
1471,
1343,
2018,
2676,
12,
436,
3504,
283,
2540,
7,
687,
314,
22483,
503,
3814,
6269,
199,
624,
421,
199,
17809,
2640,
6173,
275,
9638,
199,
2765,
14779,
2240,
365,
282,
283,
4718,
2676,
13515,
1370,
199,
199,
7940,
365,
1655,
14779,
1233,
2419,
376,
2893,
402,
2018,
2676,
1159,
14918,
14,
199,
199,
1378,
1255,
652,
12,
1265,
1471,
5341,
314,
1414,
26,
199,
1548,
2676,
14,
5803,
1182,
571,
2071,
83,
2,
199,
199,
55,
3857,
1265,
2839,
370,
5341,
652,
3063,
31,
199,
624,
199,
199,
318,
2832,
1179,
1669,
837,
199,
198,
646,
4747,
708,
1907,
199,
198,
2676,
708,
1907,
14,
13695,
8,
1763,
5229,
6173,
12,
298,
872,
16908,
531,
199,
199,
318,
14012,
20652,
14438,
837,
199,
198,
504,
1134,
2676,
14,
4857,
14,
571,
492,
26858,
20652,
14438,
199,
198,
1195,
275,
26858,
20652,
14438,
342,
199,
198,
692,
440,
4819,
26,
507,
198,
2676,
708,
1907,
14,
13695,
8,
17809,
17188,
1469,
1226,
12,
298,
872,
16908,
531,
199,
198,
1107,
4819,
199,
199,
318,
14012,
2640,
837,
199,
198,
646,
4747,
708,
1907,
199,
198,
1195,
275,
4747,
708,
1907,
14,
13695,
8,
17809,
2640,
6173,
450,
984,
14,
3020,
59,
16,
467,
298,
872,
16908,
401,
4747,
708,
388,
14,
4567,
63,
15641,
2826,
9,
199,
198,
692,
4819,
389,
2676,
708,
388,
14,
998,
15641,
26,
507,
198,
893,
26,
686,
198,
1708,
275,
4747,
708,
1907,
14,
1002,
6756,
3160,
1252,
1002,
11090,
24482,
977,
342,
686,
198,
2676,
708,
1246,
14,
8529,
12049,
8,
1708,
12,
488,
12,
283,
1548,
2676,
14,
5803,
297,
1994,
571,
2071,
83,
4507,
450,
984,
14,
3020,
59,
16,
467,
488,
12,
413,
9,
507,
198,
2590,
4747,
708,
1246,
14,
705,
12,
2436,
26,
686,
198,
2676,
708,
1907,
14,
13695,
480,
547,
14043,
1414,
446,
450,
83,
2,
450,
334,
5087,
395,
298,
872,
16908,
531,
421,
199,
504,
1134,
2676,
14,
4857,
14,
571,
492,
26858,
20652,
14438,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
646,
14779,
1208,
199,
198,
8768,
1208,
14,
1763,
1179,
1669,
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
] |
[
738,
17933,
367,
314,
14779,
83,
199,
199,
646,
984,
12,
4747,
708,
1246,
12,
4747,
708,
388,
12,
4747,
708,
1907,
199,
199,
1763,
5229,
6173,
275,
9638,
199,
2765,
14779,
2240,
365,
440,
19829,
370,
506,
1255,
465,
282,
14914,
12,
1325,
365,
199,
6101,
6665,
1202,
701,
2005,
1163,
511,
2240,
14,
221,
7754,
862,
4573,
14779,
14,
199,
624,
199,
199,
17809,
17188,
1469,
1226,
275,
9638,
199,
2765,
14779,
2240,
883,
1454,
506,
1255,
687,
6272,
402,
2018,
2676,
199,
199,
5556,
1471,
1343,
2018,
2676,
12,
436,
3504,
283,
2540,
7,
687,
314,
22483,
503,
3814,
6269,
199,
624,
421,
199,
17809,
2640,
6173,
275,
9638,
199,
2765,
14779,
2240,
365,
282,
283,
4718,
2676,
13515,
1370,
199,
199,
7940,
365,
1655,
14779,
1233,
2419,
376,
2893,
402,
2018,
2676,
1159,
14918,
14,
199,
199,
1378,
1255,
652,
12,
1265,
1471,
5341,
314,
1414,
26,
199,
1548,
2676,
14,
5803,
1182,
571,
2071,
83,
2,
199,
199,
55,
3857,
1265,
2839,
370,
5341,
652,
3063,
31,
199,
624,
199,
199,
318,
2832,
1179,
1669,
837,
199,
198,
646,
4747,
708,
1907,
199,
198,
2676,
708,
1907,
14,
13695,
8,
1763,
5229,
6173,
12,
298,
872,
16908,
531,
199,
199,
318,
14012,
20652,
14438,
837,
199,
198,
504,
1134,
2676,
14,
4857,
14,
571,
492,
26858,
20652,
14438,
199,
198,
1195,
275,
26858,
20652,
14438,
342,
199,
198,
692,
440,
4819,
26,
507,
198,
2676,
708,
1907,
14,
13695,
8,
17809,
17188,
1469,
1226,
12,
298,
872,
16908,
531,
199,
198,
1107,
4819,
199,
199,
318,
14012,
2640,
837,
199,
198,
646,
4747,
708,
1907,
199,
198,
1195,
275,
4747,
708,
1907,
14,
13695,
8,
17809,
2640,
6173,
450,
984,
14,
3020,
59,
16,
467,
298,
872,
16908,
401,
4747,
708,
388,
14,
4567,
63,
15641,
2826,
9,
199,
198,
692,
4819,
389,
2676,
708,
388,
14,
998,
15641,
26,
507,
198,
893,
26,
686,
198,
1708,
275,
4747,
708,
1907,
14,
1002,
6756,
3160,
1252,
1002,
11090,
24482,
977,
342,
686,
198,
2676,
708,
1246,
14,
8529,
12049,
8,
1708,
12,
488,
12,
283,
1548,
2676,
14,
5803,
297,
1994,
571,
2071,
83,
4507,
450,
984,
14,
3020,
59,
16,
467,
488,
12,
413,
9,
507,
198,
2590,
4747,
708,
1246,
14,
705,
12,
2436,
26,
686,
198,
2676,
708,
1907,
14,
13695,
480,
547,
14043,
1414,
446,
450,
83,
2,
450,
334,
5087,
395,
298,
872,
16908,
531,
421,
199,
504,
1134,
2676,
14,
4857,
14,
571,
492,
26858,
20652,
14438,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
646,
14779,
1208,
199,
198,
8768,
1208,
14,
1763,
1179,
1669,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
py-geek/City-Air
|
venv/lib/python2.7/site-packages/allauth/socialaccount/models.py
|
13
|
11749
|
from __future__ import absolute_import
from django.core.exceptions import PermissionDenied
from django.db import models
from django.contrib.auth import authenticate
from django.contrib.sites.models import Site
from django.utils.encoding import python_2_unicode_compatible
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
try:
from django.utils.encoding import force_text
except ImportError:
from django.utils.encoding import force_unicode as force_text
import allauth.app_settings
from allauth.account.models import EmailAddress
from allauth.account.utils import get_next_redirect_url, setup_user_email
from allauth.utils import (get_user_model, get_current_site,
serialize_instance, deserialize_instance)
from . import app_settings
from . import providers
from .fields import JSONField
from ..utils import get_request_param
class SocialAppManager(models.Manager):
def get_current(self, provider, request=None):
site = get_current_site(request)
return self.get(sites__id=site.id,
provider=provider)
@python_2_unicode_compatible
class SocialApp(models.Model):
objects = SocialAppManager()
provider = models.CharField(verbose_name=_('provider'),
max_length=30,
choices=providers.registry.as_choices())
name = models.CharField(verbose_name=_('name'),
max_length=40)
client_id = models.CharField(verbose_name=_('client id'),
max_length=100,
help_text=_('App ID, or consumer key'))
secret = models.CharField(verbose_name=_('secret key'),
max_length=100,
help_text=_('API secret, client secret, or'
' consumer secret'))
key = models.CharField(verbose_name=_('key'),
max_length=100,
blank=True,
help_text=_('Key'))
# Most apps can be used across multiple domains, therefore we use
# a ManyToManyField. Note that Facebook requires an app per domain
# (unless the domains share a common base name).
# blank=True allows for disabling apps without removing them
sites = models.ManyToManyField(Site, blank=True)
class Meta:
verbose_name = _('social application')
verbose_name_plural = _('social applications')
def __str__(self):
return self.name
@python_2_unicode_compatible
class SocialAccount(models.Model):
user = models.ForeignKey(allauth.app_settings.USER_MODEL)
provider = models.CharField(verbose_name=_('provider'),
max_length=30,
choices=providers.registry.as_choices())
# Just in case you're wondering if an OpenID identity URL is going
# to fit in a 'uid':
#
# Ideally, URLField(max_length=1024, unique=True) would be used
# for identity. However, MySQL has a max_length limitation of 255
# for URLField. How about models.TextField(unique=True) then?
# Well, that won't work either for MySQL due to another bug[1]. So
# the only way out would be to drop the unique constraint, or
# switch to shorter identity URLs. Opted for the latter, as [2]
# suggests that identity URLs are supposed to be short anyway, at
# least for the old spec.
#
# [1] http://code.djangoproject.com/ticket/2495.
# [2] http://openid.net/specs/openid-authentication-1_1.html#limits
uid = models.CharField(verbose_name=_('uid'), max_length=255)
last_login = models.DateTimeField(verbose_name=_('last login'),
auto_now=True)
date_joined = models.DateTimeField(verbose_name=_('date joined'),
auto_now_add=True)
extra_data = JSONField(verbose_name=_('extra data'), default='{}')
class Meta:
unique_together = ('provider', 'uid')
verbose_name = _('social account')
verbose_name_plural = _('social accounts')
def authenticate(self):
return authenticate(account=self)
def __str__(self):
return force_text(self.user)
def get_profile_url(self):
return self.get_provider_account().get_profile_url()
def get_avatar_url(self):
return self.get_provider_account().get_avatar_url()
def get_provider(self):
return providers.registry.by_id(self.provider)
def get_provider_account(self):
return self.get_provider().wrap_account(self)
@python_2_unicode_compatible
class SocialToken(models.Model):
app = models.ForeignKey(SocialApp)
account = models.ForeignKey(SocialAccount)
token = models \
.TextField(verbose_name=_('token'),
help_text=_('"oauth_token" (OAuth1) or access token'
' (OAuth2)'))
token_secret = models \
.TextField(blank=True,
verbose_name=_('token secret'),
help_text=_('"oauth_token_secret" (OAuth1) or refresh'
' token (OAuth2)'))
expires_at = models.DateTimeField(blank=True, null=True,
verbose_name=_('expires at'))
class Meta:
unique_together = ('app', 'account')
verbose_name = _('social application token')
verbose_name_plural = _('social application tokens')
def __str__(self):
return self.token
class SocialLogin(object):
"""
Represents a social user that is in the process of being logged
in. This consists of the following information:
`account` (`SocialAccount` instance): The social account being
logged in. Providers are not responsible for checking whether or
not an account already exists or not. Therefore, a provider
typically creates a new (unsaved) `SocialAccount` instance. The
`User` instance pointed to by the account (`account.user`) may be
prefilled by the provider for use as a starting point later on
during the signup process.
`token` (`SocialToken` instance): An optional access token token
that results from performing a successful authentication
handshake.
`state` (`dict`): The state to be preserved during the
authentication handshake. Note that this state may end up in the
url -- do not put any secrets in here. It currently only contains
the url to redirect to after login.
`email_addresses` (list of `EmailAddress`): Optional list of
e-mail addresses retrieved from the provider.
"""
def __init__(self, user=None, account=None, token=None,
email_addresses=[]):
if token:
assert token.account is None or token.account == account
self.token = token
self.user = user
self.account = account
self.email_addresses = email_addresses
self.state = {}
def connect(self, request, user):
self.user = user
self.save(request, connect=True)
def serialize(self):
ret = dict(account=serialize_instance(self.account),
user=serialize_instance(self.user),
state=self.state,
email_addresses=[serialize_instance(ea)
for ea in self.email_addresses])
if self.token:
ret['token'] = serialize_instance(self.token)
return ret
@classmethod
def deserialize(cls, data):
account = deserialize_instance(SocialAccount, data['account'])
user = deserialize_instance(get_user_model(), data['user'])
if 'token' in data:
token = deserialize_instance(SocialToken, data['token'])
else:
token = None
email_addresses = []
for ea in data['email_addresses']:
email_address = deserialize_instance(EmailAddress, ea)
email_addresses.append(email_address)
ret = SocialLogin()
ret.token = token
ret.account = account
ret.user = user
ret.email_addresses = email_addresses
ret.state = data['state']
return ret
def save(self, request, connect=False):
"""
Saves a new account. Note that while the account is new,
the user may be an existing one (when connecting accounts)
"""
assert not self.is_existing
user = self.user
user.save()
self.account.user = user
self.account.save()
if app_settings.STORE_TOKENS and self.token:
self.token.account = self.account
self.token.save()
if connect:
# TODO: Add any new email addresses automatically?
pass
else:
setup_user_email(request, user, self.email_addresses)
@property
def is_existing(self):
"""
Account is temporary, not yet backed by a database record.
"""
return self.account.pk
def lookup(self):
"""
Lookup existing account, if any.
"""
assert not self.is_existing
try:
a = SocialAccount.objects.get(provider=self.account.provider,
uid=self.account.uid)
# Update account
a.extra_data = self.account.extra_data
self.account = a
self.user = self.account.user
a.save()
# Update token
if app_settings.STORE_TOKENS and self.token:
assert not self.token.pk
try:
t = SocialToken.objects.get(account=self.account,
app=self.token.app)
t.token = self.token.token
if self.token.token_secret:
# only update the refresh token if we got one
# many oauth2 providers do not resend the refresh token
t.token_secret = self.token.token_secret
t.expires_at = self.token.expires_at
t.save()
self.token = t
except SocialToken.DoesNotExist:
self.token.account = a
self.token.save()
except SocialAccount.DoesNotExist:
pass
def get_redirect_url(self, request):
url = self.state.get('next')
return url
@classmethod
def state_from_request(cls, request):
state = {}
next_url = get_next_redirect_url(request)
if next_url:
state['next'] = next_url
state['process'] = get_request_param(request, 'process', 'login')
state['scope'] = get_request_param(request, 'scope', '')
state['auth_params'] = get_request_param(request, 'auth_params', '')
return state
@classmethod
def stash_state(cls, request):
state = cls.state_from_request(request)
verifier = get_random_string()
request.session['socialaccount_state'] = (state, verifier)
return verifier
@classmethod
def unstash_state(cls, request):
if 'socialaccount_state' not in request.session:
raise PermissionDenied()
state, verifier = request.session.pop('socialaccount_state')
return state
@classmethod
def verify_and_unstash_state(cls, request, verifier):
if 'socialaccount_state' not in request.session:
raise PermissionDenied()
state, verifier2 = request.session.pop('socialaccount_state')
if verifier != verifier2:
raise PermissionDenied()
return state
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
504,
1639,
14,
1208,
14,
10316,
492,
664,
63,
2355,
63,
875,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
893,
26,
272,
687,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
2590,
3545,
26,
272,
687,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2975,
465,
3542,
63,
505,
199,
199,
646,
741,
416,
762,
14,
571,
63,
1751,
199,
504,
741,
416,
762,
14,
2048,
14,
992,
492,
11426,
1476,
199,
504,
741,
416,
762,
14,
2048,
14,
1208,
492,
664,
63,
2184,
63,
4876,
63,
633,
12,
3272,
63,
751,
63,
2123,
199,
504,
741,
416,
762,
14,
1208,
492,
334,
362,
63,
751,
63,
1238,
12,
664,
63,
1818,
63,
2124,
12,
2574,
8437,
63,
842,
12,
22920,
63,
842,
9,
199,
199,
504,
1275,
492,
1145,
63,
1751,
199,
504,
1275,
492,
18032,
199,
504,
1275,
955,
492,
4840,
792,
199,
504,
2508,
1208,
492,
664,
63,
1069,
63,
635,
421,
199,
533,
2002,
7180,
2640,
2988,
8,
992,
14,
2988,
304,
272,
347,
664,
63,
1818,
8,
277,
12,
5022,
12,
1056,
29,
403,
304,
267,
4770,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
267,
372,
291,
14,
362,
8,
8619,
363,
344,
29,
2124,
14,
344,
12,
717,
5022,
29,
3780,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
2002,
7180,
2640,
8,
992,
14,
1685,
304,
272,
2251,
275,
2002,
7180,
2640,
2988,
342,
339,
5022,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
3780,
659,
1816,
1390,
63,
1267,
29,
1216,
12,
1816,
3415,
29,
9710,
14,
5189,
14,
305,
63,
4577,
1012,
272,
536,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
354,
659,
1169,
1390,
63,
1267,
29,
2167,
9,
272,
1890,
63,
344,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
1258,
1305,
659,
639,
1390,
63,
1267,
29,
1960,
12,
639,
1720,
63,
505,
12397,
2640,
2870,
12,
503,
9790,
790,
1333,
272,
7565,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
4731,
790,
659,
2892,
1390,
63,
1267,
29,
1960,
12,
2892,
1720,
63,
505,
12397,
3735,
7565,
12,
1890,
7565,
12,
503,
7,
2892,
283,
9790,
7565,
1333,
272,
790,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
498,
659,
2574,
1390,
63,
1267,
29,
1960,
12,
2574,
4596,
29,
549,
12,
2574,
1720,
63,
505,
12397,
1197,
1333,
272,
327,
17536,
8686,
883,
506,
1202,
9371,
3663,
14006,
12,
16119,
781,
675,
272,
327,
282,
28409,
14,
3390,
626,
27107,
5074,
376,
1145,
1126,
2881,
272,
327,
334,
18447,
314,
14006,
8663,
282,
2863,
1300,
536,
680,
272,
327,
4596,
29,
549,
6127,
367,
30723,
8686,
1928,
12881,
3062,
272,
15424,
275,
1709,
14,
7624,
8,
8972,
12,
4596,
29,
549,
9,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
4018,
13574,
4223,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
13574,
13103,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
2002,
7180,
6009,
8,
992,
14,
1685,
304,
272,
922,
275,
1709,
14,
3190,
8,
29339,
762,
14,
571,
63,
1751,
14,
3791,
63,
11429,
9,
272,
5022,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
3780,
659,
1816,
1390,
63,
1267,
29,
1216,
12,
1816,
3415,
29,
9710,
14,
5189,
14,
305,
63,
4577,
1012,
272,
327,
13870,
315,
1930,
1265,
3984,
7859,
424,
316,
340,
376,
25463,
8503,
2851,
365,
9995,
272,
327,
370,
5542,
315,
282,
283,
1535,
356,
272,
327,
272,
327,
473,
271,
1183,
12,
2851,
792,
8,
988,
63,
1267,
29,
7727,
12,
3747,
29,
549,
9,
3955,
506,
1202,
272,
327,
367,
8503,
14,
221,
9738,
12,
11200,
965,
282,
1390,
63,
1267,
12305,
402,
5450,
272,
327,
367,
2851,
792,
14,
7494,
3595,
1709,
14,
6254,
8,
3235,
29,
549,
9,
2066,
31,
272,
327,
644,
1697,
12,
626,
7859,
1133,
1736,
1902,
367,
11200,
7037,
370,
4573,
6519,
59,
17,
1055,
2002,
272,
327,
314,
1454,
4340,
734,
3955,
506,
370,
5978,
314,
3747,
5828,
12,
503,
272,
327,
6258,
370,
18299,
8503,
10867,
14,
593,
4979,
367,
314,
19045,
12,
465,
359,
18,
61,
272,
327,
18453,
83,
626,
8503,
10867,
787,
20042,
370,
506,
3974,
15988,
12,
737,
272,
327,
5210,
367,
314,
2269,
3158,
14,
272,
327,
272,
327,
359,
17,
61,
1455,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
1194,
2720,
14,
272,
327,
359,
18,
61,
1455,
921,
15403,
14,
846,
15,
7273,
15,
15403,
13,
11725,
13,
17,
63,
17,
14,
1360,
3,
9368,
339,
1747,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
1535,
659,
1390,
63,
1267,
29,
2299,
9,
272,
2061,
63,
2886,
275,
1709,
14,
4626,
8,
3832,
63,
354,
12397,
2019,
4676,
659,
4228,
2599,
63,
2131,
29,
549,
9,
272,
1434,
63,
11806,
275,
1709,
14,
4626,
8,
3832,
63,
354,
12397,
602,
16538,
659,
4318,
2599,
63,
2131,
63,
525,
29,
549,
9,
272,
2402,
63,
576,
275,
4840,
792,
8,
3832,
63,
354,
12397,
2911,
666,
659,
849,
534,
2440,
358,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
661,
3780,
297,
283,
1535,
358,
267,
3376,
63,
354,
275,
4018,
13574,
2933,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
13574,
12639,
358,
339,
347,
12895,
8,
277,
304,
267,
372,
12895,
8,
2048,
29,
277,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
3542,
63,
505,
8,
277,
14,
751,
9,
339,
347,
664,
63,
2913,
63,
633,
8,
277,
304,
267,
372,
291,
14,
362,
63,
3780,
63,
2048,
1252,
362,
63,
2913,
63,
633,
342,
339,
347,
664,
63,
14584,
63,
633
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
504,
1639,
14,
1208,
14,
10316,
492,
664,
63,
2355,
63,
875,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
893,
26,
272,
687,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
2590,
3545,
26,
272,
687,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2975,
465,
3542,
63,
505,
199,
199,
646,
741,
416,
762,
14,
571,
63,
1751,
199,
504,
741,
416,
762,
14,
2048,
14,
992,
492,
11426,
1476,
199,
504,
741,
416,
762,
14,
2048,
14,
1208,
492,
664,
63,
2184,
63,
4876,
63,
633,
12,
3272,
63,
751,
63,
2123,
199,
504,
741,
416,
762,
14,
1208,
492,
334,
362,
63,
751,
63,
1238,
12,
664,
63,
1818,
63,
2124,
12,
2574,
8437,
63,
842,
12,
22920,
63,
842,
9,
199,
199,
504,
1275,
492,
1145,
63,
1751,
199,
504,
1275,
492,
18032,
199,
504,
1275,
955,
492,
4840,
792,
199,
504,
2508,
1208,
492,
664,
63,
1069,
63,
635,
421,
199,
533,
2002,
7180,
2640,
2988,
8,
992,
14,
2988,
304,
272,
347,
664,
63,
1818,
8,
277,
12,
5022,
12,
1056,
29,
403,
304,
267,
4770,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
267,
372,
291,
14,
362,
8,
8619,
363,
344,
29,
2124,
14,
344,
12,
717,
5022,
29,
3780,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
2002,
7180,
2640,
8,
992,
14,
1685,
304,
272,
2251,
275,
2002,
7180,
2640,
2988,
342,
339,
5022,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
3780,
659,
1816,
1390,
63,
1267,
29,
1216,
12,
1816,
3415,
29,
9710,
14,
5189,
14,
305,
63,
4577,
1012,
272,
536,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
354,
659,
1169,
1390,
63,
1267,
29,
2167,
9,
272,
1890,
63,
344,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
1258,
1305,
659,
639,
1390,
63,
1267,
29,
1960,
12,
639,
1720,
63,
505,
12397,
2640,
2870,
12,
503,
9790,
790,
1333,
272,
7565,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
4731,
790,
659,
2892,
1390,
63,
1267,
29,
1960,
12,
2892,
1720,
63,
505,
12397,
3735,
7565,
12,
1890,
7565,
12,
503,
7,
2892,
283,
9790,
7565,
1333,
272,
790,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
498,
659,
2574,
1390,
63,
1267,
29,
1960,
12,
2574,
4596,
29,
549,
12,
2574,
1720,
63,
505,
12397,
1197,
1333,
272,
327,
17536,
8686,
883,
506,
1202,
9371,
3663,
14006,
12,
16119,
781,
675,
272,
327,
282,
28409,
14,
3390,
626,
27107,
5074,
376,
1145,
1126,
2881,
272,
327,
334,
18447,
314,
14006,
8663,
282,
2863,
1300,
536,
680,
272,
327,
4596,
29,
549,
6127,
367,
30723,
8686,
1928,
12881,
3062,
272,
15424,
275,
1709,
14,
7624,
8,
8972,
12,
4596,
29,
549,
9,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
4018,
13574,
4223,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
13574,
13103,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
2002,
7180,
6009,
8,
992,
14,
1685,
304,
272,
922,
275,
1709,
14,
3190,
8,
29339,
762,
14,
571,
63,
1751,
14,
3791,
63,
11429,
9,
272,
5022,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
3780,
659,
1816,
1390,
63,
1267,
29,
1216,
12,
1816,
3415,
29,
9710,
14,
5189,
14,
305,
63,
4577,
1012,
272,
327,
13870,
315,
1930,
1265,
3984,
7859,
424,
316,
340,
376,
25463,
8503,
2851,
365,
9995,
272,
327,
370,
5542,
315,
282,
283,
1535,
356,
272,
327,
272,
327,
473,
271,
1183,
12,
2851,
792,
8,
988,
63,
1267,
29,
7727,
12,
3747,
29,
549,
9,
3955,
506,
1202,
272,
327,
367,
8503,
14,
221,
9738,
12,
11200,
965,
282,
1390,
63,
1267,
12305,
402,
5450,
272,
327,
367,
2851,
792,
14,
7494,
3595,
1709,
14,
6254,
8,
3235,
29,
549,
9,
2066,
31,
272,
327,
644,
1697,
12,
626,
7859,
1133,
1736,
1902,
367,
11200,
7037,
370,
4573,
6519,
59,
17,
1055,
2002,
272,
327,
314,
1454,
4340,
734,
3955,
506,
370,
5978,
314,
3747,
5828,
12,
503,
272,
327,
6258,
370,
18299,
8503,
10867,
14,
593,
4979,
367,
314,
19045,
12,
465,
359,
18,
61,
272,
327,
18453,
83,
626,
8503,
10867,
787,
20042,
370,
506,
3974,
15988,
12,
737,
272,
327,
5210,
367,
314,
2269,
3158,
14,
272,
327,
272,
327,
359,
17,
61,
1455,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
1194,
2720,
14,
272,
327,
359,
18,
61,
1455,
921,
15403,
14,
846,
15,
7273,
15,
15403,
13,
11725,
13,
17,
63,
17,
14,
1360,
3,
9368,
339,
1747,
275,
1709,
14,
2183,
8,
3832,
63,
354,
12397,
1535,
659,
1390,
63,
1267,
29,
2299,
9,
272,
2061,
63,
2886,
275,
1709,
14,
4626,
8,
3832,
63,
354,
12397,
2019,
4676,
659,
4228,
2599,
63,
2131,
29,
549,
9,
272,
1434,
63,
11806,
275,
1709,
14,
4626,
8,
3832,
63,
354,
12397,
602,
16538,
659,
4318,
2599,
63,
2131,
63,
525,
29,
549,
9,
272,
2402,
63,
576,
275,
4840,
792,
8,
3832,
63,
354,
12397,
2911,
666,
659,
849,
534,
2440,
358,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
661,
3780,
297,
283,
1535,
358,
267,
3376,
63,
354,
275,
4018,
13574,
2933,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
13574,
12639,
358,
339,
347,
12895,
8,
277,
304,
267,
372,
12895,
8,
2048,
29,
277,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
3542,
63,
505,
8,
277,
14,
751,
9,
339,
347,
664,
63,
2913,
63,
633,
8,
277,
304,
267,
372,
291,
14,
362,
63,
3780,
63,
2048,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
edmundgentle/schoolscript
|
SchoolScript/bin/Debug/pythonlib/Lib/mailcap.py
|
3
|
7640
|
"""Mailcap file handling. See RFC 1524."""
import os
__all__ = ["getcaps","findmatch"]
# Part 1: top-level interface.
def getcaps():
"""Return a dictionary containing the mailcap database.
The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
to a list of dictionaries corresponding to mailcap entries. The list
collects all the entries for that MIME type from all available mailcap
files. Each dictionary contains key-value pairs for that MIME type,
where the viewing command is stored with the key "view".
"""
caps = {}
for mailcap in listmailcapfiles():
try:
fp = open(mailcap, 'r')
except IOError:
continue
morecaps = readmailcapfile(fp)
fp.close()
for key, value in morecaps.items():
if not key in caps:
caps[key] = value
else:
caps[key] = caps[key] + value
return caps
def listmailcapfiles():
"""Return a list of all mailcap files found on the system."""
# XXX Actually, this is Unix-specific
if 'MAILCAPS' in os.environ:
str = os.environ['MAILCAPS']
mailcaps = str.split(':')
else:
if 'HOME' in os.environ:
home = os.environ['HOME']
else:
# Don't bother with getpwuid()
home = '.' # Last resort
mailcaps = [home + '/.mailcap', '/etc/mailcap',
'/usr/etc/mailcap', '/usr/local/etc/mailcap']
return mailcaps
# Part 2: the parser.
def readmailcapfile(fp):
"""Read a mailcap file and return a dictionary keyed by MIME type.
Each MIME type is mapped to an entry consisting of a list of
dictionaries; the list will contain more than one such dictionary
if a given MIME type appears more than once in the mailcap file.
Each dictionary contains key-value pairs for that MIME type, where
the viewing command is stored with the key "view".
"""
caps = {}
while 1:
line = fp.readline()
if not line: break
# Ignore comments and blank lines
if line[0] == '#' or line.strip() == '':
continue
nextline = line
# Join continuation lines
while nextline[-2:] == '\\\n':
nextline = fp.readline()
if not nextline: nextline = '\n'
line = line[:-2] + nextline
# Parse the line
key, fields = parseline(line)
if not (key and fields):
continue
# Normalize the key
types = key.split('/')
for j in range(len(types)):
types[j] = types[j].strip()
key = '/'.join(types).lower()
# Update the database
if key in caps:
caps[key].append(fields)
else:
caps[key] = [fields]
return caps
def parseline(line):
"""Parse one entry in a mailcap file and return a dictionary.
The viewing command is stored as the value with the key "view",
and the rest of the fields produce key-value pairs in the dict.
"""
fields = []
i, n = 0, len(line)
while i < n:
field, i = parsefield(line, i, n)
fields.append(field)
i = i+1 # Skip semicolon
if len(fields) < 2:
return None, None
key, view, rest = fields[0], fields[1], fields[2:]
fields = {'view': view}
for field in rest:
i = field.find('=')
if i < 0:
fkey = field
fvalue = ""
else:
fkey = field[:i].strip()
fvalue = field[i+1:].strip()
if fkey in fields:
# Ignore it
pass
else:
fields[fkey] = fvalue
return key, fields
def parsefield(line, i, n):
"""Separate one key-value pair in a mailcap entry."""
start = i
while i < n:
c = line[i]
if c == ';':
break
elif c == '\\':
i = i+2
else:
i = i+1
return line[start:i].strip(), i
# Part 3: using the database.
def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]):
"""Find a match for a mailcap entry.
Return a tuple containing the command line, and the mailcap entry
used; (None, None) if no match is found. This may invoke the
'test' command of several matching entries before deciding which
entry to use.
"""
entries = lookup(caps, MIMEtype, key)
# XXX This code should somehow check for the needsterminal flag.
for e in entries:
if 'test' in e:
test = subst(e['test'], filename, plist)
if test and os.system(test) != 0:
continue
command = subst(e[key], MIMEtype, filename, plist)
return command, e
return None, None
def lookup(caps, MIMEtype, key=None):
entries = []
if MIMEtype in caps:
entries = entries + caps[MIMEtype]
MIMEtypes = MIMEtype.split('/')
MIMEtype = MIMEtypes[0] + '/*'
if MIMEtype in caps:
entries = entries + caps[MIMEtype]
if key is not None:
entries = [e for e in entries if key in e]
return entries
def subst(field, MIMEtype, filename, plist=[]):
# XXX Actually, this is Unix-specific
res = ''
i, n = 0, len(field)
while i < n:
c = field[i]; i = i+1
if c != '%':
if c == '\\':
c = field[i:i+1]; i = i+1
res = res + c
else:
c = field[i]; i = i+1
if c == '%':
res = res + c
elif c == 's':
res = res + filename
elif c == 't':
res = res + MIMEtype
elif c == '{':
start = i
while i < n and field[i] != '}':
i = i+1
name = field[start:i]
i = i+1
res = res + findparam(name, plist)
# XXX To do:
# %n == number of parts if type is multipart/*
# %F == list of alternating type and filename for parts
else:
res = res + '%' + c
return res
def findparam(name, plist):
name = name.lower() + '='
n = len(name)
for p in plist:
if p[:n].lower() == name:
return p[n:]
return ''
# Part 4: test program.
def test():
import sys
caps = getcaps()
if not sys.argv[1:]:
show(caps)
return
for i in range(1, len(sys.argv), 2):
args = sys.argv[i:i+2]
if len(args) < 2:
print("usage: mailcap [MIMEtype file] ...")
return
MIMEtype = args[0]
file = args[1]
command, e = findmatch(caps, MIMEtype, 'view', file)
if not command:
print("No viewer found for", type)
else:
print("Executing:", command)
sts = os.system(command)
if sts:
print("Exit status:", sts)
def show(caps):
print("Mailcap files:")
for fn in listmailcapfiles(): print("\t" + fn)
print()
if not caps: caps = getcaps()
print("Mailcap entries:")
print()
ckeys = sorted(caps)
for type in ckeys:
print(type)
entries = caps[type]
for e in entries:
keys = sorted(e)
for k in keys:
print(" %-15s" % k, e[k])
print()
if __name__ == '__main__':
test()
|
gpl-2.0
|
[
624,
13681,
2874,
570,
7252,
14,
221,
1666,
7329,
4114,
1194,
1041,
2999,
199,
646,
747,
2999,
199,
363,
452,
363,
275,
2097,
362,
12029,
2266,
1623,
1431,
937,
2999,
199,
3,
14320,
413,
26,
2746,
13,
1896,
3217,
14,
2999,
199,
318,
664,
12029,
837,
1128,
408,
1767,
282,
2600,
3035,
314,
6016,
2874,
3050,
14,
2958,
710,
2600,
9033,
282,
14735,
730,
334,
262,
1006,
12141,
12,
325,
14,
71,
14,
283,
505,
15,
6104,
358,
1128,
370,
282,
769,
402,
11196,
5226,
370,
6016,
2874,
4811,
14,
221,
710,
769,
1128,
8775,
83,
1006,
314,
4811,
367,
626,
14735,
730,
687,
1006,
2808,
6016,
2874,
1128,
1584,
14,
221,
7048,
2600,
3509,
790,
13,
585,
6342,
367,
626,
14735,
730,
12,
1128,
2382,
314,
2455,
316,
1414,
365,
5489,
543,
314,
790,
298,
1345,
1674,
2958,
408,
1128,
22053,
275,
1052,
1128,
367,
6016,
2874,
315,
769,
1198,
2874,
1725,
837,
1039,
862,
26,
1675,
4090,
275,
1551,
8,
1198,
2874,
12,
283,
82,
358,
1039,
871,
5925,
26,
1675,
1980,
1039,
1655,
12029,
275,
1586,
1198,
2874,
493,
8,
3997,
9,
1039,
4090,
14,
1600,
342,
1039,
367,
790,
12,
574,
315,
1655,
12029,
14,
1744,
837,
1675,
340,
440,
790,
315,
22053,
26,
2628,
22053,
59,
498,
61,
275,
574,
1675,
587,
26,
2628,
22053,
59,
498,
61,
275,
22053,
59,
498,
61,
435,
574,
1128,
372,
22053,
2999,
199,
318,
769,
1198,
2874,
1725,
837,
1128,
408,
1767,
282,
769,
402,
1006,
6016,
2874,
1584,
1911,
641,
314,
2656,
1041,
1128,
327,
5787,
18982,
3163,
12,
642,
365,
13074,
13,
6100,
1128,
340,
283,
8175,
8549,
51,
7,
315,
747,
14,
2314,
26,
1039,
620,
275,
747,
14,
2314,
459,
8175,
8549,
51,
418,
1039,
6016,
12029,
275,
620,
14,
1294,
11633,
1128,
587,
26,
1039,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
1675,
5629,
275,
747,
14,
2314,
459,
9524,
418,
1039,
587,
26,
1675,
327,
7529,
1133,
26962,
543,
664,
8796,
1535,
342,
1675,
5629,
275,
7815,
327,
15237,
522,
361,
1039,
6016,
12029,
275,
359,
4219,
435,
1994,
14,
1198,
2874,
297,
1994,
6839,
15,
1198,
2874,
297,
2628,
1994,
2647,
15,
6839,
15,
1198,
2874,
297,
1994,
2647,
15,
1832,
15,
6839,
15,
1198,
2874,
418,
1128,
372,
6016,
12029,
8065,
199,
3,
14320,
499,
26,
314,
1798,
14,
2999,
199,
318,
1586,
1198,
2874,
493,
8,
3997,
304,
1128,
408,
3284,
282,
6016,
2874,
570,
436,
372,
282,
2600,
19272,
701,
14735,
730,
14,
2958,
7048,
14735,
730,
365,
9994,
370,
376,
2397,
22581,
402,
282,
769,
402,
1128,
11196,
27,
314,
769,
911,
1395,
1655,
2419,
1373,
4066,
2600,
1128,
340,
282,
1627,
14735,
730,
11337,
1655,
2419,
5403,
315,
314,
6016,
2874,
570,
14,
1128,
7048,
2600,
3509,
790,
13,
585,
6342,
367,
626,
14735,
730,
12,
2382,
1128,
314,
2455,
316,
1414,
365,
5489,
543,
314,
790,
298,
1345,
1674,
1128,
408,
1128,
22053,
275,
1052,
1128,
1830,
413,
26,
1039,
1004,
275,
4090,
14,
6407,
342,
1039,
340,
440,
1004,
26,
2059,
1039,
327,
14092,
6786,
436,
4596,
2385,
1039,
340,
1004,
59,
16,
61,
508,
19619,
503,
1004,
14,
1913,
342,
508,
8061,
1675,
1980,
1039,
2163,
604,
275,
1004,
1039,
327,
25733,
16015,
2385,
1039,
1830,
2163,
604,
1988,
18,
2938,
508,
6468,
60,
78,
356,
1675,
2163,
604,
275,
4090,
14,
6407,
342,
1675,
340,
440,
2163,
604,
26,
2163,
604,
275,
1557,
78,
7,
1675,
1004,
275,
1004,
4439,
18,
61,
435,
2163,
604,
1039,
327,
6077,
314,
1004,
1039,
790,
12,
1504,
275,
2198,
604,
8,
604,
9,
1039,
340,
440,
334,
498,
436,
1504,
304,
1675,
1980,
1039,
327,
21017,
314,
790,
1039,
2943,
275,
790,
14,
1294,
7825,
1039,
367,
1335,
315,
1425,
8,
552,
8,
1313,
2298,
1675,
2943,
59,
74,
61,
275,
2943,
59,
74,
1055,
1913,
342,
1039,
790,
275,
20538,
904,
8,
1313,
680,
2325,
342,
1039,
327,
6162,
314,
3050,
1039,
340,
790,
315,
22053,
26,
1675,
22053,
59,
498,
1055,
740,
8,
955,
9,
1039,
587,
26,
1675,
22053,
59,
498,
61,
275,
359,
955,
61,
1128,
372,
22053,
2999,
199,
318,
2198,
604,
8,
604,
304,
1128,
408,
4003,
1373,
2397,
315,
282,
6016,
2874,
570,
436,
372,
282,
2600,
14,
2958,
710,
2455,
316,
1414,
365,
5489,
465,
314,
574,
543,
314,
790,
298,
1345,
401,
1128,
436,
314,
4618,
402,
314,
1504,
7389,
790,
13,
585,
6342,
315,
314,
1211,
14,
1128,
408,
1128,
1504,
275,
942,
1128,
284,
12,
302,
275,
378,
12,
822,
8,
604,
9,
1128,
1830,
284,
665,
302,
26,
1039,
901,
12,
284,
275,
2198,
698,
8,
604,
12,
284,
12,
302,
9,
1039,
1504,
14,
740,
8,
698,
9,
1039,
284,
275,
284,
11,
17,
327,
8232,
18734,
12167,
1128,
340,
822,
8,
955,
9,
665,
499,
26,
1039,
372,
488,
12,
488,
1128,
790,
12,
2455,
12,
4618,
275,
1504,
59,
16,
467,
1504,
59,
17,
467,
1504,
59,
18,
2938,
1128,
1504,
275,
791,
1345,
356,
2455,
93,
1128,
367,
901,
315,
4618,
26,
1039,
284,
275,
901,
14,
1623,
23917,
1039,
340,
284,
665,
378,
26,
1675,
289,
498,
275,
901,
1675,
289,
585,
275,
3087,
1039,
587,
26,
1675,
289,
498,
275,
901,
1491,
73,
1055,
1913,
342,
1675,
289,
585,
275,
901,
59,
73,
11,
17,
11455,
1913,
342,
1039,
340,
289,
498,
315,
1504,
26,
1675,
327,
14092,
652,
1675,
986,
1039,
587,
26,
1675,
1504,
59,
70,
498,
61,
275,
289,
585,
1128,
372,
790,
12,
1504,
2999,
199,
318,
2198,
698,
8,
604,
12,
284,
12,
302,
304,
1128,
408,
12653,
323,
1373,
790,
13,
585,
4092,
315,
282,
6016,
2874,
2397,
1041,
1128,
1343,
275,
284,
1128,
1830,
284,
665,
302,
26,
1039,
286,
275,
1004,
59,
73,
61,
1039,
340,
286,
508,
283,
6015,
1675,
2059,
1039,
916,
286,
508,
29082,
1675,
284,
275,
284,
11,
18,
1039,
587,
26,
1675,
284,
275,
284,
11,
17,
1128,
372,
1004,
59,
928,
26,
73,
1055,
1913,
1062,
284,
8065,
199,
3,
14320,
650,
26,
1808,
314,
3050,
14,
2999,
199,
318,
2342,
1431,
8,
12029,
12
] |
[
13681,
2874,
570,
7252,
14,
221,
1666,
7329,
4114,
1194,
1041,
2999,
199,
646,
747,
2999,
199,
363,
452,
363,
275,
2097,
362,
12029,
2266,
1623,
1431,
937,
2999,
199,
3,
14320,
413,
26,
2746,
13,
1896,
3217,
14,
2999,
199,
318,
664,
12029,
837,
1128,
408,
1767,
282,
2600,
3035,
314,
6016,
2874,
3050,
14,
2958,
710,
2600,
9033,
282,
14735,
730,
334,
262,
1006,
12141,
12,
325,
14,
71,
14,
283,
505,
15,
6104,
358,
1128,
370,
282,
769,
402,
11196,
5226,
370,
6016,
2874,
4811,
14,
221,
710,
769,
1128,
8775,
83,
1006,
314,
4811,
367,
626,
14735,
730,
687,
1006,
2808,
6016,
2874,
1128,
1584,
14,
221,
7048,
2600,
3509,
790,
13,
585,
6342,
367,
626,
14735,
730,
12,
1128,
2382,
314,
2455,
316,
1414,
365,
5489,
543,
314,
790,
298,
1345,
1674,
2958,
408,
1128,
22053,
275,
1052,
1128,
367,
6016,
2874,
315,
769,
1198,
2874,
1725,
837,
1039,
862,
26,
1675,
4090,
275,
1551,
8,
1198,
2874,
12,
283,
82,
358,
1039,
871,
5925,
26,
1675,
1980,
1039,
1655,
12029,
275,
1586,
1198,
2874,
493,
8,
3997,
9,
1039,
4090,
14,
1600,
342,
1039,
367,
790,
12,
574,
315,
1655,
12029,
14,
1744,
837,
1675,
340,
440,
790,
315,
22053,
26,
2628,
22053,
59,
498,
61,
275,
574,
1675,
587,
26,
2628,
22053,
59,
498,
61,
275,
22053,
59,
498,
61,
435,
574,
1128,
372,
22053,
2999,
199,
318,
769,
1198,
2874,
1725,
837,
1128,
408,
1767,
282,
769,
402,
1006,
6016,
2874,
1584,
1911,
641,
314,
2656,
1041,
1128,
327,
5787,
18982,
3163,
12,
642,
365,
13074,
13,
6100,
1128,
340,
283,
8175,
8549,
51,
7,
315,
747,
14,
2314,
26,
1039,
620,
275,
747,
14,
2314,
459,
8175,
8549,
51,
418,
1039,
6016,
12029,
275,
620,
14,
1294,
11633,
1128,
587,
26,
1039,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
1675,
5629,
275,
747,
14,
2314,
459,
9524,
418,
1039,
587,
26,
1675,
327,
7529,
1133,
26962,
543,
664,
8796,
1535,
342,
1675,
5629,
275,
7815,
327,
15237,
522,
361,
1039,
6016,
12029,
275,
359,
4219,
435,
1994,
14,
1198,
2874,
297,
1994,
6839,
15,
1198,
2874,
297,
2628,
1994,
2647,
15,
6839,
15,
1198,
2874,
297,
1994,
2647,
15,
1832,
15,
6839,
15,
1198,
2874,
418,
1128,
372,
6016,
12029,
8065,
199,
3,
14320,
499,
26,
314,
1798,
14,
2999,
199,
318,
1586,
1198,
2874,
493,
8,
3997,
304,
1128,
408,
3284,
282,
6016,
2874,
570,
436,
372,
282,
2600,
19272,
701,
14735,
730,
14,
2958,
7048,
14735,
730,
365,
9994,
370,
376,
2397,
22581,
402,
282,
769,
402,
1128,
11196,
27,
314,
769,
911,
1395,
1655,
2419,
1373,
4066,
2600,
1128,
340,
282,
1627,
14735,
730,
11337,
1655,
2419,
5403,
315,
314,
6016,
2874,
570,
14,
1128,
7048,
2600,
3509,
790,
13,
585,
6342,
367,
626,
14735,
730,
12,
2382,
1128,
314,
2455,
316,
1414,
365,
5489,
543,
314,
790,
298,
1345,
1674,
1128,
408,
1128,
22053,
275,
1052,
1128,
1830,
413,
26,
1039,
1004,
275,
4090,
14,
6407,
342,
1039,
340,
440,
1004,
26,
2059,
1039,
327,
14092,
6786,
436,
4596,
2385,
1039,
340,
1004,
59,
16,
61,
508,
19619,
503,
1004,
14,
1913,
342,
508,
8061,
1675,
1980,
1039,
2163,
604,
275,
1004,
1039,
327,
25733,
16015,
2385,
1039,
1830,
2163,
604,
1988,
18,
2938,
508,
6468,
60,
78,
356,
1675,
2163,
604,
275,
4090,
14,
6407,
342,
1675,
340,
440,
2163,
604,
26,
2163,
604,
275,
1557,
78,
7,
1675,
1004,
275,
1004,
4439,
18,
61,
435,
2163,
604,
1039,
327,
6077,
314,
1004,
1039,
790,
12,
1504,
275,
2198,
604,
8,
604,
9,
1039,
340,
440,
334,
498,
436,
1504,
304,
1675,
1980,
1039,
327,
21017,
314,
790,
1039,
2943,
275,
790,
14,
1294,
7825,
1039,
367,
1335,
315,
1425,
8,
552,
8,
1313,
2298,
1675,
2943,
59,
74,
61,
275,
2943,
59,
74,
1055,
1913,
342,
1039,
790,
275,
20538,
904,
8,
1313,
680,
2325,
342,
1039,
327,
6162,
314,
3050,
1039,
340,
790,
315,
22053,
26,
1675,
22053,
59,
498,
1055,
740,
8,
955,
9,
1039,
587,
26,
1675,
22053,
59,
498,
61,
275,
359,
955,
61,
1128,
372,
22053,
2999,
199,
318,
2198,
604,
8,
604,
304,
1128,
408,
4003,
1373,
2397,
315,
282,
6016,
2874,
570,
436,
372,
282,
2600,
14,
2958,
710,
2455,
316,
1414,
365,
5489,
465,
314,
574,
543,
314,
790,
298,
1345,
401,
1128,
436,
314,
4618,
402,
314,
1504,
7389,
790,
13,
585,
6342,
315,
314,
1211,
14,
1128,
408,
1128,
1504,
275,
942,
1128,
284,
12,
302,
275,
378,
12,
822,
8,
604,
9,
1128,
1830,
284,
665,
302,
26,
1039,
901,
12,
284,
275,
2198,
698,
8,
604,
12,
284,
12,
302,
9,
1039,
1504,
14,
740,
8,
698,
9,
1039,
284,
275,
284,
11,
17,
327,
8232,
18734,
12167,
1128,
340,
822,
8,
955,
9,
665,
499,
26,
1039,
372,
488,
12,
488,
1128,
790,
12,
2455,
12,
4618,
275,
1504,
59,
16,
467,
1504,
59,
17,
467,
1504,
59,
18,
2938,
1128,
1504,
275,
791,
1345,
356,
2455,
93,
1128,
367,
901,
315,
4618,
26,
1039,
284,
275,
901,
14,
1623,
23917,
1039,
340,
284,
665,
378,
26,
1675,
289,
498,
275,
901,
1675,
289,
585,
275,
3087,
1039,
587,
26,
1675,
289,
498,
275,
901,
1491,
73,
1055,
1913,
342,
1675,
289,
585,
275,
901,
59,
73,
11,
17,
11455,
1913,
342,
1039,
340,
289,
498,
315,
1504,
26,
1675,
327,
14092,
652,
1675,
986,
1039,
587,
26,
1675,
1504,
59,
70,
498,
61,
275,
289,
585,
1128,
372,
790,
12,
1504,
2999,
199,
318,
2198,
698,
8,
604,
12,
284,
12,
302,
304,
1128,
408,
12653,
323,
1373,
790,
13,
585,
4092,
315,
282,
6016,
2874,
2397,
1041,
1128,
1343,
275,
284,
1128,
1830,
284,
665,
302,
26,
1039,
286,
275,
1004,
59,
73,
61,
1039,
340,
286,
508,
283,
6015,
1675,
2059,
1039,
916,
286,
508,
29082,
1675,
284,
275,
284,
11,
18,
1039,
587,
26,
1675,
284,
275,
284,
11,
17,
1128,
372,
1004,
59,
928,
26,
73,
1055,
1913,
1062,
284,
8065,
199,
3,
14320,
650,
26,
1808,
314,
3050,
14,
2999,
199,
318,
2342,
1431,
8,
12029,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
etashjian/ECE757-final
|
src/arch/x86/isa/insts/simd64/integer/arithmetic/multiply_add.py
|
91
|
2946
|
# Copyright (c) 2007 The Hewlett-Packard Development Company
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Gabe Black
microcode = '''
def macroop PMADDWD_MMX_MMX {
mmuli ufp3, mmx, mmxm, srcSize=2, destSize=4, ext = Signed + "| 0x10 | 0x20"
mmuli ufp4, mmx, mmxm, srcSize=2, destSize=4, ext = Signed + "| 0x10"
maddi mmx, ufp3, ufp4, size=4, ext=0
};
def macroop PMADDWD_MMX_M {
ldfp ufp1, seg, sib, "DISPLACEMENT", dataSize=8
mmuli ufp3, mmx, ufp1, srcSize=2, destSize=4, ext = Signed + "| 0x10 | 0x20"
mmuli ufp4, mmx, ufp1, srcSize=2, destSize=4, ext = Signed + "| 0x10"
maddi mmx, ufp3, ufp4, size=4, ext=0
};
def macroop PMADDWD_MMX_P {
rdip t7
ldfp ufp1, seg, riprel, "DISPLACEMENT", dataSize=8
mmuli ufp3, mmx, ufp1, srcSize=2, destSize=4, ext = Signed + "| 0x10 | 0x20"
mmuli ufp4, mmx, ufp1, srcSize=2, destSize=4, ext = Signed + "| 0x10"
maddi mmx, ufp3, ufp4, size=4, ext=0
};
'''
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
27320,
9732,
16698,
63,
3218,
56,
63,
3218,
56,
469,
272,
333,
6553,
317,
26337,
19,
12,
8562,
88,
12,
8562,
10198,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
1204,
378,
88,
1165,
2,
272,
333,
6553,
317,
26337,
20,
12,
8562,
88,
12,
8562,
10198,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
2,
272,
333,
350,
328,
8562,
88,
12,
26337,
19,
12,
26337,
20,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
27320,
9732,
16698,
63,
3218,
56,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
333,
6553,
317,
26337,
19,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
1204,
378,
88,
1165,
2,
272,
333,
6553,
317,
26337,
20,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
2,
272,
333,
350,
328,
8562,
88,
12,
26337,
19,
12,
26337,
20,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
27320,
9732,
16698,
63,
3218,
56,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
333,
6553,
317,
26337,
19,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
1204,
378,
88,
1165,
2,
272,
333,
6553,
317,
26337,
20,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
2,
272,
333,
350,
328,
8562,
88,
12,
26337,
19,
12,
26337,
20,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
27320,
9732,
16698,
63,
3218,
56,
63,
3218,
56,
469,
272,
333,
6553,
317,
26337,
19,
12,
8562,
88,
12,
8562,
10198,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
1204,
378,
88,
1165,
2,
272,
333,
6553,
317,
26337,
20,
12,
8562,
88,
12,
8562,
10198,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
2,
272,
333,
350,
328,
8562,
88,
12,
26337,
19,
12,
26337,
20,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
27320,
9732,
16698,
63,
3218,
56,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
333,
6553,
317,
26337,
19,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
1204,
378,
88,
1165,
2,
272,
333,
6553,
317,
26337,
20,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
2,
272,
333,
350,
328,
8562,
88,
12,
26337,
19,
12,
26337,
20,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
27320,
9732,
16698,
63,
3218,
56,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
333,
6553,
317,
26337,
19,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
1204,
378,
88,
1165,
2,
272,
333,
6553,
317,
26337,
20,
12,
8562,
88,
12,
26337,
17,
12,
2928,
2320,
29,
18,
12,
2053,
2320,
29,
20,
12,
1599,
275,
6632,
379,
435,
15733,
378,
88,
709,
2,
272,
333,
350,
328,
8562,
88,
12,
26337,
19,
12,
26337,
20,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MatthewWilkes/reportlab
|
demos/odyssey/dodyssey.py
|
1
|
7622
|
#Copyright ReportLab Europe Ltd. 2000-2012
#see license.txt for license details
__version__=''' $Id$ '''
__doc__=''
#REPORTLAB_TEST_SCRIPT
import sys, copy, os
from reportlab.platypus import *
_NEW_PARA=os.environ.get('NEW_PARA','0')[0] in ('y','Y','1')
_REDCAP=int(os.environ.get('REDCAP','0'))
_CALLBACK=os.environ.get('CALLBACK','0')[0] in ('y','Y','1')
if _NEW_PARA:
def Paragraph(s,style):
from rlextra.radxml.para import Paragraph as PPPP
return PPPP(s,style)
from reportlab.lib.units import inch
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
import reportlab.rl_config
reportlab.rl_config.invariant = 1
styles = getSampleStyleSheet()
Title = "The Odyssey"
Author = "Homer"
def myTitlePage(canvas, doc):
canvas.saveState()
canvas.restoreState()
def myLaterPages(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Roman',9)
canvas.drawString(inch, 0.75 * inch, "Page %d" % doc.page)
canvas.restoreState()
def go():
def myCanvasMaker(fn,**kw):
from reportlab.pdfgen.canvas import Canvas
canv = Canvas(fn,**kw)
# attach our callback to the canvas
canv.myOnDrawCB = myOnDrawCB
return canv
doc = BaseDocTemplate('dodyssey.pdf',showBoundary=0)
#normal frame as for SimpleFlowDocument
frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
#Two Columns
frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
frame2 = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6,
doc.height, id='col2')
doc.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=myTitlePage),
PageTemplate(id='OneCol',frames=frameT, onPage=myLaterPages),
PageTemplate(id='TwoCol',frames=[frame1,frame2], onPage=myLaterPages),
])
doc.build(Elements,canvasmaker=myCanvasMaker)
Elements = []
ChapterStyle = copy.deepcopy(styles["Heading1"])
ChapterStyle.alignment = TA_CENTER
ChapterStyle.fontsize = 14
InitialStyle = copy.deepcopy(ChapterStyle)
InitialStyle.fontsize = 16
InitialStyle.leading = 20
PreStyle = styles["Code"]
def newPage():
Elements.append(PageBreak())
chNum = 0
def myOnDrawCB(canv,kind,label):
print 'myOnDrawCB(%s)'%kind, 'Page number=', canv.getPageNumber(), 'label value=', label
def chapter(txt, style=ChapterStyle):
global chNum
Elements.append(NextPageTemplate('OneCol'))
newPage()
chNum += 1
if _NEW_PARA or not _CALLBACK:
Elements.append(Paragraph(txt, style))
else:
Elements.append(Paragraph(('foo<onDraw name="myOnDrawCB" label="chap %d"/> '%chNum)+txt, style))
Elements.append(Spacer(0.2*inch, 0.3*inch))
if useTwoCol:
Elements.append(NextPageTemplate('TwoCol'))
def fTitle(txt,style=InitialStyle):
Elements.append(Paragraph(txt, style))
ParaStyle = copy.deepcopy(styles["Normal"])
ParaStyle.spaceBefore = 0.1*inch
if 'right' in sys.argv:
ParaStyle.alignment = TA_RIGHT
elif 'left' in sys.argv:
ParaStyle.alignment = TA_LEFT
elif 'justify' in sys.argv:
ParaStyle.alignment = TA_JUSTIFY
elif 'center' in sys.argv or 'centre' in sys.argv:
ParaStyle.alignment = TA_CENTER
else:
ParaStyle.alignment = TA_JUSTIFY
useTwoCol = 'notwocol' not in sys.argv
def spacer(inches):
Elements.append(Spacer(0.1*inch, inches*inch))
def p(txt, style=ParaStyle):
if _REDCAP:
fs, fe = '<font color="red" size="+2">', '</font>'
n = len(txt)
for i in xrange(n):
if 'a'<=txt[i]<='z' or 'A'<=txt[i]<='Z':
txt = (txt[:i]+(fs+txt[i]+fe))+txt[i+1:]
break
if _REDCAP>=2 and n>20:
j = i+len(fs)+len(fe)+1+int((n-1)/2)
while not ('a'<=txt[j]<='z' or 'A'<=txt[j]<='Z'): j += 1
txt = (txt[:j]+('<b><i><font size="+2" color="blue">'+txt[j]+'</font></i></b>'))+txt[j+1:]
if _REDCAP==3 and n>20:
n = len(txt)
fs = '<font color="green" size="+1">'
for i in xrange(n-1,-1,-1):
if 'a'<=txt[i]<='z' or 'A'<=txt[i]<='Z':
txt = txt[:i]+((fs+txt[i]+fe)+txt[i+1:])
break
Elements.append(Paragraph(txt, style))
firstPre = 1
def pre(txt, style=PreStyle):
global firstPre
if firstPre:
Elements.append(NextPageTemplate('OneCol'))
newPage()
firstPre = 0
spacer(0.1)
p = Preformatted(txt, style)
Elements.append(p)
def parseOdyssey(fn):
from time import time
E = []
t0=time()
text = open(fn,'r').read()
i0 = text.index('Book I')
endMarker = 'covenant of peace between the two contending parties.'
i1 = text.index(endMarker)+len(endMarker)
PREAMBLE=map(str.strip,text[0:i0].split('\n'))
L=map(str.strip,text[i0:i1].split('\n'))
POSTAMBLE=map(str.strip,text[i1:].split('\n'))
def ambleText(L):
while L and not L[0]: L.pop(0)
while L:
T=[]
while L and L[0]:
T.append(L.pop(0))
yield T
while L and not L[0]: L.pop(0)
def mainText(L):
while L:
B = L.pop(0)
while not L[0]: L.pop(0)
T=[]
while L and L[0]:
T.append(L.pop(0))
while not L[0]: L.pop(0)
P = []
while L and not (L[0].startswith('Book ') and len(L[0].split())==2):
E=[]
while L and L[0]:
E.append(L.pop(0))
P.append(E)
if L:
while not L[0]: L.pop(0)
yield B,T,P
t1 = time()
print "open(%s,'r').read() took %.4f seconds" %(fn,t1-t0)
E.append([spacer,2])
E.append([fTitle,'<font color="red">%s</font>' % Title, InitialStyle])
E.append([fTitle,'<font size="-4">by</font> <font color="green">%s</font>' % Author, InitialStyle])
for T in ambleText(PREAMBLE):
E.append([p,'\n'.join(T)])
for (B,T,P) in mainText(L):
E.append([chapter,B])
E.append([p,'<font size="+1" color="Blue"><b>%s</b></font>' % '\n'.join(T),ParaStyle])
for x in P:
E.append([p,' '.join(x)])
firstPre = 1
for T in ambleText(POSTAMBLE):
E.append([p,'\n'.join(T)])
t3 = time()
print "Parsing into memory took %.4f seconds" %(t3-t1)
del L
t4 = time()
print "Deleting list of lines took %.4f seconds" %(t4-t3)
for i in xrange(len(E)):
E[i][0](*E[i][1:])
t5 = time()
print "Moving into platypus took %.4f seconds" %(t5-t4)
del E
t6 = time()
print "Deleting list of actions took %.4f seconds" %(t6-t5)
go()
t7 = time()
print "saving to PDF took %.4f seconds" %(t7-t6)
print "Total run took %.4f seconds"%(t7-t0)
import md5
print 'file digest: %s' % md5.md5(open('dodyssey.pdf','rb').read()).hexdigest()
def run():
for fn in ('odyssey.full.txt','odyssey.txt'):
if os.path.isfile(fn):
parseOdyssey(fn)
break
def doProf(profname,func,*args,**kwd):
import hotshot, hotshot.stats
prof = hotshot.Profile(profname)
prof.runcall(func)
prof.close()
stats = hotshot.stats.load(profname)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
if __name__=='__main__':
if '--prof' in sys.argv:
doProf('dodyssey.prof',run)
else:
run()
|
bsd-3-clause
|
[
3,
7384,
11774,
22511,
31615,
12126,
14,
12293,
13,
7409,
199,
3,
3239,
4190,
14,
2424,
367,
4190,
2436,
199,
363,
1023,
363,
19938,
2672,
1304,
4,
1449,
199,
363,
1301,
363,
19070,
199,
199,
3,
17356,
12019,
63,
2864,
63,
10484,
199,
646,
984,
12,
1331,
12,
747,
199,
504,
21773,
14,
14156,
2279,
527,
492,
627,
199,
63,
11365,
63,
4014,
33,
29,
736,
14,
2314,
14,
362,
360,
11365,
63,
4014,
33,
1673,
16,
5832,
16,
61,
315,
661,
89,
1673,
57,
1673,
17,
358,
199,
63,
907,
5196,
1282,
29,
442,
8,
736,
14,
2314,
14,
362,
360,
907,
5196,
1282,
1673,
16,
1333,
199,
63,
28100,
29,
736,
14,
2314,
14,
362,
360,
28100,
1673,
16,
5832,
16,
61,
315,
661,
89,
1673,
57,
1673,
17,
358,
199,
692,
485,
11365,
63,
4014,
33,
26,
272,
347,
2235,
7109,
8,
83,
12,
2487,
304,
267,
687,
519,
274,
400,
345,
14,
9525,
1652,
14,
12227,
492,
2235,
7109,
465,
510,
7701,
48,
267,
372,
510,
7701,
48,
8,
83,
12,
2487,
9,
199,
199,
504,
21773,
14,
773,
14,
5260,
492,
315,
335,
199,
504,
21773,
14,
773,
14,
12955,
492,
664,
8176,
6609,
16715,
199,
504,
21773,
14,
773,
14,
19921,
492,
377,
33,
63,
9894,
12,
377,
33,
63,
12811,
12,
377,
33,
63,
17611,
12,
377,
33,
63,
42,
7698,
13367,
199,
199,
646,
21773,
14,
4308,
63,
888,
199,
3070,
5561,
14,
4308,
63,
888,
14,
262,
8759,
275,
413,
199,
199,
12955,
275,
664,
8176,
6609,
16715,
342,
199,
199,
6888,
275,
298,
1918,
593,
68,
588,
261,
89,
2,
199,
5949,
275,
298,
12054,
82,
2,
199,
199,
318,
3002,
6888,
3276,
8,
7682,
12,
1382,
304,
272,
10218,
14,
2117,
2223,
342,
272,
10218,
14,
8011,
2223,
342,
199,
199,
318,
3002,
22028,
17773,
8,
7682,
12,
1382,
304,
272,
10218,
14,
2117,
2223,
342,
272,
10218,
14,
24432,
360,
17687,
13,
50,
21604,
297,
25,
9,
272,
10218,
14,
5485,
1558,
8,
28494,
12,
378,
14,
2194,
627,
315,
335,
12,
298,
3276,
450,
68,
2,
450,
1382,
14,
1606,
9,
272,
10218,
14,
8011,
2223,
342,
199,
199,
318,
2621,
837,
272,
347,
3002,
15174,
23560,
8,
2324,
12663,
829,
304,
267,
687,
21773,
14,
5607,
2268,
14,
7682,
492,
29349,
267,
883,
86,
275,
29349,
8,
2324,
12663,
829,
9,
267,
327,
6554,
4154,
3233,
370,
314,
10218,
267,
883,
86,
14,
1662,
3314,
9654,
9956,
275,
3002,
3314,
9654,
9956,
267,
372,
883,
86,
339,
1382,
275,
3523,
3768,
4231,
360,
68,
364,
588,
261,
89,
14,
5607,
297,
2384,
19831,
29,
16,
9,
339,
327,
3302,
2787,
465,
367,
5870,
5060,
5564,
272,
2787,
52,
275,
11726,
8,
1301,
14,
3039,
15182,
12,
1382,
14,
8305,
15182,
12,
1382,
14,
2063,
12,
1382,
14,
3333,
12,
1305,
534,
3302,
358,
339,
327,
11467,
3626,
2346,
272,
2787,
17,
275,
11726,
8,
1301,
14,
3039,
15182,
12,
1382,
14,
8305,
15182,
12,
1382,
14,
2063,
15,
18,
13,
22,
12,
1382,
14,
3333,
12,
1305,
534,
761,
17,
358,
272,
2787,
18,
275,
11726,
8,
1301,
14,
3039,
15182,
11,
1301,
14,
2063,
15,
18,
11,
22,
12,
1382,
14,
8305,
15182,
12,
1382,
14,
2063,
15,
18,
13,
22,
12,
717,
1382,
14,
3333,
12,
1305,
534,
761,
18,
358,
272,
1382,
14,
525,
3276,
17969,
779,
3276,
4231,
8,
344,
534,
7147,
297,
8444,
29,
1943,
52,
12,
641,
3276,
29,
1662,
6888,
3276,
395,
717,
10331,
4231,
8,
344,
534,
4395,
2001,
297,
8444,
29,
1943,
52,
12,
641,
3276,
29,
1662,
22028,
17773,
395,
717,
10331,
4231,
8,
344,
534,
11467,
2001,
297,
8444,
1524,
1943,
17,
12,
1943,
18,
467,
641,
3276,
29,
1662,
22028,
17773,
395,
717,
4794,
272,
1382,
14,
1506,
8,
6255,
12,
7682,
14367,
29,
1662,
15174,
23560,
9,
199,
199,
6255,
275,
942,
199,
199,
30791,
6609,
275,
1331,
14,
8293,
8,
12955,
905,
23818,
17,
3135,
199,
30791,
6609,
14,
13699,
275,
377,
33,
63,
17611,
199,
30791,
6609,
14,
22124,
275,
4329,
199,
5733,
6609,
275,
1331,
14,
8293,
8,
30791,
6609,
9,
199,
5733,
6609,
14,
22124,
275,
3193,
199,
5733,
6609,
14,
16812,
275,
3388,
199,
2398,
6609,
275,
15725,
905,
3034,
937,
199,
199,
318,
892,
3276,
837,
272,
6566,
83,
14,
740,
8,
3276,
13948,
1012,
199,
199,
335,
5667,
275,
378,
199,
318,
3002,
3314,
9654,
9956,
8,
29185,
12,
5091,
12,
1302,
304,
272,
870,
283,
1662,
3314,
9654,
9956,
4042,
83,
3171,
5,
5091,
12,
283,
3276,
1329,
4009,
883,
86,
14,
27275,
3259,
1062,
283,
1302,
574,
4009,
1768,
199,
199,
318,
17044,
8,
2424,
12,
3449,
29,
30791,
6609,
304,
272,
2288,
682,
5667,
272,
6566,
83,
14,
740,
8,
5765,
3276,
4231,
360,
4395,
2001,
1333,
272,
892,
3276,
342,
272,
682,
5667,
847,
413,
272,
340,
485,
11365,
63,
4014,
33,
503,
440,
485,
28100,
26,
267,
6566,
83,
14,
740,
8,
24038,
8,
2424,
12,
3449,
430,
272,
587,
26,
267,
6566,
83,
14,
740,
8,
24038,
4725,
1421,
28,
265,
9654,
536,
628,
1662,
3314,
9654,
9956,
2,
1768,
628,
28765,
450,
68,
7897,
1543,
335,
5667,
6393,
2424,
12,
3449,
430,
272,
6566,
83,
14,
740,
8,
12739,
2247,
8,
16,
14,
18,
10,
28494,
12,
378,
14,
19,
10,
28494,
430,
272,
340,
675,
11467,
2001,
26,
267,
6566,
83,
14,
740,
8,
5765,
3276,
4231,
360,
11467,
2001,
1333,
199,
199,
318,
289,
6888,
8,
2424,
12,
2487,
29,
5733,
6609,
304,
272,
6566,
83,
14,
740,
8,
24038,
8,
2424,
12,
3449,
430,
199,
199,
28360,
6609,
275,
1331,
14,
8293,
8,
12955,
905,
6241,
3135,
199,
28360,
6609,
14,
2638,
13569,
275,
378,
14,
17,
10,
28494,
199,
692,
283,
1019,
7,
315,
984,
14,
3020,
26,
272,
2235,
65,
6609,
14,
13699,
275,
377,
33,
63,
12811,
199,
4164,
283,
3039,
7,
315,
984,
14,
3020,
26,
272,
2235,
65,
6609,
14,
13699,
275,
377,
33,
63,
9894,
199,
4164,
283,
4764,
2021,
7,
315,
984,
14,
3020,
26,
272,
2235,
65,
6609,
14,
13699,
275,
377
] |
[
7384,
11774,
22511,
31615,
12126,
14,
12293,
13,
7409,
199,
3,
3239,
4190,
14,
2424,
367,
4190,
2436,
199,
363,
1023,
363,
19938,
2672,
1304,
4,
1449,
199,
363,
1301,
363,
19070,
199,
199,
3,
17356,
12019,
63,
2864,
63,
10484,
199,
646,
984,
12,
1331,
12,
747,
199,
504,
21773,
14,
14156,
2279,
527,
492,
627,
199,
63,
11365,
63,
4014,
33,
29,
736,
14,
2314,
14,
362,
360,
11365,
63,
4014,
33,
1673,
16,
5832,
16,
61,
315,
661,
89,
1673,
57,
1673,
17,
358,
199,
63,
907,
5196,
1282,
29,
442,
8,
736,
14,
2314,
14,
362,
360,
907,
5196,
1282,
1673,
16,
1333,
199,
63,
28100,
29,
736,
14,
2314,
14,
362,
360,
28100,
1673,
16,
5832,
16,
61,
315,
661,
89,
1673,
57,
1673,
17,
358,
199,
692,
485,
11365,
63,
4014,
33,
26,
272,
347,
2235,
7109,
8,
83,
12,
2487,
304,
267,
687,
519,
274,
400,
345,
14,
9525,
1652,
14,
12227,
492,
2235,
7109,
465,
510,
7701,
48,
267,
372,
510,
7701,
48,
8,
83,
12,
2487,
9,
199,
199,
504,
21773,
14,
773,
14,
5260,
492,
315,
335,
199,
504,
21773,
14,
773,
14,
12955,
492,
664,
8176,
6609,
16715,
199,
504,
21773,
14,
773,
14,
19921,
492,
377,
33,
63,
9894,
12,
377,
33,
63,
12811,
12,
377,
33,
63,
17611,
12,
377,
33,
63,
42,
7698,
13367,
199,
199,
646,
21773,
14,
4308,
63,
888,
199,
3070,
5561,
14,
4308,
63,
888,
14,
262,
8759,
275,
413,
199,
199,
12955,
275,
664,
8176,
6609,
16715,
342,
199,
199,
6888,
275,
298,
1918,
593,
68,
588,
261,
89,
2,
199,
5949,
275,
298,
12054,
82,
2,
199,
199,
318,
3002,
6888,
3276,
8,
7682,
12,
1382,
304,
272,
10218,
14,
2117,
2223,
342,
272,
10218,
14,
8011,
2223,
342,
199,
199,
318,
3002,
22028,
17773,
8,
7682,
12,
1382,
304,
272,
10218,
14,
2117,
2223,
342,
272,
10218,
14,
24432,
360,
17687,
13,
50,
21604,
297,
25,
9,
272,
10218,
14,
5485,
1558,
8,
28494,
12,
378,
14,
2194,
627,
315,
335,
12,
298,
3276,
450,
68,
2,
450,
1382,
14,
1606,
9,
272,
10218,
14,
8011,
2223,
342,
199,
199,
318,
2621,
837,
272,
347,
3002,
15174,
23560,
8,
2324,
12663,
829,
304,
267,
687,
21773,
14,
5607,
2268,
14,
7682,
492,
29349,
267,
883,
86,
275,
29349,
8,
2324,
12663,
829,
9,
267,
327,
6554,
4154,
3233,
370,
314,
10218,
267,
883,
86,
14,
1662,
3314,
9654,
9956,
275,
3002,
3314,
9654,
9956,
267,
372,
883,
86,
339,
1382,
275,
3523,
3768,
4231,
360,
68,
364,
588,
261,
89,
14,
5607,
297,
2384,
19831,
29,
16,
9,
339,
327,
3302,
2787,
465,
367,
5870,
5060,
5564,
272,
2787,
52,
275,
11726,
8,
1301,
14,
3039,
15182,
12,
1382,
14,
8305,
15182,
12,
1382,
14,
2063,
12,
1382,
14,
3333,
12,
1305,
534,
3302,
358,
339,
327,
11467,
3626,
2346,
272,
2787,
17,
275,
11726,
8,
1301,
14,
3039,
15182,
12,
1382,
14,
8305,
15182,
12,
1382,
14,
2063,
15,
18,
13,
22,
12,
1382,
14,
3333,
12,
1305,
534,
761,
17,
358,
272,
2787,
18,
275,
11726,
8,
1301,
14,
3039,
15182,
11,
1301,
14,
2063,
15,
18,
11,
22,
12,
1382,
14,
8305,
15182,
12,
1382,
14,
2063,
15,
18,
13,
22,
12,
717,
1382,
14,
3333,
12,
1305,
534,
761,
18,
358,
272,
1382,
14,
525,
3276,
17969,
779,
3276,
4231,
8,
344,
534,
7147,
297,
8444,
29,
1943,
52,
12,
641,
3276,
29,
1662,
6888,
3276,
395,
717,
10331,
4231,
8,
344,
534,
4395,
2001,
297,
8444,
29,
1943,
52,
12,
641,
3276,
29,
1662,
22028,
17773,
395,
717,
10331,
4231,
8,
344,
534,
11467,
2001,
297,
8444,
1524,
1943,
17,
12,
1943,
18,
467,
641,
3276,
29,
1662,
22028,
17773,
395,
717,
4794,
272,
1382,
14,
1506,
8,
6255,
12,
7682,
14367,
29,
1662,
15174,
23560,
9,
199,
199,
6255,
275,
942,
199,
199,
30791,
6609,
275,
1331,
14,
8293,
8,
12955,
905,
23818,
17,
3135,
199,
30791,
6609,
14,
13699,
275,
377,
33,
63,
17611,
199,
30791,
6609,
14,
22124,
275,
4329,
199,
5733,
6609,
275,
1331,
14,
8293,
8,
30791,
6609,
9,
199,
5733,
6609,
14,
22124,
275,
3193,
199,
5733,
6609,
14,
16812,
275,
3388,
199,
2398,
6609,
275,
15725,
905,
3034,
937,
199,
199,
318,
892,
3276,
837,
272,
6566,
83,
14,
740,
8,
3276,
13948,
1012,
199,
199,
335,
5667,
275,
378,
199,
318,
3002,
3314,
9654,
9956,
8,
29185,
12,
5091,
12,
1302,
304,
272,
870,
283,
1662,
3314,
9654,
9956,
4042,
83,
3171,
5,
5091,
12,
283,
3276,
1329,
4009,
883,
86,
14,
27275,
3259,
1062,
283,
1302,
574,
4009,
1768,
199,
199,
318,
17044,
8,
2424,
12,
3449,
29,
30791,
6609,
304,
272,
2288,
682,
5667,
272,
6566,
83,
14,
740,
8,
5765,
3276,
4231,
360,
4395,
2001,
1333,
272,
892,
3276,
342,
272,
682,
5667,
847,
413,
272,
340,
485,
11365,
63,
4014,
33,
503,
440,
485,
28100,
26,
267,
6566,
83,
14,
740,
8,
24038,
8,
2424,
12,
3449,
430,
272,
587,
26,
267,
6566,
83,
14,
740,
8,
24038,
4725,
1421,
28,
265,
9654,
536,
628,
1662,
3314,
9654,
9956,
2,
1768,
628,
28765,
450,
68,
7897,
1543,
335,
5667,
6393,
2424,
12,
3449,
430,
272,
6566,
83,
14,
740,
8,
12739,
2247,
8,
16,
14,
18,
10,
28494,
12,
378,
14,
19,
10,
28494,
430,
272,
340,
675,
11467,
2001,
26,
267,
6566,
83,
14,
740,
8,
5765,
3276,
4231,
360,
11467,
2001,
1333,
199,
199,
318,
289,
6888,
8,
2424,
12,
2487,
29,
5733,
6609,
304,
272,
6566,
83,
14,
740,
8,
24038,
8,
2424,
12,
3449,
430,
199,
199,
28360,
6609,
275,
1331,
14,
8293,
8,
12955,
905,
6241,
3135,
199,
28360,
6609,
14,
2638,
13569,
275,
378,
14,
17,
10,
28494,
199,
692,
283,
1019,
7,
315,
984,
14,
3020,
26,
272,
2235,
65,
6609,
14,
13699,
275,
377,
33,
63,
12811,
199,
4164,
283,
3039,
7,
315,
984,
14,
3020,
26,
272,
2235,
65,
6609,
14,
13699,
275,
377,
33,
63,
9894,
199,
4164,
283,
4764,
2021,
7,
315,
984,
14,
3020,
26,
272,
2235,
65,
6609,
14,
13699,
275,
377,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shepdelacreme/ansible
|
test/units/modules/network/onyx/test_onyx_lldp.py
|
45
|
2396
|
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from units.compat.mock import patch
from ansible.modules.network.onyx import onyx_lldp
from units.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxInterfaceModule(TestOnyxModule):
module = onyx_lldp
def setUp(self):
super(TestOnyxInterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_lldp.OnyxLldpModule, "_get_lldp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if commands == ['lldp']:
self.get_config.return_value = None
else:
config_file = 'onyx_lldp_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_lldp_no_change(self):
set_module_args(dict())
self.execute_module(changed=False)
def test_lldp_disable(self):
set_module_args(dict(state='absent'))
commands = ['no lldp']
self.execute_module(changed=True, commands=commands)
def test_lldp_enable(self):
set_module_args(dict(state='present'))
commands = ['lldp']
self.execute_module(changed=True, commands=commands)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
5220,
88,
492,
641,
20937,
63,
24319,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
5220,
88,
63,
578,
492,
1379,
3314,
20937,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
3314,
20937,
4267,
2377,
8,
774,
3314,
20937,
2377,
304,
339,
859,
275,
641,
20937,
63,
24319,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
14,
785,
8,
288,
641,
20937,
63,
24319,
14,
3314,
20937,
44,
17288,
2377,
12,
2668,
362,
63,
24319,
63,
888,
531,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
8,
288,
283,
4853,
14,
578,
63,
1208,
14,
1200,
14,
5220,
88,
14,
5220,
88,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
12336,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
7773,
534,
2764,
735,
267,
340,
3718,
508,
788,
24319,
2565,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
488,
267,
587,
26,
288,
1101,
63,
493,
275,
283,
5220,
88,
63,
24319,
63,
2384,
14,
4128,
7,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
24319,
63,
889,
63,
1461,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
1012,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
797,
9,
339,
347,
511,
63,
24319,
63,
5993,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
5575,
1333,
267,
3718,
275,
788,
889,
28768,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
24319,
63,
4296,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
1881,
1333,
267,
3718,
275,
788,
24319,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
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
] |
[
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
5220,
88,
492,
641,
20937,
63,
24319,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
5220,
88,
63,
578,
492,
1379,
3314,
20937,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
3314,
20937,
4267,
2377,
8,
774,
3314,
20937,
2377,
304,
339,
859,
275,
641,
20937,
63,
24319,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
14,
785,
8,
288,
641,
20937,
63,
24319,
14,
3314,
20937,
44,
17288,
2377,
12,
2668,
362,
63,
24319,
63,
888,
531,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
8,
288,
283,
4853,
14,
578,
63,
1208,
14,
1200,
14,
5220,
88,
14,
5220,
88,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
12336,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
7773,
534,
2764,
735,
267,
340,
3718,
508,
788,
24319,
2565,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
488,
267,
587,
26,
288,
1101,
63,
493,
275,
283,
5220,
88,
63,
24319,
63,
2384,
14,
4128,
7,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
24319,
63,
889,
63,
1461,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
1012,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
797,
9,
339,
347,
511,
63,
24319,
63,
5993,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
5575,
1333,
267,
3718,
275,
788,
889,
28768,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
24319,
63,
4296,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
1881,
1333,
267,
3718,
275,
788,
24319,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gefangenimnetz/mopidy-nfcread
|
mopidy_nfcread/nfc/clf/transport.py
|
3
|
16326
|
# -*- coding: latin-1 -*-
# -----------------------------------------------------------------------------
# Copyright 2012-2015 Stephen Tiedemann <stephen.tiedemann@gmail.com>
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
# -----------------------------------------------------------------------------
#
# Transport layer for host to reader communication.
#
import logging
log = logging.getLogger(__name__)
import os, sys, re, errno, importlib
from binascii import hexlify
PATH = re.compile(r'^([a-z]+)(?::|)([a-zA-Z0-9]+|)(?::|)([a-zA-Z0-9]+|)$')
class TTY(object):
TYPE = "TTY"
@classmethod
def find(cls, path):
try:
cls.serial = importlib.import_module("serial")
except ImportError:
log.error("python serial library not found")
return None
match = PATH.match(path)
if match and match.group(1) == "tty":
import termios
if re.match(r'^\D+\d+$', match.group(2)):
TTYS = re.compile(r'^tty{0}$'.format(match.group(2)))
elif re.match(r'^\D+$', match.group(2)):
TTYS = re.compile(r'^tty{0}\d+$'.format(match.group(2)))
elif re.match(r'^$', match.group(2)):
TTYS = re.compile(r'^tty(S|ACM|AMA|USB)\d+$')
else:
log.error("invalid port in 'tty' path: %r", match.group(2))
return
ttys = [fn for fn in os.listdir('/dev') if TTYS.match(fn)]
if len(ttys) == 0: return
# Sort ttys with custom function to correctly order numbers.
ttys.sort(key=lambda s:"%s%3s"%(re.match('(\D+)(\d+)',s).groups()))
log.debug('trying /dev/tty%s', ' '.join([tty[3:] for tty in ttys]))
# Eliminate tty nodes that are not physically present or
# inaccessible by the current user. Propagate IOError when
# path designated exactly one device, otherwise just log.
for i, tty in enumerate(ttys):
try:
try: termios.tcgetattr(open('/dev/%s' % tty))
except termios.error: pass
else: ttys[i] = '/dev/%s' % tty
except IOError as error:
if not TTYS.pattern.endswith(r'\d+$'): raise
else: log.debug(error)
ttys = [tty for tty in ttys if tty.startswith('/dev/')]
log.debug('avail: %s', ' '.join([tty for tty in ttys]))
return ttys, match.group(3), TTYS.pattern.endswith(r'\d+$')
if match and match.group(1) == "com":
if re.match(r'^COM\d+$', match.group(2)):
return [match.group(2)], match.group(3), False
if re.match(r'^\d+$', match.group(2)):
return ["COM" + match.group(2)], match.group(3), False
if re.match(r'^$', match.group(2)):
import serial.tools.list_ports
ports = [p[0] for p in serial.tools.list_ports.comports()]
log.debug('serial ports: %s', ' '.join([p for p in ports]))
return ports, match.group(3), True
log.error("invalid port in 'com' path: %r", match.group(2))
@property
def manufacturer_name(self):
return None
@property
def product_name(self):
return None
def __init__(self, port=None):
self.tty = None
self.open(port)
def open(self, port, baudrate=115200):
self.close()
self.tty = self.serial.Serial(port, baudrate, timeout=0.05)
@property
def port(self):
return self.tty.port if self.tty else ''
@property
def baudrate(self):
return self.tty.baudrate if self.tty else 0
@baudrate.setter
def baudrate(self, value):
if self.tty:
self.tty.baudrate = value
def read(self, timeout):
if self.tty is not None:
self.tty.timeout = max(timeout/1E3, 0.05)
frame = bytearray(self.tty.read(6))
if frame is None or len(frame) == 0:
raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
if frame.startswith("\x00\x00\xff\x00\xff\x00"):
log.log(logging.DEBUG-1, "<<< %s", str(frame).encode("hex"))
return frame
LEN = frame[3]
if LEN == 0xFF:
frame += self.tty.read(3)
LEN = frame[5]<<8 | frame[6]
frame += self.tty.read(LEN + 1)
log.log(logging.DEBUG-1, "<<< %s", str(frame).encode("hex"))
return frame
def write(self, frame):
if self.tty is not None:
log.log(logging.DEBUG-1, ">>> %s", str(frame).encode("hex"))
self.tty.flushInput()
try:
self.tty.write(str(frame))
except self.serial.SerialTimeoutException:
raise IOError(errno.EIO, os.strerror(errno.EIO))
def close(self):
if self.tty is not None:
self.tty.flushOutput()
self.tty.close()
self.tty = None
class USB(object):
TYPE = "USB"
@classmethod
def find(cls, path):
if not path.startswith("usb"):
return
cls.pyusb_version = None
try:
cls.usb_core = importlib.import_module("usb.core")
cls.usb_util = importlib.import_module("usb.util")
cls.pyusb_version = 1
except ImportError: pass
if cls.pyusb_version is None:
try:
cls.usb = importlib.import_module("usb")
cls.pyusb_version = 0
except ImportError: pass
if cls.pyusb_version is None:
log.error("python usb library not found")
return None
log.debug("using pyusb version {0}.x".format(cls.pyusb_version))
usb_or_none = re.compile(r'^(usb|)$')
usb_vid_pid = re.compile(r'^usb(:[0-9a-fA-F]{4})(:[0-9a-fA-F]{4})?$')
usb_bus_dev = re.compile(r'^usb(:[0-9]{1,3})(:[0-9]{1,3})?$')
match = None
for regex in (usb_vid_pid, usb_bus_dev, usb_or_none):
m = regex.match(path)
if m is not None:
log.debug("path matches {0!r}".format(regex.pattern))
if regex is usb_vid_pid:
match = [int(s.strip(':'), 16) for s in m.groups() if s]
match = dict(zip(['idVendor', 'idProduct'], match))
if regex is usb_bus_dev:
match = [int(s.strip(':'), 10) for s in m.groups() if s]
match = dict(zip(['bus', 'address'], match))
if regex is usb_or_none:
match = dict()
break
else: return None
if cls.pyusb_version == 1:
return [(d.idVendor, d.idProduct, d.bus, d.address)
for d in cls.usb_core.find(find_all=True, **match)]
if cls.pyusb_version == 0:
# get all devices for all busses first, then filter
devices = [(d, b) for b in cls.usb.busses() for d in b.devices]
vid, pid = match.get('idVendor'), match.get('idProduct')
bus, dev = match.get('bus'), match.get('address')
if vid is not None:
devices = [d for d in devices if d[0].idVendor == vid]
if pid is not None:
devices = [d for d in devices if d[0].idProduct == pid]
if bus is not None:
devices = [d for d in devices if int(d[1].dirname) == bus]
if dev is not None:
devices = [d for d in devices if int(d[0].filename) == dev]
return [(d[0].idVendor, d[0].idProduct, d[1].dirname,
d[0].filename) for d in devices]
def __init__(self, bus_id, dev_id):
self.usb_out = None
self.usb_inp = None
if self.pyusb_version == 0:
self.open = self._PYUSB0_open
self.read = self._PYUSB0_read
self.write = self._PYUSB0_write
self.close = self._PYUSB0_close
self.get_string = self._PYUSB0_get_string
elif self.pyusb_version == 1:
self.open = self._PYUSB1_open
self.read = self._PYUSB1_read
self.write = self._PYUSB1_write
self.close = self._PYUSB1_close
self.get_string = self._PYUSB1_get_string
else:
log.error("unexpected pyusb version")
raise SystemExit
self.open(bus_id, dev_id)
@property
def manufacturer_name(self):
if self.manufacturer_name_id:
return self.get_string(self.manufacturer_name_id)
@property
def product_name(self):
if self.product_name_id:
return self.get_string(self.product_name_id)
def _PYUSB0_get_string(self, index, langid=-1):
return self.usb_dev.getString(index, 126, langid)
def _PYUSB1_get_string(self, index, langid=None):
# Prior to version 1.0.0b2 pyusb's' util.get_string() needed a
# length parameter which has since been removed. The try/except
# clause helps support older versions until pyusb 1.0.0 is
# finally released and sufficiently spread.
try:
return self.usb_util.get_string(self.usb_dev, index, langid)
except TypeError:
return self.usb_util.get_string(self.usb_dev, 126, index, langid)
def _PYUSB0_open(self, bus_id, dev_id):
bus = [b for b in self.usb.busses() if b.dirname == bus_id][0]
dev = [d for d in bus.devices if d.filename == dev_id][0]
self.usb_dev = dev.open()
if sys.platform.startswith("darwin"):
self.usb_dev.setConfiguration(dev.configurations[0])
try:
self.usb_dev.claimInterface(0)
except self.usb.USBError:
raise IOError(errno.EBUSY, os.strerror(errno.EBUSY))
interface = dev.configurations[0].interfaces[0]
endpoints = interface[0].endpoints
bulk_inp = lambda ep: (\
(ep.type == self.usb.ENDPOINT_TYPE_BULK) and
(ep.address & self.usb.ENDPOINT_DIR_MASK == self.usb.ENDPOINT_IN))
bulk_out = lambda ep: (\
(ep.type == self.usb.ENDPOINT_TYPE_BULK) and
(ep.address & self.usb.ENDPOINT_DIR_MASK == self.usb.ENDPOINT_OUT))
self.usb_out = [ep for ep in endpoints if bulk_out(ep)].pop().address
self.usb_inp = [ep for ep in endpoints if bulk_inp(ep)].pop().address
self.manufacturer_name_id = dev.iManufacturer
self.product_name_id = dev.iProduct
def _PYUSB1_open(self, bus_id, dev_id):
self.usb_dev = self.usb_core.find(bus=bus_id, address=dev_id)
if sys.platform.startswith("darwin"):
self.usb_dev.set_configuration()
interface = self.usb_util.find_descriptor(self.usb_dev[0])
bulk_inp = lambda ep: (\
(self.usb_util.endpoint_type(ep.bmAttributes) ==
self.usb_util.ENDPOINT_TYPE_BULK) and
(self.usb_util.endpoint_direction(ep.bEndpointAddress) ==
self.usb_util.ENDPOINT_IN))
bulk_out = lambda ep: (\
(self.usb_util.endpoint_type(ep.bmAttributes) ==
self.usb_util.ENDPOINT_TYPE_BULK) and
(self.usb_util.endpoint_direction(ep.bEndpointAddress) ==
self.usb_util.ENDPOINT_OUT))
self.usb_out = [ep for ep in interface if bulk_out(ep)].pop()
self.usb_inp = [ep for ep in interface if bulk_inp(ep)].pop()
try:
# implicitely claim interface
self.usb_out.write('')
except self.usb_core.USBError:
raise IOError(errno.EBUSY, os.strerror(errno.EBUSY))
self.manufacturer_name_id = self.usb_dev.iManufacturer
self.product_name_id = self.usb_dev.iProduct
def _PYUSB0_read(self, timeout=None):
if self.usb_inp is not None:
while timeout is None or timeout > 0:
try:
poll_wait = 444 if timeout is None else min(500, timeout)
frame = self.usb_dev.bulkRead(self.usb_inp, 300, poll_wait)
except self.usb.USBError as error:
if str(error) != "Connection timed out":
log.error("%r", error)
raise IOError(errno.EIO, os.strerror(errno.EIO))
if timeout is not None:
timeout -= poll_wait
else:
if not frame:
log.error("bulk read returned without data")
raise IOError(errno.EIO, os.strerror(errno.EIO))
else:
frame = bytearray(frame)
log.log(logging.DEBUG-1, "<<< %s", hexlify(frame))
return frame
else:
raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
def _PYUSB1_read(self, timeout=None):
if self.usb_inp is not None:
while timeout is None or timeout > 0:
try:
poll_wait = 500 if timeout is None else min(500, timeout)
frame = self.usb_inp.read(300, poll_wait)
except self.usb_core.USBError as error:
if error.errno != errno.ETIMEDOUT:
log.error("%r", error)
raise IOError(error.errno, error.strerror)
if timeout is not None:
timeout -= poll_wait
else:
if not frame:
log.error("bulk read returned without data")
raise IOError(errno.EIO, os.strerror(errno.EIO))
else:
frame = bytearray(frame)
log.log(logging.DEBUG-1, "<<< %s", hexlify(frame))
return frame
else:
raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
def _PYUSB0_write(self, frame):
if self.usb_out is not None:
log.log(logging.DEBUG-1, ">>> %s", hexlify(frame))
try:
self.usb_dev.bulkWrite(self.usb_out, frame)
if len(frame) % 64 == 0: # end bulk transfer
self.usb_dev.bulkWrite(self.usb_out, '')
except self.usb.USBError as error:
if error.message == "Connection timed out":
ETIMEDOUT = errno.ETIMEDOUT
raise IOError(ETIMEDOUT, os.strerror(ETIMEDOUT))
else:
log.error("%r", error)
raise IOError(errno.EIO, os.strerror(errno.EIO))
def _PYUSB1_write(self, frame):
if self.usb_out is not None:
log.log(logging.DEBUG-1, ">>> %s", hexlify(frame))
try:
self.usb_out.write(frame)
if len(frame) % self.usb_out.wMaxPacketSize == 0:
self.usb_out.write('') # end bulk transfer
except self.usb_core.USBError as error:
if error.errno != errno.ETIMEDOUT:
log.error("%r", error)
raise IOError(error.errno, error.strerror)
def _PYUSB0_close(self):
if self.usb_dev is not None:
self.usb_dev.releaseInterface()
self.usb_dev = self.usb_out = self.usb_inp = None
def _PYUSB1_close(self):
if self.usb_dev is not None:
self.usb_util.dispose_resources(self.usb_dev)
self.usb_dev = self.usb_out = self.usb_inp = None
|
apache-2.0
|
[
3,
1882,
2803,
26,
16899,
13,
17,
1882,
199,
3,
13722,
199,
3,
1898,
6029,
13,
7806,
17854,
17579,
377,
1873,
271,
20059,
665,
1597,
17579,
14,
23958,
271,
20059,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
3909,
1334,
314,
662,
2160,
44,
12,
3394,
413,
14,
17,
503,
446,
465,
18930,
2985,
221,
199,
3,
911,
506,
30055,
701,
314,
31615,
290,
7046,
27973,
446,
13372,
199,
3,
5459,
402,
314,
662,
2160,
44,
334,
1589,
298,
44,
530,
4894,
3547,
199,
3,
2047,
1443,
440,
675,
642,
1736,
871,
315,
4151,
543,
314,
199,
3,
491,
530,
4894,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
491,
530,
4894,
737,
26,
199,
3,
199,
3,
1455,
921,
1544,
14,
736,
269,
14,
16913,
15,
69,
384,
76,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
199,
3,
3575,
12,
2032,
1854,
1334,
314,
491,
530,
4894,
365,
199,
3,
1854,
641,
376,
298,
1179,
2281,
2,
5597,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
199,
3,
4056,
503,
2478,
14,
199,
3,
1666,
314,
491,
530,
4894,
367,
314,
2488,
2637,
4210,
199,
3,
3443,
436,
4204,
1334,
314,
491,
530,
4894,
14,
199,
3,
13722,
199,
3,
199,
3,
27018,
4045,
367,
1591,
370,
7002,
23506,
14,
199,
3,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
646,
747,
12,
984,
12,
295,
12,
7554,
12,
14802,
199,
504,
14755,
492,
6318,
8209,
199,
199,
3243,
275,
295,
14,
2014,
8,
82,
4289,
779,
65,
13,
90,
11896,
2229,
447,
92,
31440,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
92,
18168,
447,
92,
31440,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
92,
9,
9988,
199,
199,
533,
377,
2099,
8,
785,
304,
272,
11511,
275,
298,
1481,
57,
2,
2286,
768,
3744,
272,
347,
2342,
8,
1886,
12,
931,
304,
267,
862,
26,
288,
843,
14,
2171,
275,
14802,
14,
646,
63,
578,
480,
2171,
531,
267,
871,
3545,
26,
288,
943,
14,
705,
480,
1548,
3012,
3555,
440,
1911,
531,
288,
372,
488,
2728,
1336,
275,
15097,
14,
1431,
8,
515,
9,
2728,
340,
1336,
436,
1336,
14,
923,
8,
17,
9,
508,
298,
4707,
582,
288,
492,
28725,
288,
340,
295,
14,
1431,
8,
82,
15542,
36,
7896,
68,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
377,
2099,
51,
275,
295,
14,
2014,
8,
82,
4289,
4707,
91,
16,
93,
4,
1370,
908,
8,
1431,
14,
923,
8,
18,
1724,
288,
916,
295,
14,
1431,
8,
82,
15542,
36,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
377,
2099,
51,
275,
295,
14,
2014,
8,
82,
4289,
4707,
91,
16,
4988,
68,
11,
4,
1370,
908,
8,
1431,
14,
923,
8,
18,
1724,
288,
916,
295,
14,
1431,
8,
82,
4289,
4268,
1336,
14,
923,
8,
18,
2298,
355,
377,
2099,
51,
275,
295,
14,
2014,
8,
82,
4289,
4707,
8,
51,
92,
1348,
45,
92,
1156,
33,
92,
19919,
2862,
68,
11,
9988,
288,
587,
26,
355,
943,
14,
705,
480,
3197,
1844,
315,
283,
4707,
7,
931,
26,
450,
82,
401,
1336,
14,
923,
8,
18,
430,
355,
372,
7846,
21862,
83,
275,
359,
2324,
367,
4325,
315,
747,
14,
7374,
2336,
2374,
358,
340,
377,
2099,
51,
14,
1431,
8,
2324,
1874,
288,
340,
822,
8,
4707,
83,
9,
508,
378,
26,
372,
953,
327,
16722,
21862,
83,
543,
3537,
805,
370,
6657,
1865,
5579,
14,
288,
21862,
83,
14,
3191,
8,
498,
29,
2734,
308,
5424,
5,
83,
5,
19,
83,
14007,
264,
14,
1431,
360,
2961,
36,
27860,
68,
14705,
83,
680,
2634,
4059,
288,
943,
14,
1757,
360,
893,
316,
1182,
2374,
15,
4707,
5,
83,
297,
283,
1987,
904,
779,
4707,
59,
19,
2938,
367,
21862,
315,
21862,
83,
2459,
953,
327,
662,
13769,
323,
21862,
3380,
626,
787,
440,
11831,
9916,
1183,
3451,
503,
288,
327,
315,
24669,
701,
314,
1453,
922,
14,
2165,
12563,
5925,
1380,
288,
327,
931,
12899,
972,
8840,
1373,
2243,
12,
4257,
2951,
943,
14,
288,
367,
284,
12,
21862,
315,
3874,
8,
4707,
83,
304,
355,
862,
26,
490,
862,
26,
28725,
14,
3641,
5675,
8,
1490,
2336,
2374,
3149,
83,
7,
450,
21862,
430,
490,
871,
28725,
14,
705,
26,
986,
490,
587,
26,
21862,
83,
59,
73,
61,
275,
1994,
2374,
3149,
83,
7,
450,
21862,
355,
871,
5925,
465,
1125,
26,
490,
340,
440,
377,
2099,
51,
14,
3401,
14,
4130,
8,
82,
1154,
68,
11,
4,
735,
746,
490,
587,
26,
943,
14,
1757,
8,
705,
9,
953,
21862,
83,
275,
359,
4707,
367,
21862,
315,
21862,
83,
340,
21862,
14,
2460,
2336,
2374,
15,
5440,
288,
943,
14,
1757,
360,
18961,
26,
450,
83,
297,
283,
1987,
904,
779,
4707,
367,
21862,
315,
21862,
83,
2459,
288,
372,
21862,
83,
12,
1336,
14,
923,
8,
19,
395,
377,
2099,
51,
14,
3401,
14,
4130,
8,
82,
1154,
68,
11,
9988,
2728,
340,
1336,
436,
1336,
14,
923,
8,
17,
9,
508,
298,
957,
582,
288,
340,
295,
14,
1431,
8,
82,
4289,
11265,
60,
68,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
372,
359,
1431,
14,
923,
8,
18,
4360,
1336,
14,
923,
8,
19,
395,
756,
288,
340,
295,
14,
1431,
8,
82,
15542,
68,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
372,
2097,
11265,
2,
435,
1336,
14,
923,
8,
18,
4360,
1336,
14,
923,
8,
19,
395,
756,
288,
340,
295,
14,
1431,
8,
82,
4289,
4268,
1336,
14,
923,
8,
18,
2298,
355,
492,
3012,
14,
2537,
14,
513,
63,
5203,
355,
8873,
275,
359,
80,
59,
16,
61,
367,
299,
315,
3012,
14,
2537,
14,
513,
63,
5203,
14,
331,
412,
83,
5106,
355,
943,
14,
1757,
360,
2171,
8873,
26,
450,
83,
297,
283,
1987,
904,
779,
80,
367,
299,
315,
8873,
2459,
355,
372,
8873,
12,
1336,
14,
923,
8,
19,
395,
715,
288,
943,
14,
705,
480,
3197,
1844,
315,
283,
957,
7,
931,
26,
450,
82,
401,
1336,
14,
923
] |
[
1882,
2803,
26,
16899,
13,
17,
1882,
199,
3,
13722,
199,
3,
1898,
6029,
13,
7806,
17854,
17579,
377,
1873,
271,
20059,
665,
1597,
17579,
14,
23958,
271,
20059,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
3909,
1334,
314,
662,
2160,
44,
12,
3394,
413,
14,
17,
503,
446,
465,
18930,
2985,
221,
199,
3,
911,
506,
30055,
701,
314,
31615,
290,
7046,
27973,
446,
13372,
199,
3,
5459,
402,
314,
662,
2160,
44,
334,
1589,
298,
44,
530,
4894,
3547,
199,
3,
2047,
1443,
440,
675,
642,
1736,
871,
315,
4151,
543,
314,
199,
3,
491,
530,
4894,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
491,
530,
4894,
737,
26,
199,
3,
199,
3,
1455,
921,
1544,
14,
736,
269,
14,
16913,
15,
69,
384,
76,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
199,
3,
3575,
12,
2032,
1854,
1334,
314,
491,
530,
4894,
365,
199,
3,
1854,
641,
376,
298,
1179,
2281,
2,
5597,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
199,
3,
4056,
503,
2478,
14,
199,
3,
1666,
314,
491,
530,
4894,
367,
314,
2488,
2637,
4210,
199,
3,
3443,
436,
4204,
1334,
314,
491,
530,
4894,
14,
199,
3,
13722,
199,
3,
199,
3,
27018,
4045,
367,
1591,
370,
7002,
23506,
14,
199,
3,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
646,
747,
12,
984,
12,
295,
12,
7554,
12,
14802,
199,
504,
14755,
492,
6318,
8209,
199,
199,
3243,
275,
295,
14,
2014,
8,
82,
4289,
779,
65,
13,
90,
11896,
2229,
447,
92,
31440,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
92,
18168,
447,
92,
31440,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
92,
9,
9988,
199,
199,
533,
377,
2099,
8,
785,
304,
272,
11511,
275,
298,
1481,
57,
2,
2286,
768,
3744,
272,
347,
2342,
8,
1886,
12,
931,
304,
267,
862,
26,
288,
843,
14,
2171,
275,
14802,
14,
646,
63,
578,
480,
2171,
531,
267,
871,
3545,
26,
288,
943,
14,
705,
480,
1548,
3012,
3555,
440,
1911,
531,
288,
372,
488,
2728,
1336,
275,
15097,
14,
1431,
8,
515,
9,
2728,
340,
1336,
436,
1336,
14,
923,
8,
17,
9,
508,
298,
4707,
582,
288,
492,
28725,
288,
340,
295,
14,
1431,
8,
82,
15542,
36,
7896,
68,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
377,
2099,
51,
275,
295,
14,
2014,
8,
82,
4289,
4707,
91,
16,
93,
4,
1370,
908,
8,
1431,
14,
923,
8,
18,
1724,
288,
916,
295,
14,
1431,
8,
82,
15542,
36,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
377,
2099,
51,
275,
295,
14,
2014,
8,
82,
4289,
4707,
91,
16,
4988,
68,
11,
4,
1370,
908,
8,
1431,
14,
923,
8,
18,
1724,
288,
916,
295,
14,
1431,
8,
82,
4289,
4268,
1336,
14,
923,
8,
18,
2298,
355,
377,
2099,
51,
275,
295,
14,
2014,
8,
82,
4289,
4707,
8,
51,
92,
1348,
45,
92,
1156,
33,
92,
19919,
2862,
68,
11,
9988,
288,
587,
26,
355,
943,
14,
705,
480,
3197,
1844,
315,
283,
4707,
7,
931,
26,
450,
82,
401,
1336,
14,
923,
8,
18,
430,
355,
372,
7846,
21862,
83,
275,
359,
2324,
367,
4325,
315,
747,
14,
7374,
2336,
2374,
358,
340,
377,
2099,
51,
14,
1431,
8,
2324,
1874,
288,
340,
822,
8,
4707,
83,
9,
508,
378,
26,
372,
953,
327,
16722,
21862,
83,
543,
3537,
805,
370,
6657,
1865,
5579,
14,
288,
21862,
83,
14,
3191,
8,
498,
29,
2734,
308,
5424,
5,
83,
5,
19,
83,
14007,
264,
14,
1431,
360,
2961,
36,
27860,
68,
14705,
83,
680,
2634,
4059,
288,
943,
14,
1757,
360,
893,
316,
1182,
2374,
15,
4707,
5,
83,
297,
283,
1987,
904,
779,
4707,
59,
19,
2938,
367,
21862,
315,
21862,
83,
2459,
953,
327,
662,
13769,
323,
21862,
3380,
626,
787,
440,
11831,
9916,
1183,
3451,
503,
288,
327,
315,
24669,
701,
314,
1453,
922,
14,
2165,
12563,
5925,
1380,
288,
327,
931,
12899,
972,
8840,
1373,
2243,
12,
4257,
2951,
943,
14,
288,
367,
284,
12,
21862,
315,
3874,
8,
4707,
83,
304,
355,
862,
26,
490,
862,
26,
28725,
14,
3641,
5675,
8,
1490,
2336,
2374,
3149,
83,
7,
450,
21862,
430,
490,
871,
28725,
14,
705,
26,
986,
490,
587,
26,
21862,
83,
59,
73,
61,
275,
1994,
2374,
3149,
83,
7,
450,
21862,
355,
871,
5925,
465,
1125,
26,
490,
340,
440,
377,
2099,
51,
14,
3401,
14,
4130,
8,
82,
1154,
68,
11,
4,
735,
746,
490,
587,
26,
943,
14,
1757,
8,
705,
9,
953,
21862,
83,
275,
359,
4707,
367,
21862,
315,
21862,
83,
340,
21862,
14,
2460,
2336,
2374,
15,
5440,
288,
943,
14,
1757,
360,
18961,
26,
450,
83,
297,
283,
1987,
904,
779,
4707,
367,
21862,
315,
21862,
83,
2459,
288,
372,
21862,
83,
12,
1336,
14,
923,
8,
19,
395,
377,
2099,
51,
14,
3401,
14,
4130,
8,
82,
1154,
68,
11,
9988,
2728,
340,
1336,
436,
1336,
14,
923,
8,
17,
9,
508,
298,
957,
582,
288,
340,
295,
14,
1431,
8,
82,
4289,
11265,
60,
68,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
372,
359,
1431,
14,
923,
8,
18,
4360,
1336,
14,
923,
8,
19,
395,
756,
288,
340,
295,
14,
1431,
8,
82,
15542,
68,
11,
4268,
1336,
14,
923,
8,
18,
2298,
355,
372,
2097,
11265,
2,
435,
1336,
14,
923,
8,
18,
4360,
1336,
14,
923,
8,
19,
395,
756,
288,
340,
295,
14,
1431,
8,
82,
4289,
4268,
1336,
14,
923,
8,
18,
2298,
355,
492,
3012,
14,
2537,
14,
513,
63,
5203,
355,
8873,
275,
359,
80,
59,
16,
61,
367,
299,
315,
3012,
14,
2537,
14,
513,
63,
5203,
14,
331,
412,
83,
5106,
355,
943,
14,
1757,
360,
2171,
8873,
26,
450,
83,
297,
283,
1987,
904,
779,
80,
367,
299,
315,
8873,
2459,
355,
372,
8873,
12,
1336,
14,
923,
8,
19,
395,
715,
288,
943,
14,
705,
480,
3197,
1844,
315,
283,
957,
7,
931,
26,
450,
82,
401,
1336,
14,
923,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dimagi/rapidsms-threadless-router
|
threadless_router/backends/http/tests.py
|
2
|
1963
|
from django.conf import settings
from django.test import TestCase, RequestFactory
from django.core.urlresolvers import reverse
from threadless_router.backends.http import views
from threadless_router.backends.http.forms import BaseHttpForm
class HttpTest(TestCase):
urls = 'threadless_router.backends.http.urls'
def setUp(self):
self.rf = RequestFactory()
self.url = reverse('simple-http', args=['simple-http'])
self.conf = {'incoming_identity': 'phone',
'incoming_text': 'message'}
self.view = views.SimpleHttpBackendView.as_view(conf=self.conf)
def _post(self, data={}):
request = self.rf.post(self.url, data)
return self.view(request, backend_name='simple-http')
def test_valid_form(self):
""" Form should be valid if POST keys match configuration """
view = views.SimpleHttpBackendView(conf=self.conf)
data = {'phone': '1112223333', 'message': 'hi there'}
view.request = self.rf.post(self.url, data)
form = view.get_form(view.get_form_class())
self.assertTrue(form.is_valid())
def test_invalid_form(self):
""" Form is invalid if POST keys don't match configuration """
view = views.SimpleHttpBackendView(conf=self.conf)
data = {'invalid-phone': '1112223333', 'invalid-message': 'hi there'}
view.request = self.rf.post(self.url, data)
form = view.get_form(view.get_form_class())
self.assertFalse(form.is_valid())
def test_invalid_response(self):
""" HTTP 400 should return if form is invalid """
data = {'invalid-phone': '1112223333', 'message': 'hi there'}
response = self._post(data)
self.assertEqual(response.status_code, 400)
def test_get_incoming_data(self):
""" Subclasses must implement get_incoming_data """
form = BaseHttpForm()
self.assertRaises(NotImplementedError, form.get_incoming_data)
|
bsd-3-clause
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
396,
492,
7640,
12,
18638,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
2462,
2003,
63,
4995,
14,
7765,
14,
1014,
492,
6858,
199,
504,
2462,
2003,
63,
4995,
14,
7765,
14,
1014,
14,
3351,
492,
3523,
5779,
2821,
421,
199,
533,
4760,
774,
8,
1746,
304,
339,
8187,
275,
283,
2671,
2003,
63,
4995,
14,
7765,
14,
1014,
14,
3603,
7,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3941,
275,
18638,
342,
267,
291,
14,
633,
275,
3837,
360,
4129,
13,
1014,
297,
1249,
2968,
4129,
13,
1014,
1105,
267,
291,
14,
2190,
275,
791,
15994,
63,
5582,
356,
283,
9339,
297,
2151,
283,
15994,
63,
505,
356,
283,
1188,
936,
267,
291,
14,
1345,
275,
6858,
14,
3184,
5779,
8447,
2768,
14,
305,
63,
1345,
8,
2190,
29,
277,
14,
2190,
9,
339,
347,
485,
1932,
8,
277,
12,
666,
16420,
267,
1056,
275,
291,
14,
3941,
14,
1932,
8,
277,
14,
633,
12,
666,
9,
267,
372,
291,
14,
1345,
8,
1069,
12,
4865,
63,
354,
534,
4129,
13,
1014,
358,
339,
347,
511,
63,
1078,
63,
964,
8,
277,
304,
267,
408,
8204,
1077,
506,
1686,
340,
8761,
2883,
1336,
2897,
408,
267,
2455,
275,
6858,
14,
3184,
5779,
8447,
2768,
8,
2190,
29,
277,
14,
2190,
9,
267,
666,
275,
791,
9339,
356,
283,
31558,
1081,
6772,
297,
283,
1188,
356,
283,
5812,
2337,
936,
267,
2455,
14,
1069,
275,
291,
14,
3941,
14,
1932,
8,
277,
14,
633,
12,
666,
9,
267,
1824,
275,
2455,
14,
362,
63,
964,
8,
1345,
14,
362,
63,
964,
63,
533,
1012,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
339,
347,
511,
63,
3197,
63,
964,
8,
277,
304,
267,
408,
8204,
365,
3866,
340,
8761,
2883,
2793,
1133,
1336,
2897,
408,
267,
2455,
275,
6858,
14,
3184,
5779,
8447,
2768,
8,
2190,
29,
277,
14,
2190,
9,
267,
666,
275,
791,
3197,
13,
9339,
356,
283,
31558,
1081,
6772,
297,
283,
3197,
13,
1188,
356,
283,
5812,
2337,
936,
267,
2455,
14,
1069,
275,
291,
14,
3941,
14,
1932,
8,
277,
14,
633,
12,
666,
9,
267,
1824,
275,
2455,
14,
362,
63,
964,
8,
1345,
14,
362,
63,
964,
63,
533,
1012,
267,
291,
14,
3334,
8,
964,
14,
374,
63,
1078,
1012,
339,
347,
511,
63,
3197,
63,
1310,
8,
277,
304,
267,
408,
3101,
8290,
1077,
372,
340,
1824,
365,
3866,
408,
267,
666,
275,
791,
3197,
13,
9339,
356,
283,
31558,
1081,
6772,
297,
283,
1188,
356,
283,
5812,
2337,
936,
267,
1177,
275,
291,
423,
1932,
8,
576,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
362,
63,
15994,
63,
576,
8,
277,
304,
267,
408,
20196,
1471,
5669,
664,
63,
15994,
63,
576,
408,
267,
1824,
275,
3523,
5779,
2821,
342,
267,
291,
14,
1855,
8,
18097,
12,
1824,
14,
362,
63,
15994,
63,
576,
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
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
396,
492,
7640,
12,
18638,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
2462,
2003,
63,
4995,
14,
7765,
14,
1014,
492,
6858,
199,
504,
2462,
2003,
63,
4995,
14,
7765,
14,
1014,
14,
3351,
492,
3523,
5779,
2821,
421,
199,
533,
4760,
774,
8,
1746,
304,
339,
8187,
275,
283,
2671,
2003,
63,
4995,
14,
7765,
14,
1014,
14,
3603,
7,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3941,
275,
18638,
342,
267,
291,
14,
633,
275,
3837,
360,
4129,
13,
1014,
297,
1249,
2968,
4129,
13,
1014,
1105,
267,
291,
14,
2190,
275,
791,
15994,
63,
5582,
356,
283,
9339,
297,
2151,
283,
15994,
63,
505,
356,
283,
1188,
936,
267,
291,
14,
1345,
275,
6858,
14,
3184,
5779,
8447,
2768,
14,
305,
63,
1345,
8,
2190,
29,
277,
14,
2190,
9,
339,
347,
485,
1932,
8,
277,
12,
666,
16420,
267,
1056,
275,
291,
14,
3941,
14,
1932,
8,
277,
14,
633,
12,
666,
9,
267,
372,
291,
14,
1345,
8,
1069,
12,
4865,
63,
354,
534,
4129,
13,
1014,
358,
339,
347,
511,
63,
1078,
63,
964,
8,
277,
304,
267,
408,
8204,
1077,
506,
1686,
340,
8761,
2883,
1336,
2897,
408,
267,
2455,
275,
6858,
14,
3184,
5779,
8447,
2768,
8,
2190,
29,
277,
14,
2190,
9,
267,
666,
275,
791,
9339,
356,
283,
31558,
1081,
6772,
297,
283,
1188,
356,
283,
5812,
2337,
936,
267,
2455,
14,
1069,
275,
291,
14,
3941,
14,
1932,
8,
277,
14,
633,
12,
666,
9,
267,
1824,
275,
2455,
14,
362,
63,
964,
8,
1345,
14,
362,
63,
964,
63,
533,
1012,
267,
291,
14,
1815,
8,
964,
14,
374,
63,
1078,
1012,
339,
347,
511,
63,
3197,
63,
964,
8,
277,
304,
267,
408,
8204,
365,
3866,
340,
8761,
2883,
2793,
1133,
1336,
2897,
408,
267,
2455,
275,
6858,
14,
3184,
5779,
8447,
2768,
8,
2190,
29,
277,
14,
2190,
9,
267,
666,
275,
791,
3197,
13,
9339,
356,
283,
31558,
1081,
6772,
297,
283,
3197,
13,
1188,
356,
283,
5812,
2337,
936,
267,
2455,
14,
1069,
275,
291,
14,
3941,
14,
1932,
8,
277,
14,
633,
12,
666,
9,
267,
1824,
275,
2455,
14,
362,
63,
964,
8,
1345,
14,
362,
63,
964,
63,
533,
1012,
267,
291,
14,
3334,
8,
964,
14,
374,
63,
1078,
1012,
339,
347,
511,
63,
3197,
63,
1310,
8,
277,
304,
267,
408,
3101,
8290,
1077,
372,
340,
1824,
365,
3866,
408,
267,
666,
275,
791,
3197,
13,
9339,
356,
283,
31558,
1081,
6772,
297,
283,
1188,
356,
283,
5812,
2337,
936,
267,
1177,
275,
291,
423,
1932,
8,
576,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
362,
63,
15994,
63,
576,
8,
277,
304,
267,
408,
20196,
1471,
5669,
664,
63,
15994,
63,
576,
408,
267,
1824,
275,
3523,
5779,
2821,
342,
267,
291,
14,
1855,
8,
18097,
12,
1824,
14,
362,
63,
15994,
63,
576,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
3558
|
import datetime
from recirq.qaoa.experiments.optimization_tasks import (
OptimizationAlgorithm, OptimizationTask, collect_optimization_data)
from recirq.qaoa.experiments.problem_generation_tasks import (
HardwareGridProblemGenerationTask, SKProblemGenerationTask,
ThreeRegularProblemGenerationTask)
def main():
pgen_dataset_id = '2020-03-19'
dcol_dataset_id = datetime.datetime.now().isoformat(timespec='minutes')
hardware_grid_problem_task = HardwareGridProblemGenerationTask(
dataset_id=pgen_dataset_id,
device_name='Sycamore23',
instance_i=0,
n_qubits=23)
sk_problem_task = SKProblemGenerationTask(
dataset_id=pgen_dataset_id,
instance_i=0,
n_qubits=12,
)
three_regular_problem_task = ThreeRegularProblemGenerationTask(
dataset_id=pgen_dataset_id, instance_i=0, n_qubits=12)
hardware_grid_algorithm = OptimizationAlgorithm(
method='MGD',
n_shots=25000,
options={
'max_iterations': 10,
'rate': 0.1,
'sample_radius': 0.1,
'n_sample_points_ratio': 1.0,
'rate_decay_exponent': 0.5,
'stability_constant': 400,
'sample_radius_decay_exponent': 0.08,
})
hardware_grid_optimization_task = OptimizationTask(
dataset_id=dcol_dataset_id,
generation_task=hardware_grid_problem_task,
device_name='Syc23-noiseless',
p=1,
algorithm=hardware_grid_algorithm,
x0=[0.3, 0.2])
sk_algorithm = OptimizationAlgorithm(method='MGD',
n_shots=25000,
options={
'max_iterations': 10,
'rate': 0.2,
'sample_radius': 0.1,
'n_sample_points_ratio': 1.0,
'rate_decay_exponent': 0.6,
'stability_constant': 400,
'sample_radius_decay_exponent':
0.08,
})
sk_optimization_task = OptimizationTask(dataset_id=dcol_dataset_id,
generation_task=sk_problem_task,
device_name='Syc23-noiseless',
p=1,
algorithm=sk_algorithm,
x0=[0.15, 0.15])
three_regular_algorithm = OptimizationAlgorithm(
method='MGD',
n_shots=25000,
options={
'max_iterations': 10,
'rate': 0.1,
'sample_radius': 0.1,
'n_sample_points_ratio': 1.0,
'rate_decay_exponent': 0.5,
'stability_constant': 400,
'sample_radius_decay_exponent': 0.08,
})
three_regular_optimization_task = OptimizationTask(
dataset_id=dcol_dataset_id,
generation_task=three_regular_problem_task,
device_name='Syc23-noiseless',
p=1,
algorithm=three_regular_algorithm,
x0=[0.3, 0.2])
collect_optimization_data(hardware_grid_optimization_task)
collect_optimization_data(sk_optimization_task)
collect_optimization_data(three_regular_optimization_task)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
646,
2197,
199,
199,
504,
295,
559,
5098,
14,
7096,
20047,
14,
476,
22263,
14,
31405,
63,
5054,
492,
334,
272,
19246,
2072,
11570,
12,
19246,
2072,
4476,
12,
8775,
63,
31405,
63,
576,
9,
199,
504,
295,
559,
5098,
14,
7096,
20047,
14,
476,
22263,
14,
6462,
63,
15043,
63,
5054,
492,
334,
272,
22825,
1068,
7900,
16467,
18514,
4476,
12,
20062,
16467,
18514,
4476,
12,
272,
30467,
16038,
16467,
18514,
4476,
9,
421,
199,
318,
2446,
837,
272,
299,
2268,
63,
5214,
63,
344,
275,
283,
13934,
13,
1644,
13,
1167,
7,
272,
366,
761,
63,
5214,
63,
344,
275,
2197,
14,
2083,
14,
2131,
1252,
17070,
8,
521,
1650,
534,
10430,
358,
339,
14991,
63,
3825,
63,
6462,
63,
1765,
275,
22825,
1068,
7900,
16467,
18514,
4476,
8,
267,
4789,
63,
344,
29,
80,
2268,
63,
5214,
63,
344,
12,
267,
2243,
63,
354,
534,
4323,
15176,
720,
1789,
297,
267,
1256,
63,
73,
29,
16,
12,
267,
302,
63,
392,
5609,
29,
1789,
9,
272,
2386,
63,
6462,
63,
1765,
275,
20062,
16467,
18514,
4476,
8,
267,
4789,
63,
344,
29,
80,
2268,
63,
5214,
63,
344,
12,
267,
1256,
63,
73,
29,
16,
12,
267,
302,
63,
392,
5609,
29,
713,
12,
272,
776,
272,
7795,
63,
7898,
63,
6462,
63,
1765,
275,
30467,
16038,
16467,
18514,
4476,
8,
267,
4789,
63,
344,
29,
80,
2268,
63,
5214,
63,
344,
12,
1256,
63,
73,
29,
16,
12,
302,
63,
392,
5609,
29,
713,
9,
339,
14991,
63,
3825,
63,
8833,
275,
19246,
2072,
11570,
8,
267,
1083,
534,
26255,
36,
297,
267,
302,
63,
2782,
83,
29,
821,
1493,
12,
267,
1511,
3126,
288,
283,
988,
63,
13570,
356,
1616,
12,
288,
283,
1866,
356,
378,
14,
17,
12,
288,
283,
3271,
63,
8017,
356,
378,
14,
17,
12,
288,
283,
78,
63,
3271,
63,
3438,
63,
6884,
356,
413,
14,
16,
12,
288,
283,
1866,
63,
16889,
63,
23475,
356,
378,
14,
21,
12,
288,
283,
270,
3616,
63,
4083,
356,
8290,
12,
288,
283,
3271,
63,
8017,
63,
16889,
63,
23475,
356,
378,
14,
2036,
12,
267,
3828,
272,
14991,
63,
3825,
63,
31405,
63,
1765,
275,
19246,
2072,
4476,
8,
267,
4789,
63,
344,
29,
68,
761,
63,
5214,
63,
344,
12,
267,
10152,
63,
1765,
29,
16529,
63,
3825,
63,
6462,
63,
1765,
12,
267,
2243,
63,
354,
534,
4323,
67,
1789,
13,
11838,
2003,
297,
267,
299,
29,
17,
12,
267,
5563,
29,
16529,
63,
3825,
63,
8833,
12,
267,
671,
16,
1524,
16,
14,
19,
12,
378,
14,
18,
566,
339,
2386,
63,
8833,
275,
19246,
2072,
11570,
8,
765,
534,
26255,
36,
297,
1460,
302,
63,
2782,
83,
29,
821,
1493,
12,
1460,
1511,
3126,
6163,
283,
988,
63,
13570,
356,
1616,
12,
6163,
283,
1866,
356,
378,
14,
18,
12,
6163,
283,
3271,
63,
8017,
356,
378,
14,
17,
12,
6163,
283,
78,
63,
3271,
63,
3438,
63,
6884,
356,
413,
14,
16,
12,
6163,
283,
1866,
63,
16889,
63,
23475,
356,
378,
14,
22,
12,
6163,
283,
270,
3616,
63,
4083,
356,
8290,
12,
6163,
283,
3271,
63,
8017,
63,
16889,
63,
23475,
356,
6163,
378,
14,
2036,
12,
1460,
3828,
272,
2386,
63,
31405,
63,
1765,
275,
19246,
2072,
4476,
8,
5214,
63,
344,
29,
68,
761,
63,
5214,
63,
344,
12,
4490,
10152,
63,
1765,
29,
1339,
63,
6462,
63,
1765,
12,
4490,
2243,
63,
354,
534,
4323,
67,
1789,
13,
11838,
2003,
297,
4490,
299,
29,
17,
12,
4490,
5563,
29,
1339,
63,
8833,
12,
4490,
671,
16,
1524,
16,
14,
1046,
12,
378,
14,
1046,
566,
339,
7795,
63,
7898,
63,
8833,
275,
19246,
2072,
11570,
8,
267,
1083,
534,
26255,
36,
297,
267,
302,
63,
2782,
83,
29,
821,
1493,
12,
267,
1511,
3126,
288,
283,
988,
63,
13570,
356,
1616,
12,
288,
283,
1866,
356,
378,
14,
17,
12,
288,
283,
3271,
63,
8017,
356,
378,
14,
17,
12,
288,
283,
78,
63,
3271,
63,
3438,
63,
6884,
356,
413,
14,
16,
12,
288,
283,
1866,
63,
16889,
63,
23475,
356,
378,
14,
21,
12,
288,
283,
270,
3616,
63,
4083,
356,
8290,
12,
288,
283,
3271,
63,
8017,
63,
16889,
63,
23475,
356,
378,
14,
2036,
12,
267,
3828,
272,
7795,
63,
7898,
63,
31405,
63,
1765,
275,
19246,
2072,
4476,
8,
267,
4789,
63,
344,
29,
68,
761,
63,
5214,
63,
344,
12,
267,
10152,
63,
1765,
29,
10480,
63,
7898,
63,
6462,
63,
1765,
12,
267,
2243,
63,
354,
534,
4323,
67,
1789,
13,
11838,
2003,
297,
267,
299,
29,
17,
12,
267,
5563,
29,
10480,
63,
7898,
63,
8833,
12,
267,
671,
16,
1524,
16,
14,
19,
12,
378,
14,
18,
566,
339,
8775,
63,
31405,
63,
576,
8,
16529,
63,
3825,
63,
31405,
63,
1765,
9,
272,
8775,
63,
31405,
63,
576,
8,
1339,
63,
31405,
63,
1765,
9,
272,
8775,
63,
31405,
63,
576,
8,
10480,
63,
7898,
63,
31405,
63,
1765,
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
] |
[
2197,
199,
199,
504,
295,
559,
5098,
14,
7096,
20047,
14,
476,
22263,
14,
31405,
63,
5054,
492,
334,
272,
19246,
2072,
11570,
12,
19246,
2072,
4476,
12,
8775,
63,
31405,
63,
576,
9,
199,
504,
295,
559,
5098,
14,
7096,
20047,
14,
476,
22263,
14,
6462,
63,
15043,
63,
5054,
492,
334,
272,
22825,
1068,
7900,
16467,
18514,
4476,
12,
20062,
16467,
18514,
4476,
12,
272,
30467,
16038,
16467,
18514,
4476,
9,
421,
199,
318,
2446,
837,
272,
299,
2268,
63,
5214,
63,
344,
275,
283,
13934,
13,
1644,
13,
1167,
7,
272,
366,
761,
63,
5214,
63,
344,
275,
2197,
14,
2083,
14,
2131,
1252,
17070,
8,
521,
1650,
534,
10430,
358,
339,
14991,
63,
3825,
63,
6462,
63,
1765,
275,
22825,
1068,
7900,
16467,
18514,
4476,
8,
267,
4789,
63,
344,
29,
80,
2268,
63,
5214,
63,
344,
12,
267,
2243,
63,
354,
534,
4323,
15176,
720,
1789,
297,
267,
1256,
63,
73,
29,
16,
12,
267,
302,
63,
392,
5609,
29,
1789,
9,
272,
2386,
63,
6462,
63,
1765,
275,
20062,
16467,
18514,
4476,
8,
267,
4789,
63,
344,
29,
80,
2268,
63,
5214,
63,
344,
12,
267,
1256,
63,
73,
29,
16,
12,
267,
302,
63,
392,
5609,
29,
713,
12,
272,
776,
272,
7795,
63,
7898,
63,
6462,
63,
1765,
275,
30467,
16038,
16467,
18514,
4476,
8,
267,
4789,
63,
344,
29,
80,
2268,
63,
5214,
63,
344,
12,
1256,
63,
73,
29,
16,
12,
302,
63,
392,
5609,
29,
713,
9,
339,
14991,
63,
3825,
63,
8833,
275,
19246,
2072,
11570,
8,
267,
1083,
534,
26255,
36,
297,
267,
302,
63,
2782,
83,
29,
821,
1493,
12,
267,
1511,
3126,
288,
283,
988,
63,
13570,
356,
1616,
12,
288,
283,
1866,
356,
378,
14,
17,
12,
288,
283,
3271,
63,
8017,
356,
378,
14,
17,
12,
288,
283,
78,
63,
3271,
63,
3438,
63,
6884,
356,
413,
14,
16,
12,
288,
283,
1866,
63,
16889,
63,
23475,
356,
378,
14,
21,
12,
288,
283,
270,
3616,
63,
4083,
356,
8290,
12,
288,
283,
3271,
63,
8017,
63,
16889,
63,
23475,
356,
378,
14,
2036,
12,
267,
3828,
272,
14991,
63,
3825,
63,
31405,
63,
1765,
275,
19246,
2072,
4476,
8,
267,
4789,
63,
344,
29,
68,
761,
63,
5214,
63,
344,
12,
267,
10152,
63,
1765,
29,
16529,
63,
3825,
63,
6462,
63,
1765,
12,
267,
2243,
63,
354,
534,
4323,
67,
1789,
13,
11838,
2003,
297,
267,
299,
29,
17,
12,
267,
5563,
29,
16529,
63,
3825,
63,
8833,
12,
267,
671,
16,
1524,
16,
14,
19,
12,
378,
14,
18,
566,
339,
2386,
63,
8833,
275,
19246,
2072,
11570,
8,
765,
534,
26255,
36,
297,
1460,
302,
63,
2782,
83,
29,
821,
1493,
12,
1460,
1511,
3126,
6163,
283,
988,
63,
13570,
356,
1616,
12,
6163,
283,
1866,
356,
378,
14,
18,
12,
6163,
283,
3271,
63,
8017,
356,
378,
14,
17,
12,
6163,
283,
78,
63,
3271,
63,
3438,
63,
6884,
356,
413,
14,
16,
12,
6163,
283,
1866,
63,
16889,
63,
23475,
356,
378,
14,
22,
12,
6163,
283,
270,
3616,
63,
4083,
356,
8290,
12,
6163,
283,
3271,
63,
8017,
63,
16889,
63,
23475,
356,
6163,
378,
14,
2036,
12,
1460,
3828,
272,
2386,
63,
31405,
63,
1765,
275,
19246,
2072,
4476,
8,
5214,
63,
344,
29,
68,
761,
63,
5214,
63,
344,
12,
4490,
10152,
63,
1765,
29,
1339,
63,
6462,
63,
1765,
12,
4490,
2243,
63,
354,
534,
4323,
67,
1789,
13,
11838,
2003,
297,
4490,
299,
29,
17,
12,
4490,
5563,
29,
1339,
63,
8833,
12,
4490,
671,
16,
1524,
16,
14,
1046,
12,
378,
14,
1046,
566,
339,
7795,
63,
7898,
63,
8833,
275,
19246,
2072,
11570,
8,
267,
1083,
534,
26255,
36,
297,
267,
302,
63,
2782,
83,
29,
821,
1493,
12,
267,
1511,
3126,
288,
283,
988,
63,
13570,
356,
1616,
12,
288,
283,
1866,
356,
378,
14,
17,
12,
288,
283,
3271,
63,
8017,
356,
378,
14,
17,
12,
288,
283,
78,
63,
3271,
63,
3438,
63,
6884,
356,
413,
14,
16,
12,
288,
283,
1866,
63,
16889,
63,
23475,
356,
378,
14,
21,
12,
288,
283,
270,
3616,
63,
4083,
356,
8290,
12,
288,
283,
3271,
63,
8017,
63,
16889,
63,
23475,
356,
378,
14,
2036,
12,
267,
3828,
272,
7795,
63,
7898,
63,
31405,
63,
1765,
275,
19246,
2072,
4476,
8,
267,
4789,
63,
344,
29,
68,
761,
63,
5214,
63,
344,
12,
267,
10152,
63,
1765,
29,
10480,
63,
7898,
63,
6462,
63,
1765,
12,
267,
2243,
63,
354,
534,
4323,
67,
1789,
13,
11838,
2003,
297,
267,
299,
29,
17,
12,
267,
5563,
29,
10480,
63,
7898,
63,
8833,
12,
267,
671,
16,
1524,
16,
14,
19,
12,
378,
14,
18,
566,
339,
8775,
63,
31405,
63,
576,
8,
16529,
63,
3825,
63,
31405,
63,
1765,
9,
272,
8775,
63,
31405,
63,
576,
8,
1339,
63,
31405,
63,
1765,
9,
272,
8775,
63,
31405,
63,
576,
8,
10480,
63,
7898,
63,
31405,
63,
1765,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nealtodd/django
|
tests/forms_tests/tests/test_media.py
|
76
|
23851
|
# -*- coding: utf-8 -*-
from django.forms import CharField, Form, Media, MultiWidget, TextInput
from django.template import Context, Template
from django.test import SimpleTestCase, override_settings
from django.utils.encoding import force_text
@override_settings(
STATIC_URL='http://media.example.com/static/',
)
class FormsMediaTestCase(SimpleTestCase):
"""Tests for the media handling on widgets and forms"""
def test_construction(self):
# Check construction of media objects
m = Media(
css={'all': ('path/to/css1', '/path/to/css2')},
js=('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'),
)
self.assertEqual(
str(m),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
class Foo:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
m3 = Media(Foo)
self.assertEqual(
str(m3),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
# A widget can exist without a media definition
class MyWidget(TextInput):
pass
w = MyWidget()
self.assertEqual(str(w.media), '')
def test_media_dsl(self):
###############################################################
# DSL Class-based media definitions
###############################################################
# A widget can define media if it needs to.
# Any absolute path will be preserved; relative paths are combined
# with the value of settings.MEDIA_URL
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
w1 = MyWidget1()
self.assertEqual(
str(w1.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
# Media objects can be interrogated by media type
self.assertEqual(
str(w1.media['css']),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />"""
)
self.assertEqual(
str(w1.media['js']),
"""<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
def test_combine_media(self):
# Media objects can be combined. Any given media resource will appear only
# once. Duplicated media definitions are ignored.
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget2(TextInput):
class Media:
css = {
'all': ('/path/to/css2', '/path/to/css3')
}
js = ('/path/to/js1', '/path/to/js4')
class MyWidget3(TextInput):
class Media:
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
w1 = MyWidget1()
w2 = MyWidget2()
w3 = MyWidget3()
self.assertEqual(
str(w1.media + w2.media + w3.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
# Check that media addition hasn't affected the original objects
self.assertEqual(
str(w1.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
# Regression check for #12879: specifying the same CSS or JS file
# multiple times in a single Media instance should result in that file
# only being included once.
class MyWidget4(TextInput):
class Media:
css = {'all': ('/path/to/css1', '/path/to/css1')}
js = ('/path/to/js1', '/path/to/js1')
w4 = MyWidget4()
self.assertEqual(str(w4.media), """<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>""")
def test_media_property(self):
###############################################################
# Property-based media definitions
###############################################################
# Widget media can be defined as a property
class MyWidget4(TextInput):
def _media(self):
return Media(css={'all': ('/some/path',)}, js=('/some/js',))
media = property(_media)
w4 = MyWidget4()
self.assertEqual(str(w4.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/some/js"></script>""")
# Media properties can reference the media of their parents
class MyWidget5(MyWidget4):
def _media(self):
return super(MyWidget5, self).media + Media(css={'all': ('/other/path',)}, js=('/other/js',))
media = property(_media)
w5 = MyWidget5()
self.assertEqual(str(w5.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="/other/js"></script>""")
def test_media_property_parent_references(self):
# Media properties can reference the media of their parents,
# even if the parent media was defined using a class
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget6(MyWidget1):
def _media(self):
return super(MyWidget6, self).media + Media(css={'all': ('/other/path',)}, js=('/other/js',))
media = property(_media)
w6 = MyWidget6()
self.assertEqual(
str(w6.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/other/js"></script>"""
)
def test_media_inheritance(self):
###############################################################
# Inheritance of media
###############################################################
# If a widget extends another but provides no media definition, it inherits the parent widget's media
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget7(MyWidget1):
pass
w7 = MyWidget7()
self.assertEqual(
str(w7.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
)
# If a widget extends another but defines media, it extends the parent widget's media by default
class MyWidget8(MyWidget1):
class Media:
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
w8 = MyWidget8()
self.assertEqual(
str(w8.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
def test_media_inheritance_from_property(self):
# If a widget extends another but defines media, it extends the parents widget's media,
# even if the parent defined media using a property.
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget4(TextInput):
def _media(self):
return Media(css={'all': ('/some/path',)}, js=('/some/js',))
media = property(_media)
class MyWidget9(MyWidget4):
class Media:
css = {
'all': ('/other/path',)
}
js = ('/other/js',)
w9 = MyWidget9()
self.assertEqual(
str(w9.media),
"""<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="/other/js"></script>"""
)
# A widget can disable media inheritance by specifying 'extend=False'
class MyWidget10(MyWidget1):
class Media:
extend = False
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
w10 = MyWidget10()
self.assertEqual(str(w10.media), """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>""")
def test_media_inheritance_extends(self):
# A widget can explicitly enable full media inheritance by specifying 'extend=True'
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget11(MyWidget1):
class Media:
extend = True
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
w11 = MyWidget11()
self.assertEqual(
str(w11.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
def test_media_inheritance_single_type(self):
# A widget can enable inheritance of one media type by specifying extend as a tuple
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget12(MyWidget1):
class Media:
extend = ('css',)
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
w12 = MyWidget12()
self.assertEqual(
str(w12.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
def test_multi_media(self):
###############################################################
# Multi-media handling for CSS
###############################################################
# A widget can define CSS media for multiple output media types
class MultimediaWidget(TextInput):
class Media:
css = {
'screen, print': ('/file1', '/file2'),
'screen': ('/file3',),
'print': ('/file4',)
}
js = ('/path/to/js1', '/path/to/js4')
multimedia = MultimediaWidget()
self.assertEqual(
str(multimedia.media),
"""<link href="/file4" type="text/css" media="print" rel="stylesheet" />
<link href="/file3" type="text/css" media="screen" rel="stylesheet" />
<link href="/file1" type="text/css" media="screen, print" rel="stylesheet" />
<link href="/file2" type="text/css" media="screen, print" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
def test_multi_widget(self):
###############################################################
# Multiwidget media handling
###############################################################
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget2(TextInput):
class Media:
css = {
'all': ('/path/to/css2', '/path/to/css3')
}
js = ('/path/to/js1', '/path/to/js4')
class MyWidget3(TextInput):
class Media:
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
# MultiWidgets have a default media definition that gets all the
# media from the component widgets
class MyMultiWidget(MultiWidget):
def __init__(self, attrs=None):
widgets = [MyWidget1, MyWidget2, MyWidget3]
super(MyMultiWidget, self).__init__(widgets, attrs)
mymulti = MyMultiWidget()
self.assertEqual(
str(mymulti.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
def test_form_media(self):
###############################################################
# Media processing for forms
###############################################################
class MyWidget1(TextInput):
class Media:
css = {
'all': ('path/to/css1', '/path/to/css2')
}
js = ('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3')
class MyWidget2(TextInput):
class Media:
css = {
'all': ('/path/to/css2', '/path/to/css3')
}
js = ('/path/to/js1', '/path/to/js4')
class MyWidget3(TextInput):
class Media:
css = {
'all': ('/path/to/css3', 'path/to/css1')
}
js = ('/path/to/js1', '/path/to/js4')
# You can ask a form for the media required by its widgets.
class MyForm(Form):
field1 = CharField(max_length=20, widget=MyWidget1())
field2 = CharField(max_length=20, widget=MyWidget2())
f1 = MyForm()
self.assertEqual(
str(f1.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
# Form media can be combined to produce a single media definition.
class AnotherForm(Form):
field3 = CharField(max_length=20, widget=MyWidget3())
f2 = AnotherForm()
self.assertEqual(
str(f1.media + f2.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
)
# Forms can also define media, following the same rules as widgets.
class FormWithMedia(Form):
field1 = CharField(max_length=20, widget=MyWidget1())
field2 = CharField(max_length=20, widget=MyWidget2())
class Media:
js = ('/some/form/javascript',)
css = {
'all': ('/some/form/css',)
}
f3 = FormWithMedia()
self.assertEqual(
str(f3.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>
<script type="text/javascript" src="/some/form/javascript"></script>"""
)
# Media works in templates
self.assertEqual(
Template("{{ form.media.js }}{{ form.media.css }}").render(Context({'form': f3})),
"""<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script>
<script type="text/javascript" src="/some/form/javascript"></script>"""
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />"""
)
def test_html_safe(self):
media = Media(css={'all': ['/path/to/css']}, js=['/path/to/js'])
self.assertTrue(hasattr(Media, '__html__'))
self.assertEqual(force_text(media), media.__html__())
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
3351,
492,
12064,
12,
8204,
12,
12300,
12,
6879,
3339,
12,
4516,
3205,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
396,
492,
24424,
12,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
421,
199,
32,
4415,
63,
1751,
8,
272,
27815,
63,
2632,
534,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
3678,
199,
9,
199,
533,
2104,
706,
11398,
1746,
8,
17968,
304,
272,
408,
2925,
367,
314,
5898,
7252,
641,
11114,
436,
4513,
624,
339,
347,
511,
63,
12708,
8,
277,
304,
267,
327,
2670,
14538,
402,
5898,
2251,
267,
333,
275,
12300,
8,
288,
11431,
3713,
452,
356,
661,
515,
15,
475,
15,
3919,
17,
297,
1994,
515,
15,
475,
15,
3919,
18,
3904,
288,
8586,
29,
2336,
515,
15,
475,
15,
3596,
17,
297,
283,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
297,
283,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
659,
267,
776,
267,
291,
14,
629,
8,
288,
620,
8,
77,
395,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
9555,
515,
15,
475,
15,
3596,
17,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
10070,
1579,
11193,
267,
776,
398,
1021,
8024,
26,
288,
11431,
275,
469,
355,
283,
452,
356,
661,
515,
15,
475,
15,
3919,
17,
297,
1994,
515,
15,
475,
15,
3919,
18,
358,
288,
789,
288,
8586,
275,
14606,
515,
15,
475,
15,
3596,
17,
297,
283,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
297,
283,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
358,
398,
333,
19,
275,
12300,
8,
5686,
9,
267,
291,
14,
629,
8,
288,
620,
8,
77,
19,
395,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
9555,
515,
15,
475,
15,
3596,
17,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
10070,
1579,
11193,
267,
776,
398,
327,
437,
3938,
883,
2187,
1928,
282,
5898,
5492,
267,
1021,
4932,
3339,
8,
18362,
304,
288,
986,
398,
336,
275,
4932,
3339,
342,
267,
291,
14,
629,
8,
495,
8,
87,
14,
4603,
395,
4074,
339,
347,
511,
63,
4603,
63,
795,
76,
8,
277,
304,
267,
24515,
14776,
267,
327,
577,
4929,
8089,
13,
6788,
5898,
10269,
267,
24515,
14776,
398,
327,
437,
3938,
883,
5627,
5898,
340,
652,
4839,
370,
14,
267,
327,
6184,
3679,
931,
911,
506,
17731,
27,
3847,
3792,
787,
12149,
267,
327,
543,
314,
574,
402,
2202,
14,
13669,
63,
2632,
267,
1021,
4932,
3339,
17,
8,
18362,
304,
288,
1021,
12300,
26,
355,
11431,
275,
469,
490,
283,
452,
356,
661,
515,
15,
475,
15,
3919,
17,
297,
1994,
515,
15,
475,
15,
3919,
18,
358,
355,
789,
355,
8586,
275,
14606,
515,
15,
475,
15,
3596,
17,
297,
283,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
297,
283,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
358,
398,
336,
17,
275,
4932,
3339,
17,
342,
267,
291,
14,
629,
8,
288,
620,
8,
87,
17,
14,
4603,
395,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
9555,
515,
15,
475,
15,
3596,
17,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
10070,
1579,
11193,
267,
776,
398,
327,
12300,
2251,
883,
506,
1640,
19029,
972,
701,
5898,
730,
267,
291,
14,
629,
8,
288,
620,
8,
87,
17,
14,
4603,
459,
3919,
3815,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
624,
267,
776,
398,
291,
14,
629,
8,
288,
620,
8,
87,
17,
14,
4603,
459,
3596
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
3351,
492,
12064,
12,
8204,
12,
12300,
12,
6879,
3339,
12,
4516,
3205,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
396,
492,
24424,
12,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
421,
199,
32,
4415,
63,
1751,
8,
272,
27815,
63,
2632,
534,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
3678,
199,
9,
199,
533,
2104,
706,
11398,
1746,
8,
17968,
304,
272,
408,
2925,
367,
314,
5898,
7252,
641,
11114,
436,
4513,
624,
339,
347,
511,
63,
12708,
8,
277,
304,
267,
327,
2670,
14538,
402,
5898,
2251,
267,
333,
275,
12300,
8,
288,
11431,
3713,
452,
356,
661,
515,
15,
475,
15,
3919,
17,
297,
1994,
515,
15,
475,
15,
3919,
18,
3904,
288,
8586,
29,
2336,
515,
15,
475,
15,
3596,
17,
297,
283,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
297,
283,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
659,
267,
776,
267,
291,
14,
629,
8,
288,
620,
8,
77,
395,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
9555,
515,
15,
475,
15,
3596,
17,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
10070,
1579,
11193,
267,
776,
398,
1021,
8024,
26,
288,
11431,
275,
469,
355,
283,
452,
356,
661,
515,
15,
475,
15,
3919,
17,
297,
1994,
515,
15,
475,
15,
3919,
18,
358,
288,
789,
288,
8586,
275,
14606,
515,
15,
475,
15,
3596,
17,
297,
283,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
297,
283,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
358,
398,
333,
19,
275,
12300,
8,
5686,
9,
267,
291,
14,
629,
8,
288,
620,
8,
77,
19,
395,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
9555,
515,
15,
475,
15,
3596,
17,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
10070,
1579,
11193,
267,
776,
398,
327,
437,
3938,
883,
2187,
1928,
282,
5898,
5492,
267,
1021,
4932,
3339,
8,
18362,
304,
288,
986,
398,
336,
275,
4932,
3339,
342,
267,
291,
14,
629,
8,
495,
8,
87,
14,
4603,
395,
4074,
339,
347,
511,
63,
4603,
63,
795,
76,
8,
277,
304,
267,
24515,
14776,
267,
327,
577,
4929,
8089,
13,
6788,
5898,
10269,
267,
24515,
14776,
398,
327,
437,
3938,
883,
5627,
5898,
340,
652,
4839,
370,
14,
267,
327,
6184,
3679,
931,
911,
506,
17731,
27,
3847,
3792,
787,
12149,
267,
327,
543,
314,
574,
402,
2202,
14,
13669,
63,
2632,
267,
1021,
4932,
3339,
17,
8,
18362,
304,
288,
1021,
12300,
26,
355,
11431,
275,
469,
490,
283,
452,
356,
661,
515,
15,
475,
15,
3919,
17,
297,
1994,
515,
15,
475,
15,
3919,
18,
358,
355,
789,
355,
8586,
275,
14606,
515,
15,
475,
15,
3596,
17,
297,
283,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
297,
283,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
358,
398,
336,
17,
275,
4932,
3339,
17,
342,
267,
291,
14,
629,
8,
288,
620,
8,
87,
17,
14,
4603,
395,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
9555,
515,
15,
475,
15,
3596,
17,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
1014,
921,
4603,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
18,
10070,
1579,
30,
199,
28,
1579,
730,
628,
505,
15,
9554,
2,
2928,
628,
2859,
921,
7817,
14,
1848,
14,
957,
15,
515,
15,
475,
15,
3596,
19,
10070,
1579,
11193,
267,
776,
398,
327,
12300,
2251,
883,
506,
1640,
19029,
972,
701,
5898,
730,
267,
291,
14,
629,
8,
288,
620,
8,
87,
17,
14,
4603,
459,
3919,
3815,
288,
8894,
1073,
4369,
628,
1014,
921,
4603,
14,
2694,
14,
957,
15,
1986,
15,
515,
15,
475,
15,
3919,
17,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
199,
28,
1073,
4369,
9555,
515,
15,
475,
15,
3919,
18,
2,
730,
628,
505,
15,
3919,
2,
5898,
628,
452,
2,
4668,
628,
15479,
2,
7082,
624,
267,
776,
398,
291,
14,
629,
8,
288,
620,
8,
87,
17,
14,
4603,
459,
3596,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ools import Signals
from PyObjCTools import AppHelper
class TinyTinyDocument(NSDocument):
textView = objc.IBOutlet()
path = None
def windowNibName(self):
return "TinyTinyDocument"
def readFromFile_ofType_(self, path, tp):
if self.textView is None:
# we're not yet fully loaded
self.path = path
else:
# "revert"
self.readFromUTF8(path)
return True
def writeToFile_ofType_(self, path, tp):
f = file(path, "w")
text = self.textView.string()
f.write(text.encode("utf8"))
f.close()
return True
def windowControllerDidLoadNib_(self, controller):
if self.path:
self.readFromUTF8(self.path)
def readFromUTF8(self, path):
f = file(path)
text = unicode(f.read(), "utf8")
f.close()
self.textView.setString_(text)
if __name__ == "__main__":
AppHelper.runEventLoop()
|
mit
|
[
624,
52,
8952,
52,
8952,
4685,
1553,
437,
13460,
7543,
13,
6788,
1849,
331,
65,
4223,
1041,
199,
504,
1849,
331,
65,
492,
627,
199,
504,
1611,
5665,
1028,
5998,
492,
6632,
2551,
199,
504,
1611,
5665,
1028,
5998,
492,
4693,
4433,
199,
199,
533,
11947,
52,
8952,
5564,
8,
2709,
5564,
304,
272,
1318,
2768,
275,
1559,
67,
14,
2100,
2204,
2723,
342,
272,
931,
275,
488,
339,
347,
4353,
46,
1892,
985,
8,
277,
304,
267,
372,
298,
52,
8952,
52,
8952,
5564,
2,
339,
347,
1586,
26637,
63,
1618,
804,
2531,
277,
12,
931,
12,
9253,
304,
267,
340,
291,
14,
505,
2768,
365,
488,
26,
288,
327,
781,
3984,
440,
5966,
9999,
6511,
288,
291,
14,
515,
275,
931,
267,
587,
26,
288,
327,
298,
19092,
2,
288,
291,
14,
739,
2532,
6610,
24,
8,
515,
9,
267,
372,
715,
339,
347,
2218,
24320,
63,
1618,
804,
2531,
277,
12,
931,
12,
9253,
304,
267,
289,
275,
570,
8,
515,
12,
298,
87,
531,
267,
1318,
275,
291,
14,
505,
2768,
14,
875,
342,
267,
289,
14,
952,
8,
505,
14,
2143,
480,
1624,
24,
2237,
267,
289,
14,
1600,
342,
267,
372,
715,
339,
347,
4353,
7506,
17366,
6200,
46,
1892,
2531,
277,
12,
7614,
304,
267,
340,
291,
14,
515,
26,
288,
291,
14,
739,
2532,
6610,
24,
8,
277,
14,
515,
9,
339,
347,
1586,
2532,
6610,
24,
8,
277,
12,
931,
304,
267,
289,
275,
570,
8,
515,
9,
267,
1318,
275,
2649,
8,
70,
14,
739,
1062,
298,
1624,
24,
531,
267,
289,
14,
1600,
342,
267,
291,
14,
505,
2768,
14,
409,
1558,
2531,
505,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4693,
4433,
14,
1065,
2390,
7382,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
52,
8952,
52,
8952,
4685,
1553,
437,
13460,
7543,
13,
6788,
1849,
331,
65,
4223,
1041,
199,
504,
1849,
331,
65,
492,
627,
199,
504,
1611,
5665,
1028,
5998,
492,
6632,
2551,
199,
504,
1611,
5665,
1028,
5998,
492,
4693,
4433,
199,
199,
533,
11947,
52,
8952,
5564,
8,
2709,
5564,
304,
272,
1318,
2768,
275,
1559,
67,
14,
2100,
2204,
2723,
342,
272,
931,
275,
488,
339,
347,
4353,
46,
1892,
985,
8,
277,
304,
267,
372,
298,
52,
8952,
52,
8952,
5564,
2,
339,
347,
1586,
26637,
63,
1618,
804,
2531,
277,
12,
931,
12,
9253,
304,
267,
340,
291,
14,
505,
2768,
365,
488,
26,
288,
327,
781,
3984,
440,
5966,
9999,
6511,
288,
291,
14,
515,
275,
931,
267,
587,
26,
288,
327,
298,
19092,
2,
288,
291,
14,
739,
2532,
6610,
24,
8,
515,
9,
267,
372,
715,
339,
347,
2218,
24320,
63,
1618,
804,
2531,
277,
12,
931,
12,
9253,
304,
267,
289,
275,
570,
8,
515,
12,
298,
87,
531,
267,
1318,
275,
291,
14,
505,
2768,
14,
875,
342,
267,
289,
14,
952,
8,
505,
14,
2143,
480,
1624,
24,
2237,
267,
289,
14,
1600,
342,
267,
372,
715,
339,
347,
4353,
7506,
17366,
6200,
46,
1892,
2531,
277,
12,
7614,
304,
267,
340,
291,
14,
515,
26,
288,
291,
14,
739,
2532,
6610,
24,
8,
277,
14,
515,
9,
339,
347,
1586,
2532,
6610,
24,
8,
277,
12,
931,
304,
267,
289,
275,
570,
8,
515,
9,
267,
1318,
275,
2649,
8,
70,
14,
739,
1062,
298,
1624,
24,
531,
267,
289,
14,
1600,
342,
267,
291,
14,
505,
2768,
14,
409,
1558,
2531,
505,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4693,
4433,
14,
1065,
2390,
7382,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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8 -*-
"""
jinja2.testsuite.lexnparse
~~~~~~~~~~~~~~~~~~~~~~~~~~
All the unittests regarding lexing, parsing and syntax.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
import unittest
from jinja2.testsuite import JinjaTestCase
from jinja2 import Environment, Template, TemplateSyntaxError, \
UndefinedError, nodes
from jinja2._compat import next, iteritems, text_type, PY2
from jinja2.lexer import Token, TokenStream, TOKEN_EOF, \
TOKEN_BLOCK_BEGIN, TOKEN_BLOCK_END
env = Environment()
# how does a string look like in jinja syntax?
if PY2:
def jinja_string_repr(string):
return repr(string)[1:]
else:
jinja_string_repr = repr
class TokenStreamTestCase(JinjaTestCase):
test_tokens = [Token(1, TOKEN_BLOCK_BEGIN, ''),
Token(2, TOKEN_BLOCK_END, ''),
]
def test_simple(self):
ts = TokenStream(self.test_tokens, "foo", "bar")
assert ts.current.type is TOKEN_BLOCK_BEGIN
assert bool(ts)
assert not bool(ts.eos)
next(ts)
assert ts.current.type is TOKEN_BLOCK_END
assert bool(ts)
assert not bool(ts.eos)
next(ts)
assert ts.current.type is TOKEN_EOF
assert not bool(ts)
assert bool(ts.eos)
def test_iter(self):
token_types = [t.type for t in TokenStream(self.test_tokens, "foo", "bar")]
assert token_types == ['block_begin', 'block_end', ]
class LexerTestCase(JinjaTestCase):
def test_raw1(self):
tmpl = env.from_string('{% raw %}foo{% endraw %}|'
'{%raw%}{{ bar }}|{% baz %}{% endraw %}')
assert tmpl.render() == 'foo|{{ bar }}|{% baz %}'
def test_raw2(self):
tmpl = env.from_string('1 {%- raw -%} 2 {%- endraw -%} 3')
assert tmpl.render() == '123'
def test_balancing(self):
env = Environment('{%', '%}', '${', '}')
tmpl = env.from_string('''{% for item in seq
%}${{'foo': item}|upper}{% endfor %}''')
assert tmpl.render(seq=list(range(3))) == "{'FOO': 0}{'FOO': 1}{'FOO': 2}"
def test_comments(self):
env = Environment('<!--', '-->', '{', '}')
tmpl = env.from_string('''\
<ul>
<!--- for item in seq -->
<li>{item}</li>
<!--- endfor -->
</ul>''')
assert tmpl.render(seq=list(range(3))) == ("<ul>\n <li>0</li>\n "
"<li>1</li>\n <li>2</li>\n</ul>")
def test_string_escapes(self):
for char in u'\0', u'\u2668', u'\xe4', u'\t', u'\r', u'\n':
tmpl = env.from_string('{{ %s }}' % jinja_string_repr(char))
assert tmpl.render() == char
assert env.from_string('{{ "\N{HOT SPRINGS}" }}').render() == u'\u2668'
def test_bytefallback(self):
from pprint import pformat
tmpl = env.from_string(u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}''')
assert tmpl.render() == pformat('foo') + '|' + pformat(u'bär')
def test_operators(self):
from jinja2.lexer import operators
for test, expect in iteritems(operators):
if test in '([{}])':
continue
stream = env.lexer.tokenize('{{ %s }}' % test)
next(stream)
assert stream.current.type == expect
def test_normalizing(self):
for seq in '\r', '\r\n', '\n':
env = Environment(newline_sequence=seq)
tmpl = env.from_string('1\n2\r\n3\n4\n')
result = tmpl.render()
assert result.replace(seq, 'X') == '1X2X3X4'
def test_trailing_newline(self):
for keep in [True, False]:
env = Environment(keep_trailing_newline=keep)
for template,expected in [
('', {}),
('no\nnewline', {}),
('with\nnewline\n', {False: 'with\nnewline'}),
('with\nseveral\n\n\n', {False: 'with\nseveral\n\n'}),
]:
tmpl = env.from_string(template)
expect = expected.get(keep, template)
result = tmpl.render()
assert result == expect, (keep, template, result, expect)
class ParserTestCase(JinjaTestCase):
def test_php_syntax(self):
env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->')
tmpl = env.from_string('''\
<!-- I'm a comment, I'm not interesting -->\
<? for item in seq -?>
<?= item ?>
<?- endfor ?>''')
assert tmpl.render(seq=list(range(5))) == '01234'
def test_erb_syntax(self):
env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>')
tmpl = env.from_string('''\
<%# I'm a comment, I'm not interesting %>\
<% for item in seq -%>
<%= item %>
<%- endfor %>''')
assert tmpl.render(seq=list(range(5))) == '01234'
def test_comment_syntax(self):
env = Environment('<!--', '-->', '${', '}', '<!--#', '-->')
tmpl = env.from_string('''\
<!--# I'm a comment, I'm not interesting -->\
<!-- for item in seq --->
${item}
<!--- endfor -->''')
assert tmpl.render(seq=list(range(5))) == '01234'
def test_balancing(self):
tmpl = env.from_string('''{{{'foo':'bar'}.foo}}''')
assert tmpl.render() == 'bar'
def test_start_comment(self):
tmpl = env.from_string('''{# foo comment
and bar comment #}
{% macro blub() %}foo{% endmacro %}
{{ blub() }}''')
assert tmpl.render().strip() == 'foo'
def test_line_syntax(self):
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%')
tmpl = env.from_string('''\
<%# regular comment %>
% for item in seq:
${item}
% endfor''')
assert [int(x.strip()) for x in tmpl.render(seq=list(range(5))).split()] == \
list(range(5))
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##')
tmpl = env.from_string('''\
<%# regular comment %>
% for item in seq:
${item} ## the rest of the stuff
% endfor''')
assert [int(x.strip()) for x in tmpl.render(seq=list(range(5))).split()] == \
list(range(5))
def test_line_syntax_priority(self):
# XXX: why is the whitespace there in front of the newline?
env = Environment('{%', '%}', '${', '}', '/*', '*/', '##', '#')
tmpl = env.from_string('''\
/* ignore me.
I'm a multiline comment */
## for item in seq:
* ${item} # this is just extra stuff
## endfor''')
assert tmpl.render(seq=[1, 2]).strip() == '* 1\n* 2'
env = Environment('{%', '%}', '${', '}', '/*', '*/', '#', '##')
tmpl = env.from_string('''\
/* ignore me.
I'm a multiline comment */
# for item in seq:
* ${item} ## this is just extra stuff
## extra stuff i just want to ignore
# endfor''')
assert tmpl.render(seq=[1, 2]).strip() == '* 1\n\n* 2'
def test_error_messages(self):
def assert_error(code, expected):
try:
Template(code)
except TemplateSyntaxError as e:
assert str(e) == expected, 'unexpected error message'
else:
assert False, 'that was supposed to be an error'
assert_error('{% for item in seq %}...{% endif %}',
"Encountered unknown tag 'endif'. Jinja was looking "
"for the following tags: 'endfor' or 'else'. The "
"innermost block that needs to be closed is 'for'.")
assert_error('{% if foo %}{% for item in seq %}...{% endfor %}{% endfor %}',
"Encountered unknown tag 'endfor'. Jinja was looking for "
"the following tags: 'elif' or 'else' or 'endif'. The "
"innermost block that needs to be closed is 'if'.")
assert_error('{% if foo %}',
"Unexpected end of template. Jinja was looking for the "
"following tags: 'elif' or 'else' or 'endif'. The "
"innermost block that needs to be closed is 'if'.")
assert_error('{% for item in seq %}',
"Unexpected end of template. Jinja was looking for the "
"following tags: 'endfor' or 'else'. The innermost block "
"that needs to be closed is 'for'.")
assert_error('{% block foo-bar-baz %}',
"Block names in Jinja have to be valid Python identifiers "
"and may not contain hyphens, use an underscore instead.")
assert_error('{% unknown_tag %}',
"Encountered unknown tag 'unknown_tag'.")
class SyntaxTestCase(JinjaTestCase):
def test_call(self):
env = Environment()
env.globals['foo'] = lambda a, b, c, e, g: a + b + c + e + g
tmpl = env.from_string("{{ foo('a', c='d', e='f', *['b'], **{'g': 'h'}) }}")
assert tmpl.render() == 'abdfh'
def test_slicing(self):
tmpl = env.from_string('{{ [1, 2, 3][:] }}|{{ [1, 2, 3][::-1] }}')
assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'
def test_attr(self):
tmpl = env.from_string("{{ foo.bar }}|{{ foo['bar'] }}")
assert tmpl.render(foo={'bar': 42}) == '42|42'
def test_subscript(self):
tmpl = env.from_string("{{ foo[0] }}|{{ foo[-1] }}")
assert tmpl.render(foo=[0, 1, 2]) == '0|2'
def test_tuple(self):
tmpl = env.from_string('{{ () }}|{{ (1,) }}|{{ (1, 2) }}')
assert tmpl.render() == '()|(1,)|(1, 2)'
def test_math(self):
tmpl = env.from_string('{{ (1 + 1 * 2) - 3 / 2 }}|{{ 2**3 }}')
assert tmpl.render() == '1.5|8'
def test_div(self):
tmpl = env.from_string('{{ 3 // 2 }}|{{ 3 / 2 }}|{{ 3 % 2 }}')
assert tmpl.render() == '1|1.5|1'
def test_unary(self):
tmpl = env.from_string('{{ +3 }}|{{ -3 }}')
assert tmpl.render() == '3|-3'
def test_concat(self):
tmpl = env.from_string("{{ [1, 2] ~ 'foo' }}")
assert tmpl.render() == '[1, 2]foo'
def test_compare(self):
tmpl = env.from_string('{{ 1 > 0 }}|{{ 1 >= 1 }}|{{ 2 < 3 }}|'
'{{ 2 == 2 }}|{{ 1 <= 1 }}')
assert tmpl.render() == 'True|True|True|True|True'
def test_inop(self):
tmpl = env.from_string('{{ 1 in [1, 2, 3] }}|{{ 1 not in [1, 2, 3] }}')
assert tmpl.render() == 'True|False'
def test_literals(self):
tmpl = env.from_string('{{ [] }}|{{ {} }}|{{ () }}')
assert tmpl.render().lower() == '[]|{}|()'
def test_bool(self):
tmpl = env.from_string('{{ true and false }}|{{ false '
'or true }}|{{ not false }}')
assert tmpl.render() == 'False|True|True'
def test_grouping(self):
tmpl = env.from_string('{{ (true and false) or (false and true) and not false }}')
assert tmpl.render() == 'False'
def test_django_attr(self):
tmpl = env.from_string('{{ [1, 2, 3].0 }}|{{ [[1]].0.0 }}')
assert tmpl.render() == '1|1'
def test_conditional_expression(self):
tmpl = env.from_string('''{{ 0 if true else 1 }}''')
assert tmpl.render() == '0'
def test_short_conditional_expression(self):
tmpl = env.from_string('<{{ 1 if false }}>')
assert tmpl.render() == '<>'
tmpl = env.from_string('<{{ (1 if false).bar }}>')
self.assert_raises(UndefinedError, tmpl.render)
def test_filter_priority(self):
tmpl = env.from_string('{{ "foo"|upper + "bar"|upper }}')
assert tmpl.render() == 'FOOBAR'
def test_function_calls(self):
tests = [
(True, '*foo, bar'),
(True, '*foo, *bar'),
(True, '*foo, bar=42'),
(True, '**foo, *bar'),
(True, '**foo, bar'),
(False, 'foo, bar'),
(False, 'foo, bar=42'),
(False, 'foo, bar=23, *args'),
(False, 'a, b=c, *d, **e'),
(False, '*foo, **bar')
]
for should_fail, sig in tests:
if should_fail:
self.assert_raises(TemplateSyntaxError,
env.from_string, '{{ foo(%s) }}' % sig)
else:
env.from_string('foo(%s)' % sig)
def test_tuple_expr(self):
for tmpl in [
'{{ () }}',
'{{ (1, 2) }}',
'{{ (1, 2,) }}',
'{{ 1, }}',
'{{ 1, 2 }}',
'{% for foo, bar in seq %}...{% endfor %}',
'{% for x in foo, bar %}...{% endfor %}',
'{% for x in foo, %}...{% endfor %}'
]:
assert env.from_string(tmpl)
def test_trailing_comma(self):
tmpl = env.from_string('{{ (1, 2,) }}|{{ [1, 2,] }}|{{ {1: 2,} }}')
assert tmpl.render().lower() == '(1, 2)|[1, 2]|{1: 2}'
def test_block_end_name(self):
env.from_string('{% block foo %}...{% endblock foo %}')
self.assert_raises(TemplateSyntaxError, env.from_string,
'{% block x %}{% endblock y %}')
def test_constant_casing(self):
for const in True, False, None:
tmpl = env.from_string('{{ %s }}|{{ %s }}|{{ %s }}' % (
str(const), str(const).lower(), str(const).upper()
))
assert tmpl.render() == '%s|%s|' % (const, const)
def test_test_chaining(self):
self.assert_raises(TemplateSyntaxError, env.from_string,
'{{ foo is string is sequence }}')
assert env.from_string('{{ 42 is string or 42 is number }}'
).render() == 'True'
def test_string_concatenation(self):
tmpl = env.from_string('{{ "foo" "bar" "baz" }}')
assert tmpl.render() == 'foobarbaz'
def test_notin(self):
bar = range(100)
tmpl = env.from_string('''{{ not 42 in bar }}''')
assert tmpl.render(bar=bar) == text_type(not 42 in bar)
def test_implicit_subscribed_tuple(self):
class Foo(object):
def __getitem__(self, x):
return x
t = env.from_string('{{ foo[1, 2] }}')
assert t.render(foo=Foo()) == u'(1, 2)'
def test_raw2(self):
tmpl = env.from_string('{% raw %}{{ FOO }} and {% BAR %}{% endraw %}')
assert tmpl.render() == '{{ FOO }} and {% BAR %}'
def test_const(self):
tmpl = env.from_string('{{ true }}|{{ false }}|{{ none }}|'
'{{ none is defined }}|{{ missing is defined }}')
assert tmpl.render() == 'True|False|None|True|False'
def test_neg_filter_priority(self):
node = env.parse('{{ -1|foo }}')
assert isinstance(node.body[0].nodes[0], nodes.Filter)
assert isinstance(node.body[0].nodes[0].node, nodes.Neg)
def test_const_assign(self):
constass1 = '''{% set true = 42 %}'''
constass2 = '''{% for none in seq %}{% endfor %}'''
for tmpl in constass1, constass2:
self.assert_raises(TemplateSyntaxError, env.from_string, tmpl)
def test_localset(self):
tmpl = env.from_string('''{% set foo = 0 %}\
{% for item in [1, 2] %}{% set foo = 1 %}{% endfor %}\
{{ foo }}''')
assert tmpl.render() == '0'
def test_parse_unary(self):
tmpl = env.from_string('{{ -foo["bar"] }}')
assert tmpl.render(foo={'bar': 42}) == '-42'
tmpl = env.from_string('{{ -foo["bar"]|abs }}')
assert tmpl.render(foo={'bar': 42}) == '42'
class LstripBlocksTestCase(JinjaTestCase):
def test_lstrip(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' {% if True %}\n {% endif %}''')
assert tmpl.render() == "\n"
def test_lstrip_trim(self):
env = Environment(lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string(''' {% if True %}\n {% endif %}''')
assert tmpl.render() == ""
def test_no_lstrip(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' {%+ if True %}\n {%+ endif %}''')
assert tmpl.render() == " \n "
def test_lstrip_endline(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' hello{% if True %}\n goodbye{% endif %}''')
assert tmpl.render() == " hello\n goodbye"
def test_lstrip_inline(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' {% if True %}hello {% endif %}''')
assert tmpl.render() == 'hello '
def test_lstrip_nested(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' {% if True %}a {% if True %}b {% endif %}c {% endif %}''')
assert tmpl.render() == 'a b c '
def test_lstrip_left_chars(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' abc {% if True %}
hello{% endif %}''')
assert tmpl.render() == ' abc \n hello'
def test_lstrip_embeded_strings(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' {% set x = " {% str %} " %}{{ x }}''')
assert tmpl.render() == ' {% str %} '
def test_lstrip_preserve_leading_newlines(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string('''\n\n\n{% set hello = 1 %}''')
assert tmpl.render() == '\n\n\n'
def test_lstrip_comment(self):
env = Environment(lstrip_blocks=True, trim_blocks=False)
tmpl = env.from_string(''' {# if True #}
hello
{#endif#}''')
assert tmpl.render() == '\nhello\n'
def test_lstrip_angle_bracket_simple(self):
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string(''' <% if True %>hello <% endif %>''')
assert tmpl.render() == 'hello '
def test_lstrip_angle_bracket_comment(self):
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string(''' <%# if True %>hello <%# endif %>''')
assert tmpl.render() == 'hello '
def test_lstrip_angle_bracket(self):
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<%# regular comment %>
<% for item in seq %>
${item} ## the rest of the stuff
<% endfor %>''')
assert tmpl.render(seq=range(5)) == \
''.join('%s\n' % x for x in range(5))
def test_lstrip_angle_bracket_compact(self):
env = Environment('<%', '%>', '${', '}', '<%#', '%>', '%', '##',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<%#regular comment%>
<%for item in seq%>
${item} ## the rest of the stuff
<%endfor%>''')
assert tmpl.render(seq=range(5)) == \
''.join('%s\n' % x for x in range(5))
def test_php_syntax_with_manual(self):
env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<!-- I'm a comment, I'm not interesting -->
<? for item in seq -?>
<?= item ?>
<?- endfor ?>''')
assert tmpl.render(seq=range(5)) == '01234'
def test_php_syntax(self):
env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<!-- I'm a comment, I'm not interesting -->
<? for item in seq ?>
<?= item ?>
<? endfor ?>''')
assert tmpl.render(seq=range(5)) == ''.join(' %s\n' % x for x in range(5))
def test_php_syntax_compact(self):
env = Environment('<?', '?>', '<?=', '?>', '<!--', '-->',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<!-- I'm a comment, I'm not interesting -->
<?for item in seq?>
<?=item?>
<?endfor?>''')
assert tmpl.render(seq=range(5)) == ''.join(' %s\n' % x for x in range(5))
def test_erb_syntax(self):
env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',
lstrip_blocks=True, trim_blocks=True)
#env.from_string('')
#for n,r in env.lexer.rules.iteritems():
# print n
#print env.lexer.rules['root'][0][0].pattern
#print "'%s'" % tmpl.render(seq=range(5))
tmpl = env.from_string('''\
<%# I'm a comment, I'm not interesting %>
<% for item in seq %>
<%= item %>
<% endfor %>
''')
assert tmpl.render(seq=range(5)) == ''.join(' %s\n' % x for x in range(5))
def test_erb_syntax_with_manual(self):
env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<%# I'm a comment, I'm not interesting %>
<% for item in seq -%>
<%= item %>
<%- endfor %>''')
assert tmpl.render(seq=range(5)) == '01234'
def test_erb_syntax_no_lstrip(self):
env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<%# I'm a comment, I'm not interesting %>
<%+ for item in seq -%>
<%= item %>
<%- endfor %>''')
assert tmpl.render(seq=range(5)) == ' 01234'
def test_comment_syntax(self):
env = Environment('<!--', '-->', '${', '}', '<!--#', '-->',
lstrip_blocks=True, trim_blocks=True)
tmpl = env.from_string('''\
<!--# I'm a comment, I'm not interesting -->\
<!-- for item in seq --->
${item}
<!--- endfor -->''')
assert tmpl.render(seq=range(5)) == '01234'
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TokenStreamTestCase))
suite.addTest(unittest.makeSuite(LexerTestCase))
suite.addTest(unittest.makeSuite(ParserTestCase))
suite.addTest(unittest.makeSuite(SyntaxTestCase))
suite.addTest(unittest.makeSuite(LstripBlocksTestCase))
return suite
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
14239,
14,
3113,
78,
1122,
272,
18294,
4919,
1714,
339,
2900,
314,
2882,
83,
12602,
7103,
316,
12,
6057,
436,
6302,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
2882,
199,
199,
504,
10321,
18,
14,
14239,
492,
17300,
1746,
199,
199,
504,
10321,
18,
492,
9711,
12,
5458,
12,
17762,
12,
971,
1362,
25868,
547,
12,
3380,
199,
504,
10321,
18,
423,
5819,
492,
2163,
12,
10849,
12,
1318,
63,
466,
12,
7843,
18,
199,
504,
10321,
18,
14,
11729,
492,
8767,
12,
8767,
3296,
12,
18243,
63,
13178,
12,
971,
1362,
18243,
63,
8475,
63,
15947,
12,
18243,
63,
8475,
63,
3902,
199,
199,
1813,
275,
9711,
342,
421,
199,
3,
4212,
1630,
282,
1059,
3648,
2839,
315,
10321,
6302,
31,
199,
692,
7843,
18,
26,
272,
347,
10321,
63,
875,
63,
2722,
8,
875,
304,
267,
372,
4700,
8,
875,
2788,
17,
2938,
199,
2836,
26,
272,
10321,
63,
875,
63,
2722,
275,
4700,
421,
199,
533,
8767,
3296,
1746,
8,
42,
4135,
1746,
304,
272,
511,
63,
4504,
275,
359,
3264,
8,
17,
12,
18243,
63,
8475,
63,
15947,
12,
9929,
673,
8767,
8,
18,
12,
18243,
63,
8475,
63,
3902,
12,
9929,
2116,
1622,
339,
347,
511,
63,
4129,
8,
277,
304,
267,
6714,
275,
8767,
3296,
8,
277,
14,
396,
63,
4504,
12,
298,
1421,
401,
298,
1700,
531,
267,
702,
6714,
14,
1818,
14,
466,
365,
18243,
63,
8475,
63,
15947,
267,
702,
2155,
8,
1086,
9,
267,
702,
440,
2155,
8,
1086,
14,
24909,
9,
267,
2163,
8,
1086,
9,
267,
702,
6714,
14,
1818,
14,
466,
365,
18243,
63,
8475,
63,
3902,
267,
702,
2155,
8,
1086,
9,
267,
702,
440,
2155,
8,
1086,
14,
24909,
9,
267,
2163,
8,
1086,
9,
267,
702,
6714,
14,
1818,
14,
466,
365,
18243,
63,
13178,
267,
702,
440,
2155,
8,
1086,
9,
267,
702,
2155,
8,
1086,
14,
24909,
9,
339,
347,
511,
63,
1661,
8,
277,
304,
267,
1526,
63,
1313,
275,
359,
84,
14,
466,
367,
307,
315,
8767,
3296,
8,
277,
14,
396,
63,
4504,
12,
298,
1421,
401,
298,
1700,
11323,
267,
702,
1526,
63,
1313,
508,
788,
1457,
63,
5037,
297,
283,
1457,
63,
500,
297,
1622,
421,
199,
533,
21125,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
1773,
17,
8,
277,
304,
267,
9675,
275,
2589,
14,
504,
63,
875,
24103,
3066,
3674,
1421,
3996,
1284,
1773,
3674,
5227,
3044,
12100,
1773,
5,
93,
3638,
4681,
3586,
92,
3996,
15507,
12760,
755,
1284,
1773,
259,
31246,
267,
702,
9675,
14,
3352,
342,
508,
283,
1421,
92,
3638,
4681,
3586,
92,
3996,
15507,
25509,
339,
347,
511,
63,
1773,
18,
8,
277,
304,
267,
9675,
275,
2589,
14,
504,
63,
875,
360,
17,
221,
7749,
13,
3066,
446,
5,
93,
257,
499,
257,
7749,
13,
1284,
1773,
446,
5,
93,
257,
650,
358,
267,
702,
9675,
14,
3352,
342,
508,
283,
4288,
7,
339,
347,
511,
63,
30260,
8,
277,
304,
267,
2589,
275,
9711,
24103,
297,
1543,
7293,
20044,
297,
283,
12216,
267,
9675,
275,
2589,
14,
504,
63,
875,
10505,
3996,
367,
1242,
315,
5412,
288,
3674,
10545,
1445,
1421,
356,
1242,
22441,
4142,
93,
3996,
17273,
3674,
12310,
267,
702,
9675,
14,
3352,
8,
3610,
29,
513,
8,
1842,
8,
19,
1724,
508,
298,
1445,
13046,
356,
378,
93,
1445,
13046,
356,
413,
93,
1445,
13046,
356,
499,
7063,
339,
347,
511,
63,
6223,
8,
277,
304,
267,
2589,
275,
9711,
4827,
17722,
297,
2850,
4206,
5041,
297,
283,
12216,
267,
9675,
275,
2589,
14,
504,
63,
875,
10505,
60,
199,
28,
348,
30,
199,
11230,
2595,
367,
1242,
315,
5412,
10541,
523,
665,
317,
22266,
1053,
17890,
317,
30,
199,
11230,
2595,
17273,
10541,
199,
1108,
348,
30,
12310,
267,
702,
9675,
14,
3352,
8,
3610,
29,
513,
8,
1842,
8,
19,
1724,
508,
1689,
28,
348,
3072,
78,
221,
665,
317,
30,
16,
1108,
317,
3072,
78,
221,
298,
6163,
3886,
317,
30,
17,
1108,
317,
3072,
78,
221,
665,
317,
30,
18,
1108,
317,
3072,
78,
1108,
348,
9579,
339,
347,
511,
63,
875,
63,
3765,
83,
8,
277,
304,
267,
367,
1495,
315,
399,
1154,
16,
297,
399,
1154,
85,
9969,
24,
297,
399,
1154,
1845,
20,
297,
399,
1154,
84,
297,
399,
1154,
82,
297,
399,
1154,
78,
356,
288,
9675,
275,
2589,
14,
504,
63,
875,
18976,
450,
83,
16339,
450,
10321,
63,
875,
63,
2722,
8,
1560,
430,
288,
702,
9675,
14,
3352,
342,
508,
1495,
267,
702,
2589,
14,
504,
63,
875,
18976,
1867,
46,
91,
40,
1387,
428,
3311,
3881,
7063,
3586,
1959,
3352,
342,
508,
399,
1154,
85,
9969,
24,
7,
339,
347,
511,
63,
4414,
10538,
8,
277,
304,
267,
687,
10933,
492,
30843,
267,
9675,
275,
2589,
14,
504,
63,
875,
8,
85,
2344,
3638,
283,
1421,
17018,
15380,
3586,
92,
3638,
283,
66,
13733,
82,
17018,
15380,
3586,
12310,
267,
702,
9675,
14,
3352,
342,
508,
30843,
360,
1421,
358,
435,
24628,
435,
30843,
8,
85,
7,
66,
13733,
82,
358,
339,
347,
511,
63,
12688,
8,
277,
304,
267,
687,
10321,
18,
14,
11729,
492,
10211,
267,
367,
511,
12,
4282,
315,
10849,
8,
12688,
304,
288,
340,
511,
315,
283,
779,
2440,
566,
356,
355,
1980,
288,
2547,
275,
2589,
14,
11729,
14,
15246,
18976,
450,
83,
16339,
450,
511,
9,
288,
2163,
8,
1745,
9,
288,
702,
2547,
14,
1818,
14,
466,
508,
4282,
339,
347,
511,
63,
3302,
9147,
8,
277,
304,
267,
367,
5412,
315,
1557,
82,
297,
1557,
82,
60,
78,
297,
1557,
78,
356,
288,
2589,
275,
9711,
8,
12210,
63,
4041,
29,
3610,
9,
288,
9675,
275,
2589,
14,
504,
63,
875,
360,
17,
60,
78,
18,
60,
82,
60,
78,
19,
60,
78,
20,
60,
78,
358,
288,
754,
275,
9675,
14,
3352,
342,
288,
702,
754,
14,
1814,
8,
3610,
12,
283,
56,
358,
508,
283,
17
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
14239,
14,
3113,
78,
1122,
272,
18294,
4919,
1714,
339,
2900,
314,
2882,
83,
12602,
7103,
316,
12,
6057,
436,
6302,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
2882,
199,
199,
504,
10321,
18,
14,
14239,
492,
17300,
1746,
199,
199,
504,
10321,
18,
492,
9711,
12,
5458,
12,
17762,
12,
971,
1362,
25868,
547,
12,
3380,
199,
504,
10321,
18,
423,
5819,
492,
2163,
12,
10849,
12,
1318,
63,
466,
12,
7843,
18,
199,
504,
10321,
18,
14,
11729,
492,
8767,
12,
8767,
3296,
12,
18243,
63,
13178,
12,
971,
1362,
18243,
63,
8475,
63,
15947,
12,
18243,
63,
8475,
63,
3902,
199,
199,
1813,
275,
9711,
342,
421,
199,
3,
4212,
1630,
282,
1059,
3648,
2839,
315,
10321,
6302,
31,
199,
692,
7843,
18,
26,
272,
347,
10321,
63,
875,
63,
2722,
8,
875,
304,
267,
372,
4700,
8,
875,
2788,
17,
2938,
199,
2836,
26,
272,
10321,
63,
875,
63,
2722,
275,
4700,
421,
199,
533,
8767,
3296,
1746,
8,
42,
4135,
1746,
304,
272,
511,
63,
4504,
275,
359,
3264,
8,
17,
12,
18243,
63,
8475,
63,
15947,
12,
9929,
673,
8767,
8,
18,
12,
18243,
63,
8475,
63,
3902,
12,
9929,
2116,
1622,
339,
347,
511,
63,
4129,
8,
277,
304,
267,
6714,
275,
8767,
3296,
8,
277,
14,
396,
63,
4504,
12,
298,
1421,
401,
298,
1700,
531,
267,
702,
6714,
14,
1818,
14,
466,
365,
18243,
63,
8475,
63,
15947,
267,
702,
2155,
8,
1086,
9,
267,
702,
440,
2155,
8,
1086,
14,
24909,
9,
267,
2163,
8,
1086,
9,
267,
702,
6714,
14,
1818,
14,
466,
365,
18243,
63,
8475,
63,
3902,
267,
702,
2155,
8,
1086,
9,
267,
702,
440,
2155,
8,
1086,
14,
24909,
9,
267,
2163,
8,
1086,
9,
267,
702,
6714,
14,
1818,
14,
466,
365,
18243,
63,
13178,
267,
702,
440,
2155,
8,
1086,
9,
267,
702,
2155,
8,
1086,
14,
24909,
9,
339,
347,
511,
63,
1661,
8,
277,
304,
267,
1526,
63,
1313,
275,
359,
84,
14,
466,
367,
307,
315,
8767,
3296,
8,
277,
14,
396,
63,
4504,
12,
298,
1421,
401,
298,
1700,
11323,
267,
702,
1526,
63,
1313,
508,
788,
1457,
63,
5037,
297,
283,
1457,
63,
500,
297,
1622,
421,
199,
533,
21125,
1746,
8,
42,
4135,
1746,
304,
339,
347,
511,
63,
1773,
17,
8,
277,
304,
267,
9675,
275,
2589,
14,
504,
63,
875,
24103,
3066,
3674,
1421,
3996,
1284,
1773,
3674,
5227,
3044,
12100,
1773,
5,
93,
3638,
4681,
3586,
92,
3996,
15507,
12760,
755,
1284,
1773,
259,
31246,
267,
702,
9675,
14,
3352,
342,
508,
283,
1421,
92,
3638,
4681,
3586,
92,
3996,
15507,
25509,
339,
347,
511,
63,
1773,
18,
8,
277,
304,
267,
9675,
275,
2589,
14,
504,
63,
875,
360,
17,
221,
7749,
13,
3066,
446,
5,
93,
257,
499,
257,
7749,
13,
1284,
1773,
446,
5,
93,
257,
650,
358,
267,
702,
9675,
14,
3352,
342,
508,
283,
4288,
7,
339,
347,
511,
63,
30260,
8,
277,
304,
267,
2589,
275,
9711,
24103,
297,
1543,
7293,
20044,
297,
283,
12216,
267,
9675,
275,
2589,
14,
504,
63,
875,
10505,
3996,
367,
1242,
315,
5412,
288,
3674,
10545,
1445,
1421,
356,
1242,
22441,
4142,
93,
3996,
17273,
3674,
12310,
267,
702,
9675,
14,
3352,
8,
3610,
29,
513,
8,
1842,
8,
19,
1724,
508,
298,
1445,
13046,
356,
378,
93,
1445,
13046,
356,
413,
93,
1445,
13046,
356,
499,
7063,
339,
347,
511,
63,
6223,
8,
277,
304,
267,
2589,
275,
9711,
4827,
17722,
297,
2850,
4206,
5041,
297,
283,
12216,
267,
9675,
275,
2589,
14,
504,
63,
875,
10505,
60,
199,
28,
348,
30,
199,
11230,
2595,
367,
1242,
315,
5412,
10541,
523,
665,
317,
22266,
1053,
17890,
317,
30,
199,
11230,
2595,
17273,
10541,
199,
1108,
348,
30,
12310,
267,
702,
9675,
14,
3352,
8,
3610,
29,
513,
8,
1842,
8,
19,
1724,
508,
1689,
28,
348,
3072,
78,
221,
665,
317,
30,
16,
1108,
317,
3072,
78,
221,
298,
6163,
3886,
317,
30,
17,
1108,
317,
3072,
78,
221,
665,
317,
30,
18,
1108,
317,
3072,
78,
1108,
348,
9579,
339,
347,
511,
63,
875,
63,
3765,
83,
8,
277,
304,
267,
367,
1495,
315,
399,
1154,
16,
297,
399,
1154,
85,
9969,
24,
297,
399,
1154,
1845,
20,
297,
399,
1154,
84,
297,
399,
1154,
82,
297,
399,
1154,
78,
356,
288,
9675,
275,
2589,
14,
504,
63,
875,
18976,
450,
83,
16339,
450,
10321,
63,
875,
63,
2722,
8,
1560,
430,
288,
702,
9675,
14,
3352,
342,
508,
1495,
267,
702,
2589,
14,
504,
63,
875,
18976,
1867,
46,
91,
40,
1387,
428,
3311,
3881,
7063,
3586,
1959,
3352,
342,
508,
399,
1154,
85,
9969,
24,
7,
339,
347,
511,
63,
4414,
10538,
8,
277,
304,
267,
687,
10933,
492,
30843,
267,
9675,
275,
2589,
14,
504,
63,
875,
8,
85,
2344,
3638,
283,
1421,
17018,
15380,
3586,
92,
3638,
283,
66,
13733,
82,
17018,
15380,
3586,
12310,
267,
702,
9675,
14,
3352,
342,
508,
30843,
360,
1421,
358,
435,
24628,
435,
30843,
8,
85,
7,
66,
13733,
82,
358,
339,
347,
511,
63,
12688,
8,
277,
304,
267,
687,
10321,
18,
14,
11729,
492,
10211,
267,
367,
511,
12,
4282,
315,
10849,
8,
12688,
304,
288,
340,
511,
315,
283,
779,
2440,
566,
356,
355,
1980,
288,
2547,
275,
2589,
14,
11729,
14,
15246,
18976,
450,
83,
16339,
450,
511,
9,
288,
2163,
8,
1745,
9,
288,
702,
2547,
14,
1818,
14,
466,
508,
4282,
339,
347,
511,
63,
3302,
9147,
8,
277,
304,
267,
367,
5412,
315,
1557,
82,
297,
1557,
82,
60,
78,
297,
1557,
78,
356,
288,
2589,
275,
9711,
8,
12210,
63,
4041,
29,
3610,
9,
288,
9675,
275,
2589,
14,
504,
63,
875,
360,
17,
60,
78,
18,
60,
82,
60,
78,
19,
60,
78,
20,
60,
78,
358,
288,
754,
275,
9675,
14,
3352,
342,
288,
702,
754,
14,
1814,
8,
3610,
12,
283,
56,
358,
508,
283,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
danielpataki/writing
|
node_modules/gulp-sass/node_modules/node-sass/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py
|
1361
|
45045
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
r"""Code to validate and convert settings of the Microsoft build tools.
This file contains code to validate and convert settings of the Microsoft
build tools. The function ConvertToMSBuildSettings(), ValidateMSVSSettings(),
and ValidateMSBuildSettings() are the entry points.
This file was created by comparing the projects created by Visual Studio 2008
and Visual Studio 2010 for all available settings through the user interface.
The MSBuild schemas were also considered. They are typically found in the
MSBuild install directory, e.g. c:\Program Files (x86)\MSBuild
"""
import sys
import re
# Dictionaries of settings validators. The key is the tool name, the value is
# a dictionary mapping setting names to validation functions.
_msvs_validators = {}
_msbuild_validators = {}
# A dictionary of settings converters. The key is the tool name, the value is
# a dictionary mapping setting names to conversion functions.
_msvs_to_msbuild_converters = {}
# Tool name mapping from MSVS to MSBuild.
_msbuild_name_of_tool = {}
class _Tool(object):
"""Represents a tool used by MSVS or MSBuild.
Attributes:
msvs_name: The name of the tool in MSVS.
msbuild_name: The name of the tool in MSBuild.
"""
def __init__(self, msvs_name, msbuild_name):
self.msvs_name = msvs_name
self.msbuild_name = msbuild_name
def _AddTool(tool):
"""Adds a tool to the four dictionaries used to process settings.
This only defines the tool. Each setting also needs to be added.
Args:
tool: The _Tool object to be added.
"""
_msvs_validators[tool.msvs_name] = {}
_msbuild_validators[tool.msbuild_name] = {}
_msvs_to_msbuild_converters[tool.msvs_name] = {}
_msbuild_name_of_tool[tool.msvs_name] = tool.msbuild_name
def _GetMSBuildToolSettings(msbuild_settings, tool):
"""Returns an MSBuild tool dictionary. Creates it if needed."""
return msbuild_settings.setdefault(tool.msbuild_name, {})
class _Type(object):
"""Type of settings (Base class)."""
def ValidateMSVS(self, value):
"""Verifies that the value is legal for MSVS.
Args:
value: the value to check for this type.
Raises:
ValueError if value is not valid for MSVS.
"""
def ValidateMSBuild(self, value):
"""Verifies that the value is legal for MSBuild.
Args:
value: the value to check for this type.
Raises:
ValueError if value is not valid for MSBuild.
"""
def ConvertToMSBuild(self, value):
"""Returns the MSBuild equivalent of the MSVS value given.
Args:
value: the MSVS value to convert.
Returns:
the MSBuild equivalent.
Raises:
ValueError if value is not valid.
"""
return value
class _String(_Type):
"""A setting that's just a string."""
def ValidateMSVS(self, value):
if not isinstance(value, basestring):
raise ValueError('expected string; got %r' % value)
def ValidateMSBuild(self, value):
if not isinstance(value, basestring):
raise ValueError('expected string; got %r' % value)
def ConvertToMSBuild(self, value):
# Convert the macros
return ConvertVCMacrosToMSBuild(value)
class _StringList(_Type):
"""A settings that's a list of strings."""
def ValidateMSVS(self, value):
if not isinstance(value, basestring) and not isinstance(value, list):
raise ValueError('expected string list; got %r' % value)
def ValidateMSBuild(self, value):
if not isinstance(value, basestring) and not isinstance(value, list):
raise ValueError('expected string list; got %r' % value)
def ConvertToMSBuild(self, value):
# Convert the macros
if isinstance(value, list):
return [ConvertVCMacrosToMSBuild(i) for i in value]
else:
return ConvertVCMacrosToMSBuild(value)
class _Boolean(_Type):
"""Boolean settings, can have the values 'false' or 'true'."""
def _Validate(self, value):
if value != 'true' and value != 'false':
raise ValueError('expected bool; got %r' % value)
def ValidateMSVS(self, value):
self._Validate(value)
def ValidateMSBuild(self, value):
self._Validate(value)
def ConvertToMSBuild(self, value):
self._Validate(value)
return value
class _Integer(_Type):
"""Integer settings."""
def __init__(self, msbuild_base=10):
_Type.__init__(self)
self._msbuild_base = msbuild_base
def ValidateMSVS(self, value):
# Try to convert, this will raise ValueError if invalid.
self.ConvertToMSBuild(value)
def ValidateMSBuild(self, value):
# Try to convert, this will raise ValueError if invalid.
int(value, self._msbuild_base)
def ConvertToMSBuild(self, value):
msbuild_format = (self._msbuild_base == 10) and '%d' or '0x%04x'
return msbuild_format % int(value)
class _Enumeration(_Type):
"""Type of settings that is an enumeration.
In MSVS, the values are indexes like '0', '1', and '2'.
MSBuild uses text labels that are more representative, like 'Win32'.
Constructor args:
label_list: an array of MSBuild labels that correspond to the MSVS index.
In the rare cases where MSVS has skipped an index value, None is
used in the array to indicate the unused spot.
new: an array of labels that are new to MSBuild.
"""
def __init__(self, label_list, new=None):
_Type.__init__(self)
self._label_list = label_list
self._msbuild_values = set(value for value in label_list
if value is not None)
if new is not None:
self._msbuild_values.update(new)
def ValidateMSVS(self, value):
# Try to convert. It will raise an exception if not valid.
self.ConvertToMSBuild(value)
def ValidateMSBuild(self, value):
if value not in self._msbuild_values:
raise ValueError('unrecognized enumerated value %s' % value)
def ConvertToMSBuild(self, value):
index = int(value)
if index < 0 or index >= len(self._label_list):
raise ValueError('index value (%d) not in expected range [0, %d)' %
(index, len(self._label_list)))
label = self._label_list[index]
if label is None:
raise ValueError('converted value for %s not specified.' % value)
return label
# Instantiate the various generic types.
_boolean = _Boolean()
_integer = _Integer()
# For now, we don't do any special validation on these types:
_string = _String()
_file_name = _String()
_folder_name = _String()
_file_list = _StringList()
_folder_list = _StringList()
_string_list = _StringList()
# Some boolean settings went from numerical values to boolean. The
# mapping is 0: default, 1: false, 2: true.
_newly_boolean = _Enumeration(['', 'false', 'true'])
def _Same(tool, name, setting_type):
"""Defines a setting that has the same name in MSVS and MSBuild.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
name: the name of the setting.
setting_type: the type of this setting.
"""
_Renamed(tool, name, name, setting_type)
def _Renamed(tool, msvs_name, msbuild_name, setting_type):
"""Defines a setting for which the name has changed.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
msvs_name: the name of the MSVS setting.
msbuild_name: the name of the MSBuild setting.
setting_type: the type of this setting.
"""
def _Translate(value, msbuild_settings):
msbuild_tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
msbuild_tool_settings[msbuild_name] = setting_type.ConvertToMSBuild(value)
_msvs_validators[tool.msvs_name][msvs_name] = setting_type.ValidateMSVS
_msbuild_validators[tool.msbuild_name][msbuild_name] = (
setting_type.ValidateMSBuild)
_msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate
def _Moved(tool, settings_name, msbuild_tool_name, setting_type):
_MovedAndRenamed(tool, settings_name, msbuild_tool_name, settings_name,
setting_type)
def _MovedAndRenamed(tool, msvs_settings_name, msbuild_tool_name,
msbuild_settings_name, setting_type):
"""Defines a setting that may have moved to a new section.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
msvs_settings_name: the MSVS name of the setting.
msbuild_tool_name: the name of the MSBuild tool to place the setting under.
msbuild_settings_name: the MSBuild name of the setting.
setting_type: the type of this setting.
"""
def _Translate(value, msbuild_settings):
tool_settings = msbuild_settings.setdefault(msbuild_tool_name, {})
tool_settings[msbuild_settings_name] = setting_type.ConvertToMSBuild(value)
_msvs_validators[tool.msvs_name][msvs_settings_name] = (
setting_type.ValidateMSVS)
validator = setting_type.ValidateMSBuild
_msbuild_validators[msbuild_tool_name][msbuild_settings_name] = validator
_msvs_to_msbuild_converters[tool.msvs_name][msvs_settings_name] = _Translate
def _MSVSOnly(tool, name, setting_type):
"""Defines a setting that is only found in MSVS.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
name: the name of the setting.
setting_type: the type of this setting.
"""
def _Translate(unused_value, unused_msbuild_settings):
# Since this is for MSVS only settings, no translation will happen.
pass
_msvs_validators[tool.msvs_name][name] = setting_type.ValidateMSVS
_msvs_to_msbuild_converters[tool.msvs_name][name] = _Translate
def _MSBuildOnly(tool, name, setting_type):
"""Defines a setting that is only found in MSBuild.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
name: the name of the setting.
setting_type: the type of this setting.
"""
def _Translate(value, msbuild_settings):
# Let msbuild-only properties get translated as-is from msvs_settings.
tool_settings = msbuild_settings.setdefault(tool.msbuild_name, {})
tool_settings[name] = value
_msbuild_validators[tool.msbuild_name][name] = setting_type.ValidateMSBuild
_msvs_to_msbuild_converters[tool.msvs_name][name] = _Translate
def _ConvertedToAdditionalOption(tool, msvs_name, flag):
"""Defines a setting that's handled via a command line option in MSBuild.
Args:
tool: a dictionary that gives the names of the tool for MSVS and MSBuild.
msvs_name: the name of the MSVS setting that if 'true' becomes a flag
flag: the flag to insert at the end of the AdditionalOptions
"""
def _Translate(value, msbuild_settings):
if value == 'true':
tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
if 'AdditionalOptions' in tool_settings:
new_flags = '%s %s' % (tool_settings['AdditionalOptions'], flag)
else:
new_flags = flag
tool_settings['AdditionalOptions'] = new_flags
_msvs_validators[tool.msvs_name][msvs_name] = _boolean.ValidateMSVS
_msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate
def _CustomGeneratePreprocessedFile(tool, msvs_name):
def _Translate(value, msbuild_settings):
tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)
if value == '0':
tool_settings['PreprocessToFile'] = 'false'
tool_settings['PreprocessSuppressLineNumbers'] = 'false'
elif value == '1': # /P
tool_settings['PreprocessToFile'] = 'true'
tool_settings['PreprocessSuppressLineNumbers'] = 'false'
elif value == '2': # /EP /P
tool_settings['PreprocessToFile'] = 'true'
tool_settings['PreprocessSuppressLineNumbers'] = 'true'
else:
raise ValueError('value must be one of [0, 1, 2]; got %s' % value)
# Create a bogus validator that looks for '0', '1', or '2'
msvs_validator = _Enumeration(['a', 'b', 'c']).ValidateMSVS
_msvs_validators[tool.msvs_name][msvs_name] = msvs_validator
msbuild_validator = _boolean.ValidateMSBuild
msbuild_tool_validators = _msbuild_validators[tool.msbuild_name]
msbuild_tool_validators['PreprocessToFile'] = msbuild_validator
msbuild_tool_validators['PreprocessSuppressLineNumbers'] = msbuild_validator
_msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate
fix_vc_macro_slashes_regex_list = ('IntDir', 'OutDir')
fix_vc_macro_slashes_regex = re.compile(
r'(\$\((?:%s)\))(?:[\\/]+)' % "|".join(fix_vc_macro_slashes_regex_list)
)
# Regular expression to detect keys that were generated by exclusion lists
_EXCLUDED_SUFFIX_RE = re.compile('^(.*)_excluded$')
def _ValidateExclusionSetting(setting, settings, error_msg, stderr=sys.stderr):
"""Verify that 'setting' is valid if it is generated from an exclusion list.
If the setting appears to be generated from an exclusion list, the root name
is checked.
Args:
setting: A string that is the setting name to validate
settings: A dictionary where the keys are valid settings
error_msg: The message to emit in the event of error
stderr: The stream receiving the error messages.
"""
# This may be unrecognized because it's an exclusion list. If the
# setting name has the _excluded suffix, then check the root name.
unrecognized = True
m = re.match(_EXCLUDED_SUFFIX_RE, setting)
if m:
root_setting = m.group(1)
unrecognized = root_setting not in settings
if unrecognized:
# We don't know this setting. Give a warning.
print >> stderr, error_msg
def FixVCMacroSlashes(s):
"""Replace macros which have excessive following slashes.
These macros are known to have a built-in trailing slash. Furthermore, many
scripts hiccup on processing paths with extra slashes in the middle.
This list is probably not exhaustive. Add as needed.
"""
if '$' in s:
s = fix_vc_macro_slashes_regex.sub(r'\1', s)
return s
def ConvertVCMacrosToMSBuild(s):
"""Convert the the MSVS macros found in the string to the MSBuild equivalent.
This list is probably not exhaustive. Add as needed.
"""
if '$' in s:
replace_map = {
'$(ConfigurationName)': '$(Configuration)',
'$(InputDir)': '%(RelativeDir)',
'$(InputExt)': '%(Extension)',
'$(InputFileName)': '%(Filename)%(Extension)',
'$(InputName)': '%(Filename)',
'$(InputPath)': '%(Identity)',
'$(ParentName)': '$(ProjectFileName)',
'$(PlatformName)': '$(Platform)',
'$(SafeInputName)': '%(Filename)',
}
for old, new in replace_map.iteritems():
s = s.replace(old, new)
s = FixVCMacroSlashes(s)
return s
def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
"""Converts MSVS settings (VS2008 and earlier) to MSBuild settings (VS2010+).
Args:
msvs_settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
Returns:
A dictionary of MSBuild settings. The key is either the MSBuild tool name
or the empty string (for the global settings). The values are themselves
dictionaries of settings and their values.
"""
msbuild_settings = {}
for msvs_tool_name, msvs_tool_settings in msvs_settings.iteritems():
if msvs_tool_name in _msvs_to_msbuild_converters:
msvs_tool = _msvs_to_msbuild_converters[msvs_tool_name]
for msvs_setting, msvs_value in msvs_tool_settings.iteritems():
if msvs_setting in msvs_tool:
# Invoke the translation function.
try:
msvs_tool[msvs_setting](msvs_value, msbuild_settings)
except ValueError, e:
print >> stderr, ('Warning: while converting %s/%s to MSBuild, '
'%s' % (msvs_tool_name, msvs_setting, e))
else:
_ValidateExclusionSetting(msvs_setting,
msvs_tool,
('Warning: unrecognized setting %s/%s '
'while converting to MSBuild.' %
(msvs_tool_name, msvs_setting)),
stderr)
else:
print >> stderr, ('Warning: unrecognized tool %s while converting to '
'MSBuild.' % msvs_tool_name)
return msbuild_settings
def ValidateMSVSSettings(settings, stderr=sys.stderr):
"""Validates that the names of the settings are valid for MSVS.
Args:
settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
"""
_ValidateSettings(_msvs_validators, settings, stderr)
def ValidateMSBuildSettings(settings, stderr=sys.stderr):
"""Validates that the names of the settings are valid for MSBuild.
Args:
settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
"""
_ValidateSettings(_msbuild_validators, settings, stderr)
def _ValidateSettings(validators, settings, stderr):
"""Validates that the settings are valid for MSBuild or MSVS.
We currently only validate the names of the settings, not their values.
Args:
validators: A dictionary of tools and their validators.
settings: A dictionary. The key is the tool name. The values are
themselves dictionaries of settings and their values.
stderr: The stream receiving the error messages.
"""
for tool_name in settings:
if tool_name in validators:
tool_validators = validators[tool_name]
for setting, value in settings[tool_name].iteritems():
if setting in tool_validators:
try:
tool_validators[setting](value)
except ValueError, e:
print >> stderr, ('Warning: for %s/%s, %s' %
(tool_name, setting, e))
else:
_ValidateExclusionSetting(setting,
tool_validators,
('Warning: unrecognized setting %s/%s' %
(tool_name, setting)),
stderr)
else:
print >> stderr, ('Warning: unrecognized tool %s' % tool_name)
# MSVS and MBuild names of the tools.
_compile = _Tool('VCCLCompilerTool', 'ClCompile')
_link = _Tool('VCLinkerTool', 'Link')
_midl = _Tool('VCMIDLTool', 'Midl')
_rc = _Tool('VCResourceCompilerTool', 'ResourceCompile')
_lib = _Tool('VCLibrarianTool', 'Lib')
_manifest = _Tool('VCManifestTool', 'Manifest')
_masm = _Tool('MASM', 'MASM')
_AddTool(_compile)
_AddTool(_link)
_AddTool(_midl)
_AddTool(_rc)
_AddTool(_lib)
_AddTool(_manifest)
_AddTool(_masm)
# Add sections only found in the MSBuild settings.
_msbuild_validators[''] = {}
_msbuild_validators['ProjectReference'] = {}
_msbuild_validators['ManifestResourceCompile'] = {}
# Descriptions of the compiler options, i.e. VCCLCompilerTool in MSVS and
# ClCompile in MSBuild.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\cl.xml" for
# the schema of the MSBuild ClCompile settings.
# Options that have the same name in MSVS and MSBuild
_Same(_compile, 'AdditionalIncludeDirectories', _folder_list) # /I
_Same(_compile, 'AdditionalOptions', _string_list)
_Same(_compile, 'AdditionalUsingDirectories', _folder_list) # /AI
_Same(_compile, 'AssemblerListingLocation', _file_name) # /Fa
_Same(_compile, 'BrowseInformationFile', _file_name)
_Same(_compile, 'BufferSecurityCheck', _boolean) # /GS
_Same(_compile, 'DisableLanguageExtensions', _boolean) # /Za
_Same(_compile, 'DisableSpecificWarnings', _string_list) # /wd
_Same(_compile, 'EnableFiberSafeOptimizations', _boolean) # /GT
_Same(_compile, 'EnablePREfast', _boolean) # /analyze Visible='false'
_Same(_compile, 'ExpandAttributedSource', _boolean) # /Fx
_Same(_compile, 'FloatingPointExceptions', _boolean) # /fp:except
_Same(_compile, 'ForceConformanceInForLoopScope', _boolean) # /Zc:forScope
_Same(_compile, 'ForcedIncludeFiles', _file_list) # /FI
_Same(_compile, 'ForcedUsingFiles', _file_list) # /FU
_Same(_compile, 'GenerateXMLDocumentationFiles', _boolean) # /doc
_Same(_compile, 'IgnoreStandardIncludePath', _boolean) # /X
_Same(_compile, 'MinimalRebuild', _boolean) # /Gm
_Same(_compile, 'OmitDefaultLibName', _boolean) # /Zl
_Same(_compile, 'OmitFramePointers', _boolean) # /Oy
_Same(_compile, 'PreprocessorDefinitions', _string_list) # /D
_Same(_compile, 'ProgramDataBaseFileName', _file_name) # /Fd
_Same(_compile, 'RuntimeTypeInfo', _boolean) # /GR
_Same(_compile, 'ShowIncludes', _boolean) # /showIncludes
_Same(_compile, 'SmallerTypeCheck', _boolean) # /RTCc
_Same(_compile, 'StringPooling', _boolean) # /GF
_Same(_compile, 'SuppressStartupBanner', _boolean) # /nologo
_Same(_compile, 'TreatWChar_tAsBuiltInType', _boolean) # /Zc:wchar_t
_Same(_compile, 'UndefineAllPreprocessorDefinitions', _boolean) # /u
_Same(_compile, 'UndefinePreprocessorDefinitions', _string_list) # /U
_Same(_compile, 'UseFullPaths', _boolean) # /FC
_Same(_compile, 'WholeProgramOptimization', _boolean) # /GL
_Same(_compile, 'XMLDocumentationFileName', _file_name)
_Same(_compile, 'AssemblerOutput',
_Enumeration(['NoListing',
'AssemblyCode', # /FA
'All', # /FAcs
'AssemblyAndMachineCode', # /FAc
'AssemblyAndSourceCode'])) # /FAs
_Same(_compile, 'BasicRuntimeChecks',
_Enumeration(['Default',
'StackFrameRuntimeCheck', # /RTCs
'UninitializedLocalUsageCheck', # /RTCu
'EnableFastChecks'])) # /RTC1
_Same(_compile, 'BrowseInformation',
_Enumeration(['false',
'true', # /FR
'true'])) # /Fr
_Same(_compile, 'CallingConvention',
_Enumeration(['Cdecl', # /Gd
'FastCall', # /Gr
'StdCall', # /Gz
'VectorCall'])) # /Gv
_Same(_compile, 'CompileAs',
_Enumeration(['Default',
'CompileAsC', # /TC
'CompileAsCpp'])) # /TP
_Same(_compile, 'DebugInformationFormat',
_Enumeration(['', # Disabled
'OldStyle', # /Z7
None,
'ProgramDatabase', # /Zi
'EditAndContinue'])) # /ZI
_Same(_compile, 'EnableEnhancedInstructionSet',
_Enumeration(['NotSet',
'StreamingSIMDExtensions', # /arch:SSE
'StreamingSIMDExtensions2', # /arch:SSE2
'AdvancedVectorExtensions', # /arch:AVX (vs2012+)
'NoExtensions', # /arch:IA32 (vs2012+)
# This one only exists in the new msbuild format.
'AdvancedVectorExtensions2', # /arch:AVX2 (vs2013r2+)
]))
_Same(_compile, 'ErrorReporting',
_Enumeration(['None', # /errorReport:none
'Prompt', # /errorReport:prompt
'Queue'], # /errorReport:queue
new=['Send'])) # /errorReport:send"
_Same(_compile, 'ExceptionHandling',
_Enumeration(['false',
'Sync', # /EHsc
'Async'], # /EHa
new=['SyncCThrow'])) # /EHs
_Same(_compile, 'FavorSizeOrSpeed',
_Enumeration(['Neither',
'Speed', # /Ot
'Size'])) # /Os
_Same(_compile, 'FloatingPointModel',
_Enumeration(['Precise', # /fp:precise
'Strict', # /fp:strict
'Fast'])) # /fp:fast
_Same(_compile, 'InlineFunctionExpansion',
_Enumeration(['Default',
'OnlyExplicitInline', # /Ob1
'AnySuitable'], # /Ob2
new=['Disabled'])) # /Ob0
_Same(_compile, 'Optimization',
_Enumeration(['Disabled', # /Od
'MinSpace', # /O1
'MaxSpeed', # /O2
'Full'])) # /Ox
_Same(_compile, 'RuntimeLibrary',
_Enumeration(['MultiThreaded', # /MT
'MultiThreadedDebug', # /MTd
'MultiThreadedDLL', # /MD
'MultiThreadedDebugDLL'])) # /MDd
_Same(_compile, 'StructMemberAlignment',
_Enumeration(['Default',
'1Byte', # /Zp1
'2Bytes', # /Zp2
'4Bytes', # /Zp4
'8Bytes', # /Zp8
'16Bytes'])) # /Zp16
_Same(_compile, 'WarningLevel',
_Enumeration(['TurnOffAllWarnings', # /W0
'Level1', # /W1
'Level2', # /W2
'Level3', # /W3
'Level4'], # /W4
new=['EnableAllWarnings'])) # /Wall
# Options found in MSVS that have been renamed in MSBuild.
_Renamed(_compile, 'EnableFunctionLevelLinking', 'FunctionLevelLinking',
_boolean) # /Gy
_Renamed(_compile, 'EnableIntrinsicFunctions', 'IntrinsicFunctions',
_boolean) # /Oi
_Renamed(_compile, 'KeepComments', 'PreprocessKeepComments', _boolean) # /C
_Renamed(_compile, 'ObjectFile', 'ObjectFileName', _file_name) # /Fo
_Renamed(_compile, 'OpenMP', 'OpenMPSupport', _boolean) # /openmp
_Renamed(_compile, 'PrecompiledHeaderThrough', 'PrecompiledHeaderFile',
_file_name) # Used with /Yc and /Yu
_Renamed(_compile, 'PrecompiledHeaderFile', 'PrecompiledHeaderOutputFile',
_file_name) # /Fp
_Renamed(_compile, 'UsePrecompiledHeader', 'PrecompiledHeader',
_Enumeration(['NotUsing', # VS recognized '' for this value too.
'Create', # /Yc
'Use'])) # /Yu
_Renamed(_compile, 'WarnAsError', 'TreatWarningAsError', _boolean) # /WX
_ConvertedToAdditionalOption(_compile, 'DefaultCharIsUnsigned', '/J')
# MSVS options not found in MSBuild.
_MSVSOnly(_compile, 'Detect64BitPortabilityProblems', _boolean)
_MSVSOnly(_compile, 'UseUnicodeResponseFiles', _boolean)
# MSBuild options not found in MSVS.
_MSBuildOnly(_compile, 'BuildingInIDE', _boolean)
_MSBuildOnly(_compile, 'CompileAsManaged',
_Enumeration([], new=['false',
'true'])) # /clr
_MSBuildOnly(_compile, 'CreateHotpatchableImage', _boolean) # /hotpatch
_MSBuildOnly(_compile, 'MultiProcessorCompilation', _boolean) # /MP
_MSBuildOnly(_compile, 'PreprocessOutputPath', _string) # /Fi
_MSBuildOnly(_compile, 'ProcessorNumber', _integer) # the number of processors
_MSBuildOnly(_compile, 'TrackerLogDirectory', _folder_name)
_MSBuildOnly(_compile, 'TreatSpecificWarningsAsErrors', _string_list) # /we
_MSBuildOnly(_compile, 'UseUnicodeForAssemblerListing', _boolean) # /FAu
# Defines a setting that needs very customized processing
_CustomGeneratePreprocessedFile(_compile, 'GeneratePreprocessedFile')
# Directives for converting MSVS VCLinkerTool to MSBuild Link.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\link.xml" for
# the schema of the MSBuild Link settings.
# Options that have the same name in MSVS and MSBuild
_Same(_link, 'AdditionalDependencies', _file_list)
_Same(_link, 'AdditionalLibraryDirectories', _folder_list) # /LIBPATH
# /MANIFESTDEPENDENCY:
_Same(_link, 'AdditionalManifestDependencies', _file_list)
_Same(_link, 'AdditionalOptions', _string_list)
_Same(_link, 'AddModuleNamesToAssembly', _file_list) # /ASSEMBLYMODULE
_Same(_link, 'AllowIsolation', _boolean) # /ALLOWISOLATION
_Same(_link, 'AssemblyLinkResource', _file_list) # /ASSEMBLYLINKRESOURCE
_Same(_link, 'BaseAddress', _string) # /BASE
_Same(_link, 'CLRUnmanagedCodeCheck', _boolean) # /CLRUNMANAGEDCODECHECK
_Same(_link, 'DelayLoadDLLs', _file_list) # /DELAYLOAD
_Same(_link, 'DelaySign', _boolean) # /DELAYSIGN
_Same(_link, 'EmbedManagedResourceFile', _file_list) # /ASSEMBLYRESOURCE
_Same(_link, 'EnableUAC', _boolean) # /MANIFESTUAC
_Same(_link, 'EntryPointSymbol', _string) # /ENTRY
_Same(_link, 'ForceSymbolReferences', _file_list) # /INCLUDE
_Same(_link, 'FunctionOrder', _file_name) # /ORDER
_Same(_link, 'GenerateDebugInformation', _boolean) # /DEBUG
_Same(_link, 'GenerateMapFile', _boolean) # /MAP
_Same(_link, 'HeapCommitSize', _string)
_Same(_link, 'HeapReserveSize', _string) # /HEAP
_Same(_link, 'IgnoreAllDefaultLibraries', _boolean) # /NODEFAULTLIB
_Same(_link, 'IgnoreEmbeddedIDL', _boolean) # /IGNOREIDL
_Same(_link, 'ImportLibrary', _file_name) # /IMPLIB
_Same(_link, 'KeyContainer', _file_name) # /KEYCONTAINER
_Same(_link, 'KeyFile', _file_name) # /KEYFILE
_Same(_link, 'ManifestFile', _file_name) # /ManifestFile
_Same(_link, 'MapExports', _boolean) # /MAPINFO:EXPORTS
_Same(_link, 'MapFileName', _file_name)
_Same(_link, 'MergedIDLBaseFileName', _file_name) # /IDLOUT
_Same(_link, 'MergeSections', _string) # /MERGE
_Same(_link, 'MidlCommandFile', _file_name) # /MIDL
_Same(_link, 'ModuleDefinitionFile', _file_name) # /DEF
_Same(_link, 'OutputFile', _file_name) # /OUT
_Same(_link, 'PerUserRedirection', _boolean)
_Same(_link, 'Profile', _boolean) # /PROFILE
_Same(_link, 'ProfileGuidedDatabase', _file_name) # /PGD
_Same(_link, 'ProgramDatabaseFile', _file_name) # /PDB
_Same(_link, 'RegisterOutput', _boolean)
_Same(_link, 'SetChecksum', _boolean) # /RELEASE
_Same(_link, 'StackCommitSize', _string)
_Same(_link, 'StackReserveSize', _string) # /STACK
_Same(_link, 'StripPrivateSymbols', _file_name) # /PDBSTRIPPED
_Same(_link, 'SupportUnloadOfDelayLoadedDLL', _boolean) # /DELAY:UNLOAD
_Same(_link, 'SuppressStartupBanner', _boolean) # /NOLOGO
_Same(_link, 'SwapRunFromCD', _boolean) # /SWAPRUN:CD
_Same(_link, 'TurnOffAssemblyGeneration', _boolean) # /NOASSEMBLY
_Same(_link, 'TypeLibraryFile', _file_name) # /TLBOUT
_Same(_link, 'TypeLibraryResourceID', _integer) # /TLBID
_Same(_link, 'UACUIAccess', _boolean) # /uiAccess='true'
_Same(_link, 'Version', _string) # /VERSION
_Same(_link, 'EnableCOMDATFolding', _newly_boolean) # /OPT:ICF
_Same(_link, 'FixedBaseAddress', _newly_boolean) # /FIXED
_Same(_link, 'LargeAddressAware', _newly_boolean) # /LARGEADDRESSAWARE
_Same(_link, 'OptimizeReferences', _newly_boolean) # /OPT:REF
_Same(_link, 'RandomizedBaseAddress', _newly_boolean) # /DYNAMICBASE
_Same(_link, 'TerminalServerAware', _newly_boolean) # /TSAWARE
_subsystem_enumeration = _Enumeration(
['NotSet',
'Console', # /SUBSYSTEM:CONSOLE
'Windows', # /SUBSYSTEM:WINDOWS
'Native', # /SUBSYSTEM:NATIVE
'EFI Application', # /SUBSYSTEM:EFI_APPLICATION
'EFI Boot Service Driver', # /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER
'EFI ROM', # /SUBSYSTEM:EFI_ROM
'EFI Runtime', # /SUBSYSTEM:EFI_RUNTIME_DRIVER
'WindowsCE'], # /SUBSYSTEM:WINDOWSCE
new=['POSIX']) # /SUBSYSTEM:POSIX
_target_machine_enumeration = _Enumeration(
['NotSet',
'MachineX86', # /MACHINE:X86
None,
'MachineARM', # /MACHINE:ARM
'MachineEBC', # /MACHINE:EBC
'MachineIA64', # /MACHINE:IA64
None,
'MachineMIPS', # /MACHINE:MIPS
'MachineMIPS16', # /MACHINE:MIPS16
'MachineMIPSFPU', # /MACHINE:MIPSFPU
'MachineMIPSFPU16', # /MACHINE:MIPSFPU16
None,
None,
None,
'MachineSH4', # /MACHINE:SH4
None,
'MachineTHUMB', # /MACHINE:THUMB
'MachineX64']) # /MACHINE:X64
_Same(_link, 'AssemblyDebug',
_Enumeration(['',
'true', # /ASSEMBLYDEBUG
'false'])) # /ASSEMBLYDEBUG:DISABLE
_Same(_link, 'CLRImageType',
_Enumeration(['Default',
'ForceIJWImage', # /CLRIMAGETYPE:IJW
'ForcePureILImage', # /Switch="CLRIMAGETYPE:PURE
'ForceSafeILImage'])) # /Switch="CLRIMAGETYPE:SAFE
_Same(_link, 'CLRThreadAttribute',
_Enumeration(['DefaultThreadingAttribute', # /CLRTHREADATTRIBUTE:NONE
'MTAThreadingAttribute', # /CLRTHREADATTRIBUTE:MTA
'STAThreadingAttribute'])) # /CLRTHREADATTRIBUTE:STA
_Same(_link, 'DataExecutionPrevention',
_Enumeration(['',
'false', # /NXCOMPAT:NO
'true'])) # /NXCOMPAT
_Same(_link, 'Driver',
_Enumeration(['NotSet',
'Driver', # /Driver
'UpOnly', # /DRIVER:UPONLY
'WDM'])) # /DRIVER:WDM
_Same(_link, 'LinkTimeCodeGeneration',
_Enumeration(['Default',
'UseLinkTimeCodeGeneration', # /LTCG
'PGInstrument', # /LTCG:PGInstrument
'PGOptimization', # /LTCG:PGOptimize
'PGUpdate'])) # /LTCG:PGUpdate
_Same(_link, 'ShowProgress',
_Enumeration(['NotSet',
'LinkVerbose', # /VERBOSE
'LinkVerboseLib'], # /VERBOSE:Lib
new=['LinkVerboseICF', # /VERBOSE:ICF
'LinkVerboseREF', # /VERBOSE:REF
'LinkVerboseSAFESEH', # /VERBOSE:SAFESEH
'LinkVerboseCLR'])) # /VERBOSE:CLR
_Same(_link, 'SubSystem', _subsystem_enumeration)
_Same(_link, 'TargetMachine', _target_machine_enumeration)
_Same(_link, 'UACExecutionLevel',
_Enumeration(['AsInvoker', # /level='asInvoker'
'HighestAvailable', # /level='highestAvailable'
'RequireAdministrator'])) # /level='requireAdministrator'
_Same(_link, 'MinimumRequiredVersion', _string)
_Same(_link, 'TreatLinkerWarningAsErrors', _boolean) # /WX
# Options found in MSVS that have been renamed in MSBuild.
_Renamed(_link, 'ErrorReporting', 'LinkErrorReporting',
_Enumeration(['NoErrorReport', # /ERRORREPORT:NONE
'PromptImmediately', # /ERRORREPORT:PROMPT
'QueueForNextLogin'], # /ERRORREPORT:QUEUE
new=['SendErrorReport'])) # /ERRORREPORT:SEND
_Renamed(_link, 'IgnoreDefaultLibraryNames', 'IgnoreSpecificDefaultLibraries',
_file_list) # /NODEFAULTLIB
_Renamed(_link, 'ResourceOnlyDLL', 'NoEntryPoint', _boolean) # /NOENTRY
_Renamed(_link, 'SwapRunFromNet', 'SwapRunFromNET', _boolean) # /SWAPRUN:NET
_Moved(_link, 'GenerateManifest', '', _boolean)
_Moved(_link, 'IgnoreImportLibrary', '', _boolean)
_Moved(_link, 'LinkIncremental', '', _newly_boolean)
_Moved(_link, 'LinkLibraryDependencies', 'ProjectReference', _boolean)
_Moved(_link, 'UseLibraryDependencyInputs', 'ProjectReference', _boolean)
# MSVS options not found in MSBuild.
_MSVSOnly(_link, 'OptimizeForWindows98', _newly_boolean)
_MSVSOnly(_link, 'UseUnicodeResponseFiles', _boolean)
# MSBuild options not found in MSVS.
_MSBuildOnly(_link, 'BuildingInIDE', _boolean)
_MSBuildOnly(_link, 'ImageHasSafeExceptionHandlers', _boolean) # /SAFESEH
_MSBuildOnly(_link, 'LinkDLL', _boolean) # /DLL Visible='false'
_MSBuildOnly(_link, 'LinkStatus', _boolean) # /LTCG:STATUS
_MSBuildOnly(_link, 'PreventDllBinding', _boolean) # /ALLOWBIND
_MSBuildOnly(_link, 'SupportNobindOfDelayLoadedDLL', _boolean) # /DELAY:NOBIND
_MSBuildOnly(_link, 'TrackerLogDirectory', _folder_name)
_MSBuildOnly(_link, 'MSDOSStubFileName', _file_name) # /STUB Visible='false'
_MSBuildOnly(_link, 'SectionAlignment', _integer) # /ALIGN
_MSBuildOnly(_link, 'SpecifySectionAttributes', _string) # /SECTION
_MSBuildOnly(_link, 'ForceFileOutput',
_Enumeration([], new=['Enabled', # /FORCE
# /FORCE:MULTIPLE
'MultiplyDefinedSymbolOnly',
'UndefinedSymbolOnly'])) # /FORCE:UNRESOLVED
_MSBuildOnly(_link, 'CreateHotPatchableImage',
_Enumeration([], new=['Enabled', # /FUNCTIONPADMIN
'X86Image', # /FUNCTIONPADMIN:5
'X64Image', # /FUNCTIONPADMIN:6
'ItaniumImage'])) # /FUNCTIONPADMIN:16
_MSBuildOnly(_link, 'CLRSupportLastError',
_Enumeration([], new=['Enabled', # /CLRSupportLastError
'Disabled', # /CLRSupportLastError:NO
# /CLRSupportLastError:SYSTEMDLL
'SystemDlls']))
# Directives for converting VCResourceCompilerTool to ResourceCompile.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\rc.xml" for
# the schema of the MSBuild ResourceCompile settings.
_Same(_rc, 'AdditionalOptions', _string_list)
_Same(_rc, 'AdditionalIncludeDirectories', _folder_list) # /I
_Same(_rc, 'Culture', _Integer(msbuild_base=16))
_Same(_rc, 'IgnoreStandardIncludePath', _boolean) # /X
_Same(_rc, 'PreprocessorDefinitions', _string_list) # /D
_Same(_rc, 'ResourceOutputFileName', _string) # /fo
_Same(_rc, 'ShowProgress', _boolean) # /v
# There is no UI in VisualStudio 2008 to set the following properties.
# However they are found in CL and other tools. Include them here for
# completeness, as they are very likely to have the same usage pattern.
_Same(_rc, 'SuppressStartupBanner', _boolean) # /nologo
_Same(_rc, 'UndefinePreprocessorDefinitions', _string_list) # /u
# MSBuild options not found in MSVS.
_MSBuildOnly(_rc, 'NullTerminateStrings', _boolean) # /n
_MSBuildOnly(_rc, 'TrackerLogDirectory', _folder_name)
# Directives for converting VCMIDLTool to Midl.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\midl.xml" for
# the schema of the MSBuild Midl settings.
_Same(_midl, 'AdditionalIncludeDirectories', _folder_list) # /I
_Same(_midl, 'AdditionalOptions', _string_list)
_Same(_midl, 'CPreprocessOptions', _string) # /cpp_opt
_Same(_midl, 'ErrorCheckAllocations', _boolean) # /error allocation
_Same(_midl, 'ErrorCheckBounds', _boolean) # /error bounds_check
_Same(_midl, 'ErrorCheckEnumRange', _boolean) # /error enum
_Same(_midl, 'ErrorCheckRefPointers', _boolean) # /error ref
_Same(_midl, 'ErrorCheckStubData', _boolean) # /error stub_data
_Same(_midl, 'GenerateStublessProxies', _boolean) # /Oicf
_Same(_midl, 'GenerateTypeLibrary', _boolean)
_Same(_midl, 'HeaderFileName', _file_name) # /h
_Same(_midl, 'IgnoreStandardIncludePath', _boolean) # /no_def_idir
_Same(_midl, 'InterfaceIdentifierFileName', _file_name) # /iid
_Same(_midl, 'MkTypLibCompatible', _boolean) # /mktyplib203
_Same(_midl, 'OutputDirectory', _string) # /out
_Same(_midl, 'PreprocessorDefinitions', _string_list) # /D
_Same(_midl, 'ProxyFileName', _file_name) # /proxy
_Same(_midl, 'RedirectOutputAndErrors', _file_name) # /o
_Same(_midl, 'SuppressStartupBanner', _boolean) # /nologo
_Same(_midl, 'TypeLibraryName', _file_name) # /tlb
_Same(_midl, 'UndefinePreprocessorDefinitions', _string_list) # /U
_Same(_midl, 'WarnAsError', _boolean) # /WX
_Same(_midl, 'DefaultCharType',
_Enumeration(['Unsigned', # /char unsigned
'Signed', # /char signed
'Ascii'])) # /char ascii7
_Same(_midl, 'TargetEnvironment',
_Enumeration(['NotSet',
'Win32', # /env win32
'Itanium', # /env ia64
'X64'])) # /env x64
_Same(_midl, 'EnableErrorChecks',
_Enumeration(['EnableCustom',
'None', # /error none
'All'])) # /error all
_Same(_midl, 'StructMemberAlignment',
_Enumeration(['NotSet',
'1', # Zp1
'2', # Zp2
'4', # Zp4
'8'])) # Zp8
_Same(_midl, 'WarningLevel',
_Enumeration(['0', # /W0
'1', # /W1
'2', # /W2
'3', # /W3
'4'])) # /W4
_Renamed(_midl, 'DLLDataFileName', 'DllDataFileName', _file_name) # /dlldata
_Renamed(_midl, 'ValidateParameters', 'ValidateAllParameters',
_boolean) # /robust
# MSBuild options not found in MSVS.
_MSBuildOnly(_midl, 'ApplicationConfigurationMode', _boolean) # /app_config
_MSBuildOnly(_midl, 'ClientStubFile', _file_name) # /cstub
_MSBuildOnly(_midl, 'GenerateClientFiles',
_Enumeration([], new=['Stub', # /client stub
'None'])) # /client none
_MSBuildOnly(_midl, 'GenerateServerFiles',
_Enumeration([], new=['Stub', # /client stub
'None'])) # /client none
_MSBuildOnly(_midl, 'LocaleID', _integer) # /lcid DECIMAL
_MSBuildOnly(_midl, 'ServerStubFile', _file_name) # /sstub
_MSBuildOnly(_midl, 'SuppressCompilerWarnings', _boolean) # /no_warn
_MSBuildOnly(_midl, 'TrackerLogDirectory', _folder_name)
_MSBuildOnly(_midl, 'TypeLibFormat',
_Enumeration([], new=['NewFormat', # /newtlb
'OldFormat'])) # /oldtlb
# Directives for converting VCLibrarianTool to Lib.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\lib.xml" for
# the schema of the MSBuild Lib settings.
_Same(_lib, 'AdditionalDependencies', _file_list)
_Same(_lib, 'AdditionalLibraryDirectories', _folder_list) # /LIBPATH
_Same(_lib, 'AdditionalOptions', _string_list)
_Same(_lib, 'ExportNamedFunctions', _string_list) # /EXPORT
_Same(_lib, 'ForceSymbolReferences', _string) # /INCLUDE
_Same(_lib, 'IgnoreAllDefaultLibraries', _boolean) # /NODEFAULTLIB
_Same(_lib, 'IgnoreSpecificDefaultLibraries', _file_list) # /NODEFAULTLIB
_Same(_lib, 'ModuleDefinitionFile', _file_name) # /DEF
_Same(_lib, 'OutputFile', _file_name) # /OUT
_Same(_lib, 'SuppressStartupBanner', _boolean) # /NOLOGO
_Same(_lib, 'UseUnicodeResponseFiles', _boolean)
_Same(_lib, 'LinkTimeCodeGeneration', _boolean) # /LTCG
_Same(_lib, 'TargetMachine', _target_machine_enumeration)
# TODO(jeanluc) _link defines the same value that gets moved to
# ProjectReference. We may want to validate that they are consistent.
_Moved(_lib, 'LinkLibraryDependencies', 'ProjectReference', _boolean)
_MSBuildOnly(_lib, 'DisplayLibrary', _string) # /LIST Visible='false'
_MSBuildOnly(_lib, 'ErrorReporting',
_Enumeration([], new=['PromptImmediately', # /ERRORREPORT:PROMPT
'QueueForNextLogin', # /ERRORREPORT:QUEUE
'SendErrorReport', # /ERRORREPORT:SEND
'NoErrorReport'])) # /ERRORREPORT:NONE
_MSBuildOnly(_lib, 'MinimumRequiredVersion', _string)
_MSBuildOnly(_lib, 'Name', _file_name) # /NAME
_MSBuildOnly(_lib, 'RemoveObjects', _file_list) # /REMOVE
_MSBuildOnly(_lib, 'SubSystem', _subsystem_enumeration)
_MSBuildOnly(_lib, 'TrackerLogDirectory', _folder_name)
_MSBuildOnly(_lib, 'TreatLibWarningAsErrors', _boolean) # /WX
_MSBuildOnly(_lib, 'Verbose', _boolean)
# Directives for converting VCManifestTool to Mt.
# See "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\1033\mt.xml" for
# the schema of the MSBuild Lib settings.
# Options that have the same name in MSVS and MSBuild
_Same(_manifest, 'AdditionalManifestFiles', _file_list) # /manifest
_Same(_manifest, 'AdditionalOptions', _string_list)
_Same(_manifest, 'AssemblyIdentity', _string) # /identity:
_Same(_manifest, 'ComponentFileName', _file_name) # /dll
_Same(_manifest, 'GenerateCatalogFiles', _boolean) # /makecdfs
_Same(_manifest, 'InputResourceManifests', _string) # /inputresource
_Same(_manifest, 'OutputManifestFile', _file_name) # /out
_Same(_manifest, 'RegistrarScriptFile', _file_name) # /rgs
_Same(_manifest, 'ReplacementsFile', _file_name) # /replacements
_Same(_manifest, 'SuppressStartupBanner', _boolean) # /nologo
_Same(_manifest, 'TypeLibraryFile', _file_name) # /tlb:
_Same(_manifest, 'UpdateFileHashes', _boolean) # /hashupdate
_Same(_manifest, 'UpdateFileHashesSearchPath', _file_name)
_Same(_manifest, 'VerboseOutput', _boolean) # /verbose
# Options that have moved location.
_MovedAndRenamed(_manifest, 'ManifestResourceFile',
'ManifestResourceCompile',
'ResourceOutputFileName',
_file_name)
_Moved(_manifest, 'EmbedManifest', '', _boolean)
# MSVS options not found in MSBuild.
_MSVSOnly(_manifest, 'DependencyInformationFile', _file_name)
_MSVSOnly(_manifest, 'UseFAT32Workaround', _boolean)
_MSVSOnly(_manifest, 'UseUnicodeResponseFiles', _boolean)
# MSBuild options not found in MSVS.
_MSBuildOnly(_manifest, 'EnableDPIAwareness', _boolean)
_MSBuildOnly(_manifest, 'GenerateCategoryTags', _boolean) # /category
_MSBuildOnly(_manifest, 'ManifestFromManagedAssembly',
_file_name) # /managedassemblyname
_MSBuildOnly(_manifest, 'OutputResourceManifests', _string) # /outputresource
_MSBuildOnly(_manifest, 'SuppressDependencyElement', _boolean) # /nodependency
_MSBuildOnly(_manifest, 'TrackerLogDirectory', _folder_name)
# Directives for MASM.
# See "$(VCTargetsPath)\BuildCustomizations\masm.xml" for the schema of the
# MSBuild MASM settings.
# Options that have the same name in MSVS and MSBuild.
_Same(_masm, 'UseSafeExceptionHandlers', _boolean) # /safeseh
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
82,
624,
3034,
370,
4107,
436,
3957,
2202,
402,
314,
15332,
1900,
7249,
14,
199,
199,
2765,
570,
3509,
1233,
370,
4107,
436,
3957,
2202,
402,
314,
15332,
199,
1506,
7249,
14,
221,
710,
805,
7905,
28361,
5268,
1062,
12134,
14206,
5268,
1062,
199,
460,
12134,
10733,
5268,
342,
787,
314,
2397,
4501,
14,
199,
199,
2765,
570,
1990,
2737,
701,
20234,
314,
11336,
2737,
701,
14702,
13225,
9079,
199,
460,
14702,
13225,
7129,
367,
1006,
2808,
2202,
4012,
314,
922,
3217,
14,
199,
1918,
21374,
32536,
4898,
2597,
8652,
14,
221,
9322,
787,
13609,
1911,
315,
314,
199,
10733,
3907,
2082,
12,
325,
14,
71,
14,
286,
3427,
9184,
16920,
334,
88,
1184,
2862,
10733,
199,
624,
199,
199,
646,
984,
199,
646,
295,
199,
199,
3,
3757,
10150,
402,
2202,
14370,
14,
710,
790,
365,
314,
4744,
536,
12,
314,
574,
365,
199,
3,
282,
2600,
4412,
4260,
1561,
370,
6411,
3423,
14,
199,
63,
8338,
63,
11346,
275,
1052,
199,
63,
14087,
63,
11346,
275,
1052,
421,
199,
3,
437,
2600,
402,
2202,
23172,
14,
710,
790,
365,
314,
4744,
536,
12,
314,
574,
365,
199,
3,
282,
2600,
4412,
4260,
1561,
370,
8603,
3423,
14,
199,
63,
8338,
63,
475,
63,
14087,
63,
17911,
275,
1052,
421,
199,
3,
15650,
536,
4412,
687,
13828,
370,
21374,
14,
199,
63,
14087,
63,
354,
63,
1618,
63,
3557,
275,
1052,
421,
199,
533,
485,
5157,
8,
785,
304,
523,
408,
18089,
282,
4744,
1202,
701,
13828,
503,
21374,
14,
819,
9382,
26,
489,
13795,
63,
354,
26,
710,
536,
402,
314,
4744,
315,
13828,
14,
489,
14835,
63,
354,
26,
710,
536,
402,
314,
4744,
315,
21374,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
13795,
63,
354,
12,
14835,
63,
354,
304,
272,
291,
14,
8338,
63,
354,
275,
13795,
63,
354,
272,
291,
14,
14087,
63,
354,
275,
14835,
63,
354,
421,
199,
318,
485,
1123,
5157,
8,
3557,
304,
523,
408,
14995,
282,
4744,
370,
314,
11648,
11196,
1202,
370,
2112,
2202,
14,
819,
961,
1454,
7890,
314,
4744,
14,
221,
7048,
4260,
2597,
4839,
370,
506,
3483,
14,
819,
3033,
26,
272,
4744,
26,
710,
485,
5157,
909,
370,
506,
3483,
14,
523,
408,
523,
485,
8338,
63,
11346,
59,
3557,
14,
8338,
63,
354,
61,
275,
1052,
523,
485,
14087,
63,
11346,
59,
3557,
14,
14087,
63,
354,
61,
275,
1052,
523,
485,
8338,
63,
475,
63,
14087,
63,
17911,
59,
3557,
14,
8338,
63,
354,
61,
275,
1052,
523,
485,
14087,
63,
354,
63,
1618,
63,
3557,
59,
3557,
14,
8338,
63,
354,
61,
275,
4744,
14,
14087,
63,
354,
421,
199,
318,
485,
26772,
5157,
5268,
8,
14087,
63,
1751,
12,
4744,
304,
523,
408,
3407,
376,
21374,
4744,
2600,
14,
221,
10560,
652,
340,
4346,
1041,
523,
372,
14835,
63,
1751,
14,
5486,
8,
3557,
14,
14087,
63,
354,
12,
5009,
421,
199,
533,
485,
804,
8,
785,
304,
523,
408,
804,
402,
2202,
334,
1563,
1021,
10477,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
408,
21168,
626,
314,
574,
365,
18393,
367,
13828,
14,
339,
3033,
26,
489,
574,
26,
314,
574,
370,
1104,
367,
642,
730,
14,
339,
6218,
26,
489,
1722,
340,
574,
365,
440,
1686,
367,
13828,
14,
272,
408,
819,
347,
12134,
10733,
8,
277,
12,
574,
304,
272,
408,
21168,
626,
314,
574,
365,
18393,
367,
21374,
14,
339,
3033,
26,
489,
574,
26,
314,
574,
370,
1104,
367,
642,
730,
14,
339,
6218,
26,
489,
1722,
340,
574,
365,
440,
1686,
367,
21374,
14,
272,
408,
819,
347,
7905,
28361,
8,
277,
12,
574,
304,
272,
408,
3407,
314,
21374,
7353,
402,
314,
13828,
574,
1627,
14,
339,
3033,
26,
489,
574,
26,
314,
13828,
574,
370,
3957,
14,
339,
1803,
26,
489,
314,
21374,
7353,
14,
339,
6218,
26,
489,
1722,
340,
574,
365,
440,
1686,
14,
272,
408,
272,
372,
574,
421,
199,
533,
485,
1558,
1547,
804,
304,
523,
408,
33,
4260,
626,
1159,
2951,
282,
1059,
1041,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
489,
746,
1722,
360,
2062,
1059,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
12134,
10733,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
489,
746,
1722,
360,
2062,
1059,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
7905,
28361,
8,
277,
12,
574,
304,
272,
327,
7905,
314,
16954,
272,
372,
7905,
9454,
25402,
28361,
8,
585,
9,
421,
199,
533,
485,
32216,
1547,
804,
304,
523,
408,
33,
2202,
626,
1159,
282,
769,
402,
3326,
1041,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
9,
436,
440,
1228,
8,
585,
12,
769,
304,
489,
746,
1722,
360,
2062,
1059,
769,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
12134,
10733,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
9,
436,
440,
1228,
8,
585,
12,
769,
304,
489,
746,
1722,
360,
2062,
1059,
769,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
7905,
28361,
8,
277,
12,
574,
304,
272,
327,
7905,
314,
16954,
272,
340,
1228,
8,
585,
12,
769,
304,
489,
372,
359,
7306,
9454,
25402,
28361,
8,
73,
9,
367,
284,
315,
574,
61,
272,
587,
26,
489,
372,
7905,
9454,
25402,
28361,
8,
585,
9,
421,
199,
533,
485,
4082,
1547,
804,
304,
523,
408,
4082,
2202,
12,
883,
1172,
314,
1338,
283,
3910,
7,
503,
283,
2052,
23690,
819,
347,
485,
12584,
8,
277,
12,
574,
304,
272,
340,
574,
1137,
283,
2052,
7,
436,
574,
1137,
283,
3910,
356,
489,
746,
1722,
360,
2062,
2155,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
291,
423,
12584
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
82,
624,
3034,
370,
4107,
436,
3957,
2202,
402,
314,
15332,
1900,
7249,
14,
199,
199,
2765,
570,
3509,
1233,
370,
4107,
436,
3957,
2202,
402,
314,
15332,
199,
1506,
7249,
14,
221,
710,
805,
7905,
28361,
5268,
1062,
12134,
14206,
5268,
1062,
199,
460,
12134,
10733,
5268,
342,
787,
314,
2397,
4501,
14,
199,
199,
2765,
570,
1990,
2737,
701,
20234,
314,
11336,
2737,
701,
14702,
13225,
9079,
199,
460,
14702,
13225,
7129,
367,
1006,
2808,
2202,
4012,
314,
922,
3217,
14,
199,
1918,
21374,
32536,
4898,
2597,
8652,
14,
221,
9322,
787,
13609,
1911,
315,
314,
199,
10733,
3907,
2082,
12,
325,
14,
71,
14,
286,
3427,
9184,
16920,
334,
88,
1184,
2862,
10733,
199,
624,
199,
199,
646,
984,
199,
646,
295,
199,
199,
3,
3757,
10150,
402,
2202,
14370,
14,
710,
790,
365,
314,
4744,
536,
12,
314,
574,
365,
199,
3,
282,
2600,
4412,
4260,
1561,
370,
6411,
3423,
14,
199,
63,
8338,
63,
11346,
275,
1052,
199,
63,
14087,
63,
11346,
275,
1052,
421,
199,
3,
437,
2600,
402,
2202,
23172,
14,
710,
790,
365,
314,
4744,
536,
12,
314,
574,
365,
199,
3,
282,
2600,
4412,
4260,
1561,
370,
8603,
3423,
14,
199,
63,
8338,
63,
475,
63,
14087,
63,
17911,
275,
1052,
421,
199,
3,
15650,
536,
4412,
687,
13828,
370,
21374,
14,
199,
63,
14087,
63,
354,
63,
1618,
63,
3557,
275,
1052,
421,
199,
533,
485,
5157,
8,
785,
304,
523,
408,
18089,
282,
4744,
1202,
701,
13828,
503,
21374,
14,
819,
9382,
26,
489,
13795,
63,
354,
26,
710,
536,
402,
314,
4744,
315,
13828,
14,
489,
14835,
63,
354,
26,
710,
536,
402,
314,
4744,
315,
21374,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
13795,
63,
354,
12,
14835,
63,
354,
304,
272,
291,
14,
8338,
63,
354,
275,
13795,
63,
354,
272,
291,
14,
14087,
63,
354,
275,
14835,
63,
354,
421,
199,
318,
485,
1123,
5157,
8,
3557,
304,
523,
408,
14995,
282,
4744,
370,
314,
11648,
11196,
1202,
370,
2112,
2202,
14,
819,
961,
1454,
7890,
314,
4744,
14,
221,
7048,
4260,
2597,
4839,
370,
506,
3483,
14,
819,
3033,
26,
272,
4744,
26,
710,
485,
5157,
909,
370,
506,
3483,
14,
523,
408,
523,
485,
8338,
63,
11346,
59,
3557,
14,
8338,
63,
354,
61,
275,
1052,
523,
485,
14087,
63,
11346,
59,
3557,
14,
14087,
63,
354,
61,
275,
1052,
523,
485,
8338,
63,
475,
63,
14087,
63,
17911,
59,
3557,
14,
8338,
63,
354,
61,
275,
1052,
523,
485,
14087,
63,
354,
63,
1618,
63,
3557,
59,
3557,
14,
8338,
63,
354,
61,
275,
4744,
14,
14087,
63,
354,
421,
199,
318,
485,
26772,
5157,
5268,
8,
14087,
63,
1751,
12,
4744,
304,
523,
408,
3407,
376,
21374,
4744,
2600,
14,
221,
10560,
652,
340,
4346,
1041,
523,
372,
14835,
63,
1751,
14,
5486,
8,
3557,
14,
14087,
63,
354,
12,
5009,
421,
199,
533,
485,
804,
8,
785,
304,
523,
408,
804,
402,
2202,
334,
1563,
1021,
10477,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
408,
21168,
626,
314,
574,
365,
18393,
367,
13828,
14,
339,
3033,
26,
489,
574,
26,
314,
574,
370,
1104,
367,
642,
730,
14,
339,
6218,
26,
489,
1722,
340,
574,
365,
440,
1686,
367,
13828,
14,
272,
408,
819,
347,
12134,
10733,
8,
277,
12,
574,
304,
272,
408,
21168,
626,
314,
574,
365,
18393,
367,
21374,
14,
339,
3033,
26,
489,
574,
26,
314,
574,
370,
1104,
367,
642,
730,
14,
339,
6218,
26,
489,
1722,
340,
574,
365,
440,
1686,
367,
21374,
14,
272,
408,
819,
347,
7905,
28361,
8,
277,
12,
574,
304,
272,
408,
3407,
314,
21374,
7353,
402,
314,
13828,
574,
1627,
14,
339,
3033,
26,
489,
574,
26,
314,
13828,
574,
370,
3957,
14,
339,
1803,
26,
489,
314,
21374,
7353,
14,
339,
6218,
26,
489,
1722,
340,
574,
365,
440,
1686,
14,
272,
408,
272,
372,
574,
421,
199,
533,
485,
1558,
1547,
804,
304,
523,
408,
33,
4260,
626,
1159,
2951,
282,
1059,
1041,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
489,
746,
1722,
360,
2062,
1059,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
12134,
10733,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
489,
746,
1722,
360,
2062,
1059,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
7905,
28361,
8,
277,
12,
574,
304,
272,
327,
7905,
314,
16954,
272,
372,
7905,
9454,
25402,
28361,
8,
585,
9,
421,
199,
533,
485,
32216,
1547,
804,
304,
523,
408,
33,
2202,
626,
1159,
282,
769,
402,
3326,
1041,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
9,
436,
440,
1228,
8,
585,
12,
769,
304,
489,
746,
1722,
360,
2062,
1059,
769,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
12134,
10733,
8,
277,
12,
574,
304,
272,
340,
440,
1228,
8,
585,
12,
7116,
9,
436,
440,
1228,
8,
585,
12,
769,
304,
489,
746,
1722,
360,
2062,
1059,
769,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
7905,
28361,
8,
277,
12,
574,
304,
272,
327,
7905,
314,
16954,
272,
340,
1228,
8,
585,
12,
769,
304,
489,
372,
359,
7306,
9454,
25402,
28361,
8,
73,
9,
367,
284,
315,
574,
61,
272,
587,
26,
489,
372,
7905,
9454,
25402,
28361,
8,
585,
9,
421,
199,
533,
485,
4082,
1547,
804,
304,
523,
408,
4082,
2202,
12,
883,
1172,
314,
1338,
283,
3910,
7,
503,
283,
2052,
23690,
819,
347,
485,
12584,
8,
277,
12,
574,
304,
272,
340,
574,
1137,
283,
2052,
7,
436,
574,
1137,
283,
3910,
356,
489,
746,
1722,
360,
2062,
2155,
27,
4788,
450,
82,
7,
450,
574,
9,
819,
347,
12134,
14206,
8,
277,
12,
574,
304,
272,
291,
423,
12584,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Coread/channels
|
tests/test_sessions.py
|
1
|
13015
|
from __future__ import unicode_literals
from django.conf import settings
from django.test import override_settings
from channels import DEFAULT_CHANNEL_LAYER, channel_layers
from channels.message import Message
from channels.sessions import (
channel_and_http_session, channel_session, enforce_ordering, http_session, session_for_reply_channel,
)
from channels.test import ChannelTestCase
try:
from unittest import mock
except ImportError:
import mock
@override_settings(SESSION_ENGINE="django.contrib.sessions.backends.cache")
class SessionTests(ChannelTestCase):
"""
Tests the channels session module.
"""
def test_session_for_reply_channel(self):
"""
Tests storing and retrieving values by reply_channel.
"""
session1 = session_for_reply_channel("test-reply-channel")
session1["testvalue"] = 42
session1.save(must_create=True)
session2 = session_for_reply_channel("test-reply-channel")
self.assertEqual(session2["testvalue"], 42)
def test_channel_session(self):
"""
Tests the channel_session decorator
"""
# Construct message to send
message = Message({"reply_channel": "test-reply"}, None, None)
# Run through a simple fake consumer that assigns to it
@channel_session
def inner(message):
message.channel_session["num_ponies"] = -1
inner(message)
# Test the session worked
session2 = session_for_reply_channel("test-reply")
self.assertEqual(session2["num_ponies"], -1)
def test_channel_session_method(self):
"""
Tests the channel_session decorator works on methods
"""
# Construct message to send
message = Message({"reply_channel": "test-reply"}, None, None)
# Run through a simple fake consumer that assigns to it
class Consumer(object):
@channel_session
def inner(self, message):
message.channel_session["num_ponies"] = -1
Consumer().inner(message)
# Test the session worked
session2 = session_for_reply_channel("test-reply")
self.assertEqual(session2["num_ponies"], -1)
def test_channel_session_third_arg(self):
"""
Tests the channel_session decorator with message as 3rd argument
"""
# Construct message to send
message = Message({"reply_channel": "test-reply"}, None, None)
# Run through a simple fake consumer that assigns to it
@channel_session
def inner(a, b, message):
message.channel_session["num_ponies"] = -1
with self.assertRaisesMessage(ValueError, 'channel_session called without Message instance'):
inner(None, None, message)
def test_channel_session_double(self):
"""
Tests the channel_session decorator detects being wrapped in itself
and doesn't blow up.
"""
# Construct message to send
message = Message({"reply_channel": "test-reply"}, None, None)
# Run through a simple fake consumer that should trigger the error
@channel_session
@channel_session
def inner(message):
message.channel_session["num_ponies"] = -1
inner(message)
# Test the session worked
session2 = session_for_reply_channel("test-reply")
self.assertEqual(session2["num_ponies"], -1)
def test_channel_session_double_method(self):
"""
Tests the channel_session decorator detects being wrapped in itself
and doesn't blow up. Method version.
"""
# Construct message to send
message = Message({"reply_channel": "test-reply"}, None, None)
# Run through a simple fake consumer that should trigger the error
class Consumer(object):
@channel_session
@channel_session
def inner(self, message):
message.channel_session["num_ponies"] = -1
Consumer().inner(message)
# Test the session worked
session2 = session_for_reply_channel("test-reply")
self.assertEqual(session2["num_ponies"], -1)
def test_channel_session_double_third_arg(self):
"""
Tests the channel_session decorator detects being wrapped in itself
and doesn't blow up.
"""
# Construct message to send
message = Message({"reply_channel": "test-reply"}, None, None)
# Run through a simple fake consumer that should trigger the error
@channel_session
@channel_session
def inner(a, b, message):
message.channel_session["num_ponies"] = -1
with self.assertRaisesMessage(ValueError, 'channel_session called without Message instance'):
inner(None, None, message)
def test_channel_session_no_reply(self):
"""
Tests the channel_session decorator detects no reply channel
"""
# Construct message to send
message = Message({}, None, None)
# Run through a simple fake consumer that should trigger the error
@channel_session
@channel_session
def inner(message):
message.channel_session["num_ponies"] = -1
with self.assertRaises(ValueError):
inner(message)
def test_channel_session_no_reply_method(self):
"""
Tests the channel_session decorator detects no reply channel
"""
# Construct message to send
message = Message({}, None, None)
# Run through a simple fake consumer that should trigger the error
class Consumer(object):
@channel_session
@channel_session
def inner(self, message):
message.channel_session["num_ponies"] = -1
with self.assertRaises(ValueError):
Consumer().inner(message)
def test_channel_session_no_reply_third_arg(self):
"""
Tests the channel_session decorator detects no reply channel
"""
# Construct message to send
message = Message({}, None, None)
# Run through a simple fake consumer that should trigger the error
@channel_session
@channel_session
def inner(a, b, message):
message.channel_session["num_ponies"] = -1
with self.assertRaisesMessage(ValueError, 'channel_session called without Message instance'):
inner(None, None, message)
def test_http_session(self):
"""
Tests that http_session correctly extracts a session cookie.
"""
# Make a session to try against
session1 = session_for_reply_channel("test-reply")
# Construct message to send
message = Message({
"reply_channel": "test-reply",
"http_version": "1.1",
"method": "GET",
"path": "/test2/",
"headers": {
"host": b"example.com",
"cookie": ("%s=%s" % (settings.SESSION_COOKIE_NAME, session1.session_key)).encode("ascii"),
},
}, None, None)
# Run it through http_session, make sure it works (test double here too)
@http_session
@http_session
def inner(message):
message.http_session["species"] = "horse"
inner(message)
# Check value assignment stuck
session2 = session_for_reply_channel("test-reply")
self.assertEqual(session2["species"], "horse")
def test_channel_and_http_session(self):
"""
Tests that channel_and_http_session decorator stores the http session key and hydrates it when expected
"""
# Make a session to try against
session = session_for_reply_channel("test-reply-session")
# Construct message to send
message = Message({
"reply_channel": "test-reply-session",
"http_version": "1.1",
"method": "GET",
"path": "/test2/",
"headers": {
"host": b"example.com",
"cookie": ("%s=%s" % (settings.SESSION_COOKIE_NAME, session.session_key)).encode("ascii"),
},
}, None, None)
@channel_and_http_session
def inner(message):
pass
inner(message)
# It should store the session key
self.assertEqual(message.channel_session[settings.SESSION_COOKIE_NAME], session.session_key)
# Construct a new message
message2 = Message({"reply_channel": "test-reply-session", "path": "/"}, None, None)
inner(message2)
# It should hydrate the http_session
self.assertEqual(message2.http_session.session_key, session.session_key)
def test_enforce_ordering(self):
"""
Tests that strict mode of enforce_ordering works
"""
# Construct messages to send
message0 = Message(
{"reply_channel": "test-reply-b", "order": 0},
"websocket.connect",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
message1 = Message(
{"reply_channel": "test-reply-b", "order": 1},
"websocket.receive",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
message2 = Message(
{"reply_channel": "test-reply-b", "order": 2},
"websocket.receive",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
# Run them in an acceptable strict order
@enforce_ordering
def inner(message):
pass
inner(message0)
inner(message1)
inner(message2)
# Ensure wait channel is empty
wait_channel = "__wait__.%s" % "test-reply-b"
next_message = self.get_next_message(wait_channel)
self.assertEqual(next_message, None)
def test_enforce_ordering_fail(self):
"""
Tests that strict mode of enforce_ordering fails on bad ordering
"""
# Construct messages to send
message0 = Message(
{"reply_channel": "test-reply-c", "order": 0},
"websocket.connect",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
message2 = Message(
{"reply_channel": "test-reply-c", "order": 2},
"websocket.receive",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
# Run them in an acceptable strict order
@enforce_ordering
def inner(message):
pass
inner(message0)
inner(message2)
# Ensure wait channel is not empty
wait_channel = "__wait__.%s" % "test-reply-c"
next_message = self.get_next_message(wait_channel)
self.assertNotEqual(next_message, None)
def test_enforce_ordering_fail_no_order(self):
"""
Makes sure messages with no "order" key fail
"""
message0 = Message(
{"reply_channel": "test-reply-d"},
None,
channel_layers[DEFAULT_CHANNEL_LAYER]
)
@enforce_ordering
def inner(message):
pass
with self.assertRaises(ValueError):
inner(message0)
def test_enforce_ordering_concurrent(self):
"""
Tests that strict mode of enforce_ordering puts messages in the correct queue after
the current message number changes while the message is being processed
"""
# Construct messages to send
message0 = Message(
{"reply_channel": "test-reply-e", "order": 0},
"websocket.connect",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
message2 = Message(
{"reply_channel": "test-reply-e", "order": 2},
"websocket.receive",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
message3 = Message(
{"reply_channel": "test-reply-e", "order": 3},
"websocket.receive",
channel_layers[DEFAULT_CHANNEL_LAYER]
)
@channel_session
def add_session(message):
pass
# Run them in an acceptable strict order
@enforce_ordering
def inner(message):
pass
inner(message0)
inner(message3)
# Add the session now so it can be mocked
add_session(message2)
with mock.patch.object(message2.channel_session, 'load', return_value={'__channels_next_order': 2}):
inner(message2)
# Ensure wait channel is empty
wait_channel = "__wait__.%s" % "test-reply-e"
next_message = self.get_next_message(wait_channel)
self.assertEqual(next_message, None)
# Ensure messages 3 and 2 both ended up back on the original channel
expected = {
2: message2,
3: message3
}
for m in range(2):
message = self.get_next_message("websocket.receive")
expected.pop(message.content['order'])
self.assertEqual(expected, {})
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
396,
492,
4278,
63,
1751,
199,
199,
504,
9245,
492,
6186,
63,
14833,
63,
24167,
12,
3623,
63,
4359,
199,
504,
9245,
14,
1188,
492,
6430,
199,
504,
9245,
14,
11676,
492,
334,
272,
3623,
63,
460,
63,
1014,
63,
1730,
12,
3623,
63,
1730,
12,
15814,
63,
7128,
12,
1455,
63,
1730,
12,
2351,
63,
509,
63,
8102,
63,
2775,
12,
199,
9,
199,
504,
9245,
14,
396,
492,
17270,
1746,
199,
199,
893,
26,
272,
687,
2882,
492,
1683,
199,
2590,
3545,
26,
272,
492,
1683,
421,
199,
32,
4415,
63,
1751,
8,
12763,
63,
15956,
628,
1176,
14,
2828,
14,
11676,
14,
7765,
14,
1637,
531,
199,
533,
8596,
2925,
8,
5358,
1746,
304,
272,
408,
272,
6496,
314,
9245,
2351,
859,
14,
272,
408,
339,
347,
511,
63,
1730,
63,
509,
63,
8102,
63,
2775,
8,
277,
304,
267,
408,
267,
6496,
16915,
436,
23812,
1338,
701,
9351,
63,
2775,
14,
267,
408,
267,
2351,
17,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
13,
2775,
531,
267,
2351,
17,
905,
396,
585,
937,
275,
5685,
267,
2351,
17,
14,
2117,
8,
7790,
63,
981,
29,
549,
9,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
13,
2775,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
396,
585,
2255,
5685,
9,
339,
347,
511,
63,
2775,
63,
1730,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
465,
20440,
370,
652,
267,
768,
2775,
63,
1730,
267,
347,
6506,
8,
1188,
304,
288,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
398,
6506,
8,
1188,
9,
267,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
765,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
5419,
641,
3102,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
465,
20440,
370,
652,
267,
1021,
1448,
5391,
8,
785,
304,
288,
768,
2775,
63,
1730,
288,
347,
6506,
8,
277,
12,
1245,
304,
355,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
398,
1448,
5391,
1252,
5216,
8,
1188,
9,
267,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
11470,
63,
1273,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
543,
1245,
465,
650,
6883,
1423,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
465,
20440,
370,
652,
267,
768,
2775,
63,
1730,
267,
347,
6506,
8,
65,
12,
330,
12,
1245,
304,
288,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
398,
543,
291,
14,
14638,
8,
3393,
12,
283,
2775,
63,
1730,
2797,
1928,
6430,
1256,
735,
288,
6506,
8,
403,
12,
488,
12,
1245,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
3157,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
477,
28853,
3769,
8072,
315,
6337,
267,
436,
3181,
1133,
28511,
1536,
14,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
1077,
6804,
314,
1125,
267,
768,
2775,
63,
1730,
267,
768,
2775,
63,
1730,
267,
347,
6506,
8,
1188,
304,
288,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
267,
6506,
8,
1188,
9,
398,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
3157,
63,
765,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
477,
28853,
3769,
8072,
315,
6337,
267,
436,
3181,
1133,
28511,
1536,
14,
9075,
1015,
14,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
1077,
6804,
314,
1125,
267,
1021,
1448,
5391,
8,
785,
304,
288,
768,
2775,
63,
1730,
288,
768,
2775,
63,
1730,
288,
347,
6506,
8,
277,
12,
1245,
304,
355,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
267,
1448,
5391,
1252,
5216,
8,
1188,
9,
398,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
3157,
63,
11470,
63,
1273,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
477,
28853,
3769,
8072,
315,
6337,
267,
436,
3181,
1133,
28511,
1536,
14,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
396,
492,
4278,
63,
1751,
199,
199,
504,
9245,
492,
6186,
63,
14833,
63,
24167,
12,
3623,
63,
4359,
199,
504,
9245,
14,
1188,
492,
6430,
199,
504,
9245,
14,
11676,
492,
334,
272,
3623,
63,
460,
63,
1014,
63,
1730,
12,
3623,
63,
1730,
12,
15814,
63,
7128,
12,
1455,
63,
1730,
12,
2351,
63,
509,
63,
8102,
63,
2775,
12,
199,
9,
199,
504,
9245,
14,
396,
492,
17270,
1746,
199,
199,
893,
26,
272,
687,
2882,
492,
1683,
199,
2590,
3545,
26,
272,
492,
1683,
421,
199,
32,
4415,
63,
1751,
8,
12763,
63,
15956,
628,
1176,
14,
2828,
14,
11676,
14,
7765,
14,
1637,
531,
199,
533,
8596,
2925,
8,
5358,
1746,
304,
272,
408,
272,
6496,
314,
9245,
2351,
859,
14,
272,
408,
339,
347,
511,
63,
1730,
63,
509,
63,
8102,
63,
2775,
8,
277,
304,
267,
408,
267,
6496,
16915,
436,
23812,
1338,
701,
9351,
63,
2775,
14,
267,
408,
267,
2351,
17,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
13,
2775,
531,
267,
2351,
17,
905,
396,
585,
937,
275,
5685,
267,
2351,
17,
14,
2117,
8,
7790,
63,
981,
29,
549,
9,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
13,
2775,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
396,
585,
2255,
5685,
9,
339,
347,
511,
63,
2775,
63,
1730,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
465,
20440,
370,
652,
267,
768,
2775,
63,
1730,
267,
347,
6506,
8,
1188,
304,
288,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
398,
6506,
8,
1188,
9,
267,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
765,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
5419,
641,
3102,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
465,
20440,
370,
652,
267,
1021,
1448,
5391,
8,
785,
304,
288,
768,
2775,
63,
1730,
288,
347,
6506,
8,
277,
12,
1245,
304,
355,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
398,
1448,
5391,
1252,
5216,
8,
1188,
9,
267,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
11470,
63,
1273,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
543,
1245,
465,
650,
6883,
1423,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
465,
20440,
370,
652,
267,
768,
2775,
63,
1730,
267,
347,
6506,
8,
65,
12,
330,
12,
1245,
304,
288,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
398,
543,
291,
14,
14638,
8,
3393,
12,
283,
2775,
63,
1730,
2797,
1928,
6430,
1256,
735,
288,
6506,
8,
403,
12,
488,
12,
1245,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
3157,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
477,
28853,
3769,
8072,
315,
6337,
267,
436,
3181,
1133,
28511,
1536,
14,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
1077,
6804,
314,
1125,
267,
768,
2775,
63,
1730,
267,
768,
2775,
63,
1730,
267,
347,
6506,
8,
1188,
304,
288,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
267,
6506,
8,
1188,
9,
398,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
3157,
63,
765,
8,
277,
304,
267,
408,
267,
6496,
314,
3623,
63,
1730,
7531,
477,
28853,
3769,
8072,
315,
6337,
267,
436,
3181,
1133,
28511,
1536,
14,
9075,
1015,
14,
267,
408,
267,
327,
9215,
1245,
370,
3222,
267,
1245,
275,
6430,
6333,
8102,
63,
2775,
582,
298,
396,
13,
8102,
6018,
488,
12,
488,
9,
398,
327,
3378,
4012,
282,
3486,
4026,
9790,
626,
1077,
6804,
314,
1125,
267,
1021,
1448,
5391,
8,
785,
304,
288,
768,
2775,
63,
1730,
288,
768,
2775,
63,
1730,
288,
347,
6506,
8,
277,
12,
1245,
304,
355,
1245,
14,
2775,
63,
1730,
905,
1507,
63,
678,
1500,
937,
275,
446,
17,
267,
1448,
5391,
1252,
5216,
8,
1188,
9,
398,
327,
1379,
314,
2351,
26731,
267,
2351,
18,
275,
2351,
63,
509,
63,
8102,
63,
2775,
480,
396,
13,
8102,
531,
267,
291,
14,
629,
8,
1730,
18,
905,
1507,
63,
678,
1500,
2255,
446,
17,
9,
339,
347,
511,
63,
2775,
63,
1730,
63,
3157,
63,
11470,
63,
1273,
8,
277,
304,
267,
408,
267,
6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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
] |
kiddinn/plaso
|
plaso/containers/event_sources.py
|
4
|
1631
|
# -*- coding: utf-8 -*-
"""Event source attribute containers."""
from plaso.containers import interface
from plaso.containers import manager
class EventSource(interface.AttributeContainer):
"""Event source attribute container.
The event source object contains information about where a specific
event originates e.g. a file, the $STANDARD_INFORMATION MFT attribute,
or Application Compatibility cache.
Attributes:
data_type (str): attribute container type indicator.
file_entry_type (str): dfVFS file entry type.
path_spec (dfvfs.PathSpec): path specification.
"""
CONTAINER_TYPE = 'event_source'
DATA_TYPE = None
def __init__(self, path_spec=None):
"""Initializes an event source.
Args:
path_spec (Optional[dfvfs.PathSpec]): path specification.
"""
super(EventSource, self).__init__()
self.data_type = self.DATA_TYPE
self.file_entry_type = None
self.path_spec = path_spec
# This method is necessary for heap sort.
def __lt__(self, other):
"""Compares if the event source attribute container is less than the other.
Args:
other (EventSource): event source attribute container to compare to.
Returns:
bool: True if the event source attribute container is less than the other.
"""
return self.path_spec.comparable < other.path_spec.comparable
class FileEntryEventSource(EventSource):
"""File entry event source.
The file entry event source is an event source that represents a file
within a file system.
"""
DATA_TYPE = 'file_entry'
manager.AttributeContainersManager.RegisterAttributeContainer(EventSource)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2390,
1350,
2225,
15333,
1041,
199,
199,
504,
1620,
305,
79,
14,
13577,
492,
3217,
199,
504,
1620,
305,
79,
14,
13577,
492,
5256,
421,
199,
533,
6763,
2980,
8,
3266,
14,
1646,
4076,
304,
523,
408,
2390,
1350,
2225,
3970,
14,
819,
710,
1566,
1350,
909,
3509,
2556,
3595,
2382,
282,
2488,
523,
1566,
6330,
2335,
325,
14,
71,
14,
282,
570,
12,
314,
2672,
19547,
63,
21583,
603,
2161,
2225,
12,
523,
503,
13515,
3599,
5880,
2581,
14,
819,
9382,
26,
272,
666,
63,
466,
334,
495,
304,
2225,
3970,
730,
16385,
14,
272,
570,
63,
2373,
63,
466,
334,
495,
304,
4051,
54,
7079,
570,
2397,
730,
14,
272,
931,
63,
1650,
334,
1587,
20970,
14,
2042,
5307,
304,
931,
8929,
14,
523,
408,
523,
1868,
6166,
568,
540,
63,
2711,
275,
283,
1430,
63,
1365,
7,
523,
7126,
63,
2711,
275,
488,
819,
347,
636,
826,
721,
277,
12,
931,
63,
1650,
29,
403,
304,
272,
408,
23489,
376,
1566,
1350,
14,
339,
3033,
26,
489,
931,
63,
1650,
334,
7012,
59,
1587,
20970,
14,
2042,
5307,
4682,
931,
8929,
14,
272,
408,
272,
1613,
8,
2390,
2980,
12,
291,
2843,
826,
4533,
272,
291,
14,
576,
63,
466,
275,
291,
14,
3998,
63,
2711,
272,
291,
14,
493,
63,
2373,
63,
466,
275,
488,
272,
291,
14,
515,
63,
1650,
275,
931,
63,
1650,
819,
327,
961,
1083,
365,
5784,
367,
13295,
4069,
14,
523,
347,
636,
4116,
721,
277,
12,
1163,
304,
272,
408,
2404,
11044,
340,
314,
1566,
1350,
2225,
3970,
365,
6656,
2419,
314,
1163,
14,
339,
3033,
26,
489,
1163,
334,
2390,
2980,
304,
1566,
1350,
2225,
3970,
370,
6540,
370,
14,
339,
1803,
26,
489,
2155,
26,
715,
340,
314,
1566,
1350,
2225,
3970,
365,
6656,
2419,
314,
1163,
14,
272,
408,
272,
372,
291,
14,
515,
63,
1650,
14,
863,
19816,
665,
1163,
14,
515,
63,
1650,
14,
863,
19816,
421,
199,
533,
3814,
3900,
2390,
2980,
8,
2390,
2980,
304,
523,
408,
1173,
2397,
1566,
1350,
14,
819,
710,
570,
2397,
1566,
1350,
365,
376,
1566,
1350,
626,
8469,
282,
570,
523,
4453,
282,
570,
2656,
14,
523,
408,
523,
7126,
63,
2711,
275,
283,
493,
63,
2373,
7,
421,
199,
2609,
14,
1646,
31266,
1192,
2988,
14,
7099,
1646,
4076,
8,
2390,
2980,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2390,
1350,
2225,
15333,
1041,
199,
199,
504,
1620,
305,
79,
14,
13577,
492,
3217,
199,
504,
1620,
305,
79,
14,
13577,
492,
5256,
421,
199,
533,
6763,
2980,
8,
3266,
14,
1646,
4076,
304,
523,
408,
2390,
1350,
2225,
3970,
14,
819,
710,
1566,
1350,
909,
3509,
2556,
3595,
2382,
282,
2488,
523,
1566,
6330,
2335,
325,
14,
71,
14,
282,
570,
12,
314,
2672,
19547,
63,
21583,
603,
2161,
2225,
12,
523,
503,
13515,
3599,
5880,
2581,
14,
819,
9382,
26,
272,
666,
63,
466,
334,
495,
304,
2225,
3970,
730,
16385,
14,
272,
570,
63,
2373,
63,
466,
334,
495,
304,
4051,
54,
7079,
570,
2397,
730,
14,
272,
931,
63,
1650,
334,
1587,
20970,
14,
2042,
5307,
304,
931,
8929,
14,
523,
408,
523,
1868,
6166,
568,
540,
63,
2711,
275,
283,
1430,
63,
1365,
7,
523,
7126,
63,
2711,
275,
488,
819,
347,
636,
826,
721,
277,
12,
931,
63,
1650,
29,
403,
304,
272,
408,
23489,
376,
1566,
1350,
14,
339,
3033,
26,
489,
931,
63,
1650,
334,
7012,
59,
1587,
20970,
14,
2042,
5307,
4682,
931,
8929,
14,
272,
408,
272,
1613,
8,
2390,
2980,
12,
291,
2843,
826,
4533,
272,
291,
14,
576,
63,
466,
275,
291,
14,
3998,
63,
2711,
272,
291,
14,
493,
63,
2373,
63,
466,
275,
488,
272,
291,
14,
515,
63,
1650,
275,
931,
63,
1650,
819,
327,
961,
1083,
365,
5784,
367,
13295,
4069,
14,
523,
347,
636,
4116,
721,
277,
12,
1163,
304,
272,
408,
2404,
11044,
340,
314,
1566,
1350,
2225,
3970,
365,
6656,
2419,
314,
1163,
14,
339,
3033,
26,
489,
1163,
334,
2390,
2980,
304,
1566,
1350,
2225,
3970,
370,
6540,
370,
14,
339,
1803,
26,
489,
2155,
26,
715,
340,
314,
1566,
1350,
2225,
3970,
365,
6656,
2419,
314,
1163,
14,
272,
408,
272,
372,
291,
14,
515,
63,
1650,
14,
863,
19816,
665,
1163,
14,
515,
63,
1650,
14,
863,
19816,
421,
199,
533,
3814,
3900,
2390,
2980,
8,
2390,
2980,
304,
523,
408,
1173,
2397,
1566,
1350,
14,
819,
710,
570,
2397,
1566,
1350,
365,
376,
1566,
1350,
626,
8469,
282,
570,
523,
4453,
282,
570,
2656,
14,
523,
408,
523,
7126,
63,
2711,
275,
283,
493,
63,
2373,
7,
421,
199,
2609,
14,
1646,
31266,
1192,
2988,
14,
7099,
1646,
4076,
8,
2390,
2980,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bgris/ODL_bgris
|
lib/python3.5/site-packages/Sphinx-1.5.1-py3.5.egg/sphinx/util/docfields.py
|
4
|
12386
|
# -*- coding: utf-8 -*-
"""
sphinx.util.docfields
~~~~~~~~~~~~~~~~~~~~~
"Doc fields" are reST field lists in object descriptions that will
be domain-specifically transformed to a more appealing presentation.
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import absolute_import
from docutils import nodes
from sphinx import addnodes
def _is_single_paragraph(node):
"""True if the node only contains one paragraph (and system messages)."""
if len(node) == 0:
return False
elif len(node) > 1:
for subnode in node[1:]:
if not isinstance(subnode, nodes.system_message):
return False
if isinstance(node[0], nodes.paragraph):
return True
return False
class Field(object):
"""A doc field that is never grouped. It can have an argument or not, the
argument can be linked using a specified *rolename*. Field should be used
for doc fields that usually don't occur more than once.
The body can be linked using a specified *bodyrolename* if the content is
just a single inline or text node.
Example::
:returns: description of the return value
:rtype: description of the return type
"""
is_grouped = False
is_typed = False
def __init__(self, name, names=(), label=None, has_arg=True, rolename=None,
bodyrolename=None):
self.name = name
self.names = names
self.label = label
self.has_arg = has_arg
self.rolename = rolename
self.bodyrolename = bodyrolename
def make_xref(self, rolename, domain, target,
innernode=addnodes.literal_emphasis, contnode=None):
if not rolename:
return contnode or innernode(target, target)
refnode = addnodes.pending_xref('', refdomain=domain, refexplicit=False,
reftype=rolename, reftarget=target)
refnode += contnode or innernode(target, target)
return refnode
def make_xrefs(self, rolename, domain, target,
innernode=addnodes.literal_emphasis, contnode=None):
return [self.make_xref(rolename, domain, target, innernode, contnode)]
def make_entry(self, fieldarg, content):
return (fieldarg, content)
def make_field(self, types, domain, item):
fieldarg, content = item
fieldname = nodes.field_name('', self.label)
if fieldarg:
fieldname += nodes.Text(' ')
fieldname.extend(self.make_xrefs(self.rolename, domain,
fieldarg, nodes.Text))
if len(content) == 1 and (
isinstance(content[0], nodes.Text) or
(isinstance(content[0], nodes.inline) and len(content[0]) == 1 and
isinstance(content[0][0], nodes.Text))):
content = self.make_xrefs(self.bodyrolename, domain,
content[0].astext(), contnode=content[0])
fieldbody = nodes.field_body('', nodes.paragraph('', '', *content))
return nodes.field('', fieldname, fieldbody)
class GroupedField(Field):
"""
A doc field that is grouped; i.e., all fields of that type will be
transformed into one field with its body being a bulleted list. It always
has an argument. The argument can be linked using the given *rolename*.
GroupedField should be used for doc fields that can occur more than once.
If *can_collapse* is true, this field will revert to a Field if only used
once.
Example::
:raises ErrorClass: description when it is raised
"""
is_grouped = True
list_type = nodes.bullet_list
def __init__(self, name, names=(), label=None, rolename=None,
can_collapse=False):
Field.__init__(self, name, names, label, True, rolename)
self.can_collapse = can_collapse
def make_field(self, types, domain, items):
fieldname = nodes.field_name('', self.label)
listnode = self.list_type()
for fieldarg, content in items:
par = nodes.paragraph()
par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
addnodes.literal_strong))
par += nodes.Text(' -- ')
par += content
listnode += nodes.list_item('', par)
if len(items) == 1 and self.can_collapse:
fieldbody = nodes.field_body('', listnode[0][0])
return nodes.field('', fieldname, fieldbody)
fieldbody = nodes.field_body('', listnode)
return nodes.field('', fieldname, fieldbody)
class TypedField(GroupedField):
"""
A doc field that is grouped and has type information for the arguments. It
always has an argument. The argument can be linked using the given
*rolename*, the type using the given *typerolename*.
Two uses are possible: either parameter and type description are given
separately, using a field from *names* and one from *typenames*,
respectively, or both are given using a field from *names*, see the example.
Example::
:param foo: description of parameter foo
:type foo: SomeClass
-- or --
:param SomeClass foo: description of parameter foo
"""
is_typed = True
def __init__(self, name, names=(), typenames=(), label=None,
rolename=None, typerolename=None, can_collapse=False):
GroupedField.__init__(self, name, names, label, rolename, can_collapse)
self.typenames = typenames
self.typerolename = typerolename
def make_field(self, types, domain, items):
def handle_item(fieldarg, content):
par = nodes.paragraph()
par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
addnodes.literal_strong))
if fieldarg in types:
par += nodes.Text(' (')
# NOTE: using .pop() here to prevent a single type node to be
# inserted twice into the doctree, which leads to
# inconsistencies later when references are resolved
fieldtype = types.pop(fieldarg)
if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text):
typename = u''.join(n.astext() for n in fieldtype)
par.extend(self.make_xrefs(self.typerolename, domain, typename,
addnodes.literal_emphasis))
else:
par += fieldtype
par += nodes.Text(')')
par += nodes.Text(' -- ')
par += content
return par
fieldname = nodes.field_name('', self.label)
if len(items) == 1 and self.can_collapse:
fieldarg, content = items[0]
bodynode = handle_item(fieldarg, content)
else:
bodynode = self.list_type()
for fieldarg, content in items:
bodynode += nodes.list_item('', handle_item(fieldarg, content))
fieldbody = nodes.field_body('', bodynode)
return nodes.field('', fieldname, fieldbody)
class DocFieldTransformer(object):
"""
Transforms field lists in "doc field" syntax into better-looking
equivalents, using the field type definitions given on a domain.
"""
def __init__(self, directive):
self.domain = directive.domain
if '_doc_field_type_map' not in directive.__class__.__dict__:
directive.__class__._doc_field_type_map = \
self.preprocess_fieldtypes(directive.__class__.doc_field_types)
self.typemap = directive._doc_field_type_map
def preprocess_fieldtypes(self, types):
typemap = {}
for fieldtype in types:
for name in fieldtype.names:
typemap[name] = fieldtype, False
if fieldtype.is_typed:
for name in fieldtype.typenames:
typemap[name] = fieldtype, True
return typemap
def transform_all(self, node):
"""Transform all field list children of a node."""
# don't traverse, only handle field lists that are immediate children
for child in node:
if isinstance(child, nodes.field_list):
self.transform(child)
def transform(self, node):
"""Transform a single field list *node*."""
typemap = self.typemap
entries = []
groupindices = {}
types = {}
# step 1: traverse all fields and collect field types and content
for field in node:
fieldname, fieldbody = field
try:
# split into field type and argument
fieldtype, fieldarg = fieldname.astext().split(None, 1)
except ValueError:
# maybe an argument-less field type?
fieldtype, fieldarg = fieldname.astext(), ''
typedesc, is_typefield = typemap.get(fieldtype, (None, None))
# sort out unknown fields
if typedesc is None or typedesc.has_arg != bool(fieldarg):
# either the field name is unknown, or the argument doesn't
# match the spec; capitalize field name and be done with it
new_fieldname = fieldtype[0:1].upper() + fieldtype[1:]
if fieldarg:
new_fieldname += ' ' + fieldarg
fieldname[0] = nodes.Text(new_fieldname)
entries.append(field)
continue
typename = typedesc.name
# collect the content, trying not to keep unnecessary paragraphs
if _is_single_paragraph(fieldbody):
content = fieldbody.children[0].children
else:
content = fieldbody.children
# if the field specifies a type, put it in the types collection
if is_typefield:
# filter out only inline nodes; others will result in invalid
# markup being written out
content = [n for n in content if isinstance(n, nodes.Inline) or
isinstance(n, nodes.Text)]
if content:
types.setdefault(typename, {})[fieldarg] = content
continue
# also support syntax like ``:param type name:``
if typedesc.is_typed:
try:
argtype, argname = fieldarg.split(None, 1)
except ValueError:
pass
else:
types.setdefault(typename, {})[argname] = \
[nodes.Text(argtype)]
fieldarg = argname
translatable_content = nodes.inline(fieldbody.rawsource,
translatable=True)
translatable_content.source = fieldbody.parent.source
translatable_content.line = fieldbody.parent.line
translatable_content += content
# grouped entries need to be collected in one entry, while others
# get one entry per field
if typedesc.is_grouped:
if typename in groupindices:
group = entries[groupindices[typename]]
else:
groupindices[typename] = len(entries)
group = [typedesc, []]
entries.append(group)
entry = typedesc.make_entry(fieldarg, [translatable_content])
group[1].append(entry)
else:
entry = typedesc.make_entry(fieldarg, [translatable_content])
entries.append([typedesc, entry])
# step 2: all entries are collected, construct the new field list
new_list = nodes.field_list()
for entry in entries:
if isinstance(entry, nodes.field):
# pass-through old field
new_list += entry
else:
fieldtype, content = entry
fieldtypes = types.get(fieldtype.name, {})
new_list += fieldtype.make_field(fieldtypes, self.domain,
content)
node.replace_self(new_list)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
15882,
14,
1974,
14,
1301,
955,
272,
18294,
2878,
94,
339,
298,
3768,
1504,
2,
787,
20883,
901,
5548,
315,
909,
18714,
626,
911,
272,
506,
2881,
13,
6100,
1183,
14834,
370,
282,
1655,
5704,
29515,
3451,
425,
14,
339,
520,
7307,
26,
1898,
10219,
13,
9261,
701,
314,
10229,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
18382,
492,
3380,
199,
199,
504,
15882,
492,
1050,
2415,
421,
199,
318,
485,
374,
63,
4780,
63,
12400,
8,
932,
304,
272,
408,
549,
340,
314,
1031,
1454,
3509,
1373,
13168,
334,
460,
2656,
3788,
10477,
272,
340,
822,
8,
932,
9,
508,
378,
26,
267,
372,
756,
272,
916,
822,
8,
932,
9,
690,
413,
26,
267,
367,
1007,
932,
315,
1031,
59,
17,
10688,
288,
340,
440,
1228,
8,
954,
932,
12,
3380,
14,
2253,
63,
1188,
304,
355,
372,
756,
272,
340,
1228,
8,
932,
59,
16,
467,
3380,
14,
12400,
304,
267,
372,
715,
272,
372,
756,
421,
199,
533,
5024,
8,
785,
304,
272,
408,
33,
1382,
901,
626,
365,
7078,
16251,
14,
221,
2779,
883,
1172,
376,
1423,
503,
440,
12,
314,
272,
1423,
883,
506,
10632,
1808,
282,
2013,
627,
3756,
354,
4856,
221,
5024,
1077,
506,
1202,
272,
367,
1382,
1504,
626,
9987,
2793,
1133,
4781,
1655,
2419,
5403,
14,
339,
710,
2396,
883,
506,
10632,
1808,
282,
2013,
627,
2030,
3756,
354,
10,
340,
314,
1564,
365,
272,
2951,
282,
2849,
8308,
503,
1318,
1031,
14,
339,
5679,
447,
10817,
520,
5808,
26,
1369,
402,
314,
372,
574,
2126,
520,
4500,
26,
1369,
402,
314,
372,
730,
272,
408,
272,
365,
63,
22674,
275,
756,
272,
365,
63,
22033,
275,
756,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1561,
16729,
1768,
29,
403,
12,
965,
63,
1273,
29,
549,
12,
4719,
354,
29,
403,
12,
326,
2396,
3756,
354,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1247,
275,
1561,
267,
291,
14,
1302,
275,
1768,
267,
291,
14,
1989,
63,
1273,
275,
965,
63,
1273,
267,
291,
14,
3756,
354,
275,
4719,
354,
267,
291,
14,
2030,
3756,
354,
275,
2396,
3756,
354,
339,
347,
1852,
63,
31332,
8,
277,
12,
4719,
354,
12,
2881,
12,
1347,
12,
2116,
6506,
932,
29,
525,
2415,
14,
8939,
63,
28907,
12,
13770,
932,
29,
403,
304,
267,
340,
440,
4719,
354,
26,
288,
372,
13770,
932,
503,
6506,
932,
8,
1375,
12,
1347,
9,
267,
2984,
932,
275,
1050,
2415,
14,
6455,
63,
31332,
8594,
2984,
2261,
29,
2261,
12,
2984,
10306,
29,
797,
12,
3147,
2984,
466,
29,
3756,
354,
12,
295,
856,
839,
29,
1375,
9,
267,
2984,
932,
847,
13770,
932,
503,
6506,
932,
8,
1375,
12,
1347,
9,
267,
372,
2984,
932,
339,
347,
1852,
63,
88,
7655,
8,
277,
12,
4719,
354,
12,
2881,
12,
1347,
12,
673,
6506,
932,
29,
525,
2415,
14,
8939,
63,
28907,
12,
13770,
932,
29,
403,
304,
267,
372,
359,
277,
14,
1875,
63,
31332,
8,
3756,
354,
12,
2881,
12,
1347,
12,
6506,
932,
12,
13770,
932,
1874,
339,
347,
1852,
63,
2373,
8,
277,
12,
901,
1273,
12,
1564,
304,
267,
372,
334,
698,
1273,
12,
1564,
9,
339,
347,
1852,
63,
698,
8,
277,
12,
2943,
12,
2881,
12,
1242,
304,
267,
901,
1273,
12,
1564,
275,
1242,
267,
18887,
275,
3380,
14,
698,
63,
354,
8594,
291,
14,
1302,
9,
267,
340,
901,
1273,
26,
288,
18887,
847,
3380,
14,
1872,
360,
5320,
288,
18887,
14,
2880,
8,
277,
14,
1875,
63,
88,
7655,
8,
277,
14,
3756,
354,
12,
2881,
12,
6163,
901,
1273,
12,
3380,
14,
1872,
430,
398,
340,
822,
8,
1317,
9,
508,
413,
436,
334,
355,
1228,
8,
1317,
59,
16,
467,
3380,
14,
1872,
9,
503,
355,
334,
6074,
8,
1317,
59,
16,
467,
3380,
14,
6460,
9,
436,
822,
8,
1317,
59,
16,
566,
508,
413,
436,
326,
1228,
8,
1317,
59,
16,
1527,
16,
467,
3380,
14,
1872,
15206,
288,
1564,
275,
291,
14,
1875,
63,
88,
7655,
8,
277,
14,
2030,
3756,
354,
12,
2881,
12,
4228,
1564,
59,
16,
1055,
305,
505,
1062,
13770,
932,
29,
1317,
59,
16,
566,
267,
901,
2030,
275,
3380,
14,
698,
63,
2030,
8594,
3380,
14,
12400,
8594,
3260,
627,
1317,
430,
267,
372,
3380,
14,
698,
8594,
18887,
12,
901,
2030,
9,
421,
199,
533,
598,
11330,
792,
8,
792,
304,
272,
408,
272,
437,
1382,
901,
626,
365,
16251,
27,
284,
14,
69,
2020,
1006,
1504,
402,
626,
730,
911,
506,
272,
14834,
1901,
1373,
901,
543,
2399,
2396,
3769,
282,
330,
348,
3496,
769,
14,
221,
2779,
3544,
272,
965,
376,
1423,
14,
221,
710,
1423,
883,
506,
10632,
1808,
314,
1627,
627,
3756,
354,
4856,
272,
598,
11330,
792,
1077,
506,
1202,
367,
1382,
1504,
626,
883,
4781,
1655,
2419,
5403,
14,
272,
982,
627,
2425,
63,
20681,
10,
365,
2549,
12,
642,
901,
911,
23347,
370,
282,
5024,
340,
1454,
1202,
272,
5403,
14,
339,
5679,
447,
10817,
520,
3536,
4520,
2543,
26,
1369,
1380,
652,
365,
4915,
272,
408,
272,
365,
63,
22674,
275,
715,
272,
769,
63,
466,
275,
3380,
14,
20520,
63,
513,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1561,
16729,
1768,
29,
403,
12,
4719,
354,
29,
403,
12,
326,
883,
63,
20681,
29,
797,
304,
267,
5024,
855,
826,
721,
277,
12,
536,
12,
1561,
12,
1768,
12,
715,
12,
4719,
354,
9,
267,
291,
14,
2425,
63,
20681,
275,
883,
63,
20681,
339,
347,
1852,
63,
698,
8,
277,
12,
2943,
12,
2881,
12,
2974,
304,
267,
18887,
275,
3380,
14,
698,
63,
354,
8594,
291,
14,
1302,
9,
267,
769,
932,
275,
291,
14,
513,
63,
466,
342,
267,
367,
901,
1273,
12,
1564,
315,
2974,
26,
288,
623,
275,
3380,
14,
12400,
342,
288,
623,
14,
2880,
8,
277,
14,
1875,
63,
88,
7655,
8,
277,
14,
3756,
354,
12,
2881
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
15882,
14,
1974,
14,
1301,
955,
272,
18294,
2878,
94,
339,
298,
3768,
1504,
2,
787,
20883,
901,
5548,
315,
909,
18714,
626,
911,
272,
506,
2881,
13,
6100,
1183,
14834,
370,
282,
1655,
5704,
29515,
3451,
425,
14,
339,
520,
7307,
26,
1898,
10219,
13,
9261,
701,
314,
10229,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
18382,
492,
3380,
199,
199,
504,
15882,
492,
1050,
2415,
421,
199,
318,
485,
374,
63,
4780,
63,
12400,
8,
932,
304,
272,
408,
549,
340,
314,
1031,
1454,
3509,
1373,
13168,
334,
460,
2656,
3788,
10477,
272,
340,
822,
8,
932,
9,
508,
378,
26,
267,
372,
756,
272,
916,
822,
8,
932,
9,
690,
413,
26,
267,
367,
1007,
932,
315,
1031,
59,
17,
10688,
288,
340,
440,
1228,
8,
954,
932,
12,
3380,
14,
2253,
63,
1188,
304,
355,
372,
756,
272,
340,
1228,
8,
932,
59,
16,
467,
3380,
14,
12400,
304,
267,
372,
715,
272,
372,
756,
421,
199,
533,
5024,
8,
785,
304,
272,
408,
33,
1382,
901,
626,
365,
7078,
16251,
14,
221,
2779,
883,
1172,
376,
1423,
503,
440,
12,
314,
272,
1423,
883,
506,
10632,
1808,
282,
2013,
627,
3756,
354,
4856,
221,
5024,
1077,
506,
1202,
272,
367,
1382,
1504,
626,
9987,
2793,
1133,
4781,
1655,
2419,
5403,
14,
339,
710,
2396,
883,
506,
10632,
1808,
282,
2013,
627,
2030,
3756,
354,
10,
340,
314,
1564,
365,
272,
2951,
282,
2849,
8308,
503,
1318,
1031,
14,
339,
5679,
447,
10817,
520,
5808,
26,
1369,
402,
314,
372,
574,
2126,
520,
4500,
26,
1369,
402,
314,
372,
730,
272,
408,
272,
365,
63,
22674,
275,
756,
272,
365,
63,
22033,
275,
756,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1561,
16729,
1768,
29,
403,
12,
965,
63,
1273,
29,
549,
12,
4719,
354,
29,
403,
12,
326,
2396,
3756,
354,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1247,
275,
1561,
267,
291,
14,
1302,
275,
1768,
267,
291,
14,
1989,
63,
1273,
275,
965,
63,
1273,
267,
291,
14,
3756,
354,
275,
4719,
354,
267,
291,
14,
2030,
3756,
354,
275,
2396,
3756,
354,
339,
347,
1852,
63,
31332,
8,
277,
12,
4719,
354,
12,
2881,
12,
1347,
12,
2116,
6506,
932,
29,
525,
2415,
14,
8939,
63,
28907,
12,
13770,
932,
29,
403,
304,
267,
340,
440,
4719,
354,
26,
288,
372,
13770,
932,
503,
6506,
932,
8,
1375,
12,
1347,
9,
267,
2984,
932,
275,
1050,
2415,
14,
6455,
63,
31332,
8594,
2984,
2261,
29,
2261,
12,
2984,
10306,
29,
797,
12,
3147,
2984,
466,
29,
3756,
354,
12,
295,
856,
839,
29,
1375,
9,
267,
2984,
932,
847,
13770,
932,
503,
6506,
932,
8,
1375,
12,
1347,
9,
267,
372,
2984,
932,
339,
347,
1852,
63,
88,
7655,
8,
277,
12,
4719,
354,
12,
2881,
12,
1347,
12,
673,
6506,
932,
29,
525,
2415,
14,
8939,
63,
28907,
12,
13770,
932,
29,
403,
304,
267,
372,
359,
277,
14,
1875,
63,
31332,
8,
3756,
354,
12,
2881,
12,
1347,
12,
6506,
932,
12,
13770,
932,
1874,
339,
347,
1852,
63,
2373,
8,
277,
12,
901,
1273,
12,
1564,
304,
267,
372,
334,
698,
1273,
12,
1564,
9,
339,
347,
1852,
63,
698,
8,
277,
12,
2943,
12,
2881,
12,
1242,
304,
267,
901,
1273,
12,
1564,
275,
1242,
267,
18887,
275,
3380,
14,
698,
63,
354,
8594,
291,
14,
1302,
9,
267,
340,
901,
1273,
26,
288,
18887,
847,
3380,
14,
1872,
360,
5320,
288,
18887,
14,
2880,
8,
277,
14,
1875,
63,
88,
7655,
8,
277,
14,
3756,
354,
12,
2881,
12,
6163,
901,
1273,
12,
3380,
14,
1872,
430,
398,
340,
822,
8,
1317,
9,
508,
413,
436,
334,
355,
1228,
8,
1317,
59,
16,
467,
3380,
14,
1872,
9,
503,
355,
334,
6074,
8,
1317,
59,
16,
467,
3380,
14,
6460,
9,
436,
822,
8,
1317,
59,
16,
566,
508,
413,
436,
326,
1228,
8,
1317,
59,
16,
1527,
16,
467,
3380,
14,
1872,
15206,
288,
1564,
275,
291,
14,
1875,
63,
88,
7655,
8,
277,
14,
2030,
3756,
354,
12,
2881,
12,
4228,
1564,
59,
16,
1055,
305,
505,
1062,
13770,
932,
29,
1317,
59,
16,
566,
267,
901,
2030,
275,
3380,
14,
698,
63,
2030,
8594,
3380,
14,
12400,
8594,
3260,
627,
1317,
430,
267,
372,
3380,
14,
698,
8594,
18887,
12,
901,
2030,
9,
421,
199,
533,
598,
11330,
792,
8,
792,
304,
272,
408,
272,
437,
1382,
901,
626,
365,
16251,
27,
284,
14,
69,
2020,
1006,
1504,
402,
626,
730,
911,
506,
272,
14834,
1901,
1373,
901,
543,
2399,
2396,
3769,
282,
330,
348,
3496,
769,
14,
221,
2779,
3544,
272,
965,
376,
1423,
14,
221,
710,
1423,
883,
506,
10632,
1808,
314,
1627,
627,
3756,
354,
4856,
272,
598,
11330,
792,
1077,
506,
1202,
367,
1382,
1504,
626,
883,
4781,
1655,
2419,
5403,
14,
272,
982,
627,
2425,
63,
20681,
10,
365,
2549,
12,
642,
901,
911,
23347,
370,
282,
5024,
340,
1454,
1202,
272,
5403,
14,
339,
5679,
447,
10817,
520,
3536,
4520,
2543,
26,
1369,
1380,
652,
365,
4915,
272,
408,
272,
365,
63,
22674,
275,
715,
272,
769,
63,
466,
275,
3380,
14,
20520,
63,
513,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1561,
16729,
1768,
29,
403,
12,
4719,
354,
29,
403,
12,
326,
883,
63,
20681,
29,
797,
304,
267,
5024,
855,
826,
721,
277,
12,
536,
12,
1561,
12,
1768,
12,
715,
12,
4719,
354,
9,
267,
291,
14,
2425,
63,
20681,
275,
883,
63,
20681,
339,
347,
1852,
63,
698,
8,
277,
12,
2943,
12,
2881,
12,
2974,
304,
267,
18887,
275,
3380,
14,
698,
63,
354,
8594,
291,
14,
1302,
9,
267,
769,
932,
275,
291,
14,
513,
63,
466,
342,
267,
367,
901,
1273,
12,
1564,
315,
2974,
26,
288,
623,
275,
3380,
14,
12400,
342,
288,
623,
14,
2880,
8,
277,
14,
1875,
63,
88,
7655,
8,
277,
14,
3756,
354,
12,
2881,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rfleissner/ChEsher
|
py/ui/uiChEsher.py
|
1
|
3772
|
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'uiChEsher.ui'
#
# Created: Sat May 06 23:31:14 2017
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(556, 680)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/resource/resource/icon.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.gridLayout = QtGui.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.labelModule = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(8)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.labelModule.setFont(font)
self.labelModule.setText(_fromUtf8(""))
self.labelModule.setAlignment(QtCore.Qt.AlignCenter)
self.labelModule.setObjectName(_fromUtf8("labelModule"))
self.gridLayout.addWidget(self.labelModule, 0, 0, 1, 1)
self.line = QtGui.QFrame(self.centralwidget)
self.line.setFrameShape(QtGui.QFrame.HLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line.setObjectName(_fromUtf8("line"))
self.gridLayout.addWidget(self.line, 1, 0, 1, 1)
self.stackedWidget = QtGui.QStackedWidget(self.centralwidget)
self.stackedWidget.setObjectName(_fromUtf8("stackedWidget"))
self.gridLayout.addWidget(self.stackedWidget, 2, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 556, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.actionReset = QtGui.QAction(MainWindow)
self.actionReset.setObjectName(_fromUtf8("actionReset"))
self.actionClose = QtGui.QAction(MainWindow)
self.actionClose.setObjectName(_fromUtf8("actionClose"))
self.actionChEsher = QtGui.QAction(MainWindow)
self.actionChEsher.setObjectName(_fromUtf8("actionChEsher"))
self.actionAbout_ChEsher = QtGui.QAction(MainWindow)
self.actionAbout_ChEsher.setObjectName(_fromUtf8("actionAbout_ChEsher"))
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(-1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "ChEsher 1.1", None))
self.actionReset.setText(_translate("MainWindow", "Reset", None))
self.actionClose.setText(_translate("MainWindow", "Close", None))
self.actionChEsher.setText(_translate("MainWindow", "ChEsher ", None))
self.actionAbout_ChEsher.setText(_translate("MainWindow", "About ChEsher", None))
import resource_rc
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
1907,
1049,
37,
609,
281,
14,
1907,
7,
199,
3,
199,
3,
18208,
26,
428,
292,
10162,
24293,
6546,
26,
2192,
26,
1079,
9708,
199,
3,
420,
701,
26,
14084,
20,
14041,
1233,
4306,
841,
14,
845,
14,
19,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
893,
26,
272,
485,
12382,
24,
275,
10565,
14,
49,
1558,
14,
12382,
24,
199,
2590,
4281,
26,
272,
347,
485,
12382,
24,
8,
83,
304,
267,
372,
308,
199,
199,
893,
26,
272,
485,
2991,
275,
5928,
14,
12757,
14,
21865,
24,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
12,
485,
2991,
9,
199,
2590,
4281,
26,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
9,
199,
199,
533,
32471,
63,
16031,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
11298,
4301,
304,
267,
11298,
4301,
14,
10376,
1547,
12382,
24,
480,
16031,
2237,
267,
11298,
4301,
14,
8709,
8,
18683,
12,
1227,
1257,
9,
267,
7016,
275,
5928,
14,
26196,
342,
267,
7016,
14,
525,
16049,
8,
10604,
14,
49,
16049,
1547,
12382,
24,
480,
11254,
1927,
15,
1927,
15,
4677,
14,
12802,
8150,
5928,
14,
26196,
14,
6241,
12,
5928,
14,
26196,
14,
5195,
9,
267,
11298,
4301,
14,
25666,
8954,
8,
4677,
9,
267,
291,
14,
16067,
3440,
275,
5928,
14,
23894,
8,
16031,
9,
267,
291,
14,
16067,
3440,
14,
10376,
1547,
12382,
24,
480,
16067,
3440,
2237,
267,
291,
14,
18308,
275,
5928,
14,
49,
7900,
4798,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
18308,
14,
10376,
1547,
12382,
24,
480,
18308,
2237,
267,
291,
14,
1302,
2377,
275,
5928,
14,
19890,
8,
277,
14,
16067,
3440,
9,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
3428,
2320,
8,
24,
9,
267,
5023,
14,
409,
26395,
8,
549,
9,
267,
5023,
14,
409,
7940,
17999,
8,
797,
9,
267,
5023,
14,
409,
16359,
8,
2194,
9,
267,
291,
14,
1302,
2377,
14,
24432,
8,
4246,
9,
267,
291,
14,
1302,
2377,
14,
8341,
1547,
12382,
24,
31348,
267,
291,
14,
1302,
2377,
14,
409,
16613,
8,
10901,
14,
4238,
14,
9497,
13551,
9,
267,
291,
14,
1302,
2377,
14,
10376,
1547,
12382,
24,
480,
1302,
2377,
2237,
267,
291,
14,
18308,
14,
9475,
8,
277,
14,
1302,
2377,
12,
378,
12,
378,
12,
413,
12,
413,
9,
267,
291,
14,
604,
275,
5928,
14,
49,
3160,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
604,
14,
409,
3160,
7238,
8,
10604,
14,
49,
3160,
14,
40,
3049,
9,
267,
291,
14,
604,
14,
409,
3160,
23574,
8,
10604,
14,
49,
3160,
14,
22546,
917,
9,
267,
291,
14,
604,
14,
10376,
1547,
12382,
24,
480,
604,
2237,
267,
291,
14,
18308,
14,
9475,
8,
277,
14,
604,
12,
413,
12,
378,
12,
413,
12,
413,
9,
267,
291,
14,
27266,
3339,
275,
5928,
14,
49,
4851,
379,
3339,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
27266,
3339,
14,
10376,
1547,
12382,
24,
480,
27266,
3339,
2237,
267,
291,
14,
18308,
14,
9475,
8,
277,
14,
27266,
3339,
12,
499,
12,
378,
12,
413,
12,
413,
9,
267,
11298,
4301,
14,
409,
25290,
3339,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
1205,
1700,
275,
5928,
14,
49,
3694,
5281,
8,
16031,
9,
267,
291,
14,
1205,
1700,
14,
10376,
1547,
12382,
24,
480,
1205,
1700,
2237,
267,
11298,
4301,
14,
409,
3694,
5281,
8,
277,
14,
1205,
1700,
9,
267,
291,
14,
31680,
275,
5928,
14,
49,
5977,
5281,
8,
16031,
9,
267,
291,
14,
31680,
14,
25559,
8,
10901,
14,
30197,
8,
16,
12,
378,
12,
31074,
12,
7829,
430,
267,
291,
14,
31680,
14,
10376,
1547,
12382,
24,
480,
31680,
2237,
267,
11298,
4301,
14,
409,
5977,
5281,
8,
277,
14,
31680,
9,
267,
291,
14,
1287,
9637,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
9637,
14,
10376,
1547,
12382,
24,
480,
1287,
9637,
2237,
267,
291,
14,
1287,
4724,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
4724,
14,
10376,
1547,
12382,
24,
480,
1287,
4724,
2237,
267,
291,
14,
1287,
1049,
37,
609,
281,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
1049,
37,
609,
281,
14,
10376,
1547,
12382,
24,
480,
1287,
1049,
37,
609,
281,
2237,
267,
291,
14,
1287,
18816,
63,
1049,
37,
609,
281,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
18816,
63,
1049,
37,
609,
281,
14,
10376,
1547,
12382,
24,
480,
1287,
18816,
63,
1049,
37,
609,
281,
2237,
398,
291,
14,
264,
5275,
18203,
8,
16031,
9,
267,
291,
14,
27266,
3339,
14,
31549,
2801,
17,
9,
267,
10565,
14,
49,
3396,
1692,
14,
2242,
26492,
11190,
8,
16031,
9,
339,
347,
295,
5275,
18203,
8,
277,
12,
11298,
4301,
304,
267,
11298,
4301,
14,
30601,
1547,
5275,
480,
16031,
401,
298,
1049,
37,
609,
281,
413,
14,
17,
401,
488,
430,
267,
291,
14,
1287,
9637,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
9637,
401,
488,
430,
267,
291,
14,
1287,
4724,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
4724,
401,
488,
430,
267,
291,
14,
1287,
1049,
37,
609,
281,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
1049,
37,
609,
281,
3872,
488,
430,
267,
291,
14,
1287,
18816,
63,
1049,
37,
609,
281,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
18816,
2799,
37,
609,
281,
401,
488,
430,
199,
199,
646,
2073,
63,
1195,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
1907,
1049,
37,
609,
281,
14,
1907,
7,
199,
3,
199,
3,
18208,
26,
428,
292,
10162,
24293,
6546,
26,
2192,
26,
1079,
9708,
199,
3,
420,
701,
26,
14084,
20,
14041,
1233,
4306,
841,
14,
845,
14,
19,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
893,
26,
272,
485,
12382,
24,
275,
10565,
14,
49,
1558,
14,
12382,
24,
199,
2590,
4281,
26,
272,
347,
485,
12382,
24,
8,
83,
304,
267,
372,
308,
199,
199,
893,
26,
272,
485,
2991,
275,
5928,
14,
12757,
14,
21865,
24,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
12,
485,
2991,
9,
199,
2590,
4281,
26,
272,
347,
485,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
9,
199,
199,
533,
32471,
63,
16031,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
11298,
4301,
304,
267,
11298,
4301,
14,
10376,
1547,
12382,
24,
480,
16031,
2237,
267,
11298,
4301,
14,
8709,
8,
18683,
12,
1227,
1257,
9,
267,
7016,
275,
5928,
14,
26196,
342,
267,
7016,
14,
525,
16049,
8,
10604,
14,
49,
16049,
1547,
12382,
24,
480,
11254,
1927,
15,
1927,
15,
4677,
14,
12802,
8150,
5928,
14,
26196,
14,
6241,
12,
5928,
14,
26196,
14,
5195,
9,
267,
11298,
4301,
14,
25666,
8954,
8,
4677,
9,
267,
291,
14,
16067,
3440,
275,
5928,
14,
23894,
8,
16031,
9,
267,
291,
14,
16067,
3440,
14,
10376,
1547,
12382,
24,
480,
16067,
3440,
2237,
267,
291,
14,
18308,
275,
5928,
14,
49,
7900,
4798,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
18308,
14,
10376,
1547,
12382,
24,
480,
18308,
2237,
267,
291,
14,
1302,
2377,
275,
5928,
14,
19890,
8,
277,
14,
16067,
3440,
9,
267,
5023,
275,
5928,
14,
49,
6986,
342,
267,
5023,
14,
409,
3428,
2320,
8,
24,
9,
267,
5023,
14,
409,
26395,
8,
549,
9,
267,
5023,
14,
409,
7940,
17999,
8,
797,
9,
267,
5023,
14,
409,
16359,
8,
2194,
9,
267,
291,
14,
1302,
2377,
14,
24432,
8,
4246,
9,
267,
291,
14,
1302,
2377,
14,
8341,
1547,
12382,
24,
31348,
267,
291,
14,
1302,
2377,
14,
409,
16613,
8,
10901,
14,
4238,
14,
9497,
13551,
9,
267,
291,
14,
1302,
2377,
14,
10376,
1547,
12382,
24,
480,
1302,
2377,
2237,
267,
291,
14,
18308,
14,
9475,
8,
277,
14,
1302,
2377,
12,
378,
12,
378,
12,
413,
12,
413,
9,
267,
291,
14,
604,
275,
5928,
14,
49,
3160,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
604,
14,
409,
3160,
7238,
8,
10604,
14,
49,
3160,
14,
40,
3049,
9,
267,
291,
14,
604,
14,
409,
3160,
23574,
8,
10604,
14,
49,
3160,
14,
22546,
917,
9,
267,
291,
14,
604,
14,
10376,
1547,
12382,
24,
480,
604,
2237,
267,
291,
14,
18308,
14,
9475,
8,
277,
14,
604,
12,
413,
12,
378,
12,
413,
12,
413,
9,
267,
291,
14,
27266,
3339,
275,
5928,
14,
49,
4851,
379,
3339,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
27266,
3339,
14,
10376,
1547,
12382,
24,
480,
27266,
3339,
2237,
267,
291,
14,
18308,
14,
9475,
8,
277,
14,
27266,
3339,
12,
499,
12,
378,
12,
413,
12,
413,
9,
267,
11298,
4301,
14,
409,
25290,
3339,
8,
277,
14,
16067,
3440,
9,
267,
291,
14,
1205,
1700,
275,
5928,
14,
49,
3694,
5281,
8,
16031,
9,
267,
291,
14,
1205,
1700,
14,
10376,
1547,
12382,
24,
480,
1205,
1700,
2237,
267,
11298,
4301,
14,
409,
3694,
5281,
8,
277,
14,
1205,
1700,
9,
267,
291,
14,
31680,
275,
5928,
14,
49,
5977,
5281,
8,
16031,
9,
267,
291,
14,
31680,
14,
25559,
8,
10901,
14,
30197,
8,
16,
12,
378,
12,
31074,
12,
7829,
430,
267,
291,
14,
31680,
14,
10376,
1547,
12382,
24,
480,
31680,
2237,
267,
11298,
4301,
14,
409,
5977,
5281,
8,
277,
14,
31680,
9,
267,
291,
14,
1287,
9637,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
9637,
14,
10376,
1547,
12382,
24,
480,
1287,
9637,
2237,
267,
291,
14,
1287,
4724,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
4724,
14,
10376,
1547,
12382,
24,
480,
1287,
4724,
2237,
267,
291,
14,
1287,
1049,
37,
609,
281,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
1049,
37,
609,
281,
14,
10376,
1547,
12382,
24,
480,
1287,
1049,
37,
609,
281,
2237,
267,
291,
14,
1287,
18816,
63,
1049,
37,
609,
281,
275,
5928,
14,
49,
3310,
8,
16031,
9,
267,
291,
14,
1287,
18816,
63,
1049,
37,
609,
281,
14,
10376,
1547,
12382,
24,
480,
1287,
18816,
63,
1049,
37,
609,
281,
2237,
398,
291,
14,
264,
5275,
18203,
8,
16031,
9,
267,
291,
14,
27266,
3339,
14,
31549,
2801,
17,
9,
267,
10565,
14,
49,
3396,
1692,
14,
2242,
26492,
11190,
8,
16031,
9,
339,
347,
295,
5275,
18203,
8,
277,
12,
11298,
4301,
304,
267,
11298,
4301,
14,
30601,
1547,
5275,
480,
16031,
401,
298,
1049,
37,
609,
281,
413,
14,
17,
401,
488,
430,
267,
291,
14,
1287,
9637,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
9637,
401,
488,
430,
267,
291,
14,
1287,
4724,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
4724,
401,
488,
430,
267,
291,
14,
1287,
1049,
37,
609,
281,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
1049,
37,
609,
281,
3872,
488,
430,
267,
291,
14,
1287,
18816,
63,
1049,
37,
609,
281,
14,
8341,
1547,
5275,
480,
16031,
401,
298,
18816,
2799,
37,
609,
281,
401,
488,
430,
199,
199,
646,
2073,
63,
1195,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vpetersson/ansible-modules-core
|
cloud/openstack/glance_image.py
|
33
|
8780
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2013, Benno Joy <benno@ansible.com>
#
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software 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 software. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
module: glance_image
version_added: "1.2"
short_description: Add/Delete images from glance
description:
- Add or Remove images from the glance repository.
options:
login_username:
description:
- login username to authenticate to keystone
required: true
default: admin
login_password:
description:
- Password of login user
required: true
default: 'yes'
login_tenant_name:
description:
- The tenant name of the login user
required: true
default: 'yes'
auth_url:
description:
- The keystone url for authentication
required: false
default: 'http://127.0.0.1:35357/v2.0/'
region_name:
description:
- Name of the region
required: false
default: None
state:
description:
- Indicate desired state of the resource
choices: ['present', 'absent']
default: present
name:
description:
- Name that has to be given to the image
required: true
default: None
disk_format:
description:
- The format of the disk that is getting uploaded
required: false
default: qcow2
container_format:
description:
- The format of the container
required: false
default: bare
owner:
description:
- The owner of the image
required: false
default: None
min_disk:
description:
- The minimum disk space required to deploy this image
required: false
default: None
min_ram:
description:
- The minimum ram required to deploy this image
required: false
default: None
is_public:
description:
- Whether the image can be accessed publicly
required: false
default: 'yes'
copy_from:
description:
- A url from where the image can be downloaded, mutually exclusive with file parameter
required: false
default: None
timeout:
description:
- The time to wait for the image process to complete in seconds
required: false
default: 180
file:
description:
- The path to the file which has to be uploaded, mutually exclusive with copy_from
required: false
default: None
endpoint_type:
description:
- The name of the glance service's endpoint URL type
choices: [publicURL, internalURL]
required: false
default: publicURL
version_added: "1.7"
requirements: ["glanceclient", "keystoneclient"]
'''
EXAMPLES = '''
# Upload an image from an HTTP URL
- glance_image: login_username=admin
login_password=passme
login_tenant_name=admin
name=cirros
container_format=bare
disk_format=qcow2
state=present
copy_from=http:launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
'''
import time
try:
import glanceclient
from keystoneclient.v2_0 import client as ksclient
except ImportError:
print("failed=True msg='glanceclient and keystone client are required'")
def _get_ksclient(module, kwargs):
try:
client = ksclient.Client(username=kwargs.get('login_username'),
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url'))
except Exception, e:
module.fail_json(msg="Error authenticating to the keystone: %s " % e.message)
return client
def _get_endpoint(module, client, endpoint_type):
try:
endpoint = client.service_catalog.url_for(service_type='image', endpoint_type=endpoint_type)
except Exception, e:
module.fail_json(msg="Error getting endpoint for glance: %s" % e.message)
return endpoint
def _get_glance_client(module, kwargs):
_ksclient = _get_ksclient(module, kwargs)
token = _ksclient.auth_token
endpoint =_get_endpoint(module, _ksclient, kwargs.get('endpoint_type'))
kwargs = {
'token': token,
}
try:
client = glanceclient.Client('1', endpoint, **kwargs)
except Exception, e:
module.fail_json(msg="Error in connecting to glance: %s" % e.message)
return client
def _glance_image_present(module, params, client):
try:
for image in client.images.list():
if image.name == params['name']:
return image.id
return None
except Exception, e:
module.fail_json(msg="Error in fetching image list: %s" % e.message)
def _glance_image_create(module, params, client):
kwargs = {
'name': params.get('name'),
'disk_format': params.get('disk_format'),
'container_format': params.get('container_format'),
'owner': params.get('owner'),
'is_public': params.get('is_public'),
'copy_from': params.get('copy_from'),
}
try:
timeout = float(params.get('timeout'))
expire = time.time() + timeout
image = client.images.create(**kwargs)
if not params['copy_from']:
image.update(data=open(params['file'], 'rb'))
while time.time() < expire:
image = client.images.get(image.id)
if image.status == 'active':
break
time.sleep(5)
except Exception, e:
module.fail_json(msg="Error in creating image: %s" % e.message)
if image.status == 'active':
module.exit_json(changed=True, result=image.status, id=image.id)
else:
module.fail_json(msg=" The module timed out, please check manually " + image.status)
def _glance_delete_image(module, params, client):
try:
for image in client.images.list():
if image.name == params['name']:
client.images.delete(image)
except Exception, e:
module.fail_json(msg="Error in deleting image: %s" % e.message)
module.exit_json(changed=True, result="Deleted")
def main():
argument_spec = openstack_argument_spec()
argument_spec.update(dict(
name = dict(required=True),
disk_format = dict(default='qcow2', choices=['aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso']),
container_format = dict(default='bare', choices=['aki', 'ari', 'bare', 'ovf']),
owner = dict(default=None),
min_disk = dict(default=None),
min_ram = dict(default=None),
is_public = dict(default=True),
copy_from = dict(default= None),
timeout = dict(default=180),
file = dict(default=None),
endpoint_type = dict(default='publicURL', choices=['publicURL', 'internalURL']),
state = dict(default='present', choices=['absent', 'present'])
))
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive = [['file','copy_from']],
)
if module.params['state'] == 'present':
if not module.params['file'] and not module.params['copy_from']:
module.fail_json(msg="Either file or copy_from variable should be set to create the image")
client = _get_glance_client(module, module.params)
id = _glance_image_present(module, module.params, client)
if not id:
_glance_image_create(module, module.params, client)
module.exit_json(changed=False, id=id, result="success")
if module.params['state'] == 'absent':
client = _get_glance_client(module, module.params)
id = _glance_image_present(module, module.params, client)
if not id:
module.exit_json(changed=False, result="Success")
else:
_glance_delete_image(module, module.params, client)
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import *
from ansible.module_utils.openstack import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6171,
12,
26844,
889,
7135,
89,
665,
18486,
889,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
859,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
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,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21785,
63,
1569,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
3612,
63,
1802,
26,
2654,
15,
5392,
5935,
687,
21785,
199,
1802,
26,
2043,
446,
2654,
503,
5852,
5935,
687,
314,
21785,
7611,
14,
199,
1419,
26,
2043,
4676,
63,
2473,
26,
1362,
1369,
26,
267,
446,
4676,
3434,
370,
12895,
370,
19395,
1362,
1415,
26,
2549,
1362,
849,
26,
4628,
2043,
4676,
63,
2060,
26,
1362,
1369,
26,
267,
446,
13635,
402,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
4676,
63,
4647,
63,
354,
26,
1362,
1369,
26,
267,
446,
710,
8261,
536,
402,
314,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
1790,
63,
633,
26,
1362,
1369,
26,
267,
446,
710,
19395,
1166,
367,
6299,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1276,
13155,
15,
86,
18,
14,
16,
4805,
2043,
4897,
63,
354,
26,
1362,
1369,
26,
267,
446,
2812,
402,
314,
4897,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1174,
26,
1362,
1369,
26,
267,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
1362,
3415,
26,
788,
1881,
297,
283,
5575,
418,
1362,
849,
26,
3451,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
626,
965,
370,
506,
1627,
370,
314,
1834,
1362,
1415,
26,
2549,
1362,
849,
26,
488,
2043,
4543,
63,
908,
26,
1362,
1369,
26,
267,
446,
710,
1475,
402,
314,
4543,
626,
365,
10232,
14238,
1362,
1415,
26,
3055,
1362,
849,
26,
1894,
19969,
18,
2043,
3970,
63,
908,
26,
1362,
1369,
26,
267,
446,
710,
1475,
402,
314,
3970,
1362,
1415,
26,
3055,
1362,
849,
26,
18753,
2043,
5771,
26,
1362,
1369,
26,
267,
446,
710,
5771,
402,
314,
1834,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1748,
63,
4032,
26,
1362,
1369,
26,
267,
446,
710,
7481,
4543,
4601,
1415,
370,
12287,
642,
1834,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1748,
63,
5975,
26,
1362,
1369,
26,
267,
446,
710,
7481,
21394,
1415,
370,
12287,
642,
1834,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
365,
63,
3455,
26,
1362,
1369,
26,
267,
446,
7480,
314,
1834,
883,
506,
13810,
7974,
317,
429,
89,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
5066,
7,
2043,
1331,
63,
504,
26,
1362,
1369,
26,
267,
446,
437,
1166,
687,
2382,
314,
1834,
883,
506,
13557,
12,
16108,
13914,
543,
570,
2725,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
2653,
26,
1362,
1369,
26,
267,
446,
710,
900,
370,
3618,
367,
314,
1834,
2112,
370,
4890,
315,
4696,
1362,
1415,
26,
3055,
1362,
849,
26,
13576,
2043,
570,
26,
1362,
1369,
26,
267,
446,
710,
931,
370,
314,
570,
1314,
965,
370,
506,
14238,
12,
16108,
13914,
543,
1331,
63,
504,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
6037,
63,
466,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
21785,
2435,
1159,
6037,
2851,
730,
1362,
3415,
26,
359,
3455,
2632,
12,
5007,
2632,
61,
1362,
1415,
26,
3055,
1362,
849,
26,
4575,
2632,
1362,
1015,
63,
3270,
26,
298,
17,
14,
23,
2,
199,
7538,
26,
2097,
18773,
1258,
401,
298,
19143,
1258,
937,
199,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
19149,
376,
1834,
687,
376,
3101,
2851,
199,
13,
21785,
63,
1569,
26,
4676,
63,
2473,
29,
2113,
355,
4676,
63,
2060,
29,
1529,
278,
355,
4676,
63,
4647,
63,
354,
29,
2113,
355,
536,
29,
559,
82,
4796,
355,
3970,
63,
908,
29,
14890,
355,
4543,
63,
908,
29,
81,
19969,
18,
355,
1174,
29,
1881,
355,
1331,
63,
504,
29,
1014,
26,
9850,
6226,
14,
846,
15,
559,
82,
4796,
15,
13409,
15,
16,
14,
19,
14,
16,
22725,
4249,
15,
559,
82,
4796,
13,
16,
14,
19,
14,
16,
13,
88,
1184,
63,
772,
13,
4032,
14,
4060,
199,
2344,
199,
199,
646,
900,
199,
893,
26,
272,
492,
21785,
1258,
272,
687,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
1022,
551,
864,
199,
2590,
3545,
26,
272,
870,
480,
4892,
29,
549,
1499,
534,
18773,
1258,
436,
19395,
1890,
787,
1415,
9859,
421,
199,
318,
485,
362,
63,
75,
551,
864,
8,
578,
12,
2074,
304,
272,
862,
26,
267,
1890,
275,
1022,
551,
864,
14,
3041,
8,
2473,
29,
958,
14,
362,
360,
2886,
63,
2473,
659,
639,
2505,
29,
958,
14,
362,
360,
2886,
63,
2060,
659,
639,
8261,
63,
354,
29,
958,
14,
362,
360,
2886,
63,
4647,
63,
354,
659,
639,
1790,
63,
633,
29,
958,
14,
362,
360,
1178,
63,
633,
1333,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
547,
28532,
1958,
370,
314,
19395,
26,
450,
83,
298,
450,
325,
14,
1188,
9,
272,
372,
1890,
221,
421,
199,
318,
485,
362,
63,
6520,
8,
578,
12,
1890,
12,
6037,
63,
466,
304
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6171,
12,
26844,
889,
7135,
89,
665,
18486,
889,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
859,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
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,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21785,
63,
1569,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
3612,
63,
1802,
26,
2654,
15,
5392,
5935,
687,
21785,
199,
1802,
26,
2043,
446,
2654,
503,
5852,
5935,
687,
314,
21785,
7611,
14,
199,
1419,
26,
2043,
4676,
63,
2473,
26,
1362,
1369,
26,
267,
446,
4676,
3434,
370,
12895,
370,
19395,
1362,
1415,
26,
2549,
1362,
849,
26,
4628,
2043,
4676,
63,
2060,
26,
1362,
1369,
26,
267,
446,
13635,
402,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
4676,
63,
4647,
63,
354,
26,
1362,
1369,
26,
267,
446,
710,
8261,
536,
402,
314,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
1790,
63,
633,
26,
1362,
1369,
26,
267,
446,
710,
19395,
1166,
367,
6299,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1276,
13155,
15,
86,
18,
14,
16,
4805,
2043,
4897,
63,
354,
26,
1362,
1369,
26,
267,
446,
2812,
402,
314,
4897,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1174,
26,
1362,
1369,
26,
267,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
1362,
3415,
26,
788,
1881,
297,
283,
5575,
418,
1362,
849,
26,
3451,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
626,
965,
370,
506,
1627,
370,
314,
1834,
1362,
1415,
26,
2549,
1362,
849,
26,
488,
2043,
4543,
63,
908,
26,
1362,
1369,
26,
267,
446,
710,
1475,
402,
314,
4543,
626,
365,
10232,
14238,
1362,
1415,
26,
3055,
1362,
849,
26,
1894,
19969,
18,
2043,
3970,
63,
908,
26,
1362,
1369,
26,
267,
446,
710,
1475,
402,
314,
3970,
1362,
1415,
26,
3055,
1362,
849,
26,
18753,
2043,
5771,
26,
1362,
1369,
26,
267,
446,
710,
5771,
402,
314,
1834,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1748,
63,
4032,
26,
1362,
1369,
26,
267,
446,
710,
7481,
4543,
4601,
1415,
370,
12287,
642,
1834,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1748,
63,
5975,
26,
1362,
1369,
26,
267,
446,
710,
7481,
21394,
1415,
370,
12287,
642,
1834,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
365,
63,
3455,
26,
1362,
1369,
26,
267,
446,
7480,
314,
1834,
883,
506,
13810,
7974,
317,
429,
89,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
5066,
7,
2043,
1331,
63,
504,
26,
1362,
1369,
26,
267,
446,
437,
1166,
687,
2382,
314,
1834,
883,
506,
13557,
12,
16108,
13914,
543,
570,
2725,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
2653,
26,
1362,
1369,
26,
267,
446,
710,
900,
370,
3618,
367,
314,
1834,
2112,
370,
4890,
315,
4696,
1362,
1415,
26,
3055,
1362,
849,
26,
13576,
2043,
570,
26,
1362,
1369,
26,
267,
446,
710,
931,
370,
314,
570,
1314,
965,
370,
506,
14238,
12,
16108,
13914,
543,
1331,
63,
504,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
6037,
63,
466,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
21785,
2435,
1159,
6037,
2851,
730,
1362,
3415,
26,
359,
3455,
2632,
12,
5007,
2632,
61,
1362,
1415,
26,
3055,
1362,
849,
26,
4575,
2632,
1362,
1015,
63,
3270,
26,
298,
17,
14,
23,
2,
199,
7538,
26,
2097,
18773,
1258,
401,
298,
19143,
1258,
937,
199,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
19149,
376,
1834,
687,
376,
3101,
2851,
199,
13,
21785,
63,
1569,
26,
4676,
63,
2473,
29,
2113,
355,
4676,
63,
2060,
29,
1529,
278,
355,
4676,
63,
4647,
63,
354,
29,
2113,
355,
536,
29,
559,
82,
4796,
355,
3970,
63,
908,
29,
14890,
355,
4543,
63,
908,
29,
81,
19969,
18,
355,
1174,
29,
1881,
355,
1331,
63,
504,
29,
1014,
26,
9850,
6226,
14,
846,
15,
559,
82,
4796,
15,
13409,
15,
16,
14,
19,
14,
16,
22725,
4249,
15,
559,
82,
4796,
13,
16,
14,
19,
14,
16,
13,
88,
1184,
63,
772,
13,
4032,
14,
4060,
199,
2344,
199,
199,
646,
900,
199,
893,
26,
272,
492,
21785,
1258,
272,
687,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
1022,
551,
864,
199,
2590,
3545,
26,
272,
870,
480,
4892,
29,
549,
1499,
534,
18773,
1258,
436,
19395,
1890,
787,
1415,
9859,
421,
199,
318,
485,
362,
63,
75,
551,
864,
8,
578,
12,
2074,
304,
272,
862,
26,
267,
1890,
275,
1022,
551,
864,
14,
3041,
8,
2473,
29,
958,
14,
362,
360,
2886,
63,
2473,
659,
639,
2505,
29,
958,
14,
362,
360,
2886,
63,
2060,
659,
639,
8261,
63,
354,
29,
958,
14,
362,
360,
2886,
63,
4647,
63,
354,
659,
639,
1790,
63,
633,
29,
958,
14,
362,
360,
1178,
63,
633,
1333,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
547,
28532,
1958,
370,
314,
19395,
26,
450,
83,
298,
450,
325,
14,
1188,
9,
272,
372,
1890,
221,
421,
199,
318,
485,
362,
63,
6520,
8,
578,
12,
1890,
12,
6037,
63,
466,
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,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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
] |
vponomaryov/rally
|
tests/functional/test_cli_info.py
|
1
|
4695
|
# Copyright 2013: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
from tests.functional import utils
class InfoTestCase(unittest.TestCase):
def setUp(self):
super(InfoTestCase, self).setUp()
self.rally = utils.Rally()
def test_find_scenario_group(self):
output = self.rally("info find Dummy")
self.assertIn("(benchmark scenario group)", output)
self.assertIn("Dummy.dummy_exception", output)
self.assertIn("Dummy.dummy_random_fail_in_atomic", output)
def test_find_scenario_group_base_class(self):
# NOTE(msdubov): We shouldn't display info about base scenario classes
# containing no end-user scenarios
self.assertRaises(utils.RallyCliError, self.rally,
("info find CeilometerScenario"))
def test_find_scenario(self):
self.assertIn("(benchmark scenario)", self.rally("info find dummy"))
def test_find_scenario_misspelling_typos(self):
self.assertIn("(benchmark scenario)", self.rally("info find dummi"))
def test_find_sla(self):
expected = "failure_rate (SLA)"
self.assertIn(expected, self.rally("info find failure_rate"))
def test_find_sla_misspelling_typos(self):
expected = "failure_rate (SLA)"
self.assertIn(expected, self.rally("info find failure_rte"))
def test_find_deployment_engine(self):
marker_string = "ExistingCloud (deploy engine)"
self.assertIn(marker_string, self.rally("info find ExistingCloud"))
def test_find_deployment_engine_misspelling_typos(self):
marker_string = "ExistingCloud (deploy engine)"
self.assertIn(marker_string, self.rally("info find ExistinCloud"))
def test_find_server_provider(self):
marker_string = "ExistingServers (server provider)"
self.assertIn(marker_string, self.rally("info find ExistingServers"))
def test_find_server_provider_misspelling_typos(self):
marker_string = "ExistingServers (server provider)"
self.assertIn(marker_string, self.rally("info find ExistingServer"))
def test_find_fails(self):
self.assertRaises(utils.RallyCliError, self.rally,
("info find NonExistingStuff"))
def test_find_misspelling_truncated(self):
marker_string = ("NovaServers.boot_and_list_server "
"(benchmark scenario)")
self.assertIn(marker_string,
self.rally("info find boot_and_list"))
def test_find_misspelling_truncated_many_substitutions(self):
try:
self.rally("info find Nova")
except utils.RallyCliError as e:
self.assertIn("NovaServers", e.output)
self.assertIn("NovaServers.boot_and_delete_server", e.output)
self.assertIn("NovaServers.snapshot_server", e.output)
def test_list(self):
output = self.rally("info list")
self.assertIn("Benchmark scenario groups:", output)
self.assertIn("NovaServers", output)
self.assertIn("SLA checks:", output)
self.assertIn("failure_rate", output)
self.assertIn("Deployment engines:", output)
self.assertIn("ExistingCloud", output)
self.assertIn("Server providers:", output)
self.assertIn("ExistingServers", output)
def test_BenchmarkScenarios(self):
output = self.rally("info BenchmarkScenarios")
self.assertIn("Benchmark scenario groups:", output)
self.assertIn("NovaServers", output)
self.assertNotIn("NovaScenario", output)
def test_SLA(self):
output = self.rally("info SLA")
self.assertIn("SLA checks:", output)
self.assertIn("failure_rate", output)
def test_DeploymentEngines(self):
output = self.rally("info DeploymentEngines")
self.assertIn("Deployment engines:", output)
self.assertIn("ExistingCloud", output)
def test_ServerProviders(self):
output = self.rally("info ServerProviders")
self.assertIn("Server providers:", output)
self.assertIn("ExistingServers", output)
|
apache-2.0
|
[
3,
1898,
6171,
26,
603,
723,
4466,
83,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
646,
2882,
199,
199,
504,
2295,
14,
15481,
492,
3778,
421,
199,
533,
10332,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
2354,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
82,
1183,
275,
3778,
14,
50,
1183,
342,
339,
347,
511,
63,
1623,
63,
13444,
63,
923,
8,
277,
304,
267,
1072,
275,
291,
14,
82,
1183,
480,
815,
2342,
9762,
531,
267,
291,
14,
4080,
18353,
11861,
15728,
1572,
4186,
1072,
9,
267,
291,
14,
4080,
480,
11324,
14,
5869,
63,
1971,
401,
1072,
9,
267,
291,
14,
4080,
480,
11324,
14,
5869,
63,
2355,
63,
1633,
63,
262,
63,
10910,
401,
1072,
9,
339,
347,
511,
63,
1623,
63,
13444,
63,
923,
63,
1095,
63,
533,
8,
277,
304,
267,
327,
6944,
8,
28982,
456,
8822,
304,
2136,
9296,
1133,
2929,
2256,
3595,
1300,
15728,
3992,
267,
327,
4483,
3035,
949,
1284,
13,
751,
28444,
267,
291,
14,
1855,
8,
1208,
14,
50,
1183,
20653,
547,
12,
291,
14,
82,
1183,
12,
2079,
1689,
815,
2342,
445,
69,
25617,
12327,
6936,
2237,
339,
347,
511,
63,
1623,
63,
13444,
8,
277,
304,
267,
291,
14,
4080,
18353,
11861,
15728,
4186,
291,
14,
82,
1183,
480,
815,
2342,
7283,
2237,
339,
347,
511,
63,
1623,
63,
13444,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
291,
14,
4080,
18353,
11861,
15728,
4186,
291,
14,
82,
1183,
480,
815,
2342,
366,
453,
2664,
2237,
339,
347,
511,
63,
1623,
63,
83,
416,
8,
277,
304,
267,
1420,
275,
298,
5328,
63,
1866,
334,
4929,
33,
2924,
267,
291,
14,
4080,
8,
2062,
12,
291,
14,
82,
1183,
480,
815,
2342,
5988,
63,
1866,
2237,
339,
347,
511,
63,
1623,
63,
83,
416,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
1420,
275,
298,
5328,
63,
1866,
334,
4929,
33,
2924,
267,
291,
14,
4080,
8,
2062,
12,
291,
14,
82,
1183,
480,
815,
2342,
5988,
63,
82,
266,
2237,
339,
347,
511,
63,
1623,
63,
13605,
63,
3908,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
9089,
334,
11060,
6869,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
26958,
9089,
2237,
339,
347,
511,
63,
1623,
63,
13605,
63,
3908,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
9089,
334,
11060,
6869,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
631,
262,
9089,
2237,
339,
347,
511,
63,
1623,
63,
1000,
63,
3780,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
23637,
334,
1000,
5022,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
26958,
23637,
2237,
339,
347,
511,
63,
1623,
63,
1000,
63,
3780,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
23637,
334,
1000,
5022,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
26958,
3120,
2237,
339,
347,
511,
63,
1623,
63,
15762,
8,
277,
304,
267,
291,
14,
1855,
8,
1208,
14,
50,
1183,
20653,
547,
12,
291,
14,
82,
1183,
12,
2079,
1689,
815,
2342,
10172,
23490,
933,
3043,
2237,
339,
347,
511,
63,
1623,
63,
1292,
12325,
10564,
63,
19347,
8,
277,
304,
267,
3608,
63,
875,
275,
1689,
19884,
23637,
14,
4930,
63,
460,
63,
513,
63,
1000,
298,
586,
7340,
11861,
15728,
6320,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
1993,
291,
14,
82,
1183,
480,
815,
2342,
8498,
63,
460,
63,
513,
2237,
339,
347,
511,
63,
1623,
63,
1292,
12325,
10564,
63,
19347,
63,
3479,
63,
14340,
8653,
8,
277,
304,
267,
862,
26,
288,
291,
14,
82,
1183,
480,
815,
2342,
28184,
531,
267,
871,
3778,
14,
50,
1183,
20653,
547,
465,
325,
26,
288,
291,
14,
4080,
480,
19884,
23637,
401,
325,
14,
1199,
9,
288,
291,
14,
4080,
480,
19884,
23637,
14,
4930,
63,
460,
63,
1807,
63,
1000,
401,
325,
14,
1199,
9,
288,
291,
14,
4080,
480,
19884,
23637,
14,
4753,
63,
1000,
401,
325,
14,
1199,
9,
339,
347,
511,
63,
513,
8,
277,
304,
267,
1072,
275,
291,
14,
82,
1183,
480,
815,
769,
531,
267,
291,
14,
4080,
480,
18644,
15728,
4652,
6783,
1072,
9,
267,
291,
14,
4080,
480,
19884,
23637,
401,
1072,
9,
267,
291,
14,
4080,
480,
4929,
33,
5920,
6783,
1072,
9,
267,
291,
14,
4080,
480,
5328,
63,
1866,
401,
1072,
9,
267,
291,
14,
4080,
480,
25434,
28156,
6783,
1072,
9,
267,
291,
14,
4080,
480,
23490,
9089,
401,
1072,
9,
267,
291,
14,
4080,
480,
3120,
18032,
6783,
1072,
9,
267,
291,
14,
4080,
480,
23490,
23637,
401,
1072,
9,
339,
347,
511,
63,
18644,
12327,
17832,
8,
277,
304,
267,
1072,
275,
291,
14,
82,
1183,
480,
815,
27067,
12327,
17832,
531,
267,
291,
14,
4080,
480,
18644,
15728,
4652,
6783,
1072,
9,
267,
291,
14,
4080,
480,
19884,
23637,
401,
1072,
9,
267,
291,
14,
8795,
480,
19884,
12327,
6936,
401,
1072
] |
[
1898,
6171,
26,
603,
723,
4466,
83,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
646,
2882,
199,
199,
504,
2295,
14,
15481,
492,
3778,
421,
199,
533,
10332,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
2354,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
82,
1183,
275,
3778,
14,
50,
1183,
342,
339,
347,
511,
63,
1623,
63,
13444,
63,
923,
8,
277,
304,
267,
1072,
275,
291,
14,
82,
1183,
480,
815,
2342,
9762,
531,
267,
291,
14,
4080,
18353,
11861,
15728,
1572,
4186,
1072,
9,
267,
291,
14,
4080,
480,
11324,
14,
5869,
63,
1971,
401,
1072,
9,
267,
291,
14,
4080,
480,
11324,
14,
5869,
63,
2355,
63,
1633,
63,
262,
63,
10910,
401,
1072,
9,
339,
347,
511,
63,
1623,
63,
13444,
63,
923,
63,
1095,
63,
533,
8,
277,
304,
267,
327,
6944,
8,
28982,
456,
8822,
304,
2136,
9296,
1133,
2929,
2256,
3595,
1300,
15728,
3992,
267,
327,
4483,
3035,
949,
1284,
13,
751,
28444,
267,
291,
14,
1855,
8,
1208,
14,
50,
1183,
20653,
547,
12,
291,
14,
82,
1183,
12,
2079,
1689,
815,
2342,
445,
69,
25617,
12327,
6936,
2237,
339,
347,
511,
63,
1623,
63,
13444,
8,
277,
304,
267,
291,
14,
4080,
18353,
11861,
15728,
4186,
291,
14,
82,
1183,
480,
815,
2342,
7283,
2237,
339,
347,
511,
63,
1623,
63,
13444,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
291,
14,
4080,
18353,
11861,
15728,
4186,
291,
14,
82,
1183,
480,
815,
2342,
366,
453,
2664,
2237,
339,
347,
511,
63,
1623,
63,
83,
416,
8,
277,
304,
267,
1420,
275,
298,
5328,
63,
1866,
334,
4929,
33,
2924,
267,
291,
14,
4080,
8,
2062,
12,
291,
14,
82,
1183,
480,
815,
2342,
5988,
63,
1866,
2237,
339,
347,
511,
63,
1623,
63,
83,
416,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
1420,
275,
298,
5328,
63,
1866,
334,
4929,
33,
2924,
267,
291,
14,
4080,
8,
2062,
12,
291,
14,
82,
1183,
480,
815,
2342,
5988,
63,
82,
266,
2237,
339,
347,
511,
63,
1623,
63,
13605,
63,
3908,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
9089,
334,
11060,
6869,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
26958,
9089,
2237,
339,
347,
511,
63,
1623,
63,
13605,
63,
3908,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
9089,
334,
11060,
6869,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
631,
262,
9089,
2237,
339,
347,
511,
63,
1623,
63,
1000,
63,
3780,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
23637,
334,
1000,
5022,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
26958,
23637,
2237,
339,
347,
511,
63,
1623,
63,
1000,
63,
3780,
63,
1292,
12325,
10564,
63,
369,
1712,
8,
277,
304,
267,
3608,
63,
875,
275,
298,
23490,
23637,
334,
1000,
5022,
2924,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
291,
14,
82,
1183,
480,
815,
2342,
1316,
26958,
3120,
2237,
339,
347,
511,
63,
1623,
63,
15762,
8,
277,
304,
267,
291,
14,
1855,
8,
1208,
14,
50,
1183,
20653,
547,
12,
291,
14,
82,
1183,
12,
2079,
1689,
815,
2342,
10172,
23490,
933,
3043,
2237,
339,
347,
511,
63,
1623,
63,
1292,
12325,
10564,
63,
19347,
8,
277,
304,
267,
3608,
63,
875,
275,
1689,
19884,
23637,
14,
4930,
63,
460,
63,
513,
63,
1000,
298,
586,
7340,
11861,
15728,
6320,
267,
291,
14,
4080,
8,
4211,
63,
875,
12,
1993,
291,
14,
82,
1183,
480,
815,
2342,
8498,
63,
460,
63,
513,
2237,
339,
347,
511,
63,
1623,
63,
1292,
12325,
10564,
63,
19347,
63,
3479,
63,
14340,
8653,
8,
277,
304,
267,
862,
26,
288,
291,
14,
82,
1183,
480,
815,
2342,
28184,
531,
267,
871,
3778,
14,
50,
1183,
20653,
547,
465,
325,
26,
288,
291,
14,
4080,
480,
19884,
23637,
401,
325,
14,
1199,
9,
288,
291,
14,
4080,
480,
19884,
23637,
14,
4930,
63,
460,
63,
1807,
63,
1000,
401,
325,
14,
1199,
9,
288,
291,
14,
4080,
480,
19884,
23637,
14,
4753,
63,
1000,
401,
325,
14,
1199,
9,
339,
347,
511,
63,
513,
8,
277,
304,
267,
1072,
275,
291,
14,
82,
1183,
480,
815,
769,
531,
267,
291,
14,
4080,
480,
18644,
15728,
4652,
6783,
1072,
9,
267,
291,
14,
4080,
480,
19884,
23637,
401,
1072,
9,
267,
291,
14,
4080,
480,
4929,
33,
5920,
6783,
1072,
9,
267,
291,
14,
4080,
480,
5328,
63,
1866,
401,
1072,
9,
267,
291,
14,
4080,
480,
25434,
28156,
6783,
1072,
9,
267,
291,
14,
4080,
480,
23490,
9089,
401,
1072,
9,
267,
291,
14,
4080,
480,
3120,
18032,
6783,
1072,
9,
267,
291,
14,
4080,
480,
23490,
23637,
401,
1072,
9,
339,
347,
511,
63,
18644,
12327,
17832,
8,
277,
304,
267,
1072,
275,
291,
14,
82,
1183,
480,
815,
27067,
12327,
17832,
531,
267,
291,
14,
4080,
480,
18644,
15728,
4652,
6783,
1072,
9,
267,
291,
14,
4080,
480,
19884,
23637,
401,
1072,
9,
267,
291,
14,
8795,
480,
19884,
12327,
6936,
401,
1072,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Bulochkin/tensorflow_pack
|
tensorflow/contrib/keras/python/keras/layers/noise.py
|
39
|
3671
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Layers for regularization models via the addition of noise.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.contrib.keras.python.keras import backend as K
from tensorflow.contrib.keras.python.keras.engine import Layer
class GaussianNoise(Layer):
"""Apply additive zero-centered Gaussian noise.
This is useful to mitigate overfitting
(you could see it as a form of random data augmentation).
Gaussian Noise (GS) is a natural choice as corruption process
for real valued inputs.
As it is a regularization layer, it is only active at training time.
Arguments:
stddev: float, standard deviation of the noise distribution.
Input shape:
Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
Output shape:
Same shape as input.
"""
def __init__(self, stddev, **kwargs):
super(GaussianNoise, self).__init__(**kwargs)
self.supports_masking = True
self.stddev = stddev
def call(self, inputs, training=None):
def noised():
return inputs + K.random_normal(
shape=K.shape(inputs), mean=0., stddev=self.stddev)
return K.in_train_phase(noised, inputs, training=training)
def get_config(self):
config = {'stddev': self.stddev}
base_config = super(GaussianNoise, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
class GaussianDropout(Layer):
"""Apply multiplicative 1-centered Gaussian noise.
As it is a regularization layer, it is only active at training time.
Arguments:
rate: float, drop probability (as with `Dropout`).
The multiplicative noise will have
standard deviation `sqrt(rate / (1 - rate))`.
Input shape:
Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
Output shape:
Same shape as input.
References:
- [Dropout: A Simple Way to Prevent Neural Networks from Overfitting
Srivastava, Hinton, et al.
2014](http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf)
"""
def __init__(self, rate, **kwargs):
super(GaussianDropout, self).__init__(**kwargs)
self.supports_masking = True
self.rate = rate
def call(self, inputs, training=None):
if 0 < self.rate < 1:
def noised():
stddev = np.sqrt(self.rate / (1.0 - self.rate))
return inputs * K.random_normal(
shape=K.shape(inputs), mean=1.0, stddev=stddev)
return K.in_train_phase(noised, inputs, training=training)
return inputs
def get_config(self):
config = {'rate': self.rate}
base_config = super(GaussianDropout, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
16862,
367,
21095,
1709,
4799,
314,
10234,
402,
11145,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
492,
4865,
465,
1804,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
3908,
492,
11915,
421,
199,
533,
17131,
21446,
8,
5003,
304,
523,
408,
16581,
1503,
30844,
4697,
13,
20080,
17131,
11145,
14,
819,
961,
365,
2997,
370,
333,
5277,
3237,
1806,
3269,
1337,
523,
334,
13297,
4293,
1937,
652,
465,
282,
1824,
402,
2196,
666,
18336,
3117,
680,
523,
17131,
3091,
572,
334,
8021,
9,
365,
282,
19981,
7141,
465,
1970,
5505,
296,
2112,
523,
367,
3363,
574,
68,
4153,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
489,
28052,
26,
2069,
12,
4465,
18458,
402,
314,
11145,
4084,
14,
819,
6924,
2215,
26,
489,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
489,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
489,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
489,
14766,
2215,
465,
1324,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
28052,
12,
1011,
958,
304,
272,
1613,
8,
26756,
21446,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
21672,
275,
28052,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
339,
347,
949,
9096,
837,
489,
372,
4153,
435,
1804,
14,
2355,
63,
3302,
8,
881,
2215,
29,
43,
14,
1392,
8,
3711,
395,
4615,
29,
16,
2020,
28052,
29,
277,
14,
21672,
9,
339,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
21672,
356,
291,
14,
21672,
93,
272,
1300,
63,
888,
275,
1613,
8,
26756,
21446,
12,
291,
680,
362,
63,
888,
342,
272,
372,
1211,
8,
513,
8,
1095,
63,
888,
14,
1744,
1012,
435,
769,
8,
888,
14,
1744,
4059,
421,
199,
533,
17131,
30662,
8,
5003,
304,
523,
408,
16581,
8897,
606,
1905,
413,
13,
20080,
17131,
11145,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
489,
6634,
26,
2069,
12,
5978,
12224,
334,
305,
543,
658,
30662,
14963,
881,
710,
8897,
606,
1905,
11145,
911,
1172,
881,
4465,
18458,
658,
5079,
8,
1866,
1182,
334,
17,
446,
6634,
430,
2313,
819,
6924,
2215,
26,
489,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
489,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
489,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
489,
14766,
2215,
465,
1324,
14,
819,
14504,
26,
489,
446,
359,
30662,
26,
437,
5870,
644,
1187,
370,
29861,
5612,
4889,
17138,
687,
7259,
3269,
1337,
267,
428,
322,
3042,
1207,
3042,
12,
869,
442,
265,
12,
10844,
741,
14,
267,
6927,
8738,
1014,
921,
1544,
14,
1259,
14,
8270,
26296,
14,
8654,
22500,
2393,
279,
1151,
10616,
15,
10443,
83,
15,
83,
322,
3042,
1207,
3042,
1079,
65,
14,
5607,
9,
523,
408,
819,
347,
636,
826,
721,
277,
12,
6634,
12,
1011,
958,
304,
272,
1613,
8,
26756,
30662,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
1866,
275,
6634,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
272,
340,
378,
665,
291,
14,
1866,
665,
413,
26,
2541,
347,
949,
9096,
837,
267,
28052,
275,
980,
14,
5079,
8,
277,
14,
1866,
1182,
334,
17,
14,
16,
446,
291,
14,
1866,
430,
267,
372,
4153,
627,
1804,
14,
2355,
63,
3302,
8,
288,
2215,
29,
43,
14,
1392,
8,
3711,
395,
4615,
29,
17,
14,
16,
12,
28052,
29,
21672,
9,
2541,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
272,
372,
4153,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
1866,
356,
291,
14,
1866,
93,
272,
1300,
63,
888,
275,
1613,
8,
26756,
30662,
12,
291,
680,
362,
63,
888,
342,
272,
372,
1211,
8,
513,
8,
1095,
63,
888,
14,
1744,
1012,
435,
769,
8,
888,
14,
1744,
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
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
16862,
367,
21095,
1709,
4799,
314,
10234,
402,
11145,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
492,
4865,
465,
1804,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
3908,
492,
11915,
421,
199,
533,
17131,
21446,
8,
5003,
304,
523,
408,
16581,
1503,
30844,
4697,
13,
20080,
17131,
11145,
14,
819,
961,
365,
2997,
370,
333,
5277,
3237,
1806,
3269,
1337,
523,
334,
13297,
4293,
1937,
652,
465,
282,
1824,
402,
2196,
666,
18336,
3117,
680,
523,
17131,
3091,
572,
334,
8021,
9,
365,
282,
19981,
7141,
465,
1970,
5505,
296,
2112,
523,
367,
3363,
574,
68,
4153,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
489,
28052,
26,
2069,
12,
4465,
18458,
402,
314,
11145,
4084,
14,
819,
6924,
2215,
26,
489,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
489,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
489,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
489,
14766,
2215,
465,
1324,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
28052,
12,
1011,
958,
304,
272,
1613,
8,
26756,
21446,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
21672,
275,
28052,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
339,
347,
949,
9096,
837,
489,
372,
4153,
435,
1804,
14,
2355,
63,
3302,
8,
881,
2215,
29,
43,
14,
1392,
8,
3711,
395,
4615,
29,
16,
2020,
28052,
29,
277,
14,
21672,
9,
339,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
21672,
356,
291,
14,
21672,
93,
272,
1300,
63,
888,
275,
1613,
8,
26756,
21446,
12,
291,
680,
362,
63,
888,
342,
272,
372,
1211,
8,
513,
8,
1095,
63,
888,
14,
1744,
1012,
435,
769,
8,
888,
14,
1744,
4059,
421,
199,
533,
17131,
30662,
8,
5003,
304,
523,
408,
16581,
8897,
606,
1905,
413,
13,
20080,
17131,
11145,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
489,
6634,
26,
2069,
12,
5978,
12224,
334,
305,
543,
658,
30662,
14963,
881,
710,
8897,
606,
1905,
11145,
911,
1172,
881,
4465,
18458,
658,
5079,
8,
1866,
1182,
334,
17,
446,
6634,
430,
2313,
819,
6924,
2215,
26,
489,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
489,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
489,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
489,
14766,
2215,
465,
1324,
14,
819,
14504,
26,
489,
446,
359,
30662,
26,
437,
5870,
644,
1187,
370,
29861,
5612,
4889,
17138,
687,
7259,
3269,
1337,
267,
428,
322,
3042,
1207,
3042,
12,
869,
442,
265,
12,
10844,
741,
14,
267,
6927,
8738,
1014,
921,
1544,
14,
1259,
14,
8270,
26296,
14,
8654,
22500,
2393,
279,
1151,
10616,
15,
10443,
83,
15,
83,
322,
3042,
1207,
3042,
1079,
65,
14,
5607,
9,
523,
408,
819,
347,
636,
826,
721,
277,
12,
6634,
12,
1011,
958,
304,
272,
1613,
8,
26756,
30662,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
1866,
275,
6634,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
272,
340,
378,
665,
291,
14,
1866,
665,
413,
26,
2541,
347,
949,
9096,
837,
267,
28052,
275,
980,
14,
5079,
8,
277,
14,
1866,
1182,
334,
17,
14,
16,
446,
291,
14,
1866,
430,
267,
372,
4153,
627,
1804,
14,
2355,
63,
3302,
8,
288,
2215,
29,
43,
14,
1392,
8,
3711,
395,
4615,
29,
17,
14,
16,
12,
28052,
29,
21672,
9,
2541,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
272,
372,
4153,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
1866,
356,
291,
14,
1866,
93,
272,
1300,
63,
888,
275,
1613,
8,
26756,
30662,
12,
291,
680,
362,
63,
888,
342,
272,
372,
1211,
8,
513,
8,
1095,
63,
888,
14,
1744,
1012,
435,
769,
8,
888,
14,
1744,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MiLk/ansible-modules-core
|
system/seboolean.py
|
90
|
6637
|
#!/usr/bin/python
# (c) 2012, Stephen Fromm <sfromm@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
module: seboolean
short_description: Toggles SELinux booleans.
description:
- Toggles SELinux booleans.
version_added: "0.7"
options:
name:
description:
- Name of the boolean to configure
required: true
default: null
persistent:
description:
- Set to C(yes) if the boolean setting should survive a reboot
required: false
default: no
choices: [ "yes", "no" ]
state:
description:
- Desired boolean value
required: true
default: null
choices: [ 'yes', 'no' ]
notes:
- Not tested on any debian based system
requirements: [ ]
author: Stephen Fromm
'''
EXAMPLES = '''
# Set (httpd_can_network_connect) flag on and keep it persistent across reboots
- seboolean: name=httpd_can_network_connect state=yes persistent=yes
'''
try:
import selinux
HAVE_SELINUX=True
except ImportError:
HAVE_SELINUX=False
try:
import semanage
HAVE_SEMANAGE=True
except ImportError:
HAVE_SEMANAGE=False
def has_boolean_value(module, name):
bools = []
try:
rc, bools = selinux.security_get_boolean_names()
except OSError, e:
module.fail_json(msg="Failed to get list of boolean names")
if name in bools:
return True
else:
return False
def get_boolean_value(module, name):
state = 0
try:
state = selinux.security_get_boolean_active(name)
except OSError, e:
module.fail_json(msg="Failed to determine current state for boolean %s" % name)
if state == 1:
return True
else:
return False
# The following method implements what setsebool.c does to change
# a boolean and make it persist after reboot..
def semanage_boolean_value(module, name, state):
rc = 0
value = 0
if state:
value = 1
handle = semanage.semanage_handle_create()
if handle is None:
module.fail_json(msg="Failed to create semanage library handle")
try:
managed = semanage.semanage_is_managed(handle)
if managed < 0:
module.fail_json(msg="Failed to determine whether policy is manage")
if managed == 0:
if os.getuid() == 0:
module.fail_json(msg="Cannot set persistent booleans without managed policy")
else:
module.fail_json(msg="Cannot set persistent booleans; please try as root")
if semanage.semanage_connect(handle) < 0:
module.fail_json(msg="Failed to connect to semanage")
if semanage.semanage_begin_transaction(handle) < 0:
module.fail_json(msg="Failed to begin semanage transaction")
rc, sebool = semanage.semanage_bool_create(handle)
if rc < 0:
module.fail_json(msg="Failed to create seboolean with semanage")
if semanage.semanage_bool_set_name(handle, sebool, name) < 0:
module.fail_json(msg="Failed to set seboolean name with semanage")
semanage.semanage_bool_set_value(sebool, value)
rc, boolkey = semanage.semanage_bool_key_extract(handle, sebool)
if rc < 0:
module.fail_json(msg="Failed to extract boolean key with semanage")
if semanage.semanage_bool_modify_local(handle, boolkey, sebool) < 0:
module.fail_json(msg="Failed to modify boolean key with semanage")
if semanage.semanage_bool_set_active(handle, boolkey, sebool) < 0:
module.fail_json(msg="Failed to set boolean key active with semanage")
semanage.semanage_bool_key_free(boolkey)
semanage.semanage_bool_free(sebool)
semanage.semanage_set_reload(handle, 0)
if semanage.semanage_commit(handle) < 0:
module.fail_json(msg="Failed to commit changes to semanage")
semanage.semanage_disconnect(handle)
semanage.semanage_handle_destroy(handle)
except Exception, e:
module.fail_json(msg="Failed to manage policy for boolean %s: %s" % (name, str(e)))
return True
def set_boolean_value(module, name, state):
rc = 0
value = 0
if state:
value = 1
try:
rc = selinux.security_set_boolean(name, value)
except OSError, e:
module.fail_json(msg="Failed to set boolean %s to %s" % (name, value))
if rc == 0:
return True
else:
return False
def main():
module = AnsibleModule(
argument_spec = dict(
name=dict(required=True),
persistent=dict(default='no', type='bool'),
state=dict(required=True, type='bool')
),
supports_check_mode=True
)
if not HAVE_SELINUX:
module.fail_json(msg="This module requires libselinux-python support")
if not HAVE_SEMANAGE:
module.fail_json(msg="This module requires libsemanage-python support")
if not selinux.is_selinux_enabled():
module.fail_json(msg="SELinux is disabled on this host.")
name = module.params['name']
persistent = module.params['persistent']
state = module.params['state']
result = {}
result['name'] = name
if not has_boolean_value(module, name):
module.fail_json(msg="SELinux boolean %s does not exist." % name)
cur_value = get_boolean_value(module, name)
if cur_value == state:
result['state'] = cur_value
result['changed'] = False
module.exit_json(**result)
if module.check_mode:
module.exit_json(changed=True)
if persistent:
r = semanage_boolean_value(module, name, state)
else:
r = set_boolean_value(module, name, state)
result['changed'] = r
if not r:
module.fail_json(msg="Failed to set boolean %s to %s" % (name, value))
try:
selinux.security_commit_booleans()
except:
module.fail_json(msg="Failed to commit pending boolean %s value" % name)
module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
6029,
12,
17854,
17579,
11606,
77,
665,
83,
504,
77,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
542,
4871,
199,
3612,
63,
1802,
26,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1802,
26,
1362,
446,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1023,
63,
3270,
26,
298,
16,
14,
23,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5046,
370,
7908,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
16149,
26,
272,
1369,
26,
489,
446,
2494,
370,
445,
8,
5066,
9,
340,
314,
5046,
4260,
1077,
6296,
433,
432,
282,
19457,
272,
1415,
26,
3055,
272,
849,
26,
949,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
5046,
574,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
7,
1622,
199,
5983,
26,
2043,
446,
2832,
12470,
641,
1263,
477,
9662,
4079,
2656,
199,
7538,
26,
359,
1622,
199,
2502,
26,
17854,
17579,
11606,
77,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2494,
334,
21594,
63,
2425,
63,
1200,
63,
2242,
9,
3305,
641,
436,
4215,
652,
16149,
9371,
19457,
83,
199,
13,
542,
4871,
26,
536,
29,
21594,
63,
2425,
63,
1200,
63,
2242,
1174,
29,
5066,
16149,
29,
5066,
199,
2344,
199,
199,
893,
26,
272,
492,
542,
5135,
272,
25227,
63,
899,
26030,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
26030,
29,
797,
199,
199,
893,
26,
272,
492,
542,
9053,
272,
25227,
63,
899,
6588,
2962,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
6588,
2962,
29,
797,
199,
199,
318,
965,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1234,
1446,
275,
942,
272,
862,
26,
267,
4819,
12,
1234,
1446,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
1247,
342,
272,
871,
6440,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
664,
769,
402,
5046,
1561,
531,
272,
340,
536,
315,
1234,
1446,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
318,
664,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1174,
275,
378,
272,
862,
26,
267,
1174,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
2682,
8,
354,
9,
272,
871,
6440,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
1453,
1174,
367,
5046,
450,
83,
2,
450,
536,
9,
272,
340,
1174,
508,
413,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
3,
710,
2569,
1083,
9031,
4052,
663,
261,
2245,
14,
67,
1630,
370,
1570,
199,
3,
282,
5046,
436,
1852,
652,
22400,
2410,
19457,
703,
199,
318,
542,
9053,
63,
4871,
63,
585,
8,
578,
12,
536,
12,
1174,
304,
272,
4819,
275,
378,
272,
574,
275,
378,
272,
340,
1174,
26,
267,
574,
275,
413,
272,
2429,
275,
542,
9053,
14,
261,
9053,
63,
2479,
63,
981,
342,
272,
340,
2429,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
9053,
3555,
2429,
531,
272,
862,
26,
267,
12883,
275,
542,
9053,
14,
261,
9053,
63,
374,
63,
11122,
8,
2479,
9,
267,
340,
12883,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
3775,
4592,
365,
9635,
531,
267,
340,
12883,
508,
378,
26,
288,
340,
747,
14,
362,
1535,
342,
508,
378,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
1928,
12883,
4592,
531,
288,
587,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
27,
8749,
862,
465,
1738,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2242,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
4907,
370,
542,
9053,
531,
398,
340,
542,
9053,
14,
261,
9053,
63,
5037,
63,
5945,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
5386,
542,
9053,
6008,
531,
398,
4819,
12,
542,
2245,
275,
542,
9053,
14,
261,
9053,
63,
2245,
63,
981,
8,
2479,
9,
267,
340,
4819,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
4871,
543,
542,
9053,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
354,
8,
2479,
12,
542,
2245,
12,
536,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
663,
542,
4871,
536,
543,
542,
9053,
531,
267,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
585,
8,
261,
2245,
12,
574,
9,
398,
4819,
12,
2155,
498,
275,
542,
9053,
14,
261,
9053,
63,
2245,
63,
498,
63,
5005,
8,
2479,
12,
542,
2245,
9,
267,
340,
4819,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
5536,
5046
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
6029,
12,
17854,
17579,
11606,
77,
665,
83,
504,
77,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
542,
4871,
199,
3612,
63,
1802,
26,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1802,
26,
1362,
446,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1023,
63,
3270,
26,
298,
16,
14,
23,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5046,
370,
7908,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
16149,
26,
272,
1369,
26,
489,
446,
2494,
370,
445,
8,
5066,
9,
340,
314,
5046,
4260,
1077,
6296,
433,
432,
282,
19457,
272,
1415,
26,
3055,
272,
849,
26,
949,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
5046,
574,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
7,
1622,
199,
5983,
26,
2043,
446,
2832,
12470,
641,
1263,
477,
9662,
4079,
2656,
199,
7538,
26,
359,
1622,
199,
2502,
26,
17854,
17579,
11606,
77,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2494,
334,
21594,
63,
2425,
63,
1200,
63,
2242,
9,
3305,
641,
436,
4215,
652,
16149,
9371,
19457,
83,
199,
13,
542,
4871,
26,
536,
29,
21594,
63,
2425,
63,
1200,
63,
2242,
1174,
29,
5066,
16149,
29,
5066,
199,
2344,
199,
199,
893,
26,
272,
492,
542,
5135,
272,
25227,
63,
899,
26030,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
26030,
29,
797,
199,
199,
893,
26,
272,
492,
542,
9053,
272,
25227,
63,
899,
6588,
2962,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
6588,
2962,
29,
797,
199,
199,
318,
965,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1234,
1446,
275,
942,
272,
862,
26,
267,
4819,
12,
1234,
1446,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
1247,
342,
272,
871,
6440,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
664,
769,
402,
5046,
1561,
531,
272,
340,
536,
315,
1234,
1446,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
318,
664,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1174,
275,
378,
272,
862,
26,
267,
1174,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
2682,
8,
354,
9,
272,
871,
6440,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
1453,
1174,
367,
5046,
450,
83,
2,
450,
536,
9,
272,
340,
1174,
508,
413,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
3,
710,
2569,
1083,
9031,
4052,
663,
261,
2245,
14,
67,
1630,
370,
1570,
199,
3,
282,
5046,
436,
1852,
652,
22400,
2410,
19457,
703,
199,
318,
542,
9053,
63,
4871,
63,
585,
8,
578,
12,
536,
12,
1174,
304,
272,
4819,
275,
378,
272,
574,
275,
378,
272,
340,
1174,
26,
267,
574,
275,
413,
272,
2429,
275,
542,
9053,
14,
261,
9053,
63,
2479,
63,
981,
342,
272,
340,
2429,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
9053,
3555,
2429,
531,
272,
862,
26,
267,
12883,
275,
542,
9053,
14,
261,
9053,
63,
374,
63,
11122,
8,
2479,
9,
267,
340,
12883,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
3775,
4592,
365,
9635,
531,
267,
340,
12883,
508,
378,
26,
288,
340,
747,
14,
362,
1535,
342,
508,
378,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
1928,
12883,
4592,
531,
288,
587,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
27,
8749,
862,
465,
1738,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2242,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
4907,
370,
542,
9053,
531,
398,
340,
542,
9053,
14,
261,
9053,
63,
5037,
63,
5945,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
5386,
542,
9053,
6008,
531,
398,
4819,
12,
542,
2245,
275,
542,
9053,
14,
261,
9053,
63,
2245,
63,
981,
8,
2479,
9,
267,
340,
4819,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
4871,
543,
542,
9053,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
354,
8,
2479,
12,
542,
2245,
12,
536,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
663,
542,
4871,
536,
543,
542,
9053,
531,
267,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
585,
8,
261,
2245,
12,
574,
9,
398,
4819,
12,
2155,
498,
275,
542,
9053,
14,
261,
9053,
63,
2245,
63,
498,
63,
5005,
8,
2479,
12,
542,
2245,
9,
267,
340,
4819,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
5536,
5046,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aziele/alfpy
|
tests/test_distmatrix.py
|
1
|
4612
|
import numpy as np
import os
import unittest
from alfpy import word_distance
from alfpy.utils import distmatrix
from . import utils
class TestDistMatrix(unittest.TestCase):
def setUp(self):
id_list = ['seq1', 'seq2', 'seq3']
data = np.array([[0, 0.3531587, 0.35509333],
[0.3531587, 0, 0.295394],
[0.35509333, 0.295394, 0.]
])
self.matrix = distmatrix.Matrix(id_list, data)
self.output_filename = utils.get_test_data('distmatrix.txt')
def test_format(self):
exp = [
' 3',
'seq1 0.0000000 0.3531587 0.3550933',
'seq2 0.3531587 0.0000000 0.2953940',
'seq3 0.3550933 0.2953940 0.0000000'
]
self.assertEqual(self.matrix.format(), "\n".join(exp))
def test_format_decimal3(self):
exp = [
' 3',
'seq1 0.000 0.353 0.355',
'seq2 0.353 0.000 0.295',
'seq3 0.355 0.295 0.000'
]
self.assertEqual(self.matrix.format(3), "\n".join(exp))
def test_min(self):
self.assertEqual(self.matrix.min(), 0)
def test_max(self):
self.assertEqual(self.matrix.max(), 0.35509332999999998)
def test_is_zero(self):
self.assertFalse(self.matrix.is_zero())
def test_normalize(self):
self.matrix.normalize()
exp = [
" 3",
"seq1 0.0000000 0.9945518 1.0000000",
"seq2 0.9945518 0.0000000 0.8318771",
"seq3 1.0000000 0.8318771 0.0000000",
]
self.assertEqual(self.matrix.format(), "\n".join(exp))
def test_write_to_file_phylip(self):
oh = open(self.output_filename, 'w')
self.matrix.write_to_file(oh)
oh.close()
fh = open(self.output_filename)
result = fh.read()
fh.close()
os.remove(self.output_filename)
exp = [
' 3',
'seq1 0.0000000 0.3531587 0.3550933',
'seq2 0.3531587 0.0000000 0.2953940',
'seq3 0.3550933 0.2953940 0.0000000\n'
]
self.assertEqual(result, "\n".join(exp))
def test_write_to_file_pairwise(self):
oh = open(self.output_filename, 'w')
self.matrix.write_to_file(oh, 'pairwise')
oh.close()
fh = open(self.output_filename)
result = fh.read()
fh.close()
os.remove(self.output_filename)
exp = [
"seq1\tseq2\t0.3531587",
"seq1\tseq3\t0.3550933",
"seq2\tseq3\t0.2953940\n"
]
self.assertEqual(result, "\n".join(exp))
def test_write_to_file_pairwise_decimal3(self):
oh = open(self.output_filename, 'w')
self.matrix.write_to_file(oh, 'pairwise', 3)
oh.close()
fh = open(self.output_filename)
result = fh.read()
fh.close()
os.remove(self.output_filename)
exp = [
"seq1\tseq2\t0.353",
"seq1\tseq3\t0.355",
"seq2\tseq3\t0.295\n"
]
self.assertEqual(result, "\n".join(exp))
def test_iter(self):
exp = [(0, 1, 'seq1', 'seq2', 0.35315869999999999),
(0, 2, 'seq1', 'seq3', 0.35509332999999998),
(1, 2, 'seq2', 'seq3', 0.29539399999999999)]
self.assertEqual(list(self.matrix), exp)
def test_create_matrix(self):
l = [[3, 6, 4, 1, 3, 4, 3, 0, 1, 1, 6, 4, 5, 0, 3, 4],
[0, 3, 0, 3, 0, 0, 0, 2, 9, 0, 3, 3, 0, 6, 3, 6],
[9, 0, 0, 3, 0, 0, 0, 2, 6, 0, 3, 3, 0, 3, 3, 3]]
vector = np.array(l)
dist = word_distance.Distance(vector, 'minkowski')
id_list = ['seq1', 'seq2', 'seq3']
matrix = distmatrix.create(id_list, dist)
exp = [
' 3',
'seq1 0.0000000 14.6969385 14.1774469',
'seq2 14.6969385 0.0000000 10.8166538',
'seq3 14.1774469 10.8166538 0.0000000'
]
self.assertEqual(matrix.format(), "\n".join(exp))
def test_highcharts(self):
self.assertEqual(len(self.matrix.highcharts()), 3)
def test_read_highcharts_matrix(self):
id_list = ['seq1', 'seq2', 'seq3']
data = [[0, 1, 0.35, 0.19], [0, 2, 1.0, 0.55], [1, 2, 0.88, 0.48]]
matrix = distmatrix.read_highcharts_matrix(id_list, data)
md5 = utils.calc_md5(matrix.format())
self.assertEqual(md5, "476c8f5d284a84ee3c7c419bde2d7658")
if __name__ == '__main__':
unittest.main()
|
mit
|
[
646,
2680,
465,
980,
199,
646,
747,
199,
646,
2882,
199,
199,
504,
282,
276,
647,
492,
4349,
63,
5590,
199,
504,
282,
276,
647,
14,
1208,
492,
2917,
3642,
199,
199,
504,
1275,
492,
3778,
421,
199,
533,
1379,
12012,
6443,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1305,
63,
513,
275,
788,
3610,
17,
297,
283,
3610,
18,
297,
283,
3610,
19,
418,
267,
666,
275,
980,
14,
1144,
4038,
16,
12,
378,
14,
1276,
9927,
1555,
12,
378,
14,
10156,
1643,
11769,
467,
586,
359,
16,
14,
1276,
9927,
1555,
12,
378,
12,
378,
14,
11405,
13549,
467,
586,
359,
16,
14,
10156,
1643,
11769,
12,
378,
14,
11405,
13549,
12,
378,
19784,
586,
4794,
267,
291,
14,
3642,
275,
2917,
3642,
14,
6443,
8,
344,
63,
513,
12,
666,
9,
267,
291,
14,
1199,
63,
1501,
275,
3778,
14,
362,
63,
396,
63,
576,
360,
2686,
3642,
14,
2424,
358,
339,
347,
511,
63,
908,
8,
277,
304,
267,
1437,
275,
359,
288,
283,
257,
650,
297,
288,
283,
3610,
17,
755,
378,
14,
9084,
378,
14,
1276,
9927,
1555,
378,
14,
10156,
1643,
1153,
297,
288,
283,
3610,
18,
755,
378,
14,
1276,
9927,
1555,
378,
14,
9084,
378,
14,
11405,
1355,
2167,
297,
288,
283,
3610,
19,
755,
378,
14,
10156,
1643,
1153,
378,
14,
11405,
1355,
2167,
378,
14,
9084,
7,
267,
1622,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
908,
1062,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
908,
63,
6355,
19,
8,
277,
304,
267,
1437,
275,
359,
288,
283,
257,
650,
297,
288,
283,
3610,
17,
755,
378,
14,
1493,
378,
14,
15355,
378,
14,
10156,
297,
288,
283,
3610,
18,
755,
378,
14,
15355,
378,
14,
1493,
378,
14,
11405,
297,
288,
283,
3610,
19,
755,
378,
14,
10156,
378,
14,
11405,
378,
14,
1493,
7,
267,
1622,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
908,
8,
19,
395,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
827,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
827,
1062,
378,
9,
339,
347,
511,
63,
988,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
988,
1062,
378,
14,
10156,
1643,
9526,
13453,
24,
9,
339,
347,
511,
63,
374,
63,
4262,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
3642,
14,
374,
63,
4262,
1012,
339,
347,
511,
63,
7721,
8,
277,
304,
267,
291,
14,
3642,
14,
7721,
342,
267,
1437,
275,
359,
288,
298,
257,
650,
401,
288,
298,
3610,
17,
755,
378,
14,
9084,
378,
14,
1020,
13267,
1085,
413,
14,
9084,
401,
288,
298,
3610,
18,
755,
378,
14,
1020,
13267,
1085,
378,
14,
9084,
378,
14,
2658,
1085,
19371,
401,
288,
298,
3610,
19,
755,
413,
14,
9084,
378,
14,
2658,
1085,
19371,
378,
14,
9084,
401,
267,
1622,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
908,
1062,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
952,
63,
475,
63,
493,
63,
6581,
3587,
8,
277,
304,
267,
312,
72,
275,
1551,
8,
277,
14,
1199,
63,
1501,
12,
283,
87,
358,
267,
291,
14,
3642,
14,
952,
63,
475,
63,
493,
8,
19194,
9,
267,
312,
72,
14,
1600,
342,
267,
11155,
275,
1551,
8,
277,
14,
1199,
63,
1501,
9,
267,
754,
275,
11155,
14,
739,
342,
267,
11155,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
14,
1199,
63,
1501,
9,
267,
1437,
275,
359,
288,
283,
257,
650,
297,
288,
283,
3610,
17,
755,
378,
14,
9084,
378,
14,
1276,
9927,
1555,
378,
14,
10156,
1643,
1153,
297,
288,
283,
3610,
18,
755,
378,
14,
1276,
9927,
1555,
378,
14,
9084,
378,
14,
11405,
1355,
2167,
297,
288,
283,
3610,
19,
755,
378,
14,
10156,
1643,
1153,
378,
14,
11405,
1355,
2167,
378,
14,
9084,
60,
78,
7,
267,
1622,
267,
291,
14,
629,
8,
1099,
12,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
952,
63,
475,
63,
493,
63,
25069,
8,
277,
304,
267,
312,
72,
275,
1551,
8,
277,
14,
1199,
63,
1501,
12,
283,
87,
358,
267,
291,
14,
3642,
14,
952,
63,
475,
63,
493,
8,
19194,
12,
283,
25069,
358,
267,
312,
72,
14,
1600,
342,
267,
11155,
275,
1551,
8,
277,
14,
1199,
63,
1501,
9,
267,
754,
275,
11155,
14,
739,
342,
267,
11155,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
14,
1199,
63,
1501,
9,
267,
1437,
275,
359,
288,
298,
3610,
17,
60,
84,
3610,
18,
60,
84,
16,
14,
1276,
9927,
1555,
401,
288,
298,
3610,
17,
60,
84,
3610,
19,
60,
84,
16,
14,
10156,
1643,
1153,
401,
288,
298,
3610,
18,
60,
84,
3610,
19,
60,
84,
16,
14,
11405,
1355,
2167,
60,
78,
2,
267,
1622,
267,
291,
14,
629,
8,
1099,
12,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
952,
63,
475,
63,
493,
63,
25069,
63,
6355,
19,
8,
277,
304,
267,
312,
72,
275,
1551,
8,
277,
14,
1199,
63,
1501,
12,
283,
87,
358,
267,
291,
14,
3642,
14,
952,
63,
475,
63,
493,
8,
19194,
12,
283,
25069,
297,
650,
9,
267,
312,
72,
14,
1600,
342,
267,
11155,
275,
1551,
8,
277,
14,
1199,
63,
1501,
9,
267,
754,
275,
11155,
14,
739,
342,
267,
11155,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
14,
1199,
63,
1501,
9,
267,
1437,
275,
359,
288,
298,
3610,
17,
60,
84,
3610,
18,
60,
84,
16,
14,
15355,
401,
288,
298,
3610,
17,
60,
84,
3610,
19,
60,
84,
16,
14,
10156,
401,
288,
298,
3610,
18,
60,
84,
3610,
19,
60,
84,
16,
14,
11405,
60,
78,
2,
267,
1622,
267,
291,
14,
629,
8,
1099,
12,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
1661,
8,
277,
304,
267,
1437,
275,
3842,
16,
12,
413,
12,
283,
3610,
17,
297,
283,
3610,
18,
297,
378,
14,
1276,
9927,
1184,
13453,
1020,
395,
2049,
334,
16,
12,
499,
12,
283,
3610
] |
[
2680,
465,
980,
199,
646,
747,
199,
646,
2882,
199,
199,
504,
282,
276,
647,
492,
4349,
63,
5590,
199,
504,
282,
276,
647,
14,
1208,
492,
2917,
3642,
199,
199,
504,
1275,
492,
3778,
421,
199,
533,
1379,
12012,
6443,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1305,
63,
513,
275,
788,
3610,
17,
297,
283,
3610,
18,
297,
283,
3610,
19,
418,
267,
666,
275,
980,
14,
1144,
4038,
16,
12,
378,
14,
1276,
9927,
1555,
12,
378,
14,
10156,
1643,
11769,
467,
586,
359,
16,
14,
1276,
9927,
1555,
12,
378,
12,
378,
14,
11405,
13549,
467,
586,
359,
16,
14,
10156,
1643,
11769,
12,
378,
14,
11405,
13549,
12,
378,
19784,
586,
4794,
267,
291,
14,
3642,
275,
2917,
3642,
14,
6443,
8,
344,
63,
513,
12,
666,
9,
267,
291,
14,
1199,
63,
1501,
275,
3778,
14,
362,
63,
396,
63,
576,
360,
2686,
3642,
14,
2424,
358,
339,
347,
511,
63,
908,
8,
277,
304,
267,
1437,
275,
359,
288,
283,
257,
650,
297,
288,
283,
3610,
17,
755,
378,
14,
9084,
378,
14,
1276,
9927,
1555,
378,
14,
10156,
1643,
1153,
297,
288,
283,
3610,
18,
755,
378,
14,
1276,
9927,
1555,
378,
14,
9084,
378,
14,
11405,
1355,
2167,
297,
288,
283,
3610,
19,
755,
378,
14,
10156,
1643,
1153,
378,
14,
11405,
1355,
2167,
378,
14,
9084,
7,
267,
1622,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
908,
1062,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
908,
63,
6355,
19,
8,
277,
304,
267,
1437,
275,
359,
288,
283,
257,
650,
297,
288,
283,
3610,
17,
755,
378,
14,
1493,
378,
14,
15355,
378,
14,
10156,
297,
288,
283,
3610,
18,
755,
378,
14,
15355,
378,
14,
1493,
378,
14,
11405,
297,
288,
283,
3610,
19,
755,
378,
14,
10156,
378,
14,
11405,
378,
14,
1493,
7,
267,
1622,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
908,
8,
19,
395,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
827,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
827,
1062,
378,
9,
339,
347,
511,
63,
988,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
988,
1062,
378,
14,
10156,
1643,
9526,
13453,
24,
9,
339,
347,
511,
63,
374,
63,
4262,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
3642,
14,
374,
63,
4262,
1012,
339,
347,
511,
63,
7721,
8,
277,
304,
267,
291,
14,
3642,
14,
7721,
342,
267,
1437,
275,
359,
288,
298,
257,
650,
401,
288,
298,
3610,
17,
755,
378,
14,
9084,
378,
14,
1020,
13267,
1085,
413,
14,
9084,
401,
288,
298,
3610,
18,
755,
378,
14,
1020,
13267,
1085,
378,
14,
9084,
378,
14,
2658,
1085,
19371,
401,
288,
298,
3610,
19,
755,
413,
14,
9084,
378,
14,
2658,
1085,
19371,
378,
14,
9084,
401,
267,
1622,
267,
291,
14,
629,
8,
277,
14,
3642,
14,
908,
1062,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
952,
63,
475,
63,
493,
63,
6581,
3587,
8,
277,
304,
267,
312,
72,
275,
1551,
8,
277,
14,
1199,
63,
1501,
12,
283,
87,
358,
267,
291,
14,
3642,
14,
952,
63,
475,
63,
493,
8,
19194,
9,
267,
312,
72,
14,
1600,
342,
267,
11155,
275,
1551,
8,
277,
14,
1199,
63,
1501,
9,
267,
754,
275,
11155,
14,
739,
342,
267,
11155,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
14,
1199,
63,
1501,
9,
267,
1437,
275,
359,
288,
283,
257,
650,
297,
288,
283,
3610,
17,
755,
378,
14,
9084,
378,
14,
1276,
9927,
1555,
378,
14,
10156,
1643,
1153,
297,
288,
283,
3610,
18,
755,
378,
14,
1276,
9927,
1555,
378,
14,
9084,
378,
14,
11405,
1355,
2167,
297,
288,
283,
3610,
19,
755,
378,
14,
10156,
1643,
1153,
378,
14,
11405,
1355,
2167,
378,
14,
9084,
60,
78,
7,
267,
1622,
267,
291,
14,
629,
8,
1099,
12,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
952,
63,
475,
63,
493,
63,
25069,
8,
277,
304,
267,
312,
72,
275,
1551,
8,
277,
14,
1199,
63,
1501,
12,
283,
87,
358,
267,
291,
14,
3642,
14,
952,
63,
475,
63,
493,
8,
19194,
12,
283,
25069,
358,
267,
312,
72,
14,
1600,
342,
267,
11155,
275,
1551,
8,
277,
14,
1199,
63,
1501,
9,
267,
754,
275,
11155,
14,
739,
342,
267,
11155,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
14,
1199,
63,
1501,
9,
267,
1437,
275,
359,
288,
298,
3610,
17,
60,
84,
3610,
18,
60,
84,
16,
14,
1276,
9927,
1555,
401,
288,
298,
3610,
17,
60,
84,
3610,
19,
60,
84,
16,
14,
10156,
1643,
1153,
401,
288,
298,
3610,
18,
60,
84,
3610,
19,
60,
84,
16,
14,
11405,
1355,
2167,
60,
78,
2,
267,
1622,
267,
291,
14,
629,
8,
1099,
12,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
952,
63,
475,
63,
493,
63,
25069,
63,
6355,
19,
8,
277,
304,
267,
312,
72,
275,
1551,
8,
277,
14,
1199,
63,
1501,
12,
283,
87,
358,
267,
291,
14,
3642,
14,
952,
63,
475,
63,
493,
8,
19194,
12,
283,
25069,
297,
650,
9,
267,
312,
72,
14,
1600,
342,
267,
11155,
275,
1551,
8,
277,
14,
1199,
63,
1501,
9,
267,
754,
275,
11155,
14,
739,
342,
267,
11155,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
14,
1199,
63,
1501,
9,
267,
1437,
275,
359,
288,
298,
3610,
17,
60,
84,
3610,
18,
60,
84,
16,
14,
15355,
401,
288,
298,
3610,
17,
60,
84,
3610,
19,
60,
84,
16,
14,
10156,
401,
288,
298,
3610,
18,
60,
84,
3610,
19,
60,
84,
16,
14,
11405,
60,
78,
2,
267,
1622,
267,
291,
14,
629,
8,
1099,
12,
1867,
78,
1674,
904,
8,
1474,
430,
339,
347,
511,
63,
1661,
8,
277,
304,
267,
1437,
275,
3842,
16,
12,
413,
12,
283,
3610,
17,
297,
283,
3610,
18,
297,
378,
14,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
georgefrank/ansible-modules-extras
|
monitoring/stackdriver.py
|
58
|
6848
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
module: stackdriver
short_description: Send code deploy and annotation events to stackdriver
description:
- Send code deploy and annotation events to Stackdriver
version_added: "1.6"
author: "Ben Whaley (@bwhaley)"
options:
key:
description:
- API key.
required: true
default: null
event:
description:
- The type of event to send, either annotation or deploy
choices: ['annotation', 'deploy']
required: false
default: null
revision_id:
description:
- The revision of the code that was deployed. Required for deploy events
required: false
default: null
deployed_by:
description:
- The person or robot responsible for deploying the code
required: false
default: "Ansible"
deployed_to:
description:
- "The environment code was deployed to. (ie: development, staging, production)"
required: false
default: null
repository:
description:
- The repository (or project) deployed
required: false
default: null
msg:
description:
- The contents of the annotation message, in plain text. Limited to 256 characters. Required for annotation.
required: false
default: null
annotated_by:
description:
- The person or robot who the annotation should be attributed to.
required: false
default: "Ansible"
level:
description:
- one of INFO/WARN/ERROR, defaults to INFO if not supplied. May affect display.
choices: ['INFO', 'WARN', 'ERROR']
required: false
default: 'INFO'
instance_id:
description:
- id of an EC2 instance that this event should be attached to, which will limit the contexts where this event is shown
required: false
default: null
event_epoch:
description:
- "Unix timestamp of where the event should appear in the timeline, defaults to now. Be careful with this."
required: false
default: null
'''
EXAMPLES = '''
- stackdriver: key=AAAAAA event=deploy deployed_to=production deployed_by=leeroyjenkins repository=MyWebApp revision_id=abcd123
- stackdriver: key=AAAAAA event=annotation msg="Greetings from Ansible" annotated_by=leeroyjenkins level=WARN instance_id=i-abcd1234
'''
# ===========================================
# Stackdriver module specific support methods.
#
try:
import json
except ImportError:
import simplejson as json
def send_deploy_event(module, key, revision_id, deployed_by='Ansible', deployed_to=None, repository=None):
"""Send a deploy event to Stackdriver"""
deploy_api = "https://event-gateway.stackdriver.com/v1/deployevent"
params = {}
params['revision_id'] = revision_id
params['deployed_by'] = deployed_by
if deployed_to:
params['deployed_to'] = deployed_to
if repository:
params['repository'] = repository
return do_send_request(module, deploy_api, params, key)
def send_annotation_event(module, key, msg, annotated_by='Ansible', level=None, instance_id=None, event_epoch=None):
"""Send an annotation event to Stackdriver"""
annotation_api = "https://event-gateway.stackdriver.com/v1/annotationevent"
params = {}
params['message'] = msg
if annotated_by:
params['annotated_by'] = annotated_by
if level:
params['level'] = level
if instance_id:
params['instance_id'] = instance_id
if event_epoch:
params['event_epoch'] = event_epoch
return do_send_request(module, annotation_api, params, key)
def do_send_request(module, url, params, key):
data = json.dumps(params)
headers = {
'Content-Type': 'application/json',
'x-stackdriver-apikey': key
}
response, info = fetch_url(module, url, headers=headers, data=data, method='POST')
if info['status'] != 200:
module.fail_json(msg="Unable to send msg: %s" % info['msg'])
# ===========================================
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
key=dict(required=True),
event=dict(required=True, choices=['deploy', 'annotation']),
msg=dict(),
revision_id=dict(),
annotated_by=dict(default='Ansible'),
level=dict(default='INFO', choices=['INFO', 'WARN', 'ERROR']),
instance_id=dict(),
event_epoch=dict(),
deployed_by=dict(default='Ansible'),
deployed_to=dict(),
repository=dict(),
),
supports_check_mode=True
)
key = module.params["key"]
event = module.params["event"]
# Annotation params
msg = module.params["msg"]
annotated_by = module.params["annotated_by"]
level = module.params["level"]
instance_id = module.params["instance_id"]
event_epoch = module.params["event_epoch"]
# Deploy params
revision_id = module.params["revision_id"]
deployed_by = module.params["deployed_by"]
deployed_to = module.params["deployed_to"]
repository = module.params["repository"]
##################################################################
# deploy requires revision_id
# annotation requires msg
# We verify these manually
##################################################################
if event == 'deploy':
if not revision_id:
module.fail_json(msg="revision_id required for deploy events")
try:
send_deploy_event(module, key, revision_id, deployed_by, deployed_to, repository)
except Exception, e:
module.fail_json(msg="unable to sent deploy event: %s" % e)
if event == 'annotation':
if not msg:
module.fail_json(msg="msg required for annotation events")
try:
send_annotation_event(module, key, msg, annotated_by, level, instance_id, event_epoch)
except Exception, e:
module.fail_json(msg="unable to sent annotation event: %s" % e)
changed = True
module.exit_json(changed=changed, deployed_by=deployed_by)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
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,
8948,
275,
1449,
199,
199,
578,
26,
3464,
3090,
199,
3612,
63,
1802,
26,
10217,
1233,
12287,
436,
11262,
4474,
370,
3464,
3090,
199,
1802,
26,
523,
446,
10217,
1233,
12287,
436,
11262,
4474,
370,
13894,
3090,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
2502,
26,
298,
31231,
2816,
1895,
89,
8593,
66,
2191,
1895,
89,
2924,
199,
1419,
26,
523,
790,
26,
272,
1369,
26,
489,
446,
3261,
790,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
1566,
26,
272,
1369,
26,
489,
446,
710,
730,
402,
1566,
370,
3222,
12,
1902,
11262,
503,
12287,
272,
3415,
26,
788,
9340,
297,
283,
11060,
418,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
6974,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
6974,
402,
314,
1233,
626,
1990,
26181,
14,
11105,
367,
12287,
4474,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
26181,
63,
991,
26,
272,
1369,
26,
489,
446,
710,
4954,
503,
14544,
17845,
367,
12287,
316,
314,
1233,
272,
1415,
26,
3055,
272,
849,
26,
298,
10047,
2,
523,
26181,
63,
475,
26,
272,
1369,
26,
489,
446,
298,
1918,
3734,
1233,
1990,
26181,
370,
14,
334,
1873,
26,
16367,
12,
28512,
12,
9920,
2924,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
7611,
26,
272,
1369,
26,
489,
446,
710,
7611,
334,
269,
2199,
9,
26181,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1499,
26,
272,
1369,
26,
15166,
446,
710,
4072,
402,
314,
11262,
1245,
12,
315,
8971,
1318,
14,
221,
10619,
7219,
5703,
370,
7633,
4110,
14,
11105,
367,
11262,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
27526,
63,
991,
26,
5591,
1369,
26,
489,
446,
710,
4954,
503,
14544,
10619,
11345,
314,
11262,
1077,
506,
737,
24855,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
298,
10047,
2,
523,
2166,
26,
5591,
1369,
26,
489,
446,
1373,
402,
24008,
15,
17449,
15,
3170,
12,
4243,
370,
24008,
340,
440,
6841,
14,
221,
10619,
15586,
12787,
2929,
14,
272,
3415,
26,
788,
4531,
297,
283,
17449,
297,
283,
3170,
418,
272,
1415,
26,
3055,
272,
849,
26,
283,
4531,
7,
523,
1256,
63,
344,
26,
272,
1369,
26,
489,
446,
1305,
402,
376,
15352,
18,
1256,
626,
642,
1566,
1077,
506,
10102,
370,
12,
1314,
911,
2304,
314,
18191,
2382,
642,
1566,
365,
9164,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1566,
63,
7367,
26,
272,
1369,
26,
489,
446,
298,
21607,
4913,
402,
2382,
314,
1566,
1077,
7468,
315,
314,
20780,
12,
4243,
370,
3063,
14,
6423,
25082,
543,
642,
2122,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
3464,
3090,
26,
790,
29,
6151,
2276,
1566,
29,
11060,
26181,
63,
475,
29,
10777,
26181,
63,
991,
29,
274,
3478,
89,
25622,
7611,
29,
5713,
5926,
2640,
6974,
63,
344,
29,
13591,
4288,
199,
199,
13,
3464,
3090,
26,
790,
29,
6151,
2276,
1566,
29,
9340,
1499,
628,
39,
7936,
780,
687,
2622,
2,
27526,
63,
991,
29,
274,
3478,
89,
25622,
2166,
29,
17449,
1256,
63,
344,
29,
73,
13,
13591,
4321,
199,
2344,
199,
199,
3,
19469,
17575,
199,
3,
13894,
3090,
859,
2488,
2291,
3102,
14,
199,
3,
199,
893,
26,
523,
492,
2022,
199,
2590,
3545,
26,
523,
492,
13804,
465,
2022,
199,
199,
318,
3222,
63,
11060,
63,
1430,
8,
578,
12,
790,
12,
6974,
63,
344,
12,
26181,
63,
991,
534,
10047,
297,
26181,
63,
475,
29,
403,
12,
7611,
29,
403,
304,
272,
408,
6795,
282,
12287,
1566,
370,
13894,
3090,
624,
272,
12287,
63,
1246,
275,
298,
2859,
921,
1430,
13,
7019,
14,
2340,
3090,
14,
957,
15,
86,
17,
15,
11060,
1430,
2,
339,
1862,
275,
1052,
272,
1862,
459,
5792,
63,
344,
418,
275,
6974,
63,
344,
272,
1862,
459,
11060,
379,
63,
991,
418,
275,
26181,
63,
991,
272,
340,
26181,
63,
475,
26,
267,
1862,
459,
11060,
379,
63,
475,
418,
275,
26181,
63,
475,
272,
340,
7611,
26,
267,
1862,
459,
8421,
418,
275,
7611,
339,
372,
886,
63,
2254,
63,
1069,
8,
578,
12,
12287,
63,
1246,
12,
1862,
12,
790,
9,
199,
199,
318,
3222,
63,
9340,
63,
1430,
8,
578,
12,
790,
12,
1499,
12,
27526,
63,
991,
534,
10047,
297,
2166,
29,
403,
12,
1256,
63,
344,
29,
403,
12,
1566,
63,
7367,
29,
403,
304,
272,
408,
6795,
376,
11262,
1566,
370,
13894,
3090,
624,
272,
11262,
63,
1246,
275,
298,
2859,
921,
1430,
13,
7019,
14,
2340,
3090,
14,
957,
15,
86,
17,
15,
9340,
1430,
2,
339,
1862,
275,
1052,
272,
1862,
459,
1188,
418,
275,
1499,
272,
340,
27526,
63,
991,
26,
267,
1862,
459,
3226,
972,
63,
991,
418,
275,
27526,
63,
991,
272,
340,
2166,
26,
267,
1862,
459,
1896,
418,
275,
2166,
272,
340,
1256,
63,
344,
26,
267,
1862,
459,
842,
63,
344,
418,
275,
1256,
63,
344,
272,
340,
1566,
63,
7367,
26,
267,
1862,
459,
1430,
63,
7367,
418,
275,
1566,
63,
7367,
339,
372,
886,
63,
2254,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
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,
8948,
275,
1449,
199,
199,
578,
26,
3464,
3090,
199,
3612,
63,
1802,
26,
10217,
1233,
12287,
436,
11262,
4474,
370,
3464,
3090,
199,
1802,
26,
523,
446,
10217,
1233,
12287,
436,
11262,
4474,
370,
13894,
3090,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
2502,
26,
298,
31231,
2816,
1895,
89,
8593,
66,
2191,
1895,
89,
2924,
199,
1419,
26,
523,
790,
26,
272,
1369,
26,
489,
446,
3261,
790,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
1566,
26,
272,
1369,
26,
489,
446,
710,
730,
402,
1566,
370,
3222,
12,
1902,
11262,
503,
12287,
272,
3415,
26,
788,
9340,
297,
283,
11060,
418,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
6974,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
6974,
402,
314,
1233,
626,
1990,
26181,
14,
11105,
367,
12287,
4474,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
26181,
63,
991,
26,
272,
1369,
26,
489,
446,
710,
4954,
503,
14544,
17845,
367,
12287,
316,
314,
1233,
272,
1415,
26,
3055,
272,
849,
26,
298,
10047,
2,
523,
26181,
63,
475,
26,
272,
1369,
26,
489,
446,
298,
1918,
3734,
1233,
1990,
26181,
370,
14,
334,
1873,
26,
16367,
12,
28512,
12,
9920,
2924,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
7611,
26,
272,
1369,
26,
489,
446,
710,
7611,
334,
269,
2199,
9,
26181,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1499,
26,
272,
1369,
26,
15166,
446,
710,
4072,
402,
314,
11262,
1245,
12,
315,
8971,
1318,
14,
221,
10619,
7219,
5703,
370,
7633,
4110,
14,
11105,
367,
11262,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
27526,
63,
991,
26,
5591,
1369,
26,
489,
446,
710,
4954,
503,
14544,
10619,
11345,
314,
11262,
1077,
506,
737,
24855,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
298,
10047,
2,
523,
2166,
26,
5591,
1369,
26,
489,
446,
1373,
402,
24008,
15,
17449,
15,
3170,
12,
4243,
370,
24008,
340,
440,
6841,
14,
221,
10619,
15586,
12787,
2929,
14,
272,
3415,
26,
788,
4531,
297,
283,
17449,
297,
283,
3170,
418,
272,
1415,
26,
3055,
272,
849,
26,
283,
4531,
7,
523,
1256,
63,
344,
26,
272,
1369,
26,
489,
446,
1305,
402,
376,
15352,
18,
1256,
626,
642,
1566,
1077,
506,
10102,
370,
12,
1314,
911,
2304,
314,
18191,
2382,
642,
1566,
365,
9164,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1566,
63,
7367,
26,
272,
1369,
26,
489,
446,
298,
21607,
4913,
402,
2382,
314,
1566,
1077,
7468,
315,
314,
20780,
12,
4243,
370,
3063,
14,
6423,
25082,
543,
642,
2122,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
3464,
3090,
26,
790,
29,
6151,
2276,
1566,
29,
11060,
26181,
63,
475,
29,
10777,
26181,
63,
991,
29,
274,
3478,
89,
25622,
7611,
29,
5713,
5926,
2640,
6974,
63,
344,
29,
13591,
4288,
199,
199,
13,
3464,
3090,
26,
790,
29,
6151,
2276,
1566,
29,
9340,
1499,
628,
39,
7936,
780,
687,
2622,
2,
27526,
63,
991,
29,
274,
3478,
89,
25622,
2166,
29,
17449,
1256,
63,
344,
29,
73,
13,
13591,
4321,
199,
2344,
199,
199,
3,
19469,
17575,
199,
3,
13894,
3090,
859,
2488,
2291,
3102,
14,
199,
3,
199,
893,
26,
523,
492,
2022,
199,
2590,
3545,
26,
523,
492,
13804,
465,
2022,
199,
199,
318,
3222,
63,
11060,
63,
1430,
8,
578,
12,
790,
12,
6974,
63,
344,
12,
26181,
63,
991,
534,
10047,
297,
26181,
63,
475,
29,
403,
12,
7611,
29,
403,
304,
272,
408,
6795,
282,
12287,
1566,
370,
13894,
3090,
624,
272,
12287,
63,
1246,
275,
298,
2859,
921,
1430,
13,
7019,
14,
2340,
3090,
14,
957,
15,
86,
17,
15,
11060,
1430,
2,
339,
1862,
275,
1052,
272,
1862,
459,
5792,
63,
344,
418,
275,
6974,
63,
344,
272,
1862,
459,
11060,
379,
63,
991,
418,
275,
26181,
63,
991,
272,
340,
26181,
63,
475,
26,
267,
1862,
459,
11060,
379,
63,
475,
418,
275,
26181,
63,
475,
272,
340,
7611,
26,
267,
1862,
459,
8421,
418,
275,
7611,
339,
372,
886,
63,
2254,
63,
1069,
8,
578,
12,
12287,
63,
1246,
12,
1862,
12,
790,
9,
199,
199,
318,
3222,
63,
9340,
63,
1430,
8,
578,
12,
790,
12,
1499,
12,
27526,
63,
991,
534,
10047,
297,
2166,
29,
403,
12,
1256,
63,
344,
29,
403,
12,
1566,
63,
7367,
29,
403,
304,
272,
408,
6795,
376,
11262,
1566,
370,
13894,
3090,
624,
272,
11262,
63,
1246,
275,
298,
2859,
921,
1430,
13,
7019,
14,
2340,
3090,
14,
957,
15,
86,
17,
15,
9340,
1430,
2,
339,
1862,
275,
1052,
272,
1862,
459,
1188,
418,
275,
1499,
272,
340,
27526,
63,
991,
26,
267,
1862,
459,
3226,
972,
63,
991,
418,
275,
27526,
63,
991,
272,
340,
2166,
26,
267,
1862,
459,
1896,
418,
275,
2166,
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,
1,
1,
1
] |
Urokhtor/AeonEngine
|
World/Scene.py
|
1
|
2258
|
class Scene:
"""
Scene is the base class for playable environments, like exteriors, interiors and the world map.
The interface defines methods that are called in different situations, such as entering a scene,
or leaving a scene which allows the users to define things like loading and unloading resources for
the environment.
"""
def __init__(self, environment):
self.environment = environment
self.updateables = []
self.renderables = []
# We should also hold a map of some kind.
def onInit(self):
raise NotImplementedError("Subclass deriving from Scene class hasn't implemented onInit method")
def onEnter(self):
raise NotImplementedError("Subclass deriving from Scene class hasn't implemented onEnter method")
def onUpdate(self, cumTime):
if len(self.updateables) < 1:
return
for updateable in self.updateables:
updateable.update(cumTime)
def onPause(self):
raise NotImplementedError("Subclass deriving from Scene class hasn't implemented onPause method")
def onLeave(self):
raise NotImplementedError("Subclass deriving from Scene class hasn't implemented onLeave method")
def onPreRender(self, cumTime):
raise NotImplementedError("Subclass deriving from Scene class hasn't implemented onPreRender method")
def onRender(self, cumTime):
if len(self.renderables) < 1:
return
for renderable in self.renderables:
renderable.render(cumTime, self.environment.renderer)
def onPostRender(self, cumTime):
raise NotImplementedError("Subclass deriving from Scene class hasn't implemented onPostRender method")
def addUpdateable(self, updateable):
if updateable is None:
return False
if updateable.update is None:
return False
self.updateables.append(updateable)
def addRenderable(self, renderable):
if renderable is None:
return False
if renderable.render is None:
return False
self.renderables.append(renderable)
|
gpl-3.0
|
[
533,
18055,
69,
26,
272,
408,
267,
18055,
69,
365,
314,
1300,
1021,
367,
5232,
461,
22196,
12,
2839,
444,
6236,
1384,
12,
4661,
322,
1384,
436,
314,
6701,
2341,
14,
267,
710,
3217,
7890,
3102,
626,
787,
2797,
315,
3365,
24325,
12,
4066,
465,
9509,
316,
282,
13856,
12,
267,
503,
23188,
282,
13856,
1314,
6127,
314,
4390,
370,
5627,
7645,
2839,
8697,
436,
625,
8786,
5944,
367,
267,
314,
3734,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
12,
3734,
304,
267,
291,
14,
5418,
275,
3734,
267,
291,
14,
873,
5921,
275,
942,
267,
291,
14,
828,
271,
6842,
83,
275,
942,
267,
327,
2136,
1077,
2597,
10266,
282,
2341,
402,
2005,
4928,
14,
2286,
347,
641,
9346,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
9346,
1083,
531,
2286,
347,
641,
8468,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
8468,
1083,
531,
2286,
347,
641,
4152,
8,
277,
12,
17303,
1366,
304,
267,
340,
822,
8,
277,
14,
873,
5921,
9,
665,
413,
26,
288,
372,
2728,
367,
1678,
461,
315,
291,
14,
873,
5921,
26,
288,
1678,
461,
14,
873,
8,
11898,
1366,
9,
2286,
347,
641,
30851,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
30851,
1083,
531,
2286,
347,
641,
23679,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
23679,
1083,
531,
2286,
347,
641,
2398,
9216,
8,
277,
12,
17303,
1366,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
2398,
9216,
1083,
531,
2286,
347,
641,
9216,
8,
277,
12,
17303,
1366,
304,
267,
340,
822,
8,
277,
14,
828,
271,
6842,
83,
9,
665,
413,
26,
288,
372,
2728,
367,
2903,
271,
6842,
315,
291,
14,
828,
271,
6842,
83,
26,
288,
2903,
271,
6842,
14,
3352,
8,
11898,
1366,
12,
291,
14,
5418,
14,
12471,
9,
2286,
347,
641,
6564,
9216,
8,
277,
12,
17303,
1366,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
6564,
9216,
1083,
531,
2286,
347,
1050,
4152,
461,
8,
277,
12,
1678,
461,
304,
267,
340,
1678,
461,
365,
488,
26,
288,
372,
756,
2728,
340,
1678,
461,
14,
873,
365,
488,
26,
288,
372,
756,
2728,
291,
14,
873,
5921,
14,
740,
8,
873,
461,
9,
5493,
347,
1050,
5349,
271,
6842,
8,
277,
12,
2903,
271,
6842,
304,
267,
340,
2903,
271,
6842,
365,
488,
26,
288,
372,
756,
2728,
340,
2903,
271,
6842,
14,
3352,
365,
488,
26,
288,
372,
756,
2728,
291,
14,
828,
271,
6842,
83,
14,
740,
8,
828,
271,
6842,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
18055,
69,
26,
272,
408,
267,
18055,
69,
365,
314,
1300,
1021,
367,
5232,
461,
22196,
12,
2839,
444,
6236,
1384,
12,
4661,
322,
1384,
436,
314,
6701,
2341,
14,
267,
710,
3217,
7890,
3102,
626,
787,
2797,
315,
3365,
24325,
12,
4066,
465,
9509,
316,
282,
13856,
12,
267,
503,
23188,
282,
13856,
1314,
6127,
314,
4390,
370,
5627,
7645,
2839,
8697,
436,
625,
8786,
5944,
367,
267,
314,
3734,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
12,
3734,
304,
267,
291,
14,
5418,
275,
3734,
267,
291,
14,
873,
5921,
275,
942,
267,
291,
14,
828,
271,
6842,
83,
275,
942,
267,
327,
2136,
1077,
2597,
10266,
282,
2341,
402,
2005,
4928,
14,
2286,
347,
641,
9346,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
9346,
1083,
531,
2286,
347,
641,
8468,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
8468,
1083,
531,
2286,
347,
641,
4152,
8,
277,
12,
17303,
1366,
304,
267,
340,
822,
8,
277,
14,
873,
5921,
9,
665,
413,
26,
288,
372,
2728,
367,
1678,
461,
315,
291,
14,
873,
5921,
26,
288,
1678,
461,
14,
873,
8,
11898,
1366,
9,
2286,
347,
641,
30851,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
30851,
1083,
531,
2286,
347,
641,
23679,
8,
277,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
23679,
1083,
531,
2286,
347,
641,
2398,
9216,
8,
277,
12,
17303,
1366,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
2398,
9216,
1083,
531,
2286,
347,
641,
9216,
8,
277,
12,
17303,
1366,
304,
267,
340,
822,
8,
277,
14,
828,
271,
6842,
83,
9,
665,
413,
26,
288,
372,
2728,
367,
2903,
271,
6842,
315,
291,
14,
828,
271,
6842,
83,
26,
288,
2903,
271,
6842,
14,
3352,
8,
11898,
1366,
12,
291,
14,
5418,
14,
12471,
9,
2286,
347,
641,
6564,
9216,
8,
277,
12,
17303,
1366,
304,
267,
746,
4279,
480,
23636,
5405,
4007,
687,
18055,
69,
1021,
18699,
1133,
6366,
641,
6564,
9216,
1083,
531,
2286,
347,
1050,
4152,
461,
8,
277,
12,
1678,
461,
304,
267,
340,
1678,
461,
365,
488,
26,
288,
372,
756,
2728,
340,
1678,
461,
14,
873,
365,
488,
26,
288,
372,
756,
2728,
291,
14,
873,
5921,
14,
740,
8,
873,
461,
9,
5493,
347,
1050,
5349,
271,
6842,
8,
277,
12,
2903,
271,
6842,
304,
267,
340,
2903,
271,
6842,
365,
488,
26,
288,
372,
756,
2728,
340,
2903,
271,
6842,
14,
3352,
365,
488,
26,
288,
372,
756,
2728,
291,
14,
828,
271,
6842,
83,
14,
740,
8,
828,
271,
6842,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
kmike/scikit-learn
|
examples/plot_lda_qda.py
|
12
|
4758
|
"""
====================================================================
Linear and Quadratic Discriminant Analysis with confidence ellipsoid
====================================================================
Plot the confidence ellipsoids of each class and decision boundary
"""
print(__doc__)
from scipy import linalg
import numpy as np
import pylab as pl
import matplotlib as mpl
from matplotlib import colors
from sklearn.lda import LDA
from sklearn.qda import QDA
###############################################################################
# colormap
cmap = colors.LinearSegmentedColormap(
'red_blue_classes',
{'red': [(0, 1, 1), (1, 0.7, 0.7)],
'green': [(0, 0.7, 0.7), (1, 0.7, 0.7)],
'blue': [(0, 0.7, 0.7), (1, 1, 1)]})
pl.cm.register_cmap(cmap=cmap)
###############################################################################
# generate datasets
def dataset_fixed_cov():
'''Generate 2 Gaussians samples with the same covariance matrix'''
n, dim = 300, 2
np.random.seed(0)
C = np.array([[0., -0.23], [0.83, .23]])
X = np.r_[np.dot(np.random.randn(n, dim), C),
np.dot(np.random.randn(n, dim), C) + np.array([1, 1])]
y = np.hstack((np.zeros(n), np.ones(n)))
return X, y
def dataset_cov():
'''Generate 2 Gaussians samples with different covariance matrices'''
n, dim = 300, 2
np.random.seed(0)
C = np.array([[0., -1.], [2.5, .7]]) * 2.
X = np.r_[np.dot(np.random.randn(n, dim), C),
np.dot(np.random.randn(n, dim), C.T) + np.array([1, 4])]
y = np.hstack((np.zeros(n), np.ones(n)))
return X, y
###############################################################################
# plot functions
def plot_data(lda, X, y, y_pred, fig_index):
splot = pl.subplot(2, 2, fig_index)
if fig_index == 1:
pl.title('Linear Discriminant Analysis')
pl.ylabel('Data with fixed covariance')
elif fig_index == 2:
pl.title('Quadratic Discriminant Analysis')
elif fig_index == 3:
pl.ylabel('Data with varying covariances')
tp = (y == y_pred) # True Positive
tp0, tp1 = tp[y == 0], tp[y == 1]
X0, X1 = X[y == 0], X[y == 1]
X0_tp, X0_fp = X0[tp0], X0[~tp0]
X1_tp, X1_fp = X1[tp1], X1[~tp1]
xmin, xmax = X[:, 0].min(), X[:, 0].max()
ymin, ymax = X[:, 1].min(), X[:, 1].max()
# class 0: dots
pl.plot(X0_tp[:, 0], X0_tp[:, 1], 'o', color='red')
pl.plot(X0_fp[:, 0], X0_fp[:, 1], '.', color='#990000') # dark red
# class 1: dots
pl.plot(X1_tp[:, 0], X1_tp[:, 1], 'o', color='blue')
pl.plot(X1_fp[:, 0], X1_fp[:, 1], '.', color='#000099') # dark blue
# class 0 and 1 : areas
nx, ny = 200, 100
x_min, x_max = pl.xlim()
y_min, y_max = pl.ylim()
xx, yy = np.meshgrid(np.linspace(x_min, x_max, nx),
np.linspace(y_min, y_max, ny))
Z = lda.predict_proba(np.c_[xx.ravel(), yy.ravel()])
Z = Z[:, 1].reshape(xx.shape)
pl.pcolormesh(xx, yy, Z, cmap='red_blue_classes',
norm=colors.Normalize(0., 1.))
pl.contour(xx, yy, Z, [0.5], linewidths=2., colors='k')
# means
pl.plot(lda.means_[0][0], lda.means_[0][1],
'o', color='black', markersize=10)
pl.plot(lda.means_[1][0], lda.means_[1][1],
'o', color='black', markersize=10)
return splot
def plot_ellipse(splot, mean, cov, color):
v, w = linalg.eigh(cov)
u = w[0] / linalg.norm(w[0])
angle = np.arctan(u[1] / u[0])
angle = 180 * angle / np.pi # convert to degrees
# filled gaussian at 2 standard deviation
ell = mpl.patches.Ellipse(mean, 2 * v[0] ** 0.5, 2 * v[1] ** 0.5,
180 + angle, color=color)
ell.set_clip_box(splot.bbox)
ell.set_alpha(0.5)
splot.add_artist(ell)
splot.set_xticks(())
splot.set_yticks(())
def plot_lda_cov(lda, splot):
plot_ellipse(splot, lda.means_[0], lda.covariance_, 'red')
plot_ellipse(splot, lda.means_[1], lda.covariance_, 'blue')
def plot_qda_cov(qda, splot):
plot_ellipse(splot, qda.means_[0], qda.covariances_[0], 'red')
plot_ellipse(splot, qda.means_[1], qda.covariances_[1], 'blue')
###############################################################################
for i, (X, y) in enumerate([dataset_fixed_cov(), dataset_cov()]):
# LDA
lda = LDA()
y_pred = lda.fit(X, y, store_covariance=True).predict(X)
splot = plot_data(lda, X, y, y_pred, fig_index=2 * i + 1)
plot_lda_cov(lda, splot)
pl.axis('tight')
# QDA
qda = QDA()
y_pred = qda.fit(X, y, store_covariances=True).predict(X)
splot = plot_data(qda, X, y, y_pred, fig_index=2 * i + 2)
plot_qda_cov(qda, splot)
pl.axis('tight')
pl.suptitle('LDA vs QDA')
pl.show()
|
bsd-3-clause
|
[
624,
199,
5695,
532,
199,
10608,
436,
5843,
350,
19826,
5289,
1408,
827,
867,
21916,
543,
15197,
16028,
29331,
199,
5695,
532,
199,
199,
10711,
314,
15197,
16028,
1152,
1580,
402,
1924,
1021,
436,
14692,
8424,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
504,
7026,
492,
16727,
199,
646,
2680,
465,
980,
199,
646,
19199,
465,
1620,
199,
646,
8027,
465,
22513,
199,
504,
8027,
492,
9229,
199,
199,
504,
6357,
14,
76,
983,
492,
491,
8980,
199,
504,
6357,
14,
81,
983,
492,
1413,
8980,
199,
199,
11490,
199,
3,
30309,
199,
16513,
275,
9229,
14,
10608,
19689,
2509,
4117,
1130,
8,
272,
283,
581,
63,
6304,
63,
2888,
297,
272,
791,
581,
356,
3842,
16,
12,
413,
12,
413,
395,
334,
17,
12,
378,
14,
23,
12,
378,
14,
23,
4360,
1362,
283,
7731,
356,
3842,
16,
12,
378,
14,
23,
12,
378,
14,
23,
395,
334,
17,
12,
378,
14,
23,
12,
378,
14,
23,
4360,
1362,
283,
6304,
356,
3842,
16,
12,
378,
14,
23,
12,
378,
14,
23,
395,
334,
17,
12,
413,
12,
413,
1874,
1552,
199,
1168,
14,
4400,
14,
2683,
63,
16513,
8,
16513,
29,
16513,
9,
421,
199,
11490,
199,
3,
3550,
13148,
199,
318,
4789,
63,
5964,
63,
8695,
837,
272,
1449,
6864,
499,
9647,
17759,
796,
5845,
543,
314,
2011,
13263,
3634,
2344,
272,
302,
12,
8134,
275,
9601,
12,
499,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
445,
275,
980,
14,
1144,
4038,
16,
2020,
446,
16,
14,
1789,
467,
359,
16,
14,
2658,
12,
1275,
1789,
3934,
272,
1323,
275,
980,
14,
82,
9925,
1590,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
395,
1598,
980,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
9,
435,
980,
14,
1144,
779,
17,
12,
413,
12457,
272,
612,
275,
980,
14,
20949,
1332,
1590,
14,
4250,
8,
78,
395,
980,
14,
4548,
8,
78,
1724,
272,
372,
1323,
12,
612,
421,
199,
318,
4789,
63,
8695,
837,
272,
1449,
6864,
499,
9647,
17759,
796,
5845,
543,
3365,
13263,
12627,
2344,
272,
302,
12,
8134,
275,
9601,
12,
499,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
445,
275,
980,
14,
1144,
4038,
16,
2020,
446,
17,
8333,
359,
18,
14,
21,
12,
1275,
23,
3934,
627,
499,
14,
272,
1323,
275,
980,
14,
82,
9925,
1590,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
395,
1598,
980,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
14,
52,
9,
435,
980,
14,
1144,
779,
17,
12,
841,
12457,
272,
612,
275,
980,
14,
20949,
1332,
1590,
14,
4250,
8,
78,
395,
980,
14,
4548,
8,
78,
1724,
272,
372,
1323,
12,
612,
421,
199,
11490,
199,
3,
5137,
3423,
199,
318,
5137,
63,
576,
8,
76,
983,
12,
1323,
12,
612,
12,
612,
63,
5991,
12,
6085,
63,
1080,
304,
272,
2249,
1653,
275,
1620,
14,
13334,
8,
18,
12,
499,
12,
6085,
63,
1080,
9,
272,
340,
6085,
63,
1080,
508,
413,
26,
267,
1620,
14,
1213,
360,
10608,
5289,
1408,
827,
867,
21916,
358,
267,
1620,
14,
13849,
360,
1451,
543,
6317,
13263,
358,
272,
916,
6085,
63,
1080,
508,
499,
26,
267,
1620,
14,
1213,
360,
23053,
19826,
5289,
1408,
827,
867,
21916,
358,
272,
916,
6085,
63,
1080,
508,
650,
26,
267,
1620,
14,
13849,
360,
1451,
543,
17083,
316,
13263,
83,
358,
339,
9253,
275,
334,
89,
508,
612,
63,
5991,
9,
221,
327,
715,
30245,
272,
9253,
16,
12,
9253,
17,
275,
9253,
59,
89,
508,
378,
467,
9253,
59,
89,
508,
413,
61,
272,
1323,
16,
12,
1323,
17,
275,
1323,
59,
89,
508,
378,
467,
1323,
59,
89,
508,
413,
61,
272,
1323,
16,
63,
683,
12,
1323,
16,
63,
3997,
275,
1323,
16,
59,
683,
16,
467,
1323,
16,
19911,
683,
16,
61,
272,
1323,
17,
63,
683,
12,
1323,
17,
63,
3997,
275,
1323,
17,
59,
683,
17,
467,
1323,
17,
19911,
683,
17,
61,
272,
22036,
12,
19906,
275,
1323,
3981,
378,
1055,
827,
1062,
1323,
3981,
378,
1055,
988,
342,
272,
22506,
12,
21023,
275,
1323,
3981,
413,
1055,
827,
1062,
1323,
3981,
413,
1055,
988,
342,
339,
327,
1021,
378,
26,
21185,
272,
1620,
14,
2798,
8,
56,
16,
63,
683,
3981,
378,
467,
1323,
16,
63,
683,
3981,
413,
467,
283,
79,
297,
3164,
534,
581,
358,
272,
1620,
14,
2798,
8,
56,
16,
63,
3997,
3981,
378,
467,
1323,
16,
63,
3997,
3981,
413,
467,
22608,
3164,
26431,
1020,
993,
358,
221,
327,
23531,
8992,
339,
327,
1021,
413,
26,
21185,
272,
1620,
14,
2798,
8,
56,
17,
63,
683,
3981,
378,
467,
1323,
17,
63,
683,
3981,
413,
467,
283,
79,
297,
3164,
534,
6304,
358,
272,
1620,
14,
2798,
8,
56,
17,
63,
3997,
3981,
378,
467,
1323,
17,
63,
3997,
3981,
413,
467,
22608,
3164,
26431,
993,
1020,
358,
221,
327,
23531,
10030,
339,
327,
1021,
378,
436,
413,
520,
787,
305,
272,
8484,
12,
25758,
275,
1926,
12,
2948,
272,
671,
63,
827,
12,
671,
63,
988,
275,
1620,
14,
18512,
342,
272,
612,
63,
827,
12,
612,
63,
988,
275,
1620,
14,
18123,
342,
272,
19379,
12,
20435,
275,
980,
14,
6480,
3825,
8,
1590,
14,
11649,
8,
88,
63,
827,
12,
671,
63,
988,
12,
8484,
395,
586,
980,
14,
11649,
8,
89,
63,
827,
12,
612,
63,
988,
12,
25758,
430,
272,
3107,
275,
634,
983,
14,
6892,
63,
14417,
8,
1590,
14,
67,
9925,
2154,
14,
11186,
1062,
20435,
14,
11186,
9383,
272,
3107,
275,
3107,
3981,
413,
1055,
5217,
8,
2154,
14,
1392,
9,
272,
1620,
14,
80,
2326,
6480,
8,
2154,
12,
20435,
12,
3107,
12,
14920,
534,
581,
63,
6304,
63,
2888,
297,
2116,
6316,
29,
7120,
14,
22580,
8,
16,
2020,
413,
26273,
272,
1620,
14,
17798,
8,
2154,
12,
20435,
12,
3107,
12,
359,
16,
14,
21,
467,
21213,
83,
29,
18,
2020,
9229,
534,
75,
358,
339,
327,
4910,
272,
1620,
14,
2798,
8
] |
[
199,
5695,
532,
199,
10608,
436,
5843,
350,
19826,
5289,
1408,
827,
867,
21916,
543,
15197,
16028,
29331,
199,
5695,
532,
199,
199,
10711,
314,
15197,
16028,
1152,
1580,
402,
1924,
1021,
436,
14692,
8424,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
504,
7026,
492,
16727,
199,
646,
2680,
465,
980,
199,
646,
19199,
465,
1620,
199,
646,
8027,
465,
22513,
199,
504,
8027,
492,
9229,
199,
199,
504,
6357,
14,
76,
983,
492,
491,
8980,
199,
504,
6357,
14,
81,
983,
492,
1413,
8980,
199,
199,
11490,
199,
3,
30309,
199,
16513,
275,
9229,
14,
10608,
19689,
2509,
4117,
1130,
8,
272,
283,
581,
63,
6304,
63,
2888,
297,
272,
791,
581,
356,
3842,
16,
12,
413,
12,
413,
395,
334,
17,
12,
378,
14,
23,
12,
378,
14,
23,
4360,
1362,
283,
7731,
356,
3842,
16,
12,
378,
14,
23,
12,
378,
14,
23,
395,
334,
17,
12,
378,
14,
23,
12,
378,
14,
23,
4360,
1362,
283,
6304,
356,
3842,
16,
12,
378,
14,
23,
12,
378,
14,
23,
395,
334,
17,
12,
413,
12,
413,
1874,
1552,
199,
1168,
14,
4400,
14,
2683,
63,
16513,
8,
16513,
29,
16513,
9,
421,
199,
11490,
199,
3,
3550,
13148,
199,
318,
4789,
63,
5964,
63,
8695,
837,
272,
1449,
6864,
499,
9647,
17759,
796,
5845,
543,
314,
2011,
13263,
3634,
2344,
272,
302,
12,
8134,
275,
9601,
12,
499,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
445,
275,
980,
14,
1144,
4038,
16,
2020,
446,
16,
14,
1789,
467,
359,
16,
14,
2658,
12,
1275,
1789,
3934,
272,
1323,
275,
980,
14,
82,
9925,
1590,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
395,
1598,
980,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
9,
435,
980,
14,
1144,
779,
17,
12,
413,
12457,
272,
612,
275,
980,
14,
20949,
1332,
1590,
14,
4250,
8,
78,
395,
980,
14,
4548,
8,
78,
1724,
272,
372,
1323,
12,
612,
421,
199,
318,
4789,
63,
8695,
837,
272,
1449,
6864,
499,
9647,
17759,
796,
5845,
543,
3365,
13263,
12627,
2344,
272,
302,
12,
8134,
275,
9601,
12,
499,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
445,
275,
980,
14,
1144,
4038,
16,
2020,
446,
17,
8333,
359,
18,
14,
21,
12,
1275,
23,
3934,
627,
499,
14,
272,
1323,
275,
980,
14,
82,
9925,
1590,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
395,
1598,
980,
14,
3287,
8,
1590,
14,
2355,
14,
10843,
8,
78,
12,
8134,
395,
445,
14,
52,
9,
435,
980,
14,
1144,
779,
17,
12,
841,
12457,
272,
612,
275,
980,
14,
20949,
1332,
1590,
14,
4250,
8,
78,
395,
980,
14,
4548,
8,
78,
1724,
272,
372,
1323,
12,
612,
421,
199,
11490,
199,
3,
5137,
3423,
199,
318,
5137,
63,
576,
8,
76,
983,
12,
1323,
12,
612,
12,
612,
63,
5991,
12,
6085,
63,
1080,
304,
272,
2249,
1653,
275,
1620,
14,
13334,
8,
18,
12,
499,
12,
6085,
63,
1080,
9,
272,
340,
6085,
63,
1080,
508,
413,
26,
267,
1620,
14,
1213,
360,
10608,
5289,
1408,
827,
867,
21916,
358,
267,
1620,
14,
13849,
360,
1451,
543,
6317,
13263,
358,
272,
916,
6085,
63,
1080,
508,
499,
26,
267,
1620,
14,
1213,
360,
23053,
19826,
5289,
1408,
827,
867,
21916,
358,
272,
916,
6085,
63,
1080,
508,
650,
26,
267,
1620,
14,
13849,
360,
1451,
543,
17083,
316,
13263,
83,
358,
339,
9253,
275,
334,
89,
508,
612,
63,
5991,
9,
221,
327,
715,
30245,
272,
9253,
16,
12,
9253,
17,
275,
9253,
59,
89,
508,
378,
467,
9253,
59,
89,
508,
413,
61,
272,
1323,
16,
12,
1323,
17,
275,
1323,
59,
89,
508,
378,
467,
1323,
59,
89,
508,
413,
61,
272,
1323,
16,
63,
683,
12,
1323,
16,
63,
3997,
275,
1323,
16,
59,
683,
16,
467,
1323,
16,
19911,
683,
16,
61,
272,
1323,
17,
63,
683,
12,
1323,
17,
63,
3997,
275,
1323,
17,
59,
683,
17,
467,
1323,
17,
19911,
683,
17,
61,
272,
22036,
12,
19906,
275,
1323,
3981,
378,
1055,
827,
1062,
1323,
3981,
378,
1055,
988,
342,
272,
22506,
12,
21023,
275,
1323,
3981,
413,
1055,
827,
1062,
1323,
3981,
413,
1055,
988,
342,
339,
327,
1021,
378,
26,
21185,
272,
1620,
14,
2798,
8,
56,
16,
63,
683,
3981,
378,
467,
1323,
16,
63,
683,
3981,
413,
467,
283,
79,
297,
3164,
534,
581,
358,
272,
1620,
14,
2798,
8,
56,
16,
63,
3997,
3981,
378,
467,
1323,
16,
63,
3997,
3981,
413,
467,
22608,
3164,
26431,
1020,
993,
358,
221,
327,
23531,
8992,
339,
327,
1021,
413,
26,
21185,
272,
1620,
14,
2798,
8,
56,
17,
63,
683,
3981,
378,
467,
1323,
17,
63,
683,
3981,
413,
467,
283,
79,
297,
3164,
534,
6304,
358,
272,
1620,
14,
2798,
8,
56,
17,
63,
3997,
3981,
378,
467,
1323,
17,
63,
3997,
3981,
413,
467,
22608,
3164,
26431,
993,
1020,
358,
221,
327,
23531,
10030,
339,
327,
1021,
378,
436,
413,
520,
787,
305,
272,
8484,
12,
25758,
275,
1926,
12,
2948,
272,
671,
63,
827,
12,
671,
63,
988,
275,
1620,
14,
18512,
342,
272,
612,
63,
827,
12,
612,
63,
988,
275,
1620,
14,
18123,
342,
272,
19379,
12,
20435,
275,
980,
14,
6480,
3825,
8,
1590,
14,
11649,
8,
88,
63,
827,
12,
671,
63,
988,
12,
8484,
395,
586,
980,
14,
11649,
8,
89,
63,
827,
12,
612,
63,
988,
12,
25758,
430,
272,
3107,
275,
634,
983,
14,
6892,
63,
14417,
8,
1590,
14,
67,
9925,
2154,
14,
11186,
1062,
20435,
14,
11186,
9383,
272,
3107,
275,
3107,
3981,
413,
1055,
5217,
8,
2154,
14,
1392,
9,
272,
1620,
14,
80,
2326,
6480,
8,
2154,
12,
20435,
12,
3107,
12,
14920,
534,
581,
63,
6304,
63,
2888,
297,
2116,
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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
] |
lparsons/tools-iuc
|
tool_collections/snpeff/gbk2fa.py
|
21
|
1634
|
import argparse
import bz2
import contextlib
import gzip
import sys
import magic
from Bio import SeqIO
parser = argparse.ArgumentParser()
parser.add_argument("genbank_file", help="GenBank input file. Can be compressed with gzip or bzip2")
parser.add_argument("fasta_file", help="FASTA output datset")
parser.add_argument("--remove_version", dest="remove_version", action="store_true", help="Remove version number from NCBI form formatted accession numbers. For example, this would convert 'B000657.2' to 'B000657'")
args = parser.parse_args()
gbk_filename = args.genbank_file
fa_filename = args.fasta_file
@contextlib.contextmanager
def get_file_handle(gbk_filename):
f_type = magic.from_file(args.genbank_file, mime=True)
if f_type == 'text/plain':
input_handle = open(gbk_filename, "r")
elif f_type == 'application/gzip' or f_type == 'application/x-gzip':
input_handle = gzip.open(gbk_filename, "rt")
elif f_type == 'application/x-bzip2':
input_handle = bz2.open(gbk_filename, "rt")
else:
sys.exit("Cannot process file of type {}. Only plain, gzip'ed, and bzip2'ed genbank files are accepted ".format(f_type))
yield input_handle
input_handle.close()
with get_file_handle(gbk_filename) as input_handle, open(fa_filename, "w") as output_handle:
for seq_record in SeqIO.parse(input_handle, "genbank"):
if args.remove_version:
seq_id = seq_record.id.split('.')[0]
else:
seq_id = seq_record.id
print('Writing FASTA record: {}'.format( seq_id ))
output_handle.write(">{}\n{}\n".format(seq_id, seq_record.seq))
|
mit
|
[
646,
7534,
199,
646,
15055,
18,
199,
646,
15502,
199,
646,
11756,
199,
646,
984,
199,
199,
646,
10628,
199,
504,
699,
2308,
492,
28534,
2090,
199,
199,
2087,
275,
7534,
14,
10730,
342,
199,
2087,
14,
525,
63,
2094,
480,
2268,
9860,
63,
493,
401,
1720,
628,
8168,
14814,
1324,
570,
14,
6855,
506,
12335,
543,
11756,
503,
330,
3065,
18,
531,
199,
2087,
14,
525,
63,
2094,
480,
20309,
63,
493,
401,
1720,
628,
24661,
33,
1072,
6394,
409,
531,
199,
2087,
14,
525,
63,
2094,
6739,
2168,
63,
1023,
401,
2053,
628,
2168,
63,
1023,
401,
1595,
628,
1617,
63,
2052,
401,
1720,
628,
5587,
1015,
1329,
687,
653,
9956,
41,
1824,
7871,
1066,
823,
438,
5579,
14,
2104,
2893,
12,
642,
3955,
3957,
283,
34,
20965,
1641,
14,
18,
7,
370,
283,
34,
20965,
1641,
9859,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
4908,
75,
63,
1501,
275,
1249,
14,
2268,
9860,
63,
493,
199,
667,
63,
1501,
275,
1249,
14,
20309,
63,
493,
421,
199,
32,
23464,
14,
14237,
199,
318,
664,
63,
493,
63,
2479,
8,
4908,
75,
63,
1501,
304,
272,
289,
63,
466,
275,
10628,
14,
504,
63,
493,
8,
589,
14,
2268,
9860,
63,
493,
12,
6660,
29,
549,
9,
272,
340,
289,
63,
466,
508,
283,
505,
15,
6104,
356,
267,
1324,
63,
2479,
275,
1551,
8,
4908,
75,
63,
1501,
12,
298,
82,
531,
272,
916,
289,
63,
466,
508,
283,
3578,
15,
12256,
7,
503,
289,
63,
466,
508,
283,
3578,
15,
88,
13,
12256,
356,
267,
1324,
63,
2479,
275,
11756,
14,
1490,
8,
4908,
75,
63,
1501,
12,
298,
2591,
531,
272,
916,
289,
63,
466,
508,
283,
3578,
15,
88,
13,
66,
3065,
18,
356,
267,
1324,
63,
2479,
275,
15055,
18,
14,
1490,
8,
4908,
75,
63,
1501,
12,
298,
2591,
531,
272,
587,
26,
267,
984,
14,
2224,
480,
6612,
2112,
570,
402,
730,
30332,
5972,
8971,
12,
11756,
7,
379,
12,
436,
330,
3065,
18,
7,
379,
3805,
9860,
1584,
787,
10226,
3680,
908,
8,
70,
63,
466,
430,
272,
1995,
1324,
63,
2479,
272,
1324,
63,
2479,
14,
1600,
342,
421,
199,
1045,
664,
63,
493,
63,
2479,
8,
4908,
75,
63,
1501,
9,
465,
1324,
63,
2479,
12,
1551,
8,
667,
63,
1501,
12,
298,
87,
531,
465,
1072,
63,
2479,
26,
339,
367,
5412,
63,
3059,
315,
28534,
2090,
14,
1122,
8,
1210,
63,
2479,
12,
298,
2268,
9860,
2349,
267,
340,
1249,
14,
2168,
63,
1023,
26,
288,
5412,
63,
344,
275,
5412,
63,
3059,
14,
344,
14,
1294,
19237,
16,
61,
267,
587,
26,
288,
5412,
63,
344,
275,
5412,
63,
3059,
14,
344,
267,
870,
360,
16646,
481,
11307,
33,
2777,
26,
9499,
908,
8,
5412,
63,
344,
5082,
267,
1072,
63,
2479,
14,
952,
19651,
24423,
78,
24423,
78,
1674,
908,
8,
3610,
63,
344,
12,
5412,
63,
3059,
14,
3610,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7534,
199,
646,
15055,
18,
199,
646,
15502,
199,
646,
11756,
199,
646,
984,
199,
199,
646,
10628,
199,
504,
699,
2308,
492,
28534,
2090,
199,
199,
2087,
275,
7534,
14,
10730,
342,
199,
2087,
14,
525,
63,
2094,
480,
2268,
9860,
63,
493,
401,
1720,
628,
8168,
14814,
1324,
570,
14,
6855,
506,
12335,
543,
11756,
503,
330,
3065,
18,
531,
199,
2087,
14,
525,
63,
2094,
480,
20309,
63,
493,
401,
1720,
628,
24661,
33,
1072,
6394,
409,
531,
199,
2087,
14,
525,
63,
2094,
6739,
2168,
63,
1023,
401,
2053,
628,
2168,
63,
1023,
401,
1595,
628,
1617,
63,
2052,
401,
1720,
628,
5587,
1015,
1329,
687,
653,
9956,
41,
1824,
7871,
1066,
823,
438,
5579,
14,
2104,
2893,
12,
642,
3955,
3957,
283,
34,
20965,
1641,
14,
18,
7,
370,
283,
34,
20965,
1641,
9859,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
4908,
75,
63,
1501,
275,
1249,
14,
2268,
9860,
63,
493,
199,
667,
63,
1501,
275,
1249,
14,
20309,
63,
493,
421,
199,
32,
23464,
14,
14237,
199,
318,
664,
63,
493,
63,
2479,
8,
4908,
75,
63,
1501,
304,
272,
289,
63,
466,
275,
10628,
14,
504,
63,
493,
8,
589,
14,
2268,
9860,
63,
493,
12,
6660,
29,
549,
9,
272,
340,
289,
63,
466,
508,
283,
505,
15,
6104,
356,
267,
1324,
63,
2479,
275,
1551,
8,
4908,
75,
63,
1501,
12,
298,
82,
531,
272,
916,
289,
63,
466,
508,
283,
3578,
15,
12256,
7,
503,
289,
63,
466,
508,
283,
3578,
15,
88,
13,
12256,
356,
267,
1324,
63,
2479,
275,
11756,
14,
1490,
8,
4908,
75,
63,
1501,
12,
298,
2591,
531,
272,
916,
289,
63,
466,
508,
283,
3578,
15,
88,
13,
66,
3065,
18,
356,
267,
1324,
63,
2479,
275,
15055,
18,
14,
1490,
8,
4908,
75,
63,
1501,
12,
298,
2591,
531,
272,
587,
26,
267,
984,
14,
2224,
480,
6612,
2112,
570,
402,
730,
30332,
5972,
8971,
12,
11756,
7,
379,
12,
436,
330,
3065,
18,
7,
379,
3805,
9860,
1584,
787,
10226,
3680,
908,
8,
70,
63,
466,
430,
272,
1995,
1324,
63,
2479,
272,
1324,
63,
2479,
14,
1600,
342,
421,
199,
1045,
664,
63,
493,
63,
2479,
8,
4908,
75,
63,
1501,
9,
465,
1324,
63,
2479,
12,
1551,
8,
667,
63,
1501,
12,
298,
87,
531,
465,
1072,
63,
2479,
26,
339,
367,
5412,
63,
3059,
315,
28534,
2090,
14,
1122,
8,
1210,
63,
2479,
12,
298,
2268,
9860,
2349,
267,
340,
1249,
14,
2168,
63,
1023,
26,
288,
5412,
63,
344,
275,
5412,
63,
3059,
14,
344,
14,
1294,
19237,
16,
61,
267,
587,
26,
288,
5412,
63,
344,
275,
5412,
63,
3059,
14,
344,
267,
870,
360,
16646,
481,
11307,
33,
2777,
26,
9499,
908,
8,
5412,
63,
344,
5082,
267,
1072,
63,
2479,
14,
952,
19651,
24423,
78,
24423,
78,
1674,
908,
8,
3610,
63,
344,
12,
5412,
63,
3059,
14,
3610,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JVillella/tensorflow
|
tensorflow/contrib/distributions/__init__.py
|
9
|
6007
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Classes representing statistical distributions and ops for working with them.
See the @{$python/contrib.distributions} guide.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# pylint: disable=unused-import,wildcard-import,line-too-long,g-importing-member
from tensorflow.contrib.distributions.python.ops import bijectors
from tensorflow.contrib.distributions.python.ops.binomial import *
from tensorflow.contrib.distributions.python.ops.chi2 import *
from tensorflow.contrib.distributions.python.ops.conditional_distribution import *
from tensorflow.contrib.distributions.python.ops.conditional_transformed_distribution import *
from tensorflow.contrib.distributions.python.ops.deterministic import *
from tensorflow.contrib.distributions.python.ops.distribution_util import matrix_diag_transform
from tensorflow.contrib.distributions.python.ops.distribution_util import softplus_inverse
from tensorflow.contrib.distributions.python.ops.geometric import *
from tensorflow.contrib.distributions.python.ops.inverse_gamma import *
from tensorflow.contrib.distributions.python.ops.logistic import *
from tensorflow.contrib.distributions.python.ops.mixture import *
from tensorflow.contrib.distributions.python.ops.mvn_diag import *
from tensorflow.contrib.distributions.python.ops.mvn_diag_plus_low_rank import *
from tensorflow.contrib.distributions.python.ops.mvn_full_covariance import *
from tensorflow.contrib.distributions.python.ops.mvn_tril import *
from tensorflow.contrib.distributions.python.ops.negative_binomial import *
from tensorflow.contrib.distributions.python.ops.normal_conjugate_posteriors import *
from tensorflow.contrib.distributions.python.ops.onehot_categorical import *
from tensorflow.contrib.distributions.python.ops.poisson import *
from tensorflow.contrib.distributions.python.ops.quantized_distribution import *
from tensorflow.contrib.distributions.python.ops.relaxed_bernoulli import *
from tensorflow.contrib.distributions.python.ops.relaxed_onehot_categorical import *
from tensorflow.contrib.distributions.python.ops.sample_stats import *
from tensorflow.contrib.distributions.python.ops.vector_exponential_diag import *
from tensorflow.contrib.distributions.python.ops.vector_laplace_diag import *
from tensorflow.contrib.distributions.python.ops.wishart import *
from tensorflow.python.ops.distributions.bernoulli import *
from tensorflow.python.ops.distributions.beta import *
from tensorflow.python.ops.distributions.categorical import *
from tensorflow.python.ops.distributions.dirichlet import *
from tensorflow.python.ops.distributions.dirichlet_multinomial import *
from tensorflow.python.ops.distributions.distribution import *
from tensorflow.python.ops.distributions.exponential import *
from tensorflow.python.ops.distributions.gamma import *
from tensorflow.python.ops.distributions.kullback_leibler import *
from tensorflow.python.ops.distributions.laplace import *
from tensorflow.python.ops.distributions.multinomial import *
from tensorflow.python.ops.distributions.normal import *
from tensorflow.python.ops.distributions.student_t import *
from tensorflow.python.ops.distributions.transformed_distribution import *
from tensorflow.python.ops.distributions.uniform import *
# pylint: enable=unused-import,wildcard-import,line-too-long,g-importing-member
from tensorflow.python.util.all_util import remove_undocumented
_allowed_symbols = [
'bijectors',
'ConditionalDistribution',
'ConditionalTransformedDistribution',
'FULLY_REPARAMETERIZED',
'NOT_REPARAMETERIZED',
'Affine',
'AffineLinearOperator',
'Bijector',
'Chain',
'CholeskyOuterProduct',
'Exp',
'Identity',
'Inline',
'Invert',
'PowerTransform',
'SigmoidCentered',
'SoftmaxCentered',
'Softplus',
'ReparameterizationType',
'Distribution',
'Binomial',
'Bernoulli',
'BernoulliWithSigmoidProbs',
'Beta',
'BetaWithSoftplusConcentration',
'Categorical',
'Chi2',
'Chi2WithAbsDf',
'Deterministic',
'VectorDeterministic',
'Exponential',
'ExponentialWithSoftplusRate',
'VectorExponentialDiag',
'Gamma',
'GammaWithSoftplusConcentrationRate',
'Geometric',
'InverseGamma',
'InverseGammaWithSoftplusConcentrationRate',
'Laplace',
'LaplaceWithSoftplusScale',
'Logistic',
'NegativeBinomial',
'Normal',
'NormalWithSoftplusScale',
'Poisson',
'StudentT',
'StudentTWithAbsDfSoftplusScale',
'Uniform',
'MultivariateNormalDiag',
'MultivariateNormalFullCovariance',
'MultivariateNormalTriL',
'MultivariateNormalDiagPlusLowRank',
'MultivariateNormalDiagWithSoftplusScale',
'Dirichlet',
'DirichletMultinomial',
'Multinomial',
'VectorLaplaceDiag',
'WishartCholesky',
'WishartFull',
'TransformedDistribution',
'QuantizedDistribution',
'Mixture',
'ExpRelaxedOneHotCategorical',
'OneHotCategorical',
'RelaxedBernoulli',
'RelaxedOneHotCategorical',
'kl_divergence',
'RegisterKL',
'matrix_diag_transform',
'normal_conjugates_known_scale_posterior',
'normal_conjugates_known_scale_predictive',
'softplus_inverse',
'percentile'
]
remove_undocumented(__name__, _allowed_symbols)
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
15711,
6144,
8753,
270,
2652,
10208,
436,
4156,
367,
6449,
543,
3062,
14,
199,
199,
9295,
314,
768,
91,
4,
1548,
15,
2828,
14,
5613,
93,
22885,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
12,
16692,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
199,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
12111,
963,
1384,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
27578,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
13175,
18,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
14353,
63,
4972,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
14353,
63,
20209,
63,
4972,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
30709,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4972,
63,
1974,
492,
3634,
63,
6706,
63,
4711,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4972,
63,
1974,
492,
880,
8915,
24879,
63,
11668,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
31509,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
11668,
63,
7325,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
23452,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
2664,
4167,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
6706,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
6706,
63,
6666,
63,
674,
63,
4648,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
2861,
63,
15024,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
32135,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
7371,
63,
27578,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
3302,
63,
26000,
63,
27706,
322,
1384,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
368,
8885,
63,
16810,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
29606,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
12316,
7068,
63,
4972,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
17060,
7887,
63,
605,
24992,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
17060,
7887,
63,
368,
8885,
63,
16810,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
3271,
63,
3200,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4106,
63,
27093,
63,
6706,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4106,
63,
416,
2778,
63,
6706,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
87,
2453,
580,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
605,
24992,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
5683,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
16810,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
328,
19683,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
328,
19683,
63,
28265,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
4972,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
27093,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
7325,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
75,
979,
894,
63,
274,
7247,
82,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
416,
2778,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
28265,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
3302,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
5500,
63,
84,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
20209,
63,
4972,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
8830,
492,
627,
199,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
12,
16692,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
199,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
2813,
63,
30107,
12546,
199,
199,
63,
6541,
63,
7450,
275,
359,
272,
283,
4492,
963,
1384,
297,
272,
283,
21321,
8580,
297,
272,
283,
21321,
3188,
6194,
8580,
297,
272,
283,
14742,
57,
63,
907,
14472,
18732,
297,
272,
283,
4609,
63,
907,
14472,
18732,
297,
272,
283,
19256,
1132,
297,
272,
283,
19256,
1132,
26463,
297,
272
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
15711,
6144,
8753,
270,
2652,
10208,
436,
4156,
367,
6449,
543,
3062,
14,
199,
199,
9295,
314,
768,
91,
4,
1548,
15,
2828,
14,
5613,
93,
22885,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
12,
16692,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
199,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
12111,
963,
1384,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
27578,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
13175,
18,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
14353,
63,
4972,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
14353,
63,
20209,
63,
4972,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
30709,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4972,
63,
1974,
492,
3634,
63,
6706,
63,
4711,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4972,
63,
1974,
492,
880,
8915,
24879,
63,
11668,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
31509,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
11668,
63,
7325,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
23452,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
2664,
4167,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
6706,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
6706,
63,
6666,
63,
674,
63,
4648,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
2861,
63,
15024,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
77,
6002,
63,
32135,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
7371,
63,
27578,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
3302,
63,
26000,
63,
27706,
322,
1384,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
368,
8885,
63,
16810,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
29606,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
12316,
7068,
63,
4972,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
17060,
7887,
63,
605,
24992,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
17060,
7887,
63,
368,
8885,
63,
16810,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
3271,
63,
3200,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4106,
63,
27093,
63,
6706,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4106,
63,
416,
2778,
63,
6706,
492,
627,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
87,
2453,
580,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
605,
24992,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
5683,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
16810,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
328,
19683,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
328,
19683,
63,
28265,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
4972,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
27093,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
7325,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
75,
979,
894,
63,
274,
7247,
82,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
416,
2778,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
28265,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
3302,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
5500,
63,
84,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
20209,
63,
4972,
492,
627,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
8830,
492,
627,
199,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
12,
16692,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
199,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
2813,
63,
30107,
12546,
199,
199,
63,
6541,
63,
7450,
275,
359,
272,
283,
4492,
963,
1384,
297,
272,
283,
21321,
8580,
297,
272,
283,
21321,
3188,
6194,
8580,
297,
272,
283,
14742,
57,
63,
907,
14472,
18732,
297,
272,
283,
4609,
63,
907,
14472,
18732,
297,
272,
283,
19256,
1132,
297,
272,
283,
19256,
1132,
26463,
297,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
jacksonicson/paper.IS2015
|
control/Control/src/virtual/util.py
|
1
|
2155
|
import conf_nodes
import libvirt
# Established connections
connections = {}
def connect(node):
# Check if connection exists
if node in connections:
return connections[node]
try:
print 'connecting with %s' % node
conn_str = "qemu+ssh://root@%s/system" % (node)
print 'connecting with %s' % (conn_str)
conn = libvirt.open(conn_str)
# Add connection to list
connections[node] = conn
return conn
except:
print 'failed connecting with node %s' % node
return None
def get_hostname(connection):
for name in connections:
if connections[name] == connection:
return name
return None
def connect_all():
print 'Connecting with all libvirt services...'
for node in conf_nodes.NODES:
connect(node)
def close_all():
print 'Closing libvirtd connections...'
for connection in connections.values():
connection.close()
def find_domain(domain_name):
last = None, None
for lv_connection in connections.values():
try:
# Check if domain is running on current connection
lv_domain = lv_connection.lookupByName(domain_name)
# Last valid entry
last = lv_domain, lv_connection
# Check if domain is active and return it if so
state = lv_domain.state(0)[0]
if state == 1:
return lv_domain, lv_connection
except:
pass
# Return last known position of domain
return last
def shutdownall():
# Go over all nodes
for host in conf_nodes.NODES:
# Go over all domains on the node
lv_connection = connections[host]
lv_ids = lv_connection.listDomainsID()
for lv_domain_id in lv_ids:
# Get domain for ID
domain = lv_connection.lookupByID(lv_domain_id)
# Shutdown domain
print ' Shutting down: %s' % (domain.name())
domain.destroy()
# Connect with all servers
connect_all()
|
mit
|
[
646,
3743,
63,
2415,
199,
646,
13108,
199,
199,
3,
15896,
13306,
379,
6947,
199,
7995,
275,
1052,
199,
199,
318,
4907,
8,
932,
304,
272,
327,
2670,
340,
1950,
3495,
272,
340,
1031,
315,
6947,
26,
267,
372,
6947,
59,
932,
61,
2286,
862,
26,
267,
870,
283,
2242,
316,
543,
450,
83,
7,
450,
1031,
267,
2557,
63,
495,
275,
298,
19839,
11,
5510,
921,
1231,
19437,
83,
15,
2253,
2,
450,
334,
932,
9,
2728,
870,
283,
2242,
316,
543,
450,
83,
7,
450,
334,
1631,
63,
495,
9,
267,
2557,
275,
13108,
14,
1490,
8,
1631,
63,
495,
9,
2728,
327,
2654,
1950,
370,
769,
267,
6947,
59,
932,
61,
275,
2557,
267,
372,
2557,
272,
871,
26,
267,
870,
283,
4892,
18170,
543,
1031,
450,
83,
7,
450,
1031,
267,
372,
488,
421,
199,
318,
664,
63,
4269,
8,
2105,
304,
272,
367,
536,
315,
6947,
26,
267,
340,
6947,
59,
354,
61,
508,
1950,
26,
288,
372,
536,
272,
372,
488,
221,
421,
199,
318,
4907,
63,
452,
837,
272,
870,
283,
32000,
543,
1006,
13108,
8500,
13698,
272,
367,
1031,
315,
3743,
63,
2415,
14,
2826,
4448,
26,
267,
4907,
8,
932,
9,
221,
421,
199,
318,
4002,
63,
452,
837,
272,
870,
283,
18433,
1973,
1042,
2076,
6947,
13698,
272,
367,
1950,
315,
6947,
14,
1459,
837,
267,
1950,
14,
1600,
342,
26339,
199,
318,
2342,
63,
2261,
8,
2261,
63,
354,
304,
272,
2061,
275,
488,
12,
488,
272,
367,
20604,
63,
2105,
315,
6947,
14,
1459,
837,
267,
862,
26,
288,
327,
2670,
340,
2881,
365,
3879,
641,
1453,
1950,
288,
20604,
63,
2261,
275,
20604,
63,
2105,
14,
3892,
11190,
8,
2261,
63,
354,
9,
7846,
327,
15237,
1686,
2397,
288,
2061,
275,
20604,
63,
2261,
12,
20604,
63,
2105,
7846,
327,
2670,
340,
2881,
365,
4702,
436,
372,
652,
340,
880,
288,
1174,
275,
20604,
63,
2261,
14,
929,
8,
16,
2788,
16,
61,
288,
340,
1174,
508,
413,
26,
355,
372,
20604,
63,
2261,
12,
20604,
63,
2105,
267,
871,
26,
288,
986,
5493,
327,
1432,
2061,
6040,
3421,
402,
2881,
272,
372,
2061,
26339,
199,
318,
12842,
452,
837,
272,
327,
3971,
1806,
1006,
3380,
272,
367,
1591,
315,
3743,
63,
2415,
14,
2826,
4448,
26,
267,
327,
3971,
1806,
1006,
14006,
641,
314,
1031,
4960,
20604,
63,
2105,
275,
6947,
59,
1102,
61,
267,
20604,
63,
1580,
275,
20604,
63,
2105,
14,
513,
7705,
83,
998,
342,
267,
367,
20604,
63,
2261,
63,
344,
315,
20604,
63,
1580,
26,
288,
327,
2372,
2881,
367,
2870,
7205,
2881,
275,
20604,
63,
2105,
14,
3892,
2175,
998,
8,
6371,
63,
2261,
63,
344,
9,
7846,
327,
5244,
6159,
2881,
288,
870,
283,
257,
5244,
337,
1337,
3224,
26,
450,
83,
7,
450,
334,
2261,
14,
354,
1012,
288,
2881,
14,
7237,
342,
26339,
199,
3,
15175,
543,
1006,
8037,
199,
2242,
63,
452,
342,
258,
1362,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3743,
63,
2415,
199,
646,
13108,
199,
199,
3,
15896,
13306,
379,
6947,
199,
7995,
275,
1052,
199,
199,
318,
4907,
8,
932,
304,
272,
327,
2670,
340,
1950,
3495,
272,
340,
1031,
315,
6947,
26,
267,
372,
6947,
59,
932,
61,
2286,
862,
26,
267,
870,
283,
2242,
316,
543,
450,
83,
7,
450,
1031,
267,
2557,
63,
495,
275,
298,
19839,
11,
5510,
921,
1231,
19437,
83,
15,
2253,
2,
450,
334,
932,
9,
2728,
870,
283,
2242,
316,
543,
450,
83,
7,
450,
334,
1631,
63,
495,
9,
267,
2557,
275,
13108,
14,
1490,
8,
1631,
63,
495,
9,
2728,
327,
2654,
1950,
370,
769,
267,
6947,
59,
932,
61,
275,
2557,
267,
372,
2557,
272,
871,
26,
267,
870,
283,
4892,
18170,
543,
1031,
450,
83,
7,
450,
1031,
267,
372,
488,
421,
199,
318,
664,
63,
4269,
8,
2105,
304,
272,
367,
536,
315,
6947,
26,
267,
340,
6947,
59,
354,
61,
508,
1950,
26,
288,
372,
536,
272,
372,
488,
221,
421,
199,
318,
4907,
63,
452,
837,
272,
870,
283,
32000,
543,
1006,
13108,
8500,
13698,
272,
367,
1031,
315,
3743,
63,
2415,
14,
2826,
4448,
26,
267,
4907,
8,
932,
9,
221,
421,
199,
318,
4002,
63,
452,
837,
272,
870,
283,
18433,
1973,
1042,
2076,
6947,
13698,
272,
367,
1950,
315,
6947,
14,
1459,
837,
267,
1950,
14,
1600,
342,
26339,
199,
318,
2342,
63,
2261,
8,
2261,
63,
354,
304,
272,
2061,
275,
488,
12,
488,
272,
367,
20604,
63,
2105,
315,
6947,
14,
1459,
837,
267,
862,
26,
288,
327,
2670,
340,
2881,
365,
3879,
641,
1453,
1950,
288,
20604,
63,
2261,
275,
20604,
63,
2105,
14,
3892,
11190,
8,
2261,
63,
354,
9,
7846,
327,
15237,
1686,
2397,
288,
2061,
275,
20604,
63,
2261,
12,
20604,
63,
2105,
7846,
327,
2670,
340,
2881,
365,
4702,
436,
372,
652,
340,
880,
288,
1174,
275,
20604,
63,
2261,
14,
929,
8,
16,
2788,
16,
61,
288,
340,
1174,
508,
413,
26,
355,
372,
20604,
63,
2261,
12,
20604,
63,
2105,
267,
871,
26,
288,
986,
5493,
327,
1432,
2061,
6040,
3421,
402,
2881,
272,
372,
2061,
26339,
199,
318,
12842,
452,
837,
272,
327,
3971,
1806,
1006,
3380,
272,
367,
1591,
315,
3743,
63,
2415,
14,
2826,
4448,
26,
267,
327,
3971,
1806,
1006,
14006,
641,
314,
1031,
4960,
20604,
63,
2105,
275,
6947,
59,
1102,
61,
267,
20604,
63,
1580,
275,
20604,
63,
2105,
14,
513,
7705,
83,
998,
342,
267,
367,
20604,
63,
2261,
63,
344,
315,
20604,
63,
1580,
26,
288,
327,
2372,
2881,
367,
2870,
7205,
2881,
275,
20604,
63,
2105,
14,
3892,
2175,
998,
8,
6371,
63,
2261,
63,
344,
9,
7846,
327,
5244,
6159,
2881,
288,
870,
283,
257,
5244,
337,
1337,
3224,
26,
450,
83,
7,
450,
334,
2261,
14,
354,
1012,
288,
2881,
14,
7237,
342,
26339,
199,
3,
15175,
543,
1006,
8037,
199,
2242,
63,
452,
342,
258,
1362,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Jorge-Rodriguez/ansible
|
lib/ansible/plugins/doc_fragments/opennebula.py
|
33
|
1345
|
# -*- coding: utf-8 -*-
#
# Copyright 2018 www.privaz.io Valletech AB
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
class ModuleDocFragment(object):
# OpenNebula common documentation
DOCUMENTATION = '''
options:
api_url:
description:
- The ENDPOINT URL of the XMLRPC server.
If not specified then the value of the ONE_URL environment variable, if any, is used.
aliases:
- api_endpoint
api_username:
description:
- The name of the user for XMLRPC authentication.
If not specified then the value of the ONE_USERNAME environment variable, if any, is used.
api_password:
description:
- The password or token for XMLRPC authentication.
If not specified then the value of the ONE_PASSWORD environment variable, if any, is used.
aliases:
- api_token
validate_certs:
description:
- Whether to validate the SSL certificates or not.
This parameter is ignored if PYTHONHTTPSVERIFY environment variable is used.
type: bool
default: true
wait_timeout:
description:
- time to wait for the desired state to be reached before timeout, in seconds.
default: 300
'''
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
14894,
20732,
14,
1359,
3042,
90,
14,
2308,
26263,
1268,
335,
14840,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
272,
327,
3232,
46,
2871,
7586,
2863,
3794,
272,
29970,
2594,
275,
1449,
199,
1419,
26,
272,
2986,
63,
633,
26,
267,
1369,
26,
288,
446,
710,
7729,
7217,
2851,
402,
314,
4692,
8171,
1654,
14,
1598,
982,
440,
2013,
2066,
314,
574,
402,
314,
13051,
63,
2632,
3734,
1750,
12,
340,
1263,
12,
365,
1202,
14,
267,
5481,
26,
288,
446,
2986,
63,
6520,
272,
2986,
63,
2473,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
922,
367,
4692,
8171,
6299,
14,
1598,
982,
440,
2013,
2066,
314,
574,
402,
314,
13051,
63,
11958,
3734,
1750,
12,
340,
1263,
12,
365,
1202,
14,
272,
2986,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
2505,
503,
1526,
367,
4692,
8171,
6299,
14,
1598,
982,
440,
2013,
2066,
314,
574,
402,
314,
13051,
63,
9032,
3734,
1750,
12,
340,
1263,
12,
365,
1202,
14,
267,
5481,
26,
288,
446,
2986,
63,
1418,
272,
4107,
63,
8356,
26,
267,
1369,
26,
288,
446,
7480,
370,
4107,
314,
7799,
14512,
503,
440,
14,
1598,
961,
2725,
365,
5525,
340,
18280,
14921,
22443,
3734,
1750,
365,
1202,
14,
267,
730,
26,
2155,
267,
849,
26,
2549,
272,
3618,
63,
2593,
26,
267,
1369,
26,
288,
446,
900,
370,
3618,
367,
314,
6387,
1174,
370,
506,
13075,
2544,
2653,
12,
315,
4696,
14,
267,
849,
26,
9601,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
14894,
20732,
14,
1359,
3042,
90,
14,
2308,
26263,
1268,
335,
14840,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
272,
327,
3232,
46,
2871,
7586,
2863,
3794,
272,
29970,
2594,
275,
1449,
199,
1419,
26,
272,
2986,
63,
633,
26,
267,
1369,
26,
288,
446,
710,
7729,
7217,
2851,
402,
314,
4692,
8171,
1654,
14,
1598,
982,
440,
2013,
2066,
314,
574,
402,
314,
13051,
63,
2632,
3734,
1750,
12,
340,
1263,
12,
365,
1202,
14,
267,
5481,
26,
288,
446,
2986,
63,
6520,
272,
2986,
63,
2473,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
922,
367,
4692,
8171,
6299,
14,
1598,
982,
440,
2013,
2066,
314,
574,
402,
314,
13051,
63,
11958,
3734,
1750,
12,
340,
1263,
12,
365,
1202,
14,
272,
2986,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
2505,
503,
1526,
367,
4692,
8171,
6299,
14,
1598,
982,
440,
2013,
2066,
314,
574,
402,
314,
13051,
63,
9032,
3734,
1750,
12,
340,
1263,
12,
365,
1202,
14,
267,
5481,
26,
288,
446,
2986,
63,
1418,
272,
4107,
63,
8356,
26,
267,
1369,
26,
288,
446,
7480,
370,
4107,
314,
7799,
14512,
503,
440,
14,
1598,
961,
2725,
365,
5525,
340,
18280,
14921,
22443,
3734,
1750,
365,
1202,
14,
267,
730,
26,
2155,
267,
849,
26,
2549,
272,
3618,
63,
2593,
26,
267,
1369,
26,
288,
446,
900,
370,
3618,
367,
314,
6387,
1174,
370,
506,
13075,
2544,
2653,
12,
315,
4696,
14,
267,
849,
26,
9601,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rmcgibbo/numpy
|
numpy/core/tests/test_datetime.py
|
38
|
85016
|
from __future__ import division, absolute_import, print_function
import os, pickle
import numpy
import numpy as np
from numpy.testing import *
from numpy.compat import asbytes
import datetime
# Use pytz to test out various time zones if available
try:
from pytz import timezone as tz
_has_pytz = True
except ImportError:
_has_pytz = False
class TestDateTime(TestCase):
def test_datetime_dtype_creation(self):
for unit in ['Y', 'M', 'W', 'D',
'h', 'm', 's', 'ms', 'us',
'ns', 'ps', 'fs', 'as']:
dt1 = np.dtype('M8[750%s]'%unit)
assert_(dt1 == np.dtype('datetime64[750%s]' % unit))
dt2 = np.dtype('m8[%s]' % unit)
assert_(dt2 == np.dtype('timedelta64[%s]' % unit))
# Generic units shouldn't add [] to the end
assert_equal(str(np.dtype("M8")), "datetime64")
# Should be possible to specify the endianness
assert_equal(np.dtype("=M8"), np.dtype("M8"))
assert_equal(np.dtype("=M8[s]"), np.dtype("M8[s]"))
assert_(np.dtype(">M8") == np.dtype("M8") or
np.dtype("<M8") == np.dtype("M8"))
assert_(np.dtype(">M8[D]") == np.dtype("M8[D]") or
np.dtype("<M8[D]") == np.dtype("M8[D]"))
assert_(np.dtype(">M8") != np.dtype("<M8"))
assert_equal(np.dtype("=m8"), np.dtype("m8"))
assert_equal(np.dtype("=m8[s]"), np.dtype("m8[s]"))
assert_(np.dtype(">m8") == np.dtype("m8") or
np.dtype("<m8") == np.dtype("m8"))
assert_(np.dtype(">m8[D]") == np.dtype("m8[D]") or
np.dtype("<m8[D]") == np.dtype("m8[D]"))
assert_(np.dtype(">m8") != np.dtype("<m8"))
# Check that the parser rejects bad datetime types
assert_raises(TypeError, np.dtype, 'M8[badunit]')
assert_raises(TypeError, np.dtype, 'm8[badunit]')
assert_raises(TypeError, np.dtype, 'M8[YY]')
assert_raises(TypeError, np.dtype, 'm8[YY]')
assert_warns(DeprecationWarning, np.dtype, 'm4')
assert_warns(DeprecationWarning, np.dtype, 'M7')
assert_warns(DeprecationWarning, np.dtype, 'm7')
assert_warns(DeprecationWarning, np.dtype, 'M16')
assert_warns(DeprecationWarning, np.dtype, 'm16')
def test_datetime_casting_rules(self):
# Cannot cast safely/same_kind between timedelta and datetime
assert_(not np.can_cast('m8', 'M8', casting='same_kind'))
assert_(not np.can_cast('M8', 'm8', casting='same_kind'))
assert_(not np.can_cast('m8', 'M8', casting='safe'))
assert_(not np.can_cast('M8', 'm8', casting='safe'))
# Can cast safely/same_kind from integer to timedelta
assert_(np.can_cast('i8', 'm8', casting='same_kind'))
assert_(np.can_cast('i8', 'm8', casting='safe'))
# Cannot cast safely/same_kind from float to timedelta
assert_(not np.can_cast('f4', 'm8', casting='same_kind'))
assert_(not np.can_cast('f4', 'm8', casting='safe'))
# Cannot cast safely/same_kind from integer to datetime
assert_(not np.can_cast('i8', 'M8', casting='same_kind'))
assert_(not np.can_cast('i8', 'M8', casting='safe'))
# Cannot cast safely/same_kind from bool to datetime
assert_(not np.can_cast('b1', 'M8', casting='same_kind'))
assert_(not np.can_cast('b1', 'M8', casting='safe'))
# Can cast safely/same_kind from bool to timedelta
assert_(np.can_cast('b1', 'm8', casting='same_kind'))
assert_(np.can_cast('b1', 'm8', casting='safe'))
# Can cast datetime safely from months/years to days
assert_(np.can_cast('M8[M]', 'M8[D]', casting='safe'))
assert_(np.can_cast('M8[Y]', 'M8[D]', casting='safe'))
# Cannot cast timedelta safely from months/years to days
assert_(not np.can_cast('m8[M]', 'm8[D]', casting='safe'))
assert_(not np.can_cast('m8[Y]', 'm8[D]', casting='safe'))
# Can cast datetime same_kind from months/years to days
assert_(np.can_cast('M8[M]', 'M8[D]', casting='same_kind'))
assert_(np.can_cast('M8[Y]', 'M8[D]', casting='same_kind'))
# Can't cast timedelta same_kind from months/years to days
assert_(not np.can_cast('m8[M]', 'm8[D]', casting='same_kind'))
assert_(not np.can_cast('m8[Y]', 'm8[D]', casting='same_kind'))
# Can't cast datetime same_kind across the date/time boundary
assert_(not np.can_cast('M8[D]', 'M8[h]', casting='same_kind'))
assert_(not np.can_cast('M8[h]', 'M8[D]', casting='same_kind'))
# Can cast timedelta same_kind across the date/time boundary
assert_(np.can_cast('m8[D]', 'm8[h]', casting='same_kind'))
assert_(np.can_cast('m8[h]', 'm8[D]', casting='same_kind'))
# Cannot cast safely if the integer multiplier doesn't divide
assert_(not np.can_cast('M8[7h]', 'M8[3h]', casting='safe'))
assert_(not np.can_cast('M8[3h]', 'M8[6h]', casting='safe'))
# But can cast same_kind
assert_(np.can_cast('M8[7h]', 'M8[3h]', casting='same_kind'))
# Can cast safely if the integer multiplier does divide
assert_(np.can_cast('M8[6h]', 'M8[3h]', casting='safe'))
def test_datetime_scalar_construction(self):
# Construct with different units
assert_equal(np.datetime64('1950-03-12', 'D'),
np.datetime64('1950-03-12'))
assert_equal(np.datetime64('1950-03-12T13Z', 's'),
np.datetime64('1950-03-12T13Z', 'm'))
# Default construction means NaT
assert_equal(np.datetime64(), np.datetime64('NaT'))
# Some basic strings and repr
assert_equal(str(np.datetime64('NaT')), 'NaT')
assert_equal(repr(np.datetime64('NaT')),
"numpy.datetime64('NaT')")
assert_equal(str(np.datetime64('2011-02')), '2011-02')
assert_equal(repr(np.datetime64('2011-02')),
"numpy.datetime64('2011-02')")
# None gets constructed as NaT
assert_equal(np.datetime64(None), np.datetime64('NaT'))
# Default construction of NaT is in generic units
assert_equal(np.datetime64().dtype, np.dtype('M8'))
assert_equal(np.datetime64('NaT').dtype, np.dtype('M8'))
# Construction from integers requires a specified unit
assert_raises(ValueError, np.datetime64, 17)
# When constructing from a scalar or zero-dimensional array,
# it either keeps the units or you can override them.
a = np.datetime64('2000-03-18T16Z', 'h')
b = np.array('2000-03-18T16Z', dtype='M8[h]')
assert_equal(a.dtype, np.dtype('M8[h]'))
assert_equal(b.dtype, np.dtype('M8[h]'))
assert_equal(np.datetime64(a), a)
assert_equal(np.datetime64(a).dtype, np.dtype('M8[h]'))
assert_equal(np.datetime64(b), a)
assert_equal(np.datetime64(b).dtype, np.dtype('M8[h]'))
assert_equal(np.datetime64(a, 's'), a)
assert_equal(np.datetime64(a, 's').dtype, np.dtype('M8[s]'))
assert_equal(np.datetime64(b, 's'), a)
assert_equal(np.datetime64(b, 's').dtype, np.dtype('M8[s]'))
# Construction from datetime.date
assert_equal(np.datetime64('1945-03-25'),
np.datetime64(datetime.date(1945, 3, 25)))
assert_equal(np.datetime64('2045-03-25', 'D'),
np.datetime64(datetime.date(2045, 3, 25), 'D'))
# Construction from datetime.datetime
assert_equal(np.datetime64('1980-01-25T14:36:22.5Z'),
np.datetime64(datetime.datetime(1980, 1, 25,
14, 36, 22, 500000)))
# Construction with time units from a date raises
assert_raises(TypeError, np.datetime64, '1920-03-13', 'h')
assert_raises(TypeError, np.datetime64, '1920-03', 'm')
assert_raises(TypeError, np.datetime64, '1920', 's')
assert_raises(TypeError, np.datetime64, datetime.date(2045, 3, 25), 'ms')
# Construction with date units from a datetime raises
assert_raises(TypeError, np.datetime64, '1920-03-13T18Z', 'D')
assert_raises(TypeError, np.datetime64, '1920-03-13T18:33Z', 'W')
assert_raises(TypeError, np.datetime64, '1920-03-13T18:33:12Z', 'M')
assert_raises(TypeError, np.datetime64, '1920-03-13T18:33:12.5Z', 'Y')
assert_raises(TypeError, np.datetime64,
datetime.datetime(1920, 4, 14, 13, 20), 'D')
def test_datetime_array_find_type(self):
dt = np.datetime64('1970-01-01', 'M')
arr = np.array([dt])
assert_equal(arr.dtype, np.dtype('M8[M]'))
# at the moment, we don't automatically convert these to datetime64
dt = datetime.date(1970, 1, 1)
arr = np.array([dt])
assert_equal(arr.dtype, np.dtype('O'))
dt = datetime.datetime(1970, 1, 1, 12, 30, 40)
arr = np.array([dt])
assert_equal(arr.dtype, np.dtype('O'))
# find "supertype" for non-dates and dates
b = np.bool_(True)
dt = np.datetime64('1970-01-01', 'M')
arr = np.array([b, dt])
assert_equal(arr.dtype, np.dtype('O'))
dt = datetime.date(1970, 1, 1)
arr = np.array([b, dt])
assert_equal(arr.dtype, np.dtype('O'))
dt = datetime.datetime(1970, 1, 1, 12, 30, 40)
arr = np.array([b, dt])
assert_equal(arr.dtype, np.dtype('O'))
def test_timedelta_scalar_construction(self):
# Construct with different units
assert_equal(np.timedelta64(7, 'D'),
np.timedelta64(1, 'W'))
assert_equal(np.timedelta64(120, 's'),
np.timedelta64(2, 'm'))
# Default construction means 0
assert_equal(np.timedelta64(), np.timedelta64(0))
# None gets constructed as NaT
assert_equal(np.timedelta64(None), np.timedelta64('NaT'))
# Some basic strings and repr
assert_equal(str(np.timedelta64('NaT')), 'NaT')
assert_equal(repr(np.timedelta64('NaT')),
"numpy.timedelta64('NaT')")
assert_equal(str(np.timedelta64(3, 's')), '3 seconds')
assert_equal(repr(np.timedelta64(-3, 's')),
"numpy.timedelta64(-3,'s')")
assert_equal(repr(np.timedelta64(12)),
"numpy.timedelta64(12)")
# Construction from an integer produces generic units
assert_equal(np.timedelta64(12).dtype, np.dtype('m8'))
# When constructing from a scalar or zero-dimensional array,
# it either keeps the units or you can override them.
a = np.timedelta64(2, 'h')
b = np.array(2, dtype='m8[h]')
assert_equal(a.dtype, np.dtype('m8[h]'))
assert_equal(b.dtype, np.dtype('m8[h]'))
assert_equal(np.timedelta64(a), a)
assert_equal(np.timedelta64(a).dtype, np.dtype('m8[h]'))
assert_equal(np.timedelta64(b), a)
assert_equal(np.timedelta64(b).dtype, np.dtype('m8[h]'))
assert_equal(np.timedelta64(a, 's'), a)
assert_equal(np.timedelta64(a, 's').dtype, np.dtype('m8[s]'))
assert_equal(np.timedelta64(b, 's'), a)
assert_equal(np.timedelta64(b, 's').dtype, np.dtype('m8[s]'))
# Construction from datetime.timedelta
assert_equal(np.timedelta64(5, 'D'),
np.timedelta64(datetime.timedelta(days=5)))
assert_equal(np.timedelta64(102347621, 's'),
np.timedelta64(datetime.timedelta(seconds=102347621)))
assert_equal(np.timedelta64(-10234760000, 'us'),
np.timedelta64(datetime.timedelta(
microseconds=-10234760000)))
assert_equal(np.timedelta64(10234760000, 'us'),
np.timedelta64(datetime.timedelta(
microseconds=10234760000)))
assert_equal(np.timedelta64(1023476, 'ms'),
np.timedelta64(datetime.timedelta(milliseconds=1023476)))
assert_equal(np.timedelta64(10, 'm'),
np.timedelta64(datetime.timedelta(minutes=10)))
assert_equal(np.timedelta64(281, 'h'),
np.timedelta64(datetime.timedelta(hours=281)))
assert_equal(np.timedelta64(28, 'W'),
np.timedelta64(datetime.timedelta(weeks=28)))
# Cannot construct across nonlinear time unit boundaries
a = np.timedelta64(3, 's')
assert_raises(TypeError, np.timedelta64, a, 'M')
assert_raises(TypeError, np.timedelta64, a, 'Y')
a = np.timedelta64(6, 'M')
assert_raises(TypeError, np.timedelta64, a, 'D')
assert_raises(TypeError, np.timedelta64, a, 'h')
a = np.timedelta64(1, 'Y')
assert_raises(TypeError, np.timedelta64, a, 'D')
assert_raises(TypeError, np.timedelta64, a, 'm')
def test_timedelta_scalar_construction_units(self):
# String construction detecting units
assert_equal(np.datetime64('2010').dtype,
np.dtype('M8[Y]'))
assert_equal(np.datetime64('2010-03').dtype,
np.dtype('M8[M]'))
assert_equal(np.datetime64('2010-03-12').dtype,
np.dtype('M8[D]'))
assert_equal(np.datetime64('2010-03-12T17').dtype,
np.dtype('M8[h]'))
assert_equal(np.datetime64('2010-03-12T17:15Z').dtype,
np.dtype('M8[m]'))
assert_equal(np.datetime64('2010-03-12T17:15:08Z').dtype,
np.dtype('M8[s]'))
assert_equal(np.datetime64('2010-03-12T17:15:08.1Z').dtype,
np.dtype('M8[ms]'))
assert_equal(np.datetime64('2010-03-12T17:15:08.12Z').dtype,
np.dtype('M8[ms]'))
assert_equal(np.datetime64('2010-03-12T17:15:08.123Z').dtype,
np.dtype('M8[ms]'))
assert_equal(np.datetime64('2010-03-12T17:15:08.1234Z').dtype,
np.dtype('M8[us]'))
assert_equal(np.datetime64('2010-03-12T17:15:08.12345Z').dtype,
np.dtype('M8[us]'))
assert_equal(np.datetime64('2010-03-12T17:15:08.123456Z').dtype,
np.dtype('M8[us]'))
assert_equal(np.datetime64('1970-01-01T00:00:02.1234567Z').dtype,
np.dtype('M8[ns]'))
assert_equal(np.datetime64('1970-01-01T00:00:02.12345678Z').dtype,
np.dtype('M8[ns]'))
assert_equal(np.datetime64('1970-01-01T00:00:02.123456789Z').dtype,
np.dtype('M8[ns]'))
assert_equal(np.datetime64('1970-01-01T00:00:02.1234567890Z').dtype,
np.dtype('M8[ps]'))
assert_equal(np.datetime64('1970-01-01T00:00:02.12345678901Z').dtype,
np.dtype('M8[ps]'))
assert_equal(np.datetime64('1970-01-01T00:00:02.123456789012Z').dtype,
np.dtype('M8[ps]'))
assert_equal(np.datetime64(
'1970-01-01T00:00:02.1234567890123Z').dtype,
np.dtype('M8[fs]'))
assert_equal(np.datetime64(
'1970-01-01T00:00:02.12345678901234Z').dtype,
np.dtype('M8[fs]'))
assert_equal(np.datetime64(
'1970-01-01T00:00:02.123456789012345Z').dtype,
np.dtype('M8[fs]'))
assert_equal(np.datetime64(
'1970-01-01T00:00:02.1234567890123456Z').dtype,
np.dtype('M8[as]'))
assert_equal(np.datetime64(
'1970-01-01T00:00:02.12345678901234567Z').dtype,
np.dtype('M8[as]'))
assert_equal(np.datetime64(
'1970-01-01T00:00:02.123456789012345678Z').dtype,
np.dtype('M8[as]'))
# Python date object
assert_equal(np.datetime64(datetime.date(2010, 4, 16)).dtype,
np.dtype('M8[D]'))
# Python datetime object
assert_equal(np.datetime64(
datetime.datetime(2010, 4, 16, 13, 45, 18)).dtype,
np.dtype('M8[us]'))
# 'today' special value
assert_equal(np.datetime64('today').dtype,
np.dtype('M8[D]'))
assert_raises(TypeError, np.datetime64, 'today', 'h')
assert_raises(TypeError, np.datetime64, 'today', 's')
assert_raises(TypeError, np.datetime64, 'today', 'as')
# 'now' special value
assert_equal(np.datetime64('now').dtype,
np.dtype('M8[s]'))
assert_raises(TypeError, np.datetime64, 'now', 'Y')
assert_raises(TypeError, np.datetime64, 'now', 'M')
assert_raises(TypeError, np.datetime64, 'now', 'D')
def test_datetime_nat_casting(self):
a = np.array('NaT', dtype='M8[D]')
b = np.datetime64('NaT', '[D]')
# Arrays
assert_equal(a.astype('M8[s]'), np.array('NaT', dtype='M8[s]'))
assert_equal(a.astype('M8[ms]'), np.array('NaT', dtype='M8[ms]'))
assert_equal(a.astype('M8[M]'), np.array('NaT', dtype='M8[M]'))
assert_equal(a.astype('M8[Y]'), np.array('NaT', dtype='M8[Y]'))
assert_equal(a.astype('M8[W]'), np.array('NaT', dtype='M8[W]'))
# Scalars -> Scalars
assert_equal(np.datetime64(b, '[s]'), np.datetime64('NaT', '[s]'))
assert_equal(np.datetime64(b, '[ms]'), np.datetime64('NaT', '[ms]'))
assert_equal(np.datetime64(b, '[M]'), np.datetime64('NaT', '[M]'))
assert_equal(np.datetime64(b, '[Y]'), np.datetime64('NaT', '[Y]'))
assert_equal(np.datetime64(b, '[W]'), np.datetime64('NaT', '[W]'))
# Arrays -> Scalars
assert_equal(np.datetime64(a, '[s]'), np.datetime64('NaT', '[s]'))
assert_equal(np.datetime64(a, '[ms]'), np.datetime64('NaT', '[ms]'))
assert_equal(np.datetime64(a, '[M]'), np.datetime64('NaT', '[M]'))
assert_equal(np.datetime64(a, '[Y]'), np.datetime64('NaT', '[Y]'))
assert_equal(np.datetime64(a, '[W]'), np.datetime64('NaT', '[W]'))
def test_days_creation(self):
assert_equal(np.array('1599', dtype='M8[D]').astype('i8'),
(1600-1970)*365 - (1972-1600)/4 + 3 - 365)
assert_equal(np.array('1600', dtype='M8[D]').astype('i8'),
(1600-1970)*365 - (1972-1600)/4 + 3)
assert_equal(np.array('1601', dtype='M8[D]').astype('i8'),
(1600-1970)*365 - (1972-1600)/4 + 3 + 366)
assert_equal(np.array('1900', dtype='M8[D]').astype('i8'),
(1900-1970)*365 - (1970-1900)//4)
assert_equal(np.array('1901', dtype='M8[D]').astype('i8'),
(1900-1970)*365 - (1970-1900)//4 + 365)
assert_equal(np.array('1967', dtype='M8[D]').astype('i8'), -3*365 - 1)
assert_equal(np.array('1968', dtype='M8[D]').astype('i8'), -2*365 - 1)
assert_equal(np.array('1969', dtype='M8[D]').astype('i8'), -1*365)
assert_equal(np.array('1970', dtype='M8[D]').astype('i8'), 0*365)
assert_equal(np.array('1971', dtype='M8[D]').astype('i8'), 1*365)
assert_equal(np.array('1972', dtype='M8[D]').astype('i8'), 2*365)
assert_equal(np.array('1973', dtype='M8[D]').astype('i8'), 3*365 + 1)
assert_equal(np.array('1974', dtype='M8[D]').astype('i8'), 4*365 + 1)
assert_equal(np.array('2000', dtype='M8[D]').astype('i8'),
(2000 - 1970)*365 + (2000 - 1972)//4)
assert_equal(np.array('2001', dtype='M8[D]').astype('i8'),
(2000 - 1970)*365 + (2000 - 1972)//4 + 366)
assert_equal(np.array('2400', dtype='M8[D]').astype('i8'),
(2400 - 1970)*365 + (2400 - 1972)//4 - 3)
assert_equal(np.array('2401', dtype='M8[D]').astype('i8'),
(2400 - 1970)*365 + (2400 - 1972)//4 - 3 + 366)
assert_equal(np.array('1600-02-29', dtype='M8[D]').astype('i8'),
(1600-1970)*365 - (1972-1600)//4 + 3 + 31 + 28)
assert_equal(np.array('1600-03-01', dtype='M8[D]').astype('i8'),
(1600-1970)*365 - (1972-1600)//4 + 3 + 31 + 29)
assert_equal(np.array('2000-02-29', dtype='M8[D]').astype('i8'),
(2000 - 1970)*365 + (2000 - 1972)//4 + 31 + 28)
assert_equal(np.array('2000-03-01', dtype='M8[D]').astype('i8'),
(2000 - 1970)*365 + (2000 - 1972)//4 + 31 + 29)
assert_equal(np.array('2001-03-22', dtype='M8[D]').astype('i8'),
(2000 - 1970)*365 + (2000 - 1972)//4 + 366 + 31 + 28 + 21)
def test_days_to_pydate(self):
assert_equal(np.array('1599', dtype='M8[D]').astype('O'),
datetime.date(1599, 1, 1))
assert_equal(np.array('1600', dtype='M8[D]').astype('O'),
datetime.date(1600, 1, 1))
assert_equal(np.array('1601', dtype='M8[D]').astype('O'),
datetime.date(1601, 1, 1))
assert_equal(np.array('1900', dtype='M8[D]').astype('O'),
datetime.date(1900, 1, 1))
assert_equal(np.array('1901', dtype='M8[D]').astype('O'),
datetime.date(1901, 1, 1))
assert_equal(np.array('2000', dtype='M8[D]').astype('O'),
datetime.date(2000, 1, 1))
assert_equal(np.array('2001', dtype='M8[D]').astype('O'),
datetime.date(2001, 1, 1))
assert_equal(np.array('1600-02-29', dtype='M8[D]').astype('O'),
datetime.date(1600, 2, 29))
assert_equal(np.array('1600-03-01', dtype='M8[D]').astype('O'),
datetime.date(1600, 3, 1))
assert_equal(np.array('2001-03-22', dtype='M8[D]').astype('O'),
datetime.date(2001, 3, 22))
def test_dtype_comparison(self):
assert_(not (np.dtype('M8[us]') == np.dtype('M8[ms]')))
assert_(np.dtype('M8[us]') != np.dtype('M8[ms]'))
assert_(np.dtype('M8[2D]') != np.dtype('M8[D]'))
assert_(np.dtype('M8[D]') != np.dtype('M8[2D]'))
def test_pydatetime_creation(self):
a = np.array(['1960-03-12', datetime.date(1960, 3, 12)], dtype='M8[D]')
assert_equal(a[0], a[1])
a = np.array(['1999-12-31', datetime.date(1999, 12, 31)], dtype='M8[D]')
assert_equal(a[0], a[1])
a = np.array(['2000-01-01', datetime.date(2000, 1, 1)], dtype='M8[D]')
assert_equal(a[0], a[1])
# Will fail if the date changes during the exact right moment
a = np.array(['today', datetime.date.today()], dtype='M8[D]')
assert_equal(a[0], a[1])
# datetime.datetime.now() returns local time, not UTC
#a = np.array(['now', datetime.datetime.now()], dtype='M8[s]')
#assert_equal(a[0], a[1])
# A datetime.date will raise if you try to give it time units
assert_raises(TypeError, np.array, datetime.date(1960, 3, 12),
dtype='M8[s]')
def test_datetime_string_conversion(self):
a = ['2011-03-16', '1920-01-01', '2013-05-19']
str_a = np.array(a, dtype='S')
dt_a = np.array(a, dtype='M')
str_b = np.empty_like(str_a)
dt_b = np.empty_like(dt_a)
# String to datetime
assert_equal(dt_a, str_a.astype('M'))
assert_equal(dt_a.dtype, str_a.astype('M').dtype)
dt_b[...] = str_a
assert_equal(dt_a, dt_b)
# Datetime to string
assert_equal(str_a, dt_a.astype('S0'))
str_b[...] = dt_a
assert_equal(str_a, str_b)
# Convert the 'S' to 'U'
str_a = str_a.astype('U')
str_b = str_b.astype('U')
# Unicode to datetime
assert_equal(dt_a, str_a.astype('M'))
assert_equal(dt_a.dtype, str_a.astype('M').dtype)
dt_b[...] = str_a
assert_equal(dt_a, dt_b)
# Datetime to unicode
assert_equal(str_a, dt_a.astype('U'))
str_b[...] = dt_a
assert_equal(str_a, str_b)
def test_datetime_array_str(self):
a = np.array(['2011-03-16', '1920-01-01', '2013-05-19'], dtype='M')
assert_equal(str(a), "['2011-03-16' '1920-01-01' '2013-05-19']")
a = np.array(['2011-03-16T13:55Z', '1920-01-01T03:12Z'], dtype='M')
assert_equal(np.array2string(a, separator=', ',
formatter={'datetime': lambda x :
"'%s'" % np.datetime_as_string(x, timezone='UTC')}),
"['2011-03-16T13:55Z', '1920-01-01T03:12Z']")
# Check that one NaT doesn't corrupt subsequent entries
a = np.array(['2010', 'NaT', '2030']).astype('M')
assert_equal(str(a), "['2010' 'NaT' '2030']")
def test_pickle(self):
# Check that pickle roundtripping works
dt = np.dtype('M8[7D]')
assert_equal(pickle.loads(pickle.dumps(dt)), dt)
dt = np.dtype('M8[W]')
assert_equal(pickle.loads(pickle.dumps(dt)), dt)
# Check that loading pickles from 1.6 works
pkl = "cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
"(I4\nS'<'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'D'\np6\n" + \
"I7\nI1\nI1\ntp7\ntp8\ntp9\nb."
assert_equal(pickle.loads(asbytes(pkl)), np.dtype('<M8[7D]'))
pkl = "cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
"(I4\nS'<'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'W'\np6\n" + \
"I1\nI1\nI1\ntp7\ntp8\ntp9\nb."
assert_equal(pickle.loads(asbytes(pkl)), np.dtype('<M8[W]'))
pkl = "cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
"(I4\nS'>'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'us'\np6\n" + \
"I1\nI1\nI1\ntp7\ntp8\ntp9\nb."
assert_equal(pickle.loads(asbytes(pkl)), np.dtype('>M8[us]'))
def test_setstate(self):
"Verify that datetime dtype __setstate__ can handle bad arguments"
dt = np.dtype('>M8[us]')
assert_raises(ValueError, dt.__setstate__, (4, '>', None, None, None, -1, -1, 0, 1))
assert (dt.__reduce__()[2] == np.dtype('>M8[us]').__reduce__()[2])
assert_raises(TypeError, dt.__setstate__, (4, '>', None, None, None, -1, -1, 0, ({}, 'xxx')))
assert (dt.__reduce__()[2] == np.dtype('>M8[us]').__reduce__()[2])
def test_dtype_promotion(self):
# datetime <op> datetime computes the metadata gcd
# timedelta <op> timedelta computes the metadata gcd
for mM in ['m', 'M']:
assert_equal(
np.promote_types(np.dtype(mM+'8[2Y]'), np.dtype(mM+'8[2Y]')),
np.dtype(mM+'8[2Y]'))
assert_equal(
np.promote_types(np.dtype(mM+'8[12Y]'), np.dtype(mM+'8[15Y]')),
np.dtype(mM+'8[3Y]'))
assert_equal(
np.promote_types(np.dtype(mM+'8[62M]'), np.dtype(mM+'8[24M]')),
np.dtype(mM+'8[2M]'))
assert_equal(
np.promote_types(np.dtype(mM+'8[1W]'), np.dtype(mM+'8[2D]')),
np.dtype(mM+'8[1D]'))
assert_equal(
np.promote_types(np.dtype(mM+'8[W]'), np.dtype(mM+'8[13s]')),
np.dtype(mM+'8[s]'))
assert_equal(
np.promote_types(np.dtype(mM+'8[13W]'), np.dtype(mM+'8[49s]')),
np.dtype(mM+'8[7s]'))
# timedelta <op> timedelta raises when there is no reasonable gcd
assert_raises(TypeError, np.promote_types,
np.dtype('m8[Y]'), np.dtype('m8[D]'))
assert_raises(TypeError, np.promote_types,
np.dtype('m8[M]'), np.dtype('m8[W]'))
# timedelta <op> timedelta may overflow with big unit ranges
assert_raises(OverflowError, np.promote_types,
np.dtype('m8[W]'), np.dtype('m8[fs]'))
assert_raises(OverflowError, np.promote_types,
np.dtype('m8[s]'), np.dtype('m8[as]'))
def test_cast_overflow(self):
# gh-4486
def cast():
numpy.datetime64("1971-01-01 00:00:00.000000000000000").astype("<M8[D]")
assert_raises(OverflowError, cast)
def cast2():
numpy.datetime64("2014").astype("<M8[fs]")
assert_raises(OverflowError, cast2)
def test_pyobject_roundtrip(self):
# All datetime types should be able to roundtrip through object
a = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0,
-1020040340, -2942398, -1, 0, 1, 234523453, 1199164176],
dtype=np.int64)
# With date units
for unit in ['M8[D]', 'M8[W]', 'M8[M]', 'M8[Y]']:
b = a.copy().view(dtype=unit)
b[0] = '-0001-01-01'
b[1] = '-0001-12-31'
b[2] = '0000-01-01'
b[3] = '0001-01-01'
b[4] = '1969-12-31'
b[5] = '1970-01-01'
b[6] = '9999-12-31'
b[7] = '10000-01-01'
b[8] = 'NaT'
assert_equal(b.astype(object).astype(unit), b,
"Error roundtripping unit %s" % unit)
# With time units
for unit in ['M8[as]', 'M8[16fs]', 'M8[ps]', 'M8[us]',
'M8[300as]', 'M8[20us]']:
b = a.copy().view(dtype=unit)
b[0] = '-0001-01-01T00Z'
b[1] = '-0001-12-31T00Z'
b[2] = '0000-01-01T00Z'
b[3] = '0001-01-01T00Z'
b[4] = '1969-12-31T23:59:59.999999Z'
b[5] = '1970-01-01T00Z'
b[6] = '9999-12-31T23:59:59.999999Z'
b[7] = '10000-01-01T00Z'
b[8] = 'NaT'
assert_equal(b.astype(object).astype(unit), b,
"Error roundtripping unit %s" % unit)
def test_month_truncation(self):
# Make sure that months are truncating correctly
assert_equal(np.array('1945-03-01', dtype='M8[M]'),
np.array('1945-03-31', dtype='M8[M]'))
assert_equal(np.array('1969-11-01', dtype='M8[M]'),
np.array('1969-11-30T23:59:59.99999Z', dtype='M').astype('M8[M]'))
assert_equal(np.array('1969-12-01', dtype='M8[M]'),
np.array('1969-12-31T23:59:59.99999Z', dtype='M').astype('M8[M]'))
assert_equal(np.array('1970-01-01', dtype='M8[M]'),
np.array('1970-01-31T23:59:59.99999Z', dtype='M').astype('M8[M]'))
assert_equal(np.array('1980-02-01', dtype='M8[M]'),
np.array('1980-02-29T23:59:59.99999Z', dtype='M').astype('M8[M]'))
def test_different_unit_comparison(self):
# Check some years with date units
for unit1 in ['Y', 'M', 'D']:
dt1 = np.dtype('M8[%s]' % unit1)
for unit2 in ['Y', 'M', 'D']:
dt2 = np.dtype('M8[%s]' % unit2)
assert_equal(np.array('1945', dtype=dt1),
np.array('1945', dtype=dt2))
assert_equal(np.array('1970', dtype=dt1),
np.array('1970', dtype=dt2))
assert_equal(np.array('9999', dtype=dt1),
np.array('9999', dtype=dt2))
assert_equal(np.array('10000', dtype=dt1),
np.array('10000-01-01', dtype=dt2))
assert_equal(np.datetime64('1945', unit1),
np.datetime64('1945', unit2))
assert_equal(np.datetime64('1970', unit1),
np.datetime64('1970', unit2))
assert_equal(np.datetime64('9999', unit1),
np.datetime64('9999', unit2))
assert_equal(np.datetime64('10000', unit1),
np.datetime64('10000-01-01', unit2))
# Check some datetimes with time units
for unit1 in ['6h', 'h', 'm', 's', '10ms', 'ms', 'us']:
dt1 = np.dtype('M8[%s]' % unit1)
for unit2 in ['h', 'm', 's', 'ms', 'us']:
dt2 = np.dtype('M8[%s]' % unit2)
assert_equal(np.array('1945-03-12T18Z', dtype=dt1),
np.array('1945-03-12T18Z', dtype=dt2))
assert_equal(np.array('1970-03-12T18Z', dtype=dt1),
np.array('1970-03-12T18Z', dtype=dt2))
assert_equal(np.array('9999-03-12T18Z', dtype=dt1),
np.array('9999-03-12T18Z', dtype=dt2))
assert_equal(np.array('10000-01-01T00Z', dtype=dt1),
np.array('10000-01-01T00Z', dtype=dt2))
assert_equal(np.datetime64('1945-03-12T18Z', unit1),
np.datetime64('1945-03-12T18Z', unit2))
assert_equal(np.datetime64('1970-03-12T18Z', unit1),
np.datetime64('1970-03-12T18Z', unit2))
assert_equal(np.datetime64('9999-03-12T18Z', unit1),
np.datetime64('9999-03-12T18Z', unit2))
assert_equal(np.datetime64('10000-01-01T00Z', unit1),
np.datetime64('10000-01-01T00Z', unit2))
# Check some days with units that won't overflow
for unit1 in ['D', '12h', 'h', 'm', 's', '4s', 'ms', 'us']:
dt1 = np.dtype('M8[%s]' % unit1)
for unit2 in ['D', 'h', 'm', 's', 'ms', 'us']:
dt2 = np.dtype('M8[%s]' % unit2)
assert_(np.equal(np.array('1932-02-17', dtype='M').astype(dt1),
np.array('1932-02-17T00:00:00Z', dtype='M').astype(dt2),
casting='unsafe'))
assert_(np.equal(np.array('10000-04-27', dtype='M').astype(dt1),
np.array('10000-04-27T00:00:00Z', dtype='M').astype(dt2),
casting='unsafe'))
# Shouldn't be able to compare datetime and timedelta
# TODO: Changing to 'same_kind' or 'safe' casting in the ufuncs by
# default is needed to properly catch this kind of thing...
a = np.array('2012-12-21', dtype='M8[D]')
b = np.array(3, dtype='m8[D]')
#assert_raises(TypeError, np.less, a, b)
assert_raises(TypeError, np.less, a, b, casting='same_kind')
def test_datetime_like(self):
a = np.array([3], dtype='m8[4D]')
b = np.array(['2012-12-21'], dtype='M8[D]')
assert_equal(np.ones_like(a).dtype, a.dtype)
assert_equal(np.zeros_like(a).dtype, a.dtype)
assert_equal(np.empty_like(a).dtype, a.dtype)
assert_equal(np.ones_like(b).dtype, b.dtype)
assert_equal(np.zeros_like(b).dtype, b.dtype)
assert_equal(np.empty_like(b).dtype, b.dtype)
def test_datetime_unary(self):
for tda, tdb, tdzero, tdone, tdmone in \
[
# One-dimensional arrays
(np.array([3], dtype='m8[D]'),
np.array([-3], dtype='m8[D]'),
np.array([0], dtype='m8[D]'),
np.array([1], dtype='m8[D]'),
np.array([-1], dtype='m8[D]')),
# NumPy scalars
(np.timedelta64(3, '[D]'),
np.timedelta64(-3, '[D]'),
np.timedelta64(0, '[D]'),
np.timedelta64(1, '[D]'),
np.timedelta64(-1, '[D]'))]:
# negative ufunc
assert_equal(-tdb, tda)
assert_equal((-tdb).dtype, tda.dtype)
assert_equal(np.negative(tdb), tda)
assert_equal(np.negative(tdb).dtype, tda.dtype)
# absolute ufunc
assert_equal(np.absolute(tdb), tda)
assert_equal(np.absolute(tdb).dtype, tda.dtype)
# sign ufunc
assert_equal(np.sign(tda), tdone)
assert_equal(np.sign(tdb), tdmone)
assert_equal(np.sign(tdzero), tdzero)
assert_equal(np.sign(tda).dtype, tda.dtype)
# The ufuncs always produce native-endian results
assert_
def test_datetime_add(self):
for dta, dtb, dtc, dtnat, tda, tdb, tdc in \
[
# One-dimensional arrays
(np.array(['2012-12-21'], dtype='M8[D]'),
np.array(['2012-12-24'], dtype='M8[D]'),
np.array(['2012-12-21T11Z'], dtype='M8[h]'),
np.array(['NaT'], dtype='M8[D]'),
np.array([3], dtype='m8[D]'),
np.array([11], dtype='m8[h]'),
np.array([3*24 + 11], dtype='m8[h]')),
# NumPy scalars
(np.datetime64('2012-12-21', '[D]'),
np.datetime64('2012-12-24', '[D]'),
np.datetime64('2012-12-21T11Z', '[h]'),
np.datetime64('NaT', '[D]'),
np.timedelta64(3, '[D]'),
np.timedelta64(11, '[h]'),
np.timedelta64(3*24 + 11, '[h]'))]:
# m8 + m8
assert_equal(tda + tdb, tdc)
assert_equal((tda + tdb).dtype, np.dtype('m8[h]'))
# m8 + bool
assert_equal(tdb + True, tdb + 1)
assert_equal((tdb + True).dtype, np.dtype('m8[h]'))
# m8 + int
assert_equal(tdb + 3*24, tdc)
assert_equal((tdb + 3*24).dtype, np.dtype('m8[h]'))
# bool + m8
assert_equal(False + tdb, tdb)
assert_equal((False + tdb).dtype, np.dtype('m8[h]'))
# int + m8
assert_equal(3*24 + tdb, tdc)
assert_equal((3*24 + tdb).dtype, np.dtype('m8[h]'))
# M8 + bool
assert_equal(dta + True, dta + 1)
assert_equal(dtnat + True, dtnat)
assert_equal((dta + True).dtype, np.dtype('M8[D]'))
# M8 + int
assert_equal(dta + 3, dtb)
assert_equal(dtnat + 3, dtnat)
assert_equal((dta + 3).dtype, np.dtype('M8[D]'))
# bool + M8
assert_equal(False + dta, dta)
assert_equal(False + dtnat, dtnat)
assert_equal((False + dta).dtype, np.dtype('M8[D]'))
# int + M8
assert_equal(3 + dta, dtb)
assert_equal(3 + dtnat, dtnat)
assert_equal((3 + dta).dtype, np.dtype('M8[D]'))
# M8 + m8
assert_equal(dta + tda, dtb)
assert_equal(dtnat + tda, dtnat)
assert_equal((dta + tda).dtype, np.dtype('M8[D]'))
# m8 + M8
assert_equal(tda + dta, dtb)
assert_equal(tda + dtnat, dtnat)
assert_equal((tda + dta).dtype, np.dtype('M8[D]'))
# In M8 + m8, the result goes to higher precision
assert_equal(np.add(dta, tdb, casting='unsafe'), dtc)
assert_equal(np.add(dta, tdb, casting='unsafe').dtype,
np.dtype('M8[h]'))
assert_equal(np.add(tdb, dta, casting='unsafe'), dtc)
assert_equal(np.add(tdb, dta, casting='unsafe').dtype,
np.dtype('M8[h]'))
# M8 + M8
assert_raises(TypeError, np.add, dta, dtb)
def test_datetime_subtract(self):
for dta, dtb, dtc, dtd, dte, dtnat, tda, tdb, tdc in \
[
# One-dimensional arrays
(np.array(['2012-12-21'], dtype='M8[D]'),
np.array(['2012-12-24'], dtype='M8[D]'),
np.array(['1940-12-24'], dtype='M8[D]'),
np.array(['1940-12-24T00Z'], dtype='M8[h]'),
np.array(['1940-12-23T13Z'], dtype='M8[h]'),
np.array(['NaT'], dtype='M8[D]'),
np.array([3], dtype='m8[D]'),
np.array([11], dtype='m8[h]'),
np.array([3*24 - 11], dtype='m8[h]')),
# NumPy scalars
(np.datetime64('2012-12-21', '[D]'),
np.datetime64('2012-12-24', '[D]'),
np.datetime64('1940-12-24', '[D]'),
np.datetime64('1940-12-24T00Z', '[h]'),
np.datetime64('1940-12-23T13Z', '[h]'),
np.datetime64('NaT', '[D]'),
np.timedelta64(3, '[D]'),
np.timedelta64(11, '[h]'),
np.timedelta64(3*24 - 11, '[h]'))]:
# m8 - m8
assert_equal(tda - tdb, tdc)
assert_equal((tda - tdb).dtype, np.dtype('m8[h]'))
assert_equal(tdb - tda, -tdc)
assert_equal((tdb - tda).dtype, np.dtype('m8[h]'))
# m8 - bool
assert_equal(tdc - True, tdc - 1)
assert_equal((tdc - True).dtype, np.dtype('m8[h]'))
# m8 - int
assert_equal(tdc - 3*24, -tdb)
assert_equal((tdc - 3*24).dtype, np.dtype('m8[h]'))
# int - m8
assert_equal(False - tdb, -tdb)
assert_equal((False - tdb).dtype, np.dtype('m8[h]'))
# int - m8
assert_equal(3*24 - tdb, tdc)
assert_equal((3*24 - tdb).dtype, np.dtype('m8[h]'))
# M8 - bool
assert_equal(dtb - True, dtb - 1)
assert_equal(dtnat - True, dtnat)
assert_equal((dtb - True).dtype, np.dtype('M8[D]'))
# M8 - int
assert_equal(dtb - 3, dta)
assert_equal(dtnat - 3, dtnat)
assert_equal((dtb - 3).dtype, np.dtype('M8[D]'))
# M8 - m8
assert_equal(dtb - tda, dta)
assert_equal(dtnat - tda, dtnat)
assert_equal((dtb - tda).dtype, np.dtype('M8[D]'))
# In M8 - m8, the result goes to higher precision
assert_equal(np.subtract(dtc, tdb, casting='unsafe'), dte)
assert_equal(np.subtract(dtc, tdb, casting='unsafe').dtype,
np.dtype('M8[h]'))
# M8 - M8 with different goes to higher precision
assert_equal(np.subtract(dtc, dtd, casting='unsafe'),
np.timedelta64(0, 'h'))
assert_equal(np.subtract(dtc, dtd, casting='unsafe').dtype,
np.dtype('m8[h]'))
assert_equal(np.subtract(dtd, dtc, casting='unsafe'),
np.timedelta64(0, 'h'))
assert_equal(np.subtract(dtd, dtc, casting='unsafe').dtype,
np.dtype('m8[h]'))
# m8 - M8
assert_raises(TypeError, np.subtract, tda, dta)
# bool - M8
assert_raises(TypeError, np.subtract, False, dta)
# int - M8
assert_raises(TypeError, np.subtract, 3, dta)
def test_datetime_multiply(self):
for dta, tda, tdb, tdc in \
[
# One-dimensional arrays
(np.array(['2012-12-21'], dtype='M8[D]'),
np.array([6], dtype='m8[h]'),
np.array([9], dtype='m8[h]'),
np.array([12], dtype='m8[h]')),
# NumPy scalars
(np.datetime64('2012-12-21', '[D]'),
np.timedelta64(6, '[h]'),
np.timedelta64(9, '[h]'),
np.timedelta64(12, '[h]'))]:
# m8 * int
assert_equal(tda * 2, tdc)
assert_equal((tda * 2).dtype, np.dtype('m8[h]'))
# int * m8
assert_equal(2 * tda, tdc)
assert_equal((2 * tda).dtype, np.dtype('m8[h]'))
# m8 * float
assert_equal(tda * 1.5, tdb)
assert_equal((tda * 1.5).dtype, np.dtype('m8[h]'))
# float * m8
assert_equal(1.5 * tda, tdb)
assert_equal((1.5 * tda).dtype, np.dtype('m8[h]'))
# m8 * m8
assert_raises(TypeError, np.multiply, tda, tdb)
# m8 * M8
assert_raises(TypeError, np.multiply, dta, tda)
# M8 * m8
assert_raises(TypeError, np.multiply, tda, dta)
# M8 * int
assert_raises(TypeError, np.multiply, dta, 2)
# int * M8
assert_raises(TypeError, np.multiply, 2, dta)
# M8 * float
assert_raises(TypeError, np.multiply, dta, 1.5)
# float * M8
assert_raises(TypeError, np.multiply, 1.5, dta)
def test_datetime_divide(self):
for dta, tda, tdb, tdc, tdd in \
[
# One-dimensional arrays
(np.array(['2012-12-21'], dtype='M8[D]'),
np.array([6], dtype='m8[h]'),
np.array([9], dtype='m8[h]'),
np.array([12], dtype='m8[h]'),
np.array([6], dtype='m8[m]')),
# NumPy scalars
(np.datetime64('2012-12-21', '[D]'),
np.timedelta64(6, '[h]'),
np.timedelta64(9, '[h]'),
np.timedelta64(12, '[h]'),
np.timedelta64(6, '[m]'))]:
# m8 / int
assert_equal(tdc / 2, tda)
assert_equal((tdc / 2).dtype, np.dtype('m8[h]'))
# m8 / float
assert_equal(tda / 0.5, tdc)
assert_equal((tda / 0.5).dtype, np.dtype('m8[h]'))
# m8 / m8
assert_equal(tda / tdb, 6.0 / 9.0)
assert_equal(np.divide(tda, tdb), 6.0 / 9.0)
assert_equal(np.true_divide(tda, tdb), 6.0 / 9.0)
assert_equal(tdb / tda, 9.0 / 6.0)
assert_equal((tda / tdb).dtype, np.dtype('f8'))
assert_equal(tda / tdd, 60.0)
assert_equal(tdd / tda, 1.0 / 60.0)
# m8 // m8
assert_raises(TypeError, np.floor_divide, tda, tdb)
# int / m8
assert_raises(TypeError, np.divide, 2, tdb)
# float / m8
assert_raises(TypeError, np.divide, 0.5, tdb)
# m8 / M8
assert_raises(TypeError, np.divide, dta, tda)
# M8 / m8
assert_raises(TypeError, np.divide, tda, dta)
# M8 / int
assert_raises(TypeError, np.divide, dta, 2)
# int / M8
assert_raises(TypeError, np.divide, 2, dta)
# M8 / float
assert_raises(TypeError, np.divide, dta, 1.5)
# float / M8
assert_raises(TypeError, np.divide, 1.5, dta)
def test_datetime_compare(self):
# Test all the comparison operators
a = np.datetime64('2000-03-12T18:00:00.000000-0600')
b = np.array(['2000-03-12T18:00:00.000000-0600',
'2000-03-12T17:59:59.999999-0600',
'2000-03-12T18:00:00.000001-0600',
'1970-01-11T12:00:00.909090-0600',
'2016-01-11T12:00:00.909090-0600'],
dtype='datetime64[us]')
assert_equal(np.equal(a, b), [1, 0, 0, 0, 0])
assert_equal(np.not_equal(a, b), [0, 1, 1, 1, 1])
assert_equal(np.less(a, b), [0, 0, 1, 0, 1])
assert_equal(np.less_equal(a, b), [1, 0, 1, 0, 1])
assert_equal(np.greater(a, b), [0, 1, 0, 1, 0])
assert_equal(np.greater_equal(a, b), [1, 1, 0, 1, 0])
def test_datetime_minmax(self):
# The metadata of the result should become the GCD
# of the operand metadata
a = np.array('1999-03-12T13Z', dtype='M8[2m]')
b = np.array('1999-03-12T12Z', dtype='M8[s]')
assert_equal(np.minimum(a, b), b)
assert_equal(np.minimum(a, b).dtype, np.dtype('M8[s]'))
assert_equal(np.fmin(a, b), b)
assert_equal(np.fmin(a, b).dtype, np.dtype('M8[s]'))
assert_equal(np.maximum(a, b), a)
assert_equal(np.maximum(a, b).dtype, np.dtype('M8[s]'))
assert_equal(np.fmax(a, b), a)
assert_equal(np.fmax(a, b).dtype, np.dtype('M8[s]'))
# Viewed as integers, the comparison is opposite because
# of the units chosen
assert_equal(np.minimum(a.view('i8'), b.view('i8')), a.view('i8'))
# Interaction with NaT
a = np.array('1999-03-12T13Z', dtype='M8[2m]')
dtnat = np.array('NaT', dtype='M8[h]')
assert_equal(np.minimum(a, dtnat), a)
assert_equal(np.minimum(dtnat, a), a)
assert_equal(np.maximum(a, dtnat), a)
assert_equal(np.maximum(dtnat, a), a)
# Also do timedelta
a = np.array(3, dtype='m8[h]')
b = np.array(3*3600 - 3, dtype='m8[s]')
assert_equal(np.minimum(a, b), b)
assert_equal(np.minimum(a, b).dtype, np.dtype('m8[s]'))
assert_equal(np.fmin(a, b), b)
assert_equal(np.fmin(a, b).dtype, np.dtype('m8[s]'))
assert_equal(np.maximum(a, b), a)
assert_equal(np.maximum(a, b).dtype, np.dtype('m8[s]'))
assert_equal(np.fmax(a, b), a)
assert_equal(np.fmax(a, b).dtype, np.dtype('m8[s]'))
# Viewed as integers, the comparison is opposite because
# of the units chosen
assert_equal(np.minimum(a.view('i8'), b.view('i8')), a.view('i8'))
# should raise between datetime and timedelta
#
# TODO: Allowing unsafe casting by
# default in ufuncs strikes again... :(
a = np.array(3, dtype='m8[h]')
b = np.array('1999-03-12T12Z', dtype='M8[s]')
#assert_raises(TypeError, np.minimum, a, b)
#assert_raises(TypeError, np.maximum, a, b)
#assert_raises(TypeError, np.fmin, a, b)
#assert_raises(TypeError, np.fmax, a, b)
assert_raises(TypeError, np.minimum, a, b, casting='same_kind')
assert_raises(TypeError, np.maximum, a, b, casting='same_kind')
assert_raises(TypeError, np.fmin, a, b, casting='same_kind')
assert_raises(TypeError, np.fmax, a, b, casting='same_kind')
def test_hours(self):
t = np.ones(3, dtype='M8[s]')
t[0] = 60*60*24 + 60*60*10
assert_(t[0].item().hour == 10 )
def test_divisor_conversion_year(self):
assert_(np.dtype('M8[Y/4]') == np.dtype('M8[3M]'))
assert_(np.dtype('M8[Y/13]') == np.dtype('M8[4W]'))
assert_(np.dtype('M8[3Y/73]') == np.dtype('M8[15D]'))
def test_divisor_conversion_month(self):
assert_(np.dtype('M8[M/2]') == np.dtype('M8[2W]'))
assert_(np.dtype('M8[M/15]') == np.dtype('M8[2D]'))
assert_(np.dtype('M8[3M/40]') == np.dtype('M8[54h]'))
def test_divisor_conversion_week(self):
assert_(np.dtype('m8[W/7]') == np.dtype('m8[D]'))
assert_(np.dtype('m8[3W/14]') == np.dtype('m8[36h]'))
assert_(np.dtype('m8[5W/140]') == np.dtype('m8[360m]'))
def test_divisor_conversion_day(self):
assert_(np.dtype('M8[D/12]') == np.dtype('M8[2h]'))
assert_(np.dtype('M8[D/120]') == np.dtype('M8[12m]'))
assert_(np.dtype('M8[3D/960]') == np.dtype('M8[270s]'))
def test_divisor_conversion_hour(self):
assert_(np.dtype('m8[h/30]') == np.dtype('m8[2m]'))
assert_(np.dtype('m8[3h/300]') == np.dtype('m8[36s]'))
def test_divisor_conversion_minute(self):
assert_(np.dtype('m8[m/30]') == np.dtype('m8[2s]'))
assert_(np.dtype('m8[3m/300]') == np.dtype('m8[600ms]'))
def test_divisor_conversion_second(self):
assert_(np.dtype('m8[s/100]') == np.dtype('m8[10ms]'))
assert_(np.dtype('m8[3s/10000]') == np.dtype('m8[300us]'))
def test_divisor_conversion_fs(self):
assert_(np.dtype('M8[fs/100]') == np.dtype('M8[10as]'))
self.assertRaises(ValueError, lambda : np.dtype('M8[3fs/10000]'))
def test_divisor_conversion_as(self):
self.assertRaises(ValueError, lambda : np.dtype('M8[as/10]'))
def test_string_parser_variants(self):
# Allow space instead of 'T' between date and time
assert_equal(np.array(['1980-02-29T01:02:03'], np.dtype('M8[s]')),
np.array(['1980-02-29 01:02:03'], np.dtype('M8[s]')))
# Allow negative years
assert_equal(np.array(['-1980-02-29T01:02:03'], np.dtype('M8[s]')),
np.array(['-1980-02-29 01:02:03'], np.dtype('M8[s]')))
# UTC specifier
assert_equal(np.array(['-1980-02-29T01:02:03Z'], np.dtype('M8[s]')),
np.array(['-1980-02-29 01:02:03Z'], np.dtype('M8[s]')))
# Time zone offset
assert_equal(np.array(['1980-02-29T02:02:03Z'], np.dtype('M8[s]')),
np.array(['1980-02-29 00:32:03-0130'], np.dtype('M8[s]')))
assert_equal(np.array(['1980-02-28T22:32:03Z'], np.dtype('M8[s]')),
np.array(['1980-02-29 00:02:03+01:30'], np.dtype('M8[s]')))
assert_equal(np.array(['1980-02-29T02:32:03.506Z'], np.dtype('M8[s]')),
np.array(['1980-02-29 00:32:03.506-02'], np.dtype('M8[s]')))
assert_equal(np.datetime64('1977-03-02T12:30-0230'),
np.datetime64('1977-03-02T15:00Z'))
def test_string_parser_error_check(self):
# Arbitrary bad string
assert_raises(ValueError, np.array, ['badvalue'], np.dtype('M8[us]'))
# Character after year must be '-'
assert_raises(ValueError, np.array, ['1980X'], np.dtype('M8[us]'))
# Cannot have trailing '-'
assert_raises(ValueError, np.array, ['1980-'], np.dtype('M8[us]'))
# Month must be in range [1,12]
assert_raises(ValueError, np.array, ['1980-00'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-13'], np.dtype('M8[us]'))
# Month must have two digits
assert_raises(ValueError, np.array, ['1980-1'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-1-02'], np.dtype('M8[us]'))
# 'Mor' is not a valid month
assert_raises(ValueError, np.array, ['1980-Mor'], np.dtype('M8[us]'))
# Cannot have trailing '-'
assert_raises(ValueError, np.array, ['1980-01-'], np.dtype('M8[us]'))
# Day must be in range [1,len(month)]
assert_raises(ValueError, np.array, ['1980-01-0'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-01-00'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-01-32'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1979-02-29'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-30'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-03-32'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-04-31'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-05-32'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-06-31'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-07-32'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-08-32'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-09-31'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-10-32'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-11-31'], np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-12-32'], np.dtype('M8[us]'))
# Cannot have trailing characters
assert_raises(ValueError, np.array, ['1980-02-03%'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 q'],
np.dtype('M8[us]'))
# Hours must be in range [0, 23]
assert_raises(ValueError, np.array, ['1980-02-03 25'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03T25'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 24:01'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03T24:01'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 -1'],
np.dtype('M8[us]'))
# No trailing ':'
assert_raises(ValueError, np.array, ['1980-02-03 01:'],
np.dtype('M8[us]'))
# Minutes must be in range [0, 59]
assert_raises(ValueError, np.array, ['1980-02-03 01:-1'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 01:60'],
np.dtype('M8[us]'))
# No trailing ':'
assert_raises(ValueError, np.array, ['1980-02-03 01:60:'],
np.dtype('M8[us]'))
# Seconds must be in range [0, 59]
assert_raises(ValueError, np.array, ['1980-02-03 01:10:-1'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 01:01:60'],
np.dtype('M8[us]'))
# Timezone offset must within a reasonable range
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00+0661'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00+2500'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00-0070'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00-3000'],
np.dtype('M8[us]'))
assert_raises(ValueError, np.array, ['1980-02-03 01:01:00-25:00'],
np.dtype('M8[us]'))
def test_creation_overflow(self):
date = '1980-03-23 20:00:00Z'
timesteps = np.array([date], dtype='datetime64[s]')[0].astype(np.int64)
for unit in ['ms', 'us', 'ns']:
timesteps *= 1000
x = np.array([date], dtype='datetime64[%s]' % unit)
assert_equal(timesteps, x[0].astype(np.int64),
err_msg='Datetime conversion error for unit %s' % unit)
assert_equal(x[0].astype(np.int64), 322689600000000000)
def test_datetime_as_string(self):
# Check all the units with default string conversion
date = '1959-10-13'
datetime = '1959-10-13T12:34:56.789012345678901234Z'
assert_equal(np.datetime_as_string(np.datetime64(date, 'Y')),
'1959')
assert_equal(np.datetime_as_string(np.datetime64(date, 'M')),
'1959-10')
assert_equal(np.datetime_as_string(np.datetime64(date, 'D')),
'1959-10-13')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'h')),
'1959-10-13T12Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'm')),
'1959-10-13T12:34Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 's')),
'1959-10-13T12:34:56Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'ms')),
'1959-10-13T12:34:56.789Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'us')),
'1959-10-13T12:34:56.789012Z')
datetime = '1969-12-31T23:34:56.789012345678901234Z'
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'ns')),
'1969-12-31T23:34:56.789012345Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'ps')),
'1969-12-31T23:34:56.789012345678Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'fs')),
'1969-12-31T23:34:56.789012345678901Z')
datetime = '1969-12-31T23:59:57.789012345678901234Z'
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'as')),
datetime)
datetime = '1970-01-01T00:34:56.789012345678901234Z'
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'ns')),
'1970-01-01T00:34:56.789012345Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'ps')),
'1970-01-01T00:34:56.789012345678Z')
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'fs')),
'1970-01-01T00:34:56.789012345678901Z')
datetime = '1970-01-01T00:00:05.789012345678901234Z'
assert_equal(np.datetime_as_string(np.datetime64(datetime, 'as')),
datetime)
# String conversion with the unit= parameter
a = np.datetime64('2032-07-18T12:23:34.123456Z', 'us')
assert_equal(np.datetime_as_string(a, unit='Y', casting='unsafe'),
'2032')
assert_equal(np.datetime_as_string(a, unit='M', casting='unsafe'),
'2032-07')
assert_equal(np.datetime_as_string(a, unit='W', casting='unsafe'),
'2032-07-18')
assert_equal(np.datetime_as_string(a, unit='D', casting='unsafe'),
'2032-07-18')
assert_equal(np.datetime_as_string(a, unit='h'), '2032-07-18T12Z')
assert_equal(np.datetime_as_string(a, unit='m'),
'2032-07-18T12:23Z')
assert_equal(np.datetime_as_string(a, unit='s'),
'2032-07-18T12:23:34Z')
assert_equal(np.datetime_as_string(a, unit='ms'),
'2032-07-18T12:23:34.123Z')
assert_equal(np.datetime_as_string(a, unit='us'),
'2032-07-18T12:23:34.123456Z')
assert_equal(np.datetime_as_string(a, unit='ns'),
'2032-07-18T12:23:34.123456000Z')
assert_equal(np.datetime_as_string(a, unit='ps'),
'2032-07-18T12:23:34.123456000000Z')
assert_equal(np.datetime_as_string(a, unit='fs'),
'2032-07-18T12:23:34.123456000000000Z')
assert_equal(np.datetime_as_string(a, unit='as'),
'2032-07-18T12:23:34.123456000000000000Z')
# unit='auto' parameter
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:34.123456Z', 'us'),
unit='auto'),
'2032-07-18T12:23:34.123456Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:34.12Z', 'us'),
unit='auto'),
'2032-07-18T12:23:34.120Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:34Z', 'us'),
unit='auto'),
'2032-07-18T12:23:34Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:23:00Z', 'us'),
unit='auto'),
'2032-07-18T12:23Z')
# 'auto' doesn't split up hour and minute
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T12:00:00Z', 'us'),
unit='auto'),
'2032-07-18T12:00Z')
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-18T00:00:00Z', 'us'),
unit='auto'),
'2032-07-18')
# 'auto' doesn't split up the date
assert_equal(np.datetime_as_string(
np.datetime64('2032-07-01T00:00:00Z', 'us'),
unit='auto'),
'2032-07-01')
assert_equal(np.datetime_as_string(
np.datetime64('2032-01-01T00:00:00Z', 'us'),
unit='auto'),
'2032-01-01')
@dec.skipif(not _has_pytz, "The pytz module is not available.")
def test_datetime_as_string_timezone(self):
# timezone='local' vs 'UTC'
a = np.datetime64('2010-03-15T06:30Z', 'm')
assert_equal(np.datetime_as_string(a, timezone='UTC'),
'2010-03-15T06:30Z')
assert_(np.datetime_as_string(a, timezone='local') !=
'2010-03-15T06:30Z')
b = np.datetime64('2010-02-15T06:30Z', 'm')
assert_equal(np.datetime_as_string(a, timezone=tz('US/Central')),
'2010-03-15T01:30-0500')
assert_equal(np.datetime_as_string(a, timezone=tz('US/Eastern')),
'2010-03-15T02:30-0400')
assert_equal(np.datetime_as_string(a, timezone=tz('US/Pacific')),
'2010-03-14T23:30-0700')
assert_equal(np.datetime_as_string(b, timezone=tz('US/Central')),
'2010-02-15T00:30-0600')
assert_equal(np.datetime_as_string(b, timezone=tz('US/Eastern')),
'2010-02-15T01:30-0500')
assert_equal(np.datetime_as_string(b, timezone=tz('US/Pacific')),
'2010-02-14T22:30-0800')
# Dates to strings with a timezone attached is disabled by default
assert_raises(TypeError, np.datetime_as_string, a, unit='D',
timezone=tz('US/Pacific'))
# Check that we can print out the date in the specified time zone
assert_equal(np.datetime_as_string(a, unit='D',
timezone=tz('US/Pacific'), casting='unsafe'),
'2010-03-14')
assert_equal(np.datetime_as_string(b, unit='D',
timezone=tz('US/Central'), casting='unsafe'),
'2010-02-15')
def test_datetime_arange(self):
# With two datetimes provided as strings
a = np.arange('2010-01-05', '2010-01-10', dtype='M8[D]')
assert_equal(a.dtype, np.dtype('M8[D]'))
assert_equal(a,
np.array(['2010-01-05', '2010-01-06', '2010-01-07',
'2010-01-08', '2010-01-09'], dtype='M8[D]'))
a = np.arange('1950-02-10', '1950-02-06', -1, dtype='M8[D]')
assert_equal(a.dtype, np.dtype('M8[D]'))
assert_equal(a,
np.array(['1950-02-10', '1950-02-09', '1950-02-08',
'1950-02-07'], dtype='M8[D]'))
# Unit should be detected as months here
a = np.arange('1969-05', '1970-05', 2, dtype='M8')
assert_equal(a.dtype, np.dtype('M8[M]'))
assert_equal(a,
np.datetime64('1969-05') + np.arange(12, step=2))
# datetime, integer|timedelta works as well
# produces arange (start, start + stop) in this case
a = np.arange('1969', 18, 3, dtype='M8')
assert_equal(a.dtype, np.dtype('M8[Y]'))
assert_equal(a,
np.datetime64('1969') + np.arange(18, step=3))
a = np.arange('1969-12-19', 22, np.timedelta64(2), dtype='M8')
assert_equal(a.dtype, np.dtype('M8[D]'))
assert_equal(a,
np.datetime64('1969-12-19') + np.arange(22, step=2))
# Step of 0 is disallowed
assert_raises(ValueError, np.arange, np.datetime64('today'),
np.datetime64('today') + 3, 0)
# Promotion across nonlinear unit boundaries is disallowed
assert_raises(TypeError, np.arange, np.datetime64('2011-03-01', 'D'),
np.timedelta64(5, 'M'))
assert_raises(TypeError, np.arange,
np.datetime64('2012-02-03T14Z', 's'),
np.timedelta64(5, 'Y'))
def test_datetime_arange_no_dtype(self):
d = np.array('2010-01-04', dtype="M8[D]")
assert_equal(np.arange(d, d + 1), d)
assert_raises(ValueError, np.arange, d)
def test_timedelta_arange(self):
a = np.arange(3, 10, dtype='m8')
assert_equal(a.dtype, np.dtype('m8'))
assert_equal(a, np.timedelta64(0) + np.arange(3, 10))
a = np.arange(np.timedelta64(3, 's'), 10, 2, dtype='m8')
assert_equal(a.dtype, np.dtype('m8[s]'))
assert_equal(a, np.timedelta64(0, 's') + np.arange(3, 10, 2))
# Step of 0 is disallowed
assert_raises(ValueError, np.arange, np.timedelta64(0),
np.timedelta64(5), 0)
# Promotion across nonlinear unit boundaries is disallowed
assert_raises(TypeError, np.arange, np.timedelta64(0, 'D'),
np.timedelta64(5, 'M'))
assert_raises(TypeError, np.arange, np.timedelta64(0, 'Y'),
np.timedelta64(5, 'D'))
def test_timedelta_arange_no_dtype(self):
d = np.array(5, dtype="m8[D]")
assert_equal(np.arange(d, d + 1), d)
assert_raises(ValueError, np.arange, d)
def test_datetime_maximum_reduce(self):
a = np.array(['2010-01-02', '1999-03-14', '1833-03'], dtype='M8[D]')
assert_equal(np.maximum.reduce(a).dtype, np.dtype('M8[D]'))
assert_equal(np.maximum.reduce(a),
np.datetime64('2010-01-02'))
a = np.array([1, 4, 0, 7, 2], dtype='m8[s]')
assert_equal(np.maximum.reduce(a).dtype, np.dtype('m8[s]'))
assert_equal(np.maximum.reduce(a),
np.timedelta64(7, 's'))
def test_datetime_busday_offset(self):
# First Monday in June
assert_equal(
np.busday_offset('2011-06', 0, roll='forward', weekmask='Mon'),
np.datetime64('2011-06-06'))
# Last Monday in June
assert_equal(
np.busday_offset('2011-07', -1, roll='forward', weekmask='Mon'),
np.datetime64('2011-06-27'))
assert_equal(
np.busday_offset('2011-07', -1, roll='forward', weekmask='Mon'),
np.datetime64('2011-06-27'))
# Default M-F business days, different roll modes
assert_equal(np.busday_offset('2010-08', 0, roll='backward'),
np.datetime64('2010-07-30'))
assert_equal(np.busday_offset('2010-08', 0, roll='preceding'),
np.datetime64('2010-07-30'))
assert_equal(np.busday_offset('2010-08', 0, roll='modifiedpreceding'),
np.datetime64('2010-08-02'))
assert_equal(np.busday_offset('2010-08', 0, roll='modifiedfollowing'),
np.datetime64('2010-08-02'))
assert_equal(np.busday_offset('2010-08', 0, roll='forward'),
np.datetime64('2010-08-02'))
assert_equal(np.busday_offset('2010-08', 0, roll='following'),
np.datetime64('2010-08-02'))
assert_equal(np.busday_offset('2010-10-30', 0, roll='following'),
np.datetime64('2010-11-01'))
assert_equal(
np.busday_offset('2010-10-30', 0, roll='modifiedfollowing'),
np.datetime64('2010-10-29'))
assert_equal(
np.busday_offset('2010-10-30', 0, roll='modifiedpreceding'),
np.datetime64('2010-10-29'))
# roll='raise' by default
assert_raises(ValueError, np.busday_offset, '2011-06-04', 0)
# Bigger offset values
assert_equal(np.busday_offset('2006-02-01', 25),
np.datetime64('2006-03-08'))
assert_equal(np.busday_offset('2006-03-08', -25),
np.datetime64('2006-02-01'))
assert_equal(np.busday_offset('2007-02-25', 11, weekmask='SatSun'),
np.datetime64('2007-04-07'))
assert_equal(np.busday_offset('2007-04-07', -11, weekmask='SatSun'),
np.datetime64('2007-02-25'))
def test_datetime_busdaycalendar(self):
# Check that it removes NaT, duplicates, and weekends
# and sorts the result.
bdd = np.busdaycalendar(
holidays=['NaT', '2011-01-17', '2011-03-06', 'NaT',
'2011-12-26', '2011-05-30', '2011-01-17'])
assert_equal(bdd.holidays,
np.array(['2011-01-17', '2011-05-30', '2011-12-26'], dtype='M8'))
# Default M-F weekmask
assert_equal(bdd.weekmask, np.array([1, 1, 1, 1, 1, 0, 0], dtype='?'))
# Check string weekmask with varying whitespace.
bdd = np.busdaycalendar(weekmask="Sun TueWed Thu\tFri")
assert_equal(bdd.weekmask, np.array([0, 1, 1, 1, 1, 0, 1], dtype='?'))
# Check length 7 0/1 string
bdd = np.busdaycalendar(weekmask="0011001")
assert_equal(bdd.weekmask, np.array([0, 0, 1, 1, 0, 0, 1], dtype='?'))
# Check length 7 string weekmask.
bdd = np.busdaycalendar(weekmask="Mon Tue")
assert_equal(bdd.weekmask, np.array([1, 1, 0, 0, 0, 0, 0], dtype='?'))
# All-zeros weekmask should raise
assert_raises(ValueError, np.busdaycalendar, weekmask=[0, 0, 0, 0, 0, 0, 0])
# weekday names must be correct case
assert_raises(ValueError, np.busdaycalendar, weekmask="satsun")
# All-zeros weekmask should raise
assert_raises(ValueError, np.busdaycalendar, weekmask="")
# Invalid weekday name codes should raise
assert_raises(ValueError, np.busdaycalendar, weekmask="Mon Tue We")
assert_raises(ValueError, np.busdaycalendar, weekmask="Max")
assert_raises(ValueError, np.busdaycalendar, weekmask="Monday Tue")
def test_datetime_busday_holidays_offset(self):
# With exactly one holiday
assert_equal(
np.busday_offset('2011-11-10', 1, holidays=['2011-11-11']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-04', 5, holidays=['2011-11-11']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-10', 5, holidays=['2011-11-11']),
np.datetime64('2011-11-18'))
assert_equal(
np.busday_offset('2011-11-14', -1, holidays=['2011-11-11']),
np.datetime64('2011-11-10'))
assert_equal(
np.busday_offset('2011-11-18', -5, holidays=['2011-11-11']),
np.datetime64('2011-11-10'))
assert_equal(
np.busday_offset('2011-11-14', -5, holidays=['2011-11-11']),
np.datetime64('2011-11-04'))
# With the holiday appearing twice
assert_equal(
np.busday_offset('2011-11-10', 1,
holidays=['2011-11-11', '2011-11-11']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-14', -1,
holidays=['2011-11-11', '2011-11-11']),
np.datetime64('2011-11-10'))
# With a NaT holiday
assert_equal(
np.busday_offset('2011-11-10', 1,
holidays=['2011-11-11', 'NaT']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-14', -1,
holidays=['NaT', '2011-11-11']),
np.datetime64('2011-11-10'))
# With another holiday after
assert_equal(
np.busday_offset('2011-11-10', 1,
holidays=['2011-11-11', '2011-11-24']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-14', -1,
holidays=['2011-11-11', '2011-11-24']),
np.datetime64('2011-11-10'))
# With another holiday before
assert_equal(
np.busday_offset('2011-11-10', 1,
holidays=['2011-10-10', '2011-11-11']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-14', -1,
holidays=['2011-10-10', '2011-11-11']),
np.datetime64('2011-11-10'))
# With another holiday before and after
assert_equal(
np.busday_offset('2011-11-10', 1,
holidays=['2011-10-10', '2011-11-11', '2011-11-24']),
np.datetime64('2011-11-14'))
assert_equal(
np.busday_offset('2011-11-14', -1,
holidays=['2011-10-10', '2011-11-11', '2011-11-24']),
np.datetime64('2011-11-10'))
# A bigger forward jump across more than one week/holiday
holidays=['2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21',
'2011-12-26', '2012-01-02']
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)
assert_equal(
np.busday_offset('2011-10-03', 4, holidays=holidays),
np.busday_offset('2011-10-03', 4))
assert_equal(
np.busday_offset('2011-10-03', 5, holidays=holidays),
np.busday_offset('2011-10-03', 5 + 1))
assert_equal(
np.busday_offset('2011-10-03', 27, holidays=holidays),
np.busday_offset('2011-10-03', 27 + 1))
assert_equal(
np.busday_offset('2011-10-03', 28, holidays=holidays),
np.busday_offset('2011-10-03', 28 + 2))
assert_equal(
np.busday_offset('2011-10-03', 35, holidays=holidays),
np.busday_offset('2011-10-03', 35 + 2))
assert_equal(
np.busday_offset('2011-10-03', 36, holidays=holidays),
np.busday_offset('2011-10-03', 36 + 3))
assert_equal(
np.busday_offset('2011-10-03', 56, holidays=holidays),
np.busday_offset('2011-10-03', 56 + 3))
assert_equal(
np.busday_offset('2011-10-03', 57, holidays=holidays),
np.busday_offset('2011-10-03', 57 + 4))
assert_equal(
np.busday_offset('2011-10-03', 60, holidays=holidays),
np.busday_offset('2011-10-03', 60 + 4))
assert_equal(
np.busday_offset('2011-10-03', 61, holidays=holidays),
np.busday_offset('2011-10-03', 61 + 5))
assert_equal(
np.busday_offset('2011-10-03', 61, busdaycal=bdd),
np.busday_offset('2011-10-03', 61 + 5))
# A bigger backward jump across more than one week/holiday
assert_equal(
np.busday_offset('2012-01-03', -1, holidays=holidays),
np.busday_offset('2012-01-03', -1 - 1))
assert_equal(
np.busday_offset('2012-01-03', -4, holidays=holidays),
np.busday_offset('2012-01-03', -4 - 1))
assert_equal(
np.busday_offset('2012-01-03', -5, holidays=holidays),
np.busday_offset('2012-01-03', -5 - 2))
assert_equal(
np.busday_offset('2012-01-03', -25, holidays=holidays),
np.busday_offset('2012-01-03', -25 - 2))
assert_equal(
np.busday_offset('2012-01-03', -26, holidays=holidays),
np.busday_offset('2012-01-03', -26 - 3))
assert_equal(
np.busday_offset('2012-01-03', -33, holidays=holidays),
np.busday_offset('2012-01-03', -33 - 3))
assert_equal(
np.busday_offset('2012-01-03', -34, holidays=holidays),
np.busday_offset('2012-01-03', -34 - 4))
assert_equal(
np.busday_offset('2012-01-03', -56, holidays=holidays),
np.busday_offset('2012-01-03', -56 - 4))
assert_equal(
np.busday_offset('2012-01-03', -57, holidays=holidays),
np.busday_offset('2012-01-03', -57 - 5))
assert_equal(
np.busday_offset('2012-01-03', -57, busdaycal=bdd),
np.busday_offset('2012-01-03', -57 - 5))
# Can't supply both a weekmask/holidays and busdaycal
assert_raises(ValueError, np.busday_offset, '2012-01-03', -15,
weekmask='1111100', busdaycal=bdd)
assert_raises(ValueError, np.busday_offset, '2012-01-03', -15,
holidays=holidays, busdaycal=bdd)
# Roll with the holidays
assert_equal(
np.busday_offset('2011-12-25', 0,
roll='forward', holidays=holidays),
np.datetime64('2011-12-27'))
assert_equal(
np.busday_offset('2011-12-26', 0,
roll='forward', holidays=holidays),
np.datetime64('2011-12-27'))
assert_equal(
np.busday_offset('2011-12-26', 0,
roll='backward', holidays=holidays),
np.datetime64('2011-12-23'))
assert_equal(
np.busday_offset('2012-02-27', 0,
roll='modifiedfollowing',
holidays=['2012-02-27', '2012-02-26', '2012-02-28',
'2012-03-01', '2012-02-29']),
np.datetime64('2012-02-24'))
assert_equal(
np.busday_offset('2012-03-06', 0,
roll='modifiedpreceding',
holidays=['2012-03-02', '2012-03-03', '2012-03-01',
'2012-03-05', '2012-03-07', '2012-03-06']),
np.datetime64('2012-03-08'))
def test_datetime_busday_holidays_count(self):
holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10']
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)
# Validate against busday_offset broadcast against
# a range of offsets
dates = np.busday_offset('2011-01-01', np.arange(366),
roll='forward', busdaycal=bdd)
assert_equal(np.busday_count('2011-01-01', dates, busdaycal=bdd),
np.arange(366))
# Returns negative value when reversed
assert_equal(np.busday_count(dates, '2011-01-01', busdaycal=bdd),
-np.arange(366))
dates = np.busday_offset('2011-12-31', -np.arange(366),
roll='forward', busdaycal=bdd)
assert_equal(np.busday_count(dates, '2011-12-31', busdaycal=bdd),
np.arange(366))
# Returns negative value when reversed
assert_equal(np.busday_count('2011-12-31', dates, busdaycal=bdd),
-np.arange(366))
# Can't supply both a weekmask/holidays and busdaycal
assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03',
weekmask='1111100', busdaycal=bdd)
assert_raises(ValueError, np.busday_offset, '2012-01-03', '2012-02-03',
holidays=holidays, busdaycal=bdd)
# Number of Mondays in March 2011
assert_equal(np.busday_count('2011-03', '2011-04', weekmask='Mon'), 4)
# Returns negative value when reversed
assert_equal(np.busday_count('2011-04', '2011-03', weekmask='Mon'), -4)
def test_datetime_is_busday(self):
holidays=['2011-01-01', '2011-10-10', '2011-11-11', '2011-11-24',
'2011-12-25', '2011-05-30', '2011-02-21', '2011-01-17',
'2011-12-26', '2012-01-02', '2011-02-21', '2011-05-30',
'2011-07-01', '2011-07-04', '2011-09-05', '2011-10-10',
'NaT']
bdd = np.busdaycalendar(weekmask='1111100', holidays=holidays)
# Weekend/weekday tests
assert_equal(np.is_busday('2011-01-01'), False)
assert_equal(np.is_busday('2011-01-02'), False)
assert_equal(np.is_busday('2011-01-03'), True)
# All the holidays are not business days
assert_equal(np.is_busday(holidays, busdaycal=bdd),
np.zeros(len(holidays), dtype='?'))
def test_datetime_y2038(self):
# Test parsing on either side of the Y2038 boundary
a = np.datetime64('2038-01-19T03:14:07Z')
assert_equal(a.view(np.int64), 2**31 - 1)
a = np.datetime64('2038-01-19T03:14:08Z')
assert_equal(a.view(np.int64), 2**31)
# Test parsing on either side of the Y2038 boundary with
# a manually specified timezone offset
a = np.datetime64('2038-01-19T04:14:07+0100')
assert_equal(a.view(np.int64), 2**31 - 1)
a = np.datetime64('2038-01-19T04:14:08+0100')
assert_equal(a.view(np.int64), 2**31)
# Test parsing a date after Y2038 in the local timezone
a = np.datetime64('2038-01-20T13:21:14')
assert_equal(str(a)[:-5], '2038-01-20T13:21:14')
class TestDateTimeData(TestCase):
def test_basic(self):
a = np.array(['1980-03-23'], dtype=np.datetime64)
assert_equal(np.datetime_data(a.dtype), ('D', 1))
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
12,
5927,
199,
646,
2680,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
627,
199,
504,
2680,
14,
5819,
492,
28217,
199,
646,
2197,
199,
199,
3,
3645,
15444,
370,
511,
734,
7750,
900,
18666,
340,
2808,
199,
893,
26,
272,
687,
15444,
492,
7137,
465,
5823,
272,
485,
1989,
63,
21948,
275,
715,
199,
2590,
3545,
26,
272,
485,
1989,
63,
21948,
275,
756,
421,
199,
533,
1379,
3926,
8,
1746,
304,
272,
347,
511,
63,
2083,
63,
2271,
63,
8782,
8,
277,
304,
267,
367,
4137,
315,
788,
57,
297,
283,
45,
297,
283,
55,
297,
283,
36,
297,
2151,
283,
72,
297,
283,
77,
297,
283,
83,
297,
283,
706,
297,
283,
527,
297,
2151,
283,
561,
297,
283,
1190,
297,
283,
2319,
297,
283,
305,
2565,
288,
4487,
17,
275,
980,
14,
2271,
360,
45,
24,
59,
27045,
5,
83,
61,
5956,
3248,
9,
288,
702,
2531,
3583,
17,
508,
980,
14,
2271,
360,
2083,
772,
59,
27045,
5,
83,
6616,
450,
4137,
430,
288,
4487,
18,
275,
980,
14,
2271,
360,
77,
24,
9722,
83,
6616,
450,
4137,
9,
288,
702,
2531,
3583,
18,
508,
980,
14,
2271,
360,
7473,
772,
9722,
83,
6616,
450,
4137,
430,
398,
327,
8307,
6204,
9296,
1133,
1050,
942,
370,
314,
1284,
267,
702,
63,
1452,
8,
495,
8,
1590,
14,
2271,
480,
45,
24,
8150,
298,
2083,
772,
531,
398,
327,
7719,
506,
3962,
370,
4165,
314,
17638,
4171,
267,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
45,
24,
1288,
980,
14,
2271,
480,
45,
24,
2237,
267,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
45,
24,
59,
83,
31937,
980,
14,
2271,
480,
45,
24,
59,
83,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
45,
24,
531,
508,
980,
14,
2271,
480,
45,
24,
531,
503,
355,
980,
14,
2271,
6757,
45,
24,
531,
508,
980,
14,
2271,
480,
45,
24,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
45,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
45,
24,
59,
36,
12523,
503,
355,
980,
14,
2271,
6757,
45,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
45,
24,
59,
36,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
45,
24,
531,
1137,
980,
14,
2271,
6757,
45,
24,
2237,
398,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
77,
24,
1288,
980,
14,
2271,
480,
77,
24,
2237,
267,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
77,
24,
59,
83,
31937,
980,
14,
2271,
480,
77,
24,
59,
83,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
77,
24,
531,
508,
980,
14,
2271,
480,
77,
24,
531,
503,
355,
980,
14,
2271,
6757,
77,
24,
531,
508,
980,
14,
2271,
480,
77,
24,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
77,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
77,
24,
59,
36,
12523,
503,
355,
980,
14,
2271,
6757,
77,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
77,
24,
59,
36,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
77,
24,
531,
1137,
980,
14,
2271,
6757,
77,
24,
2237,
398,
327,
2670,
626,
314,
1798,
17100,
83,
4875,
2197,
2943,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
45,
24,
59,
4087,
3248,
10374,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
77,
24,
59,
4087,
3248,
10374,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
45,
24,
59,
7080,
10374,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
77,
24,
59,
7080,
10374,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
77,
20,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
45,
23,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
77,
23,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
45,
975,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
77,
975,
358,
339,
347,
511,
63,
2083,
63,
2931,
316,
63,
4423,
8,
277,
304,
267,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
3382,
6871,
436,
2197,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
77,
24,
297,
283,
45,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
45,
24,
297,
283,
77,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
77,
24,
297,
283,
45,
24,
297,
22883,
534,
3489,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
45,
24,
297,
283,
77,
24,
297,
22883,
534,
3489,
1333,
398,
327,
6855,
9106,
19353,
15,
7191,
63,
5091,
687,
3000,
370,
6871,
267,
702,
2531,
1590,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
77,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1590,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
77,
24,
297,
22883,
534,
3489,
1333,
398,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
687,
2069,
370,
6871,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
70,
20,
297,
283,
77,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
70,
20,
297,
283,
77,
24,
297,
22883,
534,
3489,
1333,
398,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
687,
3000,
370,
2197,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
45,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
45,
24,
297,
22883,
534,
3489,
1333,
398,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
687,
2155,
370,
2197,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
66,
17,
297,
283,
45,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
12,
5927,
199,
646,
2680,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
627,
199,
504,
2680,
14,
5819,
492,
28217,
199,
646,
2197,
199,
199,
3,
3645,
15444,
370,
511,
734,
7750,
900,
18666,
340,
2808,
199,
893,
26,
272,
687,
15444,
492,
7137,
465,
5823,
272,
485,
1989,
63,
21948,
275,
715,
199,
2590,
3545,
26,
272,
485,
1989,
63,
21948,
275,
756,
421,
199,
533,
1379,
3926,
8,
1746,
304,
272,
347,
511,
63,
2083,
63,
2271,
63,
8782,
8,
277,
304,
267,
367,
4137,
315,
788,
57,
297,
283,
45,
297,
283,
55,
297,
283,
36,
297,
2151,
283,
72,
297,
283,
77,
297,
283,
83,
297,
283,
706,
297,
283,
527,
297,
2151,
283,
561,
297,
283,
1190,
297,
283,
2319,
297,
283,
305,
2565,
288,
4487,
17,
275,
980,
14,
2271,
360,
45,
24,
59,
27045,
5,
83,
61,
5956,
3248,
9,
288,
702,
2531,
3583,
17,
508,
980,
14,
2271,
360,
2083,
772,
59,
27045,
5,
83,
6616,
450,
4137,
430,
288,
4487,
18,
275,
980,
14,
2271,
360,
77,
24,
9722,
83,
6616,
450,
4137,
9,
288,
702,
2531,
3583,
18,
508,
980,
14,
2271,
360,
7473,
772,
9722,
83,
6616,
450,
4137,
430,
398,
327,
8307,
6204,
9296,
1133,
1050,
942,
370,
314,
1284,
267,
702,
63,
1452,
8,
495,
8,
1590,
14,
2271,
480,
45,
24,
8150,
298,
2083,
772,
531,
398,
327,
7719,
506,
3962,
370,
4165,
314,
17638,
4171,
267,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
45,
24,
1288,
980,
14,
2271,
480,
45,
24,
2237,
267,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
45,
24,
59,
83,
31937,
980,
14,
2271,
480,
45,
24,
59,
83,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
45,
24,
531,
508,
980,
14,
2271,
480,
45,
24,
531,
503,
355,
980,
14,
2271,
6757,
45,
24,
531,
508,
980,
14,
2271,
480,
45,
24,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
45,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
45,
24,
59,
36,
12523,
503,
355,
980,
14,
2271,
6757,
45,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
45,
24,
59,
36,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
45,
24,
531,
1137,
980,
14,
2271,
6757,
45,
24,
2237,
398,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
77,
24,
1288,
980,
14,
2271,
480,
77,
24,
2237,
267,
702,
63,
1452,
8,
1590,
14,
2271,
480,
29,
77,
24,
59,
83,
31937,
980,
14,
2271,
480,
77,
24,
59,
83,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
77,
24,
531,
508,
980,
14,
2271,
480,
77,
24,
531,
503,
355,
980,
14,
2271,
6757,
77,
24,
531,
508,
980,
14,
2271,
480,
77,
24,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
77,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
77,
24,
59,
36,
12523,
503,
355,
980,
14,
2271,
6757,
77,
24,
59,
36,
12523,
508,
980,
14,
2271,
480,
77,
24,
59,
36,
61,
2237,
267,
702,
2531,
1590,
14,
2271,
19651,
77,
24,
531,
1137,
980,
14,
2271,
6757,
77,
24,
2237,
398,
327,
2670,
626,
314,
1798,
17100,
83,
4875,
2197,
2943,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
45,
24,
59,
4087,
3248,
10374,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
77,
24,
59,
4087,
3248,
10374,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
45,
24,
59,
7080,
10374,
267,
702,
63,
3536,
8,
4333,
12,
980,
14,
2271,
12,
283,
77,
24,
59,
7080,
10374,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
77,
20,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
45,
23,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
77,
23,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
45,
975,
358,
267,
702,
63,
19811,
8,
15561,
12,
980,
14,
2271,
12,
283,
77,
975,
358,
339,
347,
511,
63,
2083,
63,
2931,
316,
63,
4423,
8,
277,
304,
267,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
3382,
6871,
436,
2197,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
77,
24,
297,
283,
45,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
45,
24,
297,
283,
77,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
77,
24,
297,
283,
45,
24,
297,
22883,
534,
3489,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
45,
24,
297,
283,
77,
24,
297,
22883,
534,
3489,
1333,
398,
327,
6855,
9106,
19353,
15,
7191,
63,
5091,
687,
3000,
370,
6871,
267,
702,
2531,
1590,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
77,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1590,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
77,
24,
297,
22883,
534,
3489,
1333,
398,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
687,
2069,
370,
6871,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
70,
20,
297,
283,
77,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
70,
20,
297,
283,
77,
24,
297,
22883,
534,
3489,
1333,
398,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
687,
3000,
370,
2197,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
45,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
73,
24,
297,
283,
45,
24,
297,
22883,
534,
3489,
1333,
398,
327,
18435,
9106,
19353,
15,
7191,
63,
5091,
687,
2155,
370,
2197,
267,
702,
2531,
1397,
980,
14,
2425,
63,
2931,
360,
66,
17,
297,
283,
45,
24,
297,
22883,
534,
7191,
63,
5091,
1333,
267,
702,
2531,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ade/db/models.py
|
63
|
4420
|
# Copyright 2014 Brocade Communications System, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Brocade specific database schema/model."""
import sqlalchemy as sa
from neutron.db import model_base
from neutron.db import models_v2
class ML2_BrocadeNetwork(model_base.BASEV2, models_v2.HasId,
models_v2.HasTenant):
"""Schema for brocade network."""
vlan = sa.Column(sa.String(10))
segment_id = sa.Column(sa.String(36))
network_type = sa.Column(sa.String(10))
class ML2_BrocadePort(model_base.BASEV2, models_v2.HasId,
models_v2.HasTenant):
"""Schema for brocade port."""
network_id = sa.Column(sa.String(36),
sa.ForeignKey("ml2_brocadenetworks.id"),
nullable=False)
admin_state_up = sa.Column(sa.Boolean, nullable=False)
physical_interface = sa.Column(sa.String(36))
vlan_id = sa.Column(sa.String(36))
def create_network(context, net_id, vlan, segment_id, network_type, tenant_id):
"""Create a brocade specific network/port-profiles."""
# only network_type of vlan is supported
session = context.session
with session.begin(subtransactions=True):
net = get_network(context, net_id, None)
if not net:
net = ML2_BrocadeNetwork(id=net_id, vlan=vlan,
segment_id=segment_id,
network_type='vlan',
tenant_id=tenant_id)
session.add(net)
return net
def delete_network(context, net_id):
"""Delete a brocade specific network/port-profiles."""
session = context.session
with session.begin(subtransactions=True):
net = get_network(context, net_id, None)
if net:
session.delete(net)
def get_network(context, net_id, fields=None):
"""Get brocade specific network, with vlan extension."""
session = context.session
return session.query(ML2_BrocadeNetwork).filter_by(id=net_id).first()
def get_networks(context, filters=None, fields=None):
"""Get all brocade specific networks."""
session = context.session
return session.query(ML2_BrocadeNetwork).all()
def create_port(context, port_id, network_id, physical_interface,
vlan_id, tenant_id, admin_state_up):
"""Create a brocade specific port, has policy like vlan."""
session = context.session
with session.begin(subtransactions=True):
port = get_port(context, port_id)
if not port:
port = ML2_BrocadePort(id=port_id,
network_id=network_id,
physical_interface=physical_interface,
vlan_id=vlan_id,
admin_state_up=admin_state_up,
tenant_id=tenant_id)
session.add(port)
return port
def get_port(context, port_id):
"""get a brocade specific port."""
session = context.session
return session.query(ML2_BrocadePort).filter_by(id=port_id).first()
def get_ports(context, network_id=None):
"""get a brocade specific port."""
session = context.session
return session.query(ML2_BrocadePort).filter_by(
network_id=network_id).all()
def delete_port(context, port_id):
"""delete brocade specific port."""
session = context.session
with session.begin(subtransactions=True):
port = get_port(context, port_id)
if port:
session.delete(port)
def update_port_state(context, port_id, admin_state_up):
"""Update port attributes."""
session = context.session
with session.begin(subtransactions=True):
session.query(ML2_BrocadePort).filter_by(
id=port_id).update({'admin_state_up': admin_state_up})
|
apache-2.0
|
[
3,
1898,
6927,
699,
293,
9490,
18686,
6187,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
624,
34,
293,
9490,
2488,
3050,
4177,
15,
1238,
1041,
199,
646,
8335,
465,
2937,
199,
199,
504,
8224,
14,
697,
492,
1402,
63,
1095,
199,
504,
8224,
14,
697,
492,
1709,
63,
86,
18,
421,
199,
533,
28007,
18,
63,
34,
293,
9490,
4491,
8,
1238,
63,
1095,
14,
5825,
54,
18,
12,
1709,
63,
86,
18,
14,
6362,
1304,
12,
586,
1709,
63,
86,
18,
14,
6362,
27807,
304,
272,
408,
6700,
367,
330,
293,
9490,
2784,
1041,
339,
10119,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
709,
430,
272,
8135,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
430,
272,
2784,
63,
466,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
709,
430,
421,
199,
533,
28007,
18,
63,
34,
293,
9490,
4313,
8,
1238,
63,
1095,
14,
5825,
54,
18,
12,
1709,
63,
86,
18,
14,
6362,
1304,
12,
1993,
1709,
63,
86,
18,
14,
6362,
27807,
304,
272,
408,
6700,
367,
330,
293,
9490,
1844,
1041,
339,
2784,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
395,
2574,
2937,
14,
3190,
480,
757,
18,
63,
20670,
9490,
7642,
14,
344,
1288,
2574,
7854,
29,
797,
9,
272,
4628,
63,
929,
63,
384,
275,
2937,
14,
4547,
8,
2231,
14,
4082,
12,
7854,
29,
797,
9,
272,
14095,
63,
3266,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
430,
272,
10119,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
430,
421,
199,
318,
1218,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
10119,
12,
8135,
63,
344,
12,
2784,
63,
466,
12,
8261,
63,
344,
304,
272,
408,
2499,
282,
330,
293,
9490,
2488,
2784,
15,
719,
13,
11225,
1041,
339,
327,
1454,
2784,
63,
466,
402,
10119,
365,
3748,
272,
2351,
275,
1067,
14,
1730,
272,
543,
2351,
14,
5037,
8,
954,
13754,
29,
549,
304,
267,
1851,
275,
664,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
488,
9,
267,
340,
440,
1851,
26,
288,
1851,
275,
28007,
18,
63,
34,
293,
9490,
4491,
8,
344,
29,
846,
63,
344,
12,
10119,
29,
7175,
12,
3660,
8135,
63,
344,
29,
9255,
63,
344,
12,
3660,
2784,
63,
466,
534,
7175,
297,
3660,
8261,
63,
344,
29,
4647,
63,
344,
9,
288,
2351,
14,
525,
8,
846,
9,
272,
372,
1851,
421,
199,
318,
3145,
63,
1200,
8,
1100,
12,
1851,
63,
344,
304,
272,
408,
5392,
282,
330,
293,
9490,
2488,
2784,
15,
719,
13,
11225,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
543,
2351,
14,
5037,
8,
954,
13754,
29,
549,
304,
267,
1851,
275,
664,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
488,
9,
267,
340,
1851,
26,
288,
2351,
14,
1807,
8,
846,
9,
421,
199,
318,
664,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
1504,
29,
403,
304,
272,
408,
1002,
330,
293,
9490,
2488,
2784,
12,
543,
10119,
3329,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4491,
680,
1541,
63,
991,
8,
344,
29,
846,
63,
344,
680,
2246,
342,
421,
199,
318,
664,
63,
7642,
8,
1100,
12,
4766,
29,
403,
12,
1504,
29,
403,
304,
272,
408,
1002,
1006,
330,
293,
9490,
2488,
11759,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4491,
680,
452,
342,
421,
199,
318,
1218,
63,
719,
8,
1100,
12,
1844,
63,
344,
12,
2784,
63,
344,
12,
14095,
63,
3266,
12,
355,
10119,
63,
344,
12,
8261,
63,
344,
12,
4628,
63,
929,
63,
384,
304,
272,
408,
2499,
282,
330,
293,
9490,
2488,
1844,
12,
965,
4592,
2839,
10119,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
543,
2351,
14,
5037,
8,
954,
13754,
29,
549,
304,
267,
1844,
275,
664,
63,
719,
8,
1100,
12,
1844,
63,
344,
9,
267,
340,
440,
1844,
26,
288,
1844,
275,
28007,
18,
63,
34,
293,
9490,
4313,
8,
344,
29,
719,
63,
344,
12,
3521,
2784,
63,
344,
29,
1200,
63,
344,
12,
3521,
14095,
63,
3266,
29,
15020,
63,
3266,
12,
3521,
10119,
63,
344,
29,
7175,
63,
344,
12,
3521,
4628,
63,
929,
63,
384,
29,
2113,
63,
929,
63,
384,
12,
3521,
8261,
63,
344,
29,
4647,
63,
344,
9,
288,
2351,
14,
525,
8,
719,
9,
339,
372,
1844,
421,
199,
318,
664,
63,
719,
8,
1100,
12,
1844,
63,
344,
304,
272,
408,
362,
282,
330,
293,
9490,
2488,
1844,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4313,
680,
1541,
63,
991,
8,
344,
29,
719,
63,
344,
680,
2246,
342,
421,
199,
318,
664,
63,
5203,
8,
1100,
12,
2784,
63,
344,
29,
403,
304,
272,
408,
362,
282,
330,
293,
9490,
2488,
1844,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4313,
680,
1541,
63,
991,
8,
267,
2784,
63,
344,
29,
1200,
63,
344,
680,
452,
342,
421,
199,
318,
3145,
63,
719,
8,
1100,
12,
1844,
63,
344,
304
] |
[
1898,
6927,
699,
293,
9490,
18686,
6187,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
624,
34,
293,
9490,
2488,
3050,
4177,
15,
1238,
1041,
199,
646,
8335,
465,
2937,
199,
199,
504,
8224,
14,
697,
492,
1402,
63,
1095,
199,
504,
8224,
14,
697,
492,
1709,
63,
86,
18,
421,
199,
533,
28007,
18,
63,
34,
293,
9490,
4491,
8,
1238,
63,
1095,
14,
5825,
54,
18,
12,
1709,
63,
86,
18,
14,
6362,
1304,
12,
586,
1709,
63,
86,
18,
14,
6362,
27807,
304,
272,
408,
6700,
367,
330,
293,
9490,
2784,
1041,
339,
10119,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
709,
430,
272,
8135,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
430,
272,
2784,
63,
466,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
709,
430,
421,
199,
533,
28007,
18,
63,
34,
293,
9490,
4313,
8,
1238,
63,
1095,
14,
5825,
54,
18,
12,
1709,
63,
86,
18,
14,
6362,
1304,
12,
1993,
1709,
63,
86,
18,
14,
6362,
27807,
304,
272,
408,
6700,
367,
330,
293,
9490,
1844,
1041,
339,
2784,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
395,
2574,
2937,
14,
3190,
480,
757,
18,
63,
20670,
9490,
7642,
14,
344,
1288,
2574,
7854,
29,
797,
9,
272,
4628,
63,
929,
63,
384,
275,
2937,
14,
4547,
8,
2231,
14,
4082,
12,
7854,
29,
797,
9,
272,
14095,
63,
3266,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
430,
272,
10119,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
430,
421,
199,
318,
1218,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
10119,
12,
8135,
63,
344,
12,
2784,
63,
466,
12,
8261,
63,
344,
304,
272,
408,
2499,
282,
330,
293,
9490,
2488,
2784,
15,
719,
13,
11225,
1041,
339,
327,
1454,
2784,
63,
466,
402,
10119,
365,
3748,
272,
2351,
275,
1067,
14,
1730,
272,
543,
2351,
14,
5037,
8,
954,
13754,
29,
549,
304,
267,
1851,
275,
664,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
488,
9,
267,
340,
440,
1851,
26,
288,
1851,
275,
28007,
18,
63,
34,
293,
9490,
4491,
8,
344,
29,
846,
63,
344,
12,
10119,
29,
7175,
12,
3660,
8135,
63,
344,
29,
9255,
63,
344,
12,
3660,
2784,
63,
466,
534,
7175,
297,
3660,
8261,
63,
344,
29,
4647,
63,
344,
9,
288,
2351,
14,
525,
8,
846,
9,
272,
372,
1851,
421,
199,
318,
3145,
63,
1200,
8,
1100,
12,
1851,
63,
344,
304,
272,
408,
5392,
282,
330,
293,
9490,
2488,
2784,
15,
719,
13,
11225,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
543,
2351,
14,
5037,
8,
954,
13754,
29,
549,
304,
267,
1851,
275,
664,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
488,
9,
267,
340,
1851,
26,
288,
2351,
14,
1807,
8,
846,
9,
421,
199,
318,
664,
63,
1200,
8,
1100,
12,
1851,
63,
344,
12,
1504,
29,
403,
304,
272,
408,
1002,
330,
293,
9490,
2488,
2784,
12,
543,
10119,
3329,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4491,
680,
1541,
63,
991,
8,
344,
29,
846,
63,
344,
680,
2246,
342,
421,
199,
318,
664,
63,
7642,
8,
1100,
12,
4766,
29,
403,
12,
1504,
29,
403,
304,
272,
408,
1002,
1006,
330,
293,
9490,
2488,
11759,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4491,
680,
452,
342,
421,
199,
318,
1218,
63,
719,
8,
1100,
12,
1844,
63,
344,
12,
2784,
63,
344,
12,
14095,
63,
3266,
12,
355,
10119,
63,
344,
12,
8261,
63,
344,
12,
4628,
63,
929,
63,
384,
304,
272,
408,
2499,
282,
330,
293,
9490,
2488,
1844,
12,
965,
4592,
2839,
10119,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
543,
2351,
14,
5037,
8,
954,
13754,
29,
549,
304,
267,
1844,
275,
664,
63,
719,
8,
1100,
12,
1844,
63,
344,
9,
267,
340,
440,
1844,
26,
288,
1844,
275,
28007,
18,
63,
34,
293,
9490,
4313,
8,
344,
29,
719,
63,
344,
12,
3521,
2784,
63,
344,
29,
1200,
63,
344,
12,
3521,
14095,
63,
3266,
29,
15020,
63,
3266,
12,
3521,
10119,
63,
344,
29,
7175,
63,
344,
12,
3521,
4628,
63,
929,
63,
384,
29,
2113,
63,
929,
63,
384,
12,
3521,
8261,
63,
344,
29,
4647,
63,
344,
9,
288,
2351,
14,
525,
8,
719,
9,
339,
372,
1844,
421,
199,
318,
664,
63,
719,
8,
1100,
12,
1844,
63,
344,
304,
272,
408,
362,
282,
330,
293,
9490,
2488,
1844,
1041,
339,
2351,
275,
1067,
14,
1730,
272,
372,
2351,
14,
1131,
8,
1698,
18,
63,
34,
293,
9490,
4313,
680,
1541,
63,
991,
8,
344,
29,
719,
63,
344,
680,
2246,
342,
421,
199,
318,
664,
63,
5203,
8,
1100,
12,
2784,
63,
344,
29,
403,
304,
272,
408,
362,
282,
330,
293,
9490,
2488,
1844,
1041,
339,
2351,
275,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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
] |
tanyunshi/python-docx
|
tests/oxml/unitdata/text.py
|
10
|
3187
|
# encoding: utf-8
"""
Test data builders for text XML elements
"""
from ...unitdata import BaseBuilder
from .shared import CT_OnOffBuilder, CT_StringBuilder
class CT_BrBuilder(BaseBuilder):
__tag__ = 'w:br'
__nspfxs__ = ('w',)
__attrs__ = ('w:type', 'w:clear')
class CT_EmptyBuilder(BaseBuilder):
__nspfxs__ = ('w',)
__attrs__ = ()
def __init__(self, tag):
self.__tag__ = tag
super(CT_EmptyBuilder, self).__init__()
class CT_JcBuilder(BaseBuilder):
__tag__ = 'w:jc'
__nspfxs__ = ('w',)
__attrs__ = ('w:val',)
class CT_PBuilder(BaseBuilder):
__tag__ = 'w:p'
__nspfxs__ = ('w',)
__attrs__ = ()
class CT_PPrBuilder(BaseBuilder):
__tag__ = 'w:pPr'
__nspfxs__ = ('w',)
__attrs__ = ()
class CT_RBuilder(BaseBuilder):
__tag__ = 'w:r'
__nspfxs__ = ('w',)
__attrs__ = ()
class CT_RPrBuilder(BaseBuilder):
__tag__ = 'w:rPr'
__nspfxs__ = ('w',)
__attrs__ = ()
class CT_SectPrBuilder(BaseBuilder):
__tag__ = 'w:sectPr'
__nspfxs__ = ('w',)
__attrs__ = ()
class CT_TextBuilder(BaseBuilder):
__tag__ = 'w:t'
__nspfxs__ = ('w',)
__attrs__ = ()
def with_space(self, value):
self._set_xmlattr('xml:space', str(value))
return self
class CT_UnderlineBuilder(BaseBuilder):
__tag__ = 'w:u'
__nspfxs__ = ('w',)
__attrs__ = (
'w:val', 'w:color', 'w:themeColor', 'w:themeTint', 'w:themeShade'
)
def a_b():
return CT_OnOffBuilder('w:b')
def a_bCs():
return CT_OnOffBuilder('w:bCs')
def a_br():
return CT_BrBuilder()
def a_caps():
return CT_OnOffBuilder('w:caps')
def a_cr():
return CT_EmptyBuilder('w:cr')
def a_cs():
return CT_OnOffBuilder('w:cs')
def a_dstrike():
return CT_OnOffBuilder('w:dstrike')
def a_jc():
return CT_JcBuilder()
def a_noProof():
return CT_OnOffBuilder('w:noProof')
def a_shadow():
return CT_OnOffBuilder('w:shadow')
def a_smallCaps():
return CT_OnOffBuilder('w:smallCaps')
def a_snapToGrid():
return CT_OnOffBuilder('w:snapToGrid')
def a_specVanish():
return CT_OnOffBuilder('w:specVanish')
def a_strike():
return CT_OnOffBuilder('w:strike')
def a_tab():
return CT_EmptyBuilder('w:tab')
def a_vanish():
return CT_OnOffBuilder('w:vanish')
def a_webHidden():
return CT_OnOffBuilder('w:webHidden')
def a_p():
return CT_PBuilder()
def a_pPr():
return CT_PPrBuilder()
def a_pStyle():
return CT_StringBuilder('w:pStyle')
def a_sectPr():
return CT_SectPrBuilder()
def a_t():
return CT_TextBuilder()
def a_u():
return CT_UnderlineBuilder()
def an_emboss():
return CT_OnOffBuilder('w:emboss')
def an_i():
return CT_OnOffBuilder('w:i')
def an_iCs():
return CT_OnOffBuilder('w:iCs')
def an_imprint():
return CT_OnOffBuilder('w:imprint')
def an_oMath():
return CT_OnOffBuilder('w:oMath')
def an_outline():
return CT_OnOffBuilder('w:outline')
def an_r():
return CT_RBuilder()
def an_rPr():
return CT_RPrBuilder()
def an_rStyle():
return CT_StringBuilder('w:rStyle')
def an_rtl():
return CT_OnOffBuilder('w:rtl')
|
mit
|
[
3,
2644,
26,
2774,
13,
24,
199,
199,
624,
199,
774,
666,
27378,
367,
1318,
4692,
4008,
199,
624,
199,
199,
504,
2263,
3248,
576,
492,
3523,
6437,
199,
504,
1275,
5555,
492,
24990,
63,
3314,
5195,
6437,
12,
24990,
63,
1558,
6437,
421,
199,
533,
24990,
63,
12771,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
3289,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
661,
87,
26,
466,
297,
283,
87,
26,
3584,
358,
421,
199,
533,
24990,
63,
4699,
6437,
8,
1563,
6437,
304,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
339,
347,
636,
826,
721,
277,
12,
1947,
304,
267,
291,
855,
1450,
363,
275,
1947,
267,
1613,
8,
1028,
63,
4699,
6437,
12,
291,
2843,
826,
4533,
421,
199,
533,
24990,
63,
42,
67,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
22760,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
661,
87,
26,
637,
9538,
421,
199,
533,
24990,
63,
48,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
80,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
7701,
82,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
80,
9779,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
50,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
82,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
50,
9779,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
82,
9779,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
51,
449,
9779,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
8519,
9779,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
1872,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
84,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
339,
347,
543,
63,
2638,
8,
277,
12,
574,
304,
267,
291,
423,
409,
63,
1652,
962,
360,
1652,
26,
2638,
297,
620,
8,
585,
430,
267,
372,
291,
421,
199,
533,
24990,
63,
16001,
604,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
85,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
334,
267,
283,
87,
26,
637,
297,
283,
87,
26,
2326,
297,
283,
87,
26,
7915,
4117,
297,
283,
87,
26,
7915,
52,
442,
297,
283,
87,
26,
7915,
23527,
271,
7,
272,
776,
421,
199,
318,
282,
63,
66,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
66,
358,
421,
199,
318,
282,
63,
66,
13912,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
66,
13912,
358,
421,
199,
318,
282,
63,
3289,
837,
272,
372,
24990,
63,
12771,
6437,
342,
421,
199,
318,
282,
63,
12029,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
12029,
358,
421,
199,
318,
282,
63,
1556,
837,
272,
372,
24990,
63,
4699,
6437,
360,
87,
26,
1556,
358,
421,
199,
318,
282,
63,
1259,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
1259,
358,
421,
199,
318,
282,
63,
68,
26845,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
68,
26845,
358,
421,
199,
318,
282,
63,
22760,
837,
272,
372,
24990,
63,
42,
67,
6437,
342,
421,
199,
318,
282,
63,
889,
919,
1618,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
889,
919,
1618,
358,
421,
199,
318,
282,
63,
14714,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
14714,
358,
421,
199,
318,
282,
63,
7241,
35,
7461,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
7241,
35,
7461,
358,
421,
199,
318,
282,
63,
10002,
1378,
7900,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
10002,
1378,
7900,
358,
421,
199,
318,
282,
63,
1650,
54,
290,
2453,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
1650,
54,
290,
2453,
358,
421,
199,
318,
282,
63,
26845,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
26845,
358,
421,
199,
318,
282,
63,
2902,
837,
272,
372,
24990,
63,
4699,
6437,
360,
87,
26,
2902,
358,
421,
199,
318,
282,
63,
20662,
2453,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
20662,
2453,
358,
421,
199,
318,
282,
63,
2520,
14983,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
2520,
14983,
358,
421,
199,
318,
282,
63,
80,
837,
272,
372,
24990,
63,
48,
6437,
342,
421,
199,
318,
282,
63,
80,
9779,
837,
272,
372,
24990,
63,
7701,
82,
6437,
342,
421,
199,
318,
282,
63,
80,
6609,
837,
272,
372,
24990,
63,
1558,
6437,
360,
87,
26,
80,
6609,
358,
421,
199,
318,
282,
63,
8519,
9779,
837,
272,
372,
24990,
63,
51,
449,
9779,
6437,
342,
421,
199,
318,
282,
63,
84,
837,
272,
372,
24990,
63,
1872,
6437,
342,
421,
199,
318,
282,
63,
85,
837,
272,
372,
24990,
63,
16001,
604,
6437,
342,
421,
199,
318,
376,
63,
5633,
25020,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
5633,
25020,
358,
421,
199,
318,
376,
63,
73,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
73,
358,
421,
199,
318,
376,
63,
73,
13912,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
73,
13912,
358,
421,
199,
318,
376,
63,
3236,
672,
837,
272,
372,
24990,
63,
3314,
5195
] |
[
2644,
26,
2774,
13,
24,
199,
199,
624,
199,
774,
666,
27378,
367,
1318,
4692,
4008,
199,
624,
199,
199,
504,
2263,
3248,
576,
492,
3523,
6437,
199,
504,
1275,
5555,
492,
24990,
63,
3314,
5195,
6437,
12,
24990,
63,
1558,
6437,
421,
199,
533,
24990,
63,
12771,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
3289,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
661,
87,
26,
466,
297,
283,
87,
26,
3584,
358,
421,
199,
533,
24990,
63,
4699,
6437,
8,
1563,
6437,
304,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
339,
347,
636,
826,
721,
277,
12,
1947,
304,
267,
291,
855,
1450,
363,
275,
1947,
267,
1613,
8,
1028,
63,
4699,
6437,
12,
291,
2843,
826,
4533,
421,
199,
533,
24990,
63,
42,
67,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
22760,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
661,
87,
26,
637,
9538,
421,
199,
533,
24990,
63,
48,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
80,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
7701,
82,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
80,
9779,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
50,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
82,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
50,
9779,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
82,
9779,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
51,
449,
9779,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
8519,
9779,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
421,
199,
533,
24990,
63,
1872,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
84,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
6248,
339,
347,
543,
63,
2638,
8,
277,
12,
574,
304,
267,
291,
423,
409,
63,
1652,
962,
360,
1652,
26,
2638,
297,
620,
8,
585,
430,
267,
372,
291,
421,
199,
533,
24990,
63,
16001,
604,
6437,
8,
1563,
6437,
304,
272,
636,
1450,
363,
275,
283,
87,
26,
85,
7,
272,
636,
561,
9928,
7977,
363,
275,
661,
87,
9538,
272,
636,
3288,
363,
275,
334,
267,
283,
87,
26,
637,
297,
283,
87,
26,
2326,
297,
283,
87,
26,
7915,
4117,
297,
283,
87,
26,
7915,
52,
442,
297,
283,
87,
26,
7915,
23527,
271,
7,
272,
776,
421,
199,
318,
282,
63,
66,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
66,
358,
421,
199,
318,
282,
63,
66,
13912,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
66,
13912,
358,
421,
199,
318,
282,
63,
3289,
837,
272,
372,
24990,
63,
12771,
6437,
342,
421,
199,
318,
282,
63,
12029,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
12029,
358,
421,
199,
318,
282,
63,
1556,
837,
272,
372,
24990,
63,
4699,
6437,
360,
87,
26,
1556,
358,
421,
199,
318,
282,
63,
1259,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
1259,
358,
421,
199,
318,
282,
63,
68,
26845,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
68,
26845,
358,
421,
199,
318,
282,
63,
22760,
837,
272,
372,
24990,
63,
42,
67,
6437,
342,
421,
199,
318,
282,
63,
889,
919,
1618,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
889,
919,
1618,
358,
421,
199,
318,
282,
63,
14714,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
14714,
358,
421,
199,
318,
282,
63,
7241,
35,
7461,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
7241,
35,
7461,
358,
421,
199,
318,
282,
63,
10002,
1378,
7900,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
10002,
1378,
7900,
358,
421,
199,
318,
282,
63,
1650,
54,
290,
2453,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
1650,
54,
290,
2453,
358,
421,
199,
318,
282,
63,
26845,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
26845,
358,
421,
199,
318,
282,
63,
2902,
837,
272,
372,
24990,
63,
4699,
6437,
360,
87,
26,
2902,
358,
421,
199,
318,
282,
63,
20662,
2453,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
20662,
2453,
358,
421,
199,
318,
282,
63,
2520,
14983,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
2520,
14983,
358,
421,
199,
318,
282,
63,
80,
837,
272,
372,
24990,
63,
48,
6437,
342,
421,
199,
318,
282,
63,
80,
9779,
837,
272,
372,
24990,
63,
7701,
82,
6437,
342,
421,
199,
318,
282,
63,
80,
6609,
837,
272,
372,
24990,
63,
1558,
6437,
360,
87,
26,
80,
6609,
358,
421,
199,
318,
282,
63,
8519,
9779,
837,
272,
372,
24990,
63,
51,
449,
9779,
6437,
342,
421,
199,
318,
282,
63,
84,
837,
272,
372,
24990,
63,
1872,
6437,
342,
421,
199,
318,
282,
63,
85,
837,
272,
372,
24990,
63,
16001,
604,
6437,
342,
421,
199,
318,
376,
63,
5633,
25020,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
5633,
25020,
358,
421,
199,
318,
376,
63,
73,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
73,
358,
421,
199,
318,
376,
63,
73,
13912,
837,
272,
372,
24990,
63,
3314,
5195,
6437,
360,
87,
26,
73,
13912,
358,
421,
199,
318,
376,
63,
3236,
672,
837,
272,
372,
24990,
63,
3314,
5195,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
forcedotcom/distributions
|
distributions/tests/test_random.py
|
1
|
10178
|
# Copyright (c) 2014, Salesforce.com, 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 Salesforce.com nor the names of its contributors
# may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import itertools
import numpy
import scipy
from nose.tools import (
assert_less,
assert_equal,
assert_almost_equal,
assert_raises,
assert_true,
)
from distributions.dbg.random import (
sample_stick,
sample_discrete_log,
sample_inverse_wishart,
score_student_t as dbg_score_student_t,
)
from distributions.lp.random import (
score_student_t as lp_score_student_t,
)
from distributions.dbg.models.nich import (
score_student_t as scalar_score_student_t,
)
from distributions.tests.util import (
require_cython,
assert_close,
assert_samples_match_scores,
seed_all,
)
SAMPLES = 1000
def assert_normal(x, y, sigma, stddevs=4.0):
'''
Assert that the difference between two values is within a few standard
deviations of the predicted [normally distributed] error of zero.
'''
assert_less(x, y + sigma * stddevs)
assert_less(y, x + sigma * stddevs)
def test_seed():
require_cython()
import distributions.hp.random
global_rng = distributions.hp.random.random
distributions.hp.random.seed(0)
values1 = [global_rng() for _ in xrange(10)]
distributions.hp.random.seed(0)
values2 = [global_rng() for _ in xrange(10)]
assert_equal(values1, values2)
def test_sample_discrete_log_underflow():
sample_discrete_log([-1e3])
sample_discrete_log([-1e3, -1e-3])
def test_sample_discrete_log():
assert_equal(sample_discrete_log([-1.]), 0)
assert_equal(sample_discrete_log([-1e3]), 0)
assert_equal(sample_discrete_log([-1e-3]), 0)
assert_equal(sample_discrete_log([-1., -1e3]), 0)
assert_equal(sample_discrete_log([-1e3, -1.]), 1)
assert_raises(Exception, sample_discrete_log, [])
def test_sample_stick():
gammas = [.1, 1., 5., 10.]
for gamma in gammas:
for _ in range(5):
betas = sample_stick(gamma).values()
assert_almost_equal(sum(betas), 1., places=5)
def scipy_normal_draw(mean, variance):
return scipy.stats.norm.rvs(mean, numpy.sqrt(variance))
def test_normal_draw():
require_cython()
import distributions.hp.random
means = [1.0 * i for i in range(-2, 3)]
variances = [10.0 ** i for i in range(-3, 4)]
for mean, variance in itertools.product(means, variances):
# Assume scipy.stats is correct
#yield _test_normal_draw, scipy_normal_draw, mean, variance
_test_normal_draw(
distributions.hp.random.sample_normal,
mean,
variance)
def _test_normal_draw(draw, mean, variance):
samples = [draw(mean, variance) for _ in range(SAMPLES)]
assert_normal(numpy.mean(samples), mean, numpy.sqrt(variance / SAMPLES))
error = numpy.array(samples) - mean
chisq = numpy.dot(error, error) / variance
assert_normal(chisq, SAMPLES, 2 * SAMPLES)
def test_chisq_draw():
require_cython()
import distributions.hp.random
nus = [1.5 ** i for i in range(-10, 11)]
for nu in nus:
# Assume scipy.stats is correct
#yield _test_chisq_draw, scipy.stats.chi2.rvs, nu
_test_chisq_draw(distributions.hp.random.sample_chisq, nu)
def _test_chisq_draw(draw, nu):
samples = [draw(nu) for _ in range(SAMPLES)]
assert_normal(numpy.mean(samples), nu, numpy.sqrt(2 * nu / SAMPLES))
def test_sample_pair_from_urn():
require_cython()
import distributions.lp.random
TEST_FAIL_PROB = 1e-5
ITEM_COUNT = 10
items = range(ITEM_COUNT)
counts = {(i, j): 0 for i in items for j in items if i != j}
pair_count = len(counts)
def test_fail_prob(sample_count):
'''
Let X1,...,XK ~iid uniform({1, ..., N = pair_count})
and for n in {1,..,N} let Cn = sum_k (1 if Xk = n else 0).
Then for each n,
P(Cn = 0) = ((N-1) / N)^K
P(Cn > 0) = 1 - ((N-1) / N)^K
P(test fails) = 1 - P(for all n, Cn > 0)
~ 1 - (1 - ((N-1) / N)^K)^N
'''
item_fail_prob = ((pair_count - 1.0) / pair_count) ** sample_count
test_fail_prob = 1 - (1 - item_fail_prob) ** pair_count
return test_fail_prob
sample_count = 1
while test_fail_prob(sample_count) > TEST_FAIL_PROB:
sample_count *= 2
print 'pair_count = {}'.format(pair_count)
print 'sample_count = {}'.format(sample_count)
for _ in xrange(sample_count):
i, j = distributions.lp.random.sample_pair_from_urn(items)
assert i != j
counts[i, j] += 1
assert_less(0, min(counts.itervalues()))
def test_prob_from_scores():
require_cython()
import distributions.lp.random
for size in range(1, 100):
scores = numpy.random.normal(size=size).tolist()
for _ in xrange(size):
sample, prob1 = distributions.lp.random.sample_prob_from_scores(
scores)
assert 0 <= sample and sample < size
prob2 = distributions.lp.random.prob_from_scores(
sample,
scores)
assert_close(
prob1,
prob2,
err_msg='sample_prob_from_scores != prob_from_scores')
def test_sample_prob_from_scores():
require_cython()
import distributions.lp.random
for size in range(1, 10):
scores = numpy.random.normal(size=size).tolist()
def sampler():
return distributions.lp.random.sample_prob_from_scores(scores)
assert_samples_match_scores(sampler)
def test_log_sum_exp():
require_cython()
import distributions.lp.random
for size in xrange(20):
scores = numpy.random.normal(size=size).tolist()
expected = numpy.logaddexp.reduce(scores) if size else 0.0
actual = distributions.lp.random.log_sum_exp(scores)
assert_close(actual, expected, err_msg='log_sum_exp')
def test_sample_discrete():
require_cython()
import distributions.lp.random
assert_equal(
distributions.lp.random.sample_discrete(
numpy.array([.5], dtype=numpy.float32)),
0)
assert_equal(
distributions.lp.random.sample_discrete(
numpy.array([1.], dtype=numpy.float32)),
0)
assert_equal(
distributions.lp.random.sample_discrete(
numpy.array([1e-3], dtype=numpy.float32)),
0)
assert_equal(
distributions.lp.random.sample_discrete(
numpy.array([1 - 1e-3, 1e-3], dtype=numpy.float32)),
0)
assert_equal(
distributions.lp.random.sample_discrete(
numpy.array([1e-3, 1 - 1e-3], dtype=numpy.float32)),
1)
def random_orthogonal_matrix(m, n):
A, _ = numpy.linalg.qr(numpy.random.random((m, n)))
return A
def random_orthonormal_matrix(n):
A = random_orthogonal_matrix(n, n)
return A
def test_sample_iw():
Q = random_orthonormal_matrix(2)
nu = 4
S = numpy.dot(Q, numpy.dot(numpy.diag([1.0, 0.5]), Q.T))
true_mean = 1. / (nu - S.shape[0] - 1) * S
ntries = 100
samples = []
while ntries:
samples.extend([sample_inverse_wishart(nu, S) for _ in xrange(10000)])
mean = sum(samples) / len(samples)
diff = numpy.linalg.norm(true_mean - mean)
if diff <= 0.1:
return
ntries -= 1
assert_true(False, "mean did not converge")
def test_score_student_t_scalar_equiv():
values = (
(1.2, 5., -0.2, 0.7),
(-3., 3., 1.2, 1.3),
)
for x, nu, mu, sigmasq in values:
mv_args = [
numpy.array([x]),
nu,
numpy.array([mu]),
numpy.array([[sigmasq]])]
scalar_score = scalar_score_student_t(x, nu, mu, sigmasq)
dbg_mv_score = dbg_score_student_t(*mv_args)
lp_mv_score = lp_score_student_t(*mv_args)
assert_close(scalar_score, dbg_mv_score)
assert_close(scalar_score, lp_mv_score)
assert_close(dbg_mv_score, lp_mv_score)
def test_score_student_t_dbg_lp_equiv():
seed_all(0)
def random_vec(dim):
return numpy.random.uniform(low=-3., high=3., size=dim)
def random_cov(dim):
Q = random_orthonormal_matrix(dim)
return numpy.dot(Q, Q.T)
def random_values(dim):
return (random_vec(dim),
float(dim) + 1.,
random_vec(dim),
random_cov(dim))
values = (
[random_values(2) for _ in xrange(10)] +
[random_values(3) for _ in xrange(10)]
)
for x, nu, mu, cov in values:
dbg_mv_score = dbg_score_student_t(x, nu, mu, cov)
lp_mv_score = lp_score_student_t(x, nu, mu, cov)
assert_close(dbg_mv_score, lp_mv_score)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6927,
12,
428,
7098,
3990,
14,
957,
12,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
446,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
446,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
446,
11443,
314,
536,
402,
428,
7098,
3990,
14,
957,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
199,
3,
257,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
199,
3,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
199,
3,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
7975,
199,
646,
2680,
199,
646,
7026,
199,
504,
11354,
14,
2537,
492,
334,
272,
702,
63,
2003,
12,
272,
702,
63,
1452,
12,
272,
702,
63,
4398,
63,
1452,
12,
272,
702,
63,
3536,
12,
272,
702,
63,
2052,
12,
199,
9,
199,
504,
10208,
14,
16310,
14,
2355,
492,
334,
272,
2690,
63,
18043,
12,
272,
2690,
63,
23591,
63,
793,
12,
272,
2690,
63,
11668,
63,
87,
2453,
580,
12,
272,
5396,
63,
5500,
63,
84,
465,
24465,
63,
3397,
63,
5500,
63,
84,
12,
199,
9,
199,
504,
10208,
14,
10343,
14,
2355,
492,
334,
272,
5396,
63,
5500,
63,
84,
465,
13204,
63,
3397,
63,
5500,
63,
84,
12,
199,
9,
199,
504,
10208,
14,
16310,
14,
992,
14,
78,
1158,
492,
334,
272,
5396,
63,
5500,
63,
84,
465,
6917,
63,
3397,
63,
5500,
63,
84,
12,
199,
9,
199,
504,
10208,
14,
2219,
14,
1974,
492,
334,
272,
4409,
63,
20747,
12,
272,
702,
63,
1600,
12,
272,
702,
63,
3356,
63,
1431,
63,
7107,
12,
272,
6347,
63,
452,
12,
199,
9,
421,
199,
51,
8236,
275,
5198,
421,
199,
318,
702,
63,
3302,
8,
88,
12,
612,
12,
10819,
12,
2418,
18804,
29,
20,
14,
16,
304,
272,
1449,
272,
10716,
626,
314,
8865,
3382,
2877,
1338,
365,
4453,
282,
9284,
4465,
272,
29052,
1298,
402,
314,
14746,
359,
4791,
1183,
1854,
61,
1125,
402,
4697,
14,
272,
1449,
272,
702,
63,
2003,
8,
88,
12,
612,
435,
10819,
627,
2418,
18804,
9,
272,
702,
63,
2003,
8,
89,
12,
671,
435,
10819,
627,
2418,
18804,
9,
421,
199,
318,
511,
63,
5176,
837,
272,
4409,
63,
20747,
342,
272,
492,
10208,
14,
12025,
14,
2355,
272,
2288,
63,
12686,
275,
10208,
14,
12025,
14,
2355,
14,
2355,
272,
10208,
14,
12025,
14,
2355,
14,
5176,
8,
16,
9,
272,
1338,
17,
275,
359,
2966,
63,
12686,
342,
367,
485,
315,
4945,
8,
709,
1874,
272,
10208,
14,
12025,
14,
2355,
14,
5176,
8,
16,
9,
272,
1338,
18,
275,
359,
2966,
63,
12686,
342,
367,
485,
315,
4945,
8,
709,
1874,
272,
702,
63,
1452,
8,
1459,
17,
12,
1338,
18,
9,
421,
199,
318,
511,
63,
3271,
63,
23591,
63,
793,
63,
7138,
1659,
837,
272,
2690,
63,
23591,
63,
793,
11468,
17,
69,
19,
566,
272,
2690,
63,
23591,
63,
793,
11468,
17,
69,
19,
12,
446,
17,
69,
13,
19,
566,
421,
199,
318,
511,
63,
3271,
63,
23591,
63,
793,
837,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
14,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
69,
19,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
69,
13,
19,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
2020,
446,
17,
69,
19,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
69,
19,
12,
446,
17,
14,
2522,
413,
9,
272,
702,
63,
3536,
8,
1726,
12,
2690,
63,
23591,
63,
793,
12,
3073,
421,
199,
318,
511,
63,
3271,
63,
18043,
837,
272,
486,
455,
5892,
275,
26496,
17,
12,
413,
2020,
959,
2020,
1616,
19784,
272,
367,
10169,
315,
486,
455,
5892,
26,
267,
367,
485,
315,
1425,
8,
21,
304,
288,
2907,
305,
275,
2690,
63,
18043,
8,
7325,
680,
1459,
342,
288,
702,
63,
4398,
63,
1452,
8,
1838,
8,
9549,
305,
395,
413,
2020,
9825,
29,
21,
9,
421,
199,
318,
7026,
63,
3302,
63,
5485,
8,
3670,
12,
11773,
304,
272,
372,
7026,
14,
3200,
14,
4791,
14,
23322,
8,
3670,
12,
2680,
14,
5079,
8,
6221,
430,
421,
199,
318,
511,
63,
3302,
63,
5485,
837,
272,
4409,
63,
20747,
342,
272,
492,
10208,
14,
12025,
14,
2355,
272,
4910,
275,
359,
17,
14,
16,
627,
284,
367,
284,
315,
1425,
2801,
18,
12,
650,
1874,
272,
11773,
83,
275,
359,
709,
14,
16,
1011,
284,
367,
284,
315,
1425,
2801,
19,
12,
841,
1874,
272,
367,
4615,
12,
11773,
315,
7975,
14,
2558,
8,
11579,
12
] |
[
1898,
334,
67,
9,
6927,
12,
428,
7098,
3990,
14,
957,
12,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
446,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
446,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
446,
11443,
314,
536,
402,
428,
7098,
3990,
14,
957,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
199,
3,
257,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
199,
3,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
199,
3,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
7975,
199,
646,
2680,
199,
646,
7026,
199,
504,
11354,
14,
2537,
492,
334,
272,
702,
63,
2003,
12,
272,
702,
63,
1452,
12,
272,
702,
63,
4398,
63,
1452,
12,
272,
702,
63,
3536,
12,
272,
702,
63,
2052,
12,
199,
9,
199,
504,
10208,
14,
16310,
14,
2355,
492,
334,
272,
2690,
63,
18043,
12,
272,
2690,
63,
23591,
63,
793,
12,
272,
2690,
63,
11668,
63,
87,
2453,
580,
12,
272,
5396,
63,
5500,
63,
84,
465,
24465,
63,
3397,
63,
5500,
63,
84,
12,
199,
9,
199,
504,
10208,
14,
10343,
14,
2355,
492,
334,
272,
5396,
63,
5500,
63,
84,
465,
13204,
63,
3397,
63,
5500,
63,
84,
12,
199,
9,
199,
504,
10208,
14,
16310,
14,
992,
14,
78,
1158,
492,
334,
272,
5396,
63,
5500,
63,
84,
465,
6917,
63,
3397,
63,
5500,
63,
84,
12,
199,
9,
199,
504,
10208,
14,
2219,
14,
1974,
492,
334,
272,
4409,
63,
20747,
12,
272,
702,
63,
1600,
12,
272,
702,
63,
3356,
63,
1431,
63,
7107,
12,
272,
6347,
63,
452,
12,
199,
9,
421,
199,
51,
8236,
275,
5198,
421,
199,
318,
702,
63,
3302,
8,
88,
12,
612,
12,
10819,
12,
2418,
18804,
29,
20,
14,
16,
304,
272,
1449,
272,
10716,
626,
314,
8865,
3382,
2877,
1338,
365,
4453,
282,
9284,
4465,
272,
29052,
1298,
402,
314,
14746,
359,
4791,
1183,
1854,
61,
1125,
402,
4697,
14,
272,
1449,
272,
702,
63,
2003,
8,
88,
12,
612,
435,
10819,
627,
2418,
18804,
9,
272,
702,
63,
2003,
8,
89,
12,
671,
435,
10819,
627,
2418,
18804,
9,
421,
199,
318,
511,
63,
5176,
837,
272,
4409,
63,
20747,
342,
272,
492,
10208,
14,
12025,
14,
2355,
272,
2288,
63,
12686,
275,
10208,
14,
12025,
14,
2355,
14,
2355,
272,
10208,
14,
12025,
14,
2355,
14,
5176,
8,
16,
9,
272,
1338,
17,
275,
359,
2966,
63,
12686,
342,
367,
485,
315,
4945,
8,
709,
1874,
272,
10208,
14,
12025,
14,
2355,
14,
5176,
8,
16,
9,
272,
1338,
18,
275,
359,
2966,
63,
12686,
342,
367,
485,
315,
4945,
8,
709,
1874,
272,
702,
63,
1452,
8,
1459,
17,
12,
1338,
18,
9,
421,
199,
318,
511,
63,
3271,
63,
23591,
63,
793,
63,
7138,
1659,
837,
272,
2690,
63,
23591,
63,
793,
11468,
17,
69,
19,
566,
272,
2690,
63,
23591,
63,
793,
11468,
17,
69,
19,
12,
446,
17,
69,
13,
19,
566,
421,
199,
318,
511,
63,
3271,
63,
23591,
63,
793,
837,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
14,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
69,
19,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
69,
13,
19,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
2020,
446,
17,
69,
19,
2522,
378,
9,
272,
702,
63,
1452,
8,
3271,
63,
23591,
63,
793,
11468,
17,
69,
19,
12,
446,
17,
14,
2522,
413,
9,
272,
702,
63,
3536,
8,
1726,
12,
2690,
63,
23591,
63,
793,
12,
3073,
421,
199,
318,
511,
63,
3271,
63,
18043,
837,
272,
486,
455,
5892,
275,
26496,
17,
12,
413,
2020,
959,
2020,
1616,
19784,
272,
367,
10169,
315,
486,
455,
5892,
26,
267,
367,
485,
315,
1425,
8,
21,
304,
288,
2907,
305,
275,
2690,
63,
18043,
8,
7325,
680,
1459,
342,
288,
702,
63,
4398,
63,
1452,
8,
1838,
8,
9549,
305,
395,
413,
2020,
9825,
29,
21,
9,
421,
199,
318,
7026,
63,
3302,
63,
5485,
8,
3670,
12,
11773,
304,
272,
372,
7026,
14,
3200,
14,
4791,
14,
23322,
8,
3670,
12,
2680,
14,
5079,
8,
6221,
430,
421,
199,
318,
511,
63,
3302,
63,
5485,
837,
272,
4409,
63,
20747,
342,
272,
492,
10208,
14,
12025,
14,
2355,
272,
4910,
275,
359,
17,
14,
16,
627,
284,
367,
284,
315,
1425,
2801,
18,
12,
650,
1874,
272,
11773,
83,
275,
359,
709,
14,
16,
1011,
284,
367,
284,
315,
1425,
2801,
19,
12,
841,
1874,
272,
367,
4615,
12,
11773,
315,
7975,
14,
2558,
8,
11579,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
CallaJun/hackprince
|
indico/nose/proxy.py
|
94
|
6879
|
"""
Result Proxy
------------
The result proxy wraps the result instance given to each test. It
performs two functions: enabling extended error/failure reporting
and calling plugins.
As each result event is fired, plugins are called with the same event;
however, plugins are called with the nose.case.Test instance that
wraps the actual test. So when a test fails and calls
result.addFailure(self, err), the result proxy calls
addFailure(self.test, err) for each plugin. This allows plugins to
have a single stable interface for all test types, and also to
manipulate the test object itself by setting the `test` attribute of
the nose.case.Test that they receive.
"""
import logging
from nose.config import Config
log = logging.getLogger(__name__)
def proxied_attribute(local_attr, proxied_attr, doc):
"""Create a property that proxies attribute ``proxied_attr`` through
the local attribute ``local_attr``.
"""
def fget(self):
return getattr(getattr(self, local_attr), proxied_attr)
def fset(self, value):
setattr(getattr(self, local_attr), proxied_attr, value)
def fdel(self):
delattr(getattr(self, local_attr), proxied_attr)
return property(fget, fset, fdel, doc)
class ResultProxyFactory(object):
"""Factory for result proxies. Generates a ResultProxy bound to each test
and the result passed to the test.
"""
def __init__(self, config=None):
if config is None:
config = Config()
self.config = config
self.__prepared = False
self.__result = None
def __call__(self, result, test):
"""Return a ResultProxy for the current test.
On first call, plugins are given a chance to replace the
result used for the remaining tests. If a plugin returns a
value from prepareTestResult, that object will be used as the
result for all tests.
"""
if not self.__prepared:
self.__prepared = True
plug_result = self.config.plugins.prepareTestResult(result)
if plug_result is not None:
self.__result = result = plug_result
if self.__result is not None:
result = self.__result
return ResultProxy(result, test, config=self.config)
class ResultProxy(object):
"""Proxy to TestResults (or other results handler).
One ResultProxy is created for each nose.case.Test. The result
proxy calls plugins with the nose.case.Test instance (instead of
the wrapped test case) as each result call is made. Finally, the
real result method is called, also with the nose.case.Test
instance as the test parameter.
"""
def __init__(self, result, test, config=None):
if config is None:
config = Config()
self.config = config
self.plugins = config.plugins
self.result = result
self.test = test
def __repr__(self):
return repr(self.result)
def _prepareErr(self, err):
if not isinstance(err[1], Exception) and isinstance(err[0], type):
# Turn value back into an Exception (required in Python 3.x).
# Plugins do all sorts of crazy things with exception values.
# Convert it to a custom subclass of Exception with the same
# name as the actual exception to make it print correctly.
value = type(err[0].__name__, (Exception,), {})(err[1])
err = (err[0], value, err[2])
return err
def assertMyTest(self, test):
# The test I was called with must be my .test or my
# .test's .test. or my .test.test's .case
case = getattr(self.test, 'test', None)
assert (test is self.test
or test is case
or test is getattr(case, '_nose_case', None)), (
"ResultProxy for %r (%s) was called with test %r (%s)"
% (self.test, id(self.test), test, id(test)))
def afterTest(self, test):
self.assertMyTest(test)
self.plugins.afterTest(self.test)
if hasattr(self.result, "afterTest"):
self.result.afterTest(self.test)
def beforeTest(self, test):
self.assertMyTest(test)
self.plugins.beforeTest(self.test)
if hasattr(self.result, "beforeTest"):
self.result.beforeTest(self.test)
def addError(self, test, err):
self.assertMyTest(test)
plugins = self.plugins
plugin_handled = plugins.handleError(self.test, err)
if plugin_handled:
return
# test.passed is set in result, to account for error classes
formatted = plugins.formatError(self.test, err)
if formatted is not None:
err = formatted
plugins.addError(self.test, err)
self.result.addError(self.test, self._prepareErr(err))
if not self.result.wasSuccessful() and self.config.stopOnError:
self.shouldStop = True
def addFailure(self, test, err):
self.assertMyTest(test)
plugins = self.plugins
plugin_handled = plugins.handleFailure(self.test, err)
if plugin_handled:
return
self.test.passed = False
formatted = plugins.formatFailure(self.test, err)
if formatted is not None:
err = formatted
plugins.addFailure(self.test, err)
self.result.addFailure(self.test, self._prepareErr(err))
if self.config.stopOnError:
self.shouldStop = True
def addSkip(self, test, reason):
# 2.7 compat shim
from nose.plugins.skip import SkipTest
self.assertMyTest(test)
plugins = self.plugins
if not isinstance(reason, Exception):
# for Python 3.2+
reason = Exception(reason)
plugins.addError(self.test, (SkipTest, reason, None))
self.result.addSkip(self.test, reason)
def addSuccess(self, test):
self.assertMyTest(test)
self.plugins.addSuccess(self.test)
self.result.addSuccess(self.test)
def startTest(self, test):
self.assertMyTest(test)
self.plugins.startTest(self.test)
self.result.startTest(self.test)
def stop(self):
self.result.stop()
def stopTest(self, test):
self.assertMyTest(test)
self.plugins.stopTest(self.test)
self.result.stopTest(self.test)
# proxied attributes
shouldStop = proxied_attribute('result', 'shouldStop',
"""Should the test run stop?""")
errors = proxied_attribute('result', 'errors',
"""Tests that raised an exception""")
failures = proxied_attribute('result', 'failures',
"""Tests that failed""")
testsRun = proxied_attribute('result', 'testsRun',
"""Number of tests run""")
|
lgpl-3.0
|
[
624,
199,
2889,
12373,
199,
4559,
199,
199,
1918,
754,
4566,
14018,
314,
754,
1256,
1627,
370,
1924,
511,
14,
2779,
199,
529,
3351,
2877,
3423,
26,
29310,
9243,
1125,
15,
5328,
17290,
199,
460,
6358,
8963,
14,
199,
199,
2822,
1924,
754,
1566,
365,
31974,
12,
8963,
787,
2797,
543,
314,
2011,
1566,
27,
199,
526,
1129,
422,
12,
8963,
787,
2797,
543,
314,
11354,
14,
2546,
14,
774,
1256,
626,
199,
13582,
314,
3503,
511,
14,
2002,
1380,
282,
511,
6918,
436,
4882,
199,
1099,
14,
525,
6782,
8,
277,
12,
2329,
395,
314,
754,
4566,
4882,
199,
525,
6782,
8,
277,
14,
396,
12,
2329,
9,
367,
1924,
3589,
14,
961,
6127,
8963,
370,
199,
7804,
282,
2849,
17830,
3217,
367,
1006,
511,
2943,
12,
436,
2597,
370,
199,
29798,
5434,
314,
511,
909,
6337,
701,
4260,
314,
658,
396,
64,
2225,
402,
199,
1589,
11354,
14,
2546,
14,
774,
626,
2985,
9128,
14,
199,
624,
199,
646,
2050,
199,
504,
11354,
14,
888,
492,
4094,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
10645,
5299,
63,
3215,
8,
1832,
63,
962,
12,
10645,
5299,
63,
962,
12,
1382,
304,
272,
408,
2499,
282,
3324,
626,
14942,
2225,
1124,
8221,
5299,
63,
962,
1040,
4012,
272,
314,
2257,
2225,
1124,
1832,
63,
962,
4345,
272,
408,
272,
347,
289,
362,
8,
277,
304,
267,
372,
2519,
8,
5675,
8,
277,
12,
2257,
63,
962,
395,
10645,
5299,
63,
962,
9,
272,
347,
289,
409,
8,
277,
12,
574,
304,
267,
5371,
8,
5675,
8,
277,
12,
2257,
63,
962,
395,
10645,
5299,
63,
962,
12,
574,
9,
272,
347,
289,
2264,
8,
277,
304,
267,
24358,
8,
5675,
8,
277,
12,
2257,
63,
962,
395,
10645,
5299,
63,
962,
9,
272,
372,
3324,
8,
27823,
12,
289,
409,
12,
289,
2264,
12,
1382,
9,
421,
199,
533,
10695,
4936,
2927,
8,
785,
304,
272,
408,
2927,
367,
754,
14942,
14,
21687,
282,
10695,
4936,
3914,
370,
1924,
511,
272,
436,
314,
754,
3032,
370,
314,
511,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1101,
29,
403,
304,
267,
340,
1101,
365,
488,
26,
288,
1101,
275,
4094,
342,
267,
291,
14,
888,
275,
1101,
267,
291,
855,
19260,
275,
756,
267,
291,
855,
1099,
275,
488,
339,
347,
636,
1250,
721,
277,
12,
754,
12,
511,
304,
267,
408,
1767,
282,
10695,
4936,
367,
314,
1453,
511,
14,
398,
4068,
1642,
1240,
12,
8963,
787,
1627,
282,
22044,
370,
3350,
314,
267,
754,
1202,
367,
314,
7971,
2295,
14,
982,
282,
3589,
2529,
282,
267,
574,
687,
9275,
13120,
12,
626,
909,
911,
506,
1202,
465,
314,
267,
754,
367,
1006,
2295,
14,
267,
408,
267,
340,
440,
291,
855,
19260,
26,
288,
291,
855,
19260,
275,
715,
288,
14202,
63,
1099,
275,
291,
14,
888,
14,
5265,
14,
6726,
13120,
8,
1099,
9,
288,
340,
14202,
63,
1099,
365,
440,
488,
26,
355,
291,
855,
1099,
275,
754,
275,
14202,
63,
1099,
267,
340,
291,
855,
1099,
365,
440,
488,
26,
288,
754,
275,
291,
855,
1099,
267,
372,
10695,
4936,
8,
1099,
12,
511,
12,
1101,
29,
277,
14,
888,
9,
421,
199,
533,
10695,
4936,
8,
785,
304,
272,
408,
4936,
370,
1379,
6579,
334,
269,
1163,
2058,
3016,
680,
339,
7309,
10695,
4936,
365,
2737,
367,
1924,
11354,
14,
2546,
14,
774,
14,
710,
754,
272,
4566,
4882,
8963,
543,
314,
11354,
14,
2546,
14,
774,
1256,
334,
23145,
402,
272,
314,
8072,
511,
1930,
9,
465,
1924,
754,
1240,
365,
6326,
14,
19177,
12,
314,
272,
3363,
754,
1083,
365,
2797,
12,
2597,
543,
314,
11354,
14,
2546,
14,
774,
272,
1256,
465,
314,
511,
2725,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
754,
12,
511,
12,
1101,
29,
403,
304,
267,
340,
1101,
365,
488,
26,
288,
1101,
275,
4094,
342,
267,
291,
14,
888,
275,
1101,
267,
291,
14,
5265,
275,
1101,
14,
5265,
267,
291,
14,
1099,
275,
754,
267,
291,
14,
396,
275,
511,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
1099,
9,
339,
347,
485,
6726,
5432,
8,
277,
12,
2329,
304,
267,
340,
440,
1228,
8,
1508,
59,
17,
467,
2186,
9,
436,
1228,
8,
1508,
59,
16,
467,
730,
304,
288,
327,
16147,
574,
1771,
1901,
376,
2186,
334,
2427,
315,
2018,
650,
14,
88,
680,
288,
327,
30317,
886,
1006,
30313,
402,
286,
30566,
7645,
543,
1919,
1338,
14,
288,
327,
7905,
652,
370,
282,
3537,
5516,
402,
2186,
543,
314,
2011,
288,
327,
536,
465,
314,
3503,
1919,
370,
1852,
652,
870,
6657,
14,
288,
574,
275,
730,
8,
1508,
59,
16,
17979,
354,
3108,
334,
1726,
4706,
5009,
8,
1508,
59,
17,
566,
288,
2329,
275,
334,
1508,
59,
16,
467,
574,
12,
2329,
59,
18,
566,
267,
372,
2329,
339,
347,
702,
5713,
774,
8,
277,
12,
511,
304,
267,
327,
710,
511,
473,
1990,
2797,
543,
1471,
506,
3002,
1275,
396,
503,
3002,
267,
327,
1275,
396,
1159,
1275,
396,
14,
503,
3002,
1275,
396,
14,
396,
1159,
1275,
2546,
398,
1930,
275,
2519,
8,
277,
14,
396,
12,
283,
396,
297,
488,
9,
267,
702,
334,
396,
365,
291,
14,
396,
355,
503,
511,
365,
1930,
355,
503,
511,
365,
2519,
8,
2546,
12,
2513,
21085,
63,
2546,
297,
488,
1826,
334,
355,
298,
2889,
4936,
367,
450,
82,
4366,
83,
9,
1990,
2797,
543,
511,
450,
82,
4366,
83,
2924,
355,
450,
334,
277,
14,
396,
12,
1305,
8,
277,
14,
396,
395,
511,
12,
1305,
8,
396,
1724,
339,
347,
2410,
774,
8,
277,
12,
511,
304,
267,
291,
14,
479,
5713,
774,
8,
396,
9,
267,
291,
14,
5265,
14,
4399,
774,
8,
277,
14,
396,
9,
267,
340,
2688,
8,
277,
14,
1099,
12,
298,
4399,
774,
2349,
288,
291,
14,
1099,
14,
4399,
774,
8,
277,
14,
396,
9,
339,
347,
2544,
774,
8,
277,
12,
511,
304,
267,
291,
14,
479,
5713,
774,
8,
396,
9,
267,
291,
14,
5265,
14,
5182,
774,
8,
277,
14,
396,
9,
267,
340
] |
[
199,
2889,
12373,
199,
4559,
199,
199,
1918,
754,
4566,
14018,
314,
754,
1256,
1627,
370,
1924,
511,
14,
2779,
199,
529,
3351,
2877,
3423,
26,
29310,
9243,
1125,
15,
5328,
17290,
199,
460,
6358,
8963,
14,
199,
199,
2822,
1924,
754,
1566,
365,
31974,
12,
8963,
787,
2797,
543,
314,
2011,
1566,
27,
199,
526,
1129,
422,
12,
8963,
787,
2797,
543,
314,
11354,
14,
2546,
14,
774,
1256,
626,
199,
13582,
314,
3503,
511,
14,
2002,
1380,
282,
511,
6918,
436,
4882,
199,
1099,
14,
525,
6782,
8,
277,
12,
2329,
395,
314,
754,
4566,
4882,
199,
525,
6782,
8,
277,
14,
396,
12,
2329,
9,
367,
1924,
3589,
14,
961,
6127,
8963,
370,
199,
7804,
282,
2849,
17830,
3217,
367,
1006,
511,
2943,
12,
436,
2597,
370,
199,
29798,
5434,
314,
511,
909,
6337,
701,
4260,
314,
658,
396,
64,
2225,
402,
199,
1589,
11354,
14,
2546,
14,
774,
626,
2985,
9128,
14,
199,
624,
199,
646,
2050,
199,
504,
11354,
14,
888,
492,
4094,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
10645,
5299,
63,
3215,
8,
1832,
63,
962,
12,
10645,
5299,
63,
962,
12,
1382,
304,
272,
408,
2499,
282,
3324,
626,
14942,
2225,
1124,
8221,
5299,
63,
962,
1040,
4012,
272,
314,
2257,
2225,
1124,
1832,
63,
962,
4345,
272,
408,
272,
347,
289,
362,
8,
277,
304,
267,
372,
2519,
8,
5675,
8,
277,
12,
2257,
63,
962,
395,
10645,
5299,
63,
962,
9,
272,
347,
289,
409,
8,
277,
12,
574,
304,
267,
5371,
8,
5675,
8,
277,
12,
2257,
63,
962,
395,
10645,
5299,
63,
962,
12,
574,
9,
272,
347,
289,
2264,
8,
277,
304,
267,
24358,
8,
5675,
8,
277,
12,
2257,
63,
962,
395,
10645,
5299,
63,
962,
9,
272,
372,
3324,
8,
27823,
12,
289,
409,
12,
289,
2264,
12,
1382,
9,
421,
199,
533,
10695,
4936,
2927,
8,
785,
304,
272,
408,
2927,
367,
754,
14942,
14,
21687,
282,
10695,
4936,
3914,
370,
1924,
511,
272,
436,
314,
754,
3032,
370,
314,
511,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1101,
29,
403,
304,
267,
340,
1101,
365,
488,
26,
288,
1101,
275,
4094,
342,
267,
291,
14,
888,
275,
1101,
267,
291,
855,
19260,
275,
756,
267,
291,
855,
1099,
275,
488,
339,
347,
636,
1250,
721,
277,
12,
754,
12,
511,
304,
267,
408,
1767,
282,
10695,
4936,
367,
314,
1453,
511,
14,
398,
4068,
1642,
1240,
12,
8963,
787,
1627,
282,
22044,
370,
3350,
314,
267,
754,
1202,
367,
314,
7971,
2295,
14,
982,
282,
3589,
2529,
282,
267,
574,
687,
9275,
13120,
12,
626,
909,
911,
506,
1202,
465,
314,
267,
754,
367,
1006,
2295,
14,
267,
408,
267,
340,
440,
291,
855,
19260,
26,
288,
291,
855,
19260,
275,
715,
288,
14202,
63,
1099,
275,
291,
14,
888,
14,
5265,
14,
6726,
13120,
8,
1099,
9,
288,
340,
14202,
63,
1099,
365,
440,
488,
26,
355,
291,
855,
1099,
275,
754,
275,
14202,
63,
1099,
267,
340,
291,
855,
1099,
365,
440,
488,
26,
288,
754,
275,
291,
855,
1099,
267,
372,
10695,
4936,
8,
1099,
12,
511,
12,
1101,
29,
277,
14,
888,
9,
421,
199,
533,
10695,
4936,
8,
785,
304,
272,
408,
4936,
370,
1379,
6579,
334,
269,
1163,
2058,
3016,
680,
339,
7309,
10695,
4936,
365,
2737,
367,
1924,
11354,
14,
2546,
14,
774,
14,
710,
754,
272,
4566,
4882,
8963,
543,
314,
11354,
14,
2546,
14,
774,
1256,
334,
23145,
402,
272,
314,
8072,
511,
1930,
9,
465,
1924,
754,
1240,
365,
6326,
14,
19177,
12,
314,
272,
3363,
754,
1083,
365,
2797,
12,
2597,
543,
314,
11354,
14,
2546,
14,
774,
272,
1256,
465,
314,
511,
2725,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
754,
12,
511,
12,
1101,
29,
403,
304,
267,
340,
1101,
365,
488,
26,
288,
1101,
275,
4094,
342,
267,
291,
14,
888,
275,
1101,
267,
291,
14,
5265,
275,
1101,
14,
5265,
267,
291,
14,
1099,
275,
754,
267,
291,
14,
396,
275,
511,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
1099,
9,
339,
347,
485,
6726,
5432,
8,
277,
12,
2329,
304,
267,
340,
440,
1228,
8,
1508,
59,
17,
467,
2186,
9,
436,
1228,
8,
1508,
59,
16,
467,
730,
304,
288,
327,
16147,
574,
1771,
1901,
376,
2186,
334,
2427,
315,
2018,
650,
14,
88,
680,
288,
327,
30317,
886,
1006,
30313,
402,
286,
30566,
7645,
543,
1919,
1338,
14,
288,
327,
7905,
652,
370,
282,
3537,
5516,
402,
2186,
543,
314,
2011,
288,
327,
536,
465,
314,
3503,
1919,
370,
1852,
652,
870,
6657,
14,
288,
574,
275,
730,
8,
1508,
59,
16,
17979,
354,
3108,
334,
1726,
4706,
5009,
8,
1508,
59,
17,
566,
288,
2329,
275,
334,
1508,
59,
16,
467,
574,
12,
2329,
59,
18,
566,
267,
372,
2329,
339,
347,
702,
5713,
774,
8,
277,
12,
511,
304,
267,
327,
710,
511,
473,
1990,
2797,
543,
1471,
506,
3002,
1275,
396,
503,
3002,
267,
327,
1275,
396,
1159,
1275,
396,
14,
503,
3002,
1275,
396,
14,
396,
1159,
1275,
2546,
398,
1930,
275,
2519,
8,
277,
14,
396,
12,
283,
396,
297,
488,
9,
267,
702,
334,
396,
365,
291,
14,
396,
355,
503,
511,
365,
1930,
355,
503,
511,
365,
2519,
8,
2546,
12,
2513,
21085,
63,
2546,
297,
488,
1826,
334,
355,
298,
2889,
4936,
367,
450,
82,
4366,
83,
9,
1990,
2797,
543,
511,
450,
82,
4366,
83,
2924,
355,
450,
334,
277,
14,
396,
12,
1305,
8,
277,
14,
396,
395,
511,
12,
1305,
8,
396,
1724,
339,
347,
2410,
774,
8,
277,
12,
511,
304,
267,
291,
14,
479,
5713,
774,
8,
396,
9,
267,
291,
14,
5265,
14,
4399,
774,
8,
277,
14,
396,
9,
267,
340,
2688,
8,
277,
14,
1099,
12,
298,
4399,
774,
2349,
288,
291,
14,
1099,
14,
4399,
774,
8,
277,
14,
396,
9,
339,
347,
2544,
774,
8,
277,
12,
511,
304,
267,
291,
14,
479,
5713,
774,
8,
396,
9,
267,
291,
14,
5265,
14,
5182,
774,
8,
277,
14,
396,
9,
267,
340,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
espressif/esp-idf
|
docs/idf_extensions/gen_defines.py
|
1
|
3181
|
# Sphinx extension to integrate defines into the Sphinx Build
#
# Runs after the IDF dummy project has been built
#
# Then emits the new 'idf-defines-generated' event which has a dictionary of raw text define values
# that other extensions can use to generate relevant data.
import glob
import os
import pprint
import re
import subprocess
def generate_defines(app, project_description):
sdk_config_path = os.path.join(project_description['build_dir'], 'config')
# Parse kconfig macros to pass into doxygen
#
# TODO: this should use the set of "config which can't be changed" eventually,
# not the header
defines = get_defines(os.path.join(project_description['build_dir'],
'config', 'sdkconfig.h'), sdk_config_path)
# Add all SOC _caps.h headers and kconfig macros to the defines
#
# kind of a hack, be nicer to add a component info dict in project_description.json
soc_path = [p for p in project_description['build_component_paths'] if p.endswith('/soc')][0]
soc_headers = glob.glob(os.path.join(soc_path, project_description['target'],
'include', 'soc', '*_caps.h'))
assert len(soc_headers) > 0
for soc_header in soc_headers:
defines.update(get_defines(soc_header, sdk_config_path))
# write a list of definitions to make debugging easier
with open(os.path.join(app.config.build_dir, 'macro-definitions.txt'), 'w') as f:
pprint.pprint(defines, f)
print('Saved macro list to %s' % f.name)
add_tags(app, defines)
app.emit('idf-defines-generated', defines)
def get_defines(header_path, sdk_config_path):
defines = {}
# Note: we run C preprocessor here without any -I arguments (except "sdkconfig.h"), so assumption is
# that these headers are all self-contained and don't include any other headers
# not in the same directory
print('Reading macros from %s...' % (header_path))
processed_output = subprocess.check_output(['xtensa-esp32-elf-gcc', '-I', sdk_config_path,
'-dM', '-E', header_path]).decode()
for line in processed_output.split('\n'):
line = line.strip()
m = re.search('#define ([^ ]+) ?(.*)', line)
if m:
name = m.group(1)
value = m.group(2)
if name.startswith('_'):
continue # toolchain macro
if (' ' in value) or ('=' in value):
value = '' # macros that expand to multiple tokens (ie function macros) cause doxygen errors, so just mark as 'defined'
defines[name] = value
return defines
def add_tags(app, defines):
# try to parse define values as ints and add to tags
for name, value in defines.items():
try:
define_value = int(value.strip('()'))
if define_value > 0:
app.tags.add(name)
except ValueError:
continue
def setup(app):
app.connect('idf-info', generate_defines)
app.add_event('idf-defines-generated')
return {'parallel_read_safe': True, 'parallel_write_safe': True, 'version': '0.2'}
|
apache-2.0
|
[
3,
10229,
3329,
370,
21494,
7890,
1901,
314,
10229,
6516,
199,
3,
199,
3,
23773,
2410,
314,
2870,
38,
7283,
2199,
965,
2757,
6137,
199,
3,
199,
3,
9442,
8689,
83,
314,
892,
283,
24003,
13,
14334,
13,
10176,
7,
1566,
1314,
965,
282,
2600,
402,
3066,
1318,
5627,
1338,
199,
3,
626,
1163,
5478,
883,
675,
370,
3550,
12082,
666,
14,
199,
199,
646,
5739,
199,
646,
747,
199,
646,
10933,
199,
646,
295,
199,
646,
3873,
421,
199,
318,
3550,
63,
14334,
8,
571,
12,
2199,
63,
1802,
304,
272,
13628,
63,
888,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1715,
63,
1802,
459,
1506,
63,
694,
995,
283,
888,
358,
339,
327,
6077,
1022,
888,
16954,
370,
986,
1901,
886,
20515,
272,
327,
272,
327,
3254,
26,
642,
1077,
675,
314,
663,
402,
298,
888,
1314,
883,
1133,
506,
2896,
2,
21356,
12,
272,
327,
440,
314,
1406,
272,
7890,
275,
664,
63,
14334,
8,
736,
14,
515,
14,
904,
8,
1715,
63,
1802,
459,
1506,
63,
694,
995,
4318,
283,
888,
297,
283,
9277,
888,
14,
72,
659,
13628,
63,
888,
63,
515,
9,
339,
327,
2654,
1006,
3562,
35,
485,
12029,
14,
72,
2323,
436,
1022,
888,
16954,
370,
314,
7890,
272,
327,
272,
327,
4928,
402,
282,
11176,
12,
506,
30023,
370,
1050,
282,
3931,
2256,
1211,
315,
2199,
63,
1802,
14,
1001,
272,
308,
679,
63,
515,
275,
359,
80,
367,
299,
315,
2199,
63,
1802,
459,
1506,
63,
3173,
63,
3771,
418,
340,
299,
14,
4130,
2336,
83,
679,
358,
1527,
16,
61,
272,
308,
679,
63,
2139,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
83,
679,
63,
515,
12,
2199,
63,
1802,
459,
1375,
995,
1460,
283,
2613,
297,
283,
83,
679,
297,
6438,
63,
12029,
14,
72,
1333,
272,
702,
822,
8,
83,
679,
63,
2139,
9,
690,
378,
339,
367,
308,
679,
63,
1291,
315,
308,
679,
63,
2139,
26,
267,
7890,
14,
873,
8,
362,
63,
14334,
8,
83,
679,
63,
1291,
12,
13628,
63,
888,
63,
515,
430,
339,
327,
2218,
282,
769,
402,
10269,
370,
1852,
10201,
14905,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
571,
14,
888,
14,
1506,
63,
694,
12,
283,
11300,
13,
15388,
14,
2424,
659,
283,
87,
358,
465,
289,
26,
267,
10933,
14,
15380,
8,
14334,
12,
289,
9,
267,
870,
360,
21969,
9559,
769,
370,
450,
83,
7,
450,
289,
14,
354,
9,
339,
1050,
63,
2969,
8,
571,
12,
7890,
9,
339,
1145,
14,
8159,
360,
24003,
13,
14334,
13,
10176,
297,
7890,
9,
421,
199,
318,
664,
63,
14334,
8,
1291,
63,
515,
12,
13628,
63,
888,
63,
515,
304,
272,
7890,
275,
1052,
272,
327,
3390,
26,
781,
1255,
445,
22335,
2348,
1928,
1263,
446,
41,
2368,
334,
2590,
298,
9277,
888,
14,
72,
1288,
880,
30075,
365,
272,
327,
626,
3520,
2323,
787,
1006,
291,
13,
30288,
436,
2793,
1133,
2387,
1263,
1163,
2323,
272,
327,
440,
315,
314,
2011,
2082,
272,
870,
360,
20568,
16954,
687,
450,
83,
13698,
450,
334,
1291,
63,
515,
430,
272,
7686,
63,
1199,
275,
3873,
14,
1074,
63,
1199,
2941,
88,
32461,
65,
13,
397,
80,
708,
13,
25371,
13,
13112,
297,
2475,
41,
297,
13628,
63,
888,
63,
515,
12,
6059,
2475,
68,
45,
297,
2475,
37,
297,
1406,
63,
515,
6575,
2708,
342,
272,
367,
1004,
315,
7686,
63,
1199,
14,
1294,
2258,
78,
735,
267,
1004,
275,
1004,
14,
1913,
342,
267,
333,
275,
295,
14,
1733,
7863,
4640,
334,
4735,
1622,
8771,
5805,
19276,
3196,
1004,
9,
267,
340,
333,
26,
288,
536,
275,
333,
14,
923,
8,
17,
9,
288,
574,
275,
333,
14,
923,
8,
18,
9,
288,
340,
536,
14,
2460,
30018,
355,
1980,
221,
327,
22689,
9559,
288,
340,
661,
283,
315,
574,
9,
503,
661,
534,
315,
574,
304,
355,
574,
275,
2125,
221,
327,
16954,
626,
6544,
370,
3663,
4645,
334,
1873,
805,
16954,
9,
7675,
886,
20515,
2552,
12,
880,
2951,
2216,
465,
283,
4037,
7,
288,
7890,
59,
354,
61,
275,
574,
339,
372,
7890,
421,
199,
318,
1050,
63,
2969,
8,
571,
12,
7890,
304,
272,
327,
862,
370,
2198,
5627,
1338,
465,
14526,
436,
1050,
370,
3762,
272,
367,
536,
12,
574,
315,
7890,
14,
1744,
837,
267,
862,
26,
288,
5627,
63,
585,
275,
1109,
8,
585,
14,
1913,
360,
342,
1333,
288,
340,
5627,
63,
585,
690,
378,
26,
355,
1145,
14,
2969,
14,
525,
8,
354,
9,
267,
871,
1722,
26,
288,
1980,
421,
199,
318,
3272,
8,
571,
304,
272,
1145,
14,
2242,
360,
24003,
13,
815,
297,
3550,
63,
14334,
9,
272,
1145,
14,
525,
63,
1430,
360,
24003,
13,
14334,
13,
10176,
358,
339,
372,
791,
11887,
63,
739,
63,
3489,
356,
715,
12,
283,
11887,
63,
952,
63,
3489,
356,
715,
12,
283,
1023,
356,
283,
16,
14,
18,
936,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
10229,
3329,
370,
21494,
7890,
1901,
314,
10229,
6516,
199,
3,
199,
3,
23773,
2410,
314,
2870,
38,
7283,
2199,
965,
2757,
6137,
199,
3,
199,
3,
9442,
8689,
83,
314,
892,
283,
24003,
13,
14334,
13,
10176,
7,
1566,
1314,
965,
282,
2600,
402,
3066,
1318,
5627,
1338,
199,
3,
626,
1163,
5478,
883,
675,
370,
3550,
12082,
666,
14,
199,
199,
646,
5739,
199,
646,
747,
199,
646,
10933,
199,
646,
295,
199,
646,
3873,
421,
199,
318,
3550,
63,
14334,
8,
571,
12,
2199,
63,
1802,
304,
272,
13628,
63,
888,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1715,
63,
1802,
459,
1506,
63,
694,
995,
283,
888,
358,
339,
327,
6077,
1022,
888,
16954,
370,
986,
1901,
886,
20515,
272,
327,
272,
327,
3254,
26,
642,
1077,
675,
314,
663,
402,
298,
888,
1314,
883,
1133,
506,
2896,
2,
21356,
12,
272,
327,
440,
314,
1406,
272,
7890,
275,
664,
63,
14334,
8,
736,
14,
515,
14,
904,
8,
1715,
63,
1802,
459,
1506,
63,
694,
995,
4318,
283,
888,
297,
283,
9277,
888,
14,
72,
659,
13628,
63,
888,
63,
515,
9,
339,
327,
2654,
1006,
3562,
35,
485,
12029,
14,
72,
2323,
436,
1022,
888,
16954,
370,
314,
7890,
272,
327,
272,
327,
4928,
402,
282,
11176,
12,
506,
30023,
370,
1050,
282,
3931,
2256,
1211,
315,
2199,
63,
1802,
14,
1001,
272,
308,
679,
63,
515,
275,
359,
80,
367,
299,
315,
2199,
63,
1802,
459,
1506,
63,
3173,
63,
3771,
418,
340,
299,
14,
4130,
2336,
83,
679,
358,
1527,
16,
61,
272,
308,
679,
63,
2139,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
83,
679,
63,
515,
12,
2199,
63,
1802,
459,
1375,
995,
1460,
283,
2613,
297,
283,
83,
679,
297,
6438,
63,
12029,
14,
72,
1333,
272,
702,
822,
8,
83,
679,
63,
2139,
9,
690,
378,
339,
367,
308,
679,
63,
1291,
315,
308,
679,
63,
2139,
26,
267,
7890,
14,
873,
8,
362,
63,
14334,
8,
83,
679,
63,
1291,
12,
13628,
63,
888,
63,
515,
430,
339,
327,
2218,
282,
769,
402,
10269,
370,
1852,
10201,
14905,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
571,
14,
888,
14,
1506,
63,
694,
12,
283,
11300,
13,
15388,
14,
2424,
659,
283,
87,
358,
465,
289,
26,
267,
10933,
14,
15380,
8,
14334,
12,
289,
9,
267,
870,
360,
21969,
9559,
769,
370,
450,
83,
7,
450,
289,
14,
354,
9,
339,
1050,
63,
2969,
8,
571,
12,
7890,
9,
339,
1145,
14,
8159,
360,
24003,
13,
14334,
13,
10176,
297,
7890,
9,
421,
199,
318,
664,
63,
14334,
8,
1291,
63,
515,
12,
13628,
63,
888,
63,
515,
304,
272,
7890,
275,
1052,
272,
327,
3390,
26,
781,
1255,
445,
22335,
2348,
1928,
1263,
446,
41,
2368,
334,
2590,
298,
9277,
888,
14,
72,
1288,
880,
30075,
365,
272,
327,
626,
3520,
2323,
787,
1006,
291,
13,
30288,
436,
2793,
1133,
2387,
1263,
1163,
2323,
272,
327,
440,
315,
314,
2011,
2082,
272,
870,
360,
20568,
16954,
687,
450,
83,
13698,
450,
334,
1291,
63,
515,
430,
272,
7686,
63,
1199,
275,
3873,
14,
1074,
63,
1199,
2941,
88,
32461,
65,
13,
397,
80,
708,
13,
25371,
13,
13112,
297,
2475,
41,
297,
13628,
63,
888,
63,
515,
12,
6059,
2475,
68,
45,
297,
2475,
37,
297,
1406,
63,
515,
6575,
2708,
342,
272,
367,
1004,
315,
7686,
63,
1199,
14,
1294,
2258,
78,
735,
267,
1004,
275,
1004,
14,
1913,
342,
267,
333,
275,
295,
14,
1733,
7863,
4640,
334,
4735,
1622,
8771,
5805,
19276,
3196,
1004,
9,
267,
340,
333,
26,
288,
536,
275,
333,
14,
923,
8,
17,
9,
288,
574,
275,
333,
14,
923,
8,
18,
9,
288,
340,
536,
14,
2460,
30018,
355,
1980,
221,
327,
22689,
9559,
288,
340,
661,
283,
315,
574,
9,
503,
661,
534,
315,
574,
304,
355,
574,
275,
2125,
221,
327,
16954,
626,
6544,
370,
3663,
4645,
334,
1873,
805,
16954,
9,
7675,
886,
20515,
2552,
12,
880,
2951,
2216,
465,
283,
4037,
7,
288,
7890,
59,
354,
61,
275,
574,
339,
372,
7890,
421,
199,
318,
1050,
63,
2969,
8,
571,
12,
7890,
304,
272,
327,
862,
370,
2198,
5627,
1338,
465,
14526,
436,
1050,
370,
3762,
272,
367,
536,
12,
574,
315,
7890,
14,
1744,
837,
267,
862,
26,
288,
5627,
63,
585,
275,
1109,
8,
585,
14,
1913,
360,
342,
1333,
288,
340,
5627,
63,
585,
690,
378,
26,
355,
1145,
14,
2969,
14,
525,
8,
354,
9,
267,
871,
1722,
26,
288,
1980,
421,
199,
318,
3272,
8,
571,
304,
272,
1145,
14,
2242,
360,
24003,
13,
815,
297,
3550,
63,
14334,
9,
272,
1145,
14,
525,
63,
1430,
360,
24003,
13,
14334,
13,
10176,
358,
339,
372,
791,
11887,
63,
739,
63,
3489,
356,
715,
12,
283,
11887,
63,
952,
63,
3489,
356,
715,
12,
283,
1023,
356,
283,
16,
14,
18,
936,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
rockychen-dpaw/oim-cms
|
registers/migrations/0003_auto_20161003_2217.py
|
1
|
7301
|
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-10-03 14:17
from __future__ import unicode_literals
from django.db import migrations, models
import registers.models
class Migration(migrations.Migration):
dependencies = [
('registers', '0002_auto_20160919_1303'),
]
operations = [
migrations.AlterModelOptions(
name='processitsystemrelationship',
options={'verbose_name_plural': 'Process/IT System relationships'},
),
migrations.AddField(
model_name='itsystem',
name='alt_processing',
field=models.TextField(blank=True, null=True, verbose_name='alternate processing procedure'),
),
migrations.AddField(
model_name='itsystem',
name='capability',
field=registers.models.ChoiceArrayField(base_field=models.CharField(choices=[('0', 'Information lifecycle'), ('1', 'Communication and collaboration'), ('2', 'Automation and integration'), ('3', 'Security and risk management'), ('4', 'Intelligence and analytics')], max_length=256), blank=True, default=list, null=True, size=None, verbose_name='IT System capabilities'),
),
migrations.AddField(
model_name='itsystem',
name='critical_period',
field=models.CharField(blank=True, help_text='Is there a period/season when this system is most important?', max_length=255, null=True),
),
migrations.AddField(
model_name='itsystem',
name='function',
field=registers.models.ChoiceArrayField(base_field=models.CharField(choices=[('0', 'Planning'), ('1', 'Operation'), ('2', 'Reporting')], max_length=256), blank=True, default=list, null=True, size=None, verbose_name='IT System function(s)'),
),
migrations.AddField(
model_name='itsystem',
name='legal_need_to_retain',
field=models.NullBooleanField(default=None, help_text='Is there a legal or compliance need to keep the digital content in this system?'),
),
migrations.AddField(
model_name='itsystem',
name='notes',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='itsystem',
name='point_of_truth',
field=models.NullBooleanField(default=None, help_text='Is the digital content kept in this business system a single point of truth?'),
),
migrations.AddField(
model_name='itsystem',
name='post_recovery',
field=models.TextField(blank=True, help_text='Functional testing and post recovery procedure.', null=True, verbose_name='post recovery procedure'),
),
migrations.AddField(
model_name='itsystem',
name='risks',
field=registers.models.ChoiceArrayField(base_field=models.CharField(choices=[('0', 'IT System features not aligned to business processes'), ('1', 'IT System technology refresh lifecycle not safeguarded or future-proofed'), ('2', 'IT System data/information integrity and availability not aligned to business processes'), ('3', 'IT System emergency contingency and disaster recovery approach not well established'), ('4', 'IT System support arrangements not well established, value for money and/or safeguarded'), ('5', 'IT System roles and responsibilities not well established'), ('6', 'IT System solution design not aligned to department IT standards'), ('7', 'IT System change management does not consistently consider risk and security'), ('8', 'IT System incident and security management not triaged on business criticality'), ('9', 'IT System user training not well established')], max_length=256), blank=True, default=list, null=True, size=None, verbose_name='IT System risks'),
),
migrations.AddField(
model_name='itsystem',
name='system_creation_date',
field=models.DateField(blank=True, help_text='Date that this system went into production.', null=True),
),
migrations.AddField(
model_name='itsystem',
name='system_health',
field=models.PositiveIntegerField(blank=True, choices=[(0, 'Healthy'), (1, 'Issues noted'), (2, 'At risk')], null=True),
),
migrations.AddField(
model_name='itsystem',
name='technical_recov',
field=models.TextField(blank=True, null=True, verbose_name='technical recovery procedure'),
),
migrations.AddField(
model_name='itsystem',
name='unique_evidence',
field=models.NullBooleanField(default=None, help_text='Is the digital content kept in this business system unique evidence of the official business of the Department?'),
),
migrations.AddField(
model_name='itsystem',
name='use',
field=registers.models.ChoiceArrayField(base_field=models.CharField(choices=[('0', 'Measurement'), ('1', 'Information'), ('2', 'Wisdom'), ('3', 'Data'), ('4', 'Knowledge'), ('5', 'Intelligence')], max_length=256), blank=True, default=list, null=True, size=None, verbose_name='IT System use(s)'),
),
migrations.AddField(
model_name='itsystem',
name='user_notification',
field=models.TextField(blank=True, help_text='List of users/stakeholders to contact regarding incidents', null=True),
),
migrations.AddField(
model_name='itsystem',
name='variation_iscp',
field=models.TextField(blank=True, null=True, verbose_name='Variation to the ISCP'),
),
migrations.AlterField(
model_name='itsystem',
name='access',
field=models.PositiveSmallIntegerField(choices=[(1, 'Public Internet'), (2, 'Authenticated Extranet'), (3, 'Corporate Network'), (4, 'Local System (Networked)'), (5, 'Local System (Standalone)')], default=3, help_text='The network upon which this system is accessible.'),
),
migrations.AlterField(
model_name='itsystem',
name='authentication',
field=models.PositiveSmallIntegerField(choices=[(1, 'Domain/application Credentials'), (2, 'Single Sign On'), (3, 'Externally Managed')], default=1, help_text='The method by which users authenticate themselve to the system.'),
),
migrations.AlterField(
model_name='itsystem',
name='criticality',
field=models.PositiveIntegerField(blank=True, choices=[(1, 'Critical'), (2, 'Moderate'), (3, 'Low')], help_text='How critical is this system to P&W core functions?', null=True),
),
migrations.AlterField(
model_name='itsystem',
name='hardwares',
field=models.ManyToManyField(blank=True, help_text='Hardware that is used to provide this IT System', to='registers.ITSystemHardware', verbose_name='hardware'),
),
migrations.AlterField(
model_name='itsystem',
name='softwares',
field=models.ManyToManyField(blank=True, help_text='Software that is used to provide this IT System', to='registers.Software', verbose_name='software'),
),
]
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
25,
14,
25,
641,
7800,
13,
709,
13,
1644,
4329,
26,
1196,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
24493,
14,
992,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
30792,
297,
283,
9425,
63,
2495,
63,
9261,
1643,
1167,
63,
969,
1644,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14364,
1685,
4558,
8,
288,
536,
534,
496,
823,
30066,
3045,
11704,
297,
288,
1511,
3713,
3832,
63,
354,
63,
10019,
356,
283,
3498,
15,
649,
6187,
20045,
2267,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
4478,
63,
6338,
297,
288,
901,
29,
992,
14,
6254,
8,
2500,
29,
549,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
17170,
6661,
17782,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
21181,
297,
288,
901,
29,
30792,
14,
992,
14,
9054,
3836,
792,
8,
1095,
63,
698,
29,
992,
14,
2183,
8,
4577,
11699,
16,
297,
283,
4935,
15451,
7612,
659,
661,
17,
297,
283,
27258,
425,
436,
1048,
5561,
14496,
659,
661,
18,
297,
283,
3358,
1615,
436,
13150,
659,
661,
19,
297,
283,
7676,
436,
22633,
10041,
659,
661,
20,
297,
283,
8309,
31566,
436,
30159,
2665,
1390,
63,
1267,
29,
3912,
395,
4596,
29,
549,
12,
849,
29,
513,
12,
2973,
29,
549,
12,
1568,
29,
403,
12,
3376,
63,
354,
534,
649,
6187,
14918,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
13138,
63,
5191,
297,
288,
901,
29,
992,
14,
2183,
8,
2500,
29,
549,
12,
1720,
63,
505,
534,
1831,
2337,
282,
6247,
15,
12605,
1380,
642,
2656,
365,
4750,
11012,
7044,
1390,
63,
1267,
29,
2299,
12,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
1593,
297,
288,
901,
29,
30792,
14,
992,
14,
9054,
3836,
792,
8,
1095,
63,
698,
29,
992,
14,
2183,
8,
4577,
11699,
16,
297,
283,
3714,
11495,
659,
661,
17,
297,
283,
6044,
659,
661,
18,
297,
283,
28457,
2665,
1390,
63,
1267,
29,
3912,
395,
4596,
29,
549,
12,
849,
29,
513,
12,
2973,
29,
549,
12,
1568,
29,
403,
12,
3376,
63,
354,
534,
649,
6187,
805,
8,
83,
11218,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
9666,
63,
9321,
63,
475,
63,
264,
877,
297,
288,
901,
29,
992,
14,
29068,
8,
885,
29,
403,
12,
1720,
63,
505,
534,
1831,
2337,
282,
18393,
503,
4151,
1929,
370,
4215,
314,
20545,
1564,
315,
642,
2656,
31,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
5983,
297,
288,
901,
29,
992,
14,
6254,
8,
2500,
29,
549,
12,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
1403,
63,
1618,
63,
17167,
297,
288,
901,
29,
992,
14,
29068,
8,
885,
29,
403,
12,
1720,
63,
505,
534,
1831,
314,
20545,
1564,
16204,
315,
642,
26440,
2656,
282,
2849,
2376,
402,
16865,
31,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
1932,
63,
29920,
297,
288,
901,
29,
992,
14,
6254,
8,
2500,
29,
549,
12,
1720,
63,
505,
534,
3481,
279,
5343,
436,
2963,
24201,
17782,
3130,
2973,
29,
549,
12,
3376,
63,
354,
534,
1932,
24201,
17782,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
27473,
83,
297,
288,
901,
29,
30792,
14,
992,
14,
9054,
3836,
792,
8,
1095,
63,
698,
29,
992,
14,
2183,
8,
4577,
11699,
16,
297,
283,
649,
6187,
4534,
440,
22569,
370,
26440,
10358,
659,
661,
17,
297,
283,
649,
6187,
1565,
24731,
9236,
15451,
7612,
440,
5048,
6051,
12910,
503,
6466,
13,
496,
1618,
379,
659,
661,
18,
297,
283,
649,
6187,
666,
15,
11697,
4661,
12997,
436,
14962,
440,
22569,
370,
26440,
10358,
659,
661,
19,
297,
283,
649,
6187,
325,
2626,
27798,
406,
1337,
9501,
436,
2153,
2311,
24201,
18140,
440,
5521,
23594,
659,
661,
20,
297,
283,
649,
6187,
2291,
601,
1842,
1470,
440,
5521,
23594,
12,
574,
367,
333,
13234,
436,
15,
269,
5048,
6051,
12910,
659,
661,
21,
297,
283,
649,
6187,
11689,
436,
9163,
23422,
440,
5521,
23594,
659,
661,
22,
297,
283,
649,
6187,
8744,
12899,
440,
22569,
370,
27669,
473,
52,
10584,
5596,
659,
661,
23,
297,
283,
649,
6187,
1570,
10041,
1630,
440,
12137,
590,
11201,
22633,
436,
6391,
659,
661,
24,
297,
283,
649,
6187,
315,
12689,
436,
6391,
10041,
440,
3229,
6028,
641,
26440,
19698,
1209,
659,
661,
25,
297,
283,
649,
6187,
922,
6093,
440,
5521,
23594,
2665,
1390,
63,
1267,
29,
3912,
395,
4596,
29,
549,
12,
849,
29,
513,
12,
2973,
29,
549,
12,
1568,
29,
403,
12,
3376,
63,
354,
534,
649,
6187,
22633,
83,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
2253,
63,
8782,
63,
602,
297,
288,
901,
29,
992,
14,
14071,
8,
2500,
29,
549,
12,
1720,
63,
505,
534,
2506,
626,
642,
2656,
22396,
1901,
9920,
3130,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
2253,
63,
9665,
297,
288,
901,
29,
992,
14,
8591,
8,
2500,
29,
549,
12,
3415,
17497,
16,
12,
283,
18850,
89,
659,
334,
17,
12,
283,
17106,
83,
949,
471,
659,
334,
18,
12,
283,
1271,
22633,
2665,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
266,
28836,
63,
264,
8695,
297,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
25,
14,
25,
641,
7800,
13,
709,
13,
1644,
4329,
26,
1196,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
24493,
14,
992,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
30792,
297,
283,
9425,
63,
2495,
63,
9261,
1643,
1167,
63,
969,
1644,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14364,
1685,
4558,
8,
288,
536,
534,
496,
823,
30066,
3045,
11704,
297,
288,
1511,
3713,
3832,
63,
354,
63,
10019,
356,
283,
3498,
15,
649,
6187,
20045,
2267,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
4478,
63,
6338,
297,
288,
901,
29,
992,
14,
6254,
8,
2500,
29,
549,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
17170,
6661,
17782,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
21181,
297,
288,
901,
29,
30792,
14,
992,
14,
9054,
3836,
792,
8,
1095,
63,
698,
29,
992,
14,
2183,
8,
4577,
11699,
16,
297,
283,
4935,
15451,
7612,
659,
661,
17,
297,
283,
27258,
425,
436,
1048,
5561,
14496,
659,
661,
18,
297,
283,
3358,
1615,
436,
13150,
659,
661,
19,
297,
283,
7676,
436,
22633,
10041,
659,
661,
20,
297,
283,
8309,
31566,
436,
30159,
2665,
1390,
63,
1267,
29,
3912,
395,
4596,
29,
549,
12,
849,
29,
513,
12,
2973,
29,
549,
12,
1568,
29,
403,
12,
3376,
63,
354,
534,
649,
6187,
14918,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
13138,
63,
5191,
297,
288,
901,
29,
992,
14,
2183,
8,
2500,
29,
549,
12,
1720,
63,
505,
534,
1831,
2337,
282,
6247,
15,
12605,
1380,
642,
2656,
365,
4750,
11012,
7044,
1390,
63,
1267,
29,
2299,
12,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
1593,
297,
288,
901,
29,
30792,
14,
992,
14,
9054,
3836,
792,
8,
1095,
63,
698,
29,
992,
14,
2183,
8,
4577,
11699,
16,
297,
283,
3714,
11495,
659,
661,
17,
297,
283,
6044,
659,
661,
18,
297,
283,
28457,
2665,
1390,
63,
1267,
29,
3912,
395,
4596,
29,
549,
12,
849,
29,
513,
12,
2973,
29,
549,
12,
1568,
29,
403,
12,
3376,
63,
354,
534,
649,
6187,
805,
8,
83,
11218,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
9666,
63,
9321,
63,
475,
63,
264,
877,
297,
288,
901,
29,
992,
14,
29068,
8,
885,
29,
403,
12,
1720,
63,
505,
534,
1831,
2337,
282,
18393,
503,
4151,
1929,
370,
4215,
314,
20545,
1564,
315,
642,
2656,
31,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
5983,
297,
288,
901,
29,
992,
14,
6254,
8,
2500,
29,
549,
12,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
1403,
63,
1618,
63,
17167,
297,
288,
901,
29,
992,
14,
29068,
8,
885,
29,
403,
12,
1720,
63,
505,
534,
1831,
314,
20545,
1564,
16204,
315,
642,
26440,
2656,
282,
2849,
2376,
402,
16865,
31,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
1932,
63,
29920,
297,
288,
901,
29,
992,
14,
6254,
8,
2500,
29,
549,
12,
1720,
63,
505,
534,
3481,
279,
5343,
436,
2963,
24201,
17782,
3130,
2973,
29,
549,
12,
3376,
63,
354,
534,
1932,
24201,
17782,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
27473,
83,
297,
288,
901,
29,
30792,
14,
992,
14,
9054,
3836,
792,
8,
1095,
63,
698,
29,
992,
14,
2183,
8,
4577,
11699,
16,
297,
283,
649,
6187,
4534,
440,
22569,
370,
26440,
10358,
659,
661,
17,
297,
283,
649,
6187,
1565,
24731,
9236,
15451,
7612,
440,
5048,
6051,
12910,
503,
6466,
13,
496,
1618,
379,
659,
661,
18,
297,
283,
649,
6187,
666,
15,
11697,
4661,
12997,
436,
14962,
440,
22569,
370,
26440,
10358,
659,
661,
19,
297,
283,
649,
6187,
325,
2626,
27798,
406,
1337,
9501,
436,
2153,
2311,
24201,
18140,
440,
5521,
23594,
659,
661,
20,
297,
283,
649,
6187,
2291,
601,
1842,
1470,
440,
5521,
23594,
12,
574,
367,
333,
13234,
436,
15,
269,
5048,
6051,
12910,
659,
661,
21,
297,
283,
649,
6187,
11689,
436,
9163,
23422,
440,
5521,
23594,
659,
661,
22,
297,
283,
649,
6187,
8744,
12899,
440,
22569,
370,
27669,
473,
52,
10584,
5596,
659,
661,
23,
297,
283,
649,
6187,
1570,
10041,
1630,
440,
12137,
590,
11201,
22633,
436,
6391,
659,
661,
24,
297,
283,
649,
6187,
315,
12689,
436,
6391,
10041,
440,
3229,
6028,
641,
26440,
19698,
1209,
659,
661,
25,
297,
283,
649,
6187,
922,
6093,
440,
5521,
23594,
2665,
1390,
63,
1267,
29,
3912,
395,
4596,
29,
549,
12,
849,
29,
513,
12,
2973,
29,
549,
12,
1568,
29,
403,
12,
3376,
63,
354,
534,
649,
6187,
22633,
83,
659,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
2253,
63,
8782,
63,
602,
297,
288,
901,
29,
992,
14,
14071,
8,
2500,
29,
549,
12,
1720,
63,
505,
534,
2506,
626,
642,
2656,
22396,
1901,
9920,
3130,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
2253,
63,
9665,
297,
288,
901,
29,
992,
14,
8591,
8,
2500,
29,
549,
12,
3415,
17497,
16,
12,
283,
18850,
89,
659,
334,
17,
12,
283,
17106,
83,
949,
471,
659,
334,
18,
12,
283,
1271,
22633,
2665,
2973,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
390,
2253,
297,
288,
536,
534,
266,
28836,
63,
264,
8695,
297,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DirectXMan12/nova-hacking
|
nova/tests/db/test_sqlite.py
|
12
|
2231
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# Copyright 2010 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.
"""Test cases for sqlite-specific logic"""
from nova import test
import os
from sqlalchemy import create_engine
from sqlalchemy import Column, BigInteger, String
from sqlalchemy.ext.declarative import declarative_base
import subprocess
class TestSqlite(test.TestCase):
"""Tests for sqlite-specific logic."""
def setUp(self):
super(TestSqlite, self).setUp()
self.db_file = "test_bigint.sqlite"
if os.path.exists(self.db_file):
os.remove(self.db_file)
def test_big_int_mapping(self):
base_class = declarative_base()
class User(base_class):
"""Dummy class with a BigInteger column for testing."""
__tablename__ = "users"
id = Column(BigInteger, primary_key=True)
name = Column(String)
get_schema_cmd = "sqlite3 %s '.schema'" % self.db_file
engine = create_engine("sqlite:///%s" % self.db_file)
base_class.metadata.create_all(engine)
process = subprocess.Popen(get_schema_cmd, shell=True,
stdout=subprocess.PIPE)
output, _ = process.communicate()
self.assertFalse('BIGINT' in output, msg="column type BIGINT "
"not converted to INTEGER in schema")
def tearDown(self):
if os.path.exists(self.db_file):
os.remove(self.db_file)
super(TestSqlite, self).tearDown()
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7129,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
1898,
7129,
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,
624,
774,
5560,
367,
11723,
13,
6100,
9661,
624,
199,
199,
504,
5913,
492,
511,
199,
646,
747,
199,
504,
8335,
492,
1218,
63,
3908,
199,
504,
8335,
492,
4996,
12,
13123,
2674,
12,
2624,
199,
504,
8335,
14,
832,
14,
12164,
1905,
492,
30191,
63,
1095,
199,
646,
3873,
421,
199,
533,
1379,
24614,
5333,
8,
396,
14,
1746,
304,
272,
408,
2925,
367,
11723,
13,
6100,
9661,
1041,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
24614,
5333,
12,
291,
680,
5996,
342,
267,
291,
14,
697,
63,
493,
275,
298,
396,
63,
24884,
14,
10659,
2,
267,
340,
747,
14,
515,
14,
2444,
8,
277,
14,
697,
63,
493,
304,
288,
747,
14,
2168,
8,
277,
14,
697,
63,
493,
9,
339,
347,
511,
63,
5076,
63,
442,
63,
4745,
8,
277,
304,
267,
1300,
63,
533,
275,
30191,
63,
1095,
342,
398,
1021,
2876,
8,
1095,
63,
533,
304,
288,
408,
11324,
1021,
543,
282,
13123,
2674,
2763,
367,
5343,
1041,
288,
636,
10983,
363,
275,
298,
3707,
2,
288,
1305,
275,
4996,
8,
7279,
2674,
12,
5062,
63,
498,
29,
549,
9,
288,
536,
275,
4996,
8,
1558,
9,
398,
664,
63,
3629,
63,
1760,
275,
298,
10659,
19,
450,
83,
1987,
3629,
4065,
450,
291,
14,
697,
63,
493,
267,
6869,
275,
1218,
63,
3908,
480,
10659,
921,
3149,
83,
2,
450,
291,
14,
697,
63,
493,
9,
267,
1300,
63,
533,
14,
2343,
14,
981,
63,
452,
8,
3908,
9,
267,
2112,
275,
3873,
14,
7942,
8,
362,
63,
3629,
63,
1760,
12,
5218,
29,
549,
12,
3521,
3839,
29,
5781,
14,
6089,
9,
267,
1072,
12,
485,
275,
2112,
14,
10664,
342,
267,
291,
14,
3334,
360,
18643,
2919,
7,
315,
1072,
12,
1499,
628,
2301,
730,
16524,
2919,
298,
586,
298,
1397,
6702,
370,
17086,
315,
4177,
531,
339,
347,
6766,
8,
277,
304,
267,
340,
747,
14,
515,
14,
2444,
8,
277,
14,
697,
63,
493,
304,
288,
747,
14,
2168,
8,
277,
14,
697,
63,
493,
9,
267,
1613,
8,
774,
24614,
5333,
12,
291,
680,
12336,
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
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7129,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
1898,
7129,
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,
624,
774,
5560,
367,
11723,
13,
6100,
9661,
624,
199,
199,
504,
5913,
492,
511,
199,
646,
747,
199,
504,
8335,
492,
1218,
63,
3908,
199,
504,
8335,
492,
4996,
12,
13123,
2674,
12,
2624,
199,
504,
8335,
14,
832,
14,
12164,
1905,
492,
30191,
63,
1095,
199,
646,
3873,
421,
199,
533,
1379,
24614,
5333,
8,
396,
14,
1746,
304,
272,
408,
2925,
367,
11723,
13,
6100,
9661,
1041,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
24614,
5333,
12,
291,
680,
5996,
342,
267,
291,
14,
697,
63,
493,
275,
298,
396,
63,
24884,
14,
10659,
2,
267,
340,
747,
14,
515,
14,
2444,
8,
277,
14,
697,
63,
493,
304,
288,
747,
14,
2168,
8,
277,
14,
697,
63,
493,
9,
339,
347,
511,
63,
5076,
63,
442,
63,
4745,
8,
277,
304,
267,
1300,
63,
533,
275,
30191,
63,
1095,
342,
398,
1021,
2876,
8,
1095,
63,
533,
304,
288,
408,
11324,
1021,
543,
282,
13123,
2674,
2763,
367,
5343,
1041,
288,
636,
10983,
363,
275,
298,
3707,
2,
288,
1305,
275,
4996,
8,
7279,
2674,
12,
5062,
63,
498,
29,
549,
9,
288,
536,
275,
4996,
8,
1558,
9,
398,
664,
63,
3629,
63,
1760,
275,
298,
10659,
19,
450,
83,
1987,
3629,
4065,
450,
291,
14,
697,
63,
493,
267,
6869,
275,
1218,
63,
3908,
480,
10659,
921,
3149,
83,
2,
450,
291,
14,
697,
63,
493,
9,
267,
1300,
63,
533,
14,
2343,
14,
981,
63,
452,
8,
3908,
9,
267,
2112,
275,
3873,
14,
7942,
8,
362,
63,
3629,
63,
1760,
12,
5218,
29,
549,
12,
3521,
3839,
29,
5781,
14,
6089,
9,
267,
1072,
12,
485,
275,
2112,
14,
10664,
342,
267,
291,
14,
3334,
360,
18643,
2919,
7,
315,
1072,
12,
1499,
628,
2301,
730,
16524,
2919,
298,
586,
298,
1397,
6702,
370,
17086,
315,
4177,
531,
339,
347,
6766,
8,
277,
304,
267,
340,
747,
14,
515,
14,
2444,
8,
277,
14,
697,
63,
493,
304,
288,
747,
14,
2168,
8,
277,
14,
697,
63,
493,
9,
267,
1613,
8,
774,
24614,
5333,
12,
291,
680,
12336,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Srisai85/numpy
|
numpy/core/tests/test_indexing.py
|
13
|
39934
|
from __future__ import division, absolute_import, print_function
import sys
import warnings
import functools
import numpy as np
from numpy.core.multiarray_tests import array_indexing
from itertools import product
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
assert_array_equal, assert_warns
)
try:
cdll = np.ctypeslib.load_library('multiarray', np.core.multiarray.__file__)
_HAS_CTYPE = True
except ImportError:
_HAS_CTYPE = False
class TestIndexing(TestCase):
def test_none_index(self):
# `None` index adds newaxis
a = np.array([1, 2, 3])
assert_equal(a[None], a[np.newaxis])
assert_equal(a[None].ndim, a.ndim + 1)
def test_empty_tuple_index(self):
# Empty tuple index creates a view
a = np.array([1, 2, 3])
assert_equal(a[()], a)
assert_(a[()].base is a)
a = np.array(0)
assert_(isinstance(a[()], np.int_))
# Regression, it needs to fall through integer and fancy indexing
# cases, so need the with statement to ignore the non-integer error.
with warnings.catch_warnings():
warnings.filterwarnings('ignore', '', DeprecationWarning)
a = np.array([1.])
assert_(isinstance(a[0.], np.float_))
a = np.array([np.array(1)], dtype=object)
assert_(isinstance(a[0.], np.ndarray))
def test_same_kind_index_casting(self):
# Indexes should be cast with same-kind and not safe, even if
# that is somewhat unsafe. So test various different code paths.
index = np.arange(5)
u_index = index.astype(np.uintp)
arr = np.arange(10)
assert_array_equal(arr[index], arr[u_index])
arr[u_index] = np.arange(5)
assert_array_equal(arr, np.arange(10))
arr = np.arange(10).reshape(5, 2)
assert_array_equal(arr[index], arr[u_index])
arr[u_index] = np.arange(5)[:,None]
assert_array_equal(arr, np.arange(5)[:,None].repeat(2, axis=1))
arr = np.arange(25).reshape(5, 5)
assert_array_equal(arr[u_index, u_index], arr[index, index])
def test_empty_fancy_index(self):
# Empty list index creates an empty array
# with the same dtype (but with weird shape)
a = np.array([1, 2, 3])
assert_equal(a[[]], [])
assert_equal(a[[]].dtype, a.dtype)
b = np.array([], dtype=np.intp)
assert_equal(a[[]], [])
assert_equal(a[[]].dtype, a.dtype)
b = np.array([])
assert_raises(IndexError, a.__getitem__, b)
def test_ellipsis_index(self):
# Ellipsis index does not create a view
a = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
assert_equal(a[...], a)
assert_(a[...].base is a) # `a[...]` was `a` in numpy <1.9.)
# Slicing with ellipsis can skip an
# arbitrary number of dimensions
assert_equal(a[0, ...], a[0])
assert_equal(a[0, ...], a[0,:])
assert_equal(a[..., 0], a[:, 0])
# Slicing with ellipsis always results
# in an array, not a scalar
assert_equal(a[0, ..., 1], np.array(2))
# Assignment with `(Ellipsis,)` on 0-d arrays
b = np.array(1)
b[(Ellipsis,)] = 2
assert_equal(b, 2)
def test_single_int_index(self):
# Single integer index selects one row
a = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
assert_equal(a[0], [1, 2, 3])
assert_equal(a[-1], [7, 8, 9])
# Index out of bounds produces IndexError
assert_raises(IndexError, a.__getitem__, 1 << 30)
# Index overflow produces IndexError
assert_raises(IndexError, a.__getitem__, 1 << 64)
def test_single_bool_index(self):
# Single boolean index
a = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# Python boolean converts to integer
# These are being deprecated (and test in test_deprecations)
#assert_equal(a[True], a[1])
#assert_equal(a[False], a[0])
# Same with NumPy boolean scalar
# Before DEPRECATE, this is an error (as always, but telling about
# future change):
assert_raises(IndexError, a.__getitem__, np.array(True))
assert_raises(IndexError, a.__getitem__, np.array(False))
# After DEPRECATE, this behaviour can be enabled:
#assert_equal(a[np.array(True)], a[None])
#assert_equal(a[np.array(False), a[None][0:0]])
def test_boolean_indexing_onedim(self):
# Indexing a 2-dimensional array with
# boolean array of length one
a = np.array([[ 0., 0., 0.]])
b = np.array([ True], dtype=bool)
assert_equal(a[b], a)
# boolean assignment
a[b] = 1.
assert_equal(a, [[1., 1., 1.]])
def test_boolean_assignment_value_mismatch(self):
# A boolean assignment should fail when the shape of the values
# cannot be broadcast to the subscription. (see also gh-3458)
a = np.arange(4)
def f(a, v):
a[a > -1] = v
assert_raises(ValueError, f, a, [])
assert_raises(ValueError, f, a, [1, 2, 3])
assert_raises(ValueError, f, a[:1], [1, 2, 3])
def test_boolean_indexing_twodim(self):
# Indexing a 2-dimensional array with
# 2-dimensional boolean array
a = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
b = np.array([[ True, False, True],
[False, True, False],
[ True, False, True]])
assert_equal(a[b], [1, 3, 5, 7, 9])
assert_equal(a[b[1]], [[4, 5, 6]])
assert_equal(a[b[0]], a[b[2]])
# boolean assignment
a[b] = 0
assert_equal(a, [[0, 2, 0],
[4, 0, 6],
[0, 8, 0]])
def test_reverse_strides_and_subspace_bufferinit(self):
# This tests that the strides are not reversed for simple and
# subspace fancy indexing.
a = np.ones(5)
b = np.zeros(5, dtype=np.intp)[::-1]
c = np.arange(5)[::-1]
a[b] = c
# If the strides are not reversed, the 0 in the arange comes last.
assert_equal(a[0], 0)
# This also tests that the subspace buffer is initialized:
a = np.ones((5, 2))
c = np.arange(10).reshape(5, 2)[::-1]
a[b, :] = c
assert_equal(a[0], [0, 1])
def test_reversed_strides_result_allocation(self):
# Test a bug when calculating the output strides for a result array
# when the subspace size was 1 (and test other cases as well)
a = np.arange(10)[:, None]
i = np.arange(10)[::-1]
assert_array_equal(a[i], a[i.copy('C')])
a = np.arange(20).reshape(-1, 2)
def test_uncontiguous_subspace_assignment(self):
# During development there was a bug activating a skip logic
# based on ndim instead of size.
a = np.full((3, 4, 2), -1)
b = np.full((3, 4, 2), -1)
a[[0, 1]] = np.arange(2 * 4 * 2).reshape(2, 4, 2).T
b[[0, 1]] = np.arange(2 * 4 * 2).reshape(2, 4, 2).T.copy()
assert_equal(a, b)
def test_too_many_fancy_indices_special_case(self):
# Just documents behaviour, this is a small limitation.
a = np.ones((1,) * 32) # 32 is NPY_MAXDIMS
assert_raises(IndexError, a.__getitem__, (np.array([0]),) * 32)
def test_scalar_array_bool(self):
# Numpy bools can be used as boolean index (python ones as of yet not)
a = np.array(1)
assert_equal(a[np.bool_(True)], a[np.array(True)])
assert_equal(a[np.bool_(False)], a[np.array(False)])
# After deprecating bools as integers:
#a = np.array([0,1,2])
#assert_equal(a[True, :], a[None, :])
#assert_equal(a[:, True], a[:, None])
#
#assert_(not np.may_share_memory(a, a[True, :]))
def test_everything_returns_views(self):
# Before `...` would return a itself.
a = np.arange(5)
assert_(a is not a[()])
assert_(a is not a[...])
assert_(a is not a[:])
def test_broaderrors_indexing(self):
a = np.zeros((5, 5))
assert_raises(IndexError, a.__getitem__, ([0, 1], [0, 1, 2]))
assert_raises(IndexError, a.__setitem__, ([0, 1], [0, 1, 2]), 0)
def test_trivial_fancy_out_of_bounds(self):
a = np.zeros(5)
ind = np.ones(20, dtype=np.intp)
ind[-1] = 10
assert_raises(IndexError, a.__getitem__, ind)
assert_raises(IndexError, a.__setitem__, ind, 0)
ind = np.ones(20, dtype=np.intp)
ind[0] = 11
assert_raises(IndexError, a.__getitem__, ind)
assert_raises(IndexError, a.__setitem__, ind, 0)
def test_nonbaseclass_values(self):
class SubClass(np.ndarray):
def __array_finalize__(self, old):
# Have array finalize do funny things
self.fill(99)
a = np.zeros((5, 5))
s = a.copy().view(type=SubClass)
s.fill(1)
a[[0, 1, 2, 3, 4], :] = s
assert_((a == 1).all())
# Subspace is last, so transposing might want to finalize
a[:, [0, 1, 2, 3, 4]] = s
assert_((a == 1).all())
a.fill(0)
a[...] = s
assert_((a == 1).all())
def test_subclass_writeable(self):
d = np.rec.array([('NGC1001', 11), ('NGC1002', 1.), ('NGC1003', 1.)],
dtype=[('target', 'S20'), ('V_mag', '>f4')])
ind = np.array([False, True, True], dtype=bool)
assert_(d[ind].flags.writeable)
ind = np.array([0, 1])
assert_(d[ind].flags.writeable)
assert_(d[...].flags.writeable)
assert_(d[0].flags.writeable)
def test_memory_order(self):
# This is not necessary to preserve. Memory layouts for
# more complex indices are not as simple.
a = np.arange(10)
b = np.arange(10).reshape(5,2).T
assert_(a[b].flags.f_contiguous)
# Takes a different implementation branch:
a = a.reshape(-1, 1)
assert_(a[b, 0].flags.f_contiguous)
def test_scalar_return_type(self):
# Full scalar indices should return scalars and object
# arrays should not call PyArray_Return on their items
class Zero(object):
# The most basic valid indexing
def __index__(self):
return 0
z = Zero()
class ArrayLike(object):
# Simple array, should behave like the array
def __array__(self):
return np.array(0)
a = np.zeros(())
assert_(isinstance(a[()], np.float_))
a = np.zeros(1)
assert_(isinstance(a[z], np.float_))
a = np.zeros((1, 1))
assert_(isinstance(a[z, np.array(0)], np.float_))
assert_(isinstance(a[z, ArrayLike()], np.float_))
# And object arrays do not call it too often:
b = np.array(0)
a = np.array(0, dtype=object)
a[()] = b
assert_(isinstance(a[()], np.ndarray))
a = np.array([b, None])
assert_(isinstance(a[z], np.ndarray))
a = np.array([[b, None]])
assert_(isinstance(a[z, np.array(0)], np.ndarray))
assert_(isinstance(a[z, ArrayLike()], np.ndarray))
def test_small_regressions(self):
# Reference count of intp for index checks
a = np.array([0])
refcount = sys.getrefcount(np.dtype(np.intp))
# item setting always checks indices in separate function:
a[np.array([0], dtype=np.intp)] = 1
a[np.array([0], dtype=np.uint8)] = 1
assert_raises(IndexError, a.__setitem__,
np.array([1], dtype=np.intp), 1)
assert_raises(IndexError, a.__setitem__,
np.array([1], dtype=np.uint8), 1)
assert_equal(sys.getrefcount(np.dtype(np.intp)), refcount)
def test_unaligned(self):
v = (np.zeros(64, dtype=np.int8) + ord('a'))[1:-7]
d = v.view(np.dtype("S8"))
# unaligned source
x = (np.zeros(16, dtype=np.int8) + ord('a'))[1:-7]
x = x.view(np.dtype("S8"))
x[...] = np.array("b" * 8, dtype="S")
b = np.arange(d.size)
#trivial
assert_equal(d[b], d)
d[b] = x
# nontrivial
# unaligned index array
b = np.zeros(d.size + 1).view(np.int8)[1:-(np.intp(0).itemsize - 1)]
b = b.view(np.intp)[:d.size]
b[...] = np.arange(d.size)
assert_equal(d[b.astype(np.int16)], d)
d[b.astype(np.int16)] = x
# boolean
d[b % 2 == 0]
d[b % 2 == 0] = x[::2]
def test_tuple_subclass(self):
arr = np.ones((5, 5))
# A tuple subclass should also be an nd-index
class TupleSubclass(tuple):
pass
index = ([1], [1])
index = TupleSubclass(index)
assert_(arr[index].shape == (1,))
# Unlike the non nd-index:
assert_(arr[index,].shape != (1,))
def test_broken_sequence_not_nd_index(self):
# See gh-5063:
# If we have an object which claims to be a sequence, but fails
# on item getting, this should not be converted to an nd-index (tuple)
# If this object happens to be a valid index otherwise, it should work
# This object here is very dubious and probably bad though:
class SequenceLike(object):
def __index__(self):
return 0
def __len__(self):
return 1
def __getitem__(self, item):
raise IndexError('Not possible')
arr = np.arange(10)
assert_array_equal(arr[SequenceLike()], arr[SequenceLike(),])
# also test that field indexing does not segfault
# for a similar reason, by indexing a structured array
arr = np.zeros((1,), dtype=[('f1', 'i8'), ('f2', 'i8')])
assert_array_equal(arr[SequenceLike()], arr[SequenceLike(),])
class TestFieldIndexing(TestCase):
def test_scalar_return_type(self):
# Field access on an array should return an array, even if it
# is 0-d.
a = np.zeros((), [('a','f8')])
assert_(isinstance(a['a'], np.ndarray))
assert_(isinstance(a[['a']], np.ndarray))
class TestBroadcastedAssignments(TestCase):
def assign(self, a, ind, val):
a[ind] = val
return a
def test_prepending_ones(self):
a = np.zeros((3, 2))
a[...] = np.ones((1, 3, 2))
# Fancy with subspace with and without transpose
a[[0, 1, 2], :] = np.ones((1, 3, 2))
a[:, [0, 1]] = np.ones((1, 3, 2))
# Fancy without subspace (with broadcasting)
a[[[0], [1], [2]], [0, 1]] = np.ones((1, 3, 2))
def test_prepend_not_one(self):
assign = self.assign
s_ = np.s_
a = np.zeros(5)
# Too large and not only ones.
assert_raises(ValueError, assign, a, s_[...], np.ones((2, 1)))
with warnings.catch_warnings():
# Will be a ValueError as well.
warnings.simplefilter("error", DeprecationWarning)
assert_raises(DeprecationWarning, assign, a, s_[[1, 2, 3],],
np.ones((2, 1)))
assert_raises(DeprecationWarning, assign, a, s_[[[1], [2]],],
np.ones((2,2,1)))
def test_simple_broadcasting_errors(self):
assign = self.assign
s_ = np.s_
a = np.zeros((5, 1))
assert_raises(ValueError, assign, a, s_[...], np.zeros((5, 2)))
assert_raises(ValueError, assign, a, s_[...], np.zeros((5, 0)))
assert_raises(ValueError, assign, a, s_[:, [0]], np.zeros((5, 2)))
assert_raises(ValueError, assign, a, s_[:, [0]], np.zeros((5, 0)))
assert_raises(ValueError, assign, a, s_[[0], :], np.zeros((2, 1)))
def test_index_is_larger(self):
# Simple case of fancy index broadcasting of the index.
a = np.zeros((5, 5))
a[[[0], [1], [2]], [0, 1, 2]] = [2, 3, 4]
assert_((a[:3, :3] == [2, 3, 4]).all())
def test_broadcast_subspace(self):
a = np.zeros((100, 100))
v = np.arange(100)[:,None]
b = np.arange(100)[::-1]
a[b] = v
assert_((a[::-1] == v).all())
class TestSubclasses(TestCase):
def test_basic(self):
class SubClass(np.ndarray):
pass
s = np.arange(5).view(SubClass)
assert_(isinstance(s[:3], SubClass))
assert_(s[:3].base is s)
assert_(isinstance(s[[0, 1, 2]], SubClass))
assert_(isinstance(s[s > 0], SubClass))
def test_matrix_fancy(self):
# The matrix class messes with the shape. While this is always
# weird (getitem is not used, it does not have setitem nor knows
# about fancy indexing), this tests gh-3110
m = np.matrix([[1, 2], [3, 4]])
assert_(isinstance(m[[0,1,0], :], np.matrix))
# gh-3110. Note the transpose currently because matrices do *not*
# support dimension fixing for fancy indexing correctly.
x = np.asmatrix(np.arange(50).reshape(5,10))
assert_equal(x[:2, np.array(-1)], x[:2, -1].T)
def test_finalize_gets_full_info(self):
# Array finalize should be called on the filled array.
class SubClass(np.ndarray):
def __array_finalize__(self, old):
self.finalize_status = np.array(self)
self.old = old
s = np.arange(10).view(SubClass)
new_s = s[:3]
assert_array_equal(new_s.finalize_status, new_s)
assert_array_equal(new_s.old, s)
new_s = s[[0,1,2,3]]
assert_array_equal(new_s.finalize_status, new_s)
assert_array_equal(new_s.old, s)
new_s = s[s > 0]
assert_array_equal(new_s.finalize_status, new_s)
assert_array_equal(new_s.old, s)
class TestFancingIndexingCast(TestCase):
def test_boolean_index_cast_assign(self):
# Setup the boolean index and float arrays.
shape = (8, 63)
bool_index = np.zeros(shape).astype(bool)
bool_index[0, 1] = True
zero_array = np.zeros(shape)
# Assigning float is fine.
zero_array[bool_index] = np.array([1])
assert_equal(zero_array[0, 1], 1)
# Fancy indexing works, although we get a cast warning.
assert_warns(np.ComplexWarning,
zero_array.__setitem__, ([0], [1]), np.array([2 + 1j]))
assert_equal(zero_array[0, 1], 2) # No complex part
# Cast complex to float, throwing away the imaginary portion.
assert_warns(np.ComplexWarning,
zero_array.__setitem__, bool_index, np.array([1j]))
assert_equal(zero_array[0, 1], 0)
class TestFancyIndexingEquivalence(TestCase):
def test_object_assign(self):
# Check that the field and object special case using copyto is active.
# The right hand side cannot be converted to an array here.
a = np.arange(5, dtype=object)
b = a.copy()
a[:3] = [1, (1,2), 3]
b[[0, 1, 2]] = [1, (1,2), 3]
assert_array_equal(a, b)
# test same for subspace fancy indexing
b = np.arange(5, dtype=object)[None, :]
b[[0], :3] = [[1, (1,2), 3]]
assert_array_equal(a, b[0])
# Check that swapping of axes works.
# There was a bug that made the later assignment throw a ValueError
# do to an incorrectly transposed temporary right hand side (gh-5714)
b = b.T
b[:3, [0]] = [[1], [(1,2)], [3]]
assert_array_equal(a, b[:, 0])
# Another test for the memory order of the subspace
arr = np.ones((3, 4, 5), dtype=object)
# Equivalent slicing assignment for comparison
cmp_arr = arr.copy()
cmp_arr[:1, ...] = [[[1], [2], [3], [4]]]
arr[[0], ...] = [[[1], [2], [3], [4]]]
assert_array_equal(arr, cmp_arr)
arr = arr.copy('F')
arr[[0], ...] = [[[1], [2], [3], [4]]]
assert_array_equal(arr, cmp_arr)
def test_cast_equivalence(self):
# Yes, normal slicing uses unsafe casting.
a = np.arange(5)
b = a.copy()
a[:3] = np.array(['2', '-3', '-1'])
b[[0, 2, 1]] = np.array(['2', '-1', '-3'])
assert_array_equal(a, b)
# test the same for subspace fancy indexing
b = np.arange(5)[None, :]
b[[0], :3] = np.array([['2', '-3', '-1']])
assert_array_equal(a, b[0])
class TestMultiIndexingAutomated(TestCase):
"""
These test use code to mimic the C-Code indexing for selection.
NOTE: * This still lacks tests for complex item setting.
* If you change behavior of indexing, you might want to modify
these tests to try more combinations.
* Behavior was written to match numpy version 1.8. (though a
first version matched 1.7.)
* Only tuple indices are supported by the mimicking code.
(and tested as of writing this)
* Error types should match most of the time as long as there
is only one error. For multiple errors, what gets raised
will usually not be the same one. They are *not* tested.
"""
def setUp(self):
self.a = np.arange(np.prod([3, 1, 5, 6])).reshape(3, 1, 5, 6)
self.b = np.empty((3, 0, 5, 6))
self.complex_indices = ['skip', Ellipsis,
0,
# Boolean indices, up to 3-d for some special cases of eating up
# dimensions, also need to test all False
np.array(False),
np.array([True, False, False]),
np.array([[True, False], [False, True]]),
np.array([[[False, False], [False, False]]]),
# Some slices:
slice(-5, 5, 2),
slice(1, 1, 100),
slice(4, -1, -2),
slice(None, None, -3),
# Some Fancy indexes:
np.empty((0, 1, 1), dtype=np.intp), # empty and can be broadcast
np.array([0, 1, -2]),
np.array([[2], [0], [1]]),
np.array([[0, -1], [0, 1]], dtype=np.dtype('intp').newbyteorder()),
np.array([2, -1], dtype=np.int8),
np.zeros([1]*31, dtype=int), # trigger too large array.
np.array([0., 1.])] # invalid datatype
# Some simpler indices that still cover a bit more
self.simple_indices = [Ellipsis, None, -1, [1], np.array([True]), 'skip']
# Very simple ones to fill the rest:
self.fill_indices = [slice(None, None), 0]
def _get_multi_index(self, arr, indices):
"""Mimic multi dimensional indexing.
Parameters
----------
arr : ndarray
Array to be indexed.
indices : tuple of index objects
Returns
-------
out : ndarray
An array equivalent to the indexing operation (but always a copy).
`arr[indices]` should be identical.
no_copy : bool
Whether the indexing operation requires a copy. If this is `True`,
`np.may_share_memory(arr, arr[indicies])` should be `True` (with
some exceptions for scalars and possibly 0-d arrays).
Notes
-----
While the function may mostly match the errors of normal indexing this
is generally not the case.
"""
in_indices = list(indices)
indices = []
# if False, this is a fancy or boolean index
no_copy = True
# number of fancy/scalar indexes that are not consecutive
num_fancy = 0
# number of dimensions indexed by a "fancy" index
fancy_dim = 0
# NOTE: This is a funny twist (and probably OK to change).
# The boolean array has illegal indexes, but this is
# allowed if the broadcast fancy-indices are 0-sized.
# This variable is to catch that case.
error_unless_broadcast_to_empty = False
# We need to handle Ellipsis and make arrays from indices, also
# check if this is fancy indexing (set no_copy).
ndim = 0
ellipsis_pos = None # define here mostly to replace all but first.
for i, indx in enumerate(in_indices):
if indx is None:
continue
if isinstance(indx, np.ndarray) and indx.dtype == bool:
no_copy = False
if indx.ndim == 0:
raise IndexError
# boolean indices can have higher dimensions
ndim += indx.ndim
fancy_dim += indx.ndim
continue
if indx is Ellipsis:
if ellipsis_pos is None:
ellipsis_pos = i
continue # do not increment ndim counter
raise IndexError
if isinstance(indx, slice):
ndim += 1
continue
if not isinstance(indx, np.ndarray):
# This could be open for changes in numpy.
# numpy should maybe raise an error if casting to intp
# is not safe. It rejects np.array([1., 2.]) but not
# [1., 2.] as index (same for ie. np.take).
# (Note the importance of empty lists if changing this here)
indx = np.array(indx, dtype=np.intp)
in_indices[i] = indx
elif indx.dtype.kind != 'b' and indx.dtype.kind != 'i':
raise IndexError('arrays used as indices must be of integer (or boolean) type')
if indx.ndim != 0:
no_copy = False
ndim += 1
fancy_dim += 1
if arr.ndim - ndim < 0:
# we can't take more dimensions then we have, not even for 0-d arrays.
# since a[()] makes sense, but not a[(),]. We will raise an error
# later on, unless a broadcasting error occurs first.
raise IndexError
if ndim == 0 and None not in in_indices:
# Well we have no indexes or one Ellipsis. This is legal.
return arr.copy(), no_copy
if ellipsis_pos is not None:
in_indices[ellipsis_pos:ellipsis_pos+1] = [slice(None, None)] * (arr.ndim - ndim)
for ax, indx in enumerate(in_indices):
if isinstance(indx, slice):
# convert to an index array
indx = np.arange(*indx.indices(arr.shape[ax]))
indices.append(['s', indx])
continue
elif indx is None:
# this is like taking a slice with one element from a new axis:
indices.append(['n', np.array([0], dtype=np.intp)])
arr = arr.reshape((arr.shape[:ax] + (1,) + arr.shape[ax:]))
continue
if isinstance(indx, np.ndarray) and indx.dtype == bool:
if indx.shape != arr.shape[ax:ax+indx.ndim]:
raise IndexError
try:
flat_indx = np.ravel_multi_index(np.nonzero(indx),
arr.shape[ax:ax+indx.ndim], mode='raise')
except:
error_unless_broadcast_to_empty = True
# fill with 0s instead, and raise error later
flat_indx = np.array([0]*indx.sum(), dtype=np.intp)
# concatenate axis into a single one:
if indx.ndim != 0:
arr = arr.reshape((arr.shape[:ax]
+ (np.prod(arr.shape[ax:ax+indx.ndim]),)
+ arr.shape[ax+indx.ndim:]))
indx = flat_indx
else:
# This could be changed, a 0-d boolean index can
# make sense (even outside the 0-d indexed array case)
# Note that originally this is could be interpreted as
# integer in the full integer special case.
raise IndexError
else:
# If the index is a singleton, the bounds check is done
# before the broadcasting. This used to be different in <1.9
if indx.ndim == 0:
if indx >= arr.shape[ax] or indx < -arr.shape[ax]:
raise IndexError
if indx.ndim == 0:
# The index is a scalar. This used to be two fold, but if fancy
# indexing was active, the check was done later, possibly
# after broadcasting it away (1.7. or earlier). Now it is always
# done.
if indx >= arr.shape[ax] or indx < - arr.shape[ax]:
raise IndexError
if len(indices) > 0 and indices[-1][0] == 'f' and ax != ellipsis_pos:
# NOTE: There could still have been a 0-sized Ellipsis
# between them. Checked that with ellipsis_pos.
indices[-1].append(indx)
else:
# We have a fancy index that is not after an existing one.
# NOTE: A 0-d array triggers this as well, while
# one may expect it to not trigger it, since a scalar
# would not be considered fancy indexing.
num_fancy += 1
indices.append(['f', indx])
if num_fancy > 1 and not no_copy:
# We have to flush the fancy indexes left
new_indices = indices[:]
axes = list(range(arr.ndim))
fancy_axes = []
new_indices.insert(0, ['f'])
ni = 0
ai = 0
for indx in indices:
ni += 1
if indx[0] == 'f':
new_indices[0].extend(indx[1:])
del new_indices[ni]
ni -= 1
for ax in range(ai, ai + len(indx[1:])):
fancy_axes.append(ax)
axes.remove(ax)
ai += len(indx) - 1 # axis we are at
indices = new_indices
# and now we need to transpose arr:
arr = arr.transpose(*(fancy_axes + axes))
# We only have one 'f' index now and arr is transposed accordingly.
# Now handle newaxis by reshaping...
ax = 0
for indx in indices:
if indx[0] == 'f':
if len(indx) == 1:
continue
# First of all, reshape arr to combine fancy axes into one:
orig_shape = arr.shape
orig_slice = orig_shape[ax:ax + len(indx[1:])]
arr = arr.reshape((arr.shape[:ax]
+ (np.prod(orig_slice).astype(int),)
+ arr.shape[ax + len(indx[1:]):]))
# Check if broadcasting works
if len(indx[1:]) != 1:
res = np.broadcast(*indx[1:]) # raises ValueError...
else:
res = indx[1]
# unfortunately the indices might be out of bounds. So check
# that first, and use mode='wrap' then. However only if
# there are any indices...
if res.size != 0:
if error_unless_broadcast_to_empty:
raise IndexError
for _indx, _size in zip(indx[1:], orig_slice):
if _indx.size == 0:
continue
if np.any(_indx >= _size) or np.any(_indx < -_size):
raise IndexError
if len(indx[1:]) == len(orig_slice):
if np.product(orig_slice) == 0:
# Work around for a crash or IndexError with 'wrap'
# in some 0-sized cases.
try:
mi = np.ravel_multi_index(indx[1:], orig_slice, mode='raise')
except:
# This happens with 0-sized orig_slice (sometimes?)
# here it is a ValueError, but indexing gives a:
raise IndexError('invalid index into 0-sized')
else:
mi = np.ravel_multi_index(indx[1:], orig_slice, mode='wrap')
else:
# Maybe never happens...
raise ValueError
arr = arr.take(mi.ravel(), axis=ax)
arr = arr.reshape((arr.shape[:ax]
+ mi.shape
+ arr.shape[ax+1:]))
ax += mi.ndim
continue
# If we are here, we have a 1D array for take:
arr = arr.take(indx[1], axis=ax)
ax += 1
return arr, no_copy
def _check_multi_index(self, arr, index):
"""Check a multi index item getting and simple setting.
Parameters
----------
arr : ndarray
Array to be indexed, must be a reshaped arange.
index : tuple of indexing objects
Index being tested.
"""
# Test item getting
try:
mimic_get, no_copy = self._get_multi_index(arr, index)
except Exception:
prev_refcount = sys.getrefcount(arr)
assert_raises(Exception, arr.__getitem__, index)
assert_raises(Exception, arr.__setitem__, index, 0)
assert_equal(prev_refcount, sys.getrefcount(arr))
return
self._compare_index_result(arr, index, mimic_get, no_copy)
def _check_single_index(self, arr, index):
"""Check a single index item getting and simple setting.
Parameters
----------
arr : ndarray
Array to be indexed, must be an arange.
index : indexing object
Index being tested. Must be a single index and not a tuple
of indexing objects (see also `_check_multi_index`).
"""
try:
mimic_get, no_copy = self._get_multi_index(arr, (index,))
except Exception:
prev_refcount = sys.getrefcount(arr)
assert_raises(Exception, arr.__getitem__, index)
assert_raises(Exception, arr.__setitem__, index, 0)
assert_equal(prev_refcount, sys.getrefcount(arr))
return
self._compare_index_result(arr, index, mimic_get, no_copy)
def _compare_index_result(self, arr, index, mimic_get, no_copy):
"""Compare mimicked result to indexing result.
"""
arr = arr.copy()
indexed_arr = arr[index]
assert_array_equal(indexed_arr, mimic_get)
# Check if we got a view, unless its a 0-sized or 0-d array.
# (then its not a view, and that does not matter)
if indexed_arr.size != 0 and indexed_arr.ndim != 0:
assert_(np.may_share_memory(indexed_arr, arr) == no_copy)
# Check reference count of the original array
if no_copy:
# refcount increases by one:
assert_equal(sys.getrefcount(arr), 3)
else:
assert_equal(sys.getrefcount(arr), 2)
# Test non-broadcast setitem:
b = arr.copy()
b[index] = mimic_get + 1000
if b.size == 0:
return # nothing to compare here...
if no_copy and indexed_arr.ndim != 0:
# change indexed_arr in-place to manipulate original:
indexed_arr += 1000
assert_array_equal(arr, b)
return
# Use the fact that the array is originally an arange:
arr.flat[indexed_arr.ravel()] += 1000
assert_array_equal(arr, b)
def test_boolean(self):
a = np.array(5)
assert_equal(a[np.array(True)], 5)
a[np.array(True)] = 1
assert_equal(a, 1)
# NOTE: This is different from normal broadcasting, as
# arr[boolean_array] works like in a multi index. Which means
# it is aligned to the left. This is probably correct for
# consistency with arr[boolean_array,] also no broadcasting
# is done at all
self._check_multi_index(self.a, (np.zeros_like(self.a, dtype=bool),))
self._check_multi_index(self.a, (np.zeros_like(self.a, dtype=bool)[..., 0],))
self._check_multi_index(self.a, (np.zeros_like(self.a, dtype=bool)[None, ...],))
def test_multidim(self):
# Automatically test combinations with complex indexes on 2nd (or 1st)
# spot and the simple ones in one other spot.
with warnings.catch_warnings():
# This is so that np.array(True) is not accepted in a full integer
# index, when running the file separately.
warnings.filterwarnings('error', '', DeprecationWarning)
warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
def isskip(idx):
return isinstance(idx, str) and idx == "skip"
for simple_pos in [0, 2, 3]:
tocheck = [self.fill_indices, self.complex_indices,
self.fill_indices, self.fill_indices]
tocheck[simple_pos] = self.simple_indices
for index in product(*tocheck):
index = tuple(i for i in index if not isskip(i))
self._check_multi_index(self.a, index)
self._check_multi_index(self.b, index)
# Check very simple item getting:
self._check_multi_index(self.a, (0, 0, 0, 0))
self._check_multi_index(self.b, (0, 0, 0, 0))
# Also check (simple cases of) too many indices:
assert_raises(IndexError, self.a.__getitem__, (0, 0, 0, 0, 0))
assert_raises(IndexError, self.a.__setitem__, (0, 0, 0, 0, 0), 0)
assert_raises(IndexError, self.a.__getitem__, (0, 0, [1], 0, 0))
assert_raises(IndexError, self.a.__setitem__, (0, 0, [1], 0, 0), 0)
def test_1d(self):
a = np.arange(10)
with warnings.catch_warnings():
warnings.filterwarnings('error', '', np.VisibleDeprecationWarning)
for index in self.complex_indices:
self._check_single_index(a, index)
class TestCApiAccess(TestCase):
def test_getitem(self):
subscript = functools.partial(array_indexing, 0)
# 0-d arrays don't work:
assert_raises(IndexError, subscript, np.ones(()), 0)
# Out of bound values:
assert_raises(IndexError, subscript, np.ones(10), 11)
assert_raises(IndexError, subscript, np.ones(10), -11)
assert_raises(IndexError, subscript, np.ones((10, 10)), 11)
assert_raises(IndexError, subscript, np.ones((10, 10)), -11)
a = np.arange(10)
assert_array_equal(a[4], subscript(a, 4))
a = a.reshape(5, 2)
assert_array_equal(a[-4], subscript(a, -4))
def test_setitem(self):
assign = functools.partial(array_indexing, 1)
# Deletion is impossible:
assert_raises(ValueError, assign, np.ones(10), 0)
# 0-d arrays don't work:
assert_raises(IndexError, assign, np.ones(()), 0, 0)
# Out of bound values:
assert_raises(IndexError, assign, np.ones(10), 11, 0)
assert_raises(IndexError, assign, np.ones(10), -11, 0)
assert_raises(IndexError, assign, np.ones((10, 10)), 11, 0)
assert_raises(IndexError, assign, np.ones((10, 10)), -11, 0)
a = np.arange(10)
assign(a, 4, 10)
assert_(a[4] == 10)
a = a.reshape(5, 2)
assign(a, 4, 10)
assert_array_equal(a[-1], [10, 10])
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
984,
199,
646,
3598,
199,
646,
9143,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
1018,
14,
23698,
63,
2219,
492,
1625,
63,
28703,
199,
504,
7975,
492,
3336,
199,
504,
2680,
14,
4776,
492,
334,
272,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
702,
63,
3536,
12,
272,
702,
63,
1144,
63,
1452,
12,
702,
63,
19811,
199,
9,
421,
199,
893,
26,
272,
286,
9259,
275,
980,
14,
9798,
773,
14,
912,
63,
4342,
360,
23698,
297,
980,
14,
1018,
14,
23698,
855,
493,
3368,
272,
485,
13533,
63,
7540,
275,
715,
199,
2590,
3545,
26,
272,
485,
13533,
63,
7540,
275,
756,
421,
199,
533,
1379,
2681,
316,
8,
1746,
304,
272,
347,
511,
63,
3592,
63,
1080,
8,
277,
304,
267,
327,
658,
403,
64,
1478,
9584,
892,
3127,
267,
282,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
65,
59,
403,
467,
282,
59,
1590,
14,
14483,
566,
267,
702,
63,
1452,
8,
65,
59,
403,
1055,
8322,
12,
282,
14,
8322,
435,
413,
9,
339,
347,
511,
63,
1667,
63,
2960,
63,
1080,
8,
277,
304,
267,
327,
9630,
2008,
1478,
8491,
282,
2455,
267,
282,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
65,
59,
15618,
282,
9,
267,
702,
2531,
65,
59,
342,
1055,
1095,
365,
282,
9,
267,
282,
275,
980,
14,
1144,
8,
16,
9,
267,
702,
2531,
6074,
8,
65,
59,
15618,
980,
14,
442,
13309,
398,
327,
13262,
12,
652,
4839,
370,
11264,
4012,
3000,
436,
27571,
16356,
267,
327,
5560,
12,
880,
1929,
314,
543,
5164,
370,
3686,
314,
2222,
13,
4115,
1125,
14,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
23945,
360,
4247,
297,
3260,
13413,
9,
288,
282,
275,
980,
14,
1144,
779,
17,
14444,
288,
702,
2531,
6074,
8,
65,
59,
16,
8333,
980,
14,
1609,
13309,
953,
282,
275,
980,
14,
1144,
779,
1590,
14,
1144,
8,
17,
4360,
2152,
29,
785,
9,
288,
702,
2531,
6074,
8,
65,
59,
16,
8333,
980,
14,
8237,
430,
339,
347,
511,
63,
7191,
63,
5091,
63,
1080,
63,
2931,
316,
8,
277,
304,
267,
327,
5499,
397,
1077,
506,
9106,
543,
2011,
13,
5091,
436,
440,
5048,
12,
2755,
340,
267,
327,
626,
365,
30362,
19293,
14,
2002,
511,
7750,
3365,
1233,
3792,
14,
267,
1478,
275,
980,
14,
5605,
8,
21,
9,
267,
399,
63,
1080,
275,
1478,
14,
6041,
8,
1590,
14,
1635,
80,
9,
267,
7953,
275,
980,
14,
5605,
8,
709,
9,
398,
702,
63,
1144,
63,
1452,
8,
5250,
59,
1080,
467,
7953,
59,
85,
63,
1080,
566,
267,
7953,
59,
85,
63,
1080,
61,
275,
980,
14,
5605,
8,
21,
9,
267,
702,
63,
1144,
63,
1452,
8,
5250,
12,
980,
14,
5605,
8,
709,
430,
398,
7953,
275,
980,
14,
5605,
8,
709,
680,
5217,
8,
21,
12,
499,
9,
267,
702,
63,
1144,
63,
1452,
8,
5250,
59,
1080,
467,
7953,
59,
85,
63,
1080,
566,
398,
7953,
59,
85,
63,
1080,
61,
275,
980,
14,
5605,
8,
21,
24517,
403,
61,
267,
702,
63,
1144,
63,
1452,
8,
5250,
12,
980,
14,
5605,
8,
21,
24517,
403,
1055,
8755,
8,
18,
12,
3114,
29,
17,
430,
398,
7953,
275,
980,
14,
5605,
8,
821,
680,
5217,
8,
21,
12,
959,
9,
267,
702,
63,
1144,
63,
1452,
8,
5250,
59,
85,
63,
1080,
12,
399,
63,
1080,
467,
7953,
59,
1080,
12,
1478,
566,
339,
347,
511,
63,
1667,
63,
25352,
63,
1080,
8,
277,
304,
267,
327,
9630,
769,
1478,
8491,
376,
2701,
1625,
267,
327,
543,
314,
2011,
2152,
334,
7911,
543,
22965,
2215,
9,
267,
282,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
65,
9046,
2365,
3073,
267,
702,
63,
1452,
8,
65,
59,
8607,
1055,
2271,
12,
282,
14,
2271,
9,
398,
330,
275,
980,
14,
1144,
8798,
2152,
29,
1590,
14,
25319,
9,
267,
702,
63,
1452,
8,
65,
9046,
2365,
3073,
267,
702,
63,
1452,
8,
65,
59,
8607,
1055,
2271,
12,
282,
14,
2271,
9,
398,
330,
275,
980,
14,
1144,
4157,
267,
702,
63,
3536,
8,
12129,
12,
282,
855,
6095,
3108,
330,
9,
339,
347,
511,
63,
16514,
2316,
63,
1080,
8,
277,
304,
267,
327,
27761,
2316,
1478,
1630,
440,
1218,
282,
2455,
267,
282,
275,
980,
14,
1144,
4038,
17,
12,
499,
12,
650,
467,
1993,
359,
20,
12,
959,
12,
1227,
467,
1993,
359,
23,
12,
1695,
12,
1749,
3934,
267,
702,
63,
1452,
8,
65,
59,
1396,
467,
282,
9,
267,
702,
2531,
65,
59,
1396,
1055,
1095,
365,
282,
9,
221,
327,
658,
65,
59,
1396,
16090,
1990,
658,
65,
64,
315,
2680,
665,
17,
14,
25,
4959,
398,
327,
428,
17463,
543,
32696,
883,
3372,
376,
267,
327,
9697,
1329,
402,
7365,
267,
702,
63,
1452,
8,
65,
59,
16,
12,
2263,
467,
282,
59,
16,
566,
267,
702,
63,
1452,
8,
65,
59,
16,
12,
2263,
467,
282,
59,
16,
12,
5728,
267,
702,
63,
1452,
8,
65,
18999,
378,
467,
282,
3981,
378,
566,
398,
327,
428,
17463,
543,
32696,
3544,
2058,
267,
327,
315,
376,
1625,
12,
440,
282,
6917,
267,
702,
63,
1452,
8,
65,
59,
16,
12,
14263,
413,
467,
980,
14,
1144,
8,
18,
430,
398,
327,
16927,
434,
543,
16918,
23525,
2316,
4258,
64,
641,
378,
13,
68,
6572,
267,
330,
275,
980,
14,
1144,
8,
17,
9,
267,
330,
7528,
23525,
2316,
12,
1874,
275,
499,
267,
702,
63,
1452,
8,
66,
12,
499,
9,
339,
347,
511,
63,
4780,
63,
442,
63,
1080,
8,
277,
304,
267,
327,
13050,
3000,
1478,
24750,
1373,
1962,
267,
282,
275,
980,
14,
1144,
4038,
17,
12,
499,
12,
650,
467,
1993,
359,
20,
12,
959,
12,
1227,
467,
1993,
359,
23,
12,
1695,
12,
1749,
3934,
398,
702,
63,
1452,
8,
65,
59,
16
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
984,
199,
646,
3598,
199,
646,
9143,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
1018,
14,
23698,
63,
2219,
492,
1625,
63,
28703,
199,
504,
7975,
492,
3336,
199,
504,
2680,
14,
4776,
492,
334,
272,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
702,
63,
3536,
12,
272,
702,
63,
1144,
63,
1452,
12,
702,
63,
19811,
199,
9,
421,
199,
893,
26,
272,
286,
9259,
275,
980,
14,
9798,
773,
14,
912,
63,
4342,
360,
23698,
297,
980,
14,
1018,
14,
23698,
855,
493,
3368,
272,
485,
13533,
63,
7540,
275,
715,
199,
2590,
3545,
26,
272,
485,
13533,
63,
7540,
275,
756,
421,
199,
533,
1379,
2681,
316,
8,
1746,
304,
272,
347,
511,
63,
3592,
63,
1080,
8,
277,
304,
267,
327,
658,
403,
64,
1478,
9584,
892,
3127,
267,
282,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
65,
59,
403,
467,
282,
59,
1590,
14,
14483,
566,
267,
702,
63,
1452,
8,
65,
59,
403,
1055,
8322,
12,
282,
14,
8322,
435,
413,
9,
339,
347,
511,
63,
1667,
63,
2960,
63,
1080,
8,
277,
304,
267,
327,
9630,
2008,
1478,
8491,
282,
2455,
267,
282,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
65,
59,
15618,
282,
9,
267,
702,
2531,
65,
59,
342,
1055,
1095,
365,
282,
9,
267,
282,
275,
980,
14,
1144,
8,
16,
9,
267,
702,
2531,
6074,
8,
65,
59,
15618,
980,
14,
442,
13309,
398,
327,
13262,
12,
652,
4839,
370,
11264,
4012,
3000,
436,
27571,
16356,
267,
327,
5560,
12,
880,
1929,
314,
543,
5164,
370,
3686,
314,
2222,
13,
4115,
1125,
14,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
23945,
360,
4247,
297,
3260,
13413,
9,
288,
282,
275,
980,
14,
1144,
779,
17,
14444,
288,
702,
2531,
6074,
8,
65,
59,
16,
8333,
980,
14,
1609,
13309,
953,
282,
275,
980,
14,
1144,
779,
1590,
14,
1144,
8,
17,
4360,
2152,
29,
785,
9,
288,
702,
2531,
6074,
8,
65,
59,
16,
8333,
980,
14,
8237,
430,
339,
347,
511,
63,
7191,
63,
5091,
63,
1080,
63,
2931,
316,
8,
277,
304,
267,
327,
5499,
397,
1077,
506,
9106,
543,
2011,
13,
5091,
436,
440,
5048,
12,
2755,
340,
267,
327,
626,
365,
30362,
19293,
14,
2002,
511,
7750,
3365,
1233,
3792,
14,
267,
1478,
275,
980,
14,
5605,
8,
21,
9,
267,
399,
63,
1080,
275,
1478,
14,
6041,
8,
1590,
14,
1635,
80,
9,
267,
7953,
275,
980,
14,
5605,
8,
709,
9,
398,
702,
63,
1144,
63,
1452,
8,
5250,
59,
1080,
467,
7953,
59,
85,
63,
1080,
566,
267,
7953,
59,
85,
63,
1080,
61,
275,
980,
14,
5605,
8,
21,
9,
267,
702,
63,
1144,
63,
1452,
8,
5250,
12,
980,
14,
5605,
8,
709,
430,
398,
7953,
275,
980,
14,
5605,
8,
709,
680,
5217,
8,
21,
12,
499,
9,
267,
702,
63,
1144,
63,
1452,
8,
5250,
59,
1080,
467,
7953,
59,
85,
63,
1080,
566,
398,
7953,
59,
85,
63,
1080,
61,
275,
980,
14,
5605,
8,
21,
24517,
403,
61,
267,
702,
63,
1144,
63,
1452,
8,
5250,
12,
980,
14,
5605,
8,
21,
24517,
403,
1055,
8755,
8,
18,
12,
3114,
29,
17,
430,
398,
7953,
275,
980,
14,
5605,
8,
821,
680,
5217,
8,
21,
12,
959,
9,
267,
702,
63,
1144,
63,
1452,
8,
5250,
59,
85,
63,
1080,
12,
399,
63,
1080,
467,
7953,
59,
1080,
12,
1478,
566,
339,
347,
511,
63,
1667,
63,
25352,
63,
1080,
8,
277,
304,
267,
327,
9630,
769,
1478,
8491,
376,
2701,
1625,
267,
327,
543,
314,
2011,
2152,
334,
7911,
543,
22965,
2215,
9,
267,
282,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
65,
9046,
2365,
3073,
267,
702,
63,
1452,
8,
65,
59,
8607,
1055,
2271,
12,
282,
14,
2271,
9,
398,
330,
275,
980,
14,
1144,
8798,
2152,
29,
1590,
14,
25319,
9,
267,
702,
63,
1452,
8,
65,
9046,
2365,
3073,
267,
702,
63,
1452,
8,
65,
59,
8607,
1055,
2271,
12,
282,
14,
2271,
9,
398,
330,
275,
980,
14,
1144,
4157,
267,
702,
63,
3536,
8,
12129,
12,
282,
855,
6095,
3108,
330,
9,
339,
347,
511,
63,
16514,
2316,
63,
1080,
8,
277,
304,
267,
327,
27761,
2316,
1478,
1630,
440,
1218,
282,
2455,
267,
282,
275,
980,
14,
1144,
4038,
17,
12,
499,
12,
650,
467,
1993,
359,
20,
12,
959,
12,
1227,
467,
1993,
359,
23,
12,
1695,
12,
1749,
3934,
267,
702,
63,
1452,
8,
65,
59,
1396,
467,
282,
9,
267,
702,
2531,
65,
59,
1396,
1055,
1095,
365,
282,
9,
221,
327,
658,
65,
59,
1396,
16090,
1990,
658,
65,
64,
315,
2680,
665,
17,
14,
25,
4959,
398,
327,
428,
17463,
543,
32696,
883,
3372,
376,
267,
327,
9697,
1329,
402,
7365,
267,
702,
63,
1452,
8,
65,
59,
16,
12,
2263,
467,
282,
59,
16,
566,
267,
702,
63,
1452,
8,
65,
59,
16,
12,
2263,
467,
282,
59,
16,
12,
5728,
267,
702,
63,
1452,
8,
65,
18999,
378,
467,
282,
3981,
378,
566,
398,
327,
428,
17463,
543,
32696,
3544,
2058,
267,
327,
315,
376,
1625,
12,
440,
282,
6917,
267,
702,
63,
1452,
8,
65,
59,
16,
12,
14263,
413,
467,
980,
14,
1144,
8,
18,
430,
398,
327,
16927,
434,
543,
16918,
23525,
2316,
4258,
64,
641,
378,
13,
68,
6572,
267,
330,
275,
980,
14,
1144,
8,
17,
9,
267,
330,
7528,
23525,
2316,
12,
1874,
275,
499,
267,
702,
63,
1452,
8,
66,
12,
499,
9,
339,
347,
511,
63,
4780,
63,
442,
63,
1080,
8,
277,
304,
267,
327,
13050,
3000,
1478,
24750,
1373,
1962,
267,
282,
275,
980,
14,
1144,
4038,
17,
12,
499,
12,
650,
467,
1993,
359,
20,
12,
959,
12,
1227,
467,
1993,
359,
23,
12,
1695,
12,
1749,
3934,
398,
702,
63,
1452,
8,
65,
59,
16,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
knowledgegraph/schema
|
scripts/fb15k_schema/fb15k_schema.py
|
1
|
1681
|
#!/usr/bin/python -uB
# -*- coding: utf-8 -*-
# Classes of methods
base_vers = ['TransE', 'ScalE']
scaltrans_vers = ['ScalTransE']
xi_vers = ['XiTransE', 'XiScalE']
semixi_vers = ['XiScalTransSE', 'XiTransScalSE']
xiscaltrans_vers = ['XiScalTransE']
simple_method_set = base_vers + xi_vers #+ scaltrans_vers + semixi_vers + xiscaltrans_vers
sim_set = ['L1', 'L2', 'dot']
margin_set = [1] #, 2, 5, 10]
ndim_set = [20, 50, 100, 200]
nhid_set = [20, 50, 100, 200]
epochs = 100
nbatches = 10
lr = 0.1
seed = 123
train_path = 'data/fb15k_schema/FB15k-train.pkl'
valid_path = 'data/fb15k_schema/FB15k-valid.pkl'
test_path = 'data/fb15k_schema/FB15k-test.pkl'
# ADAGRAD
# def adagrad(param, rate, epsilon, gradient, updates, param_squared_gradients):
c, method = 0, 'ADAGRAD'
# def adagrad(param, rate, epsilon, gradient, updates, param_squared_gradients):
cmd_adagrad = ('./learn_parameters.py --seed=%d --strategy=%s --totepochs=%d --test_all=%d --lr=%f --name=fb15k_schema/fb15k_%s_%d '
' --train=%s --valid=%s --test=%s --nbatches=%d --no_rescaling --filtered '
' --domain_range=data/fb15k_schema/fb15k_domains_ranges.pkl '
' --op=%s --sim=%s --ndim=%d --nhid=%d --margin=%d' # varying params
' > logs/fb15k_schema/fb15k_schema.%s_%s_%d_%d_%d_%d.log 2>&1')
for op in simple_method_set:
for sim in sim_set:
for ndim in ndim_set:
nhid = ndim
for margin in margin_set:
print(cmd_adagrad % (seed, method, epochs, epochs, lr, op, c, train_path, valid_path, test_path, nbatches, op, sim, ndim, nhid, margin, op, sim, ndim, nhid, margin, c))
c += 1
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
85,
34,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
27939,
402,
3102,
199,
1095,
63,
14895,
275,
788,
3188,
37,
297,
283,
10249,
37,
418,
199,
4732,
1515,
63,
14895,
275,
788,
10249,
3188,
37,
418,
199,
6865,
63,
14895,
275,
788,
14828,
3188,
37,
297,
283,
14828,
10249,
37,
418,
199,
261,
13979,
73,
63,
14895,
275,
788,
14828,
10249,
3188,
899,
297,
283,
14828,
3188,
10249,
899,
418,
199,
7291,
915,
1515,
63,
14895,
275,
788,
14828,
10249,
3188,
37,
418,
199,
199,
4129,
63,
765,
63,
409,
275,
1300,
63,
14895,
435,
19905,
63,
14895,
327,
11,
5269,
1515,
63,
14895,
435,
542,
13979,
73,
63,
14895,
435,
671,
15734,
1515,
63,
14895,
199,
199,
5206,
63,
409,
275,
788,
44,
17,
297,
283,
44,
18,
297,
283,
3287,
418,
199,
199,
9650,
63,
409,
275,
359,
17,
61,
327,
12,
499,
12,
959,
12,
1616,
61,
199,
8322,
63,
409,
275,
359,
1165,
12,
5238,
12,
2948,
12,
1926,
61,
199,
78,
18209,
63,
409,
275,
359,
1165,
12,
5238,
12,
2948,
12,
1926,
61,
199,
199,
13161,
275,
2948,
199,
78,
14896,
275,
1616,
199,
7493,
275,
378,
14,
17,
199,
5176,
275,
11869,
199,
199,
2834,
63,
515,
275,
283,
576,
15,
4675,
1046,
75,
63,
3629,
15,
8223,
1046,
75,
13,
2834,
14,
23947,
7,
199,
1078,
63,
515,
275,
283,
576,
15,
4675,
1046,
75,
63,
3629,
15,
8223,
1046,
75,
13,
1078,
14,
23947,
7,
199,
396,
63,
515,
275,
283,
576,
15,
4675,
1046,
75,
63,
3629,
15,
8223,
1046,
75,
13,
396,
14,
23947,
7,
199,
199,
3,
16271,
1254,
19662,
199,
3,
347,
1503,
27707,
8,
635,
12,
6634,
12,
14030,
12,
6709,
12,
7029,
12,
1215,
63,
12973,
63,
13065,
304,
199,
67,
12,
1083,
275,
378,
12,
283,
1554,
1254,
19662,
7,
199,
199,
3,
347,
1503,
27707,
8,
635,
12,
6634,
12,
14030,
12,
6709,
12,
7029,
12,
1215,
63,
12973,
63,
13065,
304,
199,
1760,
63,
350,
27707,
275,
661,
13186,
4643,
63,
3214,
14,
647,
1553,
5176,
2458,
68,
1553,
8590,
2458,
83,
1553,
475,
266,
5132,
83,
2458,
68,
1553,
396,
63,
452,
2458,
68,
1553,
7493,
2458,
70,
1553,
354,
29,
4675,
1046,
75,
63,
3629,
15,
4675,
1046,
75,
4970,
83,
4970,
68,
283,
355,
283,
1553,
2834,
2458,
83,
1553,
1078,
2458,
83,
1553,
396,
2458,
83,
1553,
78,
14896,
2458,
68,
1553,
889,
63,
470,
915,
316,
1553,
11142,
283,
355,
283,
1553,
2261,
63,
1842,
29,
576,
15,
4675,
1046,
75,
63,
3629,
15,
4675,
1046,
75,
63,
9756,
63,
8404,
14,
23947,
283,
355,
283,
1553,
411,
2458,
83,
1553,
5206,
2458,
83,
1553,
8322,
2458,
68,
1553,
78,
18209,
2458,
68,
1553,
9650,
2458,
68,
7,
327,
17083,
316,
1862,
355,
283,
690,
9610,
15,
4675,
1046,
75,
63,
3629,
15,
4675,
1046,
75,
63,
3629,
4111,
83,
4970,
83,
4970,
68,
4970,
68,
4970,
68,
4970,
68,
14,
793,
499,
18181,
17,
358,
421,
199,
509,
1687,
315,
3486,
63,
765,
63,
409,
26,
272,
367,
4389,
315,
4389,
63,
409,
26,
267,
367,
17951,
315,
17951,
63,
409,
26,
288,
302,
18209,
275,
17951,
288,
367,
11042,
315,
11042,
63,
409,
26,
355,
870,
8,
1760,
63,
350,
27707,
450,
334,
5176,
12,
1083,
12,
18463,
12,
18463,
12,
13645,
12,
1687,
12,
286,
12,
3560,
63,
515,
12,
1686,
63,
515,
12,
511,
63,
515,
12,
302,
14896,
12,
1687,
12,
4389,
12,
17951,
12,
302,
18209,
12,
11042,
12,
1687,
12,
4389,
12,
17951,
12,
302,
18209,
12,
11042,
12,
286,
430,
355,
286,
847,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
446,
85,
34,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
27939,
402,
3102,
199,
1095,
63,
14895,
275,
788,
3188,
37,
297,
283,
10249,
37,
418,
199,
4732,
1515,
63,
14895,
275,
788,
10249,
3188,
37,
418,
199,
6865,
63,
14895,
275,
788,
14828,
3188,
37,
297,
283,
14828,
10249,
37,
418,
199,
261,
13979,
73,
63,
14895,
275,
788,
14828,
10249,
3188,
899,
297,
283,
14828,
3188,
10249,
899,
418,
199,
7291,
915,
1515,
63,
14895,
275,
788,
14828,
10249,
3188,
37,
418,
199,
199,
4129,
63,
765,
63,
409,
275,
1300,
63,
14895,
435,
19905,
63,
14895,
327,
11,
5269,
1515,
63,
14895,
435,
542,
13979,
73,
63,
14895,
435,
671,
15734,
1515,
63,
14895,
199,
199,
5206,
63,
409,
275,
788,
44,
17,
297,
283,
44,
18,
297,
283,
3287,
418,
199,
199,
9650,
63,
409,
275,
359,
17,
61,
327,
12,
499,
12,
959,
12,
1616,
61,
199,
8322,
63,
409,
275,
359,
1165,
12,
5238,
12,
2948,
12,
1926,
61,
199,
78,
18209,
63,
409,
275,
359,
1165,
12,
5238,
12,
2948,
12,
1926,
61,
199,
199,
13161,
275,
2948,
199,
78,
14896,
275,
1616,
199,
7493,
275,
378,
14,
17,
199,
5176,
275,
11869,
199,
199,
2834,
63,
515,
275,
283,
576,
15,
4675,
1046,
75,
63,
3629,
15,
8223,
1046,
75,
13,
2834,
14,
23947,
7,
199,
1078,
63,
515,
275,
283,
576,
15,
4675,
1046,
75,
63,
3629,
15,
8223,
1046,
75,
13,
1078,
14,
23947,
7,
199,
396,
63,
515,
275,
283,
576,
15,
4675,
1046,
75,
63,
3629,
15,
8223,
1046,
75,
13,
396,
14,
23947,
7,
199,
199,
3,
16271,
1254,
19662,
199,
3,
347,
1503,
27707,
8,
635,
12,
6634,
12,
14030,
12,
6709,
12,
7029,
12,
1215,
63,
12973,
63,
13065,
304,
199,
67,
12,
1083,
275,
378,
12,
283,
1554,
1254,
19662,
7,
199,
199,
3,
347,
1503,
27707,
8,
635,
12,
6634,
12,
14030,
12,
6709,
12,
7029,
12,
1215,
63,
12973,
63,
13065,
304,
199,
1760,
63,
350,
27707,
275,
661,
13186,
4643,
63,
3214,
14,
647,
1553,
5176,
2458,
68,
1553,
8590,
2458,
83,
1553,
475,
266,
5132,
83,
2458,
68,
1553,
396,
63,
452,
2458,
68,
1553,
7493,
2458,
70,
1553,
354,
29,
4675,
1046,
75,
63,
3629,
15,
4675,
1046,
75,
4970,
83,
4970,
68,
283,
355,
283,
1553,
2834,
2458,
83,
1553,
1078,
2458,
83,
1553,
396,
2458,
83,
1553,
78,
14896,
2458,
68,
1553,
889,
63,
470,
915,
316,
1553,
11142,
283,
355,
283,
1553,
2261,
63,
1842,
29,
576,
15,
4675,
1046,
75,
63,
3629,
15,
4675,
1046,
75,
63,
9756,
63,
8404,
14,
23947,
283,
355,
283,
1553,
411,
2458,
83,
1553,
5206,
2458,
83,
1553,
8322,
2458,
68,
1553,
78,
18209,
2458,
68,
1553,
9650,
2458,
68,
7,
327,
17083,
316,
1862,
355,
283,
690,
9610,
15,
4675,
1046,
75,
63,
3629,
15,
4675,
1046,
75,
63,
3629,
4111,
83,
4970,
83,
4970,
68,
4970,
68,
4970,
68,
4970,
68,
14,
793,
499,
18181,
17,
358,
421,
199,
509,
1687,
315,
3486,
63,
765,
63,
409,
26,
272,
367,
4389,
315,
4389,
63,
409,
26,
267,
367,
17951,
315,
17951,
63,
409,
26,
288,
302,
18209,
275,
17951,
288,
367,
11042,
315,
11042,
63,
409,
26,
355,
870,
8,
1760,
63,
350,
27707,
450,
334,
5176,
12,
1083,
12,
18463,
12,
18463,
12,
13645,
12,
1687,
12,
286,
12,
3560,
63,
515,
12,
1686,
63,
515,
12,
511,
63,
515,
12,
302,
14896,
12,
1687,
12,
4389,
12,
17951,
12,
302,
18209,
12,
11042,
12,
1687,
12,
4389,
12,
17951,
12,
302,
18209,
12,
11042,
12,
286,
430,
355,
286,
847,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
infobloxopen/neutron
|
neutron/plugins/ml2/drivers/freescale/mechanism_fslsdn.py
|
40
|
9123
|
# Copyright (c) 2014 Freescale Semiconductor
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_log import helpers as log_helpers
from oslo_log import log as logging
from neutron.common import constants as n_const
from neutron.extensions import portbindings
from neutron.i18n import _LI
from neutron.plugins.common import constants
from neutron.plugins.ml2 import driver_api as api
from neutron.plugins.ml2.drivers.freescale import config # noqa
LOG = logging.getLogger(__name__)
class FslsdnMechanismDriver(api.MechanismDriver):
"""Freescale SDN OS Mechanism Driver for ML2 Plugin."""
@log_helpers.log_method_call
def initialize(self):
"""Initialize the Mechanism driver."""
self.vif_type = portbindings.VIF_TYPE_OVS
self.vif_details = {portbindings.CAP_PORT_FILTER: True}
LOG.info(_LI("Initializing CRD client... "))
self._crdclient = config.get_crdclient()
# Network Management
@staticmethod
@log_helpers.log_method_call
def _prepare_crd_network(network, segments):
"""Helper function to create 'network' data."""
return {'network':
{'network_id': network['id'],
'tenant_id': network['tenant_id'],
'name': network['name'],
'status': network['status'],
'admin_state_up': network['admin_state_up'],
'segments': segments,
}}
def create_network_postcommit(self, context):
"""Send create_network data to CRD service."""
network = context.current
segments = context.network_segments
body = self._prepare_crd_network(network, segments)
self._crdclient.create_network(body=body)
LOG.debug("create_network update sent to CRD Server: %s", body)
def update_network_postcommit(self, context):
"""Send update_network data to CRD service."""
network = context.current
segments = context.network_segments
body = self._prepare_crd_network(network, segments)
self._crdclient.update_network(network['id'], body=body)
LOG.debug("update_network update sent to CRD Server: %s", body)
def delete_network_postcommit(self, context):
"""Send delete_network data to CRD service."""
network = context.current
self._crdclient.delete_network(network['id'])
LOG.debug(
"delete_network update sent to CRD Server: %s",
network['id'])
# Port Management
@staticmethod
def _prepare_crd_port(port):
"""Helper function to prepare 'port' data."""
crd_subnet_id = ''
crd_ipaddress = ''
crd_sec_grps = ''
# Since CRD accepts one Fixed IP,
# so handle only one fixed IP per port.
if len(port['fixed_ips']) > 1:
LOG.debug("More than one fixed IP exists - using first one.")
# check empty fixed_ips list, move on if one or more exists
if len(port['fixed_ips']) != 0:
crd_subnet_id = port['fixed_ips'][0]['subnet_id']
crd_ipaddress = port['fixed_ips'][0]['ip_address']
LOG.debug("Handling fixed IP {subnet_id:%(subnet)s, "
"ip_address:%(ip)s}",
{'subnet': crd_subnet_id, 'ip': crd_ipaddress})
else:
LOG.debug("No fixed IPs found.")
if 'security_groups' in port:
crd_sec_grps = ','.join(port['security_groups'])
return {'port':
{'port_id': port['id'],
'tenant_id': port['tenant_id'],
'name': port['name'],
'network_id': port['network_id'],
'subnet_id': crd_subnet_id,
'mac_address': port['mac_address'],
'device_id': port['device_id'],
'ip_address': crd_ipaddress,
'admin_state_up': port['admin_state_up'],
'status': port['status'],
'device_owner': port['device_owner'],
'security_groups': crd_sec_grps,
}}
def create_port_postcommit(self, context):
"""Send create_port data to CRD service."""
port = context.current
body = self._prepare_crd_port(port)
self._crdclient.create_port(body=body)
LOG.debug("create_port update sent to CRD Server: %s", body)
def delete_port_postcommit(self, context):
"""Send delete_port data to CRD service."""
port = context.current
self._crdclient.delete_port(port['id'])
LOG.debug("delete_port update sent to CRD Server: %s", port['id'])
# Subnet Management
@staticmethod
@log_helpers.log_method_call
def _prepare_crd_subnet(subnet):
"""Helper function to prepare 'subnet' data."""
crd_allocation_pools = ''
crd_dns_nameservers = ''
crd_host_routes = ''
# Handling Allocation IPs
if 'allocation_pools' in subnet:
a_pools = subnet['allocation_pools']
crd_allocation_pools = ','.join(["%s-%s" % (p['start'],
p['end'])
for p in a_pools])
# Handling Host Routes
if 'host_routes' in subnet:
crd_host_routes = ','.join(["%s-%s" % (r['destination'],
r['nexthop'])
for r in subnet['host_routes']])
# Handling DNS Nameservers
if 'dns_nameservers' in subnet:
crd_dns_nameservers = ','.join(subnet['dns_nameservers'])
# return Subnet Data
return {'subnet':
{'subnet_id': subnet['id'],
'tenant_id': subnet['tenant_id'],
'name': subnet['name'],
'network_id': subnet['network_id'],
'ip_version': subnet['ip_version'],
'cidr': subnet['cidr'],
'gateway_ip': subnet['gateway_ip'],
'dns_nameservers': crd_dns_nameservers,
'allocation_pools': crd_allocation_pools,
'host_routes': crd_host_routes,
}}
def create_subnet_postcommit(self, context):
"""Send create_subnet data to CRD service."""
subnet = context.current
body = self._prepare_crd_subnet(subnet)
self._crdclient.create_subnet(body=body)
LOG.debug("create_subnet update sent to CRD Server: %s", body)
def update_subnet_postcommit(self, context):
"""Send update_subnet data to CRD service."""
subnet = context.current
body = self._prepare_crd_subnet(subnet)
self._crdclient.update_subnet(subnet['id'], body=body)
LOG.debug("update_subnet update sent to CRD Server: %s", body)
def delete_subnet_postcommit(self, context):
"""Send delete_subnet data to CRD service."""
subnet = context.current
self._crdclient.delete_subnet(subnet['id'])
LOG.debug("delete_subnet update sent to CRD Server: %s", subnet['id'])
def bind_port(self, context):
"""Set porting binding data for use with nova."""
LOG.debug("Attempting to bind port %(port)s on "
"network %(network)s",
{'port': context.current['id'],
'network': context.network.current['id']})
# Prepared porting binding data
for segment in context.segments_to_bind:
if self.check_segment(segment):
context.set_binding(segment[api.ID],
self.vif_type,
self.vif_details,
status=n_const.PORT_STATUS_ACTIVE)
LOG.debug("Bound using segment: %s", segment)
return
else:
LOG.debug("Refusing to bind port for segment ID %(id)s, "
"segment %(seg)s, phys net %(physnet)s, and "
"network type %(nettype)s",
{'id': segment[api.ID],
'seg': segment[api.SEGMENTATION_ID],
'physnet': segment[api.PHYSICAL_NETWORK],
'nettype': segment[api.NETWORK_TYPE]})
@log_helpers.log_method_call
def check_segment(self, segment):
"""Verify a segment is valid for the FSL SDN MechanismDriver."""
return segment[api.NETWORK_TYPE] in [constants.TYPE_VLAN,
constants.TYPE_VXLAN]
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
481,
5710,
2357,
3240,
2664,
28678,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
793,
492,
10897,
465,
943,
63,
7546,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
8224,
14,
2330,
492,
5262,
465,
302,
63,
1297,
199,
504,
8224,
14,
5359,
492,
1844,
10880,
199,
504,
8224,
14,
73,
1085,
78,
492,
485,
2673,
199,
504,
8224,
14,
5265,
14,
2330,
492,
5262,
199,
504,
8224,
14,
5265,
14,
757,
18,
492,
5253,
63,
1246,
465,
2986,
199,
504,
8224,
14,
5265,
14,
757,
18,
14,
13337,
14,
70,
5710,
2357,
492,
1101,
221,
327,
8151,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
481,
83,
478,
4272,
1352,
11993,
6158,
8,
1246,
14,
1352,
11993,
6158,
304,
339,
408,
38,
5710,
2357,
428,
10872,
4403,
3194,
11993,
19447,
367,
28007,
18,
11349,
1041,
339,
768,
793,
63,
7546,
14,
793,
63,
765,
63,
1250,
272,
347,
8265,
8,
277,
304,
267,
408,
9345,
314,
3194,
11993,
5253,
1041,
398,
291,
14,
14430,
63,
466,
275,
1844,
10880,
14,
27890,
63,
2711,
63,
47,
7428,
267,
291,
14,
14430,
63,
5087,
275,
469,
719,
10880,
14,
8549,
63,
3657,
63,
9905,
26,
715,
93,
267,
5051,
14,
815,
1547,
2673,
480,
5733,
9147,
445,
15543,
1890,
1396,
26725,
267,
291,
423,
1556,
68,
1258,
275,
1101,
14,
362,
63,
1556,
68,
1258,
342,
339,
327,
7220,
8259,
272,
768,
4639,
272,
768,
793,
63,
7546,
14,
793,
63,
765,
63,
1250,
272,
347,
485,
6726,
63,
1556,
68,
63,
1200,
8,
1200,
12,
11998,
304,
267,
408,
4433,
805,
370,
1218,
283,
1200,
7,
666,
1041,
398,
372,
791,
1200,
356,
355,
791,
1200,
63,
344,
356,
2784,
459,
344,
995,
326,
283,
4647,
63,
344,
356,
2784,
459,
4647,
63,
344,
995,
326,
283,
354,
356,
2784,
459,
354,
995,
326,
283,
1205,
356,
2784,
459,
1205,
995,
326,
283,
2113,
63,
929,
63,
384,
356,
2784,
459,
2113,
63,
929,
63,
384,
995,
326,
283,
13879,
356,
11998,
12,
326,
3586,
339,
347,
1218,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
6795,
1218,
63,
1200,
666,
370,
445,
15543,
2435,
1041,
398,
2784,
275,
1067,
14,
1818,
267,
11998,
275,
1067,
14,
1200,
63,
13879,
267,
2396,
275,
291,
423,
6726,
63,
1556,
68,
63,
1200,
8,
1200,
12,
11998,
9,
267,
291,
423,
1556,
68,
1258,
14,
981,
63,
1200,
8,
2030,
29,
2030,
9,
267,
5051,
14,
1757,
480,
981,
63,
1200,
1678,
4847,
370,
445,
15543,
7146,
26,
450,
83,
401,
2396,
9,
339,
347,
1678,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
6795,
1678,
63,
1200,
666,
370,
445,
15543,
2435,
1041,
398,
2784,
275,
1067,
14,
1818,
267,
11998,
275,
1067,
14,
1200,
63,
13879,
267,
2396,
275,
291,
423,
6726,
63,
1556,
68,
63,
1200,
8,
1200,
12,
11998,
9,
267,
291,
423,
1556,
68,
1258,
14,
873,
63,
1200,
8,
1200,
459,
344,
995,
2396,
29,
2030,
9,
267,
5051,
14,
1757,
480,
873,
63,
1200,
1678,
4847,
370,
445,
15543,
7146,
26,
450,
83,
401,
2396,
9,
339,
347,
3145,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
6795,
3145,
63,
1200,
666,
370,
445,
15543,
2435,
1041,
398,
2784,
275,
1067,
14,
1818,
267,
291,
423,
1556,
68,
1258,
14,
1807,
63,
1200,
8,
1200,
459,
344,
1105,
267,
5051,
14,
1757,
8,
288,
298,
1807,
63,
1200,
1678,
4847,
370,
445,
15543,
7146,
26,
450,
83,
401,
288,
2784,
459,
344,
1105,
339,
327,
10977,
8259,
272,
768,
4639,
272,
347,
485,
6726,
63,
1556,
68,
63,
719,
8,
719,
304,
267,
408,
4433,
805,
370,
9275,
283,
719,
7,
666,
1041,
398,
2467,
68,
63,
5327,
63,
344,
275,
2125,
267,
2467,
68,
63,
21809,
275,
2125,
267,
2467,
68,
63,
3321,
63,
2587,
1190,
275,
2125,
267,
327,
9336,
445,
15543,
11479,
1373,
18659,
3531,
12,
267,
327,
880,
2429,
1454,
1373,
6317,
3531,
1126,
1844,
14,
267,
340,
822,
8,
719,
459,
5964,
63,
6142,
1105,
690,
413,
26,
288,
5051,
14,
1757,
480,
11053,
2419,
1373,
6317,
3531,
3495,
446,
1808,
1642,
1373,
2685,
267,
327,
1104,
2701,
6317,
63,
6142,
769,
12,
4057,
641,
340,
1373,
503,
1655,
3495,
267,
340,
822,
8,
719,
459,
5964,
63,
6142,
1105,
1137,
378,
26,
288,
2467,
68,
63,
5327,
63,
344,
275,
1844,
459,
5964,
63,
6142,
3488,
16,
2733,
5327,
63,
344,
418,
288,
2467,
68,
63,
21809,
275,
1844,
459,
5964,
63,
6142,
3488,
16,
2733,
711,
63,
1562,
418,
288,
5051,
14,
1757,
480,
26443,
6317,
3531,
469,
5327,
63,
344,
19648,
5327,
9,
83,
12,
298,
1993,
298,
711,
63,
1562,
19648,
711,
9,
83,
10750,
1993,
791,
5327,
356,
2467,
68,
63,
5327,
63,
344,
12,
283,
711,
356,
2467,
68,
63,
21809,
1552,
267,
587,
26,
288,
5051,
14,
1757,
480,
1944,
6317,
30657,
1911,
2685,
267,
340,
283,
4416,
63,
2634,
7,
315,
1844,
26,
288,
2467,
68,
63,
3321,
63,
2587,
1190,
275,
12814,
904,
8,
719,
459,
4416,
63,
2634,
1105,
267,
372,
791,
719,
356,
355,
791,
719,
63,
344,
356,
1844,
459,
344,
995,
326,
283,
4647,
63,
344,
356,
1844,
459,
4647,
63,
344,
995,
326
] |
[
1898,
334,
67,
9,
6927,
481,
5710,
2357,
3240,
2664,
28678,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
793,
492,
10897,
465,
943,
63,
7546,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
8224,
14,
2330,
492,
5262,
465,
302,
63,
1297,
199,
504,
8224,
14,
5359,
492,
1844,
10880,
199,
504,
8224,
14,
73,
1085,
78,
492,
485,
2673,
199,
504,
8224,
14,
5265,
14,
2330,
492,
5262,
199,
504,
8224,
14,
5265,
14,
757,
18,
492,
5253,
63,
1246,
465,
2986,
199,
504,
8224,
14,
5265,
14,
757,
18,
14,
13337,
14,
70,
5710,
2357,
492,
1101,
221,
327,
8151,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
481,
83,
478,
4272,
1352,
11993,
6158,
8,
1246,
14,
1352,
11993,
6158,
304,
339,
408,
38,
5710,
2357,
428,
10872,
4403,
3194,
11993,
19447,
367,
28007,
18,
11349,
1041,
339,
768,
793,
63,
7546,
14,
793,
63,
765,
63,
1250,
272,
347,
8265,
8,
277,
304,
267,
408,
9345,
314,
3194,
11993,
5253,
1041,
398,
291,
14,
14430,
63,
466,
275,
1844,
10880,
14,
27890,
63,
2711,
63,
47,
7428,
267,
291,
14,
14430,
63,
5087,
275,
469,
719,
10880,
14,
8549,
63,
3657,
63,
9905,
26,
715,
93,
267,
5051,
14,
815,
1547,
2673,
480,
5733,
9147,
445,
15543,
1890,
1396,
26725,
267,
291,
423,
1556,
68,
1258,
275,
1101,
14,
362,
63,
1556,
68,
1258,
342,
339,
327,
7220,
8259,
272,
768,
4639,
272,
768,
793,
63,
7546,
14,
793,
63,
765,
63,
1250,
272,
347,
485,
6726,
63,
1556,
68,
63,
1200,
8,
1200,
12,
11998,
304,
267,
408,
4433,
805,
370,
1218,
283,
1200,
7,
666,
1041,
398,
372,
791,
1200,
356,
355,
791,
1200,
63,
344,
356,
2784,
459,
344,
995,
326,
283,
4647,
63,
344,
356,
2784,
459,
4647,
63,
344,
995,
326,
283,
354,
356,
2784,
459,
354,
995,
326,
283,
1205,
356,
2784,
459,
1205,
995,
326,
283,
2113,
63,
929,
63,
384,
356,
2784,
459,
2113,
63,
929,
63,
384,
995,
326,
283,
13879,
356,
11998,
12,
326,
3586,
339,
347,
1218,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
6795,
1218,
63,
1200,
666,
370,
445,
15543,
2435,
1041,
398,
2784,
275,
1067,
14,
1818,
267,
11998,
275,
1067,
14,
1200,
63,
13879,
267,
2396,
275,
291,
423,
6726,
63,
1556,
68,
63,
1200,
8,
1200,
12,
11998,
9,
267,
291,
423,
1556,
68,
1258,
14,
981,
63,
1200,
8,
2030,
29,
2030,
9,
267,
5051,
14,
1757,
480,
981,
63,
1200,
1678,
4847,
370,
445,
15543,
7146,
26,
450,
83,
401,
2396,
9,
339,
347,
1678,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
6795,
1678,
63,
1200,
666,
370,
445,
15543,
2435,
1041,
398,
2784,
275,
1067,
14,
1818,
267,
11998,
275,
1067,
14,
1200,
63,
13879,
267,
2396,
275,
291,
423,
6726,
63,
1556,
68,
63,
1200,
8,
1200,
12,
11998,
9,
267,
291,
423,
1556,
68,
1258,
14,
873,
63,
1200,
8,
1200,
459,
344,
995,
2396,
29,
2030,
9,
267,
5051,
14,
1757,
480,
873,
63,
1200,
1678,
4847,
370,
445,
15543,
7146,
26,
450,
83,
401,
2396,
9,
339,
347,
3145,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
6795,
3145,
63,
1200,
666,
370,
445,
15543,
2435,
1041,
398,
2784,
275,
1067,
14,
1818,
267,
291,
423,
1556,
68,
1258,
14,
1807,
63,
1200,
8,
1200,
459,
344,
1105,
267,
5051,
14,
1757,
8,
288,
298,
1807,
63,
1200,
1678,
4847,
370,
445,
15543,
7146,
26,
450,
83,
401,
288,
2784,
459,
344,
1105,
339,
327,
10977,
8259,
272,
768,
4639,
272,
347,
485,
6726,
63,
1556,
68,
63,
719,
8,
719,
304,
267,
408,
4433,
805,
370,
9275,
283,
719,
7,
666,
1041,
398,
2467,
68,
63,
5327,
63,
344,
275,
2125,
267,
2467,
68,
63,
21809,
275,
2125,
267,
2467,
68,
63,
3321,
63,
2587,
1190,
275,
2125,
267,
327,
9336,
445,
15543,
11479,
1373,
18659,
3531,
12,
267,
327,
880,
2429,
1454,
1373,
6317,
3531,
1126,
1844,
14,
267,
340,
822,
8,
719,
459,
5964,
63,
6142,
1105,
690,
413,
26,
288,
5051,
14,
1757,
480,
11053,
2419,
1373,
6317,
3531,
3495,
446,
1808,
1642,
1373,
2685,
267,
327,
1104,
2701,
6317,
63,
6142,
769,
12,
4057,
641,
340,
1373,
503,
1655,
3495,
267,
340,
822,
8,
719,
459,
5964,
63,
6142,
1105,
1137,
378,
26,
288,
2467,
68,
63,
5327,
63,
344,
275,
1844,
459,
5964,
63,
6142,
3488,
16,
2733,
5327,
63,
344,
418,
288,
2467,
68,
63,
21809,
275,
1844,
459,
5964,
63,
6142,
3488,
16,
2733,
711,
63,
1562,
418,
288,
5051,
14,
1757,
480,
26443,
6317,
3531,
469,
5327,
63,
344,
19648,
5327,
9,
83,
12,
298,
1993,
298,
711,
63,
1562,
19648,
711,
9,
83,
10750,
1993,
791,
5327,
356,
2467,
68,
63,
5327,
63,
344,
12,
283,
711,
356,
2467,
68,
63,
21809,
1552,
267,
587,
26,
288,
5051,
14,
1757,
480,
1944,
6317,
30657,
1911,
2685,
267,
340,
283,
4416,
63,
2634,
7,
315,
1844,
26,
288,
2467,
68,
63,
3321,
63,
2587,
1190,
275,
12814,
904,
8,
719,
459,
4416,
63,
2634,
1105,
267,
372,
791,
719,
356,
355,
791,
719,
63,
344,
356,
1844,
459,
344,
995,
326,
283,
4647,
63,
344,
356,
1844,
459,
4647,
63,
344,
995,
326,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40423218/2017springcd_hw
|
plugin/sitemap/sitemap.py
|
292
|
8774
|
# -*- coding: utf-8 -*-
'''
Sitemap
-------
The sitemap plugin generates plain-text or XML sitemaps.
'''
from __future__ import unicode_literals
import re
import collections
import os.path
from datetime import datetime
from logging import warning, info
from codecs import open
from pytz import timezone
from pelican import signals, contents
from pelican.utils import get_date
TXT_HEADER = """{0}/index.html
{0}/archives.html
{0}/tags.html
{0}/categories.html
"""
XML_HEADER = """<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
"""
XML_URL = """
<url>
<loc>{0}/{1}</loc>
<lastmod>{2}</lastmod>
<changefreq>{3}</changefreq>
<priority>{4}</priority>
</url>
"""
XML_FOOTER = """
</urlset>
"""
def format_date(date):
if date.tzinfo:
tz = date.strftime('%z')
tz = tz[:-2] + ':' + tz[-2:]
else:
tz = "-00:00"
return date.strftime("%Y-%m-%dT%H:%M:%S") + tz
class SitemapGenerator(object):
def __init__(self, context, settings, path, theme, output_path, *null):
self.output_path = output_path
self.context = context
self.now = datetime.now()
self.siteurl = settings.get('SITEURL')
self.default_timezone = settings.get('TIMEZONE', 'UTC')
self.timezone = getattr(self, 'timezone', self.default_timezone)
self.timezone = timezone(self.timezone)
self.format = 'xml'
self.changefreqs = {
'articles': 'monthly',
'indexes': 'daily',
'pages': 'monthly'
}
self.priorities = {
'articles': 0.5,
'indexes': 0.5,
'pages': 0.5
}
self.sitemapExclude = []
config = settings.get('SITEMAP', {})
if not isinstance(config, dict):
warning("sitemap plugin: the SITEMAP setting must be a dict")
else:
fmt = config.get('format')
pris = config.get('priorities')
chfreqs = config.get('changefreqs')
self.sitemapExclude = config.get('exclude', [])
if fmt not in ('xml', 'txt'):
warning("sitemap plugin: SITEMAP['format'] must be `txt' or `xml'")
warning("sitemap plugin: Setting SITEMAP['format'] on `xml'")
elif fmt == 'txt':
self.format = fmt
return
valid_keys = ('articles', 'indexes', 'pages')
valid_chfreqs = ('always', 'hourly', 'daily', 'weekly', 'monthly',
'yearly', 'never')
if isinstance(pris, dict):
# We use items for Py3k compat. .iteritems() otherwise
for k, v in pris.items():
if k in valid_keys and not isinstance(v, (int, float)):
default = self.priorities[k]
warning("sitemap plugin: priorities must be numbers")
warning("sitemap plugin: setting SITEMAP['priorities']"
"['{0}'] on {1}".format(k, default))
pris[k] = default
self.priorities.update(pris)
elif pris is not None:
warning("sitemap plugin: SITEMAP['priorities'] must be a dict")
warning("sitemap plugin: using the default values")
if isinstance(chfreqs, dict):
# .items() for py3k compat.
for k, v in chfreqs.items():
if k in valid_keys and v not in valid_chfreqs:
default = self.changefreqs[k]
warning("sitemap plugin: invalid changefreq `{0}'".format(v))
warning("sitemap plugin: setting SITEMAP['changefreqs']"
"['{0}'] on '{1}'".format(k, default))
chfreqs[k] = default
self.changefreqs.update(chfreqs)
elif chfreqs is not None:
warning("sitemap plugin: SITEMAP['changefreqs'] must be a dict")
warning("sitemap plugin: using the default values")
def write_url(self, page, fd):
if getattr(page, 'status', 'published') != 'published':
return
# We can disable categories/authors/etc by using False instead of ''
if not page.save_as:
return
page_path = os.path.join(self.output_path, page.save_as)
if not os.path.exists(page_path):
return
lastdate = getattr(page, 'date', self.now)
try:
lastdate = self.get_date_modified(page, lastdate)
except ValueError:
warning("sitemap plugin: " + page.save_as + " has invalid modification date,")
warning("sitemap plugin: using date value as lastmod.")
lastmod = format_date(lastdate)
if isinstance(page, contents.Article):
pri = self.priorities['articles']
chfreq = self.changefreqs['articles']
elif isinstance(page, contents.Page):
pri = self.priorities['pages']
chfreq = self.changefreqs['pages']
else:
pri = self.priorities['indexes']
chfreq = self.changefreqs['indexes']
pageurl = '' if page.url == 'index.html' else page.url
#Exclude URLs from the sitemap:
if self.format == 'xml':
flag = False
for regstr in self.sitemapExclude:
if re.match(regstr, pageurl):
flag = True
break
if not flag:
fd.write(XML_URL.format(self.siteurl, pageurl, lastmod, chfreq, pri))
else:
fd.write(self.siteurl + '/' + pageurl + '\n')
def get_date_modified(self, page, default):
if hasattr(page, 'modified'):
if isinstance(page.modified, datetime):
return page.modified
return get_date(page.modified)
else:
return default
def set_url_wrappers_modification_date(self, wrappers):
for (wrapper, articles) in wrappers:
lastmod = datetime.min.replace(tzinfo=self.timezone)
for article in articles:
lastmod = max(lastmod, article.date.replace(tzinfo=self.timezone))
try:
modified = self.get_date_modified(article, datetime.min).replace(tzinfo=self.timezone)
lastmod = max(lastmod, modified)
except ValueError:
# Supressed: user will be notified.
pass
setattr(wrapper, 'modified', str(lastmod))
def generate_output(self, writer):
path = os.path.join(self.output_path, 'sitemap.{0}'.format(self.format))
pages = self.context['pages'] + self.context['articles'] \
+ [ c for (c, a) in self.context['categories']] \
+ [ t for (t, a) in self.context['tags']] \
+ [ a for (a, b) in self.context['authors']]
self.set_url_wrappers_modification_date(self.context['categories'])
self.set_url_wrappers_modification_date(self.context['tags'])
self.set_url_wrappers_modification_date(self.context['authors'])
for article in self.context['articles']:
pages += article.translations
info('writing {0}'.format(path))
with open(path, 'w', encoding='utf-8') as fd:
if self.format == 'xml':
fd.write(XML_HEADER)
else:
fd.write(TXT_HEADER.format(self.siteurl))
FakePage = collections.namedtuple('FakePage',
['status',
'date',
'url',
'save_as'])
for standard_page_url in ['index.html',
'archives.html',
'tags.html',
'categories.html']:
fake = FakePage(status='published',
date=self.now,
url=standard_page_url,
save_as=standard_page_url)
self.write_url(fake, fd)
for page in pages:
self.write_url(page, fd)
if self.format == 'xml':
fd.write(XML_FOOTER)
def get_generators(generators):
return SitemapGenerator
def register():
signals.get_generators.connect(get_generators)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
8972,
1130,
199,
12797,
199,
199,
1918,
25121,
3589,
12821,
8971,
13,
505,
503,
4692,
4770,
8919,
14,
199,
2344,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
5055,
199,
646,
747,
14,
515,
199,
199,
504,
2197,
492,
2197,
199,
504,
2050,
492,
5721,
12,
2256,
199,
504,
6010,
492,
1551,
199,
504,
15444,
492,
7137,
199,
199,
504,
4837,
28091,
492,
10166,
12,
4072,
199,
504,
4837,
28091,
14,
1208,
492,
664,
63,
602,
199,
199,
17715,
63,
7311,
275,
408,
91,
16,
5995,
1080,
14,
1360,
199,
91,
16,
5995,
28067,
14,
1360,
199,
91,
16,
5995,
2969,
14,
1360,
199,
91,
16,
5995,
8906,
14,
1360,
199,
624,
199,
199,
4317,
63,
7311,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
24327,
199,
28,
633,
409,
9604,
26,
88,
338,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8339,
15,
32565,
13,
842,
2,
199,
88,
338,
26,
3629,
6592,
628,
1014,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
1455,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
15,
17205,
14,
10515,
2,
199,
13991,
628,
1014,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
1743,
199,
624,
199,
199,
4317,
63,
2632,
275,
408,
199,
28,
633,
30,
199,
28,
2102,
22266,
16,
16152,
17,
17890,
2102,
30,
199,
28,
2019,
1494,
22266,
18,
17890,
2019,
1494,
30,
199,
28,
1461,
5646,
22266,
19,
17890,
1461,
5646,
30,
199,
28,
6693,
22266,
20,
17890,
6693,
30,
199,
1108,
633,
30,
199,
624,
199,
199,
4317,
63,
13046,
1157,
275,
408,
199,
1108,
633,
409,
30,
199,
624,
421,
199,
318,
1475,
63,
602,
8,
602,
304,
272,
340,
1434,
14,
9374,
26,
267,
5823,
275,
1434,
14,
6205,
3508,
90,
358,
267,
5823,
275,
5823,
4439,
18,
61,
435,
10871,
435,
5823,
1988,
18,
2938,
272,
587,
26,
267,
5823,
275,
3905,
383,
26,
383,
2,
272,
372,
1434,
14,
6205,
3647,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
531,
435,
5823,
199,
199,
533,
11666,
1130,
7599,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1067,
12,
2202,
12,
931,
12,
8879,
12,
1072,
63,
515,
12,
627,
2307,
304,
398,
291,
14,
1199,
63,
515,
275,
1072,
63,
515,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
2131,
275,
2197,
14,
2131,
342,
267,
291,
14,
2124,
633,
275,
2202,
14,
362,
360,
7917,
2632,
358,
7318,
291,
14,
885,
63,
7145,
275,
2202,
14,
362,
360,
4961,
15353,
297,
283,
11288,
358,
267,
291,
14,
7145,
275,
2519,
8,
277,
12,
283,
7145,
297,
291,
14,
885,
63,
7145,
9,
267,
291,
14,
7145,
275,
7137,
8,
277,
14,
7145,
9,
398,
291,
14,
908,
275,
283,
1652,
7,
398,
291,
14,
1461,
28557,
275,
469,
288,
283,
19813,
356,
283,
30517,
297,
288,
283,
10116,
356,
283,
18621,
297,
288,
283,
5856,
356,
283,
30517,
7,
267,
789,
398,
291,
14,
13775,
12107,
275,
469,
288,
283,
19813,
356,
378,
14,
21,
12,
288,
283,
10116,
356,
378,
14,
21,
12,
288,
283,
5856,
356,
378,
14,
21,
267,
789,
398,
291,
14,
17205,
29448,
275,
942,
398,
1101,
275,
2202,
14,
362,
360,
51,
10439,
1282,
297,
5009,
398,
340,
440,
1228,
8,
888,
12,
1211,
304,
288,
5721,
480,
17205,
3589,
26,
314,
428,
10439,
1282,
4260,
1471,
506,
282,
1211,
531,
267,
587,
26,
288,
7104,
275,
1101,
14,
362,
360,
908,
358,
288,
1979,
83,
275,
1101,
14,
362,
360,
13775,
12107,
358,
288,
682,
28557,
275,
1101,
14,
362,
360,
1461,
28557,
358,
288,
291,
14,
17205,
29448,
275,
1101,
14,
362,
360,
5473,
297,
3073,
953,
340,
7104,
440,
315,
661,
1652,
297,
283,
2424,
735,
355,
5721,
480,
17205,
3589,
26,
428,
10439,
1282,
459,
908,
418,
1471,
506,
658,
2424,
7,
503,
658,
1652,
9859,
355,
5721,
480,
17205,
3589,
26,
13510,
428,
10439,
1282,
459,
908,
418,
641,
658,
1652,
9859,
288,
916,
7104,
508,
283,
2424,
356,
355,
291,
14,
908,
275,
7104,
355,
372,
953,
1686,
63,
1612,
275,
661,
19813,
297,
283,
10116,
297,
283,
5856,
358,
288,
1686,
63,
335,
28557,
275,
661,
9223,
297,
283,
5180,
590,
297,
283,
18621,
297,
283,
6419,
590,
297,
283,
30517,
297,
490,
283,
16785,
297,
283,
18178,
358,
953,
340,
1228,
8,
1359,
83,
12,
1211,
304,
355,
327,
2136,
675,
2974,
367,
1611,
19,
75,
8434,
14,
1275,
4611,
342,
4257,
355,
367,
1022,
12,
373,
315,
1979,
83,
14,
1744,
837,
490,
340,
1022,
315,
1686,
63,
1612,
436,
440,
1228,
8,
86,
12,
334,
442,
12,
2069,
2298,
717,
849,
275,
291,
14,
13775,
12107,
59,
75,
61,
717,
5721,
480,
17205,
3589,
26,
6791,
12107,
1471,
506,
5579,
531,
717,
5721,
480,
17205,
3589,
26,
4260,
428,
10439,
1282,
459,
13775,
12107,
18721,
1816,
25280,
91,
16,
93,
418,
641,
469,
17,
5469,
908,
8,
75,
12,
849,
430,
717,
1979,
83,
59,
75,
61,
275,
849,
355,
291,
14,
13775,
12107,
14,
873,
8,
1359,
83,
9,
288,
916,
1979,
83,
365,
440,
488,
26,
355,
5721,
480,
17205,
3589,
26,
428,
10439,
1282,
459,
13775,
12107,
418,
1471,
506,
282,
1211,
531,
355,
5721,
480,
17205,
3589,
26,
1808,
314,
849,
1338,
531,
953,
340,
1228,
8,
335,
28557,
12,
1211,
304,
355,
327,
1275,
1744,
342,
367,
1134,
19,
75,
8434,
14,
355,
367,
1022,
12,
373,
315,
682,
28557,
14,
1744,
837,
490,
340,
1022,
315,
1686,
63,
1612,
436,
373,
440,
315,
1686,
63,
335,
28557,
26,
717,
849,
275,
291,
14,
1461,
28557,
59,
75,
61,
717,
5721,
480,
17205,
3589,
26,
3866,
1570,
5646,
658,
91,
16,
30366,
908,
8,
86,
430,
717,
5721,
480,
17205,
3589,
26,
4260,
428,
10439,
1282,
459,
1461,
28557,
18721,
1816,
25280,
91,
16,
93,
418,
641,
5041,
17,
30366,
908,
8,
75,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
8972,
1130,
199,
12797,
199,
199,
1918,
25121,
3589,
12821,
8971,
13,
505,
503,
4692,
4770,
8919,
14,
199,
2344,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
5055,
199,
646,
747,
14,
515,
199,
199,
504,
2197,
492,
2197,
199,
504,
2050,
492,
5721,
12,
2256,
199,
504,
6010,
492,
1551,
199,
504,
15444,
492,
7137,
199,
199,
504,
4837,
28091,
492,
10166,
12,
4072,
199,
504,
4837,
28091,
14,
1208,
492,
664,
63,
602,
199,
199,
17715,
63,
7311,
275,
408,
91,
16,
5995,
1080,
14,
1360,
199,
91,
16,
5995,
28067,
14,
1360,
199,
91,
16,
5995,
2969,
14,
1360,
199,
91,
16,
5995,
8906,
14,
1360,
199,
624,
199,
199,
4317,
63,
7311,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
24327,
199,
28,
633,
409,
9604,
26,
88,
338,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8339,
15,
32565,
13,
842,
2,
199,
88,
338,
26,
3629,
6592,
628,
1014,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
1455,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
15,
17205,
14,
10515,
2,
199,
13991,
628,
1014,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
1743,
199,
624,
199,
199,
4317,
63,
2632,
275,
408,
199,
28,
633,
30,
199,
28,
2102,
22266,
16,
16152,
17,
17890,
2102,
30,
199,
28,
2019,
1494,
22266,
18,
17890,
2019,
1494,
30,
199,
28,
1461,
5646,
22266,
19,
17890,
1461,
5646,
30,
199,
28,
6693,
22266,
20,
17890,
6693,
30,
199,
1108,
633,
30,
199,
624,
199,
199,
4317,
63,
13046,
1157,
275,
408,
199,
1108,
633,
409,
30,
199,
624,
421,
199,
318,
1475,
63,
602,
8,
602,
304,
272,
340,
1434,
14,
9374,
26,
267,
5823,
275,
1434,
14,
6205,
3508,
90,
358,
267,
5823,
275,
5823,
4439,
18,
61,
435,
10871,
435,
5823,
1988,
18,
2938,
272,
587,
26,
267,
5823,
275,
3905,
383,
26,
383,
2,
272,
372,
1434,
14,
6205,
3647,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
531,
435,
5823,
199,
199,
533,
11666,
1130,
7599,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1067,
12,
2202,
12,
931,
12,
8879,
12,
1072,
63,
515,
12,
627,
2307,
304,
398,
291,
14,
1199,
63,
515,
275,
1072,
63,
515,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
2131,
275,
2197,
14,
2131,
342,
267,
291,
14,
2124,
633,
275,
2202,
14,
362,
360,
7917,
2632,
358,
7318,
291,
14,
885,
63,
7145,
275,
2202,
14,
362,
360,
4961,
15353,
297,
283,
11288,
358,
267,
291,
14,
7145,
275,
2519,
8,
277,
12,
283,
7145,
297,
291,
14,
885,
63,
7145,
9,
267,
291,
14,
7145,
275,
7137,
8,
277,
14,
7145,
9,
398,
291,
14,
908,
275,
283,
1652,
7,
398,
291,
14,
1461,
28557,
275,
469,
288,
283,
19813,
356,
283,
30517,
297,
288,
283,
10116,
356,
283,
18621,
297,
288,
283,
5856,
356,
283,
30517,
7,
267,
789,
398,
291,
14,
13775,
12107,
275,
469,
288,
283,
19813,
356,
378,
14,
21,
12,
288,
283,
10116,
356,
378,
14,
21,
12,
288,
283,
5856,
356,
378,
14,
21,
267,
789,
398,
291,
14,
17205,
29448,
275,
942,
398,
1101,
275,
2202,
14,
362,
360,
51,
10439,
1282,
297,
5009,
398,
340,
440,
1228,
8,
888,
12,
1211,
304,
288,
5721,
480,
17205,
3589,
26,
314,
428,
10439,
1282,
4260,
1471,
506,
282,
1211,
531,
267,
587,
26,
288,
7104,
275,
1101,
14,
362,
360,
908,
358,
288,
1979,
83,
275,
1101,
14,
362,
360,
13775,
12107,
358,
288,
682,
28557,
275,
1101,
14,
362,
360,
1461,
28557,
358,
288,
291,
14,
17205,
29448,
275,
1101,
14,
362,
360,
5473,
297,
3073,
953,
340,
7104,
440,
315,
661,
1652,
297,
283,
2424,
735,
355,
5721,
480,
17205,
3589,
26,
428,
10439,
1282,
459,
908,
418,
1471,
506,
658,
2424,
7,
503,
658,
1652,
9859,
355,
5721,
480,
17205,
3589,
26,
13510,
428,
10439,
1282,
459,
908,
418,
641,
658,
1652,
9859,
288,
916,
7104,
508,
283,
2424,
356,
355,
291,
14,
908,
275,
7104,
355,
372,
953,
1686,
63,
1612,
275,
661,
19813,
297,
283,
10116,
297,
283,
5856,
358,
288,
1686,
63,
335,
28557,
275,
661,
9223,
297,
283,
5180,
590,
297,
283,
18621,
297,
283,
6419,
590,
297,
283,
30517,
297,
490,
283,
16785,
297,
283,
18178,
358,
953,
340,
1228,
8,
1359,
83,
12,
1211,
304,
355,
327,
2136,
675,
2974,
367,
1611,
19,
75,
8434,
14,
1275,
4611,
342,
4257,
355,
367,
1022,
12,
373,
315,
1979,
83,
14,
1744,
837,
490,
340,
1022,
315,
1686,
63,
1612,
436,
440,
1228,
8,
86,
12,
334,
442,
12,
2069,
2298,
717,
849,
275,
291,
14,
13775,
12107,
59,
75,
61,
717,
5721,
480,
17205,
3589,
26,
6791,
12107,
1471,
506,
5579,
531,
717,
5721,
480,
17205,
3589,
26,
4260,
428,
10439,
1282,
459,
13775,
12107,
18721,
1816,
25280,
91,
16,
93,
418,
641,
469,
17,
5469,
908,
8,
75,
12,
849,
430,
717,
1979,
83,
59,
75,
61,
275,
849,
355,
291,
14,
13775,
12107,
14,
873,
8,
1359,
83,
9,
288,
916,
1979,
83,
365,
440,
488,
26,
355,
5721,
480,
17205,
3589,
26,
428,
10439,
1282,
459,
13775,
12107,
418,
1471,
506,
282,
1211,
531,
355,
5721,
480,
17205,
3589,
26,
1808,
314,
849,
1338,
531,
953,
340,
1228,
8,
335,
28557,
12,
1211,
304,
355,
327,
1275,
1744,
342,
367,
1134,
19,
75,
8434,
14,
355,
367,
1022,
12,
373,
315,
682,
28557,
14,
1744,
837,
490,
340,
1022,
315,
1686,
63,
1612,
436,
373,
440,
315,
1686,
63,
335,
28557,
26,
717,
849,
275,
291,
14,
1461,
28557,
59,
75,
61,
717,
5721,
480,
17205,
3589,
26,
3866,
1570,
5646,
658,
91,
16,
30366,
908,
8,
86,
430,
717,
5721,
480,
17205,
3589,
26,
4260,
428,
10439,
1282,
459,
1461,
28557,
18721,
1816,
25280,
91,
16,
93,
418,
641,
5041,
17,
30366,
908,
8,
75,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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props.py
|
4
|
3885
|
# encoding: utf-8
"""
Core properties part, corresponds to ``/docProps/core.xml`` part in package.
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
from datetime import datetime
from ..opc.constants import CONTENT_TYPE as CT
from ..opc.package import XmlPart
from ..opc.packuri import PackURI
from ..oxml.coreprops import CT_CoreProperties
class CorePropertiesPart(XmlPart):
"""
Corresponds to part named ``/docProps/core.xml``, containing the core
document properties for this document package.
"""
@classmethod
def default(cls):
core_props = cls._new()
core_props.title = 'PowerPoint Presentation'
core_props.last_modified_by = 'python-pptx'
core_props.revision = 1
core_props.modified = datetime.utcnow()
return core_props
@property
def author(self):
return self._element.author_text
@author.setter
def author(self, value):
self._element.author_text = value
@property
def category(self):
return self._element.category_text
@category.setter
def category(self, value):
self._element.category_text = value
@property
def comments(self):
return self._element.comments_text
@comments.setter
def comments(self, value):
self._element.comments_text = value
@property
def content_status(self):
return self._element.contentStatus_text
@content_status.setter
def content_status(self, value):
self._element.contentStatus_text = value
@property
def created(self):
return self._element.created_datetime
@created.setter
def created(self, value):
self._element.created_datetime = value
@property
def identifier(self):
return self._element.identifier_text
@identifier.setter
def identifier(self, value):
self._element.identifier_text = value
@property
def keywords(self):
return self._element.keywords_text
@keywords.setter
def keywords(self, value):
self._element.keywords_text = value
@property
def language(self):
return self._element.language_text
@language.setter
def language(self, value):
self._element.language_text = value
@property
def last_modified_by(self):
return self._element.lastModifiedBy_text
@last_modified_by.setter
def last_modified_by(self, value):
self._element.lastModifiedBy_text = value
@property
def last_printed(self):
return self._element.lastPrinted_datetime
@last_printed.setter
def last_printed(self, value):
self._element.lastPrinted_datetime = value
@property
def modified(self):
return self._element.modified_datetime
@modified.setter
def modified(self, value):
self._element.modified_datetime = value
@property
def revision(self):
return self._element.revision_number
@revision.setter
def revision(self, value):
self._element.revision_number = value
@property
def subject(self):
return self._element.subject_text
@subject.setter
def subject(self, value):
self._element.subject_text = value
@property
def title(self):
return self._element.title_text
@title.setter
def title(self, value):
self._element.title_text = value
@property
def version(self):
return self._element.version_text
@version.setter
def version(self, value):
self._element.version_text = value
@classmethod
def _new(cls):
partname = PackURI('/docProps/core.xml')
content_type = CT.OPC_CORE_PROPERTIES
core_props_elm = CT_CoreProperties.new_coreProperties()
return CorePropertiesPart(partname, content_type, core_props_elm)
|
apache-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
199,
624,
199,
5402,
4382,
1777,
12,
13718,
370,
1124,
15,
1301,
24188,
15,
1018,
14,
1652,
1040,
1777,
315,
2559,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
272,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
9,
199,
199,
504,
2197,
492,
2197,
199,
199,
504,
2508,
411,
67,
14,
5559,
492,
29417,
63,
2711,
465,
24990,
199,
504,
2508,
411,
67,
14,
2491,
492,
24881,
8416,
199,
504,
2508,
411,
67,
14,
1389,
2302,
492,
9954,
7639,
199,
504,
2508,
79,
1652,
14,
1018,
6750,
492,
24990,
63,
5402,
8516,
421,
199,
533,
11672,
8516,
8416,
8,
8672,
8416,
304,
272,
408,
272,
7499,
3853,
795,
370,
1777,
4310,
1124,
15,
1301,
24188,
15,
1018,
14,
1652,
4542,
3035,
314,
6170,
272,
2213,
4382,
367,
642,
2213,
2559,
14,
272,
408,
272,
768,
3744,
272,
347,
849,
8,
1886,
304,
267,
6170,
63,
6750,
275,
843,
423,
1222,
342,
267,
6170,
63,
6750,
14,
1213,
275,
283,
6921,
3428,
5543,
1150,
425,
7,
267,
6170,
63,
6750,
14,
2019,
63,
5540,
63,
991,
275,
283,
1548,
13,
80,
541,
88,
7,
267,
6170,
63,
6750,
14,
5792,
275,
413,
267,
6170,
63,
6750,
14,
5540,
275,
2197,
14,
10779,
342,
267,
372,
6170,
63,
6750,
339,
768,
1829,
272,
347,
4132,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
2502,
63,
505,
339,
768,
2502,
14,
8345,
272,
347,
4132,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
2502,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
4637,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
3710,
63,
505,
339,
768,
3710,
14,
8345,
272,
347,
4637,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
3710,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
6786,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
6223,
63,
505,
339,
768,
6223,
14,
8345,
272,
347,
6786,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
6223,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
1564,
63,
1205,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
1317,
3694,
63,
505,
339,
768,
1317,
63,
1205,
14,
8345,
272,
347,
1564,
63,
1205,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
1317,
3694,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2737,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
3966,
63,
2083,
339,
768,
3966,
14,
8345,
272,
347,
2737,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
3966,
63,
2083,
275,
574,
339,
768,
1829,
272,
347,
5148,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5364,
63,
505,
339,
768,
5364,
14,
8345,
272,
347,
5148,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5364,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
7681,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
7511,
63,
505,
339,
768,
7511,
14,
8345,
272,
347,
7681,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
7511,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
3671,
63,
505,
339,
768,
3671,
14,
8345,
272,
347,
2637,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
3671,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2061,
63,
5540,
63,
991,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
2019,
11911,
2175,
63,
505,
339,
768,
2019,
63,
5540,
63,
991,
14,
8345,
272,
347,
2061,
63,
5540,
63,
991,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
2019,
11911,
2175,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2061,
63,
27131,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
2019,
9779,
9082,
63,
2083,
339,
768,
2019,
63,
27131,
14,
8345,
272,
347,
2061,
63,
27131,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
2019,
9779,
9082,
63,
2083,
275,
574,
339,
768,
1829,
272,
347,
6042,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5540,
63,
2083,
339,
768,
5540,
14,
8345,
272,
347,
6042,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5540,
63,
2083,
275,
574,
339,
768,
1829,
272,
347,
6974,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5792,
63,
1955,
339,
768,
5792,
14,
8345,
272,
347,
6974,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5792,
63,
1955,
275,
574,
339,
768,
1829,
272,
347,
5420,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5875,
63,
505,
339,
768,
5875,
14,
8345,
272,
347,
5420,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5875,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2538,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
1213,
63,
505,
339,
768,
1213,
14,
8345,
272,
347,
2538,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
1213,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
1015,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
1023,
63,
505,
339,
768,
1023,
14,
8345,
272,
347,
1015,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
1023,
63,
505,
275,
574,
339,
768,
3744,
272,
347,
485,
1222,
8,
1886,
304,
267,
1777,
354,
275,
9954,
7639,
2336,
1301,
24188,
15,
1018,
14,
1652,
358,
267,
1564,
63,
466,
275,
24990,
14,
1938,
35,
63,
24428,
63,
18858,
29807,
267,
6170,
63,
6750,
63,
21226,
275,
24990,
63,
5402,
8516,
14,
1222,
63,
1018,
8516,
342,
267,
372,
11672,
8516,
8416,
8,
2064,
354,
12,
1564,
63,
466,
12,
6170,
63,
6750,
63,
21226,
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
] |
[
2644,
26,
2774,
13,
24,
199,
199,
624,
199,
5402,
4382,
1777,
12,
13718,
370,
1124,
15,
1301,
24188,
15,
1018,
14,
1652,
1040,
1777,
315,
2559,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
272,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
9,
199,
199,
504,
2197,
492,
2197,
199,
199,
504,
2508,
411,
67,
14,
5559,
492,
29417,
63,
2711,
465,
24990,
199,
504,
2508,
411,
67,
14,
2491,
492,
24881,
8416,
199,
504,
2508,
411,
67,
14,
1389,
2302,
492,
9954,
7639,
199,
504,
2508,
79,
1652,
14,
1018,
6750,
492,
24990,
63,
5402,
8516,
421,
199,
533,
11672,
8516,
8416,
8,
8672,
8416,
304,
272,
408,
272,
7499,
3853,
795,
370,
1777,
4310,
1124,
15,
1301,
24188,
15,
1018,
14,
1652,
4542,
3035,
314,
6170,
272,
2213,
4382,
367,
642,
2213,
2559,
14,
272,
408,
272,
768,
3744,
272,
347,
849,
8,
1886,
304,
267,
6170,
63,
6750,
275,
843,
423,
1222,
342,
267,
6170,
63,
6750,
14,
1213,
275,
283,
6921,
3428,
5543,
1150,
425,
7,
267,
6170,
63,
6750,
14,
2019,
63,
5540,
63,
991,
275,
283,
1548,
13,
80,
541,
88,
7,
267,
6170,
63,
6750,
14,
5792,
275,
413,
267,
6170,
63,
6750,
14,
5540,
275,
2197,
14,
10779,
342,
267,
372,
6170,
63,
6750,
339,
768,
1829,
272,
347,
4132,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
2502,
63,
505,
339,
768,
2502,
14,
8345,
272,
347,
4132,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
2502,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
4637,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
3710,
63,
505,
339,
768,
3710,
14,
8345,
272,
347,
4637,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
3710,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
6786,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
6223,
63,
505,
339,
768,
6223,
14,
8345,
272,
347,
6786,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
6223,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
1564,
63,
1205,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
1317,
3694,
63,
505,
339,
768,
1317,
63,
1205,
14,
8345,
272,
347,
1564,
63,
1205,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
1317,
3694,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2737,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
3966,
63,
2083,
339,
768,
3966,
14,
8345,
272,
347,
2737,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
3966,
63,
2083,
275,
574,
339,
768,
1829,
272,
347,
5148,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5364,
63,
505,
339,
768,
5364,
14,
8345,
272,
347,
5148,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5364,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
7681,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
7511,
63,
505,
339,
768,
7511,
14,
8345,
272,
347,
7681,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
7511,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
3671,
63,
505,
339,
768,
3671,
14,
8345,
272,
347,
2637,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
3671,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2061,
63,
5540,
63,
991,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
2019,
11911,
2175,
63,
505,
339,
768,
2019,
63,
5540,
63,
991,
14,
8345,
272,
347,
2061,
63,
5540,
63,
991,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
2019,
11911,
2175,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2061,
63,
27131,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
2019,
9779,
9082,
63,
2083,
339,
768,
2019,
63,
27131,
14,
8345,
272,
347,
2061,
63,
27131,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
2019,
9779,
9082,
63,
2083,
275,
574,
339,
768,
1829,
272,
347,
6042,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5540,
63,
2083,
339,
768,
5540,
14,
8345,
272,
347,
6042,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5540,
63,
2083,
275,
574,
339,
768,
1829,
272,
347,
6974,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5792,
63,
1955,
339,
768,
5792,
14,
8345,
272,
347,
6974,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5792,
63,
1955,
275,
574,
339,
768,
1829,
272,
347,
5420,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
5875,
63,
505,
339,
768,
5875,
14,
8345,
272,
347,
5420,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
5875,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
2538,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
1213,
63,
505,
339,
768,
1213,
14,
8345,
272,
347,
2538,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
1213,
63,
505,
275,
574,
339,
768,
1829,
272,
347,
1015,
8,
277,
304,
267,
372,
291,
423,
2108,
14,
1023,
63,
505,
339,
768,
1023,
14,
8345,
272,
347,
1015,
8,
277,
12,
574,
304,
267,
291,
423,
2108,
14,
1023,
63,
505,
275,
574,
339,
768,
3744,
272,
347,
485,
1222,
8,
1886,
304,
267,
1777,
354,
275,
9954,
7639,
2336,
1301,
24188,
15,
1018,
14,
1652,
358,
267,
1564,
63,
466,
275,
24990,
14,
1938,
35,
63,
24428,
63,
18858,
29807,
267,
6170,
63,
6750,
63,
21226,
275,
24990,
63,
5402,
8516,
14,
1222,
63,
1018,
8516,
342,
267,
372,
11672,
8516,
8416,
8,
2064,
354,
12,
1564,
63,
466,
12,
6170,
63,
6750,
63,
21226,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jazkarta/edx-platform
|
lms/djangoapps/branding/migrations/0001_initial.py
|
102
|
4789
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'BrandingInfoConfig'
db.create_table('branding_brandinginfoconfig', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('change_date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('changed_by', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, on_delete=models.PROTECT)),
('enabled', self.gf('django.db.models.fields.BooleanField')(default=False)),
('configuration', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal('branding', ['BrandingInfoConfig'])
def backwards(self, orm):
# Deleting model 'BrandingInfoConfig'
db.delete_table('branding_brandinginfoconfig')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'branding.brandinginfoconfig': {
'Meta': {'object_name': 'BrandingInfoConfig'},
'change_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'changed_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'on_delete': 'models.PROTECT'}),
'configuration': ('django.db.models.fields.TextField', [], {}),
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['branding']
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
34,
3759,
316,
2354,
2028,
7,
267,
1592,
14,
981,
63,
1224,
360,
19026,
316,
63,
19026,
316,
815,
888,
297,
334,
288,
661,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1461,
63,
602,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
63,
525,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
2489,
63,
991,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
995,
2973,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
29148,
1826,
288,
661,
3827,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
797,
1826,
288,
661,
4758,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
358,
4000,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
19026,
316,
297,
788,
34,
3759,
316,
2354,
2028,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
34,
3759,
316,
2354,
2028,
7,
267,
1592,
14,
1807,
63,
1224,
360,
19026,
316,
63,
19026,
316,
815,
888,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
19026,
316,
14,
19026,
316,
815,
888,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
34,
3759,
316,
2354,
2028,
2267,
288,
283,
1461,
63,
602,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2489,
63,
991,
356,
661,
1176,
14,
697,
14,
992,
14,
955
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
34,
3759,
316,
2354,
2028,
7,
267,
1592,
14,
981,
63,
1224,
360,
19026,
316,
63,
19026,
316,
815,
888,
297,
334,
288,
661,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1461,
63,
602,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
63,
525,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
2489,
63,
991,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
995,
2973,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
29148,
1826,
288,
661,
3827,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
797,
1826,
288,
661,
4758,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
358,
4000,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
19026,
316,
297,
788,
34,
3759,
316,
2354,
2028,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
34,
3759,
316,
2354,
2028,
7,
267,
1592,
14,
1807,
63,
1224,
360,
19026,
316,
63,
19026,
316,
815,
888,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
19026,
316,
14,
19026,
316,
815,
888,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
34,
3759,
316,
2354,
2028,
2267,
288,
283,
1461,
63,
602,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2489,
63,
991,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
GitSomeCode/RecipeApp
|
Proj/initial.py
|
1
|
8001
|
#!/usr/bin/env python
import os
import sys
import django
import random
randomUser = lambda: get_user_model().objects.all()[random.randrange(0, get_user_model().objects.count())]
rr = lambda x, y: random.randrange(x, y)
def endall():
# Delete Snippets.
for obj in Recipe.objects.all():
obj.delete()
# Delete Users.
for obj in get_user_model().objects.all():
obj.delete()
def makeUser(n, e, p):
try:
usr = get_user_model().objects.get(username = n)
return usr
except get_user_model().DoesNotExist:
return get_user_model().objects.create_user(username = n, email = e, password = p)
def makeRecipe(author = None, title = None, slug = None, ingredients = None, method = None, notes = None, tags = None):
y = rr(1, 10)
p = rr(1, 15)
c = rr(15, 50)
s = Recipe.objects.create(author = author, title = title, ingredients = ingredients, method = method, yieldAmt = y, prepTime = p, cookTime = c, notes = notes)
for t in tags:
s.tags.add(t)
s.save()
## title, slug, ingredients, method, yieldAmt, prepTime, cookTime, notes, author
def main():
# Make Users.
Emily = makeUser("emily", "emily@gmail.com", "emily")
Ramin = makeUser("ramin", "ramin@gmail.com", "ramin")
Tyler = makeUser("tyler", "tyler@gmail.com", "tyler")
Bella = makeUser("bella", "bella@gmail.com", "bella")
Jessica = makeUser("jessica", "jessica@gmail.com", "jessica")
Freddy = makeUser("freddy", "freddy@gmail.com", "freddy")
Drogo = get_user_model().objects.create_superuser(username = "drogo", email = "drogo@gmail.com", password = "drogo")
Harry = get_user_model().objects.create_superuser(username = "harry", email = "harry@gmail.com", password = "harry")
###################################
In_r1 = {
"1":"8 cups finely diced cabbage",
"2":"1/4 cup diced carrots",
"3":"2 tablespoons minced onions",
"4":"1/3 cup granulated sugar",
"5":"1/2 teaspoon salt",
"6":"1/8 teaspoon pepper",
"7":"1/4 cup milk",
"8":"1/2 cup mayonnaise",
"9":"1/4 cup buttermilk",
"10":"1 1/2 tablespoons white vinegar",
"11":"2 1/2 tablespoons lemon juice"
}
Md_r1 = {
"1":"Cabbage and carrots must be finely diced. (I use fine shredder disc on food processor).",
"2":"Pour cabbage and carrot mixture into large bowl and stir in minced onions.",
"3":"Using regular blade on food processor process remaining ingredients until smooth.",
"4":"Pour over vegetable mixture and mix thoroughly."
}
N_r1 = "Cover bowl and refrigerate several hours or overnight before serving."
makeRecipe(
title = "KFC Coleslaw",
ingredients = In_r1,
method = Md_r1,
notes = N_r1,
author = randomUser(),
tags = ["coleslaw", "salad", "dinner", "lettuce"]
)
#--------------------------------------------------------
In_r1 = {
"1":"1 cup old fashioned rolled oats",
"2":"2 cups water",
"3":"sea salt to taste",
"4":"1/2 tsp cinnamon",
"5":"1/4 cup raisins",
"6":"1/4 cup sliced almonds",
"7":"1 cup skim milk",
"8":"1 TBS blackstrap molasses",
}
Md_r1 = {
"1":"Bring the water and salt to a boil in a saucepan, then turn the heat to low and add the oats.",
"2":"Cook for about 5 minutes, stirring regularly so that the oatmeal will not clump together.",
"3":"Add cinnamon, raisins and almonds, stir, cover the pan and turn off heat.",
"4":"Let sit for 5 minutes.",
}
N_r1 = "Serve with milk and sweetener."
makeRecipe(
title = "Five Minute Energizing Oatmeal",
ingredients = In_r1,
method = Md_r1,
notes = N_r1,
author = randomUser(),
tags = ["oatmeal", "energy", "food", "yes"]
)
#--------------------------------------------------------
In_r1 = {
"1":"1 cup old fashioned rolled oats",
"2":"2 cups water",
"3":"sea salt to taste",
"4":"1/2 tsp cinnamon",
"5":"1/4 cup raisins",
"6":"1/4 cup sliced almonds",
"7":"1 cup skim milk",
"8":"1 TBS blackstrap molasses",
}
Md_r1 = {
"1":"Bring the water and salt to a boil in a saucepan, then turn the heat to low and add the oats.",
"2":"Cook for about 5 minutes, stirring regularly so that the oatmeal will not clump together.",
"3":"Add cinnamon, raisins and almonds, stir, cover the pan and turn off heat.",
"4":"Let sit for 5 minutes.",
}
N_r1 = "Serve with milk and sweetener."
makeRecipe(
title = "Five Minute Energizing Oatmeal",
ingredients = In_r1,
method = Md_r1,
notes = N_r1,
author = randomUser(),
tags = ["oatmeal", "energy", "food", "yes"]
)
#--------------------------------------------------------
In_r1 = {
"1":"2 omega-3-rich eggs",
"2":"1/2 can black beans, drained and mashed",
"3":"1 TBS extra virgin olive oil",
"4":"1 tsp lemon juice",
"5":"sea salt and pepper, to taste",
"6":"1/4 avocado, sliced",
"7":"salsa from a jar, to taste",
"8":"3 TBS grated low-fat cheddar cheese",
"9":"chopped cilantro, to taste",
}
Md_r1 = {
"1":"Poach eggs.",
"2":"Heat beans in a skillet while eggs are cooking.",
"3":"Remove beans from heat and mix in olive oil, lemon juice, salt and pepper Add a pinch of cayenne for spicy beans.",
"4":"Place beans on plate, top with poached eggs, avocado, salsa, cheese and cilantro",
}
N_r1 = "Serve with milk and sweetener."
makeRecipe(
title = "Two Minute Huevos Rancheros",
ingredients = In_r1,
method = Md_r1,
notes = N_r1,
author = randomUser(),
tags = ["huevos", "ranchero", "mexican", "eggs"]
)
#--------------------------------------------------------
In_r1 = {
"1":"3 eggs warmed in hot water for 5 minutes",
"2":"pinch salt",
"3":"1 teaspoon room temperature butter, plus 1/2 teaspoon for finishing omelet",
"4":"1/2 teaspoon fresh chopped chives",
}
Md_r1 = {
"1":"Crack the warm eggs into a bowl, add salt and blend with a fork. Heat a 10-inch nonstick aluminum pan over medium-high heat. Once the pan is hot, add the butter and brush around the surface of the pan. Pour the eggs into the center of the pan and stir vigorously with a rubber spatula for 5 seconds.",
"2":"As soon as a semi-solid mass begins to form, lift the pan and move it around until the excess liquid pours off into the pan. Using your spatula, move it around the edge of the egg mixture to help shape into a round and loosen the edge. Let the omelet sit in the pan for 10 seconds without touching",
"3":"Shake the pan to loosen from the pan. Lift up the far edge of the pan and snap it back toward you. Using your spatula, fold over one-third of the omelet. Slide the omelet onto a plate and fold over so that the omelet is a tri-fold.",
"4":"Coat with the remaining butter and sprinkle with the chives. Serve immediately.",
}
N_r1 = "Add scallions"
makeRecipe(
title = "Omelet",
ingredients = In_r1,
method = Md_r1,
notes = N_r1,
author = randomUser(),
tags = ["omelet", "tasty", "peppers", "eggs"]
)
#--------------------------------------------------------
In_r1 = {
"1":"11 cup high fiber cereal",
"2":"1 cup blueberries",
"3":"2 tsp blackstrap molasses",
"4":"1/2 cup skim milk or dairy-free milk alternative",
}
Md_r1 = {
"1":"Combine all ingredients and enjoy!",
}
N_r1 = ""
makeRecipe(
title = "High Fiber Cereal",
ingredients = In_r1,
method = Md_r1,
notes = N_r1,
author = randomUser(),
tags = ["cereal", "oats", "fiber", "health"]
)
#--------------------------------------------------------
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Proj.settings")
django.setup()
from myrecipe.models import Recipe
from django.contrib.auth import get_user_model
if 'x' in sys.argv[1:]:
print "Clearing database...\n"
endall()
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
646,
747,
199,
646,
984,
199,
646,
1639,
199,
646,
2196,
199,
199,
2355,
1899,
275,
2400,
26,
664,
63,
751,
63,
1238,
1252,
1462,
14,
452,
3430,
2355,
14,
20539,
8,
16,
12,
664,
63,
751,
63,
1238,
1252,
1462,
14,
835,
24821,
199,
9734,
275,
2400,
671,
12,
612,
26,
2196,
14,
20539,
8,
88,
12,
612,
9,
199,
199,
318,
1284,
452,
837,
523,
327,
8496,
428,
78,
15147,
14,
523,
367,
1559,
315,
799,
8233,
14,
1462,
14,
452,
837,
272,
1559,
14,
1807,
342,
523,
327,
8496,
20123,
14,
523,
367,
1559,
315,
664,
63,
751,
63,
1238,
1252,
1462,
14,
452,
837,
272,
1559,
14,
1807,
342,
199,
199,
318,
1852,
1899,
8,
78,
12,
325,
12,
299,
304,
523,
862,
26,
272,
30464,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
362,
8,
2473,
275,
302,
9,
272,
372,
30464,
523,
871,
664,
63,
751,
63,
1238,
1252,
7400,
26,
272,
372,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
751,
8,
2473,
275,
302,
12,
3031,
275,
325,
12,
2505,
275,
299,
9,
2043,
199,
318,
1852,
25879,
8,
2502,
275,
488,
12,
2538,
275,
488,
12,
8889,
275,
488,
12,
315,
9157,
3766,
83,
275,
488,
12,
1083,
275,
488,
12,
12681,
275,
488,
12,
3762,
275,
488,
304,
272,
612,
275,
17615,
8,
17,
12,
1616,
9,
272,
299,
275,
17615,
8,
17,
12,
4114,
9,
272,
286,
275,
17615,
8,
1046,
12,
5238,
9,
272,
308,
275,
799,
8233,
14,
1462,
14,
981,
8,
2502,
275,
4132,
12,
2538,
275,
2538,
12,
315,
9157,
3766,
83,
275,
315,
9157,
3766,
83,
12,
1083,
275,
1083,
12,
1995,
33,
2037,
275,
612,
12,
19986,
1366,
275,
299,
12,
512,
745,
1366,
275,
286,
12,
12681,
275,
12681,
9,
272,
367,
307,
315,
3762,
26,
489,
308,
14,
2969,
14,
525,
8,
84,
9,
272,
308,
14,
2117,
342,
199,
199,
309,
2538,
12,
8889,
12,
315,
9157,
3766,
83,
12,
1083,
12,
1995,
33,
2037,
12,
19986,
1366,
12,
512,
745,
1366,
12,
12681,
12,
4132,
199,
199,
318,
2446,
837,
819,
327,
4155,
20123,
14,
523,
662,
77,
3444,
275,
1852,
1899,
480,
5633,
3444,
401,
298,
5633,
3444,
32,
6799,
14,
957,
401,
298,
5633,
3444,
531,
523,
820,
32374,
275,
1852,
1899,
480,
345,
827,
401,
298,
345,
827,
32,
6799,
14,
957,
401,
298,
345,
827,
531,
523,
377,
89,
1435,
275,
1852,
1899,
480,
369,
1435,
401,
298,
369,
1435,
32,
6799,
14,
957,
401,
298,
369,
1435,
531,
523,
699,
352,
416,
275,
1852,
1899,
480,
20621,
416,
401,
298,
20621,
416,
32,
6799,
14,
957,
401,
298,
20621,
416,
531,
523,
1603,
28601,
696,
275,
1852,
1899,
480,
74,
28601,
696,
401,
298,
74,
28601,
696,
32,
6799,
14,
957,
401,
298,
74,
28601,
696,
531,
523,
481,
581,
8161,
275,
1852,
1899,
480,
22980,
8161,
401,
298,
22980,
8161,
32,
6799,
14,
957,
401,
298,
22980,
8161,
531,
523,
577,
293,
1939,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
11434,
8,
2473,
275,
298,
17264,
1939,
401,
3031,
275,
298,
17264,
1939,
32,
6799,
14,
957,
401,
2505,
275,
298,
17264,
1939,
531,
523,
25378,
651,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
11434,
8,
2473,
275,
298,
8210,
651,
401,
3031,
275,
298,
8210,
651,
32,
6799,
14,
957,
401,
2505,
275,
298,
8210,
651,
531,
12244,
10371,
5680,
523,
1010,
63,
82,
17,
275,
469,
272,
298,
17,
5122,
24,
286,
15203,
2583,
7742,
487,
6867,
286,
12198,
474,
401,
272,
298,
18,
5122,
17,
15,
20,
286,
384,
487,
6867,
9590,
293,
1086,
401,
272,
298,
19,
5122,
18,
6716,
555,
4654,
1748,
6867,
641,
15293,
401,
272,
298,
20,
5122,
17,
15,
19,
286,
384,
9202,
8097,
308,
21922,
401,
272,
298,
21,
5122,
17,
15,
18,
1565,
305,
555,
265,
10105,
401,
272,
298,
22,
5122,
17,
15,
24,
1565,
305,
555,
265,
22602,
529,
401,
272,
298,
23,
5122,
17,
15,
20,
286,
384,
333,
382,
75,
401,
272,
298,
24,
5122,
17,
15,
18,
286,
384,
1443,
265,
3540,
572,
401,
272,
298,
25,
5122,
17,
15,
20,
286,
384,
1325,
5125,
382,
75,
401,
272,
298,
709,
5122,
17,
413,
15,
18,
6716,
555,
4654,
10424,
373,
1132,
23909,
401,
272,
298,
845,
5122,
18,
413,
15,
18,
6716,
555,
4654,
1026,
2106,
1335,
85,
1885,
2,
523,
789,
523,
603,
68,
63,
82,
17,
275,
469,
272,
298,
17,
5122,
35,
12198,
474,
436,
9590,
293,
1086,
1471,
506,
2583,
7742,
487,
6867,
14,
334,
41,
675,
15701,
1033,
581,
424,
4339,
641,
7090,
364,
12495,
680,
401,
272,
298,
18,
5122,
48,
567,
286,
12198,
474,
436,
9590,
4571,
31885,
1901,
7031,
330,
583,
76,
436,
410,
723,
315,
1748,
6867,
641,
15293,
4765,
272,
298,
19,
5122,
10369,
5578,
330,
17236,
641,
7090,
364,
12495,
2112,
7971,
315,
9157,
3766,
83,
5133,
19608,
4765,
272,
298,
20,
5122,
48,
567,
1806,
11199,
362,
461,
31885,
436,
13667,
294,
269,
4937,
590,
2122,
523,
789,
523,
653,
63,
82,
17,
275,
298,
31048,
330,
583,
76,
436,
2984,
322,
836,
323,
9978,
10857,
503,
1806,
14873,
2544,
22701,
2122,
523,
1852,
25879,
8,
489,
2538,
275,
298,
43,
4161,
1849,
2978,
22277,
401,
489,
315,
9157,
3766,
83,
275,
1010,
63,
82,
17,
12,
489,
1083,
275,
603,
68,
63,
82,
17,
12,
489,
12681,
275,
653,
63,
82,
17,
12,
489,
4132,
275,
2196,
1899,
1062,
489,
3762,
275,
2097,
331,
2978,
22277,
401,
298,
6327,
350,
401,
298,
68,
5216,
401,
298,
22784,
3683,
937,
2043,
776,
2043,
27721,
518,
12244,
1010,
63,
82,
17,
275,
469,
272,
298,
17,
5122,
17,
286,
384,
2269,
289,
1119,
26277,
68,
20182,
1146,
312,
1956,
401,
272,
298,
18,
5122,
18,
286,
15203,
22834,
401,
272,
298,
19,
5122,
27590,
10105,
370,
307,
9209,
401,
272,
298,
20,
5122,
17,
15,
18,
307,
681,
286,
262,
17811,
265,
401,
272,
298,
21,
5122,
17,
15,
20,
286
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
646,
747,
199,
646,
984,
199,
646,
1639,
199,
646,
2196,
199,
199,
2355,
1899,
275,
2400,
26,
664,
63,
751,
63,
1238,
1252,
1462,
14,
452,
3430,
2355,
14,
20539,
8,
16,
12,
664,
63,
751,
63,
1238,
1252,
1462,
14,
835,
24821,
199,
9734,
275,
2400,
671,
12,
612,
26,
2196,
14,
20539,
8,
88,
12,
612,
9,
199,
199,
318,
1284,
452,
837,
523,
327,
8496,
428,
78,
15147,
14,
523,
367,
1559,
315,
799,
8233,
14,
1462,
14,
452,
837,
272,
1559,
14,
1807,
342,
523,
327,
8496,
20123,
14,
523,
367,
1559,
315,
664,
63,
751,
63,
1238,
1252,
1462,
14,
452,
837,
272,
1559,
14,
1807,
342,
199,
199,
318,
1852,
1899,
8,
78,
12,
325,
12,
299,
304,
523,
862,
26,
272,
30464,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
362,
8,
2473,
275,
302,
9,
272,
372,
30464,
523,
871,
664,
63,
751,
63,
1238,
1252,
7400,
26,
272,
372,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
751,
8,
2473,
275,
302,
12,
3031,
275,
325,
12,
2505,
275,
299,
9,
2043,
199,
318,
1852,
25879,
8,
2502,
275,
488,
12,
2538,
275,
488,
12,
8889,
275,
488,
12,
315,
9157,
3766,
83,
275,
488,
12,
1083,
275,
488,
12,
12681,
275,
488,
12,
3762,
275,
488,
304,
272,
612,
275,
17615,
8,
17,
12,
1616,
9,
272,
299,
275,
17615,
8,
17,
12,
4114,
9,
272,
286,
275,
17615,
8,
1046,
12,
5238,
9,
272,
308,
275,
799,
8233,
14,
1462,
14,
981,
8,
2502,
275,
4132,
12,
2538,
275,
2538,
12,
315,
9157,
3766,
83,
275,
315,
9157,
3766,
83,
12,
1083,
275,
1083,
12,
1995,
33,
2037,
275,
612,
12,
19986,
1366,
275,
299,
12,
512,
745,
1366,
275,
286,
12,
12681,
275,
12681,
9,
272,
367,
307,
315,
3762,
26,
489,
308,
14,
2969,
14,
525,
8,
84,
9,
272,
308,
14,
2117,
342,
199,
199,
309,
2538,
12,
8889,
12,
315,
9157,
3766,
83,
12,
1083,
12,
1995,
33,
2037,
12,
19986,
1366,
12,
512,
745,
1366,
12,
12681,
12,
4132,
199,
199,
318,
2446,
837,
819,
327,
4155,
20123,
14,
523,
662,
77,
3444,
275,
1852,
1899,
480,
5633,
3444,
401,
298,
5633,
3444,
32,
6799,
14,
957,
401,
298,
5633,
3444,
531,
523,
820,
32374,
275,
1852,
1899,
480,
345,
827,
401,
298,
345,
827,
32,
6799,
14,
957,
401,
298,
345,
827,
531,
523,
377,
89,
1435,
275,
1852,
1899,
480,
369,
1435,
401,
298,
369,
1435,
32,
6799,
14,
957,
401,
298,
369,
1435,
531,
523,
699,
352,
416,
275,
1852,
1899,
480,
20621,
416,
401,
298,
20621,
416,
32,
6799,
14,
957,
401,
298,
20621,
416,
531,
523,
1603,
28601,
696,
275,
1852,
1899,
480,
74,
28601,
696,
401,
298,
74,
28601,
696,
32,
6799,
14,
957,
401,
298,
74,
28601,
696,
531,
523,
481,
581,
8161,
275,
1852,
1899,
480,
22980,
8161,
401,
298,
22980,
8161,
32,
6799,
14,
957,
401,
298,
22980,
8161,
531,
523,
577,
293,
1939,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
11434,
8,
2473,
275,
298,
17264,
1939,
401,
3031,
275,
298,
17264,
1939,
32,
6799,
14,
957,
401,
2505,
275,
298,
17264,
1939,
531,
523,
25378,
651,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
11434,
8,
2473,
275,
298,
8210,
651,
401,
3031,
275,
298,
8210,
651,
32,
6799,
14,
957,
401,
2505,
275,
298,
8210,
651,
531,
12244,
10371,
5680,
523,
1010,
63,
82,
17,
275,
469,
272,
298,
17,
5122,
24,
286,
15203,
2583,
7742,
487,
6867,
286,
12198,
474,
401,
272,
298,
18,
5122,
17,
15,
20,
286,
384,
487,
6867,
9590,
293,
1086,
401,
272,
298,
19,
5122,
18,
6716,
555,
4654,
1748,
6867,
641,
15293,
401,
272,
298,
20,
5122,
17,
15,
19,
286,
384,
9202,
8097,
308,
21922,
401,
272,
298,
21,
5122,
17,
15,
18,
1565,
305,
555,
265,
10105,
401,
272,
298,
22,
5122,
17,
15,
24,
1565,
305,
555,
265,
22602,
529,
401,
272,
298,
23,
5122,
17,
15,
20,
286,
384,
333,
382,
75,
401,
272,
298,
24,
5122,
17,
15,
18,
286,
384,
1443,
265,
3540,
572,
401,
272,
298,
25,
5122,
17,
15,
20,
286,
384,
1325,
5125,
382,
75,
401,
272,
298,
709,
5122,
17,
413,
15,
18,
6716,
555,
4654,
10424,
373,
1132,
23909,
401,
272,
298,
845,
5122,
18,
413,
15,
18,
6716,
555,
4654,
1026,
2106,
1335,
85,
1885,
2,
523,
789,
523,
603,
68,
63,
82,
17,
275,
469,
272,
298,
17,
5122,
35,
12198,
474,
436,
9590,
293,
1086,
1471,
506,
2583,
7742,
487,
6867,
14,
334,
41,
675,
15701,
1033,
581,
424,
4339,
641,
7090,
364,
12495,
680,
401,
272,
298,
18,
5122,
48,
567,
286,
12198,
474,
436,
9590,
4571,
31885,
1901,
7031,
330,
583,
76,
436,
410,
723,
315,
1748,
6867,
641,
15293,
4765,
272,
298,
19,
5122,
10369,
5578,
330,
17236,
641,
7090,
364,
12495,
2112,
7971,
315,
9157,
3766,
83,
5133,
19608,
4765,
272,
298,
20,
5122,
48,
567,
1806,
11199,
362,
461,
31885,
436,
13667,
294,
269,
4937,
590,
2122,
523,
789,
523,
653,
63,
82,
17,
275,
298,
31048,
330,
583,
76,
436,
2984,
322,
836,
323,
9978,
10857,
503,
1806,
14873,
2544,
22701,
2122,
523,
1852,
25879,
8,
489,
2538,
275,
298,
43,
4161,
1849,
2978,
22277,
401,
489,
315,
9157,
3766,
83,
275,
1010,
63,
82,
17,
12,
489,
1083,
275,
603,
68,
63,
82,
17,
12,
489,
12681,
275,
653,
63,
82,
17,
12,
489,
4132,
275,
2196,
1899,
1062,
489,
3762,
275,
2097,
331,
2978,
22277,
401,
298,
6327,
350,
401,
298,
68,
5216,
401,
298,
22784,
3683,
937,
2043,
776,
2043,
27721,
518,
12244,
1010,
63,
82,
17,
275,
469,
272,
298,
17,
5122,
17,
286,
384,
2269,
289,
1119,
26277,
68,
20182,
1146,
312,
1956,
401,
272,
298,
18,
5122,
18,
286,
15203,
22834,
401,
272,
298,
19,
5122,
27590,
10105,
370,
307,
9209,
401,
272,
298,
20,
5122,
17,
15,
18,
307,
681,
286,
262,
17811,
265,
401,
272,
298,
21,
5122,
17,
15,
20,
286,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ael-code/libreant
|
archivant/test/test_update_volume.py
|
3
|
2363
|
from archivant.test.class_template import TestArchivant
from nose.tools import eq_
from copy import deepcopy
class TestArchivantUpdateVolume(TestArchivant):
def test_update_volume_denormalize(self):
volume_metadata = self.generate_volume_metadata()
attachments = self.generate_attachments(2)
attachments[0]['notes'] = 'noteacaso'
id = self.arc.insert_volume(volume_metadata, attachments=attachments)
rawVolume = self.arc._req_raw_volume(id)
normalized = self.arc.normalize_volume(deepcopy(rawVolume))
denom_id, denormalized = self.arc.denormalize_volume(normalized)
del(rawVolume['_source']['_text_' + rawVolume['_source']['_language']])
eq_(denom_id, id)
eq_(denormalized, rawVolume['_source'])
def test_update_volume_add(self):
volume_metadata = {'_language': 'en',
'old_1': 'old_value_1'}
id = self.arc.insert_volume(volume_metadata)
volume_metadata['new_1'] = 'new_value_1'
self.arc.update_volume(id, volume_metadata)
vol_metadata = (self.arc.get_volume(id))['metadata']
eq_(vol_metadata['_language'], 'en')
eq_(vol_metadata['old_1'], 'old_value_1')
eq_(vol_metadata['new_1'], 'new_value_1')
def test_update_volume_change(self):
volume_metadata = {'_language': 'en',
'old_1': 'old_value_1',
'old_2': 'old_value_2'}
id = self.arc.insert_volume(volume_metadata)
volume_metadata['old_2'] = 'new_value_2'
volume_metadata['_language'] = 'it'
self.arc.update_volume(id, volume_metadata)
vol_metadata = (self.arc.get_volume(id))['metadata']
eq_(vol_metadata['_language'], 'it')
eq_(vol_metadata['old_1'], 'old_value_1')
eq_(vol_metadata['old_2'], 'new_value_2')
def test_update_volume_delete(self):
volume_metadata = {'_language': 'en',
'old_1': 'old_value_1',
'old_2': 'old_value_2'}
id = self.arc.insert_volume(volume_metadata)
del(volume_metadata['old_2'])
self.arc.update_volume(id, volume_metadata)
vol_metadata = (self.arc.get_volume(id))['metadata']
eq_(vol_metadata['_language'], 'en')
eq_(vol_metadata['old_1'], 'old_value_1')
|
agpl-3.0
|
[
504,
3819,
1003,
867,
14,
396,
14,
533,
63,
1160,
492,
1379,
8438,
1003,
867,
199,
199,
504,
11354,
14,
2537,
492,
3850,
63,
199,
504,
1331,
492,
14800,
421,
199,
533,
1379,
8438,
1003,
867,
4152,
6464,
8,
774,
8438,
1003,
867,
304,
339,
347,
511,
63,
873,
63,
2405,
63,
848,
1783,
794,
8,
277,
304,
267,
3301,
63,
2343,
275,
291,
14,
4208,
63,
2405,
63,
2343,
342,
267,
18912,
275,
291,
14,
4208,
63,
15855,
8,
18,
9,
267,
18912,
59,
16,
2733,
5983,
418,
275,
283,
4610,
645,
305,
79,
7,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
12,
18912,
29,
15855,
9,
267,
3066,
6464,
275,
291,
14,
9912,
423,
2103,
63,
1773,
63,
2405,
8,
344,
9,
267,
9657,
275,
291,
14,
9912,
14,
7721,
63,
2405,
8,
8293,
8,
1773,
6464,
430,
267,
27878,
63,
344,
12,
477,
12916,
275,
291,
14,
9912,
14,
848,
1783,
794,
63,
2405,
8,
12916,
9,
267,
2150,
8,
1773,
6464,
8680,
1365,
2545,
63,
505,
8650,
435,
3066,
6464,
8680,
1365,
2545,
63,
3671,
12121,
267,
3850,
2531,
23249,
63,
344,
12,
1305,
9,
267,
3850,
2531,
848,
1783,
1759,
12,
3066,
6464,
8680,
1365,
1105,
339,
347,
511,
63,
873,
63,
2405,
63,
525,
8,
277,
304,
267,
3301,
63,
2343,
275,
32136,
3671,
356,
283,
287,
297,
2574,
283,
1753,
63,
17,
356,
283,
1753,
63,
585,
63,
17,
936,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
9,
267,
3301,
63,
2343,
459,
1222,
63,
17,
418,
275,
283,
1222,
63,
585,
63,
17,
7,
267,
291,
14,
9912,
14,
873,
63,
2405,
8,
344,
12,
3301,
63,
2343,
9,
267,
5236,
63,
2343,
275,
334,
277,
14,
9912,
14,
362,
63,
2405,
8,
344,
430,
459,
2343,
418,
267,
3850,
2531,
5650,
63,
2343,
8680,
3671,
995,
283,
287,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
17,
995,
283,
1753,
63,
585,
63,
17,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1222,
63,
17,
995,
283,
1222,
63,
585,
63,
17,
358,
339,
347,
511,
63,
873,
63,
2405,
63,
1461,
8,
277,
304,
267,
3301,
63,
2343,
275,
32136,
3671,
356,
283,
287,
297,
2574,
283,
1753,
63,
17,
356,
283,
1753,
63,
585,
63,
17,
297,
2574,
283,
1753,
63,
18,
356,
283,
1753,
63,
585,
63,
18,
936,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
9,
267,
3301,
63,
2343,
459,
1753,
63,
18,
418,
275,
283,
1222,
63,
585,
63,
18,
7,
267,
3301,
63,
2343,
8680,
3671,
418,
275,
283,
390,
7,
267,
291,
14,
9912,
14,
873,
63,
2405,
8,
344,
12,
3301,
63,
2343,
9,
267,
5236,
63,
2343,
275,
334,
277,
14,
9912,
14,
362,
63,
2405,
8,
344,
430,
459,
2343,
418,
267,
3850,
2531,
5650,
63,
2343,
8680,
3671,
995,
283,
390,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
17,
995,
283,
1753,
63,
585,
63,
17,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
18,
995,
283,
1222,
63,
585,
63,
18,
358,
339,
347,
511,
63,
873,
63,
2405,
63,
1807,
8,
277,
304,
267,
3301,
63,
2343,
275,
32136,
3671,
356,
283,
287,
297,
2574,
283,
1753,
63,
17,
356,
283,
1753,
63,
585,
63,
17,
297,
2574,
283,
1753,
63,
18,
356,
283,
1753,
63,
585,
63,
18,
936,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
9,
267,
2150,
8,
2405,
63,
2343,
459,
1753,
63,
18,
1105,
267,
291,
14,
9912,
14,
873,
63,
2405,
8,
344,
12,
3301,
63,
2343,
9,
267,
5236,
63,
2343,
275,
334,
277,
14,
9912,
14,
362,
63,
2405,
8,
344,
430,
459,
2343,
418,
267,
3850,
2531,
5650,
63,
2343,
8680,
3671,
995,
283,
287,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
17,
995,
283,
1753,
63,
585,
63,
17,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3819,
1003,
867,
14,
396,
14,
533,
63,
1160,
492,
1379,
8438,
1003,
867,
199,
199,
504,
11354,
14,
2537,
492,
3850,
63,
199,
504,
1331,
492,
14800,
421,
199,
533,
1379,
8438,
1003,
867,
4152,
6464,
8,
774,
8438,
1003,
867,
304,
339,
347,
511,
63,
873,
63,
2405,
63,
848,
1783,
794,
8,
277,
304,
267,
3301,
63,
2343,
275,
291,
14,
4208,
63,
2405,
63,
2343,
342,
267,
18912,
275,
291,
14,
4208,
63,
15855,
8,
18,
9,
267,
18912,
59,
16,
2733,
5983,
418,
275,
283,
4610,
645,
305,
79,
7,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
12,
18912,
29,
15855,
9,
267,
3066,
6464,
275,
291,
14,
9912,
423,
2103,
63,
1773,
63,
2405,
8,
344,
9,
267,
9657,
275,
291,
14,
9912,
14,
7721,
63,
2405,
8,
8293,
8,
1773,
6464,
430,
267,
27878,
63,
344,
12,
477,
12916,
275,
291,
14,
9912,
14,
848,
1783,
794,
63,
2405,
8,
12916,
9,
267,
2150,
8,
1773,
6464,
8680,
1365,
2545,
63,
505,
8650,
435,
3066,
6464,
8680,
1365,
2545,
63,
3671,
12121,
267,
3850,
2531,
23249,
63,
344,
12,
1305,
9,
267,
3850,
2531,
848,
1783,
1759,
12,
3066,
6464,
8680,
1365,
1105,
339,
347,
511,
63,
873,
63,
2405,
63,
525,
8,
277,
304,
267,
3301,
63,
2343,
275,
32136,
3671,
356,
283,
287,
297,
2574,
283,
1753,
63,
17,
356,
283,
1753,
63,
585,
63,
17,
936,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
9,
267,
3301,
63,
2343,
459,
1222,
63,
17,
418,
275,
283,
1222,
63,
585,
63,
17,
7,
267,
291,
14,
9912,
14,
873,
63,
2405,
8,
344,
12,
3301,
63,
2343,
9,
267,
5236,
63,
2343,
275,
334,
277,
14,
9912,
14,
362,
63,
2405,
8,
344,
430,
459,
2343,
418,
267,
3850,
2531,
5650,
63,
2343,
8680,
3671,
995,
283,
287,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
17,
995,
283,
1753,
63,
585,
63,
17,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1222,
63,
17,
995,
283,
1222,
63,
585,
63,
17,
358,
339,
347,
511,
63,
873,
63,
2405,
63,
1461,
8,
277,
304,
267,
3301,
63,
2343,
275,
32136,
3671,
356,
283,
287,
297,
2574,
283,
1753,
63,
17,
356,
283,
1753,
63,
585,
63,
17,
297,
2574,
283,
1753,
63,
18,
356,
283,
1753,
63,
585,
63,
18,
936,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
9,
267,
3301,
63,
2343,
459,
1753,
63,
18,
418,
275,
283,
1222,
63,
585,
63,
18,
7,
267,
3301,
63,
2343,
8680,
3671,
418,
275,
283,
390,
7,
267,
291,
14,
9912,
14,
873,
63,
2405,
8,
344,
12,
3301,
63,
2343,
9,
267,
5236,
63,
2343,
275,
334,
277,
14,
9912,
14,
362,
63,
2405,
8,
344,
430,
459,
2343,
418,
267,
3850,
2531,
5650,
63,
2343,
8680,
3671,
995,
283,
390,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
17,
995,
283,
1753,
63,
585,
63,
17,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
18,
995,
283,
1222,
63,
585,
63,
18,
358,
339,
347,
511,
63,
873,
63,
2405,
63,
1807,
8,
277,
304,
267,
3301,
63,
2343,
275,
32136,
3671,
356,
283,
287,
297,
2574,
283,
1753,
63,
17,
356,
283,
1753,
63,
585,
63,
17,
297,
2574,
283,
1753,
63,
18,
356,
283,
1753,
63,
585,
63,
18,
936,
267,
1305,
275,
291,
14,
9912,
14,
3176,
63,
2405,
8,
2405,
63,
2343,
9,
267,
2150,
8,
2405,
63,
2343,
459,
1753,
63,
18,
1105,
267,
291,
14,
9912,
14,
873,
63,
2405,
8,
344,
12,
3301,
63,
2343,
9,
267,
5236,
63,
2343,
275,
334,
277,
14,
9912,
14,
362,
63,
2405,
8,
344,
430,
459,
2343,
418,
267,
3850,
2531,
5650,
63,
2343,
8680,
3671,
995,
283,
287,
358,
267,
3850,
2531,
5650,
63,
2343,
459,
1753,
63,
17,
995,
283,
1753,
63,
585,
63,
17,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
proversity-org/edx-platform
|
openedx/core/djangoapps/lang_pref/middleware.py
|
5
|
3773
|
"""
Middleware for Language Preferences
"""
from django.conf import settings
from django.utils.translation import LANGUAGE_SESSION_KEY
from django.utils.translation.trans_real import parse_accept_lang_header
from openedx.core.djangoapps.lang_pref import COOKIE_DURATION, LANGUAGE_HEADER, LANGUAGE_KEY
from openedx.core.djangoapps.user_api.errors import UserAPIInternalError, UserAPIRequestError
from openedx.core.djangoapps.user_api.preferences.api import (
get_user_preference,
set_user_preference
)
class LanguagePreferenceMiddleware(object):
"""
Middleware for user preferences.
Ensures that, once set, a user's preferences are reflected in the page
whenever they are logged in.
"""
def process_request(self, request):
"""
If a user's UserPreference contains a language preference, use the user's preference.
Save the current language preference cookie as the user's preferred language.
"""
cookie_lang = request.COOKIES.get(settings.LANGUAGE_COOKIE, None)
if cookie_lang:
if request.user.is_authenticated():
set_user_preference(request.user, LANGUAGE_KEY, cookie_lang)
else:
request._anonymous_user_cookie_lang = cookie_lang
accept_header = request.META.get(LANGUAGE_HEADER, None)
if accept_header:
current_langs = parse_accept_lang_header(accept_header)
# Promote the cookie_lang over any language currently in the accept header
current_langs = [(lang, qvalue) for (lang, qvalue) in current_langs if lang != cookie_lang]
current_langs.insert(0, (cookie_lang, 1))
accept_header = ",".join("{};q={}".format(lang, qvalue) for (lang, qvalue) in current_langs)
else:
accept_header = cookie_lang
request.META[LANGUAGE_HEADER] = accept_header
# Allow the new cookie setting to update the language in the user's session
if LANGUAGE_SESSION_KEY in request.session and request.session[LANGUAGE_SESSION_KEY] != cookie_lang:
del request.session[LANGUAGE_SESSION_KEY]
def process_response(self, request, response):
# If the user is logged in, check for their language preference. Also check for real user
# if current user is a masquerading user,
user_pref = None
current_user = None
if hasattr(request, 'user'):
current_user = getattr(request.user, 'real_user', request.user)
if current_user and current_user.is_authenticated():
anonymous_cookie_lang = getattr(request, '_anonymous_user_cookie_lang', None)
if anonymous_cookie_lang:
user_pref = anonymous_cookie_lang
set_user_preference(current_user, LANGUAGE_KEY, anonymous_cookie_lang)
else:
# Get the user's language preference
try:
user_pref = get_user_preference(current_user, LANGUAGE_KEY)
except (UserAPIRequestError, UserAPIInternalError):
# If we can't find the user preferences, then don't modify the cookie
pass
# If set, set the user_pref in the LANGUAGE_COOKIE
if user_pref:
response.set_cookie(
settings.LANGUAGE_COOKIE,
value=user_pref,
domain=settings.SESSION_COOKIE_DOMAIN,
max_age=COOKIE_DURATION,
)
else:
response.delete_cookie(
settings.LANGUAGE_COOKIE,
domain=settings.SESSION_COOKIE_DOMAIN
)
return response
|
agpl-3.0
|
[
624,
199,
6608,
367,
8466,
5543,
4023,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
30508,
2962,
63,
12763,
63,
3078,
199,
504,
1639,
14,
1208,
14,
6893,
14,
1515,
63,
3093,
492,
2198,
63,
5694,
63,
4159,
63,
1291,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
4159,
63,
13829,
492,
5099,
3593,
4332,
63,
36,
15301,
12,
30508,
2962,
63,
7311,
12,
30508,
2962,
63,
3078,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
2550,
492,
2876,
3735,
8405,
547,
12,
2876,
3735,
19261,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
18063,
14,
1246,
492,
334,
272,
664,
63,
751,
63,
14994,
12,
272,
663,
63,
751,
63,
14994,
199,
9,
421,
199,
533,
8466,
25258,
6608,
8,
785,
304,
272,
408,
272,
603,
3551,
367,
922,
23453,
14,
339,
29652,
626,
12,
5403,
663,
12,
282,
922,
1159,
23453,
787,
31948,
315,
314,
2034,
272,
18119,
2985,
787,
10367,
315,
14,
272,
408,
339,
347,
2112,
63,
1069,
8,
277,
12,
1056,
304,
267,
408,
267,
982,
282,
922,
1159,
2876,
25258,
3509,
282,
2637,
16705,
12,
675,
314,
922,
1159,
16705,
14,
267,
11063,
314,
1453,
2637,
16705,
5494,
465,
314,
922,
1159,
14388,
2637,
14,
267,
408,
267,
5494,
63,
4159,
275,
1056,
14,
12189,
2563,
14,
362,
8,
1751,
14,
13947,
63,
13665,
12,
488,
9,
267,
340,
5494,
63,
4159,
26,
288,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
355,
663,
63,
751,
63,
14994,
8,
1069,
14,
751,
12,
30508,
2962,
63,
3078,
12,
5494,
63,
4159,
9,
288,
587,
26,
355,
1056,
423,
12628,
63,
751,
63,
5306,
63,
4159,
275,
5494,
63,
4159,
953,
4729,
63,
1291,
275,
1056,
14,
10614,
14,
362,
8,
13947,
63,
7311,
12,
488,
9,
288,
340,
4729,
63,
1291,
26,
355,
1453,
63,
28182,
275,
2198,
63,
5694,
63,
4159,
63,
1291,
8,
5694,
63,
1291,
9,
355,
327,
27724,
1583,
314,
5494,
63,
4159,
1806,
1263,
2637,
5544,
315,
314,
4729,
1406,
355,
1453,
63,
28182,
275,
3842,
4159,
12,
1894,
585,
9,
367,
334,
4159,
12,
1894,
585,
9,
315,
1453,
63,
28182,
340,
6339,
1137,
5494,
63,
4159,
61,
355,
1453,
63,
28182,
14,
3176,
8,
16,
12,
334,
5306,
63,
4159,
12,
413,
430,
355,
4729,
63,
1291,
275,
19089,
904,
20794,
27,
81,
7622,
1674,
908,
8,
4159,
12,
1894,
585,
9,
367,
334,
4159,
12,
1894,
585,
9,
315,
1453,
63,
28182,
9,
288,
587,
26,
355,
4729,
63,
1291,
275,
5494,
63,
4159,
288,
1056,
14,
10614,
59,
13947,
63,
7311,
61,
275,
4729,
63,
1291,
953,
327,
9812,
314,
892,
5494,
4260,
370,
1678,
314,
2637,
315,
314,
922,
1159,
2351,
288,
340,
30508,
2962,
63,
12763,
63,
3078,
315,
1056,
14,
1730,
436,
1056,
14,
1730,
59,
13947,
63,
12763,
63,
3078,
61,
1137,
5494,
63,
4159,
26,
355,
2150,
1056,
14,
1730,
59,
13947,
63,
12763,
63,
3078,
61,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
327,
982,
314,
922,
365,
10367,
315,
12,
1104,
367,
3932,
2637,
16705,
14,
6121,
1104,
367,
3363,
922,
267,
327,
340,
1453,
922,
365,
282,
28065,
16891,
5384,
922,
12,
267,
922,
63,
13829,
275,
488,
267,
1453,
63,
751,
275,
488,
267,
340,
2688,
8,
1069,
12,
283,
751,
735,
288,
1453,
63,
751,
275,
2519,
8,
1069,
14,
751,
12,
283,
3093,
63,
751,
297,
1056,
14,
751,
9,
398,
340,
1453,
63,
751,
436,
1453,
63,
751,
14,
374,
63,
12177,
837,
288,
16535,
63,
5306,
63,
4159,
275,
2519,
8,
1069,
12,
2513,
12628,
63,
751,
63,
5306,
63,
4159,
297,
488,
9,
288,
340,
16535,
63,
5306,
63,
4159,
26,
355,
922,
63,
13829,
275,
16535,
63,
5306,
63,
4159,
355,
663,
63,
751,
63,
14994,
8,
1818,
63,
751,
12,
30508,
2962,
63,
3078,
12,
16535,
63,
5306,
63,
4159,
9,
288,
587,
26,
355,
327,
2372,
314,
922,
1159,
2637,
16705,
355,
862,
26,
490,
922,
63,
13829,
275,
664,
63,
751,
63,
14994,
8,
1818,
63,
751,
12,
30508,
2962,
63,
3078,
9,
355,
871,
334,
1899,
3735,
19261,
12,
2876,
3735,
8405,
547,
304,
490,
327,
982,
781,
883,
1133,
2342,
314,
922,
23453,
12,
2066,
2793,
1133,
2811,
314,
5494,
490,
986,
953,
327,
982,
663,
12,
663,
314,
922,
63,
13829,
315,
314,
30508,
2962,
63,
13665,
288,
340,
922,
63,
13829,
26,
355,
1177,
14,
409,
63,
5306,
8,
490,
2202,
14,
13947,
63,
13665,
12,
490,
574,
29,
751,
63,
13829,
12,
490,
2881,
29,
1751,
14,
12763,
63,
13665,
63,
7378,
12,
490,
1390,
63,
474,
29,
13665,
63,
36,
15301,
12,
355,
776,
288,
587,
26,
355,
1177,
14,
1807,
63,
5306,
8,
490,
2202,
14,
13947,
63,
13665,
12,
490,
2881,
29,
1751,
14,
12763,
63,
13665,
63,
7378,
355,
776,
398,
372,
1177,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
6608,
367,
8466,
5543,
4023,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
30508,
2962,
63,
12763,
63,
3078,
199,
504,
1639,
14,
1208,
14,
6893,
14,
1515,
63,
3093,
492,
2198,
63,
5694,
63,
4159,
63,
1291,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
4159,
63,
13829,
492,
5099,
3593,
4332,
63,
36,
15301,
12,
30508,
2962,
63,
7311,
12,
30508,
2962,
63,
3078,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
2550,
492,
2876,
3735,
8405,
547,
12,
2876,
3735,
19261,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
18063,
14,
1246,
492,
334,
272,
664,
63,
751,
63,
14994,
12,
272,
663,
63,
751,
63,
14994,
199,
9,
421,
199,
533,
8466,
25258,
6608,
8,
785,
304,
272,
408,
272,
603,
3551,
367,
922,
23453,
14,
339,
29652,
626,
12,
5403,
663,
12,
282,
922,
1159,
23453,
787,
31948,
315,
314,
2034,
272,
18119,
2985,
787,
10367,
315,
14,
272,
408,
339,
347,
2112,
63,
1069,
8,
277,
12,
1056,
304,
267,
408,
267,
982,
282,
922,
1159,
2876,
25258,
3509,
282,
2637,
16705,
12,
675,
314,
922,
1159,
16705,
14,
267,
11063,
314,
1453,
2637,
16705,
5494,
465,
314,
922,
1159,
14388,
2637,
14,
267,
408,
267,
5494,
63,
4159,
275,
1056,
14,
12189,
2563,
14,
362,
8,
1751,
14,
13947,
63,
13665,
12,
488,
9,
267,
340,
5494,
63,
4159,
26,
288,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
355,
663,
63,
751,
63,
14994,
8,
1069,
14,
751,
12,
30508,
2962,
63,
3078,
12,
5494,
63,
4159,
9,
288,
587,
26,
355,
1056,
423,
12628,
63,
751,
63,
5306,
63,
4159,
275,
5494,
63,
4159,
953,
4729,
63,
1291,
275,
1056,
14,
10614,
14,
362,
8,
13947,
63,
7311,
12,
488,
9,
288,
340,
4729,
63,
1291,
26,
355,
1453,
63,
28182,
275,
2198,
63,
5694,
63,
4159,
63,
1291,
8,
5694,
63,
1291,
9,
355,
327,
27724,
1583,
314,
5494,
63,
4159,
1806,
1263,
2637,
5544,
315,
314,
4729,
1406,
355,
1453,
63,
28182,
275,
3842,
4159,
12,
1894,
585,
9,
367,
334,
4159,
12,
1894,
585,
9,
315,
1453,
63,
28182,
340,
6339,
1137,
5494,
63,
4159,
61,
355,
1453,
63,
28182,
14,
3176,
8,
16,
12,
334,
5306,
63,
4159,
12,
413,
430,
355,
4729,
63,
1291,
275,
19089,
904,
20794,
27,
81,
7622,
1674,
908,
8,
4159,
12,
1894,
585,
9,
367,
334,
4159,
12,
1894,
585,
9,
315,
1453,
63,
28182,
9,
288,
587,
26,
355,
4729,
63,
1291,
275,
5494,
63,
4159,
288,
1056,
14,
10614,
59,
13947,
63,
7311,
61,
275,
4729,
63,
1291,
953,
327,
9812,
314,
892,
5494,
4260,
370,
1678,
314,
2637,
315,
314,
922,
1159,
2351,
288,
340,
30508,
2962,
63,
12763,
63,
3078,
315,
1056,
14,
1730,
436,
1056,
14,
1730,
59,
13947,
63,
12763,
63,
3078,
61,
1137,
5494,
63,
4159,
26,
355,
2150,
1056,
14,
1730,
59,
13947,
63,
12763,
63,
3078,
61,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
327,
982,
314,
922,
365,
10367,
315,
12,
1104,
367,
3932,
2637,
16705,
14,
6121,
1104,
367,
3363,
922,
267,
327,
340,
1453,
922,
365,
282,
28065,
16891,
5384,
922,
12,
267,
922,
63,
13829,
275,
488,
267,
1453,
63,
751,
275,
488,
267,
340,
2688,
8,
1069,
12,
283,
751,
735,
288,
1453,
63,
751,
275,
2519,
8,
1069,
14,
751,
12,
283,
3093,
63,
751,
297,
1056,
14,
751,
9,
398,
340,
1453,
63,
751,
436,
1453,
63,
751,
14,
374,
63,
12177,
837,
288,
16535,
63,
5306,
63,
4159,
275,
2519,
8,
1069,
12,
2513,
12628,
63,
751,
63,
5306,
63,
4159,
297,
488,
9,
288,
340,
16535,
63,
5306,
63,
4159,
26,
355,
922,
63,
13829,
275,
16535,
63,
5306,
63,
4159,
355,
663,
63,
751,
63,
14994,
8,
1818,
63,
751,
12,
30508,
2962,
63,
3078,
12,
16535,
63,
5306,
63,
4159,
9,
288,
587,
26,
355,
327,
2372,
314,
922,
1159,
2637,
16705,
355,
862,
26,
490,
922,
63,
13829,
275,
664,
63,
751,
63,
14994,
8,
1818,
63,
751,
12,
30508,
2962,
63,
3078,
9,
355,
871,
334,
1899,
3735,
19261,
12,
2876,
3735,
8405,
547,
304,
490,
327,
982,
781,
883,
1133,
2342,
314,
922,
23453,
12,
2066,
2793,
1133,
2811,
314,
5494,
490,
986,
953,
327,
982,
663,
12,
663,
314,
922,
63,
13829,
315,
314,
30508,
2962,
63,
13665,
288,
340,
922,
63,
13829,
26,
355,
1177,
14,
409,
63,
5306,
8,
490,
2202,
14,
13947,
63,
13665,
12,
490,
574,
29,
751,
63,
13829,
12,
490,
2881,
29,
1751,
14,
12763,
63,
13665,
63,
7378,
12,
490,
1390,
63,
474,
29,
13665,
63,
36,
15301,
12,
355,
776,
288,
587,
26,
355,
1177,
14,
1807,
63,
5306,
8,
490,
2202,
14,
13947,
63,
13665,
12,
490,
2881,
29,
1751,
14,
12763,
63,
13665,
63,
7378,
355,
776,
398,
372,
1177,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
yingcuhk/LeetCode
|
Algorithms/#1 Two Sum/PythonCode.py
|
1
|
1048
|
"""
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
"""
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
orinums = list(nums)
nums.sort()
head = 0
tail = len(nums)-1
while head < tail:
if nums[head] + nums[tail] > target:
tail -= 1
elif nums[head] + nums[tail] < target:
head += 1
else:
break
val1 = nums[head]
val2 = nums[tail]
if val1 == val2:
inds = [k for k, val in enumerate(orinums) if val == val1]
return [inds[0], inds[1]]
else:
return [orinums.index(nums[head]), orinums.index(nums[tail])]
|
mit
|
[
624,
199,
13735,
376,
1625,
402,
9446,
12,
372,
4918,
402,
314,
2877,
5579,
4066,
626,
2985,
1050,
1536,
370,
282,
2488,
1347,
14,
199,
199,
5556,
1443,
5534,
626,
1924,
1324,
3955,
1172,
8840,
1373,
8744,
14,
199,
199,
9846,
26,
199,
13735,
24047,
275,
359,
18,
12,
1520,
12,
4119,
12,
4114,
467,
1347,
275,
1749,
12,
199,
199,
3655,
2651,
24047,
59,
16,
61,
435,
24047,
59,
17,
61,
275,
499,
435,
1520,
275,
1749,
12,
199,
1107,
359,
16,
12,
413,
1055,
199,
624,
421,
199,
533,
9274,
8,
785,
304,
272,
347,
2877,
6959,
8,
277,
12,
24047,
12,
1347,
304,
267,
408,
267,
520,
466,
24047,
26,
3820,
59,
442,
61,
267,
520,
466,
1347,
26,
1109,
267,
520,
4500,
26,
3820,
59,
442,
61,
267,
408,
267,
503,
262,
23816,
275,
769,
8,
16084,
9,
267,
24047,
14,
3191,
342,
267,
4854,
275,
378,
4960,
9483,
275,
822,
8,
16084,
7216,
17,
2728,
1830,
4854,
665,
9483,
26,
288,
340,
24047,
59,
2993,
61,
435,
24047,
59,
1521,
61,
690,
1347,
26,
355,
9483,
4862,
413,
288,
916,
24047,
59,
2993,
61,
435,
24047,
59,
1521,
61,
665,
1347,
26,
355,
4854,
847,
413,
288,
587,
26,
355,
2059,
267,
1139,
17,
275,
24047,
59,
2993,
61,
267,
1139,
18,
275,
24047,
59,
1521,
61,
267,
340,
1139,
17,
508,
1139,
18,
26,
288,
315,
795,
275,
359,
75,
367,
1022,
12,
1139,
315,
3874,
8,
269,
262,
23816,
9,
340,
1139,
508,
1139,
17,
61,
288,
372,
359,
18212,
59,
16,
467,
315,
795,
59,
17,
2677,
267,
587,
26,
288,
372,
359,
269,
262,
23816,
14,
1080,
8,
16084,
59,
2993,
2522,
503,
262,
23816,
14,
1080,
8,
16084,
59,
1521,
12457,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
13735,
376,
1625,
402,
9446,
12,
372,
4918,
402,
314,
2877,
5579,
4066,
626,
2985,
1050,
1536,
370,
282,
2488,
1347,
14,
199,
199,
5556,
1443,
5534,
626,
1924,
1324,
3955,
1172,
8840,
1373,
8744,
14,
199,
199,
9846,
26,
199,
13735,
24047,
275,
359,
18,
12,
1520,
12,
4119,
12,
4114,
467,
1347,
275,
1749,
12,
199,
199,
3655,
2651,
24047,
59,
16,
61,
435,
24047,
59,
17,
61,
275,
499,
435,
1520,
275,
1749,
12,
199,
1107,
359,
16,
12,
413,
1055,
199,
624,
421,
199,
533,
9274,
8,
785,
304,
272,
347,
2877,
6959,
8,
277,
12,
24047,
12,
1347,
304,
267,
408,
267,
520,
466,
24047,
26,
3820,
59,
442,
61,
267,
520,
466,
1347,
26,
1109,
267,
520,
4500,
26,
3820,
59,
442,
61,
267,
408,
267,
503,
262,
23816,
275,
769,
8,
16084,
9,
267,
24047,
14,
3191,
342,
267,
4854,
275,
378,
4960,
9483,
275,
822,
8,
16084,
7216,
17,
2728,
1830,
4854,
665,
9483,
26,
288,
340,
24047,
59,
2993,
61,
435,
24047,
59,
1521,
61,
690,
1347,
26,
355,
9483,
4862,
413,
288,
916,
24047,
59,
2993,
61,
435,
24047,
59,
1521,
61,
665,
1347,
26,
355,
4854,
847,
413,
288,
587,
26,
355,
2059,
267,
1139,
17,
275,
24047,
59,
2993,
61,
267,
1139,
18,
275,
24047,
59,
1521,
61,
267,
340,
1139,
17,
508,
1139,
18,
26,
288,
315,
795,
275,
359,
75,
367,
1022,
12,
1139,
315,
3874,
8,
269,
262,
23816,
9,
340,
1139,
508,
1139,
17,
61,
288,
372,
359,
18212,
59,
16,
467,
315,
795,
59,
17,
2677,
267,
587,
26,
288,
372,
359,
269,
262,
23816,
14,
1080,
8,
16084,
59,
2993,
2522,
503,
262,
23816,
14,
1080,
8,
16084,
59,
1521,
12457,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
BoldingBruggeman/gotm
|
gui.py/xmlplot/data/gotmtext.py
|
1
|
35659
|
import os, StringIO
import numpy
import xmlstore.xmlstore
import xmlplot.common
class LinkedFileVariableStore(xmlplot.common.VariableStore,xmlstore.datatypes.DataFileEx):
# XML store-derived class for storing (cached) metadata of a data file,
# such as coordinate ranges.
# This is implemented as XML store (rather than Python object) because it
# needs to be saved in a descriptive form along with the data files themselves.
class DataFileCache(xmlstore.xmlstore.TypedStore):
@classmethod
def getSchemaInfo(cls):
return xmlstore.xmlstore.schemainfocache[os.path.join(xmlplot.common.getDataRoot(),'schemas/datafilecache')]
def __init__(self,valueroot=None,adddefault = True,schema=None):
if schema is None: schema = os.path.join(xmlplot.common.getDataRoot(),'schemas/datafilecache/0001.schema')
xmlstore.xmlstore.TypedStore.__init__(self,schema,valueroot,adddefault=adddefault)
class LinkedFileVariable(xmlplot.common.Variable):
def __init__(self,store,data,index):
xmlplot.common.Variable.__init__(self,store)
self.store = store
self.data = data
self.index = index
def getName_raw(self):
return self.data[0]
def getLongName(self):
return self.data[1]
def getUnit(self):
return self.data[2]
def getDimensions_raw(self):
return self.store.dimensionorder[:]
def getSlice(self,bounds):
assert False, 'This function must be implemented by inheriting class.'
@classmethod
def createTypedStore(ownclass):
return LinkedFileVariableStore.DataFileCache()
linkedfilename = 'linkedfile_metadata.xml'
rootnodename = 'DataFile'
@classmethod
def createObject(ownclass,datafile,context,infonode,nodename):
finfo = xmlstore.util.findDescendantNode(infonode,['fileinfo'])
assert finfo is not None, 'Node "%s" lacks "fileinfo" attribute.' % node
store = None
type = finfo.getAttribute('type')
if type=='pointsintime':
store = LinkedMatrix(datafile,context,infonode,nodename,type=0,dimensions={'time':{'label':'time','datatype':'datetime','preferredaxis':'x'}},dimensionorder=('time',))
elif type=='profilesintime':
store = LinkedProfilesInTime(datafile,context,infonode,nodename,dimensions={'time':{'label':'time','datatype':'datetime','preferredaxis':'x'},'z':{'label':'depth','unit':'m','preferredaxis':'y'}},dimensionorder=('time','z'))
elif type=='singleprofile':
store = LinkedMatrix(datafile,context,infonode,nodename,type=1)
else:
assert False, 'Linked file has unknown type "%s".' % node.type
return store
# Dictionary linking our data type names to MatPlotLib data types.
# Note that times are stored as numeric values (via matplotlib.dates.date2num)
mpldatatypes = {'datetime':numpy.float64,
'float': numpy.float32,
'float32': numpy.float32,
'float64': numpy.float64}
def __init__(self,datafile,context,infonode,nodename,dimensions={},dimensionorder=(),variables=[],datatype='float',defaultfilename='data'):
xmlplot.common.VariableStore.__init__(self)
xmlstore.datatypes.DataFileEx.__init__(self,datafile,context,infonode,nodename)
# Copy data from supplied dimensions and variables
self.dimensions = {}
for dimname,dimdata in dimensions.iteritems():
self.dimensions[dimname] = xmlplot.common.VariableStore.getDimensionInfo_raw(self,None)
self.dimensions[dimname].update(dimdata)
self.vardata = list(variables)
self.dimensionorder = list(dimensionorder)
# Supplement dimensions and variables with information in
# supplied XML node (if any)
self.filename = defaultfilename
if infonode is not None:
finfo = xmlstore.util.findDescendantNode(infonode,['fileinfo'])
self.filename = infonode.getAttribute('name')
if finfo.hasAttribute('datatype'): datatype = finfo.getAttribute('datatype')
# Get variables
fvars = xmlstore.util.findDescendantNode(finfo,['filevariables'])
if fvars is not None:
for ch in fvars.childNodes:
if ch.nodeType==ch.ELEMENT_NODE and ch.localName=='filevariable':
assert ch.hasAttribute('name'), '"name" attribute of filevariable is missing, label = %s.' % longname
name = ch.getAttribute('name')
unit = ch.getAttribute('unit')
if ch.hasAttribute('label'):
longname = ch.getAttribute('label')
else:
longname = name
self.vardata.append((name,longname,unit))
# Get dimensions
fdims = xmlstore.util.findDescendantNode(finfo,['filedimensions'])
if fdims is not None:
for ch in fdims.childNodes:
if ch.nodeType==ch.ELEMENT_NODE and ch.localName=='filedimension':
dimdata = xmlplot.common.VariableStore.getDimensionInfo_raw(self,None)
assert ch.hasAttribute('name'), '"name" attribute of filedimension is missing, label = "%s".' % ch.getAttribute('label')
id = ch.getAttribute('name')
if ch.hasAttribute('label'):
dimdata['label'] = ch.getAttribute('label')
else:
dimdata['label'] = id
if ch.hasAttribute('unit'): dimdata['unit'] = ch.getAttribute('unit')
if ch.hasAttribute('datatype'): dimdata['datatype'] = ch.getAttribute('datatype')
if ch.hasAttribute('preferredaxis'): dimdata['preferredaxis'] = ch.getAttribute('preferredaxis')
self.dimensions[id] = dimdata
self.dimensionorder.append(id)
self.data = None
self.datatype = datatype
def copy(self):
"""Returns a copy of the LinkedFileVariableStore object.
Currently this copies descriptive metadata, but no actual values.
"""
return LinkedFileVariableStore(None,None,None,None,self.dimensions,self.dimensionorder,self.vardata,self.datatype,defaultfilename=self.filename)
def clear(self,clearfile=True):
"""Clears all data, and by default also clears the original datafile
(if any). The metadata set on the object will be updated accordingly.
"""
self.dataChanged(clearfile=clearfile)
def setDataFile(self,datafile=None,cleardata=True):
"""Attaches a new data file as source of data. This will clear all
metadata set on the object, and by default it will also clear any
parsed data.
"""
xmlstore.datatypes.DataFileEx.setDataFile(self,datafile)
if cleardata: self.data = None
def setData(self,data,clearfile=True):
"""Sets a new data block, automatically updating the metadata set on
the object. By default it will clear the original datafile (if any).
"""
self.data = data
self.dataChanged(clearfile=clearfile)
def dataChanged(self,clearfile=True):
"""Event handler, to be called just after the data has changed.
"""
if clearfile: self.setDataFile(None,cleardata=False)
if self.data is None: return
#print '%s - caching validation result and dimension boundaries.' % self.filename
metadata = self.getMetaData()
for dimname in self.getDimensionNames():
dimnode = metadata['Dimensions'].getChildById('Dimension',id=dimname,create=True)
assert dimnode is not None, 'Failed to create Dimension node for %s.' % dimname
dimrange = self.calculateDimensionRange(dimname)
if dimrange is None: continue
minval,maxval = dimrange
if self.getDimensionInfo_raw(dimname)['datatype']=='datetime':
dimnode['IsTimeDimension'].setValue(True)
dimnode['MinimumTime'].setValue(xmlplot.common.num2date(minval))
dimnode['MaximumTime'].setValue(xmlplot.common.num2date(maxval))
else:
dimnode['IsTimeDimension'].setValue(False)
dimnode['Minimum'].setValue(minval)
dimnode['Maximum'].setValue(maxval)
metadata['Valid'].setValue(True)
def getDimensionNames(self):
"""Returns the names of data dimensions.
"""
return self.dimensionorder[:]
def getDimensionInfo_raw(self,dimname):
"""Returns information on the specified data dimension.
see VariableStore.getDimensionInfo for the type of
information returned.
"""
return self.dimensions[dimname]
def getDimensionRange(self,dimname):
"""Returns the range, i.e., the tuple (minimum, maximum) of the
specified dimension.
"""
if self.data is None and (self.datafile is None or not self.datafile.isValid()): return None
metadata = self.getMetaData()
dimnode = metadata['Dimensions'].getChildById('Dimension',dimname)
if dimnode is None:
try:
self.getData()
except Exception,e:
pass
dimnode = metadata['Dimensions'].getChildById('Dimension',dimname)
assert dimnode is not None, 'Cannot locate node for dimension %s in data file cache.' % dimname
if metadata['Valid'].getValue()==False: return None
#print '%s - using cached bounds for %s.' % (self.filename,dimname)
if dimnode['IsTimeDimension'].getValue():
minval = dimnode['MinimumTime'].getValue()
maxval = dimnode['MaximumTime'].getValue()
else:
minval = dimnode['Minimum'].getValue()
maxval = dimnode['Maximum'].getValue()
if minval is None and maxval is None: return None
return (minval,maxval)
def hasExpensiveValidate(self):
return True
def validate(self,templatenode,callback=None):
if self.data is None and (self.datafile is None or not self.datafile.isValid()): return False
metadata = self.getMetaData()
valid = metadata['Valid'].getValue()
if valid is None:
try:
self.getData(callback=callback)
except Exception,e:
pass
valid = metadata['Valid'].getValue()
assert valid is not None, 'Information on validity of data file %s not in data file cache.' % self.filename
#print '%s - using cached validation result.' % self.filename
return valid
def getVariableNames_raw(self):
"""Returns the names of all variables in the store.
"""
return [data[0] for data in self.vardata]
def getVariableLongNames_raw(self):
"""Returns the long name of the specified variable.
"""
return dict([(data[0],data[1]) for data in self.vardata])
def getVariable_raw(self,varname):
"""Returns the specified variable as LinkedFileVariable object.
"""
for (index,data) in enumerate(self.vardata):
if data[0]==varname:
return self.variableclass(self,data,index)
return None
def loadFromFile(self,path):
datafile = xmlstore.datatypes.DataContainerDirectory.DataFileFile(path)
self.setDataFile(datafile)
datafile.release()
def saveToFile(self,path,callback=None):
"""Saves the current data to file."""
if self.datafile is not None:
self.datafile.saveToFile(path)
else:
f = open(path,'w')
self.writeData(f,callback=callback)
f.close()
def getDataFile(self,callback=None):
if self.datafile is None:
assert self.data is not None, 'getDataFile called with both the data file and the data in memory are not set.'
# Data not present as data file object. Create one in memory on the spot.
target = StringIO.StringIO()
self.writeData(target,callback=callback)
self.datafile = xmlstore.datatypes.DataFileMemory(target.getvalue(),self.filename+'.dat')
target.close()
return self.datafile.addref()
def writeData(self,target,callback=None):
"""Writes the current data to a file-like object."""
assert False, 'writeData must be implemented by derived class.'
def getData(self,callback=None):
if self.data is None and self.datafile is not None:
try:
data = self.parseDataFile(callback)
except Exception,e:
self.getMetaData()['Valid'].setValue(False)
raise
self.setData(data,clearfile=False)
return self.data
def parseDataFile(self,callback=None):
assert False, 'parseDataFile must be implemented by derived class.'
class LinkedMatrix(LinkedFileVariableStore):
class LinkedMatrixVariable(LinkedFileVariableStore.LinkedFileVariable):
def getSlice(self,bounds):
slice = self.Slice(self.getDimensions())
# Get a reference to all data, and stop if the coordinate dimension is empty.
data = self.store.getData()
if data[0].shape[0]==0: return slice
if slice.ndim==1:
slice.coords[0] = data[0][:]
slice.data = data[-1][:,self.index]
slice.generateStaggered()
return slice
def getShape(self):
data = self.store.getData()
if data[0].shape[0]==0: return tuple()
return data[-1][:,self.index].shape
def __init__(self,datafile=None,context=None,infonode=None,nodename=None,type=0,dimensions={},dimensionorder=(),variables=[],defaultfilename='data'):
LinkedFileVariableStore.__init__(self,datafile,context,infonode,nodename,dimensions,dimensionorder,variables,defaultfilename=defaultfilename)
self.variableclass = self.LinkedMatrixVariable
assert len(self.dimensions)<=1, 'Linkedmatrix objects can only be used with 0 or 1 coordinate dimensions, but %i are present.' % len(self.dimensions)
self.type = type
def copy(self):
"""Returns a copy of the LinkedMatrix object.
Currently this copies descriptive metadata, but no actual values.
"""
return LinkedMatrix(dimensions=self.dimensions,dimensionorder=self.dimensionorder,variables=self.vardata,type=self.type,defaultfilename=self.filename)
def clear(self,clearfile=True):
"""Clears all contained data."""
self.data = []
if len(self.dimensions)==1:
dimdatatype = self.dimensions[self.dimensionorder[0]]['datatype']
self.data.append(numpy.empty((0,),self.mpldatatypes[dimdatatype]))
self.data.append(numpy.empty((0,len(self.vardata)),self.mpldatatypes[self.datatype]))
LinkedFileVariableStore.clear(self,clearfile=clearfile)
def calculateDimensionRange(self,dimname):
ind = self.dimensionorder.index(dimname)
dimdata = self.getData()[ind]
if 0 in dimdata.shape: return None
return (dimdata.min(),dimdata.max())
def parseDataFile(self,callback=None):
if self.datafile is None or not self.datafile.isValid(): return None
if self.type==0:
# Unknown number of rows
res = self.loadDataFile_UnknownCount(callback)
elif self.type==1:
# Known number of rows
res = self.loadDataFile_KnownCount(callback)
else:
assert False, 'unknown LinkedMatrix type %i.' % self.type
return res
def loadDataFile_KnownCount(self,callback):
"""Load a data from a DataFile object with the number of lines listed on the first line.
"""
# Get number of dimensions and variables.
dimcount = len(self.dimensions)
varcount = len(self.vardata)
# Get the size of the file (in bytes, may be None if the size is not known)
# This will be used in combination with the position of the file pointer to report progress.
filesize = float(self.datafile.getSize())
# Access the data through some read-only file-like object.
f = self.datafile.getAsReadOnlyFile()
# First line contains number of observations to follow.
line = f.readline()
if line=='':
raise Exception('File is empty. Expected number of observations on first line.')
obscount = int(line)
# Allocate arrays for storage of coordinates and variable values
values = numpy.empty((obscount,varcount),self.mpldatatypes[self.datatype])
if dimcount==1:
# One coordinate dimension present; allocate an array for its values.
dimtype = self.dimensions[self.dimensionorder[0]]['datatype']
dimisdate = (dimtype=='datetime')
if dimisdate:
prevdate = None
dimvalues = numpy.empty((obscount,),self.mpldatatypes[dimtype])
for irow in range(values.shape[0]):
# Read a line (stop if end-of-file was reached)
line = f.readline()
if line=='':
raise Exception('End-of-file reached after line %i, but expecting still %i more rows of observations.' % (irow+1,values.shape[0]-irow))
iline = irow+2 # One-based line index
if dimcount==1:
if dimisdate:
# Read the date + time
try:
refvals = map(int,(line[:4],line[5:7],line[8:10],line[11:13],line[14:16],line[17:19]))
except ValueError:
raise Exception('Line %i does not start with date and time (yyyy-mm-dd hh:mm:ss). Line contents: %s' % (iline,line))
dimvalue = xmlstore.util.dateTimeFromTuple(refvals)
if prevdate is not None and dimvalue<prevdate:
raise Exception('Line %i: observation time %s lies before previous observation time %s. Times should be increasing.' % (iline,xmlstore.util.formatDateTime(dimvalue),xmlstore.util.formatDateTime(prevdate)))
prevdate = dimvalue
dimvalue = xmlplot.common.date2num(dimvalue)
# Read variable values.
data = line[19:].split()
else:
# Split line, convert values to floats and store first as coordinate.
data = map(float,line.split())
dimvalue = data.pop(0)
else:
data = map(float,line.split())
if len(data)<varcount:
raise Exception('Line %i contains only %i observations, where %i are expected (%s).' % (iline,len(data),varcount,', '.join([d[1] for d in self.vardata])))
# Store time and values.
if dimcount==1: dimvalues[irow] = dimvalue
values[irow,:] = data[:varcount]
# Inform caller about progress
if callback is not None and iline%1000==0:
progress = None
if filesize is not None:
try:
progress = float(f.tell())/filesize
except AttributeError:
progress = None
callback(progress,'read %i lines.' % iline)
# Close data file
f.close()
# Succeeded in reading the data: store them internally.
if dimcount==1:
return [dimvalues,values]
else:
return [values]
def loadDataFile_UnknownCount(self,callback):
"""Load a data file with the number of lines not known in advance.
"""
varcount = len(self.vardata)
# Get the size of the file (in bytes, may be None if the size is not known)
# This will be used in combination with the position of the file pointer to report progress.
filesize = float(self.datafile.getSize())
# Access the data through some read-only file-like object.
f = self.datafile.getAsReadOnlyFile()
# Get the data type to use for the dimension
dimdatatype = self.dimensions[self.dimensionorder[0]]['datatype']
# Size of one memory slab (roughly equivalent to 1 MB in memory)
buffersize = 125000/(varcount+1)
times = []
values = []
iline = 0
while True:
# Read a line (stop if end-of-file was reached)
line = f.readline()
if line=='': break
# Calculate position in current memory slab, create new slab if needed.
ipos = iline%buffersize
if ipos==0:
times.append(numpy.empty((buffersize,), self.mpldatatypes[dimdatatype]))
values.append(numpy.empty((buffersize,varcount),self.mpldatatypes[self.datatype]))
# Increment current line number
iline += 1
# Read the date + time
try:
refvals = map(int,(line[:4],line[5:7],line[8:10],line[11:13],line[14:16],line[17:19]))
except ValueError:
raise Exception('Line %i does not start with date and time (yyyy-mm-dd hh:mm:ss). Line contents: %s' % (iline,line))
curdate = xmlstore.util.dateTimeFromTuple(refvals)
times[-1][ipos] = xmlplot.common.date2num(curdate)
# Read values.
data = line[19:].split()
if len(data)<varcount:
raise Exception('Line %i contains only %i observations, where %i are expected (%s).' % (iline,len(data),varcount,', '.join([d[1] for d in self.vardata])))
values[-1][ipos,:] = map(float,data[:varcount])
# Inform caller about progress
if callback is not None and iline%1000==0:
progress = None
if filesize is not None:
try:
progress = float(f.tell())/filesize
except AttributeError:
progress = None
callback(progress,'read %i lines.' % iline)
if len(times)>0:
# Delete unused rows in last memory slab.
times [-1] = times [-1][0:iline%buffersize]
values[-1] = values[-1][0:iline%buffersize,:]
# Concatenate memory slab.
times = numpy.concatenate(times,axis=0)
values = numpy.concatenate(values,axis=0)
else:
# No data read: create empty time and value arrays
times = numpy.zeros((0,),self.mpldatatypes[dimdatatype])
values = numpy.zeros((0,varcount),self.mpldatatypes[self.datatype])
# Close data file
f.close()
# Succeeded in reading the data: store them internally.
return [times,values]
def writeData(self,target,callback=None,missing=''):
"""Writes the current data to a file-like object."""
# Get number of dimensions and variables, and get shortcuts to the data.
dimcount = len(self.dimensions)
data = self.getData()
if dimcount==1:
# One coordinate dimension present; get the data type of that dimension.
dimdata = data[0]
dimtype = self.dimensions.values()[0]['datatype']
dimisdate = (dimtype=='datetime')
if dimisdate: dimdata = xmlplot.common.num2date(dimdata)
varcount = len(self.vardata)
vardata = data[-1]
# Get the mask of the data (numpy.ma.nomask if not set)
mask = numpy.ma.getmask(vardata)
if self.type==1:
# Write first line with number of observations.
target.write('%i\n' % vardata.shape[0])
# Write lines with observations.
for iline in range(vardata.shape[0]):
if dimcount==1:
if dimisdate:
target.write(xmlstore.util.formatDateTime(dimdata[iline],iso=True))
else:
target.write('%.12g' % dimdata[iline])
for ivar in range(varcount):
if mask is not numpy.ma.nomask and mask[iline,ivar]:
target.write('\t%s' % missing)
else:
target.write('\t%.12g' % vardata[iline,ivar])
target.write('\n')
if callback is not None and iline%1000==0:
callback(float(iline)/vardata.shape[0],'wrote %i lines.' % iline)
class LinkedProfilesInTime(LinkedFileVariableStore):
class LinkedProfilesInTimeVariable(LinkedFileVariableStore.LinkedFileVariable):
def getSlice(self,bounds):
varslice = self.Slice(self.getDimensions())
data = self.store.getGriddedData()
if data[0].shape[0]==0: return varslice
timebounds = xmlplot.common.findIndices((bounds[0].start,bounds[0].stop),data[0])
varslice.coords[0] = data[0][timebounds[0]:timebounds[1]+1]
varslice.coords[1] = data[1]
varslice.data = data[2][timebounds[0]:timebounds[1]+1,:,self.index]
varslice.generateStaggered()
return varslice
def getShape(self):
data = self.store.getGriddedData()
if data[0].shape[0]==0: return tuple()
return data[-1][:,:,self.index].shape
def __init__(self,datafile,context,infonode,nodename,dimensions=[],dimensionorder=(),variables=[],defaultfilename='data'):
LinkedFileVariableStore.__init__(self,datafile,context,infonode,nodename,dimensions,dimensionorder,variables,defaultfilename=defaultfilename)
self.variableclass = self.LinkedProfilesInTimeVariable
def copy(self):
"""Returns a copy of the LinkedProfilesInTime object.
Currently this copies descriptive metadata, but no actual values.
"""
return LinkedProfilesInTime(None,None,None,None,dimensions=self.dimensions,dimensionorder=self.dimensionorder,variables=self.vardata,defaultfilename=self.filename)
def setDataFile(self,datafile=None,cleardata=True):
LinkedFileVariableStore.setDataFile(self,datafile,cleardata=cleardata)
if cleardata: self.griddeddata = None
def clear(self,clearfile=True):
self.data = [numpy.empty((0,)),[],[]]
LinkedFileVariableStore.clear(self,clearfile=clearfile)
def dataChanged(self,clearfile=True):
"""Event handler, must be called by external actors when they change the data."""
self.griddeddata = None
LinkedFileVariableStore.dataChanged(self,clearfile=clearfile)
def calculateDimensionRange(self,dimname):
ind = self.dimensionorder.index(dimname)
dimdata = self.getData()[ind]
if len(dimdata)==0: return None
if ind==0:
return (dimdata.min(),dimdata.max())
else:
dimmin,dimmax = None,None
for curdata in dimdata:
if 0 in curdata.shape: continue
curmin,curmax = curdata.min(),curdata.max()
if dimmin is None or curmin<dimmin: dimmin = curmin
if dimmax is None or curmax>dimmax: dimmax = curmax
return (dimmin,dimmax)
def writeData(self,target,callback=None):
"""Writes the current data to a file-like object."""
varcount = len(self.vardata)
data = self.getData()
assert data is not None, 'Cannot write data to file, because data is set to None.'
times,depths,values = data
for itime in range(times.shape[0]):
target.write(xmlstore.util.formatDateTime(xmlplot.common.num2date(times[itime]),iso=True))
curdepths = depths[itime]
curdata = values[itime]
depthcount = len(curdepths)
target.write('\t%i\t1\n' % depthcount)
for idepth in range(depthcount):
target.write('%.9g' % curdepths[idepth])
for ivar in range(varcount):
target.write('\t%.9g' % curdata[idepth,ivar])
target.write('\n')
def getGriddedData(self,callback=None):
data = self.getData()
if self.griddeddata is None:
# Select only non-empty profiles
times,depths,values = [],[],[]
for t,d,v in zip(*data):
if 0 not in d.shape:
times.append(t)
depths.append(d)
values.append(v)
times = numpy.array(times,dtype=data[0].dtype)
varcount = len(self.vardata)
# Find unique depth levels.
uniquedepths = set()
for ds in depths:
for d in ds: uniquedepths.add(d)
# Create depth grid to interpolate on to. Use the observation depths if less than 200,
# otherwise create a equidistant 200-point grid between the minimum and maximum depth.
uniquedepths = list(uniquedepths)
uniquedepths.sort()
if len(uniquedepths)<200:
depthdatatype = self.dimensions[self.dimensionorder[1]]['datatype']
depthgrid = numpy.array(uniquedepths,self.mpldatatypes[depthdatatype])
else:
depthgrid = numpy.linspace(uniquedepths[0],uniquedepths[-1],200)
# Grid observed profiles to depth grid.
griddedvalues = numpy.empty((times.shape[0],depthgrid.shape[0],varcount),self.mpldatatypes[self.datatype])
for it in range(len(times)):
griddedvalues[it,:,:] = xmlplot.common.interp1(depths[it],values[it],depthgrid)
if callback is not None and (it+1)%20==0:
callback(float(it+1)/len(times),'gridded %i profiles.' % (it+1))
# Store time grid, depth grid and observations.
self.griddeddata = (times,depthgrid,griddedvalues)
return self.griddeddata
def parseDataFile(self,callback=None):
if self.datafile is None or not self.datafile.isValid(): return None
varcount = len(self.vardata)
# Get the size of the file (in bytes, may be None if the size is not known)
# This will be used in combination with the position of the file pointer to report progress.
filesize = float(self.datafile.getSize())
# Access the data through some read-only file-like object.
f = self.datafile.getAsReadOnlyFile()
times = []
depths = []
values = []
iline = 0
while True:
# Read a line (stop if end-of-file was reached)
line = f.readline()
if line=='': break
iline += 1
# Read date & time
try:
refvals = map(int,(line[:4],line[5:7],line[8:10],line[11:13],line[14:16],line[17:19]))
except ValueError:
raise Exception('Line %i does not start with date and time (yyyy-mm-dd hh:mm:ss). Line contents: %s' % (iline,line))
curdate = xmlstore.util.dateTimeFromTuple(refvals)
curdate = xmlplot.common.date2num(curdate)
# Get the number of observations and the depth direction.
(depthcount,updown) = map(int, line[19:].split())
# Create arrays that will contains depths and observed values.
depthdatatype = self.dimensions[self.dimensionorder[1]]['datatype']
curdepths = numpy.empty((depthcount,),self.mpldatatypes[depthdatatype])
curvalues = numpy.empty((depthcount,varcount),self.mpldatatypes[self.datatype])
# Depths can be increasing (updown==1) or decreasing (updown!=1)
if updown==1:
depthindices = range(0,depthcount,1)
else:
depthindices = range(depthcount-1,-1,-1)
# Now parse the specified number of observations to create the profiles.
prevdepth = None
for idepthline in depthindices:
if callback is not None and iline%1000==0:
pos = f.tell()
callback(pos/filesize,'processed %i lines.' % iline)
# Read line
line = f.readline()
if line=='':
raise Exception('Premature end-of-file after line %i; expected %i more observations.' % (iline,depthcount-depthindices.index(idepthline)))
iline += 1
# Read values (depth followed by data) and check.
try:
linedata = map(float,line.split())
except ValueError,e:
raise Exception('Line %i: %s' % (iline,e))
if len(linedata)<varcount+1:
raise Exception('Line %i contains only %i value(s), where %i (1 depth and %i observations) are expected.' % (iline,len(linedata),varcount+1,varcount))
if prevdepth is not None:
if linedata[0]==prevdepth:
raise Exception('Found duplicate observation for depth %.4f at line %i.' % (linedata[0],iline))
if updown==1:
if linedata[0]<prevdepth:
raise Exception('Observation depth decreases from %.4f to %.4f at line %i, but the profile depth was set to increase from first to last observation.' % (prevdepth,linedata[0],iline))
elif linedata[0]>prevdepth:
raise Exception('Observation depth increases from %.4f to %.4f at line %i, but the profile depth was set to decrease from first to last observation.' % (prevdepth,linedata[0],iline))
prevdepth = linedata[0]
# Store current observation
curdepths[idepthline] = linedata[0]
curvalues[idepthline,:] = linedata[1:varcount+1]
# Append the profiles for the current time to the list.
times.append(curdate)
depths.append(curdepths)
values.append(curvalues)
# Inform caller about progress.
if callback is not None and iline%1000==0:
pos = f.tell()
callback(pos/filesize,'processed %i lines.' % iline)
# Convert sequence with times to numpy array.
timedatatype = self.dimensions[self.dimensionorder[0]]['datatype']
times = numpy.array(times,self.mpldatatypes[timedatatype])
# Close data file
f.close()
# Succeeded in reading the data: store them internally.
return [times,depths,values]
|
gpl-2.0
|
[
646,
747,
12,
5228,
199,
199,
646,
2680,
199,
199,
646,
2748,
1617,
14,
1652,
1617,
199,
646,
2748,
2798,
14,
2330,
199,
199,
533,
10967,
379,
1173,
2773,
5502,
8,
1652,
2798,
14,
2330,
14,
2773,
5502,
12,
1652,
1617,
14,
14184,
83,
14,
1451,
1173,
920,
304,
339,
327,
4692,
3877,
13,
19588,
1021,
367,
16915,
334,
5245,
9,
3341,
402,
282,
666,
570,
12,
272,
327,
4066,
465,
10021,
12271,
14,
272,
327,
961,
365,
6366,
465,
4692,
3877,
334,
345,
728,
2419,
2018,
909,
9,
2952,
652,
272,
327,
4839,
370,
506,
6290,
315,
282,
30262,
1824,
3180,
543,
314,
666,
1584,
17279,
14,
272,
1021,
3918,
1173,
4437,
8,
1652,
1617,
14,
1652,
1617,
14,
22193,
5502,
304,
267,
768,
3744,
267,
347,
664,
6700,
2354,
8,
1886,
304,
288,
372,
2748,
1617,
14,
1652,
1617,
14,
3629,
815,
1637,
59,
736,
14,
515,
14,
904,
8,
1652,
2798,
14,
2330,
14,
29276,
6405,
1062,
7,
9482,
15,
31423,
1637,
5440,
398,
347,
636,
826,
721,
277,
12,
637,
85,
3478,
357,
29,
403,
12,
525,
885,
275,
715,
12,
3629,
29,
403,
304,
288,
340,
4177,
365,
488,
26,
4177,
275,
747,
14,
515,
14,
904,
8,
1652,
2798,
14,
2330,
14,
29276,
6405,
1062,
7,
9482,
15,
31423,
1637,
15,
4183,
14,
3629,
358,
288,
2748,
1617,
14,
1652,
1617,
14,
22193,
5502,
855,
826,
721,
277,
12,
3629,
12,
637,
85,
3478,
357,
12,
525,
885,
29,
525,
885,
9,
339,
1021,
10967,
379,
1173,
2773,
8,
1652,
2798,
14,
2330,
14,
2773,
304,
398,
347,
636,
826,
721,
277,
12,
1617,
12,
576,
12,
1080,
304,
288,
2748,
2798,
14,
2330,
14,
2773,
855,
826,
721,
277,
12,
1617,
9,
288,
291,
14,
1617,
275,
3877,
288,
291,
14,
576,
275,
666,
288,
291,
14,
1080,
275,
1478,
398,
347,
664,
985,
63,
1773,
8,
277,
304,
288,
372,
291,
14,
576,
59,
16,
61,
398,
347,
664,
9551,
985,
8,
277,
304,
288,
372,
291,
14,
576,
59,
17,
61,
398,
347,
664,
5072,
8,
277,
304,
288,
372,
291,
14,
576,
59,
18,
61,
10631,
347,
664,
23370,
63,
1773,
8,
277,
304,
288,
372,
291,
14,
1617,
14,
7430,
1648,
5873,
398,
347,
664,
14034,
8,
277,
12,
9632,
304,
288,
702,
756,
12,
283,
2765,
805,
1471,
506,
6366,
701,
29927,
1021,
3530,
15567,
768,
3744,
272,
347,
1218,
22193,
5502,
8,
944,
533,
304,
267,
372,
10967,
379,
1173,
2773,
5502,
14,
1451,
1173,
4437,
342,
339,
10632,
1501,
275,
283,
12751,
493,
63,
2343,
14,
1652,
7,
272,
1738,
932,
354,
275,
283,
1451,
1173,
7,
339,
768,
3744,
272,
347,
1218,
1692,
8,
944,
533,
12,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
304,
267,
289,
815,
275,
2748,
1617,
14,
1974,
14,
1623,
9921,
500,
867,
1716,
8,
4904,
29118,
12,
459,
493,
815,
1105,
267,
702,
289,
815,
365,
440,
488,
12,
283,
1716,
2071,
83,
2,
1127,
5618,
298,
493,
815,
2,
2225,
3530,
450,
1031,
267,
3877,
275,
488,
267,
730,
275,
289,
815,
14,
12956,
360,
466,
358,
267,
340,
730,
6803,
3438,
262,
521,
356,
288,
3877,
275,
10967,
379,
6443,
8,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
466,
29,
16,
12,
13320,
3713,
521,
3010,
1302,
5242,
521,
1673,
14184,
5242,
2083,
1673,
17477,
3127,
5242,
88,
28400,
7430,
1648,
7782,
521,
16829,
267,
916,
730,
6803,
11225,
262,
521,
356,
288,
3877,
275,
10967,
379,
30208,
607,
1366,
8,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
13320,
3713,
521,
3010,
1302,
5242,
521,
1673,
14184,
5242,
2083,
1673,
17477,
3127,
5242,
88,
2267,
7,
90,
3010,
1302,
5242,
4631,
1673,
3248,
5242,
77,
1673,
17477,
3127,
5242,
89,
28400,
7430,
1648,
7782,
521,
1673,
90,
1333,
267,
916,
730,
6803,
4780,
2913,
356,
288,
3877,
275,
10967,
379,
6443,
8,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
466,
29,
17,
9,
267,
587,
26,
288,
702,
756,
12,
283,
26748,
570,
965,
5809,
730,
2071,
83,
24217,
450,
1031,
14,
466,
267,
372,
3877,
5493,
327,
11932,
25833,
4154,
666,
730,
1561,
370,
18619,
10711,
4728,
666,
2943,
14,
272,
327,
3390,
626,
5431,
787,
5489,
465,
8950,
1338,
334,
12897,
8027,
14,
9356,
14,
602,
18,
1507,
9,
272,
6118,
1447,
292,
8588,
83,
275,
791,
2083,
356,
4714,
14,
1609,
772,
12,
490,
283,
1609,
356,
257,
2680,
14,
1609,
708,
12,
490,
283,
1609,
708,
356,
2680,
14,
1609,
708,
12,
490,
283,
1609,
772,
356,
2680,
14,
1609,
772,
93,
339,
347,
636,
826,
721,
277,
12,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
13320,
10324,
7430,
1648,
16729,
3669,
6034,
14184,
534,
1609,
297,
885,
1501,
534,
576,
735,
13857,
2748,
2798,
14,
2330,
14,
2773,
5502,
855,
826,
721,
277,
9,
267,
2748,
1617,
14,
14184,
83,
14,
1451,
1173,
920,
855,
826,
721,
277,
12,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
9,
398,
327,
11247,
666,
687,
6841,
7365,
436,
2860,
267,
291,
14,
13320,
275,
1052,
267,
367,
8134,
354,
12,
3572,
576,
315,
7365,
14,
4611,
837,
288,
291,
14,
13320,
59,
3572,
354,
61,
275,
2748,
2798,
14,
2330,
14,
2773,
5502,
14,
362,
17905,
2354,
63,
1773,
8,
277,
12,
403,
9,
288,
291,
14,
13320,
59,
3572,
354,
1055,
873,
8,
3572,
576,
9,
267,
291,
14,
1391,
576,
275,
769,
8,
3669,
9,
267,
291,
14,
7430,
1648,
275,
769,
8,
7430,
1648,
9,
2728,
327,
29083,
968,
7365,
436,
2860,
543,
2556,
315,
267,
327,
6841,
4692,
1031,
334,
692,
1263,
9,
267,
291,
14,
1501,
275,
849,
1501,
267,
340,
10739,
29118,
365,
440,
488,
26,
288,
289,
815,
275,
2748,
1617,
14,
1974,
14,
1623,
9921,
500,
867,
1716,
8,
4904,
29118,
12,
459,
493,
815,
1105,
288,
291,
14,
1501,
275,
10739,
29118,
14,
12956,
360,
354,
358,
288,
340,
289,
815,
14,
1989,
1646,
360,
14184,
735,
16048,
275,
289,
815,
14,
12956,
360,
14184,
358,
953,
327,
2372,
2860,
288,
289,
2936,
275
] |
[
747,
12,
5228,
199,
199,
646,
2680,
199,
199,
646,
2748,
1617,
14,
1652,
1617,
199,
646,
2748,
2798,
14,
2330,
199,
199,
533,
10967,
379,
1173,
2773,
5502,
8,
1652,
2798,
14,
2330,
14,
2773,
5502,
12,
1652,
1617,
14,
14184,
83,
14,
1451,
1173,
920,
304,
339,
327,
4692,
3877,
13,
19588,
1021,
367,
16915,
334,
5245,
9,
3341,
402,
282,
666,
570,
12,
272,
327,
4066,
465,
10021,
12271,
14,
272,
327,
961,
365,
6366,
465,
4692,
3877,
334,
345,
728,
2419,
2018,
909,
9,
2952,
652,
272,
327,
4839,
370,
506,
6290,
315,
282,
30262,
1824,
3180,
543,
314,
666,
1584,
17279,
14,
272,
1021,
3918,
1173,
4437,
8,
1652,
1617,
14,
1652,
1617,
14,
22193,
5502,
304,
267,
768,
3744,
267,
347,
664,
6700,
2354,
8,
1886,
304,
288,
372,
2748,
1617,
14,
1652,
1617,
14,
3629,
815,
1637,
59,
736,
14,
515,
14,
904,
8,
1652,
2798,
14,
2330,
14,
29276,
6405,
1062,
7,
9482,
15,
31423,
1637,
5440,
398,
347,
636,
826,
721,
277,
12,
637,
85,
3478,
357,
29,
403,
12,
525,
885,
275,
715,
12,
3629,
29,
403,
304,
288,
340,
4177,
365,
488,
26,
4177,
275,
747,
14,
515,
14,
904,
8,
1652,
2798,
14,
2330,
14,
29276,
6405,
1062,
7,
9482,
15,
31423,
1637,
15,
4183,
14,
3629,
358,
288,
2748,
1617,
14,
1652,
1617,
14,
22193,
5502,
855,
826,
721,
277,
12,
3629,
12,
637,
85,
3478,
357,
12,
525,
885,
29,
525,
885,
9,
339,
1021,
10967,
379,
1173,
2773,
8,
1652,
2798,
14,
2330,
14,
2773,
304,
398,
347,
636,
826,
721,
277,
12,
1617,
12,
576,
12,
1080,
304,
288,
2748,
2798,
14,
2330,
14,
2773,
855,
826,
721,
277,
12,
1617,
9,
288,
291,
14,
1617,
275,
3877,
288,
291,
14,
576,
275,
666,
288,
291,
14,
1080,
275,
1478,
398,
347,
664,
985,
63,
1773,
8,
277,
304,
288,
372,
291,
14,
576,
59,
16,
61,
398,
347,
664,
9551,
985,
8,
277,
304,
288,
372,
291,
14,
576,
59,
17,
61,
398,
347,
664,
5072,
8,
277,
304,
288,
372,
291,
14,
576,
59,
18,
61,
10631,
347,
664,
23370,
63,
1773,
8,
277,
304,
288,
372,
291,
14,
1617,
14,
7430,
1648,
5873,
398,
347,
664,
14034,
8,
277,
12,
9632,
304,
288,
702,
756,
12,
283,
2765,
805,
1471,
506,
6366,
701,
29927,
1021,
3530,
15567,
768,
3744,
272,
347,
1218,
22193,
5502,
8,
944,
533,
304,
267,
372,
10967,
379,
1173,
2773,
5502,
14,
1451,
1173,
4437,
342,
339,
10632,
1501,
275,
283,
12751,
493,
63,
2343,
14,
1652,
7,
272,
1738,
932,
354,
275,
283,
1451,
1173,
7,
339,
768,
3744,
272,
347,
1218,
1692,
8,
944,
533,
12,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
304,
267,
289,
815,
275,
2748,
1617,
14,
1974,
14,
1623,
9921,
500,
867,
1716,
8,
4904,
29118,
12,
459,
493,
815,
1105,
267,
702,
289,
815,
365,
440,
488,
12,
283,
1716,
2071,
83,
2,
1127,
5618,
298,
493,
815,
2,
2225,
3530,
450,
1031,
267,
3877,
275,
488,
267,
730,
275,
289,
815,
14,
12956,
360,
466,
358,
267,
340,
730,
6803,
3438,
262,
521,
356,
288,
3877,
275,
10967,
379,
6443,
8,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
466,
29,
16,
12,
13320,
3713,
521,
3010,
1302,
5242,
521,
1673,
14184,
5242,
2083,
1673,
17477,
3127,
5242,
88,
28400,
7430,
1648,
7782,
521,
16829,
267,
916,
730,
6803,
11225,
262,
521,
356,
288,
3877,
275,
10967,
379,
30208,
607,
1366,
8,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
13320,
3713,
521,
3010,
1302,
5242,
521,
1673,
14184,
5242,
2083,
1673,
17477,
3127,
5242,
88,
2267,
7,
90,
3010,
1302,
5242,
4631,
1673,
3248,
5242,
77,
1673,
17477,
3127,
5242,
89,
28400,
7430,
1648,
7782,
521,
1673,
90,
1333,
267,
916,
730,
6803,
4780,
2913,
356,
288,
3877,
275,
10967,
379,
6443,
8,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
466,
29,
17,
9,
267,
587,
26,
288,
702,
756,
12,
283,
26748,
570,
965,
5809,
730,
2071,
83,
24217,
450,
1031,
14,
466,
267,
372,
3877,
5493,
327,
11932,
25833,
4154,
666,
730,
1561,
370,
18619,
10711,
4728,
666,
2943,
14,
272,
327,
3390,
626,
5431,
787,
5489,
465,
8950,
1338,
334,
12897,
8027,
14,
9356,
14,
602,
18,
1507,
9,
272,
6118,
1447,
292,
8588,
83,
275,
791,
2083,
356,
4714,
14,
1609,
772,
12,
490,
283,
1609,
356,
257,
2680,
14,
1609,
708,
12,
490,
283,
1609,
708,
356,
2680,
14,
1609,
708,
12,
490,
283,
1609,
772,
356,
2680,
14,
1609,
772,
93,
339,
347,
636,
826,
721,
277,
12,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
12,
13320,
10324,
7430,
1648,
16729,
3669,
6034,
14184,
534,
1609,
297,
885,
1501,
534,
576,
735,
13857,
2748,
2798,
14,
2330,
14,
2773,
5502,
855,
826,
721,
277,
9,
267,
2748,
1617,
14,
14184,
83,
14,
1451,
1173,
920,
855,
826,
721,
277,
12,
31423,
12,
1100,
12,
4904,
29118,
12,
932,
354,
9,
398,
327,
11247,
666,
687,
6841,
7365,
436,
2860,
267,
291,
14,
13320,
275,
1052,
267,
367,
8134,
354,
12,
3572,
576,
315,
7365,
14,
4611,
837,
288,
291,
14,
13320,
59,
3572,
354,
61,
275,
2748,
2798,
14,
2330,
14,
2773,
5502,
14,
362,
17905,
2354,
63,
1773,
8,
277,
12,
403,
9,
288,
291,
14,
13320,
59,
3572,
354,
1055,
873,
8,
3572,
576,
9,
267,
291,
14,
1391,
576,
275,
769,
8,
3669,
9,
267,
291,
14,
7430,
1648,
275,
769,
8,
7430,
1648,
9,
2728,
327,
29083,
968,
7365,
436,
2860,
543,
2556,
315,
267,
327,
6841,
4692,
1031,
334,
692,
1263,
9,
267,
291,
14,
1501,
275,
849,
1501,
267,
340,
10739,
29118,
365,
440,
488,
26,
288,
289,
815,
275,
2748,
1617,
14,
1974,
14,
1623,
9921,
500,
867,
1716,
8,
4904,
29118,
12,
459,
493,
815,
1105,
288,
291,
14,
1501,
275,
10739,
29118,
14,
12956,
360,
354,
358,
288,
340,
289,
815,
14,
1989,
1646,
360,
14184,
735,
16048,
275,
289,
815,
14,
12956,
360,
14184,
358,
953,
327,
2372,
2860,
288,
289,
2936,
275,
0
] |
[
1,
1,
1,
1,
1,
1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|
plugin.video.SportsDevil/lib/utils/github/Repository.py
|
7
|
45033
|
# -*- coding: utf-8 -*-
# Copyright 2012 Vincent Jacques
# vincent@vincent-jacques.net
# This file is part of PyGithub. http://vincent-jacques.net/PyGithub
# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# PyGithub 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 PyGithub. If not, see <http://www.gnu.org/licenses/>.
import urllib
import datetime
import GithubObject
import PaginatedList
import Branch
import IssueEvent
import ContentFile
import Label
import InputGitAuthor
import GitBlob
import Organization
import GitRef
import Issue
import Repository
import PullRequest
import RepositoryKey
import NamedUser
import Milestone
import InputGitTreeElement
import Comparison
import CommitComment
import GitCommit
import Team
import Commit
import GitTree
import Hook
import Tag
import GitTag
import Download
import Permissions
import Event
import Legacy
class Repository(GithubObject.GithubObject):
@property
def clone_url(self):
self._completeIfNotSet(self._clone_url)
return self._NoneIfNotSet(self._clone_url)
@property
def created_at(self):
self._completeIfNotSet(self._created_at)
return self._NoneIfNotSet(self._created_at)
@property
def description(self):
self._completeIfNotSet(self._description)
return self._NoneIfNotSet(self._description)
@property
def fork(self):
self._completeIfNotSet(self._fork)
return self._NoneIfNotSet(self._fork)
@property
def forks(self):
self._completeIfNotSet(self._forks)
return self._NoneIfNotSet(self._forks)
@property
def full_name(self):
self._completeIfNotSet(self._full_name)
return self._NoneIfNotSet(self._full_name)
@property
def git_url(self):
self._completeIfNotSet(self._git_url)
return self._NoneIfNotSet(self._git_url)
@property
def has_downloads(self):
self._completeIfNotSet(self._has_downloads)
return self._NoneIfNotSet(self._has_downloads)
@property
def has_issues(self):
self._completeIfNotSet(self._has_issues)
return self._NoneIfNotSet(self._has_issues)
@property
def has_wiki(self):
self._completeIfNotSet(self._has_wiki)
return self._NoneIfNotSet(self._has_wiki)
@property
def homepage(self):
self._completeIfNotSet(self._homepage)
return self._NoneIfNotSet(self._homepage)
@property
def html_url(self):
self._completeIfNotSet(self._html_url)
return self._NoneIfNotSet(self._html_url)
@property
def id(self):
self._completeIfNotSet(self._id)
return self._NoneIfNotSet(self._id)
@property
def language(self):
self._completeIfNotSet(self._language)
return self._NoneIfNotSet(self._language)
@property
def master_branch(self):
self._completeIfNotSet(self._master_branch)
return self._NoneIfNotSet(self._master_branch)
@property
def name(self):
self._completeIfNotSet(self._name)
return self._NoneIfNotSet(self._name)
@property
def open_issues(self):
self._completeIfNotSet(self._open_issues)
return self._NoneIfNotSet(self._open_issues)
@property
def organization(self):
self._completeIfNotSet(self._organization)
return self._NoneIfNotSet(self._organization)
@property
def owner(self):
self._completeIfNotSet(self._owner)
return self._NoneIfNotSet(self._owner)
@property
def parent(self):
self._completeIfNotSet(self._parent)
return self._NoneIfNotSet(self._parent)
@property
def permissions(self):
self._completeIfNotSet(self._permissions)
return self._NoneIfNotSet(self._permissions)
@property
def private(self):
self._completeIfNotSet(self._private)
return self._NoneIfNotSet(self._private)
@property
def pushed_at(self):
self._completeIfNotSet(self._pushed_at)
return self._NoneIfNotSet(self._pushed_at)
@property
def size(self):
self._completeIfNotSet(self._size)
return self._NoneIfNotSet(self._size)
@property
def source(self):
self._completeIfNotSet(self._source)
return self._NoneIfNotSet(self._source)
@property
def ssh_url(self):
self._completeIfNotSet(self._ssh_url)
return self._NoneIfNotSet(self._ssh_url)
@property
def svn_url(self):
self._completeIfNotSet(self._svn_url)
return self._NoneIfNotSet(self._svn_url)
@property
def updated_at(self):
self._completeIfNotSet(self._updated_at)
return self._NoneIfNotSet(self._updated_at)
@property
def url(self):
self._completeIfNotSet(self._url)
return self._NoneIfNotSet(self._url)
@property
def watchers(self):
self._completeIfNotSet(self._watchers)
return self._NoneIfNotSet(self._watchers)
def add_to_collaborators(self, collaborator):
assert isinstance(collaborator, NamedUser.NamedUser), collaborator
headers, data = self._requester.requestAndCheck(
"PUT",
self.url + "/collaborators/" + collaborator._identity,
None,
None
)
def compare(self, base, head):
assert isinstance(base, (str, unicode)), base
assert isinstance(head, (str, unicode)), head
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/compare/" + base + "..." + head,
None,
None
)
return Comparison.Comparison(self._requester, data, completed=True)
def create_download(self, name, size, description=GithubObject.NotSet, content_type=GithubObject.NotSet):
assert isinstance(name, (str, unicode)), name
assert isinstance(size, (int, long)), size
assert description is GithubObject.NotSet or isinstance(description, (str, unicode)), description
assert content_type is GithubObject.NotSet or isinstance(content_type, (str, unicode)), content_type
post_parameters = {
"name": name,
"size": size,
}
if description is not GithubObject.NotSet:
post_parameters["description"] = description
if content_type is not GithubObject.NotSet:
post_parameters["content_type"] = content_type
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/downloads",
None,
post_parameters
)
return Download.Download(self._requester, data, completed=True)
def create_git_blob(self, content, encoding):
assert isinstance(content, (str, unicode)), content
assert isinstance(encoding, (str, unicode)), encoding
post_parameters = {
"content": content,
"encoding": encoding,
}
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/git/blobs",
None,
post_parameters
)
return GitBlob.GitBlob(self._requester, data, completed=True)
def create_git_commit(self, message, tree, parents, author=GithubObject.NotSet, committer=GithubObject.NotSet):
assert isinstance(message, (str, unicode)), message
assert isinstance(tree, GitTree.GitTree), tree
assert all(isinstance(element, GitCommit.GitCommit) for element in parents), parents
assert author is GithubObject.NotSet or isinstance(author, InputGitAuthor.InputGitAuthor), author
assert committer is GithubObject.NotSet or isinstance(committer, InputGitAuthor.InputGitAuthor), committer
post_parameters = {
"message": message,
"tree": tree._identity,
"parents": [element._identity for element in parents],
}
if author is not GithubObject.NotSet:
post_parameters["author"] = author._identity
if committer is not GithubObject.NotSet:
post_parameters["committer"] = committer._identity
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/git/commits",
None,
post_parameters
)
return GitCommit.GitCommit(self._requester, data, completed=True)
def create_git_ref(self, ref, sha):
assert isinstance(ref, (str, unicode)), ref
assert isinstance(sha, (str, unicode)), sha
post_parameters = {
"ref": ref,
"sha": sha,
}
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/git/refs",
None,
post_parameters
)
return GitRef.GitRef(self._requester, data, completed=True)
def create_git_tag(self, tag, message, object, type, tagger=GithubObject.NotSet):
assert isinstance(tag, (str, unicode)), tag
assert isinstance(message, (str, unicode)), message
assert isinstance(object, (str, unicode)), object
assert isinstance(type, (str, unicode)), type
assert tagger is GithubObject.NotSet or isinstance(tagger, InputGitAuthor.InputGitAuthor), tagger
post_parameters = {
"tag": tag,
"message": message,
"object": object,
"type": type,
}
if tagger is not GithubObject.NotSet:
post_parameters["tagger"] = tagger._identity
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/git/tags",
None,
post_parameters
)
return GitTag.GitTag(self._requester, data, completed=True)
def create_git_tree(self, tree, base_tree=GithubObject.NotSet):
assert all(isinstance(element, InputGitTreeElement.InputGitTreeElement) for element in tree), tree
assert base_tree is GithubObject.NotSet or isinstance(base_tree, GitTree.GitTree), base_tree
post_parameters = {
"tree": [element._identity for element in tree],
}
if base_tree is not GithubObject.NotSet:
post_parameters["base_tree"] = base_tree._identity
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/git/trees",
None,
post_parameters
)
return GitTree.GitTree(self._requester, data, completed=True)
def create_hook(self, name, config, events=GithubObject.NotSet, active=GithubObject.NotSet):
assert isinstance(name, (str, unicode)), name
assert isinstance(config, dict), config
assert events is GithubObject.NotSet or all(isinstance(element, (str, unicode)) for element in events), events
assert active is GithubObject.NotSet or isinstance(active, bool), active
post_parameters = {
"name": name,
"config": config,
}
if events is not GithubObject.NotSet:
post_parameters["events"] = events
if active is not GithubObject.NotSet:
post_parameters["active"] = active
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/hooks",
None,
post_parameters
)
return Hook.Hook(self._requester, data, completed=True)
def create_issue(self, title, body=GithubObject.NotSet, assignee=GithubObject.NotSet, milestone=GithubObject.NotSet, labels=GithubObject.NotSet):
assert isinstance(title, (str, unicode)), title
assert body is GithubObject.NotSet or isinstance(body, (str, unicode)), body
assert assignee is GithubObject.NotSet or isinstance(assignee, NamedUser.NamedUser), assignee
assert milestone is GithubObject.NotSet or isinstance(milestone, Milestone.Milestone), milestone
assert labels is GithubObject.NotSet or all(isinstance(element, Label.Label) for element in labels), labels
post_parameters = {
"title": title,
}
if body is not GithubObject.NotSet:
post_parameters["body"] = body
if assignee is not GithubObject.NotSet:
post_parameters["assignee"] = assignee._identity
if milestone is not GithubObject.NotSet:
post_parameters["milestone"] = milestone._identity
if labels is not GithubObject.NotSet:
post_parameters["labels"] = [element.name for element in labels]
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/issues",
None,
post_parameters
)
return Issue.Issue(self._requester, data, completed=True)
def create_key(self, title, key):
assert isinstance(title, (str, unicode)), title
assert isinstance(key, (str, unicode)), key
post_parameters = {
"title": title,
"key": key,
}
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/keys",
None,
post_parameters
)
return RepositoryKey.RepositoryKey(self._requester, data, completed=True, repoUrl=self._url)
def create_label(self, name, color):
assert isinstance(name, (str, unicode)), name
assert isinstance(color, (str, unicode)), color
post_parameters = {
"name": name,
"color": color,
}
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/labels",
None,
post_parameters
)
return Label.Label(self._requester, data, completed=True)
def create_milestone(self, title, state=GithubObject.NotSet, description=GithubObject.NotSet, due_on=GithubObject.NotSet):
assert isinstance(title, (str, unicode)), title
assert state is GithubObject.NotSet or isinstance(state, (str, unicode)), state
assert description is GithubObject.NotSet or isinstance(description, (str, unicode)), description
assert due_on is GithubObject.NotSet or isinstance(due_on, datetime.date), due_on
post_parameters = {
"title": title,
}
if state is not GithubObject.NotSet:
post_parameters["state"] = state
if description is not GithubObject.NotSet:
post_parameters["description"] = description
if due_on is not GithubObject.NotSet:
post_parameters["due_on"] = due_on.strftime("%Y-%m-%d")
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/milestones",
None,
post_parameters
)
return Milestone.Milestone(self._requester, data, completed=True)
def create_pull(self, *args, **kwds):
if len(args) + len(kwds) == 4:
return self.__create_pull_1(*args, **kwds)
else:
return self.__create_pull_2(*args, **kwds)
def __create_pull_1(self, title, body, base, head):
assert isinstance(title, (str, unicode)), title
assert isinstance(body, (str, unicode)), body
assert isinstance(base, (str, unicode)), base
assert isinstance(head, (str, unicode)), head
return self.__create_pull(title=title, body=body, base=base, head=head)
def __create_pull_2(self, issue, base, head):
assert isinstance(issue, Issue.Issue), issue
assert isinstance(base, (str, unicode)), base
assert isinstance(head, (str, unicode)), head
return self.__create_pull(issue=issue._identity, base=base, head=head)
def __create_pull(self, **kwds):
post_parameters = kwds
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/pulls",
None,
post_parameters
)
return PullRequest.PullRequest(self._requester, data, completed=True)
def delete(self):
headers, data = self._requester.requestAndCheck(
"DELETE",
self.url,
None,
None
)
def edit(self, name, description=GithubObject.NotSet, homepage=GithubObject.NotSet, public=GithubObject.NotSet, has_issues=GithubObject.NotSet, has_wiki=GithubObject.NotSet, has_downloads=GithubObject.NotSet, default_branch=GithubObject.NotSet):
assert isinstance(name, (str, unicode)), name
assert description is GithubObject.NotSet or isinstance(description, (str, unicode)), description
assert homepage is GithubObject.NotSet or isinstance(homepage, (str, unicode)), homepage
assert public is GithubObject.NotSet or isinstance(public, bool), public
assert has_issues is GithubObject.NotSet or isinstance(has_issues, bool), has_issues
assert has_wiki is GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki
assert has_downloads is GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads
assert default_branch is GithubObject.NotSet or isinstance(default_branch, (str, unicode)), default_branch
post_parameters = {
"name": name,
}
if description is not GithubObject.NotSet:
post_parameters["description"] = description
if homepage is not GithubObject.NotSet:
post_parameters["homepage"] = homepage
if public is not GithubObject.NotSet:
post_parameters["public"] = public
if has_issues is not GithubObject.NotSet:
post_parameters["has_issues"] = has_issues
if has_wiki is not GithubObject.NotSet:
post_parameters["has_wiki"] = has_wiki
if has_downloads is not GithubObject.NotSet:
post_parameters["has_downloads"] = has_downloads
if default_branch is not GithubObject.NotSet:
post_parameters["default_branch"] = default_branch
headers, data = self._requester.requestAndCheck(
"PATCH",
self.url,
None,
post_parameters
)
self._useAttributes(data)
def get_archive_link(self, archive_format, ref=GithubObject.NotSet):
assert isinstance(archive_format, (str, unicode)), archive_format
assert ref is GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
url = self.url + "/" + archive_format
if ref is not GithubObject.NotSet:
url += "/" + ref
headers, data = self._requester.requestAndCheck(
"GET",
url,
None,
None
)
return headers["location"]
def get_assignees(self):
return PaginatedList.PaginatedList(
NamedUser.NamedUser,
self._requester,
self.url + "/assignees",
None
)
def get_branch(self, branch):
assert isinstance(branch, (str, unicode)), branch
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/branches/" + branch,
None,
None
)
return Branch.Branch(self._requester, data, completed=True)
def get_branches(self):
return PaginatedList.PaginatedList(
Branch.Branch,
self._requester,
self.url + "/branches",
None
)
def get_collaborators(self):
return PaginatedList.PaginatedList(
NamedUser.NamedUser,
self._requester,
self.url + "/collaborators",
None
)
def get_comment(self, id):
assert isinstance(id, (int, long)), id
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/comments/" + str(id),
None,
None
)
return CommitComment.CommitComment(self._requester, data, completed=True)
def get_comments(self):
return PaginatedList.PaginatedList(
CommitComment.CommitComment,
self._requester,
self.url + "/comments",
None
)
def get_commit(self, sha):
assert isinstance(sha, (str, unicode)), sha
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/commits/" + sha,
None,
None
)
return Commit.Commit(self._requester, data, completed=True)
def get_commits(self, sha=GithubObject.NotSet, path=GithubObject.NotSet):
assert sha is GithubObject.NotSet or isinstance(sha, (str, unicode)), sha
assert path is GithubObject.NotSet or isinstance(path, (str, unicode)), path
url_parameters = dict()
if sha is not GithubObject.NotSet:
url_parameters["sha"] = sha
if path is not GithubObject.NotSet:
url_parameters["path"] = path
return PaginatedList.PaginatedList(
Commit.Commit,
self._requester,
self.url + "/commits",
url_parameters
)
def get_contents(self, path):
assert isinstance(path, (str, unicode)), path
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/contents" + path,
None,
None
)
return ContentFile.ContentFile(self._requester, data, completed=True)
def get_contributors(self):
return PaginatedList.PaginatedList(
NamedUser.NamedUser,
self._requester,
self.url + "/contributors",
None
)
def get_download(self, id):
assert isinstance(id, (int, long)), id
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/downloads/" + str(id),
None,
None
)
return Download.Download(self._requester, data, completed=True)
def get_downloads(self):
return PaginatedList.PaginatedList(
Download.Download,
self._requester,
self.url + "/downloads",
None
)
def get_events(self):
return PaginatedList.PaginatedList(
Event.Event,
self._requester,
self.url + "/events",
None
)
def get_forks(self):
return PaginatedList.PaginatedList(
Repository,
self._requester,
self.url + "/forks",
None
)
def get_git_blob(self, sha):
assert isinstance(sha, (str, unicode)), sha
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/git/blobs/" + sha,
None,
None
)
return GitBlob.GitBlob(self._requester, data, completed=True)
def get_git_commit(self, sha):
assert isinstance(sha, (str, unicode)), sha
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/git/commits/" + sha,
None,
None
)
return GitCommit.GitCommit(self._requester, data, completed=True)
def get_git_ref(self, ref):
prefix = "/git/refs/"
if not self._requester.FIX_REPO_GET_GIT_REF:
prefix = "/git/"
assert isinstance(ref, (str, unicode)), ref
headers, data = self._requester.requestAndCheck(
"GET",
self.url + prefix + ref,
None,
None
)
return GitRef.GitRef(self._requester, data, completed=True)
def get_git_refs(self):
return PaginatedList.PaginatedList(
GitRef.GitRef,
self._requester,
self.url + "/git/refs",
None
)
def get_git_tag(self, sha):
assert isinstance(sha, (str, unicode)), sha
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/git/tags/" + sha,
None,
None
)
return GitTag.GitTag(self._requester, data, completed=True)
def get_git_tree(self, sha, recursive=GithubObject.NotSet):
assert isinstance(sha, (str, unicode)), sha
assert recursive is GithubObject.NotSet or isinstance(recursive, bool), recursive
url_parameters = dict()
if recursive is not GithubObject.NotSet:
url_parameters["recursive"] = recursive
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/git/trees/" + sha,
url_parameters,
None
)
return GitTree.GitTree(self._requester, data, completed=True)
def get_hook(self, id):
assert isinstance(id, (int, long)), id
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/hooks/" + str(id),
None,
None
)
return Hook.Hook(self._requester, data, completed=True)
def get_hooks(self):
return PaginatedList.PaginatedList(
Hook.Hook,
self._requester,
self.url + "/hooks",
None
)
def get_issue(self, number):
assert isinstance(number, (int, long)), number
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/issues/" + str(number),
None,
None
)
return Issue.Issue(self._requester, data, completed=True)
def get_issues(self, milestone=GithubObject.NotSet, state=GithubObject.NotSet, assignee=GithubObject.NotSet, mentioned=GithubObject.NotSet, labels=GithubObject.NotSet, sort=GithubObject.NotSet, direction=GithubObject.NotSet, since=GithubObject.NotSet):
assert milestone is GithubObject.NotSet or milestone == "*" or milestone == "none" or isinstance(milestone, Milestone.Milestone), milestone
assert state is GithubObject.NotSet or isinstance(state, (str, unicode)), state
assert assignee is GithubObject.NotSet or assignee == "*" or assignee == "none" or isinstance(assignee, NamedUser.NamedUser), assignee
assert mentioned is GithubObject.NotSet or isinstance(mentioned, NamedUser.NamedUser), mentioned
assert labels is GithubObject.NotSet or all(isinstance(element, Label.Label) for element in labels), labels
assert sort is GithubObject.NotSet or isinstance(sort, (str, unicode)), sort
assert direction is GithubObject.NotSet or isinstance(direction, (str, unicode)), direction
assert since is GithubObject.NotSet or isinstance(since, datetime.datetime), since
url_parameters = dict()
if milestone is not GithubObject.NotSet:
if isinstance(milestone, str):
url_parameters["milestone"] = milestone
else:
url_parameters["milestone"] = milestone._identity
if state is not GithubObject.NotSet:
url_parameters["state"] = state
if assignee is not GithubObject.NotSet:
if isinstance(assignee, str):
url_parameters["assignee"] = assignee
else:
url_parameters["assignee"] = assignee._identity
if mentioned is not GithubObject.NotSet:
url_parameters["mentioned"] = mentioned._identity
if labels is not GithubObject.NotSet:
url_parameters["labels"] = ",".join(label.name for label in labels)
if sort is not GithubObject.NotSet:
url_parameters["sort"] = sort
if direction is not GithubObject.NotSet:
url_parameters["direction"] = direction
if since is not GithubObject.NotSet:
url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
return PaginatedList.PaginatedList(
Issue.Issue,
self._requester,
self.url + "/issues",
url_parameters
)
def get_issues_event(self, id):
assert isinstance(id, (int, long)), id
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/issues/events/" + str(id),
None,
None
)
return IssueEvent.IssueEvent(self._requester, data, completed=True)
def get_issues_events(self):
return PaginatedList.PaginatedList(
IssueEvent.IssueEvent,
self._requester,
self.url + "/issues/events",
None
)
def get_key(self, id):
assert isinstance(id, (int, long)), id
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/keys/" + str(id),
None,
None
)
return RepositoryKey.RepositoryKey(self._requester, data, completed=True, repoUrl=self._url)
def get_keys(self):
return PaginatedList.PaginatedList(
lambda requester, data, completed: RepositoryKey.RepositoryKey(requester, data, completed, repoUrl=self._url),
self._requester,
self.url + "/keys",
None
)
def get_label(self, name):
assert isinstance(name, (str, unicode)), name
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/labels/" + urllib.quote(name),
None,
None
)
return Label.Label(self._requester, data, completed=True)
def get_labels(self):
return PaginatedList.PaginatedList(
Label.Label,
self._requester,
self.url + "/labels",
None
)
def get_languages(self):
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/languages",
None,
None
)
return data
def get_milestone(self, number):
assert isinstance(number, (int, long)), number
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/milestones/" + str(number),
None,
None
)
return Milestone.Milestone(self._requester, data, completed=True)
def get_milestones(self, state=GithubObject.NotSet, sort=GithubObject.NotSet, direction=GithubObject.NotSet):
assert state is GithubObject.NotSet or isinstance(state, (str, unicode)), state
assert sort is GithubObject.NotSet or isinstance(sort, (str, unicode)), sort
assert direction is GithubObject.NotSet or isinstance(direction, (str, unicode)), direction
url_parameters = dict()
if state is not GithubObject.NotSet:
url_parameters["state"] = state
if sort is not GithubObject.NotSet:
url_parameters["sort"] = sort
if direction is not GithubObject.NotSet:
url_parameters["direction"] = direction
return PaginatedList.PaginatedList(
Milestone.Milestone,
self._requester,
self.url + "/milestones",
url_parameters
)
def get_network_events(self):
return PaginatedList.PaginatedList(
Event.Event,
self._requester,
"/networks/" + self.owner.login + "/" + self.name + "/events",
None
)
def get_pull(self, number):
assert isinstance(number, (int, long)), number
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/pulls/" + str(number),
None,
None
)
return PullRequest.PullRequest(self._requester, data, completed=True)
def get_pulls(self, state=GithubObject.NotSet):
assert state is GithubObject.NotSet or isinstance(state, (str, unicode)), state
url_parameters = dict()
if state is not GithubObject.NotSet:
url_parameters["state"] = state
return PaginatedList.PaginatedList(
PullRequest.PullRequest,
self._requester,
self.url + "/pulls",
url_parameters
)
def get_readme(self):
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/readme",
None,
None
)
return ContentFile.ContentFile(self._requester, data, completed=True)
def get_stargazers(self):
return PaginatedList.PaginatedList(
NamedUser.NamedUser,
self._requester,
self.url + "/stargazers",
None
)
def get_subscribers(self):
return PaginatedList.PaginatedList(
NamedUser.NamedUser,
self._requester,
self.url + "/subscribers",
None
)
def get_tags(self):
return PaginatedList.PaginatedList(
Tag.Tag,
self._requester,
self.url + "/tags",
None
)
def get_teams(self):
return PaginatedList.PaginatedList(
Team.Team,
self._requester,
self.url + "/teams",
None
)
def get_watchers(self):
return PaginatedList.PaginatedList(
NamedUser.NamedUser,
self._requester,
self.url + "/watchers",
None
)
def has_in_assignees(self, assignee):
assert isinstance(assignee, NamedUser.NamedUser), assignee
status, headers, data = self._requester.requestRaw(
"GET",
self.url + "/assignees/" + assignee._identity,
None,
None
)
return status == 204
def has_in_collaborators(self, collaborator):
assert isinstance(collaborator, NamedUser.NamedUser), collaborator
status, headers, data = self._requester.requestRaw(
"GET",
self.url + "/collaborators/" + collaborator._identity,
None,
None
)
return status == 204
def legacy_search_issues(self, state, keyword):
assert state in ["open", "closed"], state
assert isinstance(keyword, (str, unicode)), keyword
headers, data = self._requester.requestAndCheck(
"GET",
"/legacy/issues/search/" + self.owner.login + "/" + self.name + "/" + state + "/" + urllib.quote(keyword),
None,
None
)
return [
Issue.Issue(self._requester, Legacy.convertIssue(element), completed=False)
for element in data["issues"]
]
def merge(self, base, head, commit_message=GithubObject.NotSet):
assert isinstance(base, (str, unicode)), base
assert isinstance(head, (str, unicode)), head
assert commit_message is GithubObject.NotSet or isinstance(commit_message, (str, unicode)), commit_message
post_parameters = {
"base": base,
"head": head,
}
if commit_message is not GithubObject.NotSet:
post_parameters["commit_message"] = commit_message
headers, data = self._requester.requestAndCheck(
"POST",
self.url + "/merges",
None,
post_parameters
)
if data is None:
return None
else:
return Commit.Commit(self._requester, data, completed=True)
def remove_from_collaborators(self, collaborator):
assert isinstance(collaborator, NamedUser.NamedUser), collaborator
headers, data = self._requester.requestAndCheck(
"DELETE",
self.url + "/collaborators/" + collaborator._identity,
None,
None
)
@property
def _identity(self):
return self.owner.login + "/" + self.name
def _initAttributes(self):
self._clone_url = GithubObject.NotSet
self._created_at = GithubObject.NotSet
self._description = GithubObject.NotSet
self._fork = GithubObject.NotSet
self._forks = GithubObject.NotSet
self._full_name = GithubObject.NotSet
self._git_url = GithubObject.NotSet
self._has_downloads = GithubObject.NotSet
self._has_issues = GithubObject.NotSet
self._has_wiki = GithubObject.NotSet
self._homepage = GithubObject.NotSet
self._html_url = GithubObject.NotSet
self._id = GithubObject.NotSet
self._language = GithubObject.NotSet
self._master_branch = GithubObject.NotSet
self._name = GithubObject.NotSet
self._open_issues = GithubObject.NotSet
self._organization = GithubObject.NotSet
self._owner = GithubObject.NotSet
self._parent = GithubObject.NotSet
self._permissions = GithubObject.NotSet
self._private = GithubObject.NotSet
self._pushed_at = GithubObject.NotSet
self._size = GithubObject.NotSet
self._source = GithubObject.NotSet
self._ssh_url = GithubObject.NotSet
self._svn_url = GithubObject.NotSet
self._updated_at = GithubObject.NotSet
self._url = GithubObject.NotSet
self._watchers = GithubObject.NotSet
def _useAttributes(self, attributes):
if "clone_url" in attributes: # pragma no branch
assert attributes["clone_url"] is None or isinstance(attributes["clone_url"], (str, unicode)), attributes["clone_url"]
self._clone_url = attributes["clone_url"]
if "created_at" in attributes: # pragma no branch
assert attributes["created_at"] is None or isinstance(attributes["created_at"], (str, unicode)), attributes["created_at"]
self._created_at = self._parseDatetime(attributes["created_at"])
if "description" in attributes: # pragma no branch
assert attributes["description"] is None or isinstance(attributes["description"], (str, unicode)), attributes["description"]
self._description = attributes["description"]
if "fork" in attributes: # pragma no branch
assert attributes["fork"] is None or isinstance(attributes["fork"], bool), attributes["fork"]
self._fork = attributes["fork"]
if "forks" in attributes: # pragma no branch
assert attributes["forks"] is None or isinstance(attributes["forks"], (int, long)), attributes["forks"]
self._forks = attributes["forks"]
if "full_name" in attributes: # pragma no branch
assert attributes["full_name"] is None or isinstance(attributes["full_name"], (str, unicode)), attributes["full_name"]
self._full_name = attributes["full_name"]
if "git_url" in attributes: # pragma no branch
assert attributes["git_url"] is None or isinstance(attributes["git_url"], (str, unicode)), attributes["git_url"]
self._git_url = attributes["git_url"]
if "has_downloads" in attributes: # pragma no branch
assert attributes["has_downloads"] is None or isinstance(attributes["has_downloads"], bool), attributes["has_downloads"]
self._has_downloads = attributes["has_downloads"]
if "has_issues" in attributes: # pragma no branch
assert attributes["has_issues"] is None or isinstance(attributes["has_issues"], bool), attributes["has_issues"]
self._has_issues = attributes["has_issues"]
if "has_wiki" in attributes: # pragma no branch
assert attributes["has_wiki"] is None or isinstance(attributes["has_wiki"], bool), attributes["has_wiki"]
self._has_wiki = attributes["has_wiki"]
if "homepage" in attributes: # pragma no branch
assert attributes["homepage"] is None or isinstance(attributes["homepage"], (str, unicode)), attributes["homepage"]
self._homepage = attributes["homepage"]
if "html_url" in attributes: # pragma no branch
assert attributes["html_url"] is None or isinstance(attributes["html_url"], (str, unicode)), attributes["html_url"]
self._html_url = attributes["html_url"]
if "id" in attributes: # pragma no branch
assert attributes["id"] is None or isinstance(attributes["id"], (int, long)), attributes["id"]
self._id = attributes["id"]
if "language" in attributes: # pragma no branch
assert attributes["language"] is None or isinstance(attributes["language"], (str, unicode)), attributes["language"]
self._language = attributes["language"]
if "master_branch" in attributes: # pragma no branch
assert attributes["master_branch"] is None or isinstance(attributes["master_branch"], (str, unicode)), attributes["master_branch"]
self._master_branch = attributes["master_branch"]
if "name" in attributes: # pragma no branch
assert attributes["name"] is None or isinstance(attributes["name"], (str, unicode)), attributes["name"]
self._name = attributes["name"]
if "open_issues" in attributes: # pragma no branch
assert attributes["open_issues"] is None or isinstance(attributes["open_issues"], (int, long)), attributes["open_issues"]
self._open_issues = attributes["open_issues"]
if "organization" in attributes: # pragma no branch
assert attributes["organization"] is None or isinstance(attributes["organization"], dict), attributes["organization"]
self._organization = None if attributes["organization"] is None else Organization.Organization(self._requester, attributes["organization"], completed=False)
if "owner" in attributes: # pragma no branch
assert attributes["owner"] is None or isinstance(attributes["owner"], dict), attributes["owner"]
self._owner = None if attributes["owner"] is None else NamedUser.NamedUser(self._requester, attributes["owner"], completed=False)
if "parent" in attributes: # pragma no branch
assert attributes["parent"] is None or isinstance(attributes["parent"], dict), attributes["parent"]
self._parent = None if attributes["parent"] is None else Repository(self._requester, attributes["parent"], completed=False)
if "permissions" in attributes: # pragma no branch
assert attributes["permissions"] is None or isinstance(attributes["permissions"], dict), attributes["permissions"]
self._permissions = None if attributes["permissions"] is None else Permissions.Permissions(self._requester, attributes["permissions"], completed=False)
if "private" in attributes: # pragma no branch
assert attributes["private"] is None or isinstance(attributes["private"], bool), attributes["private"]
self._private = attributes["private"]
if "pushed_at" in attributes: # pragma no branch
assert attributes["pushed_at"] is None or isinstance(attributes["pushed_at"], (str, unicode)), attributes["pushed_at"]
self._pushed_at = self._parseDatetime(attributes["pushed_at"])
if "size" in attributes: # pragma no branch
assert attributes["size"] is None or isinstance(attributes["size"], (int, long)), attributes["size"]
self._size = attributes["size"]
if "source" in attributes: # pragma no branch
assert attributes["source"] is None or isinstance(attributes["source"], dict), attributes["source"]
self._source = None if attributes["source"] is None else Repository(self._requester, attributes["source"], completed=False)
if "ssh_url" in attributes: # pragma no branch
assert attributes["ssh_url"] is None or isinstance(attributes["ssh_url"], (str, unicode)), attributes["ssh_url"]
self._ssh_url = attributes["ssh_url"]
if "svn_url" in attributes: # pragma no branch
assert attributes["svn_url"] is None or isinstance(attributes["svn_url"], (str, unicode)), attributes["svn_url"]
self._svn_url = attributes["svn_url"]
if "updated_at" in attributes: # pragma no branch
assert attributes["updated_at"] is None or isinstance(attributes["updated_at"], (str, unicode)), attributes["updated_at"]
self._updated_at = self._parseDatetime(attributes["updated_at"])
if "url" in attributes: # pragma no branch
assert attributes["url"] is None or isinstance(attributes["url"], (str, unicode)), attributes["url"]
self._url = attributes["url"]
if "watchers" in attributes: # pragma no branch
assert attributes["watchers"] is None or isinstance(attributes["watchers"], (int, long)), attributes["watchers"]
self._watchers = attributes["watchers"]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
6029,
28882,
2946,
1603,
645,
19658,
199,
3,
373,
262,
2946,
32,
11908,
2946,
13,
9299,
19658,
14,
846,
199,
199,
3,
961,
570,
365,
1777,
402,
1611,
14772,
14,
1455,
921,
11908,
2946,
13,
9299,
19658,
14,
846,
15,
2713,
14772,
199,
199,
3,
1611,
14772,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
1611,
14772,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
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,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
3180,
543,
1611,
14772,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
4011,
199,
646,
2197,
199,
199,
646,
598,
4049,
1692,
199,
646,
28006,
23831,
1296,
199,
199,
646,
699,
2965,
199,
646,
13383,
2390,
199,
646,
6646,
1173,
199,
646,
10354,
199,
646,
6924,
14686,
5949,
199,
646,
12579,
16799,
199,
646,
18863,
199,
646,
12579,
2891,
199,
646,
13383,
199,
646,
24426,
199,
646,
27705,
2017,
199,
646,
24426,
1197,
199,
646,
16198,
1899,
199,
646,
603,
18072,
199,
646,
6924,
14686,
3987,
2162,
199,
646,
3599,
5447,
199,
646,
21447,
7488,
199,
646,
12579,
11421,
199,
646,
11682,
199,
646,
21447,
199,
646,
12579,
3987,
199,
646,
24837,
199,
646,
8053,
199,
646,
12579,
1931,
199,
646,
17955,
199,
646,
28260,
199,
646,
6763,
199,
646,
26251,
421,
199,
533,
24426,
8,
20659,
14,
20659,
304,
272,
768,
1829,
272,
347,
7289,
63,
633,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
6311,
63,
633,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
6311,
63,
633,
9,
339,
768,
1829,
272,
347,
2737,
63,
292,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
3966,
63,
292,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
3966,
63,
292,
9,
339,
768,
1829,
272,
347,
1369,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1802,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1802,
9,
339,
768,
1829,
272,
347,
14926,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
11796,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
11796,
9,
339,
768,
1829,
272,
347,
367,
6080,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
509,
6080,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
509,
6080,
9,
339,
768,
1829,
272,
347,
2615,
63,
354,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
2861,
63,
354,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
2861,
63,
354,
9,
339,
768,
1829,
272,
347,
6135,
63,
633,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
3187,
63,
633,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
3187,
63,
633,
9,
339,
768,
1829,
272,
347,
965,
63,
20373,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1989,
63,
20373,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1989,
63,
20373,
9,
339,
768,
1829,
272,
347,
965,
63,
10115,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1989,
63,
10115,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1989,
63,
10115,
9,
339,
768,
1829,
272,
347,
965,
63,
6797,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1989,
63,
6797,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1989,
63,
6797,
9,
339,
768,
1829,
272,
347,
26586,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
25539,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
25539,
9,
339,
768,
1829,
272,
347,
3517,
63,
633,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1360,
63,
633,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1360,
63,
633,
9,
339,
768,
1829,
272,
347,
1305,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
344,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
344,
9,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
3671,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
3671,
9,
339,
768,
1829,
272,
347,
5288,
63,
4694,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
4133,
63,
4694,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
4133,
63,
4694,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
354,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
354,
9,
339,
768,
1829,
272,
347,
1551,
63,
10115,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1490,
63,
10115,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1490,
63,
10115,
9,
339,
768,
1829,
272,
347,
13237,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
9071,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
9071,
9,
339,
768,
1829,
272,
347,
5771,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
4597,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
4597,
9,
339,
768,
1829,
272,
347,
1676,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1708,
9,
267,
372,
291,
423,
403,
3917,
15953
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
6029,
28882,
2946,
1603,
645,
19658,
199,
3,
373,
262,
2946,
32,
11908,
2946,
13,
9299,
19658,
14,
846,
199,
199,
3,
961,
570,
365,
1777,
402,
1611,
14772,
14,
1455,
921,
11908,
2946,
13,
9299,
19658,
14,
846,
15,
2713,
14772,
199,
199,
3,
1611,
14772,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
1611,
14772,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
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,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
3180,
543,
1611,
14772,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
4011,
199,
646,
2197,
199,
199,
646,
598,
4049,
1692,
199,
646,
28006,
23831,
1296,
199,
199,
646,
699,
2965,
199,
646,
13383,
2390,
199,
646,
6646,
1173,
199,
646,
10354,
199,
646,
6924,
14686,
5949,
199,
646,
12579,
16799,
199,
646,
18863,
199,
646,
12579,
2891,
199,
646,
13383,
199,
646,
24426,
199,
646,
27705,
2017,
199,
646,
24426,
1197,
199,
646,
16198,
1899,
199,
646,
603,
18072,
199,
646,
6924,
14686,
3987,
2162,
199,
646,
3599,
5447,
199,
646,
21447,
7488,
199,
646,
12579,
11421,
199,
646,
11682,
199,
646,
21447,
199,
646,
12579,
3987,
199,
646,
24837,
199,
646,
8053,
199,
646,
12579,
1931,
199,
646,
17955,
199,
646,
28260,
199,
646,
6763,
199,
646,
26251,
421,
199,
533,
24426,
8,
20659,
14,
20659,
304,
272,
768,
1829,
272,
347,
7289,
63,
633,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
6311,
63,
633,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
6311,
63,
633,
9,
339,
768,
1829,
272,
347,
2737,
63,
292,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
3966,
63,
292,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
3966,
63,
292,
9,
339,
768,
1829,
272,
347,
1369,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1802,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1802,
9,
339,
768,
1829,
272,
347,
14926,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
11796,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
11796,
9,
339,
768,
1829,
272,
347,
367,
6080,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
509,
6080,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
509,
6080,
9,
339,
768,
1829,
272,
347,
2615,
63,
354,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
2861,
63,
354,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
2861,
63,
354,
9,
339,
768,
1829,
272,
347,
6135,
63,
633,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
3187,
63,
633,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
3187,
63,
633,
9,
339,
768,
1829,
272,
347,
965,
63,
20373,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1989,
63,
20373,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1989,
63,
20373,
9,
339,
768,
1829,
272,
347,
965,
63,
10115,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1989,
63,
10115,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1989,
63,
10115,
9,
339,
768,
1829,
272,
347,
965,
63,
6797,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1989,
63,
6797,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1989,
63,
6797,
9,
339,
768,
1829,
272,
347,
26586,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
25539,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
25539,
9,
339,
768,
1829,
272,
347,
3517,
63,
633,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1360,
63,
633,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1360,
63,
633,
9,
339,
768,
1829,
272,
347,
1305,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
344,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
344,
9,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
3671,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
3671,
9,
339,
768,
1829,
272,
347,
5288,
63,
4694,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
4133,
63,
4694,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
4133,
63,
4694,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
354,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
354,
9,
339,
768,
1829,
272,
347,
1551,
63,
10115,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1490,
63,
10115,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
1490,
63,
10115,
9,
339,
768,
1829,
272,
347,
13237,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
9071,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
9071,
9,
339,
768,
1829,
272,
347,
5771,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
4597,
9,
267,
372,
291,
423,
403,
3917,
15953,
8,
277,
423,
4597,
9,
339,
768,
1829,
272,
347,
1676,
8,
277,
304,
267,
291,
423,
4883,
3917,
15953,
8,
277,
423,
1708,
9,
267,
372,
291,
423,
403,
3917,
15953,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tdtrask/ansible
|
lib/ansible/modules/network/f5/bigip_device_trust.py
|
22
|
10772
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: bigip_device_trust
short_description: Manage the trust relationships between BIG-IPs
description:
- Manage the trust relationships between BIG-IPs. Devices, once peered, cannot
be updated. If updating is needed, the peer must first be removed before it
can be re-added to the trust.
version_added: "2.5"
options:
peer_server:
description:
- The peer address to connect to and trust for synchronizing configuration.
This is typically the management address of the remote device, but may
also be a Self IP.
required: True
peer_hostname:
description:
- The hostname that you want to associate with the device. This value will
be used to easily distinguish this device in BIG-IP configuration. If not
specified, the value of C(peer_server) will be used as a default.
peer_user:
description:
- The API username of the remote peer device that you are trusting. Note
that the CLI user cannot be used unless it too has an API account. If this
value is not specified, then the value of C(user), or the environment
variable C(F5_USER) will be used.
peer_password:
description:
- The password of the API username of the remote peer device that you are
trusting. If this value is not specified, then the value of C(password),
or the environment variable C(F5_PASSWORD) will be used.
type:
description:
- Specifies whether the device you are adding is a Peer or a Subordinate.
The default is C(peer).
- The difference between the two is a matter of mitigating risk of
compromise.
- A subordinate device cannot sign a certificate for another device.
- In the case where the security of an authority device in a trust domain
is compromised, the risk of compromise is minimized for any subordinate
device.
- Designating devices as subordinate devices is recommended for device
groups with a large number of member devices, where the risk of compromise
is high.
choices:
- peer
- subordinate
default: peer
state:
description:
- When C(present), ensures the specified devices are trusted.
- When C(absent), removes the device trusts.
default: present
choices:
- absent
- present
requirements:
- netaddr
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
'''
EXAMPLES = r'''
- name: Add trusts for all peer devices to Active device
bigip_device_trust:
server: lb.mydomain.com
user: admin
password: secret
peer_server: "{{ item.ansible_host }}"
peer_hostname: "{{ item.inventory_hostname }}"
peer_user: "{{ item.bigip_username }}"
peer_password: "{{ item.bigip_password }}"
with_items: hostvars
when: inventory_hostname in groups['master']
delegate_to: localhost
'''
RETURN = r'''
peer_server:
description: The remote IP address of the trusted peer.
returned: changed
type: string
sample: 10.0.2.15
peer_hostname:
description: The remote hostname used to identify the trusted peer.
returned: changed
type: string
sample: test-bigip-02.localhost.localdomain
'''
import re
from ansible.module_utils.basic import AnsibleModule
HAS_DEVEL_IMPORTS = False
try:
# Sideband repository used for dev
from library.module_utils.network.f5.bigip import HAS_F5SDK
from library.module_utils.network.f5.bigip import F5Client
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fqdn_name
from library.module_utils.network.f5.common import f5_argument_spec
try:
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
except ImportError:
HAS_F5SDK = False
HAS_DEVEL_IMPORTS = True
except ImportError:
# Upstream Ansible
from ansible.module_utils.network.f5.bigip import HAS_F5SDK
from ansible.module_utils.network.f5.bigip import F5Client
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fqdn_name
from ansible.module_utils.network.f5.common import f5_argument_spec
try:
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
except ImportError:
HAS_F5SDK = False
try:
import netaddr
HAS_NETADDR = True
except ImportError:
HAS_NETADDR = False
class Parameters(AnsibleF5Parameters):
api_map = {
'deviceName': 'peer_hostname',
'caDevice': 'type',
'device': 'peer_server',
'username': 'peer_user',
'password': 'peer_password'
}
api_attributes = [
'name', 'caDevice', 'device', 'deviceName', 'username', 'password'
]
returnables = [
'peer_server', 'peer_hostname'
]
updatables = []
def to_return(self):
result = {}
try:
for returnable in self.returnables:
result[returnable] = getattr(self, returnable)
result = self._filter_params(result)
return result
except Exception:
return result
@property
def peer_server(self):
if self._values['peer_server'] is None:
return None
try:
result = str(netaddr.IPAddress(self._values['peer_server']))
return result
except netaddr.core.AddrFormatError:
raise F5ModuleError(
"The provided 'peer_server' parameter is not an IP address."
)
@property
def peer_hostname(self):
if self._values['peer_hostname'] is None:
return self.peer_server
regex = re.compile('[^a-zA-Z.-_]')
result = regex.sub('_', self._values['peer_hostname'])
return result
@property
def type(self):
if self._values['type'] == 'peer':
return True
return False
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.have = None
self.want = Parameters(params=self.module.params)
self.changes = Parameters()
def _set_changed_options(self):
changed = {}
for key in Parameters.returnables:
if getattr(self.want, key) is not None:
changed[key] = getattr(self.want, key)
if changed:
self.changes = Parameters(params=changed)
def exec_module(self):
changed = False
result = dict()
state = self.want.state
try:
if state == "present":
changed = self.present()
elif state == "absent":
changed = self.absent()
except iControlUnexpectedHTTPError as e:
raise F5ModuleError(str(e))
changes = self.changes.to_return()
result.update(**changes)
result.update(dict(changed=changed))
return result
def present(self):
if self.exists():
return False
else:
return self.create()
def create(self):
self._set_changed_options()
if self.want.peer_user is None:
self.want.update({'peer_user': self.want.user})
if self.want.peer_password is None:
self.want.update({'peer_password': self.want.password})
if self.want.peer_hostname is None:
self.want.update({'peer_hostname': self.want.server})
if self.module.check_mode:
return True
self.create_on_device()
return True
def absent(self):
if self.exists():
return self.remove()
return False
def remove(self):
if self.module.check_mode:
return True
self.remove_from_device()
if self.exists():
raise F5ModuleError("Failed to remove the trusted peer.")
return True
def exists(self):
result = self.client.api.tm.cm.devices.get_collection()
for device in result:
try:
if device.managementIp == self.want.peer_server:
return True
except AttributeError:
pass
return False
def create_on_device(self):
params = self.want.api_params()
self.client.api.tm.cm.add_to_trust.exec_cmd(
'run',
name='Root',
**params
)
def remove_from_device(self):
result = self.client.api.tm.cm.remove_from_trust.exec_cmd(
'run', deviceName=self.want.peer_hostname, name=self.want.peer_hostname
)
class ArgumentSpec(object):
def __init__(self):
self.supports_check_mode = True
argument_spec = dict(
peer_server=dict(required=True),
peer_hostname=dict(),
peer_user=dict(),
peer_password=dict(no_log=True),
type=dict(
choices=['peer', 'subordinate'],
default='peer'
),
state=dict(
default='present',
choices=['present', 'absent']
)
)
self.argument_spec = {}
self.argument_spec.update(f5_argument_spec)
self.argument_spec.update(argument_spec)
def main():
spec = ArgumentSpec()
module = AnsibleModule(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_F5SDK:
module.fail_json(msg="The python f5-sdk module is required")
if not HAS_NETADDR:
module.fail_json(msg="The python netaddr module is required")
try:
client = F5Client(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
cleanup_tokens(client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
27281,
63,
1782,
63,
15756,
199,
3612,
63,
1802,
26,
14944,
314,
16822,
20045,
3382,
16524,
13,
1772,
83,
199,
1802,
26,
523,
446,
14944,
314,
16822,
20045,
3382,
16524,
13,
1772,
83,
14,
12272,
83,
12,
5403,
299,
1024,
581,
12,
3913,
272,
506,
4588,
14,
982,
12928,
365,
4346,
12,
314,
9104,
1471,
1642,
506,
4829,
2544,
652,
272,
883,
506,
295,
13,
3270,
370,
314,
16822,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
21,
2,
199,
1419,
26,
523,
9104,
63,
1000,
26,
272,
1369,
26,
489,
446,
710,
9104,
2287,
370,
4907,
370,
436,
16822,
367,
15354,
9147,
2897,
14,
267,
961,
365,
13609,
314,
10041,
2287,
402,
314,
3982,
2243,
12,
1325,
1443,
267,
2597,
506,
282,
23820,
3531,
14,
272,
1415,
26,
715,
523,
9104,
63,
4269,
26,
272,
1369,
26,
489,
446,
710,
6246,
626,
1265,
2934,
370,
20133,
543,
314,
2243,
14,
961,
574,
911,
267,
506,
1202,
370,
16174,
22237,
642,
2243,
315,
16524,
13,
1772,
2897,
14,
982,
440,
267,
2013,
12,
314,
574,
402,
445,
8,
7866,
63,
1000,
9,
911,
506,
1202,
465,
282,
849,
14,
523,
9104,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
3261,
3434,
402,
314,
3982,
9104,
2243,
626,
1265,
787,
16822,
316,
14,
3390,
267,
626,
314,
14214,
922,
3913,
506,
1202,
7444,
652,
4634,
965,
376,
3261,
2933,
14,
982,
642,
267,
574,
365,
440,
2013,
12,
2066,
314,
574,
402,
445,
8,
751,
395,
503,
314,
3734,
267,
1750,
445,
8,
38,
21,
63,
3791,
9,
911,
506,
1202,
14,
523,
9104,
63,
2060,
26,
272,
1369,
26,
489,
446,
710,
2505,
402,
314,
3261,
3434,
402,
314,
3982,
9104,
2243,
626,
1265,
787,
267,
16822,
316,
14,
982,
642,
574,
365,
440,
2013,
12,
2066,
314,
574,
402,
445,
8,
2060,
395,
267,
503,
314,
3734,
1750,
445,
8,
38,
21,
63,
9032,
9,
911,
506,
1202,
14,
523,
730,
26,
272,
1369,
26,
489,
446,
11015,
3775,
314,
2243,
1265,
787,
7791,
365,
282,
11379,
281,
503,
282,
4804,
4055,
323,
14,
267,
710,
849,
365,
445,
8,
7866,
680,
489,
446,
710,
8865,
3382,
314,
2877,
365,
282,
17247,
402,
333,
5277,
71,
1958,
22633,
402,
267,
1013,
417,
572,
14,
489,
446,
437,
1007,
4055,
323,
2243,
3913,
2070,
282,
5897,
367,
4573,
2243,
14,
489,
446,
1010,
314,
1930,
2382,
314,
6391,
402,
376,
18330,
2243,
315,
282,
16822,
2881,
267,
365,
1013,
417,
9096,
12,
314,
22633,
402,
1013,
417,
572,
365,
18790,
1759,
367,
1263,
1007,
4055,
323,
267,
2243,
14,
489,
446,
29410,
1958,
7256,
465,
1007,
4055,
323,
7256,
365,
14318,
367,
2243,
267,
4652,
543,
282,
7031,
1329,
402,
3653,
7256,
12,
2382,
314,
22633,
402,
1013,
417,
572,
267,
365,
4721,
14,
272,
3415,
26,
489,
446,
9104,
489,
446,
1007,
4055,
323,
272,
849,
26,
9104,
523,
1174,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
1881,
395,
15620,
314,
2013,
7256,
787,
19427,
14,
489,
446,
3979,
445,
8,
5575,
395,
14185,
314,
2243,
16822,
83,
14,
272,
849,
26,
3451,
272,
3415,
26,
489,
446,
9552,
489,
446,
3451,
199,
7538,
26,
523,
446,
25798,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
2502,
26,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2654,
16822,
83,
367,
1006,
9104,
7256,
370,
23241,
2243,
523,
27281,
63,
1782,
63,
15756,
26,
272,
1654,
26,
11104,
14,
30945,
14,
957,
272,
922,
26,
4628,
272,
2505,
26,
7565,
272,
9104,
63,
1000,
26,
7370,
1242,
14,
4853,
63,
1102,
7820,
272,
9104,
63,
4269,
26,
7370,
1242,
14,
7212,
63,
4269,
7820,
272,
9104,
63,
751,
26,
7370,
1242,
14,
17833,
63,
2473,
7820,
272,
9104,
63,
2060,
26,
7370,
1242,
14,
17833,
63,
2060,
7820,
523,
543,
63,
1744,
26,
21835,
523,
1380,
26,
8200,
63,
4269,
315,
4652,
459,
4133,
418,
523,
13080,
63,
475,
26,
11667,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
7866,
63,
1000,
26,
523,
1369,
26,
710,
3982,
3531,
2287,
402,
314,
19427,
9104,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
16,
14,
18,
14,
1046,
199,
7866,
63,
4269,
26,
523,
1369,
26,
710,
3982,
6246,
1202,
370,
10405,
314,
19427,
9104,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
511,
13,
17833,
13,
996,
14,
5967,
14,
1832,
2261,
199,
2344,
199,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
13533,
63,
1093,
10429,
63,
17576,
51,
275,
756,
199,
199,
893,
26,
272,
327,
428,
2655,
7877,
7611,
1202,
367,
4866,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
7509,
63,
38,
21,
14939,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
481,
21,
3041,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
2622,
38,
21,
5976,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
9058,
63,
4504,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
27281,
63,
1782,
63,
15756,
199,
3612,
63,
1802,
26,
14944,
314,
16822,
20045,
3382,
16524,
13,
1772,
83,
199,
1802,
26,
523,
446,
14944,
314,
16822,
20045,
3382,
16524,
13,
1772,
83,
14,
12272,
83,
12,
5403,
299,
1024,
581,
12,
3913,
272,
506,
4588,
14,
982,
12928,
365,
4346,
12,
314,
9104,
1471,
1642,
506,
4829,
2544,
652,
272,
883,
506,
295,
13,
3270,
370,
314,
16822,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
21,
2,
199,
1419,
26,
523,
9104,
63,
1000,
26,
272,
1369,
26,
489,
446,
710,
9104,
2287,
370,
4907,
370,
436,
16822,
367,
15354,
9147,
2897,
14,
267,
961,
365,
13609,
314,
10041,
2287,
402,
314,
3982,
2243,
12,
1325,
1443,
267,
2597,
506,
282,
23820,
3531,
14,
272,
1415,
26,
715,
523,
9104,
63,
4269,
26,
272,
1369,
26,
489,
446,
710,
6246,
626,
1265,
2934,
370,
20133,
543,
314,
2243,
14,
961,
574,
911,
267,
506,
1202,
370,
16174,
22237,
642,
2243,
315,
16524,
13,
1772,
2897,
14,
982,
440,
267,
2013,
12,
314,
574,
402,
445,
8,
7866,
63,
1000,
9,
911,
506,
1202,
465,
282,
849,
14,
523,
9104,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
3261,
3434,
402,
314,
3982,
9104,
2243,
626,
1265,
787,
16822,
316,
14,
3390,
267,
626,
314,
14214,
922,
3913,
506,
1202,
7444,
652,
4634,
965,
376,
3261,
2933,
14,
982,
642,
267,
574,
365,
440,
2013,
12,
2066,
314,
574,
402,
445,
8,
751,
395,
503,
314,
3734,
267,
1750,
445,
8,
38,
21,
63,
3791,
9,
911,
506,
1202,
14,
523,
9104,
63,
2060,
26,
272,
1369,
26,
489,
446,
710,
2505,
402,
314,
3261,
3434,
402,
314,
3982,
9104,
2243,
626,
1265,
787,
267,
16822,
316,
14,
982,
642,
574,
365,
440,
2013,
12,
2066,
314,
574,
402,
445,
8,
2060,
395,
267,
503,
314,
3734,
1750,
445,
8,
38,
21,
63,
9032,
9,
911,
506,
1202,
14,
523,
730,
26,
272,
1369,
26,
489,
446,
11015,
3775,
314,
2243,
1265,
787,
7791,
365,
282,
11379,
281,
503,
282,
4804,
4055,
323,
14,
267,
710,
849,
365,
445,
8,
7866,
680,
489,
446,
710,
8865,
3382,
314,
2877,
365,
282,
17247,
402,
333,
5277,
71,
1958,
22633,
402,
267,
1013,
417,
572,
14,
489,
446,
437,
1007,
4055,
323,
2243,
3913,
2070,
282,
5897,
367,
4573,
2243,
14,
489,
446,
1010,
314,
1930,
2382,
314,
6391,
402,
376,
18330,
2243,
315,
282,
16822,
2881,
267,
365,
1013,
417,
9096,
12,
314,
22633,
402,
1013,
417,
572,
365,
18790,
1759,
367,
1263,
1007,
4055,
323,
267,
2243,
14,
489,
446,
29410,
1958,
7256,
465,
1007,
4055,
323,
7256,
365,
14318,
367,
2243,
267,
4652,
543,
282,
7031,
1329,
402,
3653,
7256,
12,
2382,
314,
22633,
402,
1013,
417,
572,
267,
365,
4721,
14,
272,
3415,
26,
489,
446,
9104,
489,
446,
1007,
4055,
323,
272,
849,
26,
9104,
523,
1174,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
1881,
395,
15620,
314,
2013,
7256,
787,
19427,
14,
489,
446,
3979,
445,
8,
5575,
395,
14185,
314,
2243,
16822,
83,
14,
272,
849,
26,
3451,
272,
3415,
26,
489,
446,
9552,
489,
446,
3451,
199,
7538,
26,
523,
446,
25798,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
2502,
26,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2654,
16822,
83,
367,
1006,
9104,
7256,
370,
23241,
2243,
523,
27281,
63,
1782,
63,
15756,
26,
272,
1654,
26,
11104,
14,
30945,
14,
957,
272,
922,
26,
4628,
272,
2505,
26,
7565,
272,
9104,
63,
1000,
26,
7370,
1242,
14,
4853,
63,
1102,
7820,
272,
9104,
63,
4269,
26,
7370,
1242,
14,
7212,
63,
4269,
7820,
272,
9104,
63,
751,
26,
7370,
1242,
14,
17833,
63,
2473,
7820,
272,
9104,
63,
2060,
26,
7370,
1242,
14,
17833,
63,
2060,
7820,
523,
543,
63,
1744,
26,
21835,
523,
1380,
26,
8200,
63,
4269,
315,
4652,
459,
4133,
418,
523,
13080,
63,
475,
26,
11667,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
7866,
63,
1000,
26,
523,
1369,
26,
710,
3982,
3531,
2287,
402,
314,
19427,
9104,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
16,
14,
18,
14,
1046,
199,
7866,
63,
4269,
26,
523,
1369,
26,
710,
3982,
6246,
1202,
370,
10405,
314,
19427,
9104,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
511,
13,
17833,
13,
996,
14,
5967,
14,
1832,
2261,
199,
2344,
199,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
13533,
63,
1093,
10429,
63,
17576,
51,
275,
756,
199,
199,
893,
26,
272,
327,
428,
2655,
7877,
7611,
1202,
367,
4866,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
7509,
63,
38,
21,
14939,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
481,
21,
3041,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
2622,
38,
21,
5976,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
9058,
63,
4504,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pointhi/searx
|
tests/unit/engines/test_wolframalpha_api.py
|
1
|
6796
|
# -*- coding: utf-8 -*-
from collections import defaultdict
import mock
from requests import Request
from searx.engines import wolframalpha_api
from searx.testing import SearxTestCase
class TestWolframAlphaAPIEngine(SearxTestCase):
def test_request(self):
query = 'test_query'
dicto = defaultdict(dict)
params = wolframalpha_api.request(query, dicto)
# TODO: test api_key
self.assertIn('url', params)
self.assertIn('https://api.wolframalpha.com/v2/query?', params['url'])
self.assertIn(query, params['url'])
self.assertEqual('https://www.wolframalpha.com/input/?i=test_query', params['headers']['Referer'])
def test_replace_pua_chars(self):
self.assertEqual('i', wolframalpha_api.replace_pua_chars(u'\uf74e'))
def test_response(self):
self.assertRaises(AttributeError, wolframalpha_api.response, None)
self.assertRaises(AttributeError, wolframalpha_api.response, [])
self.assertRaises(AttributeError, wolframalpha_api.response, '')
self.assertRaises(AttributeError, wolframalpha_api.response, '[]')
referer_url = 'referer_url'
request = Request(headers={'Referer': referer_url})
# test failure
xml = '''<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='false' error='false' />
'''
response = mock.Mock(content=xml)
self.assertEqual(wolframalpha_api.response(response), [])
# test basic case
xml = """<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true'
error='false'
numpods='3'
datatypes='Math'
id='queryresult_id'
host='http://www4c.wolframalpha.com'
related='related_url'
version='2.6'>
<pod title='Input'
scanner='Identity'
id='Input'
numsubpods='1'>
<subpod title=''>
<img src='input_img_src.gif'
alt='input_img_alt'
title='input_img_title' />
<plaintext>input_plaintext</plaintext>
</subpod>
</pod>
<pod title='Result'
scanner='Simplification'
id='Result'
numsubpods='1'
primary='true'>
<subpod title=''>
<img src='result_img_src.gif'
alt='result_img_alt'
title='result_img_title' />
<plaintext>result_plaintext</plaintext>
</subpod>
</pod>
<pod title='Manipulatives illustration'
scanner='Arithmetic'
id='Illustration'
numsubpods='1'>
<subpod title=''>
<img src='illustration_img_src.gif'
alt='illustration_img_alt' />
<plaintext>illustration_plaintext</plaintext>
</subpod>
</pod>
</queryresult>
"""
response = mock.Mock(content=xml, request=request)
results = wolframalpha_api.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 2)
self.assertEqual('input_plaintext', results[0]['infobox'])
self.assertEqual(len(results[0]['attributes']), 3)
self.assertEqual('Input', results[0]['attributes'][0]['label'])
self.assertEqual('input_plaintext', results[0]['attributes'][0]['value'])
self.assertEqual('Result', results[0]['attributes'][1]['label'])
self.assertEqual('result_plaintext', results[0]['attributes'][1]['value'])
self.assertEqual('Manipulatives illustration', results[0]['attributes'][2]['label'])
self.assertEqual('illustration_img_src.gif', results[0]['attributes'][2]['image']['src'])
self.assertEqual('illustration_img_alt', results[0]['attributes'][2]['image']['alt'])
self.assertEqual(len(results[0]['urls']), 1)
self.assertEqual(referer_url, results[0]['urls'][0]['url'])
self.assertEqual('Wolfram|Alpha', results[0]['urls'][0]['title'])
self.assertEqual(referer_url, results[1]['url'])
self.assertEqual('Wolfram|Alpha', results[1]['title'])
# test calc
xml = """<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true'
error='false'
numpods='2'
datatypes=''
parsetimedout='false'
id='queryresult_id'
host='http://www5b.wolframalpha.com'
related='related_url'
version='2.6' >
<pod title='Indefinite integral'
scanner='Integral'
id='IndefiniteIntegral'
error='false'
numsubpods='1'
primary='true'>
<subpod title=''>
<img src='integral_image.gif'
alt='integral_img_alt'
title='integral_img_title' />
<plaintext>integral_plaintext</plaintext>
</subpod>
</pod>
<pod title='Plot of the integral'
scanner='Integral'
id='Plot'
error='false'
numsubpods='1'>
<subpod title=''>
<img src='plot.gif'
alt='plot_alt'
title='' />
<plaintext></plaintext>
</subpod>
</pod>
</queryresult>
"""
response = mock.Mock(content=xml, request=request)
results = wolframalpha_api.response(response)
self.assertEqual(type(results), list)
self.assertEqual(len(results), 2)
self.assertEqual('integral_plaintext', results[0]['infobox'])
self.assertEqual(len(results[0]['attributes']), 2)
self.assertEqual('Indefinite integral', results[0]['attributes'][0]['label'])
self.assertEqual('integral_plaintext', results[0]['attributes'][0]['value'])
self.assertEqual('Plot of the integral', results[0]['attributes'][1]['label'])
self.assertEqual('plot.gif', results[0]['attributes'][1]['image']['src'])
self.assertEqual('plot_alt', results[0]['attributes'][1]['image']['alt'])
self.assertEqual(len(results[0]['urls']), 1)
self.assertEqual(referer_url, results[0]['urls'][0]['url'])
self.assertEqual('Wolfram|Alpha', results[0]['urls'][0]['title'])
self.assertEqual(referer_url, results[1]['url'])
self.assertEqual('Wolfram|Alpha', results[1]['title'])
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
5055,
492,
10018,
199,
646,
1683,
199,
504,
4145,
492,
4784,
199,
504,
542,
285,
88,
14,
30378,
492,
336,
79,
276,
345,
2174,
2914,
63,
1246,
199,
504,
542,
285,
88,
14,
4776,
492,
428,
2210,
88,
1746,
421,
199,
533,
1379,
26724,
276,
5975,
16192,
3735,
8524,
8,
1513,
285,
88,
1746,
304,
339,
347,
511,
63,
1069,
8,
277,
304,
267,
1827,
275,
283,
396,
63,
1131,
7,
267,
1211,
79,
275,
10018,
8,
807,
9,
267,
1862,
275,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1069,
8,
1131,
12,
1211,
79,
9,
398,
327,
3254,
26,
511,
2986,
63,
498,
267,
291,
14,
4080,
360,
633,
297,
1862,
9,
267,
291,
14,
4080,
360,
2859,
921,
1246,
14,
28070,
345,
2174,
2914,
14,
957,
15,
86,
18,
15,
1131,
7044,
1862,
459,
633,
1105,
267,
291,
14,
4080,
8,
1131,
12,
1862,
459,
633,
1105,
267,
291,
14,
629,
360,
2859,
921,
1544,
14,
28070,
345,
2174,
2914,
14,
957,
15,
1210,
10197,
73,
29,
396,
63,
1131,
297,
1862,
459,
2139,
2545,
28900,
1105,
339,
347,
511,
63,
1814,
63,
80,
1458,
63,
6574,
8,
277,
304,
267,
291,
14,
629,
360,
73,
297,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1814,
63,
80,
1458,
63,
6574,
8,
85,
1154,
1286,
1342,
69,
1333,
339,
347,
511,
63,
1310,
8,
277,
304,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
488,
9,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
3073,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
4074,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
6730,
10374,
398,
25104,
63,
633,
275,
283,
20996,
63,
633,
7,
267,
1056,
275,
4784,
8,
2139,
3713,
28900,
356,
25104,
63,
633,
1552,
398,
327,
511,
5988,
267,
2748,
275,
28827,
31,
1652,
1015,
534,
17,
14,
16,
7,
2644,
534,
6610,
13,
24,
27716,
30,
267,
665,
1131,
1099,
3182,
534,
3910,
7,
1125,
534,
3910,
7,
7082,
267,
1449,
267,
1177,
275,
1683,
14,
3346,
8,
1317,
29,
1652,
9,
267,
291,
14,
629,
8,
28070,
345,
2174,
2914,
63,
1246,
14,
1310,
8,
1310,
395,
3073,
398,
327,
511,
5678,
1930,
267,
2748,
275,
31501,
1652,
1015,
534,
17,
14,
16,
7,
2644,
534,
6610,
13,
24,
27716,
30,
267,
665,
1131,
1099,
3182,
534,
2052,
7,
288,
1125,
534,
3910,
7,
288,
302,
1220,
364,
83,
534,
19,
7,
288,
16048,
83,
534,
18568,
7,
288,
1305,
534,
1131,
1099,
63,
344,
7,
288,
1591,
534,
1014,
921,
1544,
20,
67,
14,
28070,
345,
2174,
2914,
14,
957,
7,
288,
4048,
534,
2407,
63,
633,
7,
288,
1015,
534,
18,
14,
22,
8423,
288,
665,
12656,
2538,
534,
3205,
7,
326,
19121,
534,
10193,
7,
326,
1305,
534,
3205,
7,
326,
1967,
954,
12656,
83,
534,
17,
8423,
2116,
665,
954,
12656,
2538,
534,
8423,
2432,
665,
4060,
2928,
534,
1210,
63,
4060,
63,
2164,
14,
14513,
7,
2574,
8791,
534,
1210,
63,
4060,
63,
4478,
7,
2574,
2538,
534,
1210,
63,
4060,
63,
1213,
7,
7082,
2432,
665,
17426,
30,
1210,
63,
17426,
1108,
17426,
30,
2116,
3068,
954,
12656,
30,
1467,
3068,
12656,
30,
1467,
665,
12656,
2538,
534,
2889,
7,
326,
19121,
534,
51,
3236,
317,
3477,
7,
326,
1305,
534,
2889,
7,
326,
1967,
954,
12656,
83,
534,
17,
7,
326,
5062,
534,
2052,
8423,
2116,
665,
954,
12656,
2538,
534,
8423,
2432,
665,
4060,
2928,
534,
1099,
63,
4060,
63,
2164,
14,
14513,
7,
2574,
8791,
534,
1099,
63,
4060,
63,
4478,
7,
2574,
2538,
534,
1099,
63,
4060,
63,
1213,
7,
7082,
2432,
665,
17426,
30,
1099,
63,
17426,
1108,
17426,
30,
2116,
3068,
954,
12656,
30,
1467,
3068,
12656,
30,
1467,
665,
12656,
2538,
534,
2395,
711,
348,
10661,
22907,
833,
1754,
7,
326,
19121,
534,
26291,
18764,
7,
326,
1305,
534,
41,
914,
833,
1754,
7,
326,
1967,
954,
12656,
83,
534,
17,
8423,
2116,
665,
954,
12656,
2538,
534,
8423,
2432,
665,
4060,
2928,
534,
778,
833,
1754,
63,
4060,
63,
2164,
14,
14513,
7,
2574,
8791,
534,
778,
833,
1754,
63,
4060,
63,
4478,
7,
7082,
2432,
665,
17426,
30,
778,
833,
1754,
63,
17426,
1108,
17426,
30,
2116,
3068,
954,
12656,
30,
1467,
3068,
12656,
30,
267,
3068,
1131,
1099,
30,
267,
408,
267,
1177,
275,
1683,
14,
3346,
8,
1317,
29,
1652,
12,
1056,
29,
1069,
9,
267,
2058,
275,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
8,
1310,
9,
267,
291,
14,
629,
8,
466,
8,
2604,
395,
769,
9,
267,
291,
14,
629,
8,
552,
8,
2604,
395,
499,
9,
267,
291,
14,
629,
360,
1210,
63,
17426,
297,
2058,
59,
16,
2733,
815,
1977,
1105,
398,
291,
14,
629,
8,
552,
8,
2604,
59,
16,
2733,
2987,
3815,
650,
9,
267,
291,
14,
629,
360,
3205,
297,
2058,
59,
16,
2733,
2987,
3488,
16,
2733,
1302,
1105,
267,
291,
14,
629,
360,
1210,
63,
17426,
297,
2058,
59,
16,
2733,
2987,
3488,
16,
2733,
585,
1105,
267,
291,
14,
629,
360,
2889,
297,
2058,
59,
16,
2733,
2987,
3488,
17,
2733,
1302,
1105,
267,
291,
14,
629,
360,
1099,
63,
17426,
297,
2058,
59,
16,
2733,
2987,
3488,
17,
2733,
585,
1105,
267,
291,
14,
629,
360,
2395,
711,
348,
10661,
22907,
833,
1754,
297,
2058,
59,
16,
2733,
2987,
3488,
18,
2733,
1302,
1105,
267,
291,
14,
629,
360,
778,
833,
1754,
63,
4060,
63,
2164,
14,
14513,
297,
2058,
59,
16,
2733,
2987,
3488,
18,
2733,
1569,
2545,
2164,
1105,
267,
291,
14,
629,
360,
778,
833,
1754,
63,
4060,
63,
4478,
297,
2058,
59,
16,
2733,
2987,
3488,
18,
2733,
1569,
2545,
4478,
1105,
398,
291,
14,
629,
8,
552,
8,
2604,
59,
16,
2733,
3603,
3815,
413,
9,
398,
291,
14,
629,
8,
20996,
63,
633,
12,
2058,
59
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
5055,
492,
10018,
199,
646,
1683,
199,
504,
4145,
492,
4784,
199,
504,
542,
285,
88,
14,
30378,
492,
336,
79,
276,
345,
2174,
2914,
63,
1246,
199,
504,
542,
285,
88,
14,
4776,
492,
428,
2210,
88,
1746,
421,
199,
533,
1379,
26724,
276,
5975,
16192,
3735,
8524,
8,
1513,
285,
88,
1746,
304,
339,
347,
511,
63,
1069,
8,
277,
304,
267,
1827,
275,
283,
396,
63,
1131,
7,
267,
1211,
79,
275,
10018,
8,
807,
9,
267,
1862,
275,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1069,
8,
1131,
12,
1211,
79,
9,
398,
327,
3254,
26,
511,
2986,
63,
498,
267,
291,
14,
4080,
360,
633,
297,
1862,
9,
267,
291,
14,
4080,
360,
2859,
921,
1246,
14,
28070,
345,
2174,
2914,
14,
957,
15,
86,
18,
15,
1131,
7044,
1862,
459,
633,
1105,
267,
291,
14,
4080,
8,
1131,
12,
1862,
459,
633,
1105,
267,
291,
14,
629,
360,
2859,
921,
1544,
14,
28070,
345,
2174,
2914,
14,
957,
15,
1210,
10197,
73,
29,
396,
63,
1131,
297,
1862,
459,
2139,
2545,
28900,
1105,
339,
347,
511,
63,
1814,
63,
80,
1458,
63,
6574,
8,
277,
304,
267,
291,
14,
629,
360,
73,
297,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1814,
63,
80,
1458,
63,
6574,
8,
85,
1154,
1286,
1342,
69,
1333,
339,
347,
511,
63,
1310,
8,
277,
304,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
488,
9,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
3073,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
4074,
267,
291,
14,
1855,
8,
10227,
12,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
12,
6730,
10374,
398,
25104,
63,
633,
275,
283,
20996,
63,
633,
7,
267,
1056,
275,
4784,
8,
2139,
3713,
28900,
356,
25104,
63,
633,
1552,
398,
327,
511,
5988,
267,
2748,
275,
28827,
31,
1652,
1015,
534,
17,
14,
16,
7,
2644,
534,
6610,
13,
24,
27716,
30,
267,
665,
1131,
1099,
3182,
534,
3910,
7,
1125,
534,
3910,
7,
7082,
267,
1449,
267,
1177,
275,
1683,
14,
3346,
8,
1317,
29,
1652,
9,
267,
291,
14,
629,
8,
28070,
345,
2174,
2914,
63,
1246,
14,
1310,
8,
1310,
395,
3073,
398,
327,
511,
5678,
1930,
267,
2748,
275,
31501,
1652,
1015,
534,
17,
14,
16,
7,
2644,
534,
6610,
13,
24,
27716,
30,
267,
665,
1131,
1099,
3182,
534,
2052,
7,
288,
1125,
534,
3910,
7,
288,
302,
1220,
364,
83,
534,
19,
7,
288,
16048,
83,
534,
18568,
7,
288,
1305,
534,
1131,
1099,
63,
344,
7,
288,
1591,
534,
1014,
921,
1544,
20,
67,
14,
28070,
345,
2174,
2914,
14,
957,
7,
288,
4048,
534,
2407,
63,
633,
7,
288,
1015,
534,
18,
14,
22,
8423,
288,
665,
12656,
2538,
534,
3205,
7,
326,
19121,
534,
10193,
7,
326,
1305,
534,
3205,
7,
326,
1967,
954,
12656,
83,
534,
17,
8423,
2116,
665,
954,
12656,
2538,
534,
8423,
2432,
665,
4060,
2928,
534,
1210,
63,
4060,
63,
2164,
14,
14513,
7,
2574,
8791,
534,
1210,
63,
4060,
63,
4478,
7,
2574,
2538,
534,
1210,
63,
4060,
63,
1213,
7,
7082,
2432,
665,
17426,
30,
1210,
63,
17426,
1108,
17426,
30,
2116,
3068,
954,
12656,
30,
1467,
3068,
12656,
30,
1467,
665,
12656,
2538,
534,
2889,
7,
326,
19121,
534,
51,
3236,
317,
3477,
7,
326,
1305,
534,
2889,
7,
326,
1967,
954,
12656,
83,
534,
17,
7,
326,
5062,
534,
2052,
8423,
2116,
665,
954,
12656,
2538,
534,
8423,
2432,
665,
4060,
2928,
534,
1099,
63,
4060,
63,
2164,
14,
14513,
7,
2574,
8791,
534,
1099,
63,
4060,
63,
4478,
7,
2574,
2538,
534,
1099,
63,
4060,
63,
1213,
7,
7082,
2432,
665,
17426,
30,
1099,
63,
17426,
1108,
17426,
30,
2116,
3068,
954,
12656,
30,
1467,
3068,
12656,
30,
1467,
665,
12656,
2538,
534,
2395,
711,
348,
10661,
22907,
833,
1754,
7,
326,
19121,
534,
26291,
18764,
7,
326,
1305,
534,
41,
914,
833,
1754,
7,
326,
1967,
954,
12656,
83,
534,
17,
8423,
2116,
665,
954,
12656,
2538,
534,
8423,
2432,
665,
4060,
2928,
534,
778,
833,
1754,
63,
4060,
63,
2164,
14,
14513,
7,
2574,
8791,
534,
778,
833,
1754,
63,
4060,
63,
4478,
7,
7082,
2432,
665,
17426,
30,
778,
833,
1754,
63,
17426,
1108,
17426,
30,
2116,
3068,
954,
12656,
30,
1467,
3068,
12656,
30,
267,
3068,
1131,
1099,
30,
267,
408,
267,
1177,
275,
1683,
14,
3346,
8,
1317,
29,
1652,
12,
1056,
29,
1069,
9,
267,
2058,
275,
336,
79,
276,
345,
2174,
2914,
63,
1246,
14,
1310,
8,
1310,
9,
267,
291,
14,
629,
8,
466,
8,
2604,
395,
769,
9,
267,
291,
14,
629,
8,
552,
8,
2604,
395,
499,
9,
267,
291,
14,
629,
360,
1210,
63,
17426,
297,
2058,
59,
16,
2733,
815,
1977,
1105,
398,
291,
14,
629,
8,
552,
8,
2604,
59,
16,
2733,
2987,
3815,
650,
9,
267,
291,
14,
629,
360,
3205,
297,
2058,
59,
16,
2733,
2987,
3488,
16,
2733,
1302,
1105,
267,
291,
14,
629,
360,
1210,
63,
17426,
297,
2058,
59,
16,
2733,
2987,
3488,
16,
2733,
585,
1105,
267,
291,
14,
629,
360,
2889,
297,
2058,
59,
16,
2733,
2987,
3488,
17,
2733,
1302,
1105,
267,
291,
14,
629,
360,
1099,
63,
17426,
297,
2058,
59,
16,
2733,
2987,
3488,
17,
2733,
585,
1105,
267,
291,
14,
629,
360,
2395,
711,
348,
10661,
22907,
833,
1754,
297,
2058,
59,
16,
2733,
2987,
3488,
18,
2733,
1302,
1105,
267,
291,
14,
629,
360,
778,
833,
1754,
63,
4060,
63,
2164,
14,
14513,
297,
2058,
59,
16,
2733,
2987,
3488,
18,
2733,
1569,
2545,
2164,
1105,
267,
291,
14,
629,
360,
778,
833,
1754,
63,
4060,
63,
4478,
297,
2058,
59,
16,
2733,
2987,
3488,
18,
2733,
1569,
2545,
4478,
1105,
398,
291,
14,
629,
8,
552,
8,
2604,
59,
16,
2733,
3603,
3815,
413,
9,
398,
291,
14,
629,
8,
20996,
63,
633,
12,
2058,
59,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ledtvavs/repository.ledtv
|
plugin.video.kratos/resources/lib/testings.py
|
2
|
1515
|
# -*- coding: utf-8 -*-
"""
testings.py --- functions dealing with local testings xml file
Copyright (C) 2017, Midraal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import xbmc
import xbmcaddon
import xbmcvfs
from koding import route
from resources.lib.util.xml import JenList
from resources.lib.util.xml import display_list
@route(mode="Testings", args=["file_name"])
def testings(file_name="testings.xml"):
"""
parses local xml file as a jen list
:param str file_name: local file name to parse
:return: list of jen items
:rtype: list[dict[str,str]]
"""
profile_path = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')).decode('utf-8')
test_file = xbmcvfs.File(os.path.join(profile_path, file_name))
xml = test_file.read()
test_file.close()
jenlist = JenList(xml)
display_list(jenlist.get_list(), jenlist.get_content_type())
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
272,
511,
780,
14,
647,
10894,
3423,
23654,
543,
2257,
511,
780,
2748,
570,
272,
1898,
334,
35,
9,
9708,
12,
603,
344,
345,
279,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
646,
747,
199,
199,
646,
11709,
199,
646,
11709,
9291,
199,
646,
10346,
77,
5107,
2319,
199,
199,
504,
1022,
2691,
492,
7475,
199,
504,
5944,
14,
773,
14,
1974,
14,
1652,
492,
1603,
287,
1296,
199,
504,
5944,
14,
773,
14,
1974,
14,
1652,
492,
2929,
63,
513,
421,
199,
32,
4449,
8,
632,
628,
774,
780,
401,
1249,
6270,
493,
63,
354,
3135,
199,
318,
511,
780,
8,
493,
63,
354,
628,
396,
780,
14,
1652,
2349,
272,
408,
199,
462,
874,
2257,
2748,
570,
465,
282,
1335,
287,
769,
272,
520,
635,
620,
570,
63,
354,
26,
2257,
570,
536,
370,
2198,
272,
520,
1107,
26,
769,
402,
1335,
287,
2974,
272,
520,
4500,
26,
769,
59,
807,
59,
495,
12,
495,
2677,
272,
408,
272,
4690,
63,
515,
275,
11709,
14,
5275,
2042,
8,
21382,
9291,
14,
19654,
1252,
362,
19654,
2354,
360,
2913,
11103,
2708,
360,
1624,
13,
24,
358,
272,
511,
63,
493,
275,
10346,
77,
5107,
2319,
14,
1173,
8,
736,
14,
515,
14,
904,
8,
2913,
63,
515,
12,
570,
63,
354,
430,
272,
2748,
275,
511,
63,
493,
14,
739,
342,
272,
511,
63,
493,
14,
1600,
342,
272,
1335,
287,
513,
275,
1603,
287,
1296,
8,
1652,
9,
272,
2929,
63,
513,
8,
74,
287,
513,
14,
362,
63,
513,
1062,
1335,
287,
513,
14,
362,
63,
1317,
63,
466,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
272,
511,
780,
14,
647,
10894,
3423,
23654,
543,
2257,
511,
780,
2748,
570,
272,
1898,
334,
35,
9,
9708,
12,
603,
344,
345,
279,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
646,
747,
199,
199,
646,
11709,
199,
646,
11709,
9291,
199,
646,
10346,
77,
5107,
2319,
199,
199,
504,
1022,
2691,
492,
7475,
199,
504,
5944,
14,
773,
14,
1974,
14,
1652,
492,
1603,
287,
1296,
199,
504,
5944,
14,
773,
14,
1974,
14,
1652,
492,
2929,
63,
513,
421,
199,
32,
4449,
8,
632,
628,
774,
780,
401,
1249,
6270,
493,
63,
354,
3135,
199,
318,
511,
780,
8,
493,
63,
354,
628,
396,
780,
14,
1652,
2349,
272,
408,
199,
462,
874,
2257,
2748,
570,
465,
282,
1335,
287,
769,
272,
520,
635,
620,
570,
63,
354,
26,
2257,
570,
536,
370,
2198,
272,
520,
1107,
26,
769,
402,
1335,
287,
2974,
272,
520,
4500,
26,
769,
59,
807,
59,
495,
12,
495,
2677,
272,
408,
272,
4690,
63,
515,
275,
11709,
14,
5275,
2042,
8,
21382,
9291,
14,
19654,
1252,
362,
19654,
2354,
360,
2913,
11103,
2708,
360,
1624,
13,
24,
358,
272,
511,
63,
493,
275,
10346,
77,
5107,
2319,
14,
1173,
8,
736,
14,
515,
14,
904,
8,
2913,
63,
515,
12,
570,
63,
354,
430,
272,
2748,
275,
511,
63,
493,
14,
739,
342,
272,
511,
63,
493,
14,
1600,
342,
272,
1335,
287,
513,
275,
1603,
287,
1296,
8,
1652,
9,
272,
2929,
63,
513,
8,
74,
287,
513,
14,
362,
63,
513,
1062,
1335,
287,
513,
14,
362,
63,
1317,
63,
466,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
DMLoy/ECommerceBasic
|
bin/bin/activate/lib/python2.7/site-packages/pip/log.py
|
143
|
6371
|
"""Logging
"""
import sys
import logging
from pip import backwardcompat
class Logger(object):
"""
Logging object for use in command-line script. Allows ranges of
levels, to avoid some redundancy of displayed information.
"""
VERBOSE_DEBUG = logging.DEBUG - 1
DEBUG = logging.DEBUG
INFO = logging.INFO
NOTIFY = (logging.INFO + logging.WARN) / 2
WARN = WARNING = logging.WARN
ERROR = logging.ERROR
FATAL = logging.FATAL
LEVELS = [VERBOSE_DEBUG, DEBUG, INFO, NOTIFY, WARN, ERROR, FATAL]
def __init__(self):
self.consumers = []
self.indent = 0
self.explicit_levels = False
self.in_progress = None
self.in_progress_hanging = False
def debug(self, msg, *args, **kw):
self.log(self.DEBUG, msg, *args, **kw)
def info(self, msg, *args, **kw):
self.log(self.INFO, msg, *args, **kw)
def notify(self, msg, *args, **kw):
self.log(self.NOTIFY, msg, *args, **kw)
def warn(self, msg, *args, **kw):
self.log(self.WARN, msg, *args, **kw)
def error(self, msg, *args, **kw):
self.log(self.WARN, msg, *args, **kw)
def fatal(self, msg, *args, **kw):
self.log(self.FATAL, msg, *args, **kw)
def log(self, level, msg, *args, **kw):
if args:
if kw:
raise TypeError(
"You may give positional or keyword arguments, not both")
args = args or kw
rendered = None
for consumer_level, consumer in self.consumers:
if self.level_matches(level, consumer_level):
if (self.in_progress_hanging
and consumer in (sys.stdout, sys.stderr)):
self.in_progress_hanging = False
sys.stdout.write('\n')
sys.stdout.flush()
if rendered is None:
if args:
rendered = msg % args
else:
rendered = msg
rendered = ' ' * self.indent + rendered
if self.explicit_levels:
## FIXME: should this be a name, not a level number?
rendered = '%02i %s' % (level, rendered)
if hasattr(consumer, 'write'):
rendered += '\n'
backwardcompat.fwrite(consumer, rendered)
else:
consumer(rendered)
def _show_progress(self):
"""Should we display download progress?"""
return (self.stdout_level_matches(self.NOTIFY) and sys.stdout.isatty())
def start_progress(self, msg):
assert not self.in_progress, (
"Tried to start_progress(%r) while in_progress %r"
% (msg, self.in_progress))
if self._show_progress():
sys.stdout.write(' ' * self.indent + msg)
sys.stdout.flush()
self.in_progress_hanging = True
else:
self.in_progress_hanging = False
self.in_progress = msg
self.last_message = None
def end_progress(self, msg='done.'):
assert self.in_progress, (
"Tried to end_progress without start_progress")
if self._show_progress():
if not self.in_progress_hanging:
# Some message has been printed out since start_progress
sys.stdout.write('...' + self.in_progress + msg + '\n')
sys.stdout.flush()
else:
# These erase any messages shown with show_progress (besides .'s)
logger.show_progress('')
logger.show_progress('')
sys.stdout.write(msg + '\n')
sys.stdout.flush()
self.in_progress = None
self.in_progress_hanging = False
def show_progress(self, message=None):
"""If we are in a progress scope, and no log messages have been
shown, write out another '.'"""
if self.in_progress_hanging:
if message is None:
sys.stdout.write('.')
sys.stdout.flush()
else:
if self.last_message:
padding = ' ' * max(0, len(self.last_message) - len(message))
else:
padding = ''
sys.stdout.write('\r%s%s%s%s' %
(' ' * self.indent, self.in_progress, message, padding))
sys.stdout.flush()
self.last_message = message
def stdout_level_matches(self, level):
"""Returns true if a message at this level will go to stdout"""
return self.level_matches(level, self._stdout_level())
def _stdout_level(self):
"""Returns the level that stdout runs at"""
for level, consumer in self.consumers:
if consumer is sys.stdout:
return level
return self.FATAL
def level_matches(self, level, consumer_level):
"""
>>> l = Logger()
>>> l.level_matches(3, 4)
False
>>> l.level_matches(3, 2)
True
>>> l.level_matches(slice(None, 3), 3)
False
>>> l.level_matches(slice(None, 3), 2)
True
>>> l.level_matches(slice(1, 3), 1)
True
>>> l.level_matches(slice(2, 3), 1)
False
"""
if isinstance(level, slice):
start, stop = level.start, level.stop
if start is not None and start > consumer_level:
return False
if stop is not None or stop <= consumer_level:
return False
return True
else:
return level >= consumer_level
@classmethod
def level_for_integer(cls, level):
levels = cls.LEVELS
if level < 0:
return levels[0]
if level >= len(levels):
return levels[-1]
return levels[level]
def move_stdout_to_stderr(self):
to_remove = []
to_add = []
for consumer_level, consumer in self.consumers:
if consumer == sys.stdout:
to_remove.append((consumer_level, consumer))
to_add.append((consumer_level, sys.stderr))
for item in to_remove:
self.consumers.remove(item)
self.consumers.extend(to_add)
logger = Logger()
|
mit
|
[
624,
14054,
199,
624,
199,
199,
646,
984,
199,
646,
2050,
199,
199,
504,
7305,
492,
13388,
5819,
421,
199,
533,
15996,
8,
785,
304,
272,
408,
272,
19928,
909,
367,
675,
315,
1414,
13,
604,
2884,
14,
221,
22819,
12271,
402,
272,
11106,
12,
370,
5126,
2005,
8992,
32270,
402,
9080,
2556,
14,
272,
408,
272,
12348,
14607,
63,
5287,
275,
2050,
14,
5287,
446,
413,
272,
10990,
275,
2050,
14,
5287,
272,
24008,
275,
2050,
14,
4531,
272,
2845,
13367,
275,
334,
4806,
14,
4531,
435,
2050,
14,
17449,
9,
1182,
499,
272,
13253,
46,
275,
14750,
275,
2050,
14,
17449,
272,
12539,
275,
2050,
14,
3170,
272,
481,
619,
748,
275,
2050,
14,
29086,
339,
6124,
2524,
5296,
275,
359,
16075,
63,
5287,
12,
10990,
12,
24008,
12,
2845,
13367,
12,
13253,
46,
12,
12539,
12,
481,
619,
748,
61,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
10235,
2393,
275,
942,
267,
291,
14,
3724,
275,
378,
267,
291,
14,
10306,
63,
11402,
275,
756,
267,
291,
14,
262,
63,
5734,
275,
488,
267,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
339,
347,
3105,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
5287,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
2256,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
4531,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
11705,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
24972,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
7987,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
17449,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
1125,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
17449,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
14294,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
29086,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
943,
8,
277,
12,
2166,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
340,
1249,
26,
288,
340,
4775,
26,
355,
746,
3146,
8,
490,
298,
5556,
1443,
8120,
11333,
503,
4252,
2368,
12,
440,
3865,
531,
267,
1249,
275,
1249,
503,
4775,
267,
8018,
275,
488,
267,
367,
9790,
63,
1896,
12,
9790,
315,
291,
14,
10235,
2393,
26,
288,
340,
291,
14,
1896,
63,
6742,
8,
1896,
12,
9790,
63,
1896,
304,
355,
340,
334,
277,
14,
262,
63,
5734,
63,
72,
8544,
490,
436,
9790,
315,
334,
1274,
14,
2703,
12,
984,
14,
3083,
2298,
490,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
490,
984,
14,
2703,
14,
952,
2258,
78,
358,
490,
984,
14,
2703,
14,
4939,
342,
355,
340,
8018,
365,
488,
26,
490,
340,
1249,
26,
717,
8018,
275,
1499,
450,
1249,
490,
587,
26,
717,
8018,
275,
1499,
490,
8018,
275,
283,
283,
627,
291,
14,
3724,
435,
8018,
490,
340,
291,
14,
10306,
63,
11402,
26,
717,
925,
7600,
26,
1077,
642,
506,
282,
536,
12,
440,
282,
2166,
1329,
31,
717,
8018,
275,
1543,
996,
73,
450,
83,
7,
450,
334,
1896,
12,
8018,
9,
355,
340,
2688,
8,
8542,
12,
283,
952,
735,
490,
8018,
847,
1557,
78,
7,
490,
13388,
5819,
14,
70,
952,
8,
8542,
12,
8018,
9,
355,
587,
26,
490,
9790,
8,
16841,
9,
339,
347,
485,
2384,
63,
5734,
8,
277,
304,
267,
408,
11408,
781,
2929,
5235,
6696,
30196,
267,
372,
334,
277,
14,
2703,
63,
1896,
63,
6742,
8,
277,
14,
24972,
9,
436,
984,
14,
2703,
14,
21122,
1012,
339,
347,
1343,
63,
5734,
8,
277,
12,
1499,
304,
267,
702,
440,
291,
14,
262,
63,
5734,
12,
334,
288,
298,
6948,
379,
370,
1343,
63,
5734,
4042,
82,
9,
1830,
315,
63,
5734,
450,
82,
2,
288,
450,
334,
1328,
12,
291,
14,
262,
63,
5734,
430,
267,
340,
291,
423,
2384,
63,
5734,
837,
288,
984,
14,
2703,
14,
952,
360,
283,
627,
291,
14,
3724,
435,
1499,
9,
288,
984,
14,
2703,
14,
4939,
342,
288,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
715,
267,
587,
26,
288,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
267,
291,
14,
262,
63,
5734,
275,
1499,
267,
291,
14,
2019,
63,
1188,
275,
488,
339,
347,
1284,
63,
5734,
8,
277,
12,
1499,
534,
4456,
30194,
267,
702,
291,
14,
262,
63,
5734,
12,
334,
288,
298,
6948,
379,
370,
1284,
63,
5734,
1928,
1343,
63,
5734,
531,
267,
340,
291,
423,
2384,
63,
5734,
837,
288,
340,
440,
291,
14,
262,
63,
5734,
63,
72,
8544,
26,
355,
327,
6601,
1245,
965,
2757,
12487,
734,
3967,
1343,
63,
5734,
355,
984,
14,
2703,
14,
952,
360,
13698,
435,
291,
14,
262,
63,
5734,
435,
1499,
435,
1557,
78,
358,
355,
984,
14,
2703,
14,
4939,
342,
288,
587,
26,
355,
327,
5723,
28343,
1263,
3788,
9164,
543,
2498,
63,
5734,
334,
1235,
19564,
1275,
7,
83,
9,
355,
2512,
14,
2384,
63,
5734,
8355,
355,
2512,
14,
2384,
63,
5734,
8355,
355,
984,
14,
2703,
14,
952,
8,
1328,
435,
1557,
78,
358,
355,
984,
14,
2703,
14,
4939,
342,
267,
291,
14,
262,
63,
5734,
275,
488,
267,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
339,
347,
2498,
63,
5734,
8,
277,
12,
1245,
29,
403,
304,
267,
408,
3917,
781,
787,
315,
282,
6696,
4194,
12,
436,
949,
943,
3788,
1172,
2757,
267,
9164,
12,
2218,
734,
4573,
7815,
624,
267,
340,
291,
14,
262,
63,
5734,
63,
72,
8544,
26,
288,
340,
1245,
365,
488,
26,
355,
984,
14,
2703,
14,
952,
7563,
355,
984,
14,
2703,
14,
4939,
342,
288,
587,
26,
355,
340,
291,
14,
2019,
63,
1188,
26,
490,
6273,
275,
283,
283,
627,
1390,
8,
16,
12
] |
[
14054,
199,
624,
199,
199,
646,
984,
199,
646,
2050,
199,
199,
504,
7305,
492,
13388,
5819,
421,
199,
533,
15996,
8,
785,
304,
272,
408,
272,
19928,
909,
367,
675,
315,
1414,
13,
604,
2884,
14,
221,
22819,
12271,
402,
272,
11106,
12,
370,
5126,
2005,
8992,
32270,
402,
9080,
2556,
14,
272,
408,
272,
12348,
14607,
63,
5287,
275,
2050,
14,
5287,
446,
413,
272,
10990,
275,
2050,
14,
5287,
272,
24008,
275,
2050,
14,
4531,
272,
2845,
13367,
275,
334,
4806,
14,
4531,
435,
2050,
14,
17449,
9,
1182,
499,
272,
13253,
46,
275,
14750,
275,
2050,
14,
17449,
272,
12539,
275,
2050,
14,
3170,
272,
481,
619,
748,
275,
2050,
14,
29086,
339,
6124,
2524,
5296,
275,
359,
16075,
63,
5287,
12,
10990,
12,
24008,
12,
2845,
13367,
12,
13253,
46,
12,
12539,
12,
481,
619,
748,
61,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
10235,
2393,
275,
942,
267,
291,
14,
3724,
275,
378,
267,
291,
14,
10306,
63,
11402,
275,
756,
267,
291,
14,
262,
63,
5734,
275,
488,
267,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
339,
347,
3105,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
5287,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
2256,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
4531,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
11705,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
24972,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
7987,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
17449,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
1125,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
17449,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
14294,
8,
277,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
793,
8,
277,
14,
29086,
12,
1499,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
943,
8,
277,
12,
2166,
12,
1499,
12,
627,
589,
12,
1011,
829,
304,
267,
340,
1249,
26,
288,
340,
4775,
26,
355,
746,
3146,
8,
490,
298,
5556,
1443,
8120,
11333,
503,
4252,
2368,
12,
440,
3865,
531,
267,
1249,
275,
1249,
503,
4775,
267,
8018,
275,
488,
267,
367,
9790,
63,
1896,
12,
9790,
315,
291,
14,
10235,
2393,
26,
288,
340,
291,
14,
1896,
63,
6742,
8,
1896,
12,
9790,
63,
1896,
304,
355,
340,
334,
277,
14,
262,
63,
5734,
63,
72,
8544,
490,
436,
9790,
315,
334,
1274,
14,
2703,
12,
984,
14,
3083,
2298,
490,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
490,
984,
14,
2703,
14,
952,
2258,
78,
358,
490,
984,
14,
2703,
14,
4939,
342,
355,
340,
8018,
365,
488,
26,
490,
340,
1249,
26,
717,
8018,
275,
1499,
450,
1249,
490,
587,
26,
717,
8018,
275,
1499,
490,
8018,
275,
283,
283,
627,
291,
14,
3724,
435,
8018,
490,
340,
291,
14,
10306,
63,
11402,
26,
717,
925,
7600,
26,
1077,
642,
506,
282,
536,
12,
440,
282,
2166,
1329,
31,
717,
8018,
275,
1543,
996,
73,
450,
83,
7,
450,
334,
1896,
12,
8018,
9,
355,
340,
2688,
8,
8542,
12,
283,
952,
735,
490,
8018,
847,
1557,
78,
7,
490,
13388,
5819,
14,
70,
952,
8,
8542,
12,
8018,
9,
355,
587,
26,
490,
9790,
8,
16841,
9,
339,
347,
485,
2384,
63,
5734,
8,
277,
304,
267,
408,
11408,
781,
2929,
5235,
6696,
30196,
267,
372,
334,
277,
14,
2703,
63,
1896,
63,
6742,
8,
277,
14,
24972,
9,
436,
984,
14,
2703,
14,
21122,
1012,
339,
347,
1343,
63,
5734,
8,
277,
12,
1499,
304,
267,
702,
440,
291,
14,
262,
63,
5734,
12,
334,
288,
298,
6948,
379,
370,
1343,
63,
5734,
4042,
82,
9,
1830,
315,
63,
5734,
450,
82,
2,
288,
450,
334,
1328,
12,
291,
14,
262,
63,
5734,
430,
267,
340,
291,
423,
2384,
63,
5734,
837,
288,
984,
14,
2703,
14,
952,
360,
283,
627,
291,
14,
3724,
435,
1499,
9,
288,
984,
14,
2703,
14,
4939,
342,
288,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
715,
267,
587,
26,
288,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
267,
291,
14,
262,
63,
5734,
275,
1499,
267,
291,
14,
2019,
63,
1188,
275,
488,
339,
347,
1284,
63,
5734,
8,
277,
12,
1499,
534,
4456,
30194,
267,
702,
291,
14,
262,
63,
5734,
12,
334,
288,
298,
6948,
379,
370,
1284,
63,
5734,
1928,
1343,
63,
5734,
531,
267,
340,
291,
423,
2384,
63,
5734,
837,
288,
340,
440,
291,
14,
262,
63,
5734,
63,
72,
8544,
26,
355,
327,
6601,
1245,
965,
2757,
12487,
734,
3967,
1343,
63,
5734,
355,
984,
14,
2703,
14,
952,
360,
13698,
435,
291,
14,
262,
63,
5734,
435,
1499,
435,
1557,
78,
358,
355,
984,
14,
2703,
14,
4939,
342,
288,
587,
26,
355,
327,
5723,
28343,
1263,
3788,
9164,
543,
2498,
63,
5734,
334,
1235,
19564,
1275,
7,
83,
9,
355,
2512,
14,
2384,
63,
5734,
8355,
355,
2512,
14,
2384,
63,
5734,
8355,
355,
984,
14,
2703,
14,
952,
8,
1328,
435,
1557,
78,
358,
355,
984,
14,
2703,
14,
4939,
342,
267,
291,
14,
262,
63,
5734,
275,
488,
267,
291,
14,
262,
63,
5734,
63,
72,
8544,
275,
756,
339,
347,
2498,
63,
5734,
8,
277,
12,
1245,
29,
403,
304,
267,
408,
3917,
781,
787,
315,
282,
6696,
4194,
12,
436,
949,
943,
3788,
1172,
2757,
267,
9164,
12,
2218,
734,
4573,
7815,
624,
267,
340,
291,
14,
262,
63,
5734,
63,
72,
8544,
26,
288,
340,
1245,
365,
488,
26,
355,
984,
14,
2703,
14,
952,
7563,
355,
984,
14,
2703,
14,
4939,
342,
288,
587,
26,
355,
340,
291,
14,
2019,
63,
1188,
26,
490,
6273,
275,
283,
283,
627,
1390,
8,
16,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
jgcaaprom/android_external_chromium_org
|
build/android/generate_emma_html.py
|
96
|
2874
|
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Aggregates EMMA coverage files to produce html output."""
import fnmatch
import json
import optparse
import os
import sys
from pylib import cmd_helper
from pylib import constants
def _GetFilesWithExt(root_dir, ext):
"""Gets all files with a given extension.
Args:
root_dir: Directory in which to search for files.
ext: Extension to look for (including dot)
Returns:
A list of absolute paths to files that match.
"""
files = []
for root, _, filenames in os.walk(root_dir):
basenames = fnmatch.filter(filenames, '*.' + ext)
files.extend([os.path.join(root, basename)
for basename in basenames])
return files
def main():
option_parser = optparse.OptionParser()
option_parser.add_option('--output', help='HTML output filename.')
option_parser.add_option('--coverage-dir', default=None,
help=('Root of the directory in which to search for '
'coverage data (.ec) files.'))
option_parser.add_option('--metadata-dir', default=None,
help=('Root of the directory in which to search for '
'coverage metadata (.em) files.'))
option_parser.add_option('--cleanup', action='store_true',
help=('If set, removes coverage files generated at '
'runtime.'))
options, _ = option_parser.parse_args()
if not (options.coverage_dir and options.metadata_dir and options.output):
option_parser.error('One or more mandatory options are missing.')
coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec')
metadata_files = _GetFilesWithExt(options.metadata_dir, 'em')
print 'Found coverage files: %s' % str(coverage_files)
print 'Found metadata files: %s' % str(metadata_files)
sources = []
for f in metadata_files:
sources_file = os.path.splitext(f)[0] + '_sources.txt'
with open(sources_file, 'r') as sf:
sources.extend(json.load(sf))
sources = [os.path.join(constants.DIR_SOURCE_ROOT, s) for s in sources]
print 'Sources: %s' % sources
input_args = []
for f in coverage_files + metadata_files:
input_args.append('-in')
input_args.append(f)
output_args = ['-Dreport.html.out.file', options.output]
source_args = ['-sp', ','.join(sources)]
exit_code = cmd_helper.RunCmd(
['java', '-cp',
os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'),
'emma', 'report', '-r', 'html']
+ input_args + output_args + source_args)
if options.cleanup:
for f in coverage_files:
os.remove(f)
return exit_code
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
8073,
2335,
26512,
2054,
11745,
1584,
370,
7389,
3517,
1072,
1041,
199,
199,
646,
15951,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
984,
199,
199,
504,
29219,
492,
2088,
63,
3676,
199,
504,
29219,
492,
5262,
421,
199,
318,
485,
1002,
5535,
3007,
4942,
8,
1231,
63,
694,
12,
1599,
304,
523,
408,
14426,
1006,
1584,
543,
282,
1627,
3329,
14,
819,
3033,
26,
272,
1738,
63,
694,
26,
15191,
315,
1314,
370,
2754,
367,
1584,
14,
272,
1599,
26,
13282,
370,
3648,
367,
334,
15768,
6308,
9,
819,
1803,
26,
272,
437,
769,
402,
3679,
3792,
370,
1584,
626,
1336,
14,
523,
408,
523,
1584,
275,
942,
523,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
1231,
63,
694,
304,
272,
1300,
1247,
275,
15951,
14,
1541,
8,
10309,
12,
6438,
3530,
435,
1599,
9,
272,
1584,
14,
2880,
779,
736,
14,
515,
14,
904,
8,
1231,
12,
9593,
9,
2116,
367,
9593,
315,
1300,
1247,
566,
819,
372,
1584,
421,
199,
318,
2446,
837,
523,
945,
63,
2087,
275,
8691,
14,
14553,
342,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
1199,
297,
1720,
534,
4943,
1072,
1788,
2659,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
10828,
13,
694,
297,
849,
29,
403,
12,
2574,
1720,
7782,
6405,
402,
314,
2082,
315,
1314,
370,
2754,
367,
283,
639,
283,
10828,
666,
17048,
825,
9,
1584,
12459,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
2343,
13,
694,
297,
849,
29,
403,
12,
2574,
1720,
7782,
6405,
402,
314,
2082,
315,
1314,
370,
2754,
367,
283,
639,
283,
10828,
3341,
17048,
5633,
9,
1584,
12459,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
7661,
297,
1595,
534,
1617,
63,
2052,
297,
2574,
1720,
7782,
3917,
663,
12,
14185,
11745,
1584,
4046,
737,
283,
639,
283,
7726,
12459,
523,
1511,
12,
485,
275,
945,
63,
2087,
14,
1122,
63,
589,
342,
819,
340,
440,
334,
1419,
14,
10828,
63,
694,
436,
1511,
14,
2343,
63,
694,
436,
1511,
14,
1199,
304,
272,
945,
63,
2087,
14,
705,
360,
4395,
503,
1655,
15230,
1511,
787,
4124,
2659,
819,
11745,
63,
1725,
275,
485,
1002,
5535,
3007,
4942,
8,
1419,
14,
10828,
63,
694,
12,
283,
825,
358,
523,
3341,
63,
1725,
275,
485,
1002,
5535,
3007,
4942,
8,
1419,
14,
2343,
63,
694,
12,
283,
5633,
358,
523,
870,
283,
3601,
11745,
1584,
26,
450,
83,
7,
450,
620,
8,
10828,
63,
1725,
9,
523,
870,
283,
3601,
3341,
1584,
26,
450,
83,
7,
450,
620,
8,
2343,
63,
1725,
9,
819,
5274,
275,
942,
523,
367,
289,
315,
3341,
63,
1725,
26,
272,
5274,
63,
493,
275,
747,
14,
515,
14,
7973,
8,
70,
2788,
16,
61,
435,
2513,
4553,
14,
2424,
7,
272,
543,
1551,
8,
4553,
63,
493,
12,
283,
82,
358,
465,
13330,
26,
489,
5274,
14,
2880,
8,
1001,
14,
912,
8,
7646,
430,
523,
5274,
275,
359,
736,
14,
515,
14,
904,
8,
5559,
14,
3022,
63,
10187,
63,
5441,
12,
308,
9,
367,
308,
315,
5274,
61,
523,
870,
283,
13959,
26,
450,
83,
7,
450,
5274,
819,
1324,
63,
589,
275,
942,
523,
367,
289,
315,
11745,
63,
1725,
435,
3341,
63,
1725,
26,
272,
1324,
63,
589,
14,
740,
3654,
262,
358,
272,
1324,
63,
589,
14,
740,
8,
70,
9,
819,
1072,
63,
589,
275,
11573,
36,
3070,
14,
1360,
14,
548,
14,
493,
297,
1511,
14,
1199,
61,
523,
1350,
63,
589,
275,
11573,
681,
297,
12814,
904,
8,
4553,
1874,
819,
4458,
63,
600,
275,
2088,
63,
3676,
14,
2540,
7874,
8,
489,
788,
6138,
297,
2475,
1850,
297,
2126,
747,
14,
515,
14,
904,
8,
5559,
14,
25658,
63,
14939,
63,
5441,
12,
283,
2537,
297,
283,
773,
297,
283,
5633,
391,
14,
7338,
659,
2126,
283,
5633,
391,
297,
283,
3070,
297,
2475,
82,
297,
283,
1360,
418,
489,
435,
1324,
63,
589,
435,
1072,
63,
589,
435,
1350,
63,
589,
9,
819,
340,
1511,
14,
7661,
26,
272,
367,
289,
315,
11745,
63,
1725,
26,
489,
747,
14,
2168,
8,
70,
9,
819,
372,
4458,
63,
600,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
8073,
2335,
26512,
2054,
11745,
1584,
370,
7389,
3517,
1072,
1041,
199,
199,
646,
15951,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
984,
199,
199,
504,
29219,
492,
2088,
63,
3676,
199,
504,
29219,
492,
5262,
421,
199,
318,
485,
1002,
5535,
3007,
4942,
8,
1231,
63,
694,
12,
1599,
304,
523,
408,
14426,
1006,
1584,
543,
282,
1627,
3329,
14,
819,
3033,
26,
272,
1738,
63,
694,
26,
15191,
315,
1314,
370,
2754,
367,
1584,
14,
272,
1599,
26,
13282,
370,
3648,
367,
334,
15768,
6308,
9,
819,
1803,
26,
272,
437,
769,
402,
3679,
3792,
370,
1584,
626,
1336,
14,
523,
408,
523,
1584,
275,
942,
523,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
1231,
63,
694,
304,
272,
1300,
1247,
275,
15951,
14,
1541,
8,
10309,
12,
6438,
3530,
435,
1599,
9,
272,
1584,
14,
2880,
779,
736,
14,
515,
14,
904,
8,
1231,
12,
9593,
9,
2116,
367,
9593,
315,
1300,
1247,
566,
819,
372,
1584,
421,
199,
318,
2446,
837,
523,
945,
63,
2087,
275,
8691,
14,
14553,
342,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
1199,
297,
1720,
534,
4943,
1072,
1788,
2659,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
10828,
13,
694,
297,
849,
29,
403,
12,
2574,
1720,
7782,
6405,
402,
314,
2082,
315,
1314,
370,
2754,
367,
283,
639,
283,
10828,
666,
17048,
825,
9,
1584,
12459,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
2343,
13,
694,
297,
849,
29,
403,
12,
2574,
1720,
7782,
6405,
402,
314,
2082,
315,
1314,
370,
2754,
367,
283,
639,
283,
10828,
3341,
17048,
5633,
9,
1584,
12459,
523,
945,
63,
2087,
14,
525,
63,
1422,
4517,
7661,
297,
1595,
534,
1617,
63,
2052,
297,
2574,
1720,
7782,
3917,
663,
12,
14185,
11745,
1584,
4046,
737,
283,
639,
283,
7726,
12459,
523,
1511,
12,
485,
275,
945,
63,
2087,
14,
1122,
63,
589,
342,
819,
340,
440,
334,
1419,
14,
10828,
63,
694,
436,
1511,
14,
2343,
63,
694,
436,
1511,
14,
1199,
304,
272,
945,
63,
2087,
14,
705,
360,
4395,
503,
1655,
15230,
1511,
787,
4124,
2659,
819,
11745,
63,
1725,
275,
485,
1002,
5535,
3007,
4942,
8,
1419,
14,
10828,
63,
694,
12,
283,
825,
358,
523,
3341,
63,
1725,
275,
485,
1002,
5535,
3007,
4942,
8,
1419,
14,
2343,
63,
694,
12,
283,
5633,
358,
523,
870,
283,
3601,
11745,
1584,
26,
450,
83,
7,
450,
620,
8,
10828,
63,
1725,
9,
523,
870,
283,
3601,
3341,
1584,
26,
450,
83,
7,
450,
620,
8,
2343,
63,
1725,
9,
819,
5274,
275,
942,
523,
367,
289,
315,
3341,
63,
1725,
26,
272,
5274,
63,
493,
275,
747,
14,
515,
14,
7973,
8,
70,
2788,
16,
61,
435,
2513,
4553,
14,
2424,
7,
272,
543,
1551,
8,
4553,
63,
493,
12,
283,
82,
358,
465,
13330,
26,
489,
5274,
14,
2880,
8,
1001,
14,
912,
8,
7646,
430,
523,
5274,
275,
359,
736,
14,
515,
14,
904,
8,
5559,
14,
3022,
63,
10187,
63,
5441,
12,
308,
9,
367,
308,
315,
5274,
61,
523,
870,
283,
13959,
26,
450,
83,
7,
450,
5274,
819,
1324,
63,
589,
275,
942,
523,
367,
289,
315,
11745,
63,
1725,
435,
3341,
63,
1725,
26,
272,
1324,
63,
589,
14,
740,
3654,
262,
358,
272,
1324,
63,
589,
14,
740,
8,
70,
9,
819,
1072,
63,
589,
275,
11573,
36,
3070,
14,
1360,
14,
548,
14,
493,
297,
1511,
14,
1199,
61,
523,
1350,
63,
589,
275,
11573,
681,
297,
12814,
904,
8,
4553,
1874,
819,
4458,
63,
600,
275,
2088,
63,
3676,
14,
2540,
7874,
8,
489,
788,
6138,
297,
2475,
1850,
297,
2126,
747,
14,
515,
14,
904,
8,
5559,
14,
25658,
63,
14939,
63,
5441,
12,
283,
2537,
297,
283,
773,
297,
283,
5633,
391,
14,
7338,
659,
2126,
283,
5633,
391,
297,
283,
3070,
297,
2475,
82,
297,
283,
1360,
418,
489,
435,
1324,
63,
589,
435,
1072,
63,
589,
435,
1350,
63,
589,
9,
819,
340,
1511,
14,
7661,
26,
272,
367,
289,
315,
11745,
63,
1725,
26,
489,
747,
14,
2168,
8,
70,
9,
819,
372,
4458,
63,
600,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CMLL/taiga-back
|
taiga/projects/history/migrations/0001_initial.py
|
27
|
1533
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import taiga.projects.history.models
import django.utils.timezone
import django_pgjson.fields
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='HistoryEntry',
fields=[
('id', models.CharField(primary_key=True, unique=True, max_length=255, serialize=False, default=taiga.projects.history.models._generate_uuid, editable=False)),
('user', django_pgjson.fields.JsonField(default=None, blank=True, null=True)),
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
('type', models.SmallIntegerField(choices=[(1, 'Change'), (2, 'Create'), (3, 'Delete')])),
('is_snapshot', models.BooleanField(default=False)),
('key', models.CharField(max_length=255, default=None, blank=True, null=True)),
('diff', django_pgjson.fields.JsonField(default=None, null=True)),
('snapshot', django_pgjson.fields.JsonField(default=None, null=True)),
('values', django_pgjson.fields.JsonField(default=None, null=True)),
('comment', models.TextField(blank=True)),
('comment_html', models.TextField(blank=True)),
],
options={
'ordering': ['created_at'],
},
bases=(models.Model,),
),
]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
3052,
29055,
14,
6776,
14,
5570,
14,
992,
199,
646,
1639,
14,
1208,
14,
7145,
199,
646,
1639,
63,
4198,
1001,
14,
955,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
12114,
3900,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
2183,
8,
3327,
63,
498,
29,
549,
12,
3747,
29,
549,
12,
1390,
63,
1267,
29,
2299,
12,
8437,
29,
797,
12,
849,
29,
502,
29055,
14,
6776,
14,
5570,
14,
992,
423,
4208,
63,
2580,
12,
14783,
29,
797,
1826,
355,
661,
751,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
4596,
29,
549,
12,
2973,
29,
549,
1826,
355,
661,
3966,
63,
292,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
1826,
355,
661,
466,
297,
1709,
14,
14640,
8,
4577,
17497,
17,
12,
283,
4001,
659,
334,
18,
12,
283,
2499,
659,
334,
19,
12,
283,
5392,
2023,
395,
355,
661,
374,
63,
4753,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
498,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
849,
29,
403,
12,
4596,
29,
549,
12,
2973,
29,
549,
1826,
355,
661,
3028,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
2973,
29,
549,
1826,
355,
661,
4753,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
2973,
29,
549,
1826,
355,
661,
1459,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
2973,
29,
549,
1826,
355,
661,
3349,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
355,
661,
3349,
63,
1360,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
788,
3966,
63,
292,
995,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
3052,
29055,
14,
6776,
14,
5570,
14,
992,
199,
646,
1639,
14,
1208,
14,
7145,
199,
646,
1639,
63,
4198,
1001,
14,
955,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
12114,
3900,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
2183,
8,
3327,
63,
498,
29,
549,
12,
3747,
29,
549,
12,
1390,
63,
1267,
29,
2299,
12,
8437,
29,
797,
12,
849,
29,
502,
29055,
14,
6776,
14,
5570,
14,
992,
423,
4208,
63,
2580,
12,
14783,
29,
797,
1826,
355,
661,
751,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
4596,
29,
549,
12,
2973,
29,
549,
1826,
355,
661,
3966,
63,
292,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
1826,
355,
661,
466,
297,
1709,
14,
14640,
8,
4577,
17497,
17,
12,
283,
4001,
659,
334,
18,
12,
283,
2499,
659,
334,
19,
12,
283,
5392,
2023,
395,
355,
661,
374,
63,
4753,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
498,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
849,
29,
403,
12,
4596,
29,
549,
12,
2973,
29,
549,
1826,
355,
661,
3028,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
2973,
29,
549,
1826,
355,
661,
4753,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
2973,
29,
549,
1826,
355,
661,
1459,
297,
1639,
63,
4198,
1001,
14,
955,
14,
9653,
792,
8,
885,
29,
403,
12,
2973,
29,
549,
1826,
355,
661,
3349,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
355,
661,
3349,
63,
1360,
297,
1709,
14,
6254,
8,
2500,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
788,
3966,
63,
292,
995,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
WillieMaddox/scipy
|
scipy/optimize/tests/test_zeros.py
|
7
|
2471
|
#!/usr/bin/env python
from __future__ import division, print_function, absolute_import
from math import sqrt, exp, sin, cos
from numpy.testing import (TestCase, assert_almost_equal, assert_warns,
assert_, run_module_suite, assert_allclose,
assert_equal)
from scipy.optimize import zeros as cc
from scipy.optimize import zeros
# Import testing parameters
from scipy.optimize._tstutils import functions, fstrings
class TestBasic(TestCase):
def run_check(self, method, name):
a = .5
b = sqrt(3)
for function, fname in zip(functions, fstrings):
zero, r = method(function, a, b, xtol=0.1e-12, full_output=True)
assert_(r.converged)
assert_almost_equal(zero, 1.0, decimal=12,
err_msg='method %s, function %s' % (name, fname))
def test_bisect(self):
self.run_check(cc.bisect, 'bisect')
def test_ridder(self):
self.run_check(cc.ridder, 'ridder')
def test_brentq(self):
self.run_check(cc.brentq, 'brentq')
def test_brenth(self):
self.run_check(cc.brenth, 'brenth')
def test_newton(self):
f1 = lambda x: x**2 - 2*x - 1
f1_1 = lambda x: 2*x - 2
f1_2 = lambda x: 2.0 + 0*x
f2 = lambda x: exp(x) - cos(x)
f2_1 = lambda x: exp(x) + sin(x)
f2_2 = lambda x: exp(x) + cos(x)
for f, f_1, f_2 in [(f1, f1_1, f1_2), (f2, f2_1, f2_2)]:
x = zeros.newton(f, 3, tol=1e-6)
assert_allclose(f(x), 0, atol=1e-6)
x = zeros.newton(f, 3, fprime=f_1, tol=1e-6)
assert_allclose(f(x), 0, atol=1e-6)
x = zeros.newton(f, 3, fprime=f_1, fprime2=f_2, tol=1e-6)
assert_allclose(f(x), 0, atol=1e-6)
def test_deriv_zero_warning(self):
func = lambda x: x**2
dfunc = lambda x: 2*x
assert_warns(RuntimeWarning, cc.newton, func, 0.0, dfunc)
class TestRootResults:
def test_repr(self):
r = zeros.RootResults(root=1.0,
iterations=44,
function_calls=46,
flag=0)
expected_repr = (" converged: True\n flag: 'converged'"
"\n function_calls: 46\n iterations: 44\n"
" root: 1.0")
assert_equal(repr(r), expected_repr)
if __name__ == '__main__':
run_module_suite()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
504,
3473,
492,
7452,
12,
1437,
12,
9829,
12,
9794,
199,
199,
504,
2680,
14,
4776,
492,
334,
1746,
12,
702,
63,
4398,
63,
1452,
12,
702,
63,
19811,
12,
2574,
702,
3131,
1255,
63,
578,
63,
5768,
12,
702,
63,
7520,
12,
2574,
702,
63,
1452,
9,
199,
199,
504,
7026,
14,
13416,
492,
10136,
465,
7429,
199,
504,
7026,
14,
13416,
492,
10136,
199,
199,
3,
3161,
5343,
2633,
199,
504,
7026,
14,
13416,
423,
84,
270,
1208,
492,
3423,
12,
289,
5465,
421,
199,
533,
1379,
6845,
8,
1746,
304,
272,
347,
1255,
63,
1074,
8,
277,
12,
1083,
12,
536,
304,
267,
282,
275,
1275,
21,
267,
330,
275,
7452,
8,
19,
9,
267,
367,
805,
12,
6748,
315,
3482,
8,
5777,
12,
289,
5465,
304,
288,
4697,
12,
519,
275,
1083,
8,
1593,
12,
282,
12,
330,
12,
25158,
393,
29,
16,
14,
17,
69,
13,
713,
12,
2615,
63,
1199,
29,
549,
9,
288,
702,
2531,
82,
14,
6435,
3046,
9,
288,
702,
63,
4398,
63,
1452,
8,
4262,
12,
413,
14,
16,
12,
6107,
29,
713,
12,
355,
2329,
63,
1328,
534,
765,
450,
83,
12,
805,
450,
83,
7,
450,
334,
354,
12,
6748,
430,
339,
347,
511,
63,
23247,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
23247,
12,
283,
23247,
358,
339,
347,
511,
63,
1677,
424,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
1677,
424,
12,
283,
1677,
424,
358,
339,
347,
511,
63,
66,
640,
81,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
66,
640,
81,
12,
283,
66,
640,
81,
358,
339,
347,
511,
63,
66,
828,
273,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
66,
828,
273,
12,
283,
66,
828,
273,
358,
339,
347,
511,
63,
1222,
1860,
8,
277,
304,
267,
289,
17,
275,
2400,
671,
26,
671,
538,
18,
446,
499,
10,
88,
446,
413,
267,
289,
17,
63,
17,
275,
2400,
671,
26,
499,
10,
88,
446,
499,
267,
289,
17,
63,
18,
275,
2400,
671,
26,
499,
14,
16,
435,
378,
10,
88,
398,
289,
18,
275,
2400,
671,
26,
1437,
8,
88,
9,
446,
9794,
8,
88,
9,
267,
289,
18,
63,
17,
275,
2400,
671,
26,
1437,
8,
88,
9,
435,
9829,
8,
88,
9,
267,
289,
18,
63,
18,
275,
2400,
671,
26,
1437,
8,
88,
9,
435,
9794,
8,
88,
9,
398,
367,
289,
12,
289,
63,
17,
12,
289,
63,
18,
315,
3842,
70,
17,
12,
289,
17,
63,
17,
12,
289,
17,
63,
18,
395,
334,
70,
18,
12,
289,
18,
63,
17,
12,
289,
18,
63,
18,
19532,
288,
671,
275,
10136,
14,
1222,
1860,
8,
70,
12,
650,
12,
9561,
29,
17,
69,
13,
22,
9,
288,
702,
63,
7520,
8,
70,
8,
88,
395,
378,
12,
9543,
29,
17,
69,
13,
22,
9,
288,
671,
275,
10136,
14,
1222,
1860,
8,
70,
12,
650,
12,
289,
12446,
29,
70,
63,
17,
12,
9561,
29,
17,
69,
13,
22,
9,
288,
702,
63,
7520,
8,
70,
8,
88,
395,
378,
12,
9543,
29,
17,
69,
13,
22,
9,
288,
671,
275,
10136,
14,
1222,
1860,
8,
70,
12,
650,
12,
289,
12446,
29,
70,
63,
17,
12,
289,
12446,
18,
29,
70,
63,
18,
12,
9561,
29,
17,
69,
13,
22,
9,
288,
702,
63,
7520,
8,
70,
8,
88,
395,
378,
12,
9543,
29,
17,
69,
13,
22,
9,
339,
347,
511,
63,
17922,
63,
4262,
63,
3764,
8,
277,
304,
267,
2562,
275,
2400,
671,
26,
671,
538,
18,
267,
366,
1532,
275,
2400,
671,
26,
499,
10,
88,
267,
702,
63,
19811,
8,
14357,
3849,
12,
7429,
14,
1222,
1860,
12,
2562,
12,
378,
14,
16,
12,
366,
1532,
9,
421,
199,
533,
1379,
6405,
6579,
26,
272,
347,
511,
63,
2722,
8,
277,
304,
267,
519,
275,
10136,
14,
6405,
6579,
8,
1231,
29,
17,
14,
16,
12,
2892,
10615,
29,
1602,
12,
2892,
805,
63,
5352,
29,
2466,
12,
2892,
3305,
29,
16,
9,
267,
1420,
63,
2722,
275,
1689,
420,
3818,
3046,
26,
715,
60,
78,
3698,
3305,
26,
283,
6435,
3046,
4065,
586,
1867,
78,
805,
63,
5352,
26,
12426,
60,
78,
258,
10615,
26,
10868,
60,
78,
2,
586,
298,
3698,
1738,
26,
413,
14,
16,
531,
267,
702,
63,
1452,
8,
2722,
8,
82,
395,
1420,
63,
2722,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
63,
578,
63,
5768,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
504,
3473,
492,
7452,
12,
1437,
12,
9829,
12,
9794,
199,
199,
504,
2680,
14,
4776,
492,
334,
1746,
12,
702,
63,
4398,
63,
1452,
12,
702,
63,
19811,
12,
2574,
702,
3131,
1255,
63,
578,
63,
5768,
12,
702,
63,
7520,
12,
2574,
702,
63,
1452,
9,
199,
199,
504,
7026,
14,
13416,
492,
10136,
465,
7429,
199,
504,
7026,
14,
13416,
492,
10136,
199,
199,
3,
3161,
5343,
2633,
199,
504,
7026,
14,
13416,
423,
84,
270,
1208,
492,
3423,
12,
289,
5465,
421,
199,
533,
1379,
6845,
8,
1746,
304,
272,
347,
1255,
63,
1074,
8,
277,
12,
1083,
12,
536,
304,
267,
282,
275,
1275,
21,
267,
330,
275,
7452,
8,
19,
9,
267,
367,
805,
12,
6748,
315,
3482,
8,
5777,
12,
289,
5465,
304,
288,
4697,
12,
519,
275,
1083,
8,
1593,
12,
282,
12,
330,
12,
25158,
393,
29,
16,
14,
17,
69,
13,
713,
12,
2615,
63,
1199,
29,
549,
9,
288,
702,
2531,
82,
14,
6435,
3046,
9,
288,
702,
63,
4398,
63,
1452,
8,
4262,
12,
413,
14,
16,
12,
6107,
29,
713,
12,
355,
2329,
63,
1328,
534,
765,
450,
83,
12,
805,
450,
83,
7,
450,
334,
354,
12,
6748,
430,
339,
347,
511,
63,
23247,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
23247,
12,
283,
23247,
358,
339,
347,
511,
63,
1677,
424,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
1677,
424,
12,
283,
1677,
424,
358,
339,
347,
511,
63,
66,
640,
81,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
66,
640,
81,
12,
283,
66,
640,
81,
358,
339,
347,
511,
63,
66,
828,
273,
8,
277,
304,
267,
291,
14,
1065,
63,
1074,
8,
2055,
14,
66,
828,
273,
12,
283,
66,
828,
273,
358,
339,
347,
511,
63,
1222,
1860,
8,
277,
304,
267,
289,
17,
275,
2400,
671,
26,
671,
538,
18,
446,
499,
10,
88,
446,
413,
267,
289,
17,
63,
17,
275,
2400,
671,
26,
499,
10,
88,
446,
499,
267,
289,
17,
63,
18,
275,
2400,
671,
26,
499,
14,
16,
435,
378,
10,
88,
398,
289,
18,
275,
2400,
671,
26,
1437,
8,
88,
9,
446,
9794,
8,
88,
9,
267,
289,
18,
63,
17,
275,
2400,
671,
26,
1437,
8,
88,
9,
435,
9829,
8,
88,
9,
267,
289,
18,
63,
18,
275,
2400,
671,
26,
1437,
8,
88,
9,
435,
9794,
8,
88,
9,
398,
367,
289,
12,
289,
63,
17,
12,
289,
63,
18,
315,
3842,
70,
17,
12,
289,
17,
63,
17,
12,
289,
17,
63,
18,
395,
334,
70,
18,
12,
289,
18,
63,
17,
12,
289,
18,
63,
18,
19532,
288,
671,
275,
10136,
14,
1222,
1860,
8,
70,
12,
650,
12,
9561,
29,
17,
69,
13,
22,
9,
288,
702,
63,
7520,
8,
70,
8,
88,
395,
378,
12,
9543,
29,
17,
69,
13,
22,
9,
288,
671,
275,
10136,
14,
1222,
1860,
8,
70,
12,
650,
12,
289,
12446,
29,
70,
63,
17,
12,
9561,
29,
17,
69,
13,
22,
9,
288,
702,
63,
7520,
8,
70,
8,
88,
395,
378,
12,
9543,
29,
17,
69,
13,
22,
9,
288,
671,
275,
10136,
14,
1222,
1860,
8,
70,
12,
650,
12,
289,
12446,
29,
70,
63,
17,
12,
289,
12446,
18,
29,
70,
63,
18,
12,
9561,
29,
17,
69,
13,
22,
9,
288,
702,
63,
7520,
8,
70,
8,
88,
395,
378,
12,
9543,
29,
17,
69,
13,
22,
9,
339,
347,
511,
63,
17922,
63,
4262,
63,
3764,
8,
277,
304,
267,
2562,
275,
2400,
671,
26,
671,
538,
18,
267,
366,
1532,
275,
2400,
671,
26,
499,
10,
88,
267,
702,
63,
19811,
8,
14357,
3849,
12,
7429,
14,
1222,
1860,
12,
2562,
12,
378,
14,
16,
12,
366,
1532,
9,
421,
199,
533,
1379,
6405,
6579,
26,
272,
347,
511,
63,
2722,
8,
277,
304,
267,
519,
275,
10136,
14,
6405,
6579,
8,
1231,
29,
17,
14,
16,
12,
2892,
10615,
29,
1602,
12,
2892,
805,
63,
5352,
29,
2466,
12,
2892,
3305,
29,
16,
9,
267,
1420,
63,
2722,
275,
1689,
420,
3818,
3046,
26,
715,
60,
78,
3698,
3305,
26,
283,
6435,
3046,
4065,
586,
1867,
78,
805,
63,
5352,
26,
12426,
60,
78,
258,
10615,
26,
10868,
60,
78,
2,
586,
298,
3698,
1738,
26,
413,
14,
16,
531,
267,
702,
63,
1452,
8,
2722,
8,
82,
395,
1420,
63,
2722,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
63,
578,
63,
5768,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aaronorosen/horizon-congress
|
openstack_dashboard/dashboards/admin/projects/tests.py
|
2
|
79907
|
# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import datetime
import logging
import os
import django
from django.core.urlresolvers import reverse
from django import http
from django.test.utils import override_settings
from django.utils import timezone
from django.utils import unittest
from mox import IgnoreArg # noqa
from mox import IsA # noqa
from horizon import exceptions
from horizon.workflows import views
from openstack_dashboard import api
from openstack_dashboard.dashboards.admin.projects import workflows
from openstack_dashboard.test import helpers as test
from openstack_dashboard import usage
from openstack_dashboard.usage import quotas
with_sel = os.environ.get('WITH_SELENIUM', False)
if with_sel:
from selenium.webdriver import ActionChains # noqa
from selenium.webdriver.common import keys
from socket import timeout as socket_timeout # noqa
INDEX_URL = reverse('horizon:admin:projects:index')
USER_ROLE_PREFIX = workflows.PROJECT_GROUP_MEMBER_SLUG + "_role_"
GROUP_ROLE_PREFIX = workflows.PROJECT_USER_MEMBER_SLUG + "_role_"
@test.create_stubs({api.keystone: ('tenant_list',)})
class TenantsViewTests(test.BaseAdminViewTests):
def test_index(self):
api.keystone.tenant_list(IsA(http.HttpRequest),
domain=None,
paginate=True) \
.AndReturn([self.tenants.list(), False])
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'admin/projects/index.html')
self.assertItemsEqual(res.context['table'].data, self.tenants.list())
@test.create_stubs({api.keystone: ('tenant_list', )})
def test_index_with_domain_context(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
domain_tenants = [tenant for tenant in self.tenants.list()
if tenant.domain_id == domain.id]
api.keystone.tenant_list(IsA(http.HttpRequest),
domain=domain.id) \
.AndReturn(domain_tenants)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'admin/projects/index.html')
self.assertItemsEqual(res.context['table'].data, domain_tenants)
self.assertContains(res, "<em>test_domain:</em>")
class CreateProjectWorkflowTests(test.BaseAdminViewTests):
def _get_project_info(self, project):
domain = self._get_default_domain()
project_info = {"name": project.name,
"description": project.description,
"enabled": project.enabled,
"domain": domain.id}
return project_info
def _get_workflow_fields(self, project):
domain = self._get_default_domain()
project_info = {"domain_id": domain.id,
"domain_name": domain.name,
"name": project.name,
"description": project.description,
"enabled": project.enabled}
return project_info
def _get_quota_info(self, quota):
cinder_quota = self.cinder_quotas.first()
neutron_quota = self.neutron_quotas.first()
quota_data = {}
for field in quotas.NOVA_QUOTA_FIELDS:
quota_data[field] = int(quota.get(field).limit)
for field in quotas.CINDER_QUOTA_FIELDS:
quota_data[field] = int(cinder_quota.get(field).limit)
for field in quotas.NEUTRON_QUOTA_FIELDS:
quota_data[field] = int(neutron_quota.get(field).limit)
return quota_data
def _get_workflow_data(self, project, quota):
project_info = self._get_workflow_fields(project)
quota_data = self._get_quota_info(quota)
project_info.update(quota_data)
return project_info
def _get_default_domain(self):
default_domain = self.domain
domain = {"id": self.request.session.get('domain_context',
default_domain.id),
"name": self.request.session.get('domain_context_name',
default_domain.name)}
return api.base.APIDictWrapper(domain)
def _get_all_users(self, domain_id):
if not domain_id:
users = self.users.list()
else:
users = [user for user in self.users.list()
if user.domain_id == domain_id]
return users
def _get_all_groups(self, domain_id):
if not domain_id:
groups = self.groups.list()
else:
groups = [group for group in self.groups.list()
if group.domain_id == domain_id]
return groups
@test.create_stubs({api.keystone: ('get_default_domain',
'get_default_role',
'user_list',
'group_list',
'role_list'),
api.base: ('is_service_enabled',),
api.neutron: ('is_extension_supported',),
quotas: ('get_default_quota_data',)})
def test_add_project_get(self):
quota = self.quotas.first()
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \
.MultipleTimes().AndReturn(True)
api.base.is_service_enabled(IsA(http.HttpRequest), 'volume') \
.MultipleTimes().AndReturn(True)
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(default_domain)
api.neutron.is_extension_supported(
IsA(http.HttpRequest), 'security-group').AndReturn(True)
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)
self.mox.ReplayAll()
url = reverse('horizon:admin:projects:create')
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
self.assertContains(res, '<input type="hidden" name="subnet" '
'id="id_subnet" />', html=True)
workflow = res.context['workflow']
self.assertEqual(res.context['workflow'].name,
workflows.CreateProject.name)
step = workflow.get_step("createprojectinfoaction")
self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
self.assertEqual(step.action.initial['injected_files'],
quota.get('injected_files').limit)
self.assertQuerysetEqual(workflow.steps,
['<CreateProjectInfo: createprojectinfoaction>',
'<UpdateProjectMembers: update_members>',
'<UpdateProjectGroups: update_group_members>',
'<UpdateProjectQuota: update_quotas>'])
def test_add_project_get_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_get()
@test.create_stubs({api.keystone: ('get_default_role',
'user_list',
'group_list',
'role_list',
'domain_get'),
api.neutron: ('is_extension_supported',
'tenant_quota_get'),
quotas: ('get_default_quota_data',)})
@override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
def test_add_project_get_with_neutron(self):
quota = self.quotas.first()
neutron_quotas = self.neutron_quotas.first()
quotas.get_default_quota_data(IsA(http.HttpRequest)) \
.AndReturn(quota)
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
.MultipleTimes().AndReturn(True)
api.neutron.is_extension_supported(
IsA(http.HttpRequest), 'security-group').AndReturn(True)
api.neutron.tenant_quota_get(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(neutron_quotas)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(self.roles.first())
api.keystone.user_list(IsA(http.HttpRequest), domain=None) \
.AndReturn(self.users.list())
api.keystone.role_list(IsA(http.HttpRequest)) \
.AndReturn(self.roles.list())
api.keystone.group_list(IsA(http.HttpRequest), domain=None) \
.AndReturn(self.groups.list())
api.keystone.role_list(IsA(http.HttpRequest)) \
.AndReturn(self.roles.list())
self.mox.ReplayAll()
res = self.client.get(reverse('horizon:admin:projects:create'))
self.assertTemplateUsed(res, views.WorkflowView.template_name)
if django.VERSION >= (1, 6):
self.assertContains(res, '''
<input class=" form-control"
id="id_subnet" min="-1"
name="subnet" type="number" value="10" />
''', html=True)
else:
self.assertContains(res, '''
<input class=" form-control"
name="subnet" id="id_subnet"
value="10" type="text" />
''', html=True)
workflow = res.context['workflow']
self.assertEqual(res.context['workflow'].name,
workflows.CreateProject.name)
step = workflow.get_step("createprojectinfoaction")
self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
self.assertEqual(step.action.initial['subnet'],
neutron_quotas.get('subnet').limit)
@test.create_stubs({api.keystone: ('get_default_role',
'add_tenant_user_role',
'tenant_create',
'user_list',
'group_list',
'role_list',
'domain_get'),
quotas: ('get_default_quota_data',
'get_disabled_quotas'),
api.cinder: ('tenant_quota_update',),
api.nova: ('tenant_quota_update',)})
def test_add_project_post(self, neutron=False):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
if neutron:
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
# handle
project_details = self._get_project_info(project)
quota_data = self._get_quota_info(quota)
api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
.AndReturn(project)
workflow_data = {}
for role in roles:
if USER_ROLE_PREFIX + role.id in workflow_data:
ulist = workflow_data[USER_ROLE_PREFIX + role.id]
for user_id in ulist:
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user=user_id,
role=role.id)
for role in roles:
if GROUP_ROLE_PREFIX + role.id in workflow_data:
ulist = workflow_data[GROUP_ROLE_PREFIX + role.id]
for group_id in ulist:
api.keystone.add_group_role(IsA(http.HttpRequest),
role=role.id,
group=group_id,
project=self.tenant.id)
nova_updated_quota = dict([(key, quota_data[key]) for key in
quotas.NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**nova_updated_quota)
cinder_updated_quota = dict([(key, quota_data[key]) for key in
quotas.CINDER_QUOTA_FIELDS])
api.cinder.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**cinder_updated_quota)
self.mox.ReplayAll()
workflow_data.update(self._get_workflow_data(project, quota))
url = reverse('horizon:admin:projects:create')
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_add_project_post_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_post()
@test.create_stubs({api.neutron: ('is_extension_supported',
'tenant_quota_update')})
@override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
def test_add_project_post_with_neutron(self):
quota_data = self.neutron_quotas.first()
neutron_updated_quota = dict([(key, quota_data.get(key).limit)
for key in quotas.NEUTRON_QUOTA_FIELDS])
api.neutron.is_extension_supported(
IsA(http.HttpRequest), 'security-group').AndReturn(True)
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
.MultipleTimes().AndReturn(True)
api.neutron.tenant_quota_update(IsA(http.HttpRequest),
self.tenant.id,
**neutron_updated_quota)
self.test_add_project_post(neutron=True)
@test.create_stubs({api.keystone: ('user_list',
'role_list',
'group_list',
'get_default_domain',
'get_default_role'),
quotas: ('get_default_quota_data',
'get_disabled_quotas')})
def test_add_project_quota_defaults_error(self):
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(default_domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)) \
.AndRaise(self.exceptions.nova)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
self.mox.ReplayAll()
url = reverse('horizon:admin:projects:create')
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
self.assertContains(res, "Unable to retrieve default quota values")
def test_add_project_quota_defaults_error_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_quota_defaults_error()
@test.create_stubs({api.keystone: ('tenant_create',
'user_list',
'role_list',
'group_list',
'get_default_domain',
'get_default_role'),
quotas: ('get_default_quota_data',
'get_disabled_quotas')})
def test_add_project_tenant_create_error(self):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(default_domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
# handle
project_details = self._get_project_info(project)
api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
.AndRaise(self.exceptions.keystone)
self.mox.ReplayAll()
workflow_data = self._get_workflow_data(project, quota)
url = reverse('horizon:admin:projects:create')
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_add_project_tenant_create_error_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_tenant_create_error()
@test.create_stubs({api.keystone: ('tenant_create',
'user_list',
'role_list',
'group_list',
'get_default_domain',
'get_default_role',
'add_tenant_user_role'),
quotas: ('get_default_quota_data',
'get_disabled_quotas'),
api.nova: ('tenant_quota_update',)})
def test_add_project_quota_update_error(self):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(default_domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
# handle
project_details = self._get_project_info(project)
quota_data = self._get_quota_info(quota)
api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
.AndReturn(project)
workflow_data = {}
for role in roles:
if USER_ROLE_PREFIX + role.id in workflow_data:
ulist = workflow_data[USER_ROLE_PREFIX + role.id]
for user_id in ulist:
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user=user_id,
role=role.id)
for role in roles:
if GROUP_ROLE_PREFIX + role.id in workflow_data:
ulist = workflow_data[GROUP_ROLE_PREFIX + role.id]
for group_id in ulist:
api.keystone.add_group_role(IsA(http.HttpRequest),
role=role.id,
group=group_id,
project=self.tenant.id)
nova_updated_quota = dict([(key, quota_data[key]) for key in
quotas.NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**nova_updated_quota) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
workflow_data.update(self._get_workflow_data(project, quota))
url = reverse('horizon:admin:projects:create')
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_add_project_quota_update_error_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_quota_update_error()
@test.create_stubs({api.keystone: ('tenant_create',
'user_list',
'role_list',
'group_list',
'get_default_domain',
'get_default_role',
'add_tenant_user_role'),
quotas: ('get_default_quota_data',
'get_disabled_quotas'),
api.cinder: ('tenant_quota_update',),
api.nova: ('tenant_quota_update',)})
def test_add_project_user_update_error(self):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(default_domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
# handle
project_details = self._get_project_info(project)
quota_data = self._get_quota_info(quota)
api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
.AndReturn(project)
workflow_data = {}
for role in roles:
if USER_ROLE_PREFIX + role.id in workflow_data:
ulist = workflow_data[USER_ROLE_PREFIX + role.id]
for user_id in ulist:
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user=user_id,
role=role.id) \
.AndRaise(self.exceptions.keystone)
break
break
nova_updated_quota = dict([(key, quota_data[key]) for key in
quotas.NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**nova_updated_quota)
cinder_updated_quota = dict([(key, quota_data[key]) for key in
quotas.CINDER_QUOTA_FIELDS])
api.cinder.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**cinder_updated_quota)
self.mox.ReplayAll()
workflow_data.update(self._get_workflow_data(project, quota))
url = reverse('horizon:admin:projects:create')
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_add_project_user_update_error_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_user_update_error()
@test.create_stubs({api.keystone: ('user_list',
'role_list',
'group_list',
'get_default_domain',
'get_default_role'),
quotas: ('get_default_quota_data',
'get_disabled_quotas')})
def test_add_project_missing_field_error(self):
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
default_domain = self._get_default_domain()
domain_id = default_domain.id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
# init
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(default_domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
self.mox.ReplayAll()
workflow_data = self._get_workflow_data(project, quota)
workflow_data["name"] = ""
url = reverse('horizon:admin:projects:create')
res = self.client.post(url, workflow_data)
self.assertContains(res, "field is required")
def test_add_project_missing_field_error_domain(self):
domain = self.domains.get(id="1")
self.setSessionValues(domain_context=domain.id,
domain_context_name=domain.name)
self.test_add_project_missing_field_error()
class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
def _get_quota_info(self, quota):
cinder_quota = self.cinder_quotas.first()
neutron_quota = self.neutron_quotas.first()
quota_data = {}
for field in quotas.NOVA_QUOTA_FIELDS:
quota_data[field] = int(quota.get(field).limit)
for field in quotas.CINDER_QUOTA_FIELDS:
quota_data[field] = int(cinder_quota.get(field).limit)
for field in quotas.NEUTRON_QUOTA_FIELDS:
quota_data[field] = int(neutron_quota.get(field).limit)
return quota_data
def _get_all_users(self, domain_id):
if not domain_id:
users = self.users.list()
else:
users = [user for user in self.users.list()
if user.domain_id == domain_id]
return users
def _get_all_groups(self, domain_id):
if not domain_id:
groups = self.groups.list()
else:
groups = [group for group in self.groups.list()
if group.domain_id == domain_id]
return groups
def _get_proj_users(self, project_id):
return [user for user in self.users.list()
if user.project_id == project_id]
def _get_proj_groups(self, project_id):
return [group for group in self.groups.list()
if group.project_id == project_id]
@test.create_stubs({api.keystone: ('get_default_role',
'roles_for_user',
'tenant_get',
'domain_get',
'user_list',
'roles_for_group',
'group_list',
'role_list',
'role_assignments_list'),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas')})
def test_update_project_get(self):
keystone_api_version = api.keystone.VERSIONS.active
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
domain_id = project.domain_id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
proj_users = self._get_proj_users(project.id)
role_assignments = self.role_assignments.list()
api.keystone.tenant_get(IsA(http.HttpRequest),
self.tenant.id, admin=True) \
.AndReturn(project)
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
if keystone_api_version >= 3:
api.keystone.role_assignments_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(role_assignments)
else:
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(proj_users)
for user in proj_users:
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(roles)
for group in groups:
api.keystone.roles_for_group(IsA(http.HttpRequest),
group=group.id,
project=self.tenant.id) \
.AndReturn(roles)
self.mox.ReplayAll()
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
workflow = res.context['workflow']
self.assertEqual(res.context['workflow'].name,
workflows.UpdateProject.name)
step = workflow.get_step("update_info")
self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
self.assertEqual(step.action.initial['injected_files'],
quota.get('injected_files').limit)
self.assertEqual(step.action.initial['name'], project.name)
self.assertEqual(step.action.initial['description'],
project.description)
self.assertQuerysetEqual(workflow.steps,
['<UpdateProjectInfo: update_info>',
'<UpdateProjectMembers: update_members>',
'<UpdateProjectGroups: update_group_members>',
'<UpdateProjectQuota: update_quotas>'])
@test.create_stubs({api.keystone: ('tenant_get',
'domain_get',
'tenant_update',
'get_default_role',
'roles_for_user',
'remove_tenant_user_role',
'add_tenant_user_role',
'user_list',
'roles_for_group',
'remove_group_role',
'add_group_role',
'group_list',
'role_list',
'role_assignments_list'),
api.nova: ('tenant_quota_update',),
api.cinder: ('tenant_quota_update',),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas')})
def test_update_project_save(self, neutron=False):
keystone_api_version = api.keystone.VERSIONS.active
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
domain_id = project.domain_id
users = self._get_all_users(domain_id)
proj_users = self._get_proj_users(project.id)
groups = self._get_all_groups(domain_id)
proj_groups = self._get_proj_groups(project.id)
roles = self.roles.list()
role_assignments = self.role_assignments.list()
# get/init
api.keystone.tenant_get(IsA(http.HttpRequest),
self.tenant.id, admin=True) \
.AndReturn(project)
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
if neutron:
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
workflow_data = {}
if keystone_api_version >= 3:
api.keystone.role_assignments_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(role_assignments)
else:
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(proj_users)
for user in proj_users:
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(roles)
for group in groups:
api.keystone.roles_for_group(IsA(http.HttpRequest),
group=group.id,
project=self.tenant.id) \
.AndReturn(roles)
workflow_data[USER_ROLE_PREFIX + "1"] = ['3'] # admin role
workflow_data[USER_ROLE_PREFIX + "2"] = ['2'] # member role
# Group assignment form data
workflow_data[GROUP_ROLE_PREFIX + "1"] = ['3'] # admin role
workflow_data[GROUP_ROLE_PREFIX + "2"] = ['2'] # member role
# update some fields
project._info["domain_id"] = domain_id
project._info["name"] = "updated name"
project._info["description"] = "updated description"
quota.metadata_items = 444
quota.volumes = 444
updated_project = {"name": project._info["name"],
"description": project._info["description"],
"enabled": project.enabled}
updated_quota = self._get_quota_info(quota)
# handle
api.keystone.tenant_update(IsA(http.HttpRequest),
project.id,
**updated_project) \
.AndReturn(project)
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id).AndReturn(proj_users)
# admin user - try to remove all roles on current project, warning
api.keystone.roles_for_user(IsA(http.HttpRequest), '1',
self.tenant.id) \
.AndReturn(roles)
# member user 1 - has role 1, will remove it
api.keystone.roles_for_user(IsA(http.HttpRequest), '2',
self.tenant.id) \
.AndReturn((roles[0],))
# remove role 1
api.keystone.remove_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user='2',
role='1')
# add role 2
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user='2',
role='2')
# member user 3 - has role 2
api.keystone.roles_for_user(IsA(http.HttpRequest), '3',
self.tenant.id) \
.AndReturn((roles[1],))
# remove role 2
api.keystone.remove_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user='3',
role='2')
# add role 1
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user='3',
role='1')
# Group assignments
api.keystone.group_list(IsA(http.HttpRequest),
domain=domain_id,
project=self.tenant.id).AndReturn(proj_groups)
# admin group - try to remove all roles on current project
api.keystone.roles_for_group(IsA(http.HttpRequest),
group='1',
project=self.tenant.id) \
.AndReturn(roles)
for role in roles:
api.keystone.remove_group_role(IsA(http.HttpRequest),
role=role.id,
group='1',
project=self.tenant.id)
# member group 1 - has role 1, will remove it
api.keystone.roles_for_group(IsA(http.HttpRequest),
group='2',
project=self.tenant.id) \
.AndReturn((roles[0],))
# remove role 1
api.keystone.remove_group_role(IsA(http.HttpRequest),
role='1',
group='2',
project=self.tenant.id)
# add role 2
api.keystone.add_group_role(IsA(http.HttpRequest),
role='2',
group='2',
project=self.tenant.id)
# member group 3 - has role 2
api.keystone.roles_for_group(IsA(http.HttpRequest),
group='3',
project=self.tenant.id) \
.AndReturn((roles[1],))
# remove role 2
api.keystone.remove_group_role(IsA(http.HttpRequest),
role='2',
group='3',
project=self.tenant.id)
# add role 1
api.keystone.add_group_role(IsA(http.HttpRequest),
role='1',
group='3',
project=self.tenant.id)
nova_updated_quota = dict([(key, updated_quota[key]) for key in
quotas.NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**nova_updated_quota)
cinder_updated_quota = dict([(key, updated_quota[key]) for key in
quotas.CINDER_QUOTA_FIELDS])
api.cinder.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**cinder_updated_quota)
self.mox.ReplayAll()
# submit form data
project_data = {"domain_id": project._info["domain_id"],
"name": project._info["name"],
"id": project.id,
"description": project._info["description"],
"enabled": project.enabled}
workflow_data.update(project_data)
workflow_data.update(updated_quota)
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertMessageCount(error=0, warning=1)
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.neutron: ('is_extension_supported',
'tenant_quota_get',
'tenant_quota_update')})
@override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
def test_update_project_save_with_neutron(self):
quota_data = self.neutron_quotas.first()
neutron_updated_quota = dict([(key, quota_data.get(key).limit)
for key in quotas.NEUTRON_QUOTA_FIELDS])
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
.MultipleTimes().AndReturn(True)
api.neutron.tenant_quota_get(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota_data)
api.neutron.tenant_quota_update(IsA(http.HttpRequest),
self.tenant.id,
**neutron_updated_quota)
self.test_update_project_save(neutron=True)
@test.create_stubs({api.keystone: ('tenant_get',)})
def test_update_project_get_error(self):
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
admin=True) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.keystone: ('tenant_get',
'domain_get',
'tenant_update',
'get_default_role',
'roles_for_user',
'remove_tenant_user',
'add_tenant_user_role',
'user_list',
'roles_for_group',
'remove_group_role',
'add_group_role',
'group_list',
'role_list',
'role_assignments_list'),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas'),
api.nova: ('tenant_quota_update',)})
def test_update_project_tenant_update_error(self):
keystone_api_version = api.keystone.VERSIONS.active
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
domain_id = project.domain_id
users = self._get_all_users(domain_id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
proj_users = self._get_proj_users(project.id)
role_assignments = self.role_assignments.list()
# get/init
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
admin=True) \
.AndReturn(project)
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
workflow_data = {}
if keystone_api_version >= 3:
api.keystone.role_assignments_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(role_assignments)
else:
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(proj_users)
for user in proj_users:
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(roles)
role_ids = [role.id for role in roles]
for user in proj_users:
if role_ids:
workflow_data.setdefault(USER_ROLE_PREFIX + role_ids[0], []) \
.append(user.id)
for group in groups:
api.keystone.roles_for_group(IsA(http.HttpRequest),
group=group.id,
project=self.tenant.id) \
.AndReturn(roles)
role_ids = [role.id for role in roles]
if role_ids:
workflow_data.setdefault(GROUP_ROLE_PREFIX + role_ids[0], []) \
.append(group.id)
# update some fields
project._info["domain_id"] = domain_id
project._info["name"] = "updated name"
project._info["description"] = "updated description"
quota.metadata_items = 444
quota.volumes = 444
updated_project = {"name": project._info["name"],
"description": project._info["description"],
"enabled": project.enabled}
updated_quota = self._get_quota_info(quota)
# handle
api.keystone.tenant_update(IsA(http.HttpRequest),
project.id,
**updated_project) \
.AndRaise(self.exceptions.keystone)
self.mox.ReplayAll()
# submit form data
project_data = {"domain_id": project._info["domain_id"],
"name": project._info["name"],
"id": project.id,
"description": project._info["description"],
"enabled": project.enabled}
workflow_data.update(project_data)
workflow_data.update(updated_quota)
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.keystone: ('tenant_get',
'domain_get',
'tenant_update',
'get_default_role',
'roles_for_user',
'remove_tenant_user_role',
'add_tenant_user_role',
'user_list',
'roles_for_group',
'remove_group_role',
'add_group_role',
'group_list',
'role_list',
'role_assignments_list'),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas'),
api.nova: ('tenant_quota_update',)})
def test_update_project_quota_update_error(self):
keystone_api_version = api.keystone.VERSIONS.active
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
domain_id = project.domain_id
users = self._get_all_users(domain_id)
proj_users = self._get_proj_users(project.id)
groups = self._get_all_groups(domain_id)
proj_groups = self._get_proj_groups(project.id)
roles = self.roles.list()
role_assignments = self.role_assignments.list()
# get/init
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
admin=True) \
.AndReturn(project)
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
workflow_data = {}
if keystone_api_version >= 3:
api.keystone.role_assignments_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(role_assignments)
else:
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(proj_users)
for user in proj_users:
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(roles)
for group in groups:
api.keystone.roles_for_group(IsA(http.HttpRequest),
group=group.id,
project=self.tenant.id) \
.AndReturn(roles)
workflow_data[USER_ROLE_PREFIX + "1"] = ['1', '3'] # admin role
workflow_data[USER_ROLE_PREFIX + "2"] = ['1', '2', '3'] # member role
# Group role assignment data
workflow_data[GROUP_ROLE_PREFIX + "1"] = ['1', '3'] # admin role
workflow_data[GROUP_ROLE_PREFIX + "2"] = ['1', '2', '3'] # member role
# update some fields
project._info["domain_id"] = domain_id
project._info["name"] = "updated name"
project._info["description"] = "updated description"
quota[0].limit = 444
quota[1].limit = -1
updated_project = {"name": project._info["name"],
"description": project._info["description"],
"enabled": project.enabled}
updated_quota = self._get_quota_info(quota)
# handle
api.keystone.tenant_update(IsA(http.HttpRequest),
project.id,
**updated_project) \
.AndReturn(project)
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id).AndReturn(proj_users)
# admin user - try to remove all roles on current project, warning
api.keystone.roles_for_user(IsA(http.HttpRequest), '1',
self.tenant.id) \
.AndReturn(roles)
# member user 1 - has role 1, will remove it
api.keystone.roles_for_user(IsA(http.HttpRequest), '2',
self.tenant.id) \
.AndReturn((roles[1],))
# member user 3 - has role 2
api.keystone.roles_for_user(IsA(http.HttpRequest), '3',
self.tenant.id) \
.AndReturn((roles[0],))
# add role 2
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user='3',
role='2')
# Group assignment
api.keystone.group_list(IsA(http.HttpRequest),
domain=domain_id,
project=self.tenant.id).AndReturn(proj_groups)
# admin group 1- try to remove all roles on current project
api.keystone.roles_for_group(IsA(http.HttpRequest),
group='1',
project=self.tenant.id) \
.AndReturn(roles)
# member group 1 - has no change
api.keystone.roles_for_group(IsA(http.HttpRequest),
group='2',
project=self.tenant.id) \
.AndReturn((roles[1],))
# member group 3 - has role 1
api.keystone.roles_for_group(IsA(http.HttpRequest),
group='3',
project=self.tenant.id) \
.AndReturn((roles[0],))
# add role 2
api.keystone.add_group_role(IsA(http.HttpRequest),
role='2',
group='3',
project=self.tenant.id)
nova_updated_quota = dict([(key, updated_quota[key]) for key in
quotas.NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**nova_updated_quota) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
# submit form data
project_data = {"domain_id": project._info["domain_id"],
"name": project._info["name"],
"id": project.id,
"description": project._info["description"],
"enabled": project.enabled}
workflow_data.update(project_data)
workflow_data.update(updated_quota)
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertMessageCount(error=2, warning=0)
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.keystone: ('tenant_get',
'domain_get',
'tenant_update',
'get_default_role',
'roles_for_user',
'remove_tenant_user_role',
'add_tenant_user_role',
'user_list',
'roles_for_group',
'remove_group_role',
'add_group_role',
'group_list',
'role_list',
'role_assignments_list'),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas')})
def test_update_project_member_update_error(self):
keystone_api_version = api.keystone.VERSIONS.active
project = self.tenants.first()
quota = self.quotas.first()
default_role = self.roles.first()
domain_id = project.domain_id
users = self._get_all_users(domain_id)
proj_users = self._get_proj_users(project.id)
groups = self._get_all_groups(domain_id)
roles = self.roles.list()
role_assignments = self.role_assignments.list()
# get/init
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
admin=True) \
.AndReturn(project)
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(default_role)
api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(roles)
api.keystone.group_list(IsA(http.HttpRequest), domain=domain_id) \
.AndReturn(groups)
workflow_data = {}
if keystone_api_version >= 3:
api.keystone.role_assignments_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(role_assignments)
else:
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id) \
.AndReturn(proj_users)
for user in proj_users:
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(roles)
for group in groups:
api.keystone.roles_for_group(IsA(http.HttpRequest),
group=group.id,
project=self.tenant.id) \
.AndReturn(roles)
workflow_data[USER_ROLE_PREFIX + "1"] = ['1', '3'] # admin role
workflow_data[USER_ROLE_PREFIX + "2"] = ['1', '2', '3'] # member role
workflow_data[GROUP_ROLE_PREFIX + "1"] = ['1', '3'] # admin role
workflow_data[GROUP_ROLE_PREFIX + "2"] = ['1', '2', '3'] # member role
# update some fields
project._info["domain_id"] = domain_id
project._info["name"] = "updated name"
project._info["description"] = "updated description"
quota.metadata_items = 444
quota.volumes = 444
updated_project = {"name": project._info["name"],
"description": project._info["description"],
"enabled": project.enabled}
updated_quota = self._get_quota_info(quota)
# handle
api.keystone.tenant_update(IsA(http.HttpRequest),
project.id,
**updated_project) \
.AndReturn(project)
api.keystone.user_list(IsA(http.HttpRequest),
project=self.tenant.id).AndReturn(proj_users)
# admin user - try to remove all roles on current project, warning
api.keystone.roles_for_user(IsA(http.HttpRequest), '1',
self.tenant.id).AndReturn(roles)
# member user 1 - has role 1, will remove it
api.keystone.roles_for_user(IsA(http.HttpRequest), '2',
self.tenant.id).AndReturn((roles[1],))
# member user 3 - has role 2
api.keystone.roles_for_user(IsA(http.HttpRequest), '3',
self.tenant.id).AndReturn((roles[0],))
# add role 2
api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
project=self.tenant.id,
user='3',
role='2')\
.AndRaise(self.exceptions.keystone)
self.mox.ReplayAll()
# submit form data
project_data = {"domain_id": project._info["domain_id"],
"name": project._info["name"],
"id": project.id,
"description": project._info["description"],
"enabled": project.enabled}
workflow_data.update(project_data)
workflow_data.update(updated_quota)
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertMessageCount(error=2, warning=0)
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.keystone: ('get_default_role',
'tenant_get',
'domain_get'),
quotas: ('get_tenant_quota_data',
'get_disabled_quotas')})
def test_update_project_when_default_role_does_not_exist(self):
project = self.tenants.first()
domain_id = project.domain_id
quota = self.quotas.first()
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(None) # Default role doesn't exist
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
admin=True) \
.AndReturn(project)
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
.AndReturn(self.domain)
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
.AndReturn(self.disabled_quotas.first())
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
tenant_id=self.tenant.id) \
.AndReturn(quota)
self.mox.ReplayAll()
url = reverse('horizon:admin:projects:update',
args=[self.tenant.id])
try:
# Avoid the log message in the test output when the workflow's
# step action cannot be instantiated
logging.disable(logging.ERROR)
with self.assertRaises(exceptions.NotFound):
self.client.get(url)
finally:
logging.disable(logging.NOTSET)
class UsageViewTests(test.BaseAdminViewTests):
def _stub_nova_api_calls(self, nova_stu_enabled=True):
self.mox.StubOutWithMock(api.nova, 'usage_get')
self.mox.StubOutWithMock(api.nova, 'tenant_absolute_limits')
self.mox.StubOutWithMock(api.nova, 'extension_supported')
self.mox.StubOutWithMock(api.cinder, 'tenant_absolute_limits')
api.nova.extension_supported(
'SimpleTenantUsage', IsA(http.HttpRequest)) \
.AndReturn(nova_stu_enabled)
def _stub_neutron_api_calls(self, neutron_sg_enabled=True):
self.mox.StubOutWithMock(api.neutron, 'is_extension_supported')
self.mox.StubOutWithMock(api.network, 'tenant_floating_ip_list')
if neutron_sg_enabled:
self.mox.StubOutWithMock(api.network, 'security_group_list')
api.neutron.is_extension_supported(
IsA(http.HttpRequest),
'security-group').AndReturn(neutron_sg_enabled)
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
.AndReturn(self.floating_ips.list())
if neutron_sg_enabled:
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.q_secgroups.list())
def test_usage_csv(self):
self._test_usage_csv(nova_stu_enabled=True)
def test_usage_csv_disabled(self):
self._test_usage_csv(nova_stu_enabled=False)
def _test_usage_csv(self, nova_stu_enabled=True):
now = timezone.now()
usage_obj = api.nova.NovaUsage(self.usages.first())
self._stub_nova_api_calls(nova_stu_enabled)
api.nova.extension_supported(
'SimpleTenantUsage', IsA(http.HttpRequest)) \
.AndReturn(nova_stu_enabled)
start = datetime.datetime(now.year, now.month, 1, 0, 0, 0, 0)
end = datetime.datetime(now.year, now.month, now.day, 23, 59, 59, 0)
if nova_stu_enabled:
api.nova.usage_get(IsA(http.HttpRequest),
self.tenant.id,
start, end).AndReturn(usage_obj)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
.AndReturn(self.limits['absolute'])
api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.cinder_limits['absolute'])
self._stub_neutron_api_calls()
self.mox.ReplayAll()
project_id = self.tenants.first().id
csv_url = reverse('horizon:admin:projects:usage',
args=[project_id]) + "?format=csv"
res = self.client.get(csv_url)
self.assertTemplateUsed(res, 'project/overview/usage.csv')
self.assertTrue(isinstance(res.context['usage'], usage.ProjectUsage))
hdr = ('Instance Name,VCPUs,RAM (MB),Disk (GB),Usage (Hours),'
'Uptime(Seconds),State')
self.assertContains(res, '%s\r\n' % hdr)
@unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
"The WITH_SELENIUM env variable is not set.")
class SeleniumTests(test.SeleniumAdminTestCase):
@test.create_stubs(
{api.keystone: ('tenant_list', 'tenant_get', 'tenant_update')})
def test_inline_editing_update(self):
# Tenant List
api.keystone.tenant_list(IgnoreArg(),
domain=None,
marker=None,
paginate=True) \
.AndReturn([self.tenants.list(), False])
# Edit mod
api.keystone.tenant_get(IgnoreArg(),
u'1',
admin=True) \
.AndReturn(self.tenants.list()[0])
# Update - requires get and update
api.keystone.tenant_get(IgnoreArg(),
u'1',
admin=True) \
.AndReturn(self.tenants.list()[0])
api.keystone.tenant_update(
IgnoreArg(),
u'1',
description='a test tenant.',
enabled=True,
name=u'Changed test_tenant')
# Refreshing cell with changed name
changed_tenant = copy.copy(self.tenants.list()[0])
changed_tenant.name = u'Changed test_tenant'
api.keystone.tenant_get(IgnoreArg(),
u'1',
admin=True) \
.AndReturn(changed_tenant)
self.mox.ReplayAll()
self.selenium.get("%s%s" % (self.live_server_url, INDEX_URL))
# Check the presence of the important elements
td_element = self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']")
cell_wrapper = td_element.find_element_by_class_name(
'table_cell_wrapper')
edit_button_wrapper = td_element.find_element_by_class_name(
'table_cell_action')
edit_button = edit_button_wrapper.find_element_by_tag_name('button')
# Hovering over td and clicking on edit button
action_chains = ActionChains(self.selenium)
action_chains.move_to_element(cell_wrapper).click(edit_button)
action_chains.perform()
# Waiting for the AJAX response for switching to editing mod
wait = self.ui.WebDriverWait(self.selenium, 10,
ignored_exceptions=[socket_timeout])
wait.until(lambda x: self.selenium.find_element_by_name("name__1"))
# Changing project name in cell form
td_element = self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']")
name_input = td_element.find_element_by_tag_name('input')
name_input.send_keys(keys.Keys.HOME)
name_input.send_keys("Changed ")
# Saving new project name by AJAX
td_element.find_element_by_class_name('inline-edit-submit').click()
# Waiting for the AJAX response of cell refresh
wait = self.ui.WebDriverWait(self.selenium, 10,
ignored_exceptions=[socket_timeout])
wait.until(lambda x: self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']"
"/div[@class='table_cell_wrapper']"
"/div[@class='table_cell_data_wrapper']"))
# Checking new project name after cell refresh
data_wrapper = self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']"
"/div[@class='table_cell_wrapper']"
"/div[@class='table_cell_data_wrapper']")
self.assertTrue(data_wrapper.text == u'Changed test_tenant',
"Error: saved tenant name is expected to be "
"'Changed test_tenant'")
@test.create_stubs(
{api.keystone: ('tenant_list', 'tenant_get')})
def test_inline_editing_cancel(self):
# Tenant List
api.keystone.tenant_list(IgnoreArg(),
domain=None,
marker=None,
paginate=True) \
.AndReturn([self.tenants.list(), False])
# Edit mod
api.keystone.tenant_get(IgnoreArg(),
u'1',
admin=True) \
.AndReturn(self.tenants.list()[0])
# Cancel edit mod is without the request
self.mox.ReplayAll()
self.selenium.get("%s%s" % (self.live_server_url, INDEX_URL))
# Check the presence of the important elements
td_element = self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']")
cell_wrapper = td_element.find_element_by_class_name(
'table_cell_wrapper')
edit_button_wrapper = td_element.find_element_by_class_name(
'table_cell_action')
edit_button = edit_button_wrapper.find_element_by_tag_name('button')
# Hovering over td and clicking on edit
action_chains = ActionChains(self.selenium)
action_chains.move_to_element(cell_wrapper).click(edit_button)
action_chains.perform()
# Waiting for the AJAX response for switching to editing mod
wait = self.ui.WebDriverWait(self.selenium, 10,
ignored_exceptions=[socket_timeout])
wait.until(lambda x: self.selenium.find_element_by_name("name__1"))
# Click on cancel button
td_element = self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']")
td_element.find_element_by_class_name('inline-edit-cancel').click()
# Cancel is via javascript, so it should be immediate
# Checking that tenant name is not changed
data_wrapper = self.selenium.find_element_by_xpath(
"//td[@data-update-url='/admin/projects/?action=cell_update"
"&table=tenants&cell_name=name&obj_id=1']"
"/div[@class='table_cell_wrapper']"
"/div[@class='table_cell_data_wrapper']")
self.assertTrue(data_wrapper.text == u'test_tenant',
"Error: saved tenant name is expected to be "
"'test_tenant'")
@test.create_stubs({api.keystone: ('get_default_domain',
'get_default_role',
'user_list',
'group_list',
'role_list'),
api.base: ('is_service_enabled',),
quotas: ('get_default_quota_data',)})
def test_membership_list_loads_correctly(self):
member_css_class = ".available_members"
users = self.users.list()
api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \
.MultipleTimes().AndReturn(False)
api.base.is_service_enabled(IsA(http.HttpRequest), 'volume') \
.MultipleTimes().AndReturn(False)
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
.AndReturn(self.domain)
quotas.get_default_quota_data(IsA(http.HttpRequest)) \
.AndReturn(self.quotas.first())
api.keystone.get_default_role(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(self.roles.first())
api.keystone.user_list(IsA(http.HttpRequest), domain=self.domain.id) \
.AndReturn(users)
api.keystone.role_list(IsA(http.HttpRequest)) \
.AndReturn(self.roles.list())
api.keystone.group_list(IsA(http.HttpRequest), domain=self.domain.id) \
.AndReturn(self.groups.list())
api.keystone.role_list(IsA(http.HttpRequest)) \
.AndReturn(self.roles.list())
self.mox.ReplayAll()
self.selenium.get("%s%s" % (self.live_server_url,
reverse('horizon:admin:projects:create')))
members = self.selenium.find_element_by_css_selector(member_css_class)
for user in users:
self.assertIn(user.name, members.text)
|
apache-2.0
|
[
3,
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
646,
2197,
199,
646,
2050,
199,
646,
747,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
492,
1455,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
492,
2882,
199,
199,
504,
18610,
492,
14092,
6373,
221,
327,
8151,
199,
504,
18610,
492,
29719,
221,
327,
8151,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
14,
25964,
492,
6858,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
6776,
492,
10431,
83,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
199,
504,
13869,
63,
9743,
492,
4503,
199,
504,
13869,
63,
9743,
14,
3807,
492,
22874,
199,
199,
1045,
63,
5891,
275,
747,
14,
2314,
14,
362,
360,
9139,
63,
899,
5304,
24967,
297,
756,
9,
199,
692,
543,
63,
5891,
26,
272,
687,
19481,
14,
17946,
492,
10033,
10720,
83,
221,
327,
8151,
272,
687,
19481,
14,
17946,
14,
2330,
492,
2883,
199,
199,
504,
2838,
492,
2653,
465,
2838,
63,
2593,
221,
327,
8151,
421,
199,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
6776,
26,
1080,
358,
199,
3791,
63,
15468,
63,
6351,
275,
10431,
83,
14,
10797,
63,
7823,
63,
26682,
63,
4929,
10134,
435,
2668,
3756,
12172,
199,
7823,
63,
15468,
63,
6351,
275,
10431,
83,
14,
10797,
63,
3791,
63,
26682,
63,
4929,
10134,
435,
2668,
3756,
12172,
421,
199,
32,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
4647,
63,
513,
9538,
1552,
199,
533,
377,
287,
2285,
2768,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
272,
347,
511,
63,
1080,
8,
277,
304,
267,
2986,
14,
19143,
14,
4647,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
639,
2881,
29,
403,
12,
639,
9881,
23043,
29,
549,
9,
971,
288,
1275,
8572,
779,
277,
14,
25021,
14,
513,
1062,
756,
566,
267,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
10215,
63,
2632,
9,
267,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
6776,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
291,
14,
25021,
14,
513,
1012,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
4647,
63,
513,
297,
776,
1552,
272,
347,
511,
63,
1080,
63,
1045,
63,
2261,
63,
1100,
8,
277,
304,
267,
2881,
275,
291,
14,
9756,
14,
362,
8,
344,
628,
17,
531,
267,
291,
14,
409,
4434,
6550,
8,
2261,
63,
1100,
29,
2261,
14,
344,
12,
2892,
2881,
63,
1100,
63,
354,
29,
2261,
14,
354,
9,
267,
2881,
63,
25021,
275,
359,
4647,
367,
8261,
315,
291,
14,
25021,
14,
513,
342,
2079,
340,
8261,
14,
2261,
63,
344,
508,
2881,
14,
344,
61,
267,
2986,
14,
19143,
14,
4647,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
639,
2881,
29,
2261,
14,
344,
9,
971,
490,
1275,
8572,
8,
2261,
63,
25021,
9,
267,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
10215,
63,
2632,
9,
267,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
6776,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
2881,
63,
25021,
9,
267,
291,
14,
9535,
8,
470,
12,
3886,
5633,
30,
396,
63,
2261,
9919,
5633,
9579,
421,
199,
533,
2790,
4761,
17527,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
272,
347,
485,
362,
63,
1715,
63,
815,
8,
277,
12,
2199,
304,
267,
2881,
275,
291,
423,
362,
63,
885,
63,
2261,
342,
267,
2199,
63,
815,
275,
2420,
354,
582,
2199,
14,
354,
12,
717,
298,
1802,
582,
2199,
14,
1802,
12,
717,
298,
3827,
582,
2199,
14,
3827,
12,
717,
298,
2261,
582,
2881,
14,
344,
93,
267,
372,
2199,
63,
815,
339,
347,
485,
362,
63,
8856,
63,
955,
8,
277,
12,
2199,
304,
267,
2881,
275,
291,
423,
362,
63,
885,
63,
2261,
342,
267,
2199,
63,
815,
275,
2420,
2261,
63,
344,
582,
2881,
14,
344,
12,
717,
298,
2261,
63,
354,
582,
2881,
14,
354,
12,
717,
298,
354,
582,
2199,
14,
354,
12,
717,
298,
1802,
582,
2199,
14,
1802,
12,
717,
298,
3827,
582,
2199,
14,
3827,
93,
267,
372,
2199,
63,
815,
339,
347,
485,
362,
63,
8848,
63,
815,
8,
277,
12,
12132,
304,
267,
13069,
63,
8848,
275,
291,
14,
12372,
63,
17056,
14,
2246,
342,
267,
8224,
63,
8848,
275,
291,
14,
10271,
63,
17056,
14,
2246,
342,
267,
12132,
63,
576,
275,
1052,
267,
367,
901,
315,
22874,
14,
2826,
15162,
63,
18654,
33,
63,
12767,
26,
288,
12132,
63,
576,
59,
698,
61,
275,
1109,
8,
8848,
14,
362,
8,
698,
680,
3097,
9,
267,
367,
901,
315,
22874,
14,
35,
3192,
540,
63,
18654,
33,
63,
12767,
26,
288,
12132,
63,
576,
59,
698,
61,
275,
1109,
8,
12372,
63,
8848,
14,
362,
8,
698,
680,
3097,
9,
267,
367,
901,
315,
22874,
14,
6388,
934,
12758,
63,
18654,
33,
63,
12767,
26
] |
[
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
646,
2197,
199,
646,
2050,
199,
646,
747,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
492,
1455,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
492,
2882,
199,
199,
504,
18610,
492,
14092,
6373,
221,
327,
8151,
199,
504,
18610,
492,
29719,
221,
327,
8151,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
14,
25964,
492,
6858,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
6776,
492,
10431,
83,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
199,
504,
13869,
63,
9743,
492,
4503,
199,
504,
13869,
63,
9743,
14,
3807,
492,
22874,
199,
199,
1045,
63,
5891,
275,
747,
14,
2314,
14,
362,
360,
9139,
63,
899,
5304,
24967,
297,
756,
9,
199,
692,
543,
63,
5891,
26,
272,
687,
19481,
14,
17946,
492,
10033,
10720,
83,
221,
327,
8151,
272,
687,
19481,
14,
17946,
14,
2330,
492,
2883,
199,
199,
504,
2838,
492,
2653,
465,
2838,
63,
2593,
221,
327,
8151,
421,
199,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
6776,
26,
1080,
358,
199,
3791,
63,
15468,
63,
6351,
275,
10431,
83,
14,
10797,
63,
7823,
63,
26682,
63,
4929,
10134,
435,
2668,
3756,
12172,
199,
7823,
63,
15468,
63,
6351,
275,
10431,
83,
14,
10797,
63,
3791,
63,
26682,
63,
4929,
10134,
435,
2668,
3756,
12172,
421,
199,
32,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
4647,
63,
513,
9538,
1552,
199,
533,
377,
287,
2285,
2768,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
272,
347,
511,
63,
1080,
8,
277,
304,
267,
2986,
14,
19143,
14,
4647,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
639,
2881,
29,
403,
12,
639,
9881,
23043,
29,
549,
9,
971,
288,
1275,
8572,
779,
277,
14,
25021,
14,
513,
1062,
756,
566,
267,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
10215,
63,
2632,
9,
267,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
6776,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
291,
14,
25021,
14,
513,
1012,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
4647,
63,
513,
297,
776,
1552,
272,
347,
511,
63,
1080,
63,
1045,
63,
2261,
63,
1100,
8,
277,
304,
267,
2881,
275,
291,
14,
9756,
14,
362,
8,
344,
628,
17,
531,
267,
291,
14,
409,
4434,
6550,
8,
2261,
63,
1100,
29,
2261,
14,
344,
12,
2892,
2881,
63,
1100,
63,
354,
29,
2261,
14,
354,
9,
267,
2881,
63,
25021,
275,
359,
4647,
367,
8261,
315,
291,
14,
25021,
14,
513,
342,
2079,
340,
8261,
14,
2261,
63,
344,
508,
2881,
14,
344,
61,
267,
2986,
14,
19143,
14,
4647,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
639,
2881,
29,
2261,
14,
344,
9,
971,
490,
1275,
8572,
8,
2261,
63,
25021,
9,
267,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
10215,
63,
2632,
9,
267,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
6776,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
2881,
63,
25021,
9,
267,
291,
14,
9535,
8,
470,
12,
3886,
5633,
30,
396,
63,
2261,
9919,
5633,
9579,
421,
199,
533,
2790,
4761,
17527,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
272,
347,
485,
362,
63,
1715,
63,
815,
8,
277,
12,
2199,
304,
267,
2881,
275,
291,
423,
362,
63,
885,
63,
2261,
342,
267,
2199,
63,
815,
275,
2420,
354,
582,
2199,
14,
354,
12,
717,
298,
1802,
582,
2199,
14,
1802,
12,
717,
298,
3827,
582,
2199,
14,
3827,
12,
717,
298,
2261,
582,
2881,
14,
344,
93,
267,
372,
2199,
63,
815,
339,
347,
485,
362,
63,
8856,
63,
955,
8,
277,
12,
2199,
304,
267,
2881,
275,
291,
423,
362,
63,
885,
63,
2261,
342,
267,
2199,
63,
815,
275,
2420,
2261,
63,
344,
582,
2881,
14,
344,
12,
717,
298,
2261,
63,
354,
582,
2881,
14,
354,
12,
717,
298,
354,
582,
2199,
14,
354,
12,
717,
298,
1802,
582,
2199,
14,
1802,
12,
717,
298,
3827,
582,
2199,
14,
3827,
93,
267,
372,
2199,
63,
815,
339,
347,
485,
362,
63,
8848,
63,
815,
8,
277,
12,
12132,
304,
267,
13069,
63,
8848,
275,
291,
14,
12372,
63,
17056,
14,
2246,
342,
267,
8224,
63,
8848,
275,
291,
14,
10271,
63,
17056,
14,
2246,
342,
267,
12132,
63,
576,
275,
1052,
267,
367,
901,
315,
22874,
14,
2826,
15162,
63,
18654,
33,
63,
12767,
26,
288,
12132,
63,
576,
59,
698,
61,
275,
1109,
8,
8848,
14,
362,
8,
698,
680,
3097,
9,
267,
367,
901,
315,
22874,
14,
35,
3192,
540,
63,
18654,
33,
63,
12767,
26,
288,
12132,
63,
576,
59,
698,
61,
275,
1109,
8,
12372,
63,
8848,
14,
362,
8,
698,
680,
3097,
9,
267,
367,
901,
315,
22874,
14,
6388,
934,
12758,
63,
18654,
33,
63,
12767,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
leleopard/pyXPArduino
|
avrdude/__init__.py
|
1
|
4001
|
"""
WORKING COMMAND:
./avrdude-x64 -p ATmega2560 -c wiring -P /dev/ttyACM0 -b 115200 -U flash:w:../XPArduinoSerial.ino.mega.hex -C ./avrdude.conf -D
Copyright 2011 Ryan Fobel
This file is part of dmf_control_board.
dmf_control_board 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.
dmf_control_board 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 dmf_control_board. If not, see <http://www.gnu.org/licenses/>.
"""
import os
from subprocess import Popen, PIPE, CalledProcessError
import logging
import platform
from path_helpers import path
from serial_device import SerialDevice, ConnectionError
logger = logging.getLogger()
class FirmwareError(Exception):
pass
class AvrDude(SerialDevice):
def __init__(self, protocol, microcontroller, baud_rate, conf_path=None,
port=None):
self.protocol = protocol
self.microcontroller = microcontroller
self.baud_rate = baud_rate
p = path(os.path.abspath(os.path.dirname(__file__)))
if os.name == 'nt':
self.avrdude = (p / path('avrdude.exe')).abspath()
elif platform.architecture()[0] == '64bit':
self.avrdude = (p / path('avrdude-x64')).abspath()
else:
self.avrdude = (p / path('avrdude')).abspath()
logger.info("avrdude path=%s" % self.avrdude)
if not self.avrdude.exists():
raise FirmwareError('avrdude not installed')
if conf_path is None:
self.avrconf = (p / path('avrdude.conf')).abspath()
else:
self.avrconf = path(conf_path).abspath()
if port:
self.port = port
logger.info('avrdude set to connect on port: %s' % self.port)
else:
# No serial-port was specified. Call `SerialDevice.get_port`
# method to iterate through each available serial-port until a
# connection is successfully made.
self.port = self.get_port(baud_rate)
logger.info('avrdude successfully connected on port: %s' %
self.port)
def _run_command(self, flags):
config = dict(avrdude=self.avrdude, avrconf=self.avrconf)
cmd = ['%(avrdude)s'] + flags
cmd = [v % config for v in cmd]
logger.info(' '.join(cmd))
p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
stdout, stderr = p.communicate()
if p.returncode:
raise ConnectionError(stderr)
return stdout, stderr
def flash(self, hex_path, extra_flags=None):
hex_path = path(hex_path)
flags = ['-c', self.protocol, '-b', str(self.baud_rate), '-p',
self.microcontroller, '-P', '%s' % self.port, '-U',
'flash:w:%s:i' % hex_path.name, '-C', '%(avrconf)s']
if extra_flags is not None:
flags.extend(extra_flags)
try:
cwd = os.getcwd()
os.chdir(hex_path.parent)
stdout, stderr = self._run_command(flags)
finally:
os.chdir(cwd)
return stdout, stderr
def test_connection(self, port, baud_rate):
'''
This method is called by the `get_port` method for each available
serial-port on the system until a value of `True` is returned.
'''
flags = ['-c', self.protocol, '-b', str(baud_rate), '-p',
self.microcontroller, '-P', port, '-C', '%(avrconf)s', '-n']
try:
self._run_command(flags)
except (ConnectionError, CalledProcessError):
return False
return True
|
gpl-3.0
|
[
624,
199,
199,
8406,
1206,
25965,
26,
199,
13186,
1214,
82,
2033,
271,
13,
88,
772,
446,
80,
15059,
29073,
28999,
446,
67,
336,
16648,
446,
48,
1182,
2374,
15,
4707,
1348,
45,
16,
446,
66,
22560,
1840,
446,
53,
14775,
26,
87,
26,
5093,
20168,
31924,
10175,
3571,
14,
10175,
14,
29073,
14,
4097,
446,
35,
16605,
1214,
82,
2033,
271,
14,
2190,
446,
36,
421,
199,
7384,
7760,
820,
89,
290,
481,
2873,
352,
199,
199,
2765,
570,
365,
1777,
402,
366,
11821,
63,
2785,
63,
3576,
14,
199,
199,
17104,
63,
2785,
63,
3576,
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,
17104,
63,
2785,
63,
3576,
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,
366,
11821,
63,
2785,
63,
3576,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
199,
646,
747,
199,
504,
3873,
492,
13995,
12,
22773,
12,
12295,
19148,
199,
646,
2050,
199,
646,
4298,
199,
199,
504,
931,
63,
7546,
492,
931,
199,
504,
3012,
63,
1782,
492,
11973,
2510,
12,
25417,
421,
199,
2921,
275,
2050,
14,
5572,
342,
421,
199,
533,
481,
20678,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
437,
10922,
36,
3786,
8,
3571,
2510,
304,
272,
347,
636,
826,
721,
277,
12,
4113,
12,
9967,
5538,
12,
19325,
1181,
63,
1866,
12,
3743,
63,
515,
29,
403,
12,
326,
1844,
29,
403,
304,
267,
291,
14,
3922,
275,
4113,
267,
291,
14,
6453,
5538,
275,
9967,
5538,
267,
291,
14,
2470,
1181,
63,
1866,
275,
19325,
1181,
63,
1866,
398,
299,
275,
931,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
29658,
267,
340,
747,
14,
354,
508,
283,
343,
356,
288,
291,
14,
1214,
82,
2033,
271,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
14,
5803,
11103,
4832,
342,
267,
916,
4298,
14,
19134,
3430,
16,
61,
508,
283,
772,
2075,
356,
288,
291,
14,
1214,
82,
2033,
271,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
13,
88,
772,
11103,
4832,
342,
267,
587,
26,
288,
291,
14,
1214,
82,
2033,
271,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
11103,
4832,
342,
267,
2512,
14,
815,
480,
1214,
82,
2033,
271,
931,
2458,
83,
2,
450,
291,
14,
1214,
82,
2033,
271,
9,
267,
340,
440,
291,
14,
1214,
82,
2033,
271,
14,
2444,
837,
288,
746,
481,
20678,
547,
360,
1214,
82,
2033,
271,
440,
4903,
358,
267,
340,
3743,
63,
515,
365,
488,
26,
288,
291,
14,
1214,
82,
2190,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
14,
2190,
11103,
4832,
342,
267,
587,
26,
288,
291,
14,
1214,
82,
2190,
275,
931,
8,
2190,
63,
515,
680,
4832,
342,
267,
340,
1844,
26,
288,
291,
14,
719,
275,
1844,
288,
2512,
14,
815,
360,
1214,
82,
2033,
271,
663,
370,
4907,
641,
1844,
26,
450,
83,
7,
450,
291,
14,
719,
9,
267,
587,
26,
288,
327,
3091,
3012,
13,
719,
1990,
2013,
14,
221,
6523,
658,
3571,
2510,
14,
362,
63,
719,
64,
288,
327,
1083,
370,
13974,
4012,
1924,
2808,
3012,
13,
719,
5133,
282,
288,
327,
1950,
365,
8792,
6326,
14,
288,
291,
14,
719,
275,
291,
14,
362,
63,
719,
8,
2470,
1181,
63,
1866,
9,
288,
2512,
14,
815,
360,
1214,
82,
2033,
271,
8792,
8539,
641,
1844,
26,
450,
83,
7,
450,
717,
291,
14,
719,
9,
339,
347,
485,
1065,
63,
1531,
8,
277,
12,
3285,
304,
267,
1101,
275,
1211,
8,
1214,
82,
2033,
271,
29,
277,
14,
1214,
82,
2033,
271,
12,
2289,
82,
2190,
29,
277,
14,
1214,
82,
2190,
9,
398,
2088,
275,
788,
2840,
1214,
82,
2033,
271,
9,
83,
418,
435,
3285,
267,
2088,
275,
359,
86,
450,
1101,
367,
373,
315,
2088,
61,
398,
2512,
14,
815,
360,
1987,
904,
8,
1760,
430,
267,
299,
275,
13995,
8,
1760,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
9009,
29,
6089,
9,
267,
3839,
12,
4635,
275,
299,
14,
10664,
342,
267,
340,
299,
14,
9913,
26,
288,
746,
25417,
8,
3083,
9,
267,
372,
3839,
12,
4635,
339,
347,
14775,
8,
277,
12,
6318,
63,
515,
12,
2402,
63,
2469,
29,
403,
304,
267,
6318,
63,
515,
275,
931,
8,
4097,
63,
515,
9,
267,
3285,
275,
11573,
67,
297,
291,
14,
3922,
12,
2475,
66,
297,
620,
8,
277,
14,
2470,
1181,
63,
1866,
395,
2475,
80,
297,
326,
291,
14,
6453,
5538,
12,
2475,
48,
297,
1543,
83,
7,
450,
291,
14,
719,
12,
2475,
53,
297,
326,
283,
11331,
26,
87,
2689,
83,
26,
73,
7,
450,
6318,
63,
515,
14,
354,
12,
2475,
35,
297,
9487,
1214,
82,
2190,
9,
83,
418,
267,
340,
2402,
63,
2469,
365,
440,
488,
26,
288,
3285,
14,
2880,
8,
2911,
63,
2469,
9,
398,
862,
26,
288,
8288,
275,
747,
14,
9458,
342,
288,
747,
14,
8563,
8,
4097,
63,
515,
14,
1708,
9,
288,
3839,
12,
4635,
275,
291,
423,
1065,
63,
1531,
8,
2469,
9,
267,
3753,
26,
288,
747,
14,
8563,
8,
6525,
9,
267,
372,
3839,
12,
4635,
339,
347,
511,
63,
2105,
8,
277,
12,
1844,
12,
19325,
1181,
63,
1866,
304,
267,
1449,
267,
961,
1083,
365,
2797,
701,
314,
658,
362,
63,
719,
64,
1083,
367,
1924,
2808,
267,
3012,
13,
719,
641,
314,
2656,
5133,
282,
574,
402,
658,
549,
64,
365,
2138,
14,
267,
1449,
267,
3285,
275,
11573,
67,
297,
291,
14,
3922
] |
[
199,
199,
8406,
1206,
25965,
26,
199,
13186,
1214,
82,
2033,
271,
13,
88,
772,
446,
80,
15059,
29073,
28999,
446,
67,
336,
16648,
446,
48,
1182,
2374,
15,
4707,
1348,
45,
16,
446,
66,
22560,
1840,
446,
53,
14775,
26,
87,
26,
5093,
20168,
31924,
10175,
3571,
14,
10175,
14,
29073,
14,
4097,
446,
35,
16605,
1214,
82,
2033,
271,
14,
2190,
446,
36,
421,
199,
7384,
7760,
820,
89,
290,
481,
2873,
352,
199,
199,
2765,
570,
365,
1777,
402,
366,
11821,
63,
2785,
63,
3576,
14,
199,
199,
17104,
63,
2785,
63,
3576,
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,
17104,
63,
2785,
63,
3576,
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,
366,
11821,
63,
2785,
63,
3576,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
199,
646,
747,
199,
504,
3873,
492,
13995,
12,
22773,
12,
12295,
19148,
199,
646,
2050,
199,
646,
4298,
199,
199,
504,
931,
63,
7546,
492,
931,
199,
504,
3012,
63,
1782,
492,
11973,
2510,
12,
25417,
421,
199,
2921,
275,
2050,
14,
5572,
342,
421,
199,
533,
481,
20678,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
437,
10922,
36,
3786,
8,
3571,
2510,
304,
272,
347,
636,
826,
721,
277,
12,
4113,
12,
9967,
5538,
12,
19325,
1181,
63,
1866,
12,
3743,
63,
515,
29,
403,
12,
326,
1844,
29,
403,
304,
267,
291,
14,
3922,
275,
4113,
267,
291,
14,
6453,
5538,
275,
9967,
5538,
267,
291,
14,
2470,
1181,
63,
1866,
275,
19325,
1181,
63,
1866,
398,
299,
275,
931,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
29658,
267,
340,
747,
14,
354,
508,
283,
343,
356,
288,
291,
14,
1214,
82,
2033,
271,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
14,
5803,
11103,
4832,
342,
267,
916,
4298,
14,
19134,
3430,
16,
61,
508,
283,
772,
2075,
356,
288,
291,
14,
1214,
82,
2033,
271,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
13,
88,
772,
11103,
4832,
342,
267,
587,
26,
288,
291,
14,
1214,
82,
2033,
271,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
11103,
4832,
342,
267,
2512,
14,
815,
480,
1214,
82,
2033,
271,
931,
2458,
83,
2,
450,
291,
14,
1214,
82,
2033,
271,
9,
267,
340,
440,
291,
14,
1214,
82,
2033,
271,
14,
2444,
837,
288,
746,
481,
20678,
547,
360,
1214,
82,
2033,
271,
440,
4903,
358,
267,
340,
3743,
63,
515,
365,
488,
26,
288,
291,
14,
1214,
82,
2190,
275,
334,
80,
1182,
931,
360,
1214,
82,
2033,
271,
14,
2190,
11103,
4832,
342,
267,
587,
26,
288,
291,
14,
1214,
82,
2190,
275,
931,
8,
2190,
63,
515,
680,
4832,
342,
267,
340,
1844,
26,
288,
291,
14,
719,
275,
1844,
288,
2512,
14,
815,
360,
1214,
82,
2033,
271,
663,
370,
4907,
641,
1844,
26,
450,
83,
7,
450,
291,
14,
719,
9,
267,
587,
26,
288,
327,
3091,
3012,
13,
719,
1990,
2013,
14,
221,
6523,
658,
3571,
2510,
14,
362,
63,
719,
64,
288,
327,
1083,
370,
13974,
4012,
1924,
2808,
3012,
13,
719,
5133,
282,
288,
327,
1950,
365,
8792,
6326,
14,
288,
291,
14,
719,
275,
291,
14,
362,
63,
719,
8,
2470,
1181,
63,
1866,
9,
288,
2512,
14,
815,
360,
1214,
82,
2033,
271,
8792,
8539,
641,
1844,
26,
450,
83,
7,
450,
717,
291,
14,
719,
9,
339,
347,
485,
1065,
63,
1531,
8,
277,
12,
3285,
304,
267,
1101,
275,
1211,
8,
1214,
82,
2033,
271,
29,
277,
14,
1214,
82,
2033,
271,
12,
2289,
82,
2190,
29,
277,
14,
1214,
82,
2190,
9,
398,
2088,
275,
788,
2840,
1214,
82,
2033,
271,
9,
83,
418,
435,
3285,
267,
2088,
275,
359,
86,
450,
1101,
367,
373,
315,
2088,
61,
398,
2512,
14,
815,
360,
1987,
904,
8,
1760,
430,
267,
299,
275,
13995,
8,
1760,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
9009,
29,
6089,
9,
267,
3839,
12,
4635,
275,
299,
14,
10664,
342,
267,
340,
299,
14,
9913,
26,
288,
746,
25417,
8,
3083,
9,
267,
372,
3839,
12,
4635,
339,
347,
14775,
8,
277,
12,
6318,
63,
515,
12,
2402,
63,
2469,
29,
403,
304,
267,
6318,
63,
515,
275,
931,
8,
4097,
63,
515,
9,
267,
3285,
275,
11573,
67,
297,
291,
14,
3922,
12,
2475,
66,
297,
620,
8,
277,
14,
2470,
1181,
63,
1866,
395,
2475,
80,
297,
326,
291,
14,
6453,
5538,
12,
2475,
48,
297,
1543,
83,
7,
450,
291,
14,
719,
12,
2475,
53,
297,
326,
283,
11331,
26,
87,
2689,
83,
26,
73,
7,
450,
6318,
63,
515,
14,
354,
12,
2475,
35,
297,
9487,
1214,
82,
2190,
9,
83,
418,
267,
340,
2402,
63,
2469,
365,
440,
488,
26,
288,
3285,
14,
2880,
8,
2911,
63,
2469,
9,
398,
862,
26,
288,
8288,
275,
747,
14,
9458,
342,
288,
747,
14,
8563,
8,
4097,
63,
515,
14,
1708,
9,
288,
3839,
12,
4635,
275,
291,
423,
1065,
63,
1531,
8,
2469,
9,
267,
3753,
26,
288,
747,
14,
8563,
8,
6525,
9,
267,
372,
3839,
12,
4635,
339,
347,
511,
63,
2105,
8,
277,
12,
1844,
12,
19325,
1181,
63,
1866,
304,
267,
1449,
267,
961,
1083,
365,
2797,
701,
314,
658,
362,
63,
719,
64,
1083,
367,
1924,
2808,
267,
3012,
13,
719,
641,
314,
2656,
5133,
282,
574,
402,
658,
549,
64,
365,
2138,
14,
267,
1449,
267,
3285,
275,
11573,
67,
297,
291,
14,
3922,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
naturali/tensorflow
|
tensorflow/python/kernel_tests/conv3d_backprop_filter_v2_grad_test.py
|
25
|
2440
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for convolution related functionality in tensorflow.ops.nn."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
class Conv3DBackpropFilterV2GradTest(tf.test.TestCase):
def testGradient(self):
with self.test_session():
for padding in ["SAME", "VALID"]:
for stride in [1, 2]:
np.random.seed(1)
in_shape = [2, 4, 3, 3, 2]
in_val = tf.constant(
2 * np.random.random_sample(in_shape) - 1,
dtype=tf.float32)
filter_shape = [3, 3, 3, 2, 3]
strides = [1, stride, stride, stride, 1]
# Make a convolution op with the current settings, just to easily get
# the shape of the output.
conv_out = tf.nn.conv3d(in_val, tf.zeros(filter_shape), strides,
padding)
out_backprop_shape = conv_out.get_shape().as_list()
out_backprop_val = tf.constant(
2 * np.random.random_sample(out_backprop_shape) - 1,
dtype=tf.float32)
output = tf.nn.conv3d_backprop_filter_v2(in_val, filter_shape,
out_backprop_val,
strides, padding)
err = tf.test.compute_gradient_error([in_val, out_backprop_val],
[in_shape, out_backprop_shape],
output, filter_shape)
print("conv3d_backprop_filter gradient err = %g " % err)
err_tolerance = 1e-3
self.assertLess(err, err_tolerance)
if __name__ == "__main__":
tf.test.main()
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
2925,
367,
17461,
4048,
9330,
315,
3228,
14,
1483,
14,
4411,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
646,
3228,
465,
2833,
421,
199,
533,
19140,
19,
2846,
564,
4469,
4131,
54,
18,
14812,
774,
8,
3249,
14,
396,
14,
1746,
304,
819,
347,
511,
9942,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
367,
6273,
315,
2097,
19935,
401,
298,
5600,
6229,
267,
367,
7345,
315,
359,
17,
12,
499,
2189,
881,
980,
14,
2355,
14,
5176,
8,
17,
9,
881,
315,
63,
1392,
275,
359,
18,
12,
841,
12,
650,
12,
650,
12,
499,
61,
881,
315,
63,
637,
275,
2833,
14,
4083,
8,
1598,
499,
627,
980,
14,
2355,
14,
2355,
63,
3271,
8,
262,
63,
1392,
9,
446,
413,
12,
1598,
2152,
29,
3249,
14,
1609,
708,
9,
881,
2457,
63,
1392,
275,
359,
19,
12,
650,
12,
650,
12,
499,
12,
650,
61,
881,
11883,
275,
359,
17,
12,
7345,
12,
7345,
12,
7345,
12,
413,
61,
881,
327,
4155,
282,
17461,
1687,
543,
314,
1453,
2202,
12,
2951,
370,
16174,
664,
881,
327,
314,
2215,
402,
314,
1072,
14,
881,
8260,
63,
548,
275,
2833,
14,
4411,
14,
5598,
19,
68,
8,
262,
63,
637,
12,
2833,
14,
4250,
8,
1541,
63,
1392,
395,
11883,
12,
3303,
6273,
9,
881,
734,
63,
31113,
63,
1392,
275,
8260,
63,
548,
14,
362,
63,
1392,
1252,
305,
63,
513,
342,
881,
734,
63,
31113,
63,
637,
275,
2833,
14,
4083,
8,
1598,
499,
627,
980,
14,
2355,
14,
2355,
63,
3271,
8,
548,
63,
31113,
63,
1392,
9,
446,
413,
12,
1598,
2152,
29,
3249,
14,
1609,
708,
9,
881,
1072,
275,
2833,
14,
4411,
14,
5598,
19,
68,
63,
31113,
63,
1541,
63,
86,
18,
8,
262,
63,
637,
12,
2457,
63,
1392,
12,
8962,
734,
63,
31113,
63,
637,
12,
8962,
11883,
12,
6273,
9,
881,
2329,
275,
2833,
14,
396,
14,
3357,
63,
7490,
63,
705,
779,
262,
63,
637,
12,
734,
63,
31113,
63,
637,
467,
6901,
359,
262,
63,
1392,
12,
734,
63,
31113,
63,
1392,
467,
6901,
1072,
12,
2457,
63,
1392,
9,
881,
870,
480,
5598,
19,
68,
63,
31113,
63,
1541,
6709,
2329,
275,
450,
71,
298,
450,
2329,
9,
881,
2329,
63,
16312,
275,
413,
69,
13,
19,
881,
291,
14,
15625,
8,
1508,
12,
2329,
63,
16312,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
2833,
14,
396,
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
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
2925,
367,
17461,
4048,
9330,
315,
3228,
14,
1483,
14,
4411,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
646,
3228,
465,
2833,
421,
199,
533,
19140,
19,
2846,
564,
4469,
4131,
54,
18,
14812,
774,
8,
3249,
14,
396,
14,
1746,
304,
819,
347,
511,
9942,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
367,
6273,
315,
2097,
19935,
401,
298,
5600,
6229,
267,
367,
7345,
315,
359,
17,
12,
499,
2189,
881,
980,
14,
2355,
14,
5176,
8,
17,
9,
881,
315,
63,
1392,
275,
359,
18,
12,
841,
12,
650,
12,
650,
12,
499,
61,
881,
315,
63,
637,
275,
2833,
14,
4083,
8,
1598,
499,
627,
980,
14,
2355,
14,
2355,
63,
3271,
8,
262,
63,
1392,
9,
446,
413,
12,
1598,
2152,
29,
3249,
14,
1609,
708,
9,
881,
2457,
63,
1392,
275,
359,
19,
12,
650,
12,
650,
12,
499,
12,
650,
61,
881,
11883,
275,
359,
17,
12,
7345,
12,
7345,
12,
7345,
12,
413,
61,
881,
327,
4155,
282,
17461,
1687,
543,
314,
1453,
2202,
12,
2951,
370,
16174,
664,
881,
327,
314,
2215,
402,
314,
1072,
14,
881,
8260,
63,
548,
275,
2833,
14,
4411,
14,
5598,
19,
68,
8,
262,
63,
637,
12,
2833,
14,
4250,
8,
1541,
63,
1392,
395,
11883,
12,
3303,
6273,
9,
881,
734,
63,
31113,
63,
1392,
275,
8260,
63,
548,
14,
362,
63,
1392,
1252,
305,
63,
513,
342,
881,
734,
63,
31113,
63,
637,
275,
2833,
14,
4083,
8,
1598,
499,
627,
980,
14,
2355,
14,
2355,
63,
3271,
8,
548,
63,
31113,
63,
1392,
9,
446,
413,
12,
1598,
2152,
29,
3249,
14,
1609,
708,
9,
881,
1072,
275,
2833,
14,
4411,
14,
5598,
19,
68,
63,
31113,
63,
1541,
63,
86,
18,
8,
262,
63,
637,
12,
2457,
63,
1392,
12,
8962,
734,
63,
31113,
63,
637,
12,
8962,
11883,
12,
6273,
9,
881,
2329,
275,
2833,
14,
396,
14,
3357,
63,
7490,
63,
705,
779,
262,
63,
637,
12,
734,
63,
31113,
63,
637,
467,
6901,
359,
262,
63,
1392,
12,
734,
63,
31113,
63,
1392,
467,
6901,
1072,
12,
2457,
63,
1392,
9,
881,
870,
480,
5598,
19,
68,
63,
31113,
63,
1541,
6709,
2329,
275,
450,
71,
298,
450,
2329,
9,
881,
2329,
63,
16312,
275,
413,
69,
13,
19,
881,
291,
14,
15625,
8,
1508,
12,
2329,
63,
16312,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
2833,
14,
396,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wuzhy/autotest
|
frontend/migrations/059_drone_sets_permissions.py
|
5
|
1333
|
import common
from autotest_lib.database import db_utils
UP_SQL = """
SET @group_id = (SELECT id FROM auth_group WHERE name = 'Basic Admin');
INSERT IGNORE INTO auth_group_permissions (group_id, permission_id)
SELECT @group_id, id FROM auth_permission WHERE codename IN (
'add_droneset', 'change_droneset', 'delete_droneset', 'add_drone',
'change_drone', 'delete_drone');
"""
DOWN_SQL = """
DELETE auth_group_permissions.* FROM
auth_group INNER JOIN auth_group_permissions ON (
auth_group.id = auth_group_permissions.group_id)
INNER JOIN auth_permission ON (
auth_group_permissions.permission_id = auth_permission.id)
WHERE auth_group.name = 'Basic Admin' AND codename IN (
'add_droneset', 'change_droneset', 'delete_droneset', 'add_drone',
'change_drone', 'delete_drone');
"""
def migrate_up(manager):
"""
If the auth tables don't exist, we shouldn't try to set the permissions.
The auth tables will exist if this is an existing Autotest installation. If
they don't, then this is a fresh installation, and the user will run
`manage.py syncdb` later, which will add the proper permissions.
"""
if db_utils.auth_tables_exist(manager):
manager.execute_script(UP_SQL)
def migrate_down(manager):
if db_utils.auth_tables_exist(manager):
manager.execute_script(DOWN_SQL)
|
gpl-2.0
|
[
646,
2863,
199,
504,
2599,
396,
63,
773,
14,
4659,
492,
1592,
63,
1208,
199,
199,
2160,
63,
4657,
275,
408,
199,
3597,
768,
923,
63,
344,
275,
334,
4859,
1305,
4442,
1790,
63,
923,
6038,
536,
275,
283,
6845,
9516,
11339,
199,
199,
10258,
27499,
5788,
12872,
1790,
63,
923,
63,
6060,
334,
923,
63,
344,
12,
4983,
63,
344,
9,
199,
4859,
768,
923,
63,
344,
12,
1305,
4442,
1790,
63,
5693,
6038,
29754,
1621,
334,
523,
283,
525,
63,
5012,
368,
409,
297,
283,
1461,
63,
5012,
368,
409,
297,
283,
1807,
63,
5012,
368,
409,
297,
283,
525,
63,
5012,
368,
297,
523,
283,
1461,
63,
5012,
368,
297,
283,
1807,
63,
5012,
368,
11339,
199,
624,
199,
199,
8819,
63,
4657,
275,
408,
199,
7014,
1790,
63,
923,
63,
6060,
2795,
4442,
199,
1178,
63,
923,
32272,
10593,
1790,
63,
923,
63,
6060,
5258,
334,
523,
1790,
63,
923,
14,
344,
275,
1790,
63,
923,
63,
6060,
14,
923,
63,
344,
9,
199,
31031,
10593,
1790,
63,
5693,
5258,
334,
523,
1790,
63,
923,
63,
6060,
14,
5693,
63,
344,
275,
1790,
63,
5693,
14,
344,
9,
199,
17688,
1790,
63,
923,
14,
354,
275,
283,
6845,
9516,
7,
2401,
29754,
1621,
334,
523,
283,
525,
63,
5012,
368,
409,
297,
283,
1461,
63,
5012,
368,
409,
297,
283,
1807,
63,
5012,
368,
409,
297,
283,
525,
63,
5012,
368,
297,
523,
283,
1461,
63,
5012,
368,
297,
283,
1807,
63,
5012,
368,
11339,
199,
624,
421,
199,
318,
12810,
63,
384,
8,
2609,
304,
272,
408,
272,
982,
314,
1790,
6716,
2793,
1133,
2187,
12,
781,
9296,
1133,
862,
370,
663,
314,
3443,
14,
339,
710,
1790,
6716,
911,
2187,
340,
642,
365,
376,
3411,
9195,
396,
12096,
14,
982,
272,
2985,
2793,
1133,
12,
2066,
642,
365,
282,
17480,
12096,
12,
436,
314,
922,
911,
1255,
272,
658,
9053,
14,
647,
7604,
697,
64,
2945,
12,
1314,
911,
1050,
314,
5576,
3443,
14,
272,
408,
272,
340,
1592,
63,
1208,
14,
1178,
63,
5987,
63,
4494,
8,
2609,
304,
267,
5256,
14,
2526,
63,
1579,
8,
2160,
63,
4657,
9,
421,
199,
318,
12810,
63,
2110,
8,
2609,
304,
272,
340,
1592,
63,
1208,
14,
1178,
63,
5987,
63,
4494,
8,
2609,
304,
267,
5256,
14,
2526,
63,
1579,
8,
8819,
63,
4657,
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
] |
[
2863,
199,
504,
2599,
396,
63,
773,
14,
4659,
492,
1592,
63,
1208,
199,
199,
2160,
63,
4657,
275,
408,
199,
3597,
768,
923,
63,
344,
275,
334,
4859,
1305,
4442,
1790,
63,
923,
6038,
536,
275,
283,
6845,
9516,
11339,
199,
199,
10258,
27499,
5788,
12872,
1790,
63,
923,
63,
6060,
334,
923,
63,
344,
12,
4983,
63,
344,
9,
199,
4859,
768,
923,
63,
344,
12,
1305,
4442,
1790,
63,
5693,
6038,
29754,
1621,
334,
523,
283,
525,
63,
5012,
368,
409,
297,
283,
1461,
63,
5012,
368,
409,
297,
283,
1807,
63,
5012,
368,
409,
297,
283,
525,
63,
5012,
368,
297,
523,
283,
1461,
63,
5012,
368,
297,
283,
1807,
63,
5012,
368,
11339,
199,
624,
199,
199,
8819,
63,
4657,
275,
408,
199,
7014,
1790,
63,
923,
63,
6060,
2795,
4442,
199,
1178,
63,
923,
32272,
10593,
1790,
63,
923,
63,
6060,
5258,
334,
523,
1790,
63,
923,
14,
344,
275,
1790,
63,
923,
63,
6060,
14,
923,
63,
344,
9,
199,
31031,
10593,
1790,
63,
5693,
5258,
334,
523,
1790,
63,
923,
63,
6060,
14,
5693,
63,
344,
275,
1790,
63,
5693,
14,
344,
9,
199,
17688,
1790,
63,
923,
14,
354,
275,
283,
6845,
9516,
7,
2401,
29754,
1621,
334,
523,
283,
525,
63,
5012,
368,
409,
297,
283,
1461,
63,
5012,
368,
409,
297,
283,
1807,
63,
5012,
368,
409,
297,
283,
525,
63,
5012,
368,
297,
523,
283,
1461,
63,
5012,
368,
297,
283,
1807,
63,
5012,
368,
11339,
199,
624,
421,
199,
318,
12810,
63,
384,
8,
2609,
304,
272,
408,
272,
982,
314,
1790,
6716,
2793,
1133,
2187,
12,
781,
9296,
1133,
862,
370,
663,
314,
3443,
14,
339,
710,
1790,
6716,
911,
2187,
340,
642,
365,
376,
3411,
9195,
396,
12096,
14,
982,
272,
2985,
2793,
1133,
12,
2066,
642,
365,
282,
17480,
12096,
12,
436,
314,
922,
911,
1255,
272,
658,
9053,
14,
647,
7604,
697,
64,
2945,
12,
1314,
911,
1050,
314,
5576,
3443,
14,
272,
408,
272,
340,
1592,
63,
1208,
14,
1178,
63,
5987,
63,
4494,
8,
2609,
304,
267,
5256,
14,
2526,
63,
1579,
8,
2160,
63,
4657,
9,
421,
199,
318,
12810,
63,
2110,
8,
2609,
304,
272,
340,
1592,
63,
1208,
14,
1178,
63,
5987,
63,
4494,
8,
2609,
304,
267,
5256,
14,
2526,
63,
1579,
8,
8819,
63,
4657,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MarvinT/pyMNE
|
pyMNE.py
|
1
|
6335
|
import scipy.optimize as opt
import numpy as np
def log_loss(p, stim, resp, order):
#get number of samples and dimensionality of stimulus
Nsamples, Ndim = stim.shape
resp = np.reshape(resp, (-1))
#unpack p: (var names match names in Fitzgerald paper)
a = p[0]
h = p[1:Ndim+1].T
#case: second order calculation --> need J
if order > 1:
#reshape J into Ndim x Ndim matrix:
J = np.reshape(p[Ndim+1:Ndim+1+Ndim**2], (Ndim,Ndim)).T
if order == 1:
f1 = 1 + np.exp( a + stim.dot(h))
f0 = 1 + np.exp(-a - stim.dot(h))
else:
f1 = 1 + np.exp( a + stim.dot(h) + (np.sum(stim * (stim.dot(J)),1)))
f0 = 1 + np.exp(-a - stim.dot(h) - (np.sum(stim * (stim.dot(J)),1)))
F1 = resp * np.log(f1)
F0 = (1 - resp) * np.log(f0)
F1[np.isnan(F1)] = 0
F0[np.isnan(F0)] = 0
return np.mean(F0 + F1)
def d_log_loss(p,stim,avgs,order):
#get number of samples and dimensionality of stimulus
Nsamples, Ndim = stim.shape
#unpack p: (var names match names in Fitzgerald paper)
a = p[0]
h = p[1:Ndim+1].T
#case: second order calculation --> need J
if order > 1:
J = np.reshape(p[Ndim+1:Ndim+1+Ndim**2], (Ndim,Ndim))
if order == 1:
pSpike = 1.0 / (1.0 + np.exp(a + stim.dot(h))) #Nsamples x 1
averages = np.hstack((np.mean(pSpike), stim.T.dot(pSpike) / Nsamples))
elif order == 2:
pSpike = 1.0 / (1.0 + np.exp(a + stim.dot(h) + (np.sum(stim * (stim.dot(J)),1))))
averages = np.zeros(1+Ndim+Ndim**2)
averages[0] = np.mean(pSpike)
averages[1:Ndim+1] = stim.T.dot(pSpike) / Nsamples #ave number of spikes for each stim dimension
temp = (stim.T.dot(np.tile(np.reshape(pSpike, (Nsamples, 1)), (1,Ndim)) * stim)) / Nsamples #ave number of spikes for each stim correlation
temp = np.reshape(temp,[Ndim**2,1])
averages[Ndim+1:Ndim+1+Ndim**2] = np.reshape(temp, Ndim**2)
return (np.squeeze(avgs) - averages)
def constrained_averages(stim, resp, order):
Nsamples, Ndim = stim.shape
psp = np.mean(resp) #spike probability
avg = stim.T.dot(resp) / Nsamples
avgs = np.vstack((psp,avg))
if order > 1 :
avgsqrd = stim.T.dot(np.tile(resp, (1,Ndim)) * stim) / Nsamples
avgsqrd = np.reshape(avgsqrd,(Ndim**2,1))
avgs = np.vstack((avgs,avgsqrd))
return avgs
def rand_pstart(avgs, order, Ndim):
pstart = np.log(1.0 / avgs[0] - 1.0)
pstart = np.hstack((pstart,(.001*(2*np.random.rand(Ndim)-1))))
if order > 1:
temp = .0005 * (2 * np.random.rand(Ndim,Ndim) - 1) # for symmetry
pstart = np.hstack((pstart, np.reshape(temp + temp.T, Ndim**2)))
return pstart
class IterCounter(object):
def __init__(self):
self.n_iters = 1
print '{0:5s}'.format('Iters')
def callback(self, xk):
print '{0:5d}'.format(self.n_iters)
self.n_iters += 1
class OverfitException(Exception):
def __init__(self, p):
self.p = p
class OverfitStopper(object):
def __init__(self, test_stim, test_resp, order):
self.test_stim = test_stim
self.test_resp = test_resp
self.order = order
self.n_iters = 1
self.best_ll = np.inf
self.best_p = 0
self.test_tally = 0
print '{0:5s} {1:5s} {2:9s}'.format('Iters', 'tally', 'll(test)')
def callback(self, pk):
ll_test_k = log_loss(pk, self.test_stim, self.test_resp, self.order)
print '{0:5d} {1:5d} {2: 3.6f}'.format(self.n_iters, self.test_tally, ll_test_k)
if self.n_iters <= 2 or ll_test_k < self.best_ll:
self.best_ll = ll_test_k
self.best_p = pk
self.test_tally = 0
else:
self.test_tally += 1
if self.test_tally >= 10:
print 'minimum of test set found'
raise OverfitException(self.best_p)
self.n_iters += 1
def MNEfit(stim, resp, order, pstart=None):
stim = np.array(stim, dtype=float)
resp = np.array(resp, dtype=float)
Nsamples, Ndim = stim.shape
avgs = constrained_averages(stim, resp, order)
if pstart is None: #initialize params:
pstart = rand_pstart(avgs, order, Ndim)
#redefine functions with fixed vals:
def logLoss(p):
return log_loss(p, stim, resp, order)
def dlogLoss(p):
return d_log_loss(p, stim, avgs, order)
pfinal = opt.fmin_cg(logLoss, pstart, fprime=dlogLoss,
callback=IterCounter().callback, maxiter=200)
return pfinal
def MNEfit_jackknives(stim, resp, order, pstart=None, jackknives=4, shuffle=True):
stim = np.array(stim, dtype=float)
resp = np.array(resp, dtype=float)
Nsamples, Ndim = stim.shape #TODO: rename Nsamples to n_samples
assert resp.shape[0] == Nsamples
assert resp.shape[1] == 1
if shuffle:
shuffled_indxs = range(Nsamples)
np.random.shuffle(shuffled_indxs)
stim = stim[shuffled_indxs,:]
resp = resp[shuffled_indxs,:]
for jackknife in range(jackknives):
test_stim = stim[jackknife::jackknives,:]
test_resp = resp[jackknife::jackknives,:]
train_stim = stim[np.mod(np.arange(Nsamples)-jackknife, jackknives) != 0,:]
train_resp = resp[np.mod(np.arange(Nsamples)-jackknife, jackknives) != 0,:]
avgs = constrained_averages(train_stim, train_resp, order)
if pstart is None: #initialize params:
pstart = rand_pstart(avgs, order, Ndim)
#redefine functions with fixed vals:
def logLoss(p):
return log_loss(p, train_stim, train_resp, order)
def dlogLoss(p):
return d_log_loss(p, train_stim, avgs, order)
try:
pfinal = opt.fmin_cg(logLoss, pstart, fprime=dlogLoss,
callback=OverfitStopper(test_stim, test_resp, order).callback,
maxiter=200)
except OverfitException as e:
pfinal = e.p
if jackknife == 0:
all_pfinals = np.zeros((jackknives, len(pstart)))
all_pfinals[jackknife, :] = pfinal
return all_pfinals
|
bsd-2-clause
|
[
646,
7026,
14,
13416,
465,
2450,
199,
646,
2680,
465,
980,
199,
199,
318,
943,
63,
4358,
8,
80,
12,
29965,
12,
3085,
12,
1865,
304,
272,
327,
362,
1329,
402,
5845,
436,
6240,
6712,
402,
29965,
15909,
272,
653,
3356,
12,
653,
3572,
275,
29965,
14,
1392,
272,
3085,
275,
980,
14,
5217,
8,
4518,
12,
5868,
17,
430,
2286,
327,
5301,
299,
26,
334,
1391,
1561,
1336,
1561,
315,
481,
23751,
836,
27075,
15220,
9,
272,
282,
275,
299,
59,
16,
61,
272,
394,
275,
299,
59,
17,
26,
46,
3572,
11,
17,
1055,
52,
2286,
327,
2546,
26,
3499,
1865,
15232,
10541,
1929,
1603,
272,
340,
1865,
690,
413,
26,
267,
327,
5217,
1603,
1901,
653,
3572,
671,
653,
3572,
3634,
26,
267,
1603,
275,
980,
14,
5217,
8,
80,
59,
46,
3572,
11,
17,
26,
46,
3572,
11,
17,
11,
46,
3572,
538,
18,
467,
334,
46,
3572,
12,
46,
3572,
4992,
52,
2286,
340,
1865,
508,
413,
26,
267,
289,
17,
275,
413,
435,
980,
14,
1474,
8,
282,
435,
29965,
14,
3287,
8,
72,
430,
267,
289,
16,
275,
413,
435,
980,
14,
1474,
2801,
65,
446,
29965,
14,
3287,
8,
72,
430,
272,
587,
26,
267,
289,
17,
275,
413,
435,
980,
14,
1474,
8,
282,
435,
29965,
14,
3287,
8,
72,
9,
435,
334,
1590,
14,
1838,
8,
31739,
627,
334,
31739,
14,
3287,
8,
42,
1826,
17,
1724,
267,
289,
16,
275,
413,
435,
980,
14,
1474,
2801,
65,
446,
29965,
14,
3287,
8,
72,
9,
446,
334,
1590,
14,
1838,
8,
31739,
627,
334,
31739,
14,
3287,
8,
42,
1826,
17,
1724,
2286,
481,
17,
275,
3085,
627,
980,
14,
793,
8,
70,
17,
9,
272,
481,
16,
275,
334,
17,
446,
3085,
9,
627,
980,
14,
793,
8,
70,
16,
9,
272,
481,
17,
59,
1590,
14,
12936,
8,
38,
17,
1874,
275,
378,
272,
481,
16,
59,
1590,
14,
12936,
8,
38,
16,
1874,
275,
378,
272,
372,
980,
14,
3670,
8,
38,
16,
435,
481,
17,
9,
199,
199,
318,
366,
63,
793,
63,
4358,
8,
80,
12,
31739,
12,
1214,
458,
12,
1648,
304,
272,
327,
362,
1329,
402,
5845,
436,
6240,
6712,
402,
29965,
15909,
272,
653,
3356,
12,
653,
3572,
275,
29965,
14,
1392,
2286,
327,
5301,
299,
26,
334,
1391,
1561,
1336,
1561,
315,
481,
23751,
836,
27075,
15220,
9,
272,
282,
275,
299,
59,
16,
61,
272,
394,
275,
299,
59,
17,
26,
46,
3572,
11,
17,
1055,
52,
2286,
327,
2546,
26,
3499,
1865,
15232,
10541,
1929,
1603,
272,
340,
1865,
690,
413,
26,
267,
1603,
275,
980,
14,
5217,
8,
80,
59,
46,
3572,
11,
17,
26,
46,
3572,
11,
17,
11,
46,
3572,
538,
18,
467,
334,
46,
3572,
12,
46,
3572,
430,
5493,
340,
1865,
508,
413,
26,
267,
299,
51,
1038,
415,
275,
413,
14,
16,
1182,
334,
17,
14,
16,
435,
980,
14,
1474,
8,
65,
435,
29965,
14,
3287,
8,
72,
1724,
327,
2438,
1889,
671,
413,
267,
8095,
83,
275,
980,
14,
20949,
1332,
1590,
14,
3670,
8,
80,
51,
1038,
415,
395,
29965,
14,
52,
14,
3287,
8,
80,
51,
1038,
415,
9,
1182,
653,
3356,
430,
272,
916,
1865,
508,
499,
26,
2728,
299,
51,
1038,
415,
275,
413,
14,
16,
1182,
334,
17,
14,
16,
435,
980,
14,
1474,
8,
65,
435,
29965,
14,
3287,
8,
72,
9,
435,
334,
1590,
14,
1838,
8,
31739,
627,
334,
31739,
14,
3287,
8,
42,
1826,
17,
7845,
267,
8095,
83,
275,
980,
14,
4250,
8,
17,
11,
46,
3572,
11,
46,
3572,
538,
18,
9,
267,
8095,
83,
59,
16,
61,
275,
980,
14,
3670,
8,
80,
51,
1038,
415,
9,
267,
8095,
83,
59,
17,
26,
46,
3572,
11,
17,
61,
275,
29965,
14,
52,
14,
3287,
8,
80,
51,
1038,
415,
9,
1182,
653,
3356,
327,
811,
1329,
402,
19441,
9246,
367,
1924,
29965,
6240,
2728,
2388,
275,
334,
31739,
14,
52,
14,
3287,
8,
1590,
14,
7172,
8,
1590,
14,
5217,
8,
80,
51,
1038,
415,
12,
334,
2438,
1889,
12,
413,
1826,
334,
17,
12,
46,
3572,
430,
627,
29965,
430,
1182,
653,
3356,
221,
327,
811,
1329,
402,
19441,
9246,
367,
1924,
29965,
21280,
267,
2388,
275,
980,
14,
5217,
8,
808,
14343,
46,
3572,
538,
18,
12,
17,
566,
267,
8095,
83,
59,
46,
3572,
11,
17,
26,
46,
3572,
11,
17,
11,
46,
3572,
538,
18,
61,
275,
980,
14,
5217,
8,
808,
12,
653,
3572,
538,
18,
9,
5493,
372,
334,
1590,
14,
16597,
8,
1214,
458,
9,
446,
8095,
83,
9,
199,
199,
318,
28483,
63,
8536,
83,
8,
31739,
12,
3085,
12,
1865,
304,
272,
653,
3356,
12,
653,
3572,
275,
29965,
14,
1392,
272,
299,
681,
275,
980,
14,
3670,
8,
4518,
9,
327,
29774,
12224,
272,
12402,
275,
29965,
14,
52,
14,
3287,
8,
4518,
9,
1182,
653,
3356,
272,
2289,
458,
275,
980,
14,
20221,
1332,
80,
681,
12,
8595,
430,
272,
340,
1865,
690,
413,
520,
267,
2289,
458,
81,
6883,
275,
29965,
14,
52,
14,
3287,
8,
1590,
14,
7172,
8,
4518,
12,
334,
17,
12,
46,
3572,
430,
627,
29965,
9,
1182,
653,
3356,
267,
2289,
458,
81,
6883,
275,
980,
14,
5217,
8,
1214,
458,
81,
6883,
12803,
46,
3572,
538,
18,
12,
17,
430,
267,
2289,
458,
275,
980,
14,
20221,
1332,
1214,
458,
12,
1214,
458,
81,
6883,
430,
272,
372,
2289,
458,
199,
199,
318,
10261,
63,
80,
928,
8,
1214,
458,
12,
1865,
12,
653,
3572,
304,
272,
299,
928,
275,
980,
14,
793,
8,
17,
14,
16,
1182,
2289,
458,
59,
16,
61,
446,
413,
14,
16,
9,
272,
299,
928,
275,
980,
14,
20949,
1332,
80,
928,
12803,
14,
4587,
5830,
18,
10,
1590,
14,
2355,
14,
3759,
8,
46,
3572,
7216,
17,
7845,
272,
340,
1865,
690,
413,
26,
267,
2388,
275,
1275,
15646,
627,
334,
18,
627,
980,
14,
2355,
14,
3759,
8,
46,
3572,
12,
46,
3572,
9,
446,
413,
9,
327,
367,
30246,
267,
299,
928,
275,
980,
14,
20949,
1332,
80,
928,
12,
980,
14,
5217,
8,
808,
435
] |
[
7026,
14,
13416,
465,
2450,
199,
646,
2680,
465,
980,
199,
199,
318,
943,
63,
4358,
8,
80,
12,
29965,
12,
3085,
12,
1865,
304,
272,
327,
362,
1329,
402,
5845,
436,
6240,
6712,
402,
29965,
15909,
272,
653,
3356,
12,
653,
3572,
275,
29965,
14,
1392,
272,
3085,
275,
980,
14,
5217,
8,
4518,
12,
5868,
17,
430,
2286,
327,
5301,
299,
26,
334,
1391,
1561,
1336,
1561,
315,
481,
23751,
836,
27075,
15220,
9,
272,
282,
275,
299,
59,
16,
61,
272,
394,
275,
299,
59,
17,
26,
46,
3572,
11,
17,
1055,
52,
2286,
327,
2546,
26,
3499,
1865,
15232,
10541,
1929,
1603,
272,
340,
1865,
690,
413,
26,
267,
327,
5217,
1603,
1901,
653,
3572,
671,
653,
3572,
3634,
26,
267,
1603,
275,
980,
14,
5217,
8,
80,
59,
46,
3572,
11,
17,
26,
46,
3572,
11,
17,
11,
46,
3572,
538,
18,
467,
334,
46,
3572,
12,
46,
3572,
4992,
52,
2286,
340,
1865,
508,
413,
26,
267,
289,
17,
275,
413,
435,
980,
14,
1474,
8,
282,
435,
29965,
14,
3287,
8,
72,
430,
267,
289,
16,
275,
413,
435,
980,
14,
1474,
2801,
65,
446,
29965,
14,
3287,
8,
72,
430,
272,
587,
26,
267,
289,
17,
275,
413,
435,
980,
14,
1474,
8,
282,
435,
29965,
14,
3287,
8,
72,
9,
435,
334,
1590,
14,
1838,
8,
31739,
627,
334,
31739,
14,
3287,
8,
42,
1826,
17,
1724,
267,
289,
16,
275,
413,
435,
980,
14,
1474,
2801,
65,
446,
29965,
14,
3287,
8,
72,
9,
446,
334,
1590,
14,
1838,
8,
31739,
627,
334,
31739,
14,
3287,
8,
42,
1826,
17,
1724,
2286,
481,
17,
275,
3085,
627,
980,
14,
793,
8,
70,
17,
9,
272,
481,
16,
275,
334,
17,
446,
3085,
9,
627,
980,
14,
793,
8,
70,
16,
9,
272,
481,
17,
59,
1590,
14,
12936,
8,
38,
17,
1874,
275,
378,
272,
481,
16,
59,
1590,
14,
12936,
8,
38,
16,
1874,
275,
378,
272,
372,
980,
14,
3670,
8,
38,
16,
435,
481,
17,
9,
199,
199,
318,
366,
63,
793,
63,
4358,
8,
80,
12,
31739,
12,
1214,
458,
12,
1648,
304,
272,
327,
362,
1329,
402,
5845,
436,
6240,
6712,
402,
29965,
15909,
272,
653,
3356,
12,
653,
3572,
275,
29965,
14,
1392,
2286,
327,
5301,
299,
26,
334,
1391,
1561,
1336,
1561,
315,
481,
23751,
836,
27075,
15220,
9,
272,
282,
275,
299,
59,
16,
61,
272,
394,
275,
299,
59,
17,
26,
46,
3572,
11,
17,
1055,
52,
2286,
327,
2546,
26,
3499,
1865,
15232,
10541,
1929,
1603,
272,
340,
1865,
690,
413,
26,
267,
1603,
275,
980,
14,
5217,
8,
80,
59,
46,
3572,
11,
17,
26,
46,
3572,
11,
17,
11,
46,
3572,
538,
18,
467,
334,
46,
3572,
12,
46,
3572,
430,
5493,
340,
1865,
508,
413,
26,
267,
299,
51,
1038,
415,
275,
413,
14,
16,
1182,
334,
17,
14,
16,
435,
980,
14,
1474,
8,
65,
435,
29965,
14,
3287,
8,
72,
1724,
327,
2438,
1889,
671,
413,
267,
8095,
83,
275,
980,
14,
20949,
1332,
1590,
14,
3670,
8,
80,
51,
1038,
415,
395,
29965,
14,
52,
14,
3287,
8,
80,
51,
1038,
415,
9,
1182,
653,
3356,
430,
272,
916,
1865,
508,
499,
26,
2728,
299,
51,
1038,
415,
275,
413,
14,
16,
1182,
334,
17,
14,
16,
435,
980,
14,
1474,
8,
65,
435,
29965,
14,
3287,
8,
72,
9,
435,
334,
1590,
14,
1838,
8,
31739,
627,
334,
31739,
14,
3287,
8,
42,
1826,
17,
7845,
267,
8095,
83,
275,
980,
14,
4250,
8,
17,
11,
46,
3572,
11,
46,
3572,
538,
18,
9,
267,
8095,
83,
59,
16,
61,
275,
980,
14,
3670,
8,
80,
51,
1038,
415,
9,
267,
8095,
83,
59,
17,
26,
46,
3572,
11,
17,
61,
275,
29965,
14,
52,
14,
3287,
8,
80,
51,
1038,
415,
9,
1182,
653,
3356,
327,
811,
1329,
402,
19441,
9246,
367,
1924,
29965,
6240,
2728,
2388,
275,
334,
31739,
14,
52,
14,
3287,
8,
1590,
14,
7172,
8,
1590,
14,
5217,
8,
80,
51,
1038,
415,
12,
334,
2438,
1889,
12,
413,
1826,
334,
17,
12,
46,
3572,
430,
627,
29965,
430,
1182,
653,
3356,
221,
327,
811,
1329,
402,
19441,
9246,
367,
1924,
29965,
21280,
267,
2388,
275,
980,
14,
5217,
8,
808,
14343,
46,
3572,
538,
18,
12,
17,
566,
267,
8095,
83,
59,
46,
3572,
11,
17,
26,
46,
3572,
11,
17,
11,
46,
3572,
538,
18,
61,
275,
980,
14,
5217,
8,
808,
12,
653,
3572,
538,
18,
9,
5493,
372,
334,
1590,
14,
16597,
8,
1214,
458,
9,
446,
8095,
83,
9,
199,
199,
318,
28483,
63,
8536,
83,
8,
31739,
12,
3085,
12,
1865,
304,
272,
653,
3356,
12,
653,
3572,
275,
29965,
14,
1392,
272,
299,
681,
275,
980,
14,
3670,
8,
4518,
9,
327,
29774,
12224,
272,
12402,
275,
29965,
14,
52,
14,
3287,
8,
4518,
9,
1182,
653,
3356,
272,
2289,
458,
275,
980,
14,
20221,
1332,
80,
681,
12,
8595,
430,
272,
340,
1865,
690,
413,
520,
267,
2289,
458,
81,
6883,
275,
29965,
14,
52,
14,
3287,
8,
1590,
14,
7172,
8,
4518,
12,
334,
17,
12,
46,
3572,
430,
627,
29965,
9,
1182,
653,
3356,
267,
2289,
458,
81,
6883,
275,
980,
14,
5217,
8,
1214,
458,
81,
6883,
12803,
46,
3572,
538,
18,
12,
17,
430,
267,
2289,
458,
275,
980,
14,
20221,
1332,
1214,
458,
12,
1214,
458,
81,
6883,
430,
272,
372,
2289,
458,
199,
199,
318,
10261,
63,
80,
928,
8,
1214,
458,
12,
1865,
12,
653,
3572,
304,
272,
299,
928,
275,
980,
14,
793,
8,
17,
14,
16,
1182,
2289,
458,
59,
16,
61,
446,
413,
14,
16,
9,
272,
299,
928,
275,
980,
14,
20949,
1332,
80,
928,
12803,
14,
4587,
5830,
18,
10,
1590,
14,
2355,
14,
3759,
8,
46,
3572,
7216,
17,
7845,
272,
340,
1865,
690,
413,
26,
267,
2388,
275,
1275,
15646,
627,
334,
18,
627,
980,
14,
2355,
14,
3759,
8,
46,
3572,
12,
46,
3572,
9,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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
] |
mindnervestech/mnrp
|
addons/hr_recruitment/wizard/__init__.py
|
381
|
1095
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-Today OpenERP (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import hr_recruitment_create_partner_job
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
31982,
7653,
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,
646,
16140,
63,
264,
31365,
434,
63,
981,
63,
3899,
63,
2423,
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
] |
[
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,
31982,
7653,
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,
646,
16140,
63,
264,
31365,
434,
63,
981,
63,
3899,
63,
2423,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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