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
|
|---|---|---|---|---|---|---|---|---|
libscie/liberator
|
liberator/lib/python3.6/site-packages/chardet/codingstatemachine.py
|
289
|
3590
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
import logging
from .enums import MachineState
class CodingStateMachine(object):
"""
A state machine to verify a byte sequence for a particular encoding. For
each byte the detector receives, it will feed that byte to every active
state machine available, one byte at a time. The state machine changes its
state based on its previous state and the byte it receives. There are 3
states in a state machine that are of interest to an auto-detector:
START state: This is the state to start with, or a legal byte sequence
(i.e. a valid code point) for character has been identified.
ME state: This indicates that the state machine identified a byte sequence
that is specific to the charset it is designed for and that
there is no other possible encoding which can contain this byte
sequence. This will to lead to an immediate positive answer for
the detector.
ERROR state: This indicates the state machine identified an illegal byte
sequence for that encoding. This will lead to an immediate
negative answer for this encoding. Detector will exclude this
encoding from consideration from here on.
"""
def __init__(self, sm):
self._model = sm
self._curr_byte_pos = 0
self._curr_char_len = 0
self._curr_state = None
self.logger = logging.getLogger(__name__)
self.reset()
def reset(self):
self._curr_state = MachineState.START
def next_state(self, c):
# for each byte we get its class
# if it is first byte, we also get byte length
byte_class = self._model['class_table'][c]
if self._curr_state == MachineState.START:
self._curr_byte_pos = 0
self._curr_char_len = self._model['char_len_table'][byte_class]
# from byte's class and state_table, we get its next state
curr_state = (self._curr_state * self._model['class_factor']
+ byte_class)
self._curr_state = self._model['state_table'][curr_state]
self._curr_byte_pos += 1
return self._curr_state
def get_current_charlen(self):
return self._curr_char_len
def get_coding_state_machine(self):
return self._model['name']
@property
def language(self):
return self._model['language']
|
cc0-1.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
1303,
6956,
14,
1308,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
2050,
199,
199,
504,
1275,
19921,
492,
18722,
2223,
421,
199,
533,
30539,
8,
785,
304,
272,
408,
272,
437,
1174,
6844,
370,
4911,
282,
3696,
3414,
367,
282,
6770,
2644,
14,
2104,
272,
1924,
3696,
314,
17842,
23192,
12,
652,
911,
4733,
626,
3696,
370,
4036,
4702,
272,
1174,
6844,
2808,
12,
1373,
3696,
737,
282,
900,
14,
710,
1174,
6844,
4493,
2399,
272,
1174,
4079,
641,
2399,
4136,
1174,
436,
314,
3696,
652,
23192,
14,
6006,
787,
650,
272,
6363,
315,
282,
1174,
6844,
626,
787,
402,
13518,
370,
376,
2599,
13,
19401,
26,
339,
13910,
1174,
26,
961,
365,
314,
1174,
370,
1343,
543,
12,
503,
282,
18393,
3696,
3414,
326,
334,
73,
14,
69,
14,
282,
1686,
1233,
2376,
9,
367,
4528,
965,
2757,
15836,
14,
339,
603,
37,
1174,
26,
221,
961,
9126,
626,
314,
1174,
6844,
15836,
282,
3696,
3414,
2049,
626,
365,
2488,
370,
314,
5960,
652,
365,
19829,
367,
436,
626,
2049,
2337,
365,
949,
1163,
3962,
2644,
1314,
883,
1395,
642,
3696,
2049,
3414,
14,
961,
911,
370,
12690,
370,
376,
8569,
7317,
6385,
367,
2049,
314,
17842,
14,
339,
12539,
1174,
26,
961,
9126,
314,
1174,
6844,
15836,
376,
20282,
3696,
326,
3414,
367,
626,
2644,
14,
961,
911,
12690,
370,
376,
8569,
326,
6946,
6385,
367,
642,
2644,
14,
1487,
9119,
911,
5760,
642,
326,
2644,
687,
8219,
1754,
687,
2348,
641,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
4383,
304,
267,
291,
423,
1238,
275,
4383,
267,
291,
423,
9808,
63,
4414,
63,
1712,
275,
378,
267,
291,
423,
9808,
63,
1560,
63,
552,
275,
378,
267,
291,
423,
9808,
63,
929,
275,
488,
267,
291,
14,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
291,
423,
9808,
63,
929,
275,
18722,
2223,
14,
7363,
339,
347,
2163,
63,
929,
8,
277,
12,
286,
304,
267,
327,
367,
1924,
3696,
781,
664,
2399,
1021,
267,
327,
340,
652,
365,
1642,
3696,
12,
781,
2597,
664,
3696,
2582,
267,
3696,
63,
533,
275,
291,
423,
1238,
459,
533,
63,
1224,
3488,
67,
61,
267,
340,
291,
423,
9808,
63,
929,
508,
18722,
2223,
14,
7363,
26,
288,
291,
423,
9808,
63,
4414,
63,
1712,
275,
378,
288,
291,
423,
9808,
63,
1560,
63,
552,
275,
291,
423,
1238,
459,
1560,
63,
552,
63,
1224,
3488,
4414,
63,
533,
61,
267,
327,
687,
3696,
1159,
1021,
436,
1174,
63,
1224,
12,
781,
664,
2399,
2163,
1174,
267,
8230,
63,
929,
275,
334,
277,
423,
9808,
63,
929,
627,
291,
423,
1238,
459,
533,
63,
4778,
418,
1993,
435,
3696,
63,
533,
9,
267,
291,
423,
9808,
63,
929,
275,
291,
423,
1238,
459,
929,
63,
1224,
3488,
9808,
63,
929,
61,
267,
291,
423,
9808,
63,
4414,
63,
1712,
847,
413,
267,
372,
291,
423,
9808,
63,
929,
339,
347,
664,
63,
1818,
63,
1560,
552,
8,
277,
304,
267,
372,
291,
423,
9808,
63,
1560,
63,
552,
339,
347,
664,
63,
1523,
63,
929,
63,
6744,
8,
277,
304,
267,
372,
291,
423,
1238,
459,
354,
418,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
372,
291,
423,
1238,
459,
3671,
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
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
1303,
6956,
14,
1308,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
2050,
199,
199,
504,
1275,
19921,
492,
18722,
2223,
421,
199,
533,
30539,
8,
785,
304,
272,
408,
272,
437,
1174,
6844,
370,
4911,
282,
3696,
3414,
367,
282,
6770,
2644,
14,
2104,
272,
1924,
3696,
314,
17842,
23192,
12,
652,
911,
4733,
626,
3696,
370,
4036,
4702,
272,
1174,
6844,
2808,
12,
1373,
3696,
737,
282,
900,
14,
710,
1174,
6844,
4493,
2399,
272,
1174,
4079,
641,
2399,
4136,
1174,
436,
314,
3696,
652,
23192,
14,
6006,
787,
650,
272,
6363,
315,
282,
1174,
6844,
626,
787,
402,
13518,
370,
376,
2599,
13,
19401,
26,
339,
13910,
1174,
26,
961,
365,
314,
1174,
370,
1343,
543,
12,
503,
282,
18393,
3696,
3414,
326,
334,
73,
14,
69,
14,
282,
1686,
1233,
2376,
9,
367,
4528,
965,
2757,
15836,
14,
339,
603,
37,
1174,
26,
221,
961,
9126,
626,
314,
1174,
6844,
15836,
282,
3696,
3414,
2049,
626,
365,
2488,
370,
314,
5960,
652,
365,
19829,
367,
436,
626,
2049,
2337,
365,
949,
1163,
3962,
2644,
1314,
883,
1395,
642,
3696,
2049,
3414,
14,
961,
911,
370,
12690,
370,
376,
8569,
7317,
6385,
367,
2049,
314,
17842,
14,
339,
12539,
1174,
26,
961,
9126,
314,
1174,
6844,
15836,
376,
20282,
3696,
326,
3414,
367,
626,
2644,
14,
961,
911,
12690,
370,
376,
8569,
326,
6946,
6385,
367,
642,
2644,
14,
1487,
9119,
911,
5760,
642,
326,
2644,
687,
8219,
1754,
687,
2348,
641,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
4383,
304,
267,
291,
423,
1238,
275,
4383,
267,
291,
423,
9808,
63,
4414,
63,
1712,
275,
378,
267,
291,
423,
9808,
63,
1560,
63,
552,
275,
378,
267,
291,
423,
9808,
63,
929,
275,
488,
267,
291,
14,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
291,
423,
9808,
63,
929,
275,
18722,
2223,
14,
7363,
339,
347,
2163,
63,
929,
8,
277,
12,
286,
304,
267,
327,
367,
1924,
3696,
781,
664,
2399,
1021,
267,
327,
340,
652,
365,
1642,
3696,
12,
781,
2597,
664,
3696,
2582,
267,
3696,
63,
533,
275,
291,
423,
1238,
459,
533,
63,
1224,
3488,
67,
61,
267,
340,
291,
423,
9808,
63,
929,
508,
18722,
2223,
14,
7363,
26,
288,
291,
423,
9808,
63,
4414,
63,
1712,
275,
378,
288,
291,
423,
9808,
63,
1560,
63,
552,
275,
291,
423,
1238,
459,
1560,
63,
552,
63,
1224,
3488,
4414,
63,
533,
61,
267,
327,
687,
3696,
1159,
1021,
436,
1174,
63,
1224,
12,
781,
664,
2399,
2163,
1174,
267,
8230,
63,
929,
275,
334,
277,
423,
9808,
63,
929,
627,
291,
423,
1238,
459,
533,
63,
4778,
418,
1993,
435,
3696,
63,
533,
9,
267,
291,
423,
9808,
63,
929,
275,
291,
423,
1238,
459,
929,
63,
1224,
3488,
9808,
63,
929,
61,
267,
291,
423,
9808,
63,
4414,
63,
1712,
847,
413,
267,
372,
291,
423,
9808,
63,
929,
339,
347,
664,
63,
1818,
63,
1560,
552,
8,
277,
304,
267,
372,
291,
423,
9808,
63,
1560,
63,
552,
339,
347,
664,
63,
1523,
63,
929,
63,
6744,
8,
277,
304,
267,
372,
291,
423,
1238,
459,
354,
418,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
372,
291,
423,
1238,
459,
3671,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
n-west/gnuradio
|
gnuradio-runtime/examples/volk_benchmark/volk_types.py
|
58
|
5995
|
#!/usr/bin/env python
from gnuradio import gr
from gnuradio import blocks
import argparse
from volk_test_funcs import *
######################################################################
def float_to_char(N):
op = blocks.float_to_char()
tb = helper(N, op, gr.sizeof_float, gr.sizeof_char, 1, 1)
return tb
######################################################################
def float_to_int(N):
op = blocks.float_to_int()
tb = helper(N, op, gr.sizeof_float, gr.sizeof_int, 1, 1)
return tb
######################################################################
def float_to_short(N):
op = blocks.float_to_short()
tb = helper(N, op, gr.sizeof_float, gr.sizeof_short, 1, 1)
return tb
######################################################################
def short_to_float(N):
op = blocks.short_to_float()
tb = helper(N, op, gr.sizeof_short, gr.sizeof_float, 1, 1)
return tb
######################################################################
def short_to_char(N):
op = blocks.short_to_char()
tb = helper(N, op, gr.sizeof_short, gr.sizeof_char, 1, 1)
return tb
######################################################################
def char_to_short(N):
op = blocks.char_to_short()
tb = helper(N, op, gr.sizeof_char, gr.sizeof_short, 1, 1)
######################################################################
def char_to_float(N):
op = blocks.char_to_float()
tb = helper(N, op, gr.sizeof_char, gr.sizeof_float, 1, 1)
#####################################################################
def int_to_float(N):
op = blocks.int_to_float()
tb = helper(N, op, gr.sizeof_int, gr.sizeof_float, 1, 1)
return tb
######################################################################
def complex_to_float(N):
op = blocks.complex_to_float()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_float, 1, 2)
return tb
######################################################################
def complex_to_real(N):
op = blocks.complex_to_real()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_float, 1, 1)
return tb
######################################################################
def complex_to_imag(N):
op = blocks.complex_to_imag()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_float, 1, 1)
return tb
######################################################################
def complex_to_mag(N):
op = blocks.complex_to_mag()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_float, 1, 1)
return tb
######################################################################
def complex_to_mag_squared(N):
op = blocks.complex_to_mag_squared()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_float, 1, 1)
return tb
######################################################################
def run_tests(func, N, iters):
print("Running Test: {0}".format(func.__name__))
try:
tb = func(N)
t = timeit(tb, iters)
res = format_results(func.__name__, t)
return res
except AttributeError:
print "\tCould not run test. Skipping."
return None
def main():
avail_tests = [float_to_char,
float_to_int,
float_to_short,
short_to_float,
short_to_char,
char_to_short,
char_to_float,
int_to_float,
complex_to_float,
complex_to_real,
complex_to_imag,
complex_to_mag,
complex_to_mag_squared]
desc='Time an operation to compare with other implementations. \
This program runs a simple GNU Radio flowgraph to test a \
particular math function, mostly to compare the \
Volk-optimized implementation versus a regular \
implementation. The results are stored to an SQLite database \
that can then be read by volk_plot.py to plot the differences.'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-L', '--label', type=str,
required=True, default=None,
help='Label of database table [default: %(default)s]')
parser.add_argument('-D', '--database', type=str,
default="volk_results.db",
help='Database file to store data in [default: %(default)s]')
parser.add_argument('-N', '--nitems', type=float,
default=1e9,
help='Number of items per iterations [default: %(default)s]')
parser.add_argument('-I', '--iterations', type=int,
default=20,
help='Number of iterations [default: %(default)s]')
parser.add_argument('--tests', type=int, nargs='*',
choices=xrange(len(avail_tests)),
help='A list of tests to run; can be a single test or a \
space-separated list.')
parser.add_argument('--list', action='store_true',
help='List the available tests')
parser.add_argument('--all', action='store_true',
help='Run all tests')
args = parser.parse_args()
if(args.list):
print "Available Tests to Run:"
print "\n".join(["\t{0}: {1}".format(i,f.__name__) for i,f in enumerate(avail_tests)])
sys.exit(0)
N = int(args.nitems)
iters = args.iterations
label = args.label
conn = create_connection(args.database)
new_table(conn, label)
if args.all:
tests = xrange(len(avail_tests))
else:
tests = args.tests
for test in tests:
res = run_tests(avail_tests[test], N, iters)
if res is not None:
replace_results(conn, label, N, iters, res)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
24526,
492,
7192,
199,
504,
24526,
492,
5664,
199,
646,
7534,
199,
504,
5236,
75,
63,
396,
63,
9204,
492,
627,
199,
199,
18022,
199,
199,
318,
2069,
63,
475,
63,
1560,
8,
46,
304,
272,
1687,
275,
5664,
14,
1609,
63,
475,
63,
1560,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1560,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
2069,
63,
475,
63,
442,
8,
46,
304,
272,
1687,
275,
5664,
14,
1609,
63,
475,
63,
442,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
442,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
2069,
63,
475,
63,
3612,
8,
46,
304,
272,
1687,
275,
5664,
14,
1609,
63,
475,
63,
3612,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
3612,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
3974,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
3612,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
3612,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
3974,
63,
475,
63,
1560,
8,
46,
304,
272,
1687,
275,
5664,
14,
3612,
63,
475,
63,
1560,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
3612,
12,
7192,
14,
12590,
63,
1560,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
1495,
63,
475,
63,
3612,
8,
46,
304,
272,
1687,
275,
5664,
14,
1560,
63,
475,
63,
3612,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1560,
12,
7192,
14,
12590,
63,
3612,
12,
413,
12,
413,
9,
199,
199,
18022,
199,
199,
318,
1495,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
1560,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1560,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
199,
199,
3060,
8776,
199,
199,
318,
1109,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
442,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
442,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
499,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
3093,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
3093,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
14688,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
14688,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
5615,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
5615,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
5615,
63,
12973,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
5615,
63,
12973,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
421,
199,
318,
1255,
63,
2219,
8,
1532,
12,
653,
12,
284,
878,
304,
272,
870,
480,
9602,
1379,
26,
469,
16,
5469,
908,
8,
1532,
855,
354,
8964,
272,
862,
26,
267,
7070,
275,
2562,
8,
46,
9,
267,
307,
275,
900,
390,
8,
5842,
12,
284,
878,
9,
267,
522,
275,
1475,
63,
2604,
8,
1532,
855,
354,
3108,
307,
9,
267,
372,
522,
272,
871,
4281,
26,
267,
870,
1867,
84,
6531,
440,
1255,
511,
14,
8232,
4073,
2122,
267,
372,
488,
199,
199,
318,
2446,
837,
272,
21006,
63,
2219,
275,
359,
1609,
63,
475,
63,
1560,
12,
673,
2069,
63,
475,
63,
442,
12,
673,
2069,
63,
475,
63,
3612,
12,
673,
3974,
63,
475,
63,
1609,
12,
673,
3974,
63,
475,
63,
1560,
12,
673,
1495,
63,
475,
63,
3612,
12,
673,
1495,
63,
475,
63,
1609,
12,
673,
1109,
63,
475,
63,
1609,
12,
673,
6114,
63,
475,
63,
1609,
12,
673,
6114,
63,
475,
63,
3093,
12,
673,
6114,
63,
475,
63,
14688,
12,
673,
6114,
63,
475,
63,
5615,
12,
673,
6114,
63,
475,
63,
5615,
63,
12973,
61,
339,
4328,
534,
1366,
376,
3439,
370,
6540,
543,
1163,
12591,
14,
971,
881,
961,
2240,
7858,
282,
3486,
1664,
13514,
6369,
2180,
370,
511,
282,
971,
881,
6770,
3473,
805,
12,
19762,
370,
6540,
314,
221,
971,
881,
16171,
75,
13,
25499,
4514,
809,
25253,
282,
5578,
971,
881,
4514,
14,
710,
2058,
787,
5489,
370,
376,
19245,
3050,
971,
881,
626,
883,
2066,
506,
1586,
701,
5236,
75,
63,
2798,
14,
647,
370,
5137,
314,
15109,
3530,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
3257,
9,
272,
1798,
14,
525,
63,
2094,
3654,
44,
297,
2850,
1302,
297,
730,
29
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
24526,
492,
7192,
199,
504,
24526,
492,
5664,
199,
646,
7534,
199,
504,
5236,
75,
63,
396,
63,
9204,
492,
627,
199,
199,
18022,
199,
199,
318,
2069,
63,
475,
63,
1560,
8,
46,
304,
272,
1687,
275,
5664,
14,
1609,
63,
475,
63,
1560,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1560,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
2069,
63,
475,
63,
442,
8,
46,
304,
272,
1687,
275,
5664,
14,
1609,
63,
475,
63,
442,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
442,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
2069,
63,
475,
63,
3612,
8,
46,
304,
272,
1687,
275,
5664,
14,
1609,
63,
475,
63,
3612,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
3612,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
3974,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
3612,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
3612,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
3974,
63,
475,
63,
1560,
8,
46,
304,
272,
1687,
275,
5664,
14,
3612,
63,
475,
63,
1560,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
3612,
12,
7192,
14,
12590,
63,
1560,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
1495,
63,
475,
63,
3612,
8,
46,
304,
272,
1687,
275,
5664,
14,
1560,
63,
475,
63,
3612,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1560,
12,
7192,
14,
12590,
63,
3612,
12,
413,
12,
413,
9,
199,
199,
18022,
199,
199,
318,
1495,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
1560,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1560,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
199,
199,
3060,
8776,
199,
199,
318,
1109,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
442,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
442,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
1609,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
1609,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
499,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
3093,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
3093,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
14688,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
14688,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
5615,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
5615,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
6114,
63,
475,
63,
5615,
63,
12973,
8,
46,
304,
272,
1687,
275,
5664,
14,
5254,
63,
475,
63,
5615,
63,
12973,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
421,
199,
318,
1255,
63,
2219,
8,
1532,
12,
653,
12,
284,
878,
304,
272,
870,
480,
9602,
1379,
26,
469,
16,
5469,
908,
8,
1532,
855,
354,
8964,
272,
862,
26,
267,
7070,
275,
2562,
8,
46,
9,
267,
307,
275,
900,
390,
8,
5842,
12,
284,
878,
9,
267,
522,
275,
1475,
63,
2604,
8,
1532,
855,
354,
3108,
307,
9,
267,
372,
522,
272,
871,
4281,
26,
267,
870,
1867,
84,
6531,
440,
1255,
511,
14,
8232,
4073,
2122,
267,
372,
488,
199,
199,
318,
2446,
837,
272,
21006,
63,
2219,
275,
359,
1609,
63,
475,
63,
1560,
12,
673,
2069,
63,
475,
63,
442,
12,
673,
2069,
63,
475,
63,
3612,
12,
673,
3974,
63,
475,
63,
1609,
12,
673,
3974,
63,
475,
63,
1560,
12,
673,
1495,
63,
475,
63,
3612,
12,
673,
1495,
63,
475,
63,
1609,
12,
673,
1109,
63,
475,
63,
1609,
12,
673,
6114,
63,
475,
63,
1609,
12,
673,
6114,
63,
475,
63,
3093,
12,
673,
6114,
63,
475,
63,
14688,
12,
673,
6114,
63,
475,
63,
5615,
12,
673,
6114,
63,
475,
63,
5615,
63,
12973,
61,
339,
4328,
534,
1366,
376,
3439,
370,
6540,
543,
1163,
12591,
14,
971,
881,
961,
2240,
7858,
282,
3486,
1664,
13514,
6369,
2180,
370,
511,
282,
971,
881,
6770,
3473,
805,
12,
19762,
370,
6540,
314,
221,
971,
881,
16171,
75,
13,
25499,
4514,
809,
25253,
282,
5578,
971,
881,
4514,
14,
710,
2058,
787,
5489,
370,
376,
19245,
3050,
971,
881,
626,
883,
2066,
506,
1586,
701,
5236,
75,
63,
2798,
14,
647,
370,
5137,
314,
15109,
3530,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
3257,
9,
272,
1798,
14,
525,
63,
2094,
3654,
44,
297,
2850,
1302,
297,
730,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" A simple device interface for build steps.
"""
import logging
import os
import re
import sys
import build_utils
BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
sys.path.append(BUILD_ANDROID_DIR)
from pylib import android_commands
from pylib.android_commands import GetAttachedDevices
class BuildDevice(object):
def __init__(self, configuration):
self.id = configuration['id']
self.description = configuration['description']
self.install_metadata = configuration['install_metadata']
self.adb = android_commands.AndroidCommands(self.id)
def RunShellCommand(self, *args, **kwargs):
return self.adb.RunShellCommand(*args, **kwargs)
def PushIfNeeded(self, *args, **kwargs):
return self.adb.PushIfNeeded(*args, **kwargs)
def GetSerialNumber(self):
return self.id
def Install(self, *args, **kwargs):
return self.adb.Install(*args, **kwargs)
def GetInstallMetadata(self, apk_package):
"""Gets the metadata on the device for the apk_package apk."""
# Matches lines like:
# -rw-r--r-- system system 7376582 2013-04-19 16:34 \
# org.chromium.chrome.testshell.apk
# -rw-r--r-- system system 7376582 2013-04-19 16:34 \
# org.chromium.chrome.testshell-1.apk
apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s)
matches = filter(apk_matcher, self.install_metadata)
return matches[0] if matches else None
def GetConfigurationForDevice(id):
adb = android_commands.AndroidCommands(id)
configuration = None
has_root = False
is_online = adb.IsOnline()
if is_online:
cmd = 'ls -l /data/app; getprop ro.build.description'
cmd_output = adb.RunShellCommand(cmd)
has_root = not 'Permission denied' in cmd_output[0]
if not has_root:
# Disable warning log messages from EnableAdbRoot()
logging.getLogger().disabled = True
has_root = adb.EnableAdbRoot()
logging.getLogger().disabled = False
cmd_output = adb.RunShellCommand(cmd)
configuration = {
'id': id,
'description': cmd_output[-1],
'install_metadata': cmd_output[:-1],
}
return configuration, is_online, has_root
def WriteConfigurations(configurations, path):
# Currently we only support installing to the first device.
build_utils.WriteJson(configurations[:1], path, only_if_changed=True)
def ReadConfigurations(path):
return build_utils.ReadJson(path)
def GetBuildDevice(configurations):
assert len(configurations) == 1
return BuildDevice(configurations[0])
def GetBuildDeviceFromPath(path):
configurations = ReadConfigurations(path)
if len(configurations) > 0:
return GetBuildDevice(ReadConfigurations(path))
return None
|
bsd-3-clause
|
[
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,
437,
3486,
2243,
3217,
367,
1900,
7124,
14,
199,
199,
624,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
646,
1900,
63,
1208,
199,
199,
8248,
63,
25658,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
19155,
11541,
358,
199,
1274,
14,
515,
14,
740,
8,
8248,
63,
25658,
63,
3022,
9,
199,
199,
504,
29219,
492,
15516,
63,
4405,
199,
199,
504,
29219,
14,
6238,
63,
4405,
492,
2372,
1271,
7159,
18204,
421,
199,
533,
6516,
2510,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2897,
304,
272,
291,
14,
344,
275,
2897,
459,
344,
418,
272,
291,
14,
1802,
275,
2897,
459,
1802,
418,
272,
291,
14,
3174,
63,
2343,
275,
2897,
459,
3174,
63,
2343,
418,
272,
291,
14,
13741,
275,
15516,
63,
4405,
14,
20762,
14680,
8,
277,
14,
344,
9,
819,
347,
23882,
3110,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
291,
14,
13741,
14,
2540,
8529,
3110,
2031,
589,
12,
1011,
958,
9,
819,
347,
22643,
3917,
21549,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
291,
14,
13741,
14,
10731,
3917,
21549,
2031,
589,
12,
1011,
958,
9,
819,
347,
2372,
3571,
3259,
8,
277,
304,
272,
372,
291,
14,
344,
819,
347,
13276,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
291,
14,
13741,
14,
8154,
2031,
589,
12,
1011,
958,
9,
819,
347,
2372,
8154,
5142,
8,
277,
12,
31528,
63,
2491,
304,
272,
408,
14426,
314,
3341,
641,
314,
2243,
367,
314,
31528,
63,
2491,
31528,
1041,
272,
327,
21682,
2385,
2839,
26,
272,
327,
446,
13057,
13,
82,
306,
82,
306,
2656,
257,
2656,
259,
1520,
11452,
17760,
6171,
13,
966,
13,
1167,
3193,
26,
1082,
971,
272,
327,
257,
5981,
14,
13211,
14,
9887,
14,
396,
5641,
14,
23582,
272,
327,
446,
13057,
13,
82,
306,
82,
306,
2656,
257,
2656,
259,
1520,
11452,
17760,
6171,
13,
966,
13,
1167,
3193,
26,
1082,
971,
272,
327,
257,
5981,
14,
13211,
14,
9887,
14,
396,
5641,
13,
17,
14,
23582,
272,
31528,
63,
16135,
275,
2400,
308,
26,
295,
14,
1431,
360,
2795,
5,
83,
2801,
59,
16,
13,
25,
3672,
5547,
14,
23582,
12913,
450,
31528,
63,
2491,
12,
308,
9,
272,
4450,
275,
2457,
8,
23582,
63,
16135,
12,
291,
14,
3174,
63,
2343,
9,
272,
372,
4450,
59,
16,
61,
340,
4450,
587,
488,
421,
199,
318,
2372,
5688,
16775,
8,
344,
304,
523,
28173,
275,
15516,
63,
4405,
14,
20762,
14680,
8,
344,
9,
523,
2897,
275,
488,
523,
965,
63,
1231,
275,
756,
523,
365,
63,
15178,
275,
28173,
14,
1831,
28587,
342,
523,
340,
365,
63,
15178,
26,
272,
2088,
275,
283,
478,
446,
76,
1182,
576,
15,
571,
27,
664,
4469,
882,
14,
1506,
14,
1802,
7,
272,
2088,
63,
1199,
275,
28173,
14,
2540,
8529,
3110,
8,
1760,
9,
272,
965,
63,
1231,
275,
440,
283,
7980,
23355,
7,
315,
2088,
63,
1199,
59,
16,
61,
272,
340,
440,
965,
63,
1231,
26,
489,
327,
17534,
5721,
943,
3788,
687,
12030,
33,
697,
6405,
342,
489,
2050,
14,
5572,
1252,
7011,
275,
715,
489,
965,
63,
1231,
275,
28173,
14,
6476,
33,
697,
6405,
342,
489,
2050,
14,
5572,
1252,
7011,
275,
756,
489,
2088,
63,
1199,
275,
28173,
14,
2540,
8529,
3110,
8,
1760,
9,
339,
2897,
275,
469,
267,
283,
344,
356,
1305,
12,
267,
283,
1802,
356,
2088,
63,
1199,
1988,
17,
467,
267,
283,
3174,
63,
2343,
356,
2088,
63,
1199,
4439,
17,
467,
489,
789,
523,
372,
2897,
12,
365,
63,
15178,
12,
965,
63,
1231,
421,
199,
318,
6990,
25808,
8,
10057,
12,
931,
304,
523,
327,
13550,
781,
1454,
2291,
22200,
370,
314,
1642,
2243,
14,
523,
1900,
63,
1208,
14,
3534,
9653,
8,
10057,
1491,
17,
467,
931,
12,
1454,
63,
692,
63,
2489,
29,
549,
9,
421,
199,
318,
5574,
25808,
8,
515,
304,
523,
372,
1900,
63,
1208,
14,
3284,
9653,
8,
515,
9,
421,
199,
318,
2372,
3425,
2510,
8,
10057,
304,
523,
702,
822,
8,
10057,
9,
508,
413,
523,
372,
6516,
2510,
8,
10057,
59,
16,
566,
421,
199,
318,
2372,
3425,
2510,
2532,
2042,
8,
515,
304,
523,
13422,
275,
5574,
25808,
8,
515,
9,
523,
340,
822,
8,
10057,
9,
690,
378,
26,
272,
372,
2372,
3425,
2510,
8,
3284,
25808,
8,
515,
430,
523,
372,
488,
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
] |
[
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,
437,
3486,
2243,
3217,
367,
1900,
7124,
14,
199,
199,
624,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
646,
1900,
63,
1208,
199,
199,
8248,
63,
25658,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
19155,
11541,
358,
199,
1274,
14,
515,
14,
740,
8,
8248,
63,
25658,
63,
3022,
9,
199,
199,
504,
29219,
492,
15516,
63,
4405,
199,
199,
504,
29219,
14,
6238,
63,
4405,
492,
2372,
1271,
7159,
18204,
421,
199,
533,
6516,
2510,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2897,
304,
272,
291,
14,
344,
275,
2897,
459,
344,
418,
272,
291,
14,
1802,
275,
2897,
459,
1802,
418,
272,
291,
14,
3174,
63,
2343,
275,
2897,
459,
3174,
63,
2343,
418,
272,
291,
14,
13741,
275,
15516,
63,
4405,
14,
20762,
14680,
8,
277,
14,
344,
9,
819,
347,
23882,
3110,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
291,
14,
13741,
14,
2540,
8529,
3110,
2031,
589,
12,
1011,
958,
9,
819,
347,
22643,
3917,
21549,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
291,
14,
13741,
14,
10731,
3917,
21549,
2031,
589,
12,
1011,
958,
9,
819,
347,
2372,
3571,
3259,
8,
277,
304,
272,
372,
291,
14,
344,
819,
347,
13276,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
372,
291,
14,
13741,
14,
8154,
2031,
589,
12,
1011,
958,
9,
819,
347,
2372,
8154,
5142,
8,
277,
12,
31528,
63,
2491,
304,
272,
408,
14426,
314,
3341,
641,
314,
2243,
367,
314,
31528,
63,
2491,
31528,
1041,
272,
327,
21682,
2385,
2839,
26,
272,
327,
446,
13057,
13,
82,
306,
82,
306,
2656,
257,
2656,
259,
1520,
11452,
17760,
6171,
13,
966,
13,
1167,
3193,
26,
1082,
971,
272,
327,
257,
5981,
14,
13211,
14,
9887,
14,
396,
5641,
14,
23582,
272,
327,
446,
13057,
13,
82,
306,
82,
306,
2656,
257,
2656,
259,
1520,
11452,
17760,
6171,
13,
966,
13,
1167,
3193,
26,
1082,
971,
272,
327,
257,
5981,
14,
13211,
14,
9887,
14,
396,
5641,
13,
17,
14,
23582,
272,
31528,
63,
16135,
275,
2400,
308,
26,
295,
14,
1431,
360,
2795,
5,
83,
2801,
59,
16,
13,
25,
3672,
5547,
14,
23582,
12913,
450,
31528,
63,
2491,
12,
308,
9,
272,
4450,
275,
2457,
8,
23582,
63,
16135,
12,
291,
14,
3174,
63,
2343,
9,
272,
372,
4450,
59,
16,
61,
340,
4450,
587,
488,
421,
199,
318,
2372,
5688,
16775,
8,
344,
304,
523,
28173,
275,
15516,
63,
4405,
14,
20762,
14680,
8,
344,
9,
523,
2897,
275,
488,
523,
965,
63,
1231,
275,
756,
523,
365,
63,
15178,
275,
28173,
14,
1831,
28587,
342,
523,
340,
365,
63,
15178,
26,
272,
2088,
275,
283,
478,
446,
76,
1182,
576,
15,
571,
27,
664,
4469,
882,
14,
1506,
14,
1802,
7,
272,
2088,
63,
1199,
275,
28173,
14,
2540,
8529,
3110,
8,
1760,
9,
272,
965,
63,
1231,
275,
440,
283,
7980,
23355,
7,
315,
2088,
63,
1199,
59,
16,
61,
272,
340,
440,
965,
63,
1231,
26,
489,
327,
17534,
5721,
943,
3788,
687,
12030,
33,
697,
6405,
342,
489,
2050,
14,
5572,
1252,
7011,
275,
715,
489,
965,
63,
1231,
275,
28173,
14,
6476,
33,
697,
6405,
342,
489,
2050,
14,
5572,
1252,
7011,
275,
756,
489,
2088,
63,
1199,
275,
28173,
14,
2540,
8529,
3110,
8,
1760,
9,
339,
2897,
275,
469,
267,
283,
344,
356,
1305,
12,
267,
283,
1802,
356,
2088,
63,
1199,
1988,
17,
467,
267,
283,
3174,
63,
2343,
356,
2088,
63,
1199,
4439,
17,
467,
489,
789,
523,
372,
2897,
12,
365,
63,
15178,
12,
965,
63,
1231,
421,
199,
318,
6990,
25808,
8,
10057,
12,
931,
304,
523,
327,
13550,
781,
1454,
2291,
22200,
370,
314,
1642,
2243,
14,
523,
1900,
63,
1208,
14,
3534,
9653,
8,
10057,
1491,
17,
467,
931,
12,
1454,
63,
692,
63,
2489,
29,
549,
9,
421,
199,
318,
5574,
25808,
8,
515,
304,
523,
372,
1900,
63,
1208,
14,
3284,
9653,
8,
515,
9,
421,
199,
318,
2372,
3425,
2510,
8,
10057,
304,
523,
702,
822,
8,
10057,
9,
508,
413,
523,
372,
6516,
2510,
8,
10057,
59,
16,
566,
421,
199,
318,
2372,
3425,
2510,
2532,
2042,
8,
515,
304,
523,
13422,
275,
5574,
25808,
8,
515,
9,
523,
340,
822,
8,
10057,
9,
690,
378,
26,
272,
372,
2372,
3425,
2510,
8,
3284,
25808,
8,
515,
430,
523,
372,
488,
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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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
] |
Jumpscale/jumpscale6_core
|
lib/JumpScale/baselib/remote/fabric/FabricTool.py
|
1
|
1222
|
from JumpScale import j
j.system.platform.ubuntu.check()
import fabric
import fabric.api
# from fabric.api import run as frun
# from fabric.api import execute as fexecute
# from fabric.api import env as fenv
# from fabric.api import open_shell as fopen_shell
# from fabric.api import path as fpath
# from fabric.api import show as fshow
# from fabric.api import put as fput
class FabricTool():
def __init__(self):
self.api = fabric.api
self.setHost()
self.api.env.passwords = {}
def setDefaultPasswd(self,passwd,host="localhost"):
self.api.env["password"]=passwd
self.api.env.passwords["root@%s"%host]=passwd
# self.api.env.hosts = ['user1@host1:port1', 'user2@host2.port2']
# self.api.env.passwords = {'user1@host1:port1': 'password1', 'user2@host2.port2': 'password2'}
def setHost(self, host="localhost"):
self.api.env["host_string"] = host
def setHosts(self, hosts=["localhost"]):
"""
list of hosts on which the commands will work
"""
self.api.env.hosts = [hosts]
def help(self):
C = """
easiest way to use do:
f=j.remote.fabric.api
and then
f.api.run(...)
"""
print C
|
bsd-2-clause
|
[
504,
1603,
1220,
9944,
492,
1335,
199,
199,
74,
14,
2253,
14,
3246,
14,
21151,
14,
1074,
342,
199,
199,
646,
2630,
199,
646,
2630,
14,
1246,
199,
199,
3,
687,
2630,
14,
1246,
492,
1255,
465,
289,
1065,
199,
3,
687,
2630,
14,
1246,
492,
5341,
465,
289,
2526,
199,
3,
687,
2630,
14,
1246,
492,
2589,
465,
289,
1813,
199,
3,
687,
2630,
14,
1246,
492,
1551,
63,
5641,
465,
289,
1490,
63,
5641,
199,
3,
687,
2630,
14,
1246,
492,
931,
465,
30540,
199,
3,
687,
2630,
14,
1246,
492,
2498,
465,
289,
2384,
199,
3,
687,
2630,
14,
1246,
492,
5324,
465,
289,
524,
199,
199,
533,
481,
2129,
5157,
837,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1246,
275,
2630,
14,
1246,
267,
291,
14,
409,
4965,
342,
267,
291,
14,
1246,
14,
1813,
14,
28608,
275,
1052,
339,
347,
663,
2698,
4986,
2989,
8,
277,
12,
12671,
12,
1102,
628,
5967,
2349,
267,
291,
14,
1246,
14,
1813,
905,
2060,
8713,
12671,
267,
291,
14,
1246,
14,
1813,
14,
28608,
905,
1231,
19437,
83,
6808,
1102,
10404,
12671,
267,
327,
291,
14,
1246,
14,
1813,
14,
5146,
275,
788,
751,
17,
32,
1102,
17,
26,
719,
17,
297,
283,
751,
18,
32,
1102,
18,
14,
719,
18,
418,
267,
327,
291,
14,
1246,
14,
1813,
14,
28608,
275,
791,
751,
17,
32,
1102,
17,
26,
719,
17,
356,
283,
2060,
17,
297,
283,
751,
18,
32,
1102,
18,
14,
719,
18,
356,
283,
2060,
18,
936,
339,
347,
663,
4965,
8,
277,
12,
1591,
628,
5967,
2349,
267,
291,
14,
1246,
14,
1813,
905,
1102,
63,
875,
937,
275,
1591,
339,
347,
663,
19620,
8,
277,
12,
7057,
6270,
5967,
21473,
267,
408,
267,
769,
402,
7057,
641,
1314,
314,
3718,
911,
1736,
267,
408,
267,
291,
14,
1246,
14,
1813,
14,
5146,
275,
359,
5146,
61,
339,
347,
1720,
8,
277,
304,
267,
445,
275,
408,
199,
69,
24950,
597,
4340,
370,
675,
886,
26,
199,
70,
29,
74,
14,
3846,
14,
4991,
14,
1246,
199,
460,
2066,
199,
199,
70,
14,
1246,
14,
1065,
20186,
267,
408,
267,
870,
445,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1603,
1220,
9944,
492,
1335,
199,
199,
74,
14,
2253,
14,
3246,
14,
21151,
14,
1074,
342,
199,
199,
646,
2630,
199,
646,
2630,
14,
1246,
199,
199,
3,
687,
2630,
14,
1246,
492,
1255,
465,
289,
1065,
199,
3,
687,
2630,
14,
1246,
492,
5341,
465,
289,
2526,
199,
3,
687,
2630,
14,
1246,
492,
2589,
465,
289,
1813,
199,
3,
687,
2630,
14,
1246,
492,
1551,
63,
5641,
465,
289,
1490,
63,
5641,
199,
3,
687,
2630,
14,
1246,
492,
931,
465,
30540,
199,
3,
687,
2630,
14,
1246,
492,
2498,
465,
289,
2384,
199,
3,
687,
2630,
14,
1246,
492,
5324,
465,
289,
524,
199,
199,
533,
481,
2129,
5157,
837,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1246,
275,
2630,
14,
1246,
267,
291,
14,
409,
4965,
342,
267,
291,
14,
1246,
14,
1813,
14,
28608,
275,
1052,
339,
347,
663,
2698,
4986,
2989,
8,
277,
12,
12671,
12,
1102,
628,
5967,
2349,
267,
291,
14,
1246,
14,
1813,
905,
2060,
8713,
12671,
267,
291,
14,
1246,
14,
1813,
14,
28608,
905,
1231,
19437,
83,
6808,
1102,
10404,
12671,
267,
327,
291,
14,
1246,
14,
1813,
14,
5146,
275,
788,
751,
17,
32,
1102,
17,
26,
719,
17,
297,
283,
751,
18,
32,
1102,
18,
14,
719,
18,
418,
267,
327,
291,
14,
1246,
14,
1813,
14,
28608,
275,
791,
751,
17,
32,
1102,
17,
26,
719,
17,
356,
283,
2060,
17,
297,
283,
751,
18,
32,
1102,
18,
14,
719,
18,
356,
283,
2060,
18,
936,
339,
347,
663,
4965,
8,
277,
12,
1591,
628,
5967,
2349,
267,
291,
14,
1246,
14,
1813,
905,
1102,
63,
875,
937,
275,
1591,
339,
347,
663,
19620,
8,
277,
12,
7057,
6270,
5967,
21473,
267,
408,
267,
769,
402,
7057,
641,
1314,
314,
3718,
911,
1736,
267,
408,
267,
291,
14,
1246,
14,
1813,
14,
5146,
275,
359,
5146,
61,
339,
347,
1720,
8,
277,
304,
267,
445,
275,
408,
199,
69,
24950,
597,
4340,
370,
675,
886,
26,
199,
70,
29,
74,
14,
3846,
14,
4991,
14,
1246,
199,
460,
2066,
199,
199,
70,
14,
1246,
14,
1065,
20186,
267,
408,
267,
870,
445,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
rembo10/headphones
|
lib/unidecode/x08d.py
|
252
|
4636
|
data = (
'Wei ', # 0x00
'Bai ', # 0x01
'Chen ', # 0x02
'Zhuan ', # 0x03
'Zhi ', # 0x04
'Zhui ', # 0x05
'Biao ', # 0x06
'Yun ', # 0x07
'Zeng ', # 0x08
'Tan ', # 0x09
'Zan ', # 0x0a
'Yan ', # 0x0b
'[?] ', # 0x0c
'Shan ', # 0x0d
'Wan ', # 0x0e
'Ying ', # 0x0f
'Jin ', # 0x10
'Gan ', # 0x11
'Xian ', # 0x12
'Zang ', # 0x13
'Bi ', # 0x14
'Du ', # 0x15
'Shu ', # 0x16
'Yan ', # 0x17
'[?] ', # 0x18
'Xuan ', # 0x19
'Long ', # 0x1a
'Gan ', # 0x1b
'Zang ', # 0x1c
'Bei ', # 0x1d
'Zhen ', # 0x1e
'Fu ', # 0x1f
'Yuan ', # 0x20
'Gong ', # 0x21
'Cai ', # 0x22
'Ze ', # 0x23
'Xian ', # 0x24
'Bai ', # 0x25
'Zhang ', # 0x26
'Huo ', # 0x27
'Zhi ', # 0x28
'Fan ', # 0x29
'Tan ', # 0x2a
'Pin ', # 0x2b
'Bian ', # 0x2c
'Gou ', # 0x2d
'Zhu ', # 0x2e
'Guan ', # 0x2f
'Er ', # 0x30
'Jian ', # 0x31
'Bi ', # 0x32
'Shi ', # 0x33
'Tie ', # 0x34
'Gui ', # 0x35
'Kuang ', # 0x36
'Dai ', # 0x37
'Mao ', # 0x38
'Fei ', # 0x39
'He ', # 0x3a
'Yi ', # 0x3b
'Zei ', # 0x3c
'Zhi ', # 0x3d
'Jia ', # 0x3e
'Hui ', # 0x3f
'Zi ', # 0x40
'Ren ', # 0x41
'Lu ', # 0x42
'Zang ', # 0x43
'Zi ', # 0x44
'Gai ', # 0x45
'Jin ', # 0x46
'Qiu ', # 0x47
'Zhen ', # 0x48
'Lai ', # 0x49
'She ', # 0x4a
'Fu ', # 0x4b
'Du ', # 0x4c
'Ji ', # 0x4d
'Shu ', # 0x4e
'Shang ', # 0x4f
'Si ', # 0x50
'Bi ', # 0x51
'Zhou ', # 0x52
'Geng ', # 0x53
'Pei ', # 0x54
'Tan ', # 0x55
'Lai ', # 0x56
'Feng ', # 0x57
'Zhui ', # 0x58
'Fu ', # 0x59
'Zhuan ', # 0x5a
'Sai ', # 0x5b
'Ze ', # 0x5c
'Yan ', # 0x5d
'Zan ', # 0x5e
'Yun ', # 0x5f
'Zeng ', # 0x60
'Shan ', # 0x61
'Ying ', # 0x62
'Gan ', # 0x63
'Chi ', # 0x64
'Xi ', # 0x65
'She ', # 0x66
'Nan ', # 0x67
'Xiong ', # 0x68
'Xi ', # 0x69
'Cheng ', # 0x6a
'He ', # 0x6b
'Cheng ', # 0x6c
'Zhe ', # 0x6d
'Xia ', # 0x6e
'Tang ', # 0x6f
'Zou ', # 0x70
'Zou ', # 0x71
'Li ', # 0x72
'Jiu ', # 0x73
'Fu ', # 0x74
'Zhao ', # 0x75
'Gan ', # 0x76
'Qi ', # 0x77
'Shan ', # 0x78
'Qiong ', # 0x79
'Qin ', # 0x7a
'Xian ', # 0x7b
'Ci ', # 0x7c
'Jue ', # 0x7d
'Qin ', # 0x7e
'Chi ', # 0x7f
'Ci ', # 0x80
'Chen ', # 0x81
'Chen ', # 0x82
'Die ', # 0x83
'Ju ', # 0x84
'Chao ', # 0x85
'Di ', # 0x86
'Se ', # 0x87
'Zhan ', # 0x88
'Zhu ', # 0x89
'Yue ', # 0x8a
'Qu ', # 0x8b
'Jie ', # 0x8c
'Chi ', # 0x8d
'Chu ', # 0x8e
'Gua ', # 0x8f
'Xue ', # 0x90
'Ci ', # 0x91
'Tiao ', # 0x92
'Duo ', # 0x93
'Lie ', # 0x94
'Gan ', # 0x95
'Suo ', # 0x96
'Cu ', # 0x97
'Xi ', # 0x98
'Zhao ', # 0x99
'Su ', # 0x9a
'Yin ', # 0x9b
'Ju ', # 0x9c
'Jian ', # 0x9d
'Que ', # 0x9e
'Tang ', # 0x9f
'Chuo ', # 0xa0
'Cui ', # 0xa1
'Lu ', # 0xa2
'Qu ', # 0xa3
'Dang ', # 0xa4
'Qiu ', # 0xa5
'Zi ', # 0xa6
'Ti ', # 0xa7
'Qu ', # 0xa8
'Chi ', # 0xa9
'Huang ', # 0xaa
'Qiao ', # 0xab
'Qiao ', # 0xac
'Yao ', # 0xad
'Zao ', # 0xae
'Ti ', # 0xaf
'[?] ', # 0xb0
'Zan ', # 0xb1
'Zan ', # 0xb2
'Zu ', # 0xb3
'Pa ', # 0xb4
'Bao ', # 0xb5
'Ku ', # 0xb6
'Ke ', # 0xb7
'Dun ', # 0xb8
'Jue ', # 0xb9
'Fu ', # 0xba
'Chen ', # 0xbb
'Jian ', # 0xbc
'Fang ', # 0xbd
'Zhi ', # 0xbe
'Sa ', # 0xbf
'Yue ', # 0xc0
'Pa ', # 0xc1
'Qi ', # 0xc2
'Yue ', # 0xc3
'Qiang ', # 0xc4
'Tuo ', # 0xc5
'Tai ', # 0xc6
'Yi ', # 0xc7
'Nian ', # 0xc8
'Ling ', # 0xc9
'Mei ', # 0xca
'Ba ', # 0xcb
'Die ', # 0xcc
'Ku ', # 0xcd
'Tuo ', # 0xce
'Jia ', # 0xcf
'Ci ', # 0xd0
'Pao ', # 0xd1
'Qia ', # 0xd2
'Zhu ', # 0xd3
'Ju ', # 0xd4
'Die ', # 0xd5
'Zhi ', # 0xd6
'Fu ', # 0xd7
'Pan ', # 0xd8
'Ju ', # 0xd9
'Shan ', # 0xda
'Bo ', # 0xdb
'Ni ', # 0xdc
'Ju ', # 0xdd
'Li ', # 0xde
'Gen ', # 0xdf
'Yi ', # 0xe0
'Ji ', # 0xe1
'Dai ', # 0xe2
'Xian ', # 0xe3
'Jiao ', # 0xe4
'Duo ', # 0xe5
'Zhu ', # 0xe6
'Zhuan ', # 0xe7
'Kua ', # 0xe8
'Zhuai ', # 0xe9
'Gui ', # 0xea
'Qiong ', # 0xeb
'Kui ', # 0xec
'Xiang ', # 0xed
'Chi ', # 0xee
'Lu ', # 0xef
'Beng ', # 0xf0
'Zhi ', # 0xf1
'Jia ', # 0xf2
'Tiao ', # 0xf3
'Cai ', # 0xf4
'Jian ', # 0xf5
'Ta ', # 0xf6
'Qiao ', # 0xf7
'Bi ', # 0xf8
'Xian ', # 0xf9
'Duo ', # 0xfa
'Ji ', # 0xfb
'Ju ', # 0xfc
'Ji ', # 0xfd
'Shu ', # 0xfe
'Tu ', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
383,
199,
7,
34,
5789,
1656,
259,
327,
378,
88,
614,
199,
7,
1049,
287,
1656,
259,
327,
378,
88,
996,
199,
7,
12674,
7856,
1656,
259,
327,
378,
88,
1644,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
966,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
1717,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
1690,
199,
7,
57,
324,
1656,
259,
327,
378,
88,
1780,
199,
7,
58,
7420,
1656,
259,
327,
378,
88,
2036,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
1643,
199,
7,
58,
290,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
26797,
1656,
259,
327,
378,
88,
16,
66,
199,
17892,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
42,
262,
1656,
259,
327,
378,
88,
709,
199,
7,
39,
290,
1656,
259,
327,
378,
88,
845,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
713,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
969,
199,
7,
17975,
1656,
259,
327,
378,
88,
1079,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
1046,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
975,
199,
7,
26797,
1656,
259,
327,
378,
88,
1196,
199,
17892,
1656,
259,
327,
378,
88,
1085,
199,
7,
56,
7856,
1656,
259,
327,
378,
88,
1167,
199,
7,
9551,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
39,
290,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
3655,
73,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
19590,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
57,
7856,
1656,
259,
327,
378,
88,
1165,
199,
7,
39,
951,
1656,
259,
327,
378,
88,
2025,
199,
7,
3630,
73,
1656,
259,
327,
378,
88,
1081,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
1789,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
1194,
199,
7,
34,
5789,
1656,
259,
327,
378,
88,
821,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
1479,
199,
7,
40,
13780,
1656,
259,
327,
378,
88,
1465,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1651,
199,
7,
29745,
1656,
259,
327,
378,
88,
1398,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
19909,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
34,
5653,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
39,
810,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
31183,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
39,
7856,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
539,
1656,
259,
327,
378,
88,
1216,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
2192,
199,
7,
17975,
1656,
259,
327,
378,
88,
708,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
1153,
199,
7,
52,
1873,
1656,
259,
327,
378,
88,
1082,
199,
7,
4324,
1656,
259,
327,
378,
88,
1276,
199,
7,
31487,
621,
1656,
259,
327,
378,
88,
1344,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
1401,
199,
7,
45,
8035,
1656,
259,
327,
378,
88,
1703,
199,
7,
3456,
73,
1656,
259,
327,
378,
88,
1355,
199,
7,
1966,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
21001,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
58,
24708,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
42,
4674,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
22534,
1656,
259,
327,
378,
88,
2167,
199,
7,
5349,
1656,
259,
327,
378,
88,
2953,
199,
7,
18176,
1656,
259,
327,
378,
88,
2260,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
2824,
199,
7,
22534,
1656,
259,
327,
378,
88,
1602,
199,
7,
39,
5789,
1656,
259,
327,
378,
88,
2322,
199,
7,
42,
262,
1656,
259,
327,
378,
88,
2466,
199,
7,
19910,
85,
1656,
259,
327,
378,
88,
2417,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
2006,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1887,
199,
7,
31306,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
19590,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
16911,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
2662,
621,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
18934,
1656,
259,
327,
378,
88,
1400,
199,
7,
17975,
1656,
259,
327,
378,
88,
2869,
199,
7,
58,
11586,
1656,
259,
327,
378,
88,
2528,
199,
7,
39,
7420,
1656,
259,
327,
378,
88,
2481,
199,
7,
8070,
73,
1656,
259,
327,
378,
88,
1477,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
1229,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1367,
199,
7,
38,
7420,
1656,
259,
327,
378,
88,
1641,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
2010,
199,
7,
19590,
1656,
259,
327,
378,
88,
1427,
199,
7,
12674,
7856,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
51,
5789,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
26797,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
58,
290,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
57,
324,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
58,
7420,
1656,
259,
327,
378,
88,
2259,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
2976,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
2789,
199,
7,
39,
290,
1656,
259,
327,
378,
88,
2766,
199,
7,
29218,
1656,
259,
327,
378,
88,
772,
199,
7,
14828,
1656
] |
[
275,
334,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
383,
199,
7,
34,
5789,
1656,
259,
327,
378,
88,
614,
199,
7,
1049,
287,
1656,
259,
327,
378,
88,
996,
199,
7,
12674,
7856,
1656,
259,
327,
378,
88,
1644,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
966,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
1717,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
1690,
199,
7,
57,
324,
1656,
259,
327,
378,
88,
1780,
199,
7,
58,
7420,
1656,
259,
327,
378,
88,
2036,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
1643,
199,
7,
58,
290,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
26797,
1656,
259,
327,
378,
88,
16,
66,
199,
17892,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
42,
262,
1656,
259,
327,
378,
88,
709,
199,
7,
39,
290,
1656,
259,
327,
378,
88,
845,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
713,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
969,
199,
7,
17975,
1656,
259,
327,
378,
88,
1079,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
1046,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
975,
199,
7,
26797,
1656,
259,
327,
378,
88,
1196,
199,
17892,
1656,
259,
327,
378,
88,
1085,
199,
7,
56,
7856,
1656,
259,
327,
378,
88,
1167,
199,
7,
9551,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
39,
290,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
3655,
73,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
19590,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
57,
7856,
1656,
259,
327,
378,
88,
1165,
199,
7,
39,
951,
1656,
259,
327,
378,
88,
2025,
199,
7,
3630,
73,
1656,
259,
327,
378,
88,
1081,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
1789,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
1194,
199,
7,
34,
5789,
1656,
259,
327,
378,
88,
821,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
1479,
199,
7,
40,
13780,
1656,
259,
327,
378,
88,
1465,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1651,
199,
7,
29745,
1656,
259,
327,
378,
88,
1398,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
19909,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
34,
5653,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
39,
810,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
31183,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
39,
7856,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
539,
1656,
259,
327,
378,
88,
1216,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
2192,
199,
7,
17975,
1656,
259,
327,
378,
88,
708,
199,
7,
2662,
73,
1656,
259,
327,
378,
88,
1153,
199,
7,
52,
1873,
1656,
259,
327,
378,
88,
1082,
199,
7,
4324,
1656,
259,
327,
378,
88,
1276,
199,
7,
31487,
621,
1656,
259,
327,
378,
88,
1344,
199,
7,
36,
5789,
1656,
259,
327,
378,
88,
1401,
199,
7,
45,
8035,
1656,
259,
327,
378,
88,
1703,
199,
7,
3456,
73,
1656,
259,
327,
378,
88,
1355,
199,
7,
1966,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
21001,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
58,
24708,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
42,
4674,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
22534,
1656,
259,
327,
378,
88,
2167,
199,
7,
5349,
1656,
259,
327,
378,
88,
2953,
199,
7,
18176,
1656,
259,
327,
378,
88,
2260,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
2824,
199,
7,
22534,
1656,
259,
327,
378,
88,
1602,
199,
7,
39,
5789,
1656,
259,
327,
378,
88,
2322,
199,
7,
42,
262,
1656,
259,
327,
378,
88,
2466,
199,
7,
19910,
85,
1656,
259,
327,
378,
88,
2417,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
2006,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1887,
199,
7,
31306,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
19590,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
16911,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
2662,
621,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
18934,
1656,
259,
327,
378,
88,
1400,
199,
7,
17975,
1656,
259,
327,
378,
88,
2869,
199,
7,
58,
11586,
1656,
259,
327,
378,
88,
2528,
199,
7,
39,
7420,
1656,
259,
327,
378,
88,
2481,
199,
7,
8070,
73,
1656,
259,
327,
378,
88,
1477,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
1229,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1367,
199,
7,
38,
7420,
1656,
259,
327,
378,
88,
1641,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
2010,
199,
7,
19590,
1656,
259,
327,
378,
88,
1427,
199,
7,
12674,
7856,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
51,
5789,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
26797,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
58,
290,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
57,
324,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
58,
7420,
1656,
259,
327,
378,
88,
2259,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
2976,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
2789,
199,
7,
39,
290,
1656,
259,
327,
378,
88,
2766,
199,
7,
29218,
1656,
259,
327,
378,
88,
772,
199,
7,
14828,
1656,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shsingh/ansible
|
lib/ansible/modules/network/dellos6/dellos6_facts.py
|
50
|
15435
|
#!/usr/bin/python
#
# (c) 2015 Peter Sprygada, <psprygada@ansible.com>
# Copyright (c) 2016 Dell 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 = """
---
module: dellos6_facts
version_added: "2.2"
author: "Abirami N (@abirami-n)"
short_description: Collect facts from remote devices running Dell EMC Networking OS6
description:
- Collects a base set of device facts from a remote device that
is running OS6. This module prepends all of the
base network fact keys with C(ansible_net_<fact>). The facts
module will always collect a base set of facts from the device
and can enable or disable collection of additional facts.
extends_documentation_fragment: dellos6
options:
gather_subset:
description:
- When supplied, this argument will restrict the facts collected
to a given subset. Possible values for this argument include
all, hardware, config, and interfaces. Can specify a list of
values to include a larger subset. Values can also be used
with an initial C(M(!)) to specify that a specific subset should
not be collected.
default: [ '!config' ]
"""
EXAMPLES = """
# Collect all facts from the device
- dellos6_facts:
gather_subset: all
# Collect only the config and default facts
- dellos6_facts:
gather_subset:
- config
# Do not collect hardware facts
- dellos6_facts:
gather_subset:
- "!interfaces"
"""
RETURN = """
ansible_net_gather_subset:
description: The list of fact subsets collected from the device.
returned: always.
type: list
# default
ansible_net_model:
description: The model name returned from the device.
returned: always.
type: str
ansible_net_serialnum:
description: The serial number of the remote device.
returned: always.
type: str
ansible_net_version:
description: The operating system version running on the remote device.
returned: always.
type: str
ansible_net_hostname:
description: The configured hostname of the device.
returned: always.
type: str
ansible_net_image:
description: The image file that the device is running.
returned: always
type: str
# hardware
ansible_net_memfree_mb:
description: The available free memory on the remote device in MB.
returned: When hardware is configured.
type: int
ansible_net_memtotal_mb:
description: The total memory on the remote device in MB.
returned: When hardware is configured.
type: int
# config
ansible_net_config:
description: The current active config from the device.
returned: When config is configured.
type: str
# interfaces
ansible_net_interfaces:
description: A hash of all interfaces running on the system.
returned: When interfaces is configured.
type: dict
ansible_net_neighbors:
description: The list of LLDP neighbors from the remote device.
returned: When interfaces is configured.
type: dict
"""
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.dellos6.dellos6 import run_commands
from ansible.module_utils.network.dellos6.dellos6 import dellos6_argument_spec, check_args
from ansible.module_utils.six import iteritems
class FactsBase(object):
COMMANDS = list()
def __init__(self, module):
self.module = module
self.facts = dict()
self.responses = None
def populate(self):
self.responses = run_commands(self.module, self.COMMANDS, check_rc=False)
def run(self, cmd):
return run_commands(self.module, cmd, check_rc=False)
class Default(FactsBase):
COMMANDS = [
'show version',
'show running-config | include hostname'
]
def populate(self):
super(Default, self).populate()
data = self.responses[0]
self.facts['version'] = self.parse_version(data)
self.facts['serialnum'] = self.parse_serialnum(data)
self.facts['model'] = self.parse_model(data)
self.facts['image'] = self.parse_image(data)
hdata = self.responses[1]
self.facts['hostname'] = self.parse_hostname(hdata)
def parse_version(self, data):
facts = dict()
match = re.search(r'HW Version(.+)\s(\d+)', data)
temp, temp_next = data.split('---- ----------- ----------- -------------- --------------')
for en in temp_next.splitlines():
if en == '':
continue
match_image = re.search(r'^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)', en)
version = match_image.group(4)
facts["Version"] = list()
fact = dict()
fact['HW Version'] = match.group(2)
fact['SW Version'] = match_image.group(4)
facts["Version"].append(fact)
return facts
def parse_hostname(self, data):
match = re.search(r'\S+\s(\S+)', data, re.M)
if match:
return match.group(1)
def parse_model(self, data):
match = re.search(r'System Model ID(.+)\s([A-Z0-9]*)\n', data, re.M)
if match:
return match.group(2)
def parse_image(self, data):
match = re.search(r'Image File(.+)\s([A-Z0-9a-z_.]*)\n', data)
if match:
return match.group(2)
def parse_serialnum(self, data):
match = re.search(r'Serial Number(.+)\s([A-Z0-9]*)\n', data)
if match:
return match.group(2)
class Hardware(FactsBase):
COMMANDS = [
'show memory cpu'
]
def populate(self):
super(Hardware, self).populate()
data = self.responses[0]
match = re.findall(r'\s(\d+)\s', data)
if match:
self.facts['memtotal_mb'] = int(match[0]) // 1024
self.facts['memfree_mb'] = int(match[1]) // 1024
class Config(FactsBase):
COMMANDS = ['show running-config']
def populate(self):
super(Config, self).populate()
self.facts['config'] = self.responses[0]
class Interfaces(FactsBase):
COMMANDS = [
'show interfaces',
'show interfaces status',
'show interfaces transceiver properties',
'show ip int',
'show lldp',
'show lldp remote-device all',
'show version'
]
def populate(self):
vlan_info = dict()
super(Interfaces, self).populate()
data = self.responses[0]
interfaces = self.parse_interfaces(data)
desc = self.responses[1]
properties = self.responses[2]
vlan = self.responses[3]
version_info = self.responses[6]
vlan_info = self.parse_vlan(vlan, version_info)
self.facts['interfaces'] = self.populate_interfaces(interfaces, desc, properties)
self.facts['interfaces'].update(vlan_info)
if 'LLDP is not enabled' not in self.responses[4]:
neighbors = self.responses[5]
self.facts['neighbors'] = self.parse_neighbors(neighbors)
def parse_vlan(self, vlan, version_info):
facts = dict()
if "N11" in version_info:
match = re.search(r'IP Address(.+)\s([0-9.]*)\n', vlan)
mask = re.search(r'Subnet Mask(.+)\s([0-9.]*)\n', vlan)
vlan_id_match = re.search(r'Management VLAN ID(.+)\s(\d+)', vlan)
vlan_id = "Vl" + vlan_id_match.group(2)
if vlan_id not in facts:
facts[vlan_id] = list()
fact = dict()
fact['address'] = match.group(2)
fact['masklen'] = mask.group(2)
facts[vlan_id].append(fact)
else:
vlan_info, vlan_info_next = vlan.split('---------- ----- --------------- --------------- -------')
for en in vlan_info_next.splitlines():
if en == '':
continue
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
intf = match.group(1)
if intf not in facts:
facts[intf] = list()
fact = dict()
matc = re.search(r'^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en)
fact['address'] = matc.group(2)
fact['masklen'] = matc.group(3)
facts[intf].append(fact)
return facts
def populate_interfaces(self, interfaces, desc, properties):
facts = dict()
for key, value in interfaces.items():
intf = dict()
intf['description'] = self.parse_description(key, desc)
intf['macaddress'] = self.parse_macaddress(value)
intf['mtu'] = self.parse_mtu(value)
intf['bandwidth'] = self.parse_bandwidth(value)
intf['mediatype'] = self.parse_mediatype(key, properties)
intf['duplex'] = self.parse_duplex(value)
intf['lineprotocol'] = self.parse_lineprotocol(value)
intf['operstatus'] = self.parse_operstatus(value)
intf['type'] = self.parse_type(key, properties)
facts[key] = intf
return facts
def parse_neighbors(self, neighbors):
facts = dict()
neighbor, neighbor_next = neighbors.split('--------- ------- ------------------- ----------------- -----------------')
for en in neighbor_next.splitlines():
if en == '':
continue
intf = self.parse_lldp_intf(en.split()[0])
if intf not in facts:
facts[intf] = list()
fact = dict()
fact['port'] = self.parse_lldp_port(en.split()[3])
if (len(en.split()) > 4):
fact['host'] = self.parse_lldp_host(en.split()[4])
else:
fact['host'] = "Null"
facts[intf].append(fact)
return facts
def parse_interfaces(self, data):
parsed = dict()
for line in data.split('\n'):
if len(line) == 0:
continue
else:
match = re.match(r'Interface Name(.+)\s([A-Za-z0-9/]*)', line)
if match:
key = match.group(2)
parsed[key] = line
else:
parsed[key] += '\n%s' % line
return parsed
def parse_description(self, key, desc):
desc, desc_next = desc.split('--------- --------------- ------ ------- ---- ------ ----- -- -------------------')
if desc_next.find('Oob') > 0:
desc_val, desc_info = desc_next.split('Oob')
elif desc_next.find('Port') > 0:
desc_val, desc_info = desc_next.split('Port')
for en in desc_val.splitlines():
if key in en:
match = re.search(r'^(\S+)\s+(\S+)', en)
if match.group(2) in ['Full', 'N/A']:
return "Null"
else:
return match.group(2)
def parse_macaddress(self, data):
match = re.search(r'Burned In MAC Address(.+)\s([A-Z0-9.]*)\n', data)
if match:
return match.group(2)
def parse_mtu(self, data):
match = re.search(r'MTU Size(.+)\s(\d+)\n', data)
if match:
return int(match.group(2))
def parse_bandwidth(self, data):
match = re.search(r'Port Speed\s*[:\s\.]+\s(\d+)\n', data)
if match:
return int(match.group(1))
def parse_duplex(self, data):
match = re.search(r'Port Mode\s([A-Za-z]*)(.+)\s([A-Za-z/]*)\n', data)
if match:
return match.group(3)
def parse_mediatype(self, key, properties):
mediatype, mediatype_next = properties.split('--------- ------- --------------------- --------------------- --------------')
flag = 1
for en in mediatype_next.splitlines():
if key in en:
flag = 0
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
if match:
strval = match.group(3)
return strval
if flag == 1:
return "null"
def parse_type(self, key, properties):
type_val, type_val_next = properties.split('--------- ------- --------------------- --------------------- --------------')
flag = 1
for en in type_val_next.splitlines():
if key in en:
flag = 0
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
if match:
strval = match.group(2)
return strval
if flag == 1:
return "null"
def parse_lineprotocol(self, data):
data = data.splitlines()
for d in data:
match = re.search(r'^Link Status\s*[:\s\.]+\s(\S+)', d)
if match:
return match.group(1)
def parse_operstatus(self, data):
data = data.splitlines()
for d in data:
match = re.search(r'^Link Status\s*[:\s\.]+\s(\S+)', d)
if match:
return match.group(1)
def parse_lldp_intf(self, data):
match = re.search(r'^([A-Za-z0-9/]*)', data)
if match:
return match.group(1)
def parse_lldp_host(self, data):
match = re.search(r'^([A-Za-z0-9-]*)', data)
if match:
return match.group(1)
def parse_lldp_port(self, data):
match = re.search(r'^([A-Za-z0-9/]*)', data)
if match:
return match.group(1)
FACT_SUBSETS = dict(
default=Default,
hardware=Hardware,
interfaces=Interfaces,
config=Config,
)
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
def main():
"""main entry point for module execution
"""
argument_spec = dict(
gather_subset=dict(default=['!config'], type='list')
)
argument_spec.update(dellos6_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
gather_subset = module.params['gather_subset']
runable_subsets = set()
exclude_subsets = set()
for subset in gather_subset:
if subset == 'all':
runable_subsets.update(VALID_SUBSETS)
continue
if subset.startswith('!'):
subset = subset[1:]
if subset == 'all':
exclude_subsets.update(VALID_SUBSETS)
continue
exclude = True
else:
exclude = False
if subset not in VALID_SUBSETS:
module.fail_json(msg='Bad subset')
if exclude:
exclude_subsets.add(subset)
else:
runable_subsets.add(subset)
if not runable_subsets:
runable_subsets.update(VALID_SUBSETS)
runable_subsets.difference_update(exclude_subsets)
runable_subsets.add('default')
facts = dict()
facts['gather_subset'] = list(runable_subsets)
instances = list()
for key in runable_subsets:
instances.append(FACT_SUBSETS[key](module))
for inst in instances:
inst.populate()
facts.update(inst.facts)
ansible_facts = dict()
for key, value in iteritems(facts):
key = 'ansible_net_%s' % key
ansible_facts[key] = value
warnings = list()
check_args(module, warnings)
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
334,
67,
9,
6900,
22912,
8360,
651,
71,
10641,
12,
665,
80,
681,
651,
71,
10641,
32,
4853,
14,
957,
30,
199,
3,
1898,
334,
67,
9,
7800,
577,
1697,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
2150,
11560,
22,
63,
5047,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
298,
33,
4492,
345,
2664,
653,
8593,
14677,
345,
2664,
13,
78,
2924,
199,
3612,
63,
1802,
26,
19649,
9036,
687,
3982,
7256,
3879,
577,
1697,
662,
7608,
7220,
316,
4403,
22,
199,
1802,
26,
523,
446,
19649,
83,
282,
1300,
663,
402,
2243,
9036,
687,
282,
3982,
2243,
626,
272,
365,
3879,
4403,
22,
14,
221,
961,
859,
19986,
3198,
1006,
402,
314,
272,
1300,
2784,
10572,
2883,
543,
445,
8,
4853,
63,
846,
27718,
7783,
10121,
221,
710,
9036,
272,
859,
911,
3544,
8775,
282,
1300,
663,
402,
9036,
687,
314,
2243,
272,
436,
883,
4756,
503,
3507,
3245,
402,
4722,
9036,
14,
199,
11036,
63,
9970,
63,
7677,
26,
2150,
11560,
22,
199,
1419,
26,
523,
13082,
63,
9401,
26,
272,
1369,
26,
489,
446,
3979,
6841,
12,
642,
1423,
911,
18152,
314,
9036,
13736,
267,
370,
282,
1627,
10026,
14,
221,
18558,
1338,
367,
642,
1423,
2387,
267,
1006,
12,
14991,
12,
1101,
12,
436,
8386,
14,
6855,
4165,
282,
769,
402,
267,
1338,
370,
2387,
282,
12142,
10026,
14,
221,
13468,
883,
2597,
506,
1202,
267,
543,
376,
2536,
445,
8,
45,
8,
1,
430,
370,
4165,
626,
282,
2488,
10026,
1077,
267,
440,
506,
13736,
14,
272,
849,
26,
359,
14597,
888,
7,
1622,
199,
624,
199,
199,
8918,
275,
408,
199,
3,
19649,
1006,
9036,
687,
314,
2243,
199,
13,
2150,
11560,
22,
63,
5047,
26,
272,
13082,
63,
9401,
26,
1006,
199,
199,
3,
19649,
1454,
314,
1101,
436,
849,
9036,
199,
13,
2150,
11560,
22,
63,
5047,
26,
272,
13082,
63,
9401,
26,
489,
446,
1101,
199,
199,
3,
4226,
440,
8775,
14991,
9036,
199,
13,
2150,
11560,
22,
63,
5047,
26,
272,
13082,
63,
9401,
26,
489,
446,
19724,
7436,
2,
199,
624,
199,
199,
9677,
275,
408,
199,
4853,
63,
846,
63,
13737,
63,
9401,
26,
523,
1369,
26,
710,
769,
402,
10572,
30767,
13736,
687,
314,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
769,
199,
199,
3,
849,
199,
4853,
63,
846,
63,
1238,
26,
523,
1369,
26,
710,
1402,
536,
2138,
687,
314,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
2171,
1507,
26,
523,
1369,
26,
710,
3012,
1329,
402,
314,
3982,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
1023,
26,
523,
1369,
26,
710,
17406,
2656,
1015,
3879,
641,
314,
3982,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
4269,
26,
523,
1369,
26,
710,
7526,
6246,
402,
314,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
1569,
26,
523,
1369,
26,
710,
1834,
570,
626,
314,
2243,
365,
3879,
14,
523,
2138,
26,
3544,
523,
730,
26,
620,
199,
199,
3,
14991,
199,
4853,
63,
846,
63,
5286,
4624,
63,
887,
26,
523,
1369,
26,
710,
2808,
2867,
4402,
641,
314,
3982,
2243,
315,
19487,
14,
523,
2138,
26,
3979,
14991,
365,
7526,
14,
523,
730,
26,
1109,
199,
4853,
63,
846,
63,
278,
2037,
1735,
63,
887,
26,
523,
1369,
26,
710,
3141,
4402,
641,
314,
3982,
2243,
315,
19487,
14,
523,
2138,
26,
3979,
14991,
365,
7526,
14,
523,
730,
26,
1109,
199,
199,
3,
1101,
199,
4853,
63,
846,
63,
888,
26,
523,
1369,
26,
710,
1453,
4702,
1101,
687,
314,
2243,
14,
523,
2138,
26,
3979,
1101,
365,
7526,
14,
523,
730,
26,
620,
199,
199,
3,
8386,
199,
4853,
63,
846,
63,
7436,
26,
523,
1369,
26,
437,
2631,
402,
1006,
8386,
3879,
641,
314,
2656,
14,
523,
2138,
26,
3979,
8386,
365,
7526,
14,
523,
730,
26,
1211,
199,
4853,
63,
846,
63,
11113,
26,
523,
1369,
26,
710,
769,
402,
491,
29187,
15845,
687,
314,
3982,
2243,
14,
523,
2138,
26,
3979,
8386,
365,
7526,
14,
523,
730,
26,
1211,
199,
199,
624,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2264,
11560,
22,
14,
2264,
11560,
22,
492,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2264,
11560,
22,
14,
2264,
11560,
22,
492,
2150,
11560,
22,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
421,
199,
533,
481,
22282,
1563,
8,
785,
304,
339,
11293,
20033,
275,
769,
342,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
267,
291,
14,
5047,
275,
1211,
342,
267,
291,
14,
10360,
275,
488,
339,
347,
13904,
8,
277,
304,
267,
291,
14,
10360,
275,
1255,
63,
4405,
8,
277,
14,
578,
12,
291,
14,
28442,
12,
1104,
63,
1195,
29,
797,
9,
339,
347,
1255,
8,
277,
12,
2088,
304,
267,
372,
1255,
63,
4405,
8,
277,
14,
578,
12,
2088,
12,
1104,
63,
1195,
29,
797,
9,
421,
199,
533,
3758,
8,
25821,
1563,
304,
339,
11293,
20033,
275,
359,
267,
283,
2384,
1015,
297,
267,
283,
2384,
3879,
13,
888,
1204,
2387,
6246,
7,
272,
1622,
339,
347,
13904,
8,
277,
304,
267,
1613,
8,
2698,
12
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
334,
67,
9,
6900,
22912,
8360,
651,
71,
10641,
12,
665,
80,
681,
651,
71,
10641,
32,
4853,
14,
957,
30,
199,
3,
1898,
334,
67,
9,
7800,
577,
1697,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
2150,
11560,
22,
63,
5047,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
298,
33,
4492,
345,
2664,
653,
8593,
14677,
345,
2664,
13,
78,
2924,
199,
3612,
63,
1802,
26,
19649,
9036,
687,
3982,
7256,
3879,
577,
1697,
662,
7608,
7220,
316,
4403,
22,
199,
1802,
26,
523,
446,
19649,
83,
282,
1300,
663,
402,
2243,
9036,
687,
282,
3982,
2243,
626,
272,
365,
3879,
4403,
22,
14,
221,
961,
859,
19986,
3198,
1006,
402,
314,
272,
1300,
2784,
10572,
2883,
543,
445,
8,
4853,
63,
846,
27718,
7783,
10121,
221,
710,
9036,
272,
859,
911,
3544,
8775,
282,
1300,
663,
402,
9036,
687,
314,
2243,
272,
436,
883,
4756,
503,
3507,
3245,
402,
4722,
9036,
14,
199,
11036,
63,
9970,
63,
7677,
26,
2150,
11560,
22,
199,
1419,
26,
523,
13082,
63,
9401,
26,
272,
1369,
26,
489,
446,
3979,
6841,
12,
642,
1423,
911,
18152,
314,
9036,
13736,
267,
370,
282,
1627,
10026,
14,
221,
18558,
1338,
367,
642,
1423,
2387,
267,
1006,
12,
14991,
12,
1101,
12,
436,
8386,
14,
6855,
4165,
282,
769,
402,
267,
1338,
370,
2387,
282,
12142,
10026,
14,
221,
13468,
883,
2597,
506,
1202,
267,
543,
376,
2536,
445,
8,
45,
8,
1,
430,
370,
4165,
626,
282,
2488,
10026,
1077,
267,
440,
506,
13736,
14,
272,
849,
26,
359,
14597,
888,
7,
1622,
199,
624,
199,
199,
8918,
275,
408,
199,
3,
19649,
1006,
9036,
687,
314,
2243,
199,
13,
2150,
11560,
22,
63,
5047,
26,
272,
13082,
63,
9401,
26,
1006,
199,
199,
3,
19649,
1454,
314,
1101,
436,
849,
9036,
199,
13,
2150,
11560,
22,
63,
5047,
26,
272,
13082,
63,
9401,
26,
489,
446,
1101,
199,
199,
3,
4226,
440,
8775,
14991,
9036,
199,
13,
2150,
11560,
22,
63,
5047,
26,
272,
13082,
63,
9401,
26,
489,
446,
19724,
7436,
2,
199,
624,
199,
199,
9677,
275,
408,
199,
4853,
63,
846,
63,
13737,
63,
9401,
26,
523,
1369,
26,
710,
769,
402,
10572,
30767,
13736,
687,
314,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
769,
199,
199,
3,
849,
199,
4853,
63,
846,
63,
1238,
26,
523,
1369,
26,
710,
1402,
536,
2138,
687,
314,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
2171,
1507,
26,
523,
1369,
26,
710,
3012,
1329,
402,
314,
3982,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
1023,
26,
523,
1369,
26,
710,
17406,
2656,
1015,
3879,
641,
314,
3982,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
4269,
26,
523,
1369,
26,
710,
7526,
6246,
402,
314,
2243,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
620,
199,
4853,
63,
846,
63,
1569,
26,
523,
1369,
26,
710,
1834,
570,
626,
314,
2243,
365,
3879,
14,
523,
2138,
26,
3544,
523,
730,
26,
620,
199,
199,
3,
14991,
199,
4853,
63,
846,
63,
5286,
4624,
63,
887,
26,
523,
1369,
26,
710,
2808,
2867,
4402,
641,
314,
3982,
2243,
315,
19487,
14,
523,
2138,
26,
3979,
14991,
365,
7526,
14,
523,
730,
26,
1109,
199,
4853,
63,
846,
63,
278,
2037,
1735,
63,
887,
26,
523,
1369,
26,
710,
3141,
4402,
641,
314,
3982,
2243,
315,
19487,
14,
523,
2138,
26,
3979,
14991,
365,
7526,
14,
523,
730,
26,
1109,
199,
199,
3,
1101,
199,
4853,
63,
846,
63,
888,
26,
523,
1369,
26,
710,
1453,
4702,
1101,
687,
314,
2243,
14,
523,
2138,
26,
3979,
1101,
365,
7526,
14,
523,
730,
26,
620,
199,
199,
3,
8386,
199,
4853,
63,
846,
63,
7436,
26,
523,
1369,
26,
437,
2631,
402,
1006,
8386,
3879,
641,
314,
2656,
14,
523,
2138,
26,
3979,
8386,
365,
7526,
14,
523,
730,
26,
1211,
199,
4853,
63,
846,
63,
11113,
26,
523,
1369,
26,
710,
769,
402,
491,
29187,
15845,
687,
314,
3982,
2243,
14,
523,
2138,
26,
3979,
8386,
365,
7526,
14,
523,
730,
26,
1211,
199,
199,
624,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2264,
11560,
22,
14,
2264,
11560,
22,
492,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2264,
11560,
22,
14,
2264,
11560,
22,
492,
2150,
11560,
22,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
421,
199,
533,
481,
22282,
1563,
8,
785,
304,
339,
11293,
20033,
275,
769,
342,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
267,
291,
14,
5047,
275,
1211,
342,
267,
291,
14,
10360,
275,
488,
339,
347,
13904,
8,
277,
304,
267,
291,
14,
10360,
275,
1255,
63,
4405,
8,
277,
14,
578,
12,
291,
14,
28442,
12,
1104,
63,
1195,
29,
797,
9,
339,
347,
1255,
8,
277,
12,
2088,
304,
267,
372,
1255,
63,
4405,
8,
277,
14,
578,
12,
2088,
12,
1104,
63,
1195,
29,
797,
9,
421,
199,
533,
3758,
8,
25821,
1563,
304,
339,
11293,
20033,
275,
359,
267,
283,
2384,
1015,
297,
267,
283,
2384,
3879,
13,
888,
1204,
2387,
6246,
7,
272,
1622,
339,
347,
13904,
8,
277,
304,
267,
1613,
8,
2698,
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,
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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
] |
andnovar/networkx
|
networkx/algorithms/shortest_paths/tests/test_generic.py
|
1
|
7273
|
from __future__ import division
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_false
from nose.tools import assert_true
from nose.tools import assert_raises
from nose.tools import ok_
from nose.tools import raises
import networkx as nx
def validate_grid_path(r, c, s, t, p):
ok_(isinstance(p, list))
assert_equal(p[0], s)
assert_equal(p[-1], t)
s = ((s - 1) // c, (s - 1) % c)
t = ((t - 1) // c, (t - 1) % c)
assert_equal(len(p), abs(t[0] - s[0]) + abs(t[1] - s[1]) + 1)
p = [((u - 1) // c, (u - 1) % c) for u in p]
for u in p:
ok_(0 <= u[0] < r)
ok_(0 <= u[1] < c)
for u, v in zip(p[:-1], p[1:]):
ok_((abs(v[0] - u[0]), abs(v[1] - u[1])) in [(0, 1), (1, 0)])
class TestGenericPath:
def setUp(self):
from networkx import convert_node_labels_to_integers as cnlti
self.grid=cnlti(nx.grid_2d_graph(4,4),first_label=1,ordering="sorted")
self.cycle=nx.cycle_graph(7)
self.directed_cycle=nx.cycle_graph(7,create_using=nx.DiGraph())
def test_shortest_path(self):
assert_equal(nx.shortest_path(self.cycle,0,3),[0, 1, 2, 3])
assert_equal(nx.shortest_path(self.cycle,0,4),[0, 6, 5, 4])
validate_grid_path(4, 4, 1, 12, nx.shortest_path(self.grid,1,12))
assert_equal(nx.shortest_path(self.directed_cycle,0,3),[0, 1, 2, 3])
# now with weights
assert_equal(nx.shortest_path(self.cycle,0,3,weight='weight'),[0, 1, 2, 3])
assert_equal(nx.shortest_path(self.cycle,0,4,weight='weight'),[0, 6, 5, 4])
validate_grid_path(4, 4, 1, 12, nx.shortest_path(self.grid,1,12,weight='weight'))
assert_equal(nx.shortest_path(self.directed_cycle,0,3,weight='weight'),
[0, 1, 2, 3])
def test_shortest_path_target(self):
sp = nx.shortest_path(nx.path_graph(3), target=1)
assert_equal(sp, {0: [0, 1], 1: [1], 2: [2, 1]})
def test_shortest_path_length(self):
assert_equal(nx.shortest_path_length(self.cycle,0,3),3)
assert_equal(nx.shortest_path_length(self.grid,1,12),5)
assert_equal(nx.shortest_path_length(self.directed_cycle,0,4),4)
# now with weights
assert_equal(nx.shortest_path_length(self.cycle,0,3,weight='weight'),3)
assert_equal(nx.shortest_path_length(self.grid,1,12,weight='weight'),5)
assert_equal(nx.shortest_path_length(self.directed_cycle,0,4,weight='weight'),4)
def test_shortest_path_length_target(self):
sp = dict(nx.shortest_path_length(nx.path_graph(3), target=1))
assert_equal(sp[0], 1)
assert_equal(sp[1], 0)
assert_equal(sp[2], 1)
def test_single_source_shortest_path(self):
p=nx.shortest_path(self.cycle,0)
assert_equal(p[3],[0,1,2,3])
assert_equal(p,nx.single_source_shortest_path(self.cycle,0))
p=nx.shortest_path(self.grid,1)
validate_grid_path(4, 4, 1, 12, p[12])
# now with weights
p=nx.shortest_path(self.cycle,0,weight='weight')
assert_equal(p[3],[0,1,2,3])
assert_equal(p,nx.single_source_dijkstra_path(self.cycle,0))
p=nx.shortest_path(self.grid,1,weight='weight')
validate_grid_path(4, 4, 1, 12, p[12])
def test_single_source_shortest_path_length(self):
l = dict(nx.shortest_path_length(self.cycle,0))
assert_equal(l,{0:0,1:1,2:2,3:3,4:3,5:2,6:1})
assert_equal(l, dict(nx.single_source_shortest_path_length(self.cycle,0)))
l = dict(nx.shortest_path_length(self.grid,1))
assert_equal(l[16],6)
# now with weights
l = dict(nx.shortest_path_length(self.cycle, 0, weight='weight'))
assert_equal(l, {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1})
assert_equal(l, dict(nx.single_source_dijkstra_path_length(
self.cycle, 0)))
l = dict(nx.shortest_path_length(self.grid, 1, weight='weight'))
assert_equal(l[16], 6)
def test_all_pairs_shortest_path(self):
p=nx.shortest_path(self.cycle)
assert_equal(p[0][3],[0,1,2,3])
assert_equal(p,nx.all_pairs_shortest_path(self.cycle))
p=nx.shortest_path(self.grid)
validate_grid_path(4, 4, 1, 12, p[1][12])
# now with weights
p=nx.shortest_path(self.cycle,weight='weight')
assert_equal(p[0][3],[0,1,2,3])
assert_equal(p,nx.all_pairs_dijkstra_path(self.cycle))
p=nx.shortest_path(self.grid,weight='weight')
validate_grid_path(4, 4, 1, 12, p[1][12])
def test_all_pairs_shortest_path_length(self):
l=dict(nx.shortest_path_length(self.cycle))
assert_equal(l[0],{0:0,1:1,2:2,3:3,4:3,5:2,6:1})
assert_equal(l, dict(nx.all_pairs_shortest_path_length(self.cycle)))
l=dict(nx.shortest_path_length(self.grid))
assert_equal(l[1][16],6)
# now with weights
l = dict(nx.shortest_path_length(self.cycle, weight='weight'))
assert_equal(l[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1})
assert_equal(l, dict(nx.all_pairs_dijkstra_path_length(self.cycle)))
l = dict(nx.shortest_path_length(self.grid, weight='weight'))
assert_equal(l[1][16], 6)
def test_has_path(self):
G = nx.Graph()
G.add_path(range(3))
G.add_path(range(3,5))
assert_true(nx.has_path(G,0,2))
assert_false(nx.has_path(G,0,4))
def test_all_shortest_paths(self):
G = nx.Graph()
G.add_path([0,1,2,3])
G.add_path([0,10,20,3])
assert_equal([[0,1,2,3],[0,10,20,3]],
sorted(nx.all_shortest_paths(G,0,3)))
@raises(nx.NetworkXNoPath)
def test_all_shortest_paths_raise(self):
G = nx.Graph()
G.add_path([0,1,2,3])
G.add_node(4)
paths = list(nx.all_shortest_paths(G,0,4))
class TestAverageShortestPathLength(object):
def test_cycle_graph(self):
l = nx.average_shortest_path_length(nx.cycle_graph(7))
assert_almost_equal(l, 2)
def test_path_graph(self):
l = nx.average_shortest_path_length(nx.path_graph(5))
assert_almost_equal(l, 2)
def test_weighted(self):
G = nx.Graph()
G.add_cycle(range(7), weight=2)
l = nx.average_shortest_path_length(G, weight='weight')
assert_almost_equal(l, 4)
G = nx.Graph()
G.add_path(range(5), weight=2)
l = nx.average_shortest_path_length(G, weight='weight')
assert_almost_equal(l, 4)
def test_disconnected(self):
g = nx.Graph()
g.add_nodes_from(range(3))
g.add_edge(0, 1)
assert_raises(nx.NetworkXError, nx.average_shortest_path_length, g)
g = g.to_directed()
assert_raises(nx.NetworkXError, nx.average_shortest_path_length, g)
def test_trivial_graph(self):
"""Tests that the trivial graph has average path length zero,
since there is exactly one path of length zero in the trivial
graph.
For more information, see issue #1960.
"""
G = nx.trivial_graph()
assert_equal(nx.average_shortest_path_length(G), 0)
@raises(nx.NetworkXPointlessConcept)
def test_null_graph(self):
nx.average_shortest_path_length(nx.null_graph())
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
199,
199,
504,
11354,
14,
2537,
492,
702,
63,
4398,
63,
1452,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
199,
504,
11354,
14,
2537,
492,
702,
63,
3910,
199,
504,
11354,
14,
2537,
492,
702,
63,
2052,
199,
504,
11354,
14,
2537,
492,
702,
63,
3536,
199,
504,
11354,
14,
2537,
492,
4112,
63,
199,
504,
11354,
14,
2537,
492,
6534,
199,
199,
646,
24313,
465,
8484,
421,
199,
318,
4107,
63,
3825,
63,
515,
8,
82,
12,
286,
12,
308,
12,
307,
12,
299,
304,
272,
4112,
2531,
6074,
8,
80,
12,
769,
430,
272,
702,
63,
1452,
8,
80,
59,
16,
467,
308,
9,
272,
702,
63,
1452,
8,
80,
1988,
17,
467,
307,
9,
272,
308,
275,
3666,
83,
446,
413,
9,
5001,
286,
12,
334,
83,
446,
413,
9,
450,
286,
9,
272,
307,
275,
3666,
84,
446,
413,
9,
5001,
286,
12,
334,
84,
446,
413,
9,
450,
286,
9,
272,
702,
63,
1452,
8,
552,
8,
80,
395,
2853,
8,
84,
59,
16,
61,
446,
308,
59,
16,
566,
435,
2853,
8,
84,
59,
17,
61,
446,
308,
59,
17,
566,
435,
413,
9,
272,
299,
275,
359,
1332,
85,
446,
413,
9,
5001,
286,
12,
334,
85,
446,
413,
9,
450,
286,
9,
367,
399,
315,
299,
61,
272,
367,
399,
315,
299,
26,
267,
4112,
2531,
16,
2695,
399,
59,
16,
61,
665,
519,
9,
267,
4112,
2531,
16,
2695,
399,
59,
17,
61,
665,
286,
9,
272,
367,
399,
12,
373,
315,
3482,
8,
80,
4439,
17,
467,
299,
59,
17,
28847,
267,
4112,
63,
1332,
2101,
8,
86,
59,
16,
61,
446,
399,
59,
16,
2522,
2853,
8,
86,
59,
17,
61,
446,
399,
59,
17,
2459,
315,
3842,
16,
12,
413,
395,
334,
17,
12,
378,
3948,
199,
199,
533,
1379,
9417,
2042,
26,
339,
347,
3613,
8,
277,
304,
267,
687,
24313,
492,
3957,
63,
932,
63,
3512,
63,
475,
63,
23931,
465,
286,
7530,
280,
267,
291,
14,
3825,
29,
6413,
21934,
8,
7343,
14,
3825,
63,
18,
68,
63,
2180,
8,
20,
12,
20,
395,
2246,
63,
1302,
29,
17,
12,
7128,
628,
5917,
531,
267,
291,
14,
7612,
29,
7343,
14,
7612,
63,
2180,
8,
23,
9,
267,
291,
14,
12080,
63,
7612,
29,
7343,
14,
7612,
63,
2180,
8,
23,
12,
981,
63,
4941,
29,
7343,
14,
23208,
1012,
2378,
347,
511,
63,
20695,
396,
63,
515,
8,
277,
304,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
19,
395,
59,
16,
12,
413,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
20,
395,
59,
16,
12,
1227,
12,
959,
12,
841,
566,
267,
4107,
63,
3825,
63,
515,
8,
20,
12,
841,
12,
413,
12,
3144,
12,
8484,
14,
20695,
396,
63,
515,
8,
277,
14,
3825,
12,
17,
12,
713,
430,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
19,
395,
59,
16,
12,
413,
12,
499,
12,
650,
566,
267,
327,
3063,
543,
4931,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
19,
12,
3463,
534,
3463,
659,
59,
16,
12,
413,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
20,
12,
3463,
534,
3463,
659,
59,
16,
12,
1227,
12,
959,
12,
841,
566,
267,
4107,
63,
3825,
63,
515,
8,
20,
12,
841,
12,
413,
12,
3144,
12,
8484,
14,
20695,
396,
63,
515,
8,
277,
14,
3825,
12,
17,
12,
713,
12,
3463,
534,
3463,
1333,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
19,
12,
3463,
534,
3463,
659,
2151,
359,
16,
12,
413,
12,
499,
12,
650,
566,
339,
347,
511,
63,
20695,
396,
63,
515,
63,
1375,
8,
277,
304,
267,
2249,
275,
8484,
14,
20695,
396,
63,
515,
8,
7343,
14,
515,
63,
2180,
8,
19,
395,
1347,
29,
17,
9,
267,
702,
63,
1452,
8,
681,
12,
469,
16,
26,
359,
16,
12,
413,
467,
413,
26,
359,
17,
467,
499,
26,
359,
18,
12,
413,
13412,
339,
347,
511,
63,
20695,
396,
63,
515,
63,
1267,
8,
277,
304,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
7612,
12,
16,
12,
19,
395,
19,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
3825,
12,
17,
12,
713,
395,
21,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
20,
395,
20,
9,
267,
327,
3063,
543,
4931,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
7612,
12,
16,
12,
19,
12,
3463,
534,
3463,
659,
19,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
3825,
12,
17,
12,
713,
12,
3463,
534,
3463,
659,
21,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
20,
12,
3463,
534,
3463,
659,
20,
9,
339,
347,
511,
63,
20695,
396,
63,
515,
63,
1267,
63,
1375,
8,
277,
304,
267,
2249,
275,
1211,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
7343,
14,
515,
63,
2180,
8,
19,
395,
1347,
29,
17,
430,
267,
702,
63,
1452,
8,
681,
59,
16,
467,
413,
9,
267,
702,
63,
1452,
8,
681,
59,
17,
467,
378,
9,
267,
702,
63,
1452,
8,
681,
59,
18,
467,
413,
9,
339,
347,
511,
63,
4780,
63,
1365,
63,
20695,
396,
63,
515,
8,
277,
304,
267,
299,
29,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
9,
267,
702,
63,
1452,
8
] |
[
636,
2443,
363,
492,
4629,
199,
199,
504,
11354,
14,
2537,
492,
702,
63,
4398,
63,
1452,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
199,
504,
11354,
14,
2537,
492,
702,
63,
3910,
199,
504,
11354,
14,
2537,
492,
702,
63,
2052,
199,
504,
11354,
14,
2537,
492,
702,
63,
3536,
199,
504,
11354,
14,
2537,
492,
4112,
63,
199,
504,
11354,
14,
2537,
492,
6534,
199,
199,
646,
24313,
465,
8484,
421,
199,
318,
4107,
63,
3825,
63,
515,
8,
82,
12,
286,
12,
308,
12,
307,
12,
299,
304,
272,
4112,
2531,
6074,
8,
80,
12,
769,
430,
272,
702,
63,
1452,
8,
80,
59,
16,
467,
308,
9,
272,
702,
63,
1452,
8,
80,
1988,
17,
467,
307,
9,
272,
308,
275,
3666,
83,
446,
413,
9,
5001,
286,
12,
334,
83,
446,
413,
9,
450,
286,
9,
272,
307,
275,
3666,
84,
446,
413,
9,
5001,
286,
12,
334,
84,
446,
413,
9,
450,
286,
9,
272,
702,
63,
1452,
8,
552,
8,
80,
395,
2853,
8,
84,
59,
16,
61,
446,
308,
59,
16,
566,
435,
2853,
8,
84,
59,
17,
61,
446,
308,
59,
17,
566,
435,
413,
9,
272,
299,
275,
359,
1332,
85,
446,
413,
9,
5001,
286,
12,
334,
85,
446,
413,
9,
450,
286,
9,
367,
399,
315,
299,
61,
272,
367,
399,
315,
299,
26,
267,
4112,
2531,
16,
2695,
399,
59,
16,
61,
665,
519,
9,
267,
4112,
2531,
16,
2695,
399,
59,
17,
61,
665,
286,
9,
272,
367,
399,
12,
373,
315,
3482,
8,
80,
4439,
17,
467,
299,
59,
17,
28847,
267,
4112,
63,
1332,
2101,
8,
86,
59,
16,
61,
446,
399,
59,
16,
2522,
2853,
8,
86,
59,
17,
61,
446,
399,
59,
17,
2459,
315,
3842,
16,
12,
413,
395,
334,
17,
12,
378,
3948,
199,
199,
533,
1379,
9417,
2042,
26,
339,
347,
3613,
8,
277,
304,
267,
687,
24313,
492,
3957,
63,
932,
63,
3512,
63,
475,
63,
23931,
465,
286,
7530,
280,
267,
291,
14,
3825,
29,
6413,
21934,
8,
7343,
14,
3825,
63,
18,
68,
63,
2180,
8,
20,
12,
20,
395,
2246,
63,
1302,
29,
17,
12,
7128,
628,
5917,
531,
267,
291,
14,
7612,
29,
7343,
14,
7612,
63,
2180,
8,
23,
9,
267,
291,
14,
12080,
63,
7612,
29,
7343,
14,
7612,
63,
2180,
8,
23,
12,
981,
63,
4941,
29,
7343,
14,
23208,
1012,
2378,
347,
511,
63,
20695,
396,
63,
515,
8,
277,
304,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
19,
395,
59,
16,
12,
413,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
20,
395,
59,
16,
12,
1227,
12,
959,
12,
841,
566,
267,
4107,
63,
3825,
63,
515,
8,
20,
12,
841,
12,
413,
12,
3144,
12,
8484,
14,
20695,
396,
63,
515,
8,
277,
14,
3825,
12,
17,
12,
713,
430,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
19,
395,
59,
16,
12,
413,
12,
499,
12,
650,
566,
267,
327,
3063,
543,
4931,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
19,
12,
3463,
534,
3463,
659,
59,
16,
12,
413,
12,
499,
12,
650,
566,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
12,
20,
12,
3463,
534,
3463,
659,
59,
16,
12,
1227,
12,
959,
12,
841,
566,
267,
4107,
63,
3825,
63,
515,
8,
20,
12,
841,
12,
413,
12,
3144,
12,
8484,
14,
20695,
396,
63,
515,
8,
277,
14,
3825,
12,
17,
12,
713,
12,
3463,
534,
3463,
1333,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
19,
12,
3463,
534,
3463,
659,
2151,
359,
16,
12,
413,
12,
499,
12,
650,
566,
339,
347,
511,
63,
20695,
396,
63,
515,
63,
1375,
8,
277,
304,
267,
2249,
275,
8484,
14,
20695,
396,
63,
515,
8,
7343,
14,
515,
63,
2180,
8,
19,
395,
1347,
29,
17,
9,
267,
702,
63,
1452,
8,
681,
12,
469,
16,
26,
359,
16,
12,
413,
467,
413,
26,
359,
17,
467,
499,
26,
359,
18,
12,
413,
13412,
339,
347,
511,
63,
20695,
396,
63,
515,
63,
1267,
8,
277,
304,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
7612,
12,
16,
12,
19,
395,
19,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
3825,
12,
17,
12,
713,
395,
21,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
20,
395,
20,
9,
267,
327,
3063,
543,
4931,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
7612,
12,
16,
12,
19,
12,
3463,
534,
3463,
659,
19,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
3825,
12,
17,
12,
713,
12,
3463,
534,
3463,
659,
21,
9,
267,
702,
63,
1452,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
277,
14,
12080,
63,
7612,
12,
16,
12,
20,
12,
3463,
534,
3463,
659,
20,
9,
339,
347,
511,
63,
20695,
396,
63,
515,
63,
1267,
63,
1375,
8,
277,
304,
267,
2249,
275,
1211,
8,
7343,
14,
20695,
396,
63,
515,
63,
1267,
8,
7343,
14,
515,
63,
2180,
8,
19,
395,
1347,
29,
17,
430,
267,
702,
63,
1452,
8,
681,
59,
16,
467,
413,
9,
267,
702,
63,
1452,
8,
681,
59,
17,
467,
378,
9,
267,
702,
63,
1452,
8,
681,
59,
18,
467,
413,
9,
339,
347,
511,
63,
4780,
63,
1365,
63,
20695,
396,
63,
515,
8,
277,
304,
267,
299,
29,
7343,
14,
20695,
396,
63,
515,
8,
277,
14,
7612,
12,
16,
9,
267,
702,
63,
1452,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
blueboxgroup/neutron
|
neutron/db/migration/alembic_migrations/versions/1fcfc149aca4_agents_unique_by_type_and_host.py
|
17
|
1377
|
# Copyright 2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Add a unique constraint on (agent_type, host) columns to prevent a race
condition when an agent entry is 'upserted'.
Revision ID: 1fcfc149aca4
Revises: e197124d4b9
Create Date: 2013-11-27 18:35:28.148680
"""
revision = '1fcfc149aca4'
down_revision = 'e197124d4b9'
from alembic import op
from neutron.db import migration
TABLE_NAME = 'agents'
UC_NAME = 'uniq_agents0agent_type0host'
def upgrade():
if not migration.schema_has_table(TABLE_NAME):
# Assume that, in the database we are migrating from, the
# configured plugin did not create the agents table.
return
op.create_unique_constraint(
name=UC_NAME,
source=TABLE_NAME,
local_cols=['agent_type', 'host']
)
def downgrade():
pass
|
apache-2.0
|
[
3,
1898,
6171,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
1123,
282,
3747,
5828,
641,
334,
4054,
63,
466,
12,
1591,
9,
4362,
370,
7981,
282,
21209,
199,
5394,
1380,
376,
6631,
2397,
365,
283,
384,
9449,
1370,
199,
199,
12714,
2870,
26,
413,
70,
2177,
67,
10721,
30632,
20,
199,
497,
433,
874,
26,
325,
11165,
7214,
68,
20,
66,
25,
199,
2499,
6148,
26,
6171,
13,
845,
13,
1465,
6155,
26,
1276,
26,
1651,
14,
1079,
1184,
1257,
199,
199,
624,
199,
199,
5792,
275,
283,
17,
70,
2177,
67,
10721,
30632,
20,
7,
199,
2110,
63,
5792,
275,
283,
69,
11165,
7214,
68,
20,
66,
25,
7,
199,
199,
504,
30960,
20596,
492,
1687,
199,
199,
504,
8224,
14,
697,
492,
8367,
421,
199,
8723,
63,
2339,
275,
283,
14250,
7,
199,
13371,
63,
2339,
275,
283,
22484,
63,
14250,
16,
4054,
63,
466,
16,
1102,
7,
421,
199,
318,
10754,
837,
339,
340,
440,
8367,
14,
3629,
63,
1989,
63,
1224,
8,
8723,
63,
2339,
304,
267,
327,
16269,
626,
12,
315,
314,
3050,
781,
787,
3952,
10417,
687,
12,
314,
267,
327,
7526,
3589,
8103,
440,
1218,
314,
22867,
1817,
14,
267,
372,
339,
1687,
14,
981,
63,
3235,
63,
5631,
8,
267,
536,
29,
13371,
63,
2339,
12,
267,
1350,
29,
8723,
63,
2339,
12,
267,
2257,
63,
4574,
2968,
4054,
63,
466,
297,
283,
1102,
418,
272,
776,
421,
199,
318,
32498,
837,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
1123,
282,
3747,
5828,
641,
334,
4054,
63,
466,
12,
1591,
9,
4362,
370,
7981,
282,
21209,
199,
5394,
1380,
376,
6631,
2397,
365,
283,
384,
9449,
1370,
199,
199,
12714,
2870,
26,
413,
70,
2177,
67,
10721,
30632,
20,
199,
497,
433,
874,
26,
325,
11165,
7214,
68,
20,
66,
25,
199,
2499,
6148,
26,
6171,
13,
845,
13,
1465,
6155,
26,
1276,
26,
1651,
14,
1079,
1184,
1257,
199,
199,
624,
199,
199,
5792,
275,
283,
17,
70,
2177,
67,
10721,
30632,
20,
7,
199,
2110,
63,
5792,
275,
283,
69,
11165,
7214,
68,
20,
66,
25,
7,
199,
199,
504,
30960,
20596,
492,
1687,
199,
199,
504,
8224,
14,
697,
492,
8367,
421,
199,
8723,
63,
2339,
275,
283,
14250,
7,
199,
13371,
63,
2339,
275,
283,
22484,
63,
14250,
16,
4054,
63,
466,
16,
1102,
7,
421,
199,
318,
10754,
837,
339,
340,
440,
8367,
14,
3629,
63,
1989,
63,
1224,
8,
8723,
63,
2339,
304,
267,
327,
16269,
626,
12,
315,
314,
3050,
781,
787,
3952,
10417,
687,
12,
314,
267,
327,
7526,
3589,
8103,
440,
1218,
314,
22867,
1817,
14,
267,
372,
339,
1687,
14,
981,
63,
3235,
63,
5631,
8,
267,
536,
29,
13371,
63,
2339,
12,
267,
1350,
29,
8723,
63,
2339,
12,
267,
2257,
63,
4574,
2968,
4054,
63,
466,
297,
283,
1102,
418,
272,
776,
421,
199,
318,
32498,
837,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
18padx08/PPTex
|
PPTexEnv_x86_64/lib/python2.7/site-packages/numpy/distutils/__config__.py
|
2
|
1869
|
# This file is generated by /home/patrick/Documents/PPText/PPTexEnv_x86_64/build/numpy/-c
# It contains system_info results at the time of building this package.
__all__ = ["get_info","show"]
atlas_3_10_blas_info={}
atlas_3_10_blas_threads_info={}
atlas_threads_info={}
blas_opt_info={'libraries': ['f77blas', 'cblas', 'atlas'], 'library_dirs': ['/usr/lib/atlas-base'], 'language': 'c', 'define_macros': [('ATLAS_INFO', '"\\"3.10.2\\""')], 'include_dirs': ['/usr/include/atlas']}
atlas_blas_threads_info={}
openblas_info={}
lapack_opt_info={'libraries': ['lapack', 'f77blas', 'cblas', 'atlas'], 'library_dirs': ['/usr/lib/atlas-base/atlas', '/usr/lib/atlas-base'], 'language': 'f77', 'define_macros': [('ATLAS_INFO', '"\\"3.10.2\\""')], 'include_dirs': ['/usr/include/atlas']}
openblas_lapack_info={}
atlas_3_10_threads_info={}
atlas_info={'libraries': ['lapack', 'f77blas', 'cblas', 'atlas'], 'library_dirs': ['/usr/lib/atlas-base/atlas', '/usr/lib/atlas-base'], 'language': 'f77', 'define_macros': [('ATLAS_INFO', '"\\"3.10.2\\""')], 'include_dirs': ['/usr/include/atlas']}
atlas_3_10_info={}
lapack_mkl_info={}
blas_mkl_info={}
atlas_blas_info={'libraries': ['f77blas', 'cblas', 'atlas'], 'library_dirs': ['/usr/lib/atlas-base'], 'language': 'c', 'define_macros': [('ATLAS_INFO', '"\\"3.10.2\\""')], 'include_dirs': ['/usr/include/atlas']}
mkl_info={}
def get_info(name):
g = globals()
return g.get(name, g.get(name + "_info", {}))
def show():
for name,info_dict in globals().items():
if name[0] == "_" or type(info_dict) is not type({}): continue
print(name + ":")
if not info_dict:
print(" NOT AVAILABLE")
for k,v in info_dict.items():
v = str(v)
if k == "sources" and len(v) > 200:
v = v[:60] + " ...\n... " + v[-60:]
print(" %s = %s" % (k,v))
|
mit
|
[
3,
961,
570,
365,
4046,
701,
1182,
4219,
15,
10853,
27091,
15,
26872,
15,
7701,
1872,
15,
48,
4189,
476,
7744,
63,
88,
1184,
63,
772,
15,
1506,
15,
4714,
22551,
67,
199,
3,
2779,
3509,
2656,
63,
815,
2058,
737,
314,
900,
402,
10015,
642,
2559,
14,
199,
363,
452,
363,
275,
2097,
362,
63,
815,
2266,
2384,
937,
199,
199,
24935,
63,
19,
63,
709,
63,
21044,
63,
815,
7622,
199,
24935,
63,
19,
63,
709,
63,
21044,
63,
6962,
63,
815,
7622,
199,
24935,
63,
6962,
63,
815,
7622,
199,
21044,
63,
2992,
63,
815,
3713,
10159,
356,
788,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
67,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
24935,
63,
21044,
63,
6962,
63,
815,
7622,
199,
1490,
21044,
63,
815,
7622,
199,
26760,
63,
2992,
63,
815,
3713,
10159,
356,
788,
26760,
297,
283,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
15,
24935,
297,
1994,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
70,
1138,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
1490,
21044,
63,
26760,
63,
815,
7622,
199,
24935,
63,
19,
63,
709,
63,
6962,
63,
815,
7622,
199,
24935,
63,
815,
3713,
10159,
356,
788,
26760,
297,
283,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
15,
24935,
297,
1994,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
70,
1138,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
24935,
63,
19,
63,
709,
63,
815,
7622,
199,
26760,
63,
3880,
76,
63,
815,
7622,
199,
21044,
63,
3880,
76,
63,
815,
7622,
199,
24935,
63,
21044,
63,
815,
3713,
10159,
356,
788,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
67,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
3880,
76,
63,
815,
7622,
199,
199,
318,
664,
63,
815,
8,
354,
304,
272,
486,
275,
7992,
342,
272,
372,
486,
14,
362,
8,
354,
12,
486,
14,
362,
8,
354,
435,
2668,
815,
401,
17003,
199,
199,
318,
2498,
837,
272,
367,
536,
12,
815,
63,
807,
315,
7992,
1252,
1744,
837,
267,
340,
536,
59,
16,
61,
508,
14220,
503,
730,
8,
815,
63,
807,
9,
365,
440,
730,
24692,
304,
1980,
267,
870,
8,
354,
435,
7244,
531,
267,
340,
440,
2256,
63,
807,
26,
288,
870,
480,
221,
2845,
437,
54,
6593,
2617,
531,
267,
367,
1022,
12,
86,
315,
2256,
63,
807,
14,
1744,
837,
288,
373,
275,
620,
8,
86,
9,
288,
340,
1022,
508,
298,
4553,
2,
436,
822,
8,
86,
9,
690,
1926,
26,
355,
373,
275,
373,
1491,
2259,
61,
435,
298,
2263,
60,
78,
1396,
298,
435,
373,
1988,
2259,
2938,
288,
870,
480,
259,
450,
83,
275,
450,
83,
2,
450,
334,
75,
12,
86,
430,
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
] |
[
961,
570,
365,
4046,
701,
1182,
4219,
15,
10853,
27091,
15,
26872,
15,
7701,
1872,
15,
48,
4189,
476,
7744,
63,
88,
1184,
63,
772,
15,
1506,
15,
4714,
22551,
67,
199,
3,
2779,
3509,
2656,
63,
815,
2058,
737,
314,
900,
402,
10015,
642,
2559,
14,
199,
363,
452,
363,
275,
2097,
362,
63,
815,
2266,
2384,
937,
199,
199,
24935,
63,
19,
63,
709,
63,
21044,
63,
815,
7622,
199,
24935,
63,
19,
63,
709,
63,
21044,
63,
6962,
63,
815,
7622,
199,
24935,
63,
6962,
63,
815,
7622,
199,
21044,
63,
2992,
63,
815,
3713,
10159,
356,
788,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
67,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
24935,
63,
21044,
63,
6962,
63,
815,
7622,
199,
1490,
21044,
63,
815,
7622,
199,
26760,
63,
2992,
63,
815,
3713,
10159,
356,
788,
26760,
297,
283,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
15,
24935,
297,
1994,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
70,
1138,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
1490,
21044,
63,
26760,
63,
815,
7622,
199,
24935,
63,
19,
63,
709,
63,
6962,
63,
815,
7622,
199,
24935,
63,
815,
3713,
10159,
356,
788,
26760,
297,
283,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
15,
24935,
297,
1994,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
70,
1138,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
24935,
63,
19,
63,
709,
63,
815,
7622,
199,
26760,
63,
3880,
76,
63,
815,
7622,
199,
21044,
63,
3880,
76,
63,
815,
7622,
199,
24935,
63,
21044,
63,
815,
3713,
10159,
356,
788,
70,
1138,
21044,
297,
283,
2894,
12536,
297,
283,
24935,
995,
283,
4342,
63,
3220,
356,
18744,
2647,
15,
773,
15,
24935,
13,
1095,
995,
283,
3671,
356,
283,
67,
297,
283,
4640,
63,
16358,
356,
4274,
619,
44,
1179,
63,
4531,
297,
5522,
15022,
19,
14,
709,
14,
18,
1103,
341,
2665,
283,
2613,
63,
3220,
356,
18744,
2647,
15,
2613,
15,
24935,
12074,
199,
3880,
76,
63,
815,
7622,
199,
199,
318,
664,
63,
815,
8,
354,
304,
272,
486,
275,
7992,
342,
272,
372,
486,
14,
362,
8,
354,
12,
486,
14,
362,
8,
354,
435,
2668,
815,
401,
17003,
199,
199,
318,
2498,
837,
272,
367,
536,
12,
815,
63,
807,
315,
7992,
1252,
1744,
837,
267,
340,
536,
59,
16,
61,
508,
14220,
503,
730,
8,
815,
63,
807,
9,
365,
440,
730,
24692,
304,
1980,
267,
870,
8,
354,
435,
7244,
531,
267,
340,
440,
2256,
63,
807,
26,
288,
870,
480,
221,
2845,
437,
54,
6593,
2617,
531,
267,
367,
1022,
12,
86,
315,
2256,
63,
807,
14,
1744,
837,
288,
373,
275,
620,
8,
86,
9,
288,
340,
1022,
508,
298,
4553,
2,
436,
822,
8,
86,
9,
690,
1926,
26,
355,
373,
275,
373,
1491,
2259,
61,
435,
298,
2263,
60,
78,
1396,
298,
435,
373,
1988,
2259,
2938,
288,
870,
480,
259,
450,
83,
275,
450,
83,
2,
450,
334,
75,
12,
86,
430,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
0x90sled/catapult
|
third_party/gsutil/third_party/boto/tests/integration/gs/test_generation_conditionals.py
|
135
|
14307
|
# -*- coding: utf-8 -*-
# Copyright (c) 2013, Google, Inc.
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""Integration tests for GS versioning support."""
import StringIO
import os
import tempfile
from xml import sax
from boto import handler
from boto.exception import GSResponseError
from boto.gs.acl import ACL
from tests.integration.gs.testcase import GSTestCase
# HTTP Error returned when a generation precondition fails.
VERSION_MISMATCH = "412"
class GSGenerationConditionalsTest(GSTestCase):
def testConditionalSetContentsFromFile(self):
b = self._MakeBucket()
k = b.new_key("foo")
s1 = "test1"
fp = StringIO.StringIO(s1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_file(fp, if_generation=999)
fp = StringIO.StringIO(s1)
k.set_contents_from_file(fp, if_generation=0)
g1 = k.generation
s2 = "test2"
fp = StringIO.StringIO(s2)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_file(fp, if_generation=int(g1)+1)
fp = StringIO.StringIO(s2)
k.set_contents_from_file(fp, if_generation=g1)
self.assertEqual(k.get_contents_as_string(), s2)
def testConditionalSetContentsFromString(self):
b = self._MakeBucket()
k = b.new_key("foo")
s1 = "test1"
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_string(s1, if_generation=999)
k.set_contents_from_string(s1, if_generation=0)
g1 = k.generation
s2 = "test2"
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_string(s2, if_generation=int(g1)+1)
k.set_contents_from_string(s2, if_generation=g1)
self.assertEqual(k.get_contents_as_string(), s2)
def testConditionalSetContentsFromFilename(self):
s1 = "test1"
s2 = "test2"
f1 = tempfile.NamedTemporaryFile(prefix="boto-gs-test", delete=False)
f2 = tempfile.NamedTemporaryFile(prefix="boto-gs-test", delete=False)
fname1 = f1.name
fname2 = f2.name
f1.write(s1)
f1.close()
f2.write(s2)
f2.close()
try:
b = self._MakeBucket()
k = b.new_key("foo")
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_filename(fname1, if_generation=999)
k.set_contents_from_filename(fname1, if_generation=0)
g1 = k.generation
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_filename(fname2, if_generation=int(g1)+1)
k.set_contents_from_filename(fname2, if_generation=g1)
self.assertEqual(k.get_contents_as_string(), s2)
finally:
os.remove(fname1)
os.remove(fname2)
def testBucketConditionalSetAcl(self):
b = self._MakeVersionedBucket()
k = b.new_key("foo")
s1 = "test1"
k.set_contents_from_string(s1)
g1 = k.generation
mg1 = k.metageneration
self.assertEqual(str(mg1), "1")
b.set_acl("public-read", key_name="foo")
k = b.get_key("foo")
g2 = k.generation
mg2 = k.metageneration
self.assertEqual(g2, g1)
self.assertGreater(mg2, mg1)
with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
"argument with no "
"if_generation argument")):
b.set_acl("bucket-owner-full-control", key_name="foo",
if_metageneration=123)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
b.set_acl("bucket-owner-full-control", key_name="foo",
if_generation=int(g2) + 1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
b.set_acl("bucket-owner-full-control", key_name="foo",
if_generation=g2, if_metageneration=int(mg2) + 1)
b.set_acl("bucket-owner-full-control", key_name="foo", if_generation=g2)
k = b.get_key("foo")
g3 = k.generation
mg3 = k.metageneration
self.assertEqual(g3, g2)
self.assertGreater(mg3, mg2)
b.set_acl("public-read", key_name="foo", if_generation=g3,
if_metageneration=mg3)
def testConditionalSetContentsFromStream(self):
b = self._MakeBucket()
k = b.new_key("foo")
s1 = "test1"
fp = StringIO.StringIO(s1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_stream(fp, if_generation=999)
fp = StringIO.StringIO(s1)
k.set_contents_from_stream(fp, if_generation=0)
g1 = k.generation
k = b.get_key("foo")
s2 = "test2"
fp = StringIO.StringIO(s2)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_contents_from_stream(fp, if_generation=int(g1)+1)
fp = StringIO.StringIO(s2)
k.set_contents_from_stream(fp, if_generation=g1)
self.assertEqual(k.get_contents_as_string(), s2)
def testBucketConditionalSetCannedAcl(self):
b = self._MakeVersionedBucket()
k = b.new_key("foo")
s1 = "test1"
k.set_contents_from_string(s1)
g1 = k.generation
mg1 = k.metageneration
self.assertEqual(str(mg1), "1")
b.set_canned_acl("public-read", key_name="foo")
k = b.get_key("foo")
g2 = k.generation
mg2 = k.metageneration
self.assertEqual(g2, g1)
self.assertGreater(mg2, mg1)
with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
"argument with no "
"if_generation argument")):
b.set_canned_acl("bucket-owner-full-control", key_name="foo",
if_metageneration=123)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
b.set_canned_acl("bucket-owner-full-control", key_name="foo",
if_generation=int(g2) + 1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
b.set_canned_acl("bucket-owner-full-control", key_name="foo",
if_generation=g2, if_metageneration=int(mg2) + 1)
b.set_canned_acl("bucket-owner-full-control", key_name="foo",
if_generation=g2)
k = b.get_key("foo")
g3 = k.generation
mg3 = k.metageneration
self.assertEqual(g3, g2)
self.assertGreater(mg3, mg2)
b.set_canned_acl("public-read", key_name="foo", if_generation=g3,
if_metageneration=mg3)
def testBucketConditionalSetXmlAcl(self):
b = self._MakeVersionedBucket()
k = b.new_key("foo")
s1 = "test1"
k.set_contents_from_string(s1)
g1 = k.generation
mg1 = k.metageneration
self.assertEqual(str(mg1), "1")
acl_xml = (
'<ACCESSControlList><EntrIes><Entry>' +
'<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
'</Entry></EntrIes></ACCESSControlList>')
acl = ACL()
h = handler.XmlHandler(acl, b)
sax.parseString(acl_xml, h)
acl = acl.to_xml()
b.set_xml_acl(acl, key_name="foo")
k = b.get_key("foo")
g2 = k.generation
mg2 = k.metageneration
self.assertEqual(g2, g1)
self.assertGreater(mg2, mg1)
with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
"argument with no "
"if_generation argument")):
b.set_xml_acl(acl, key_name="foo", if_metageneration=123)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
b.set_xml_acl(acl, key_name="foo", if_generation=int(g2) + 1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
b.set_xml_acl(acl, key_name="foo", if_generation=g2,
if_metageneration=int(mg2) + 1)
b.set_xml_acl(acl, key_name="foo", if_generation=g2)
k = b.get_key("foo")
g3 = k.generation
mg3 = k.metageneration
self.assertEqual(g3, g2)
self.assertGreater(mg3, mg2)
b.set_xml_acl(acl, key_name="foo", if_generation=g3,
if_metageneration=mg3)
def testObjectConditionalSetAcl(self):
b = self._MakeVersionedBucket()
k = b.new_key("foo")
k.set_contents_from_string("test1")
g1 = k.generation
mg1 = k.metageneration
self.assertEqual(str(mg1), "1")
k.set_acl("public-read")
k = b.get_key("foo")
g2 = k.generation
mg2 = k.metageneration
self.assertEqual(g2, g1)
self.assertGreater(mg2, mg1)
with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
"argument with no "
"if_generation argument")):
k.set_acl("bucket-owner-full-control", if_metageneration=123)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_acl("bucket-owner-full-control", if_generation=int(g2) + 1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_acl("bucket-owner-full-control", if_generation=g2,
if_metageneration=int(mg2) + 1)
k.set_acl("bucket-owner-full-control", if_generation=g2)
k = b.get_key("foo")
g3 = k.generation
mg3 = k.metageneration
self.assertEqual(g3, g2)
self.assertGreater(mg3, mg2)
k.set_acl("public-read", if_generation=g3, if_metageneration=mg3)
def testObjectConditionalSetCannedAcl(self):
b = self._MakeVersionedBucket()
k = b.new_key("foo")
k.set_contents_from_string("test1")
g1 = k.generation
mg1 = k.metageneration
self.assertEqual(str(mg1), "1")
k.set_canned_acl("public-read")
k = b.get_key("foo")
g2 = k.generation
mg2 = k.metageneration
self.assertEqual(g2, g1)
self.assertGreater(mg2, mg1)
with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
"argument with no "
"if_generation argument")):
k.set_canned_acl("bucket-owner-full-control",
if_metageneration=123)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_canned_acl("bucket-owner-full-control",
if_generation=int(g2) + 1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_canned_acl("bucket-owner-full-control", if_generation=g2,
if_metageneration=int(mg2) + 1)
k.set_canned_acl("bucket-owner-full-control", if_generation=g2)
k = b.get_key("foo")
g3 = k.generation
mg3 = k.metageneration
self.assertEqual(g3, g2)
self.assertGreater(mg3, mg2)
k.set_canned_acl("public-read", if_generation=g3, if_metageneration=mg3)
def testObjectConditionalSetXmlAcl(self):
b = self._MakeVersionedBucket()
k = b.new_key("foo")
s1 = "test1"
k.set_contents_from_string(s1)
g1 = k.generation
mg1 = k.metageneration
self.assertEqual(str(mg1), "1")
acl_xml = (
'<ACCESSControlList><EntrIes><Entry>' +
'<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
'</Entry></EntrIes></ACCESSControlList>')
acl = ACL()
h = handler.XmlHandler(acl, b)
sax.parseString(acl_xml, h)
acl = acl.to_xml()
k.set_xml_acl(acl)
k = b.get_key("foo")
g2 = k.generation
mg2 = k.metageneration
self.assertEqual(g2, g1)
self.assertGreater(mg2, mg1)
with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
"argument with no "
"if_generation argument")):
k.set_xml_acl(acl, if_metageneration=123)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_xml_acl(acl, if_generation=int(g2) + 1)
with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
k.set_xml_acl(acl, if_generation=g2, if_metageneration=int(mg2) + 1)
k.set_xml_acl(acl, if_generation=g2)
k = b.get_key("foo")
g3 = k.generation
mg3 = k.metageneration
self.assertEqual(g3, g2)
self.assertGreater(mg3, mg2)
k.set_xml_acl(acl, if_generation=g3, if_metageneration=mg3)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
6171,
12,
4475,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
20405,
2295,
367,
598,
51,
1015,
316,
2291,
1041,
199,
199,
646,
5228,
199,
646,
747,
199,
646,
5549,
199,
504,
2748,
492,
308,
1219,
199,
199,
504,
6055,
492,
3016,
199,
504,
6055,
14,
1971,
492,
598,
51,
19712,
199,
504,
6055,
14,
458,
14,
5853,
492,
16543,
199,
504,
2295,
14,
15092,
14,
458,
14,
10847,
492,
598,
51,
1746,
421,
199,
3,
3101,
4520,
2138,
1380,
282,
10152,
876,
5394,
6918,
14,
199,
4612,
63,
9674,
14747,
275,
298,
25746,
2,
421,
199,
533,
598,
51,
18514,
9558,
2551,
774,
8,
8021,
1746,
304,
339,
347,
511,
21321,
1084,
11383,
26637,
8,
277,
304,
267,
330,
275,
291,
423,
5483,
12311,
342,
267,
1022,
275,
330,
14,
1222,
63,
498,
480,
1421,
531,
267,
308,
17,
275,
298,
396,
17,
2,
267,
4090,
275,
5228,
14,
6424,
8,
83,
17,
9,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
5637,
9,
398,
4090,
275,
5228,
14,
6424,
8,
83,
17,
9,
267,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
16,
9,
267,
486,
17,
275,
1022,
14,
15043,
398,
308,
18,
275,
298,
396,
18,
2,
267,
4090,
275,
5228,
14,
6424,
8,
83,
18,
9,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
442,
8,
71,
17,
6393,
17,
9,
398,
4090,
275,
5228,
14,
6424,
8,
83,
18,
9,
267,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
71,
17,
9,
267,
291,
14,
629,
8,
75,
14,
362,
63,
4407,
63,
305,
63,
875,
1062,
308,
18,
9,
339,
347,
511,
21321,
1084,
11383,
7671,
8,
277,
304,
267,
330,
275,
291,
423,
5483,
12311,
342,
267,
1022,
275,
330,
14,
1222,
63,
498,
480,
1421,
531,
267,
308,
17,
275,
298,
396,
17,
2,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
17,
12,
340,
63,
15043,
29,
5637,
9,
398,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
17,
12,
340,
63,
15043,
29,
16,
9,
267,
486,
17,
275,
1022,
14,
15043,
398,
308,
18,
275,
298,
396,
18,
2,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
18,
12,
340,
63,
15043,
29,
442,
8,
71,
17,
6393,
17,
9,
398,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
18,
12,
340,
63,
15043,
29,
71,
17,
9,
267,
291,
14,
629,
8,
75,
14,
362,
63,
4407,
63,
305,
63,
875,
1062,
308,
18,
9,
339,
347,
511,
21321,
1084,
11383,
2532,
8117,
8,
277,
304,
267,
308,
17,
275,
298,
396,
17,
2,
267,
308,
18,
275,
298,
396,
18,
2,
267,
289,
17,
275,
5549,
14,
19320,
8,
1861,
628,
10914,
13,
458,
13,
396,
401,
3145,
29,
797,
9,
267,
289,
18,
275,
5549,
14,
19320,
8,
1861,
628,
10914,
13,
458,
13,
396,
401,
3145,
29,
797,
9,
267,
6748,
17,
275,
289,
17,
14,
354,
267,
6748,
18,
275,
289,
18,
14,
354,
267,
289,
17,
14,
952,
8,
83,
17,
9,
267,
289,
17,
14,
1600,
342,
267,
289,
18,
14,
952,
8,
83,
18,
9,
267,
289,
18,
14,
1600,
342,
398,
862,
26,
288,
330,
275,
291,
423,
5483,
12311,
342,
288,
1022,
275,
330,
14,
1222,
63,
498,
480,
1421,
531,
953,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
355,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
17,
12,
340,
63,
15043,
29,
5637,
9,
953,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
17,
12,
340,
63,
15043,
29,
16,
9,
288,
486,
17,
275,
1022,
14,
15043,
953,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
355,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
18,
12,
340,
63,
15043,
29,
442,
8,
71,
17,
6393,
17,
9,
953,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
18,
12,
340,
63,
15043,
29,
71,
17,
9,
288,
291,
14,
629
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
6171,
12,
4475,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
20405,
2295,
367,
598,
51,
1015,
316,
2291,
1041,
199,
199,
646,
5228,
199,
646,
747,
199,
646,
5549,
199,
504,
2748,
492,
308,
1219,
199,
199,
504,
6055,
492,
3016,
199,
504,
6055,
14,
1971,
492,
598,
51,
19712,
199,
504,
6055,
14,
458,
14,
5853,
492,
16543,
199,
504,
2295,
14,
15092,
14,
458,
14,
10847,
492,
598,
51,
1746,
421,
199,
3,
3101,
4520,
2138,
1380,
282,
10152,
876,
5394,
6918,
14,
199,
4612,
63,
9674,
14747,
275,
298,
25746,
2,
421,
199,
533,
598,
51,
18514,
9558,
2551,
774,
8,
8021,
1746,
304,
339,
347,
511,
21321,
1084,
11383,
26637,
8,
277,
304,
267,
330,
275,
291,
423,
5483,
12311,
342,
267,
1022,
275,
330,
14,
1222,
63,
498,
480,
1421,
531,
267,
308,
17,
275,
298,
396,
17,
2,
267,
4090,
275,
5228,
14,
6424,
8,
83,
17,
9,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
5637,
9,
398,
4090,
275,
5228,
14,
6424,
8,
83,
17,
9,
267,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
16,
9,
267,
486,
17,
275,
1022,
14,
15043,
398,
308,
18,
275,
298,
396,
18,
2,
267,
4090,
275,
5228,
14,
6424,
8,
83,
18,
9,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
442,
8,
71,
17,
6393,
17,
9,
398,
4090,
275,
5228,
14,
6424,
8,
83,
18,
9,
267,
1022,
14,
409,
63,
4407,
63,
504,
63,
493,
8,
3997,
12,
340,
63,
15043,
29,
71,
17,
9,
267,
291,
14,
629,
8,
75,
14,
362,
63,
4407,
63,
305,
63,
875,
1062,
308,
18,
9,
339,
347,
511,
21321,
1084,
11383,
7671,
8,
277,
304,
267,
330,
275,
291,
423,
5483,
12311,
342,
267,
1022,
275,
330,
14,
1222,
63,
498,
480,
1421,
531,
267,
308,
17,
275,
298,
396,
17,
2,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
17,
12,
340,
63,
15043,
29,
5637,
9,
398,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
17,
12,
340,
63,
15043,
29,
16,
9,
267,
486,
17,
275,
1022,
14,
15043,
398,
308,
18,
275,
298,
396,
18,
2,
267,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
288,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
18,
12,
340,
63,
15043,
29,
442,
8,
71,
17,
6393,
17,
9,
398,
1022,
14,
409,
63,
4407,
63,
504,
63,
875,
8,
83,
18,
12,
340,
63,
15043,
29,
71,
17,
9,
267,
291,
14,
629,
8,
75,
14,
362,
63,
4407,
63,
305,
63,
875,
1062,
308,
18,
9,
339,
347,
511,
21321,
1084,
11383,
2532,
8117,
8,
277,
304,
267,
308,
17,
275,
298,
396,
17,
2,
267,
308,
18,
275,
298,
396,
18,
2,
267,
289,
17,
275,
5549,
14,
19320,
8,
1861,
628,
10914,
13,
458,
13,
396,
401,
3145,
29,
797,
9,
267,
289,
18,
275,
5549,
14,
19320,
8,
1861,
628,
10914,
13,
458,
13,
396,
401,
3145,
29,
797,
9,
267,
6748,
17,
275,
289,
17,
14,
354,
267,
6748,
18,
275,
289,
18,
14,
354,
267,
289,
17,
14,
952,
8,
83,
17,
9,
267,
289,
17,
14,
1600,
342,
267,
289,
18,
14,
952,
8,
83,
18,
9,
267,
289,
18,
14,
1600,
342,
398,
862,
26,
288,
330,
275,
291,
423,
5483,
12311,
342,
288,
1022,
275,
330,
14,
1222,
63,
498,
480,
1421,
531,
953,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
355,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
17,
12,
340,
63,
15043,
29,
5637,
9,
953,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
17,
12,
340,
63,
15043,
29,
16,
9,
288,
486,
17,
275,
1022,
14,
15043,
953,
543,
291,
14,
10835,
8,
8021,
19712,
12,
15945,
63,
9674,
14747,
304,
355,
1022,
14,
409,
63,
4407,
63,
504,
63,
1501,
8,
5252,
18,
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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
] |
ronkitay/Rons-Tutorials
|
Python/APIs/tor_json_processing.py
|
1
|
3684
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Python considers any map or collection as JSON elements. 'Serializing/DeSerializing' them is VERY easy
Read:
- json.load(data_file) --> Loads an object from a File
- json.loads(json_as_string) --> Loads an object from a string representing a JSON object
Write:
- json.dump(json_object, target_file) --> Saved te object into the file
- json.dumps(json_object) --> Returns the JSON Object in its String representation
"""
import json
from sets import Set
phase = 0
def load_json_from_file(input_file_name):
with open(input_file_name) as data_file:
return json.load(data_file)
def save_json_to_file(output_file, json_object):
with open(output_file, 'w') as outfile:
json.dump(json_object, outfile)
def print_json_object(json_object):
print json.dumps(json_object, indent=True, sort_keys=True)
def print_phase():
global phase
print '==== Step %d ====' % phase
phase += 1
tor_details_full_list = load_json_from_file('/Users/rkitay/tmp/tor2/tor_details_full.json')
relays = tor_details_full_list["relays"]
output = Set()
for relay in relays:
exit_policy = relay["exit_policy"]
if exit_policy[0] == "reject *:*":
continue
# print relay["nickname"]
if "or_addresses" in relay:
or_addresses = relay["or_addresses"]
# print or_addresses
for ip in or_addresses:
if '.' in ip:
ip = ip[0:ip.index(':')]
output.add(ip)
if "exit_addresses" in relay:
exit_addresses = relay["exit_addresses"]
# print exit_addresses
for ip in exit_addresses:
if '.' in ip:
output.add(ip)
print "all tor addresses size is: " + str (output.__len__())
print output
check_tor_file = open("/Users/rkitay/tmp/tor2/check-tor.ips", "r")
check_tor_lines = check_tor_file.readlines()
for check_tor_ip in check_tor_lines:
if check_tor_ip in output:
continue
# print check_tor_ip + " was found in the onionoo list"
else:
print check_tor_ip + " was NOT found in the onionoo list"
# print_phase()
# print type(data) # Data is a dictionary
# print data
#
# print_phase()
# data['object1']['field2'] = 'new value'
# print data
#
# print_phase()
# data['object2'] = {'fieldX': 'valueY', 'fieldZ': 12940.43}
# print_json_object(data)
#
# print_phase()
# if 'object3' not in data:
# data['object3'] = {}
# print_json_object(data)
#
# print_phase()
# if 'object2' not in data:
# data['object2'] = {}
# else:
# data['object2']['fieldZ'] = 96943.34
# print_json_object(data)
#
# print_phase()
# dummy_json_output_file = '/tmp/dummy_output.json'
# save_json_to_file(dummy_json_output_file, data)
# contents_of_file_i_just_saved = load_json_from_file(dummy_json_output_file)
# print_json_object(contents_of_file_i_just_saved)
#
# print_phase()
# sample_data = [
# {"action": "Allow", "key": "ALLOW", "rules": 20},
# {"action": "Alternate Content", "key": "ALT_CONT", "rules": 20},
# {"action": "Alternate Origin", "key": "ALT_ORG", "rules": 20},
# {"action": "Get from Cache", "key": "CACHE", "rules": 20},
# {"action": "Annoy user", "key": "CUSTOM_1234", "rules": 20},
# {"action": "Distract user", "key": "CUSTOM_5678", "rules": 20},
# {"action": "Delay the user", "key": "DELAY", "rules": 20},
# {"action": "DROP", "key": "DROP", "rules": 20},
# {"action": "Do nothing", "key": "NONE", "rules": 20},
# {"action": "Slow the user", "key": "SLOW", "rules": 20}
# ]
# print type(sample_data)
# print_json_object(sample_data)
#
# print_phase()
# sample_data[1:3] = []
# print_json_object(sample_data)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
421,
199,
624,
199,
4718,
7399,
7735,
1263,
2341,
503,
3245,
465,
4840,
4008,
14,
283,
3571,
9147,
15,
872,
3571,
9147,
7,
3062,
365,
812,
9418,
8837,
199,
3284,
26,
199,
446,
2022,
14,
912,
8,
576,
63,
493,
9,
10541,
30367,
376,
909,
687,
282,
3814,
199,
446,
2022,
14,
3640,
8,
1001,
63,
305,
63,
875,
9,
10541,
30367,
376,
909,
687,
282,
1059,
6144,
282,
4840,
909,
199,
3534,
26,
199,
446,
2022,
14,
2724,
8,
1001,
63,
785,
12,
1347,
63,
493,
9,
10541,
29026,
1565,
909,
1901,
314,
570,
199,
446,
2022,
14,
4180,
8,
1001,
63,
785,
9,
10541,
1803,
314,
4840,
6935,
315,
2399,
2624,
6025,
199,
624,
199,
646,
2022,
199,
199,
504,
5951,
492,
2494,
199,
199,
6971,
275,
378,
421,
199,
318,
2248,
63,
1001,
63,
504,
63,
493,
8,
1210,
63,
493,
63,
354,
304,
272,
543,
1551,
8,
1210,
63,
493,
63,
354,
9,
465,
666,
63,
493,
26,
267,
372,
2022,
14,
912,
8,
576,
63,
493,
9,
421,
199,
318,
3354,
63,
1001,
63,
475,
63,
493,
8,
1199,
63,
493,
12,
2022,
63,
785,
304,
272,
543,
1551,
8,
1199,
63,
493,
12,
283,
87,
358,
465,
4386,
26,
267,
2022,
14,
2724,
8,
1001,
63,
785,
12,
4386,
9,
421,
199,
318,
870,
63,
1001,
63,
785,
8,
1001,
63,
785,
304,
272,
870,
2022,
14,
4180,
8,
1001,
63,
785,
12,
4363,
29,
549,
12,
4069,
63,
1612,
29,
549,
9,
421,
199,
318,
870,
63,
6971,
837,
272,
2288,
7669,
272,
870,
283,
532,
13382,
450,
68,
24768,
534,
450,
7669,
272,
7669,
847,
413,
421,
199,
8270,
63,
5087,
63,
2861,
63,
513,
275,
2248,
63,
1001,
63,
504,
63,
493,
2336,
12117,
15,
82,
6065,
1187,
15,
2791,
15,
8270,
18,
15,
8270,
63,
5087,
63,
2861,
14,
1001,
358,
199,
199,
264,
9316,
275,
11095,
63,
5087,
63,
2861,
63,
513,
905,
264,
9316,
937,
199,
1199,
275,
2494,
342,
199,
199,
509,
25931,
315,
295,
9316,
26,
272,
4458,
63,
3185,
275,
25931,
905,
2224,
63,
3185,
937,
272,
340,
4458,
63,
3185,
59,
16,
61,
508,
298,
16857,
627,
27344,
582,
267,
1980,
272,
327,
870,
25931,
905,
18544,
937,
272,
340,
298,
269,
63,
7423,
2,
315,
25931,
26,
267,
503,
63,
7423,
275,
25931,
905,
269,
63,
7423,
937,
267,
327,
870,
503,
63,
7423,
267,
367,
3384,
315,
503,
63,
7423,
26,
288,
340,
7815,
315,
3384,
26,
355,
3384,
275,
3384,
59,
16,
26,
711,
14,
1080,
6176,
5440,
355,
1072,
14,
525,
8,
711,
9,
272,
340,
298,
2224,
63,
7423,
2,
315,
25931,
26,
267,
4458,
63,
7423,
275,
25931,
905,
2224,
63,
7423,
937,
267,
327,
870,
4458,
63,
7423,
267,
367,
3384,
315,
4458,
63,
7423,
26,
288,
340,
7815,
315,
3384,
26,
355,
1072,
14,
525,
8,
711,
9,
199,
199,
1361,
298,
452,
11095,
7149,
1568,
365,
26,
298,
435,
620,
334,
1199,
855,
552,
29133,
199,
1361,
1072,
199,
199,
1074,
63,
8270,
63,
493,
275,
1551,
4769,
12117,
15,
82,
6065,
1187,
15,
2791,
15,
8270,
18,
15,
1074,
13,
8270,
14,
6142,
401,
298,
82,
531,
199,
1074,
63,
8270,
63,
1278,
275,
1104,
63,
8270,
63,
493,
14,
9684,
342,
199,
199,
509,
1104,
63,
8270,
63,
711,
315,
1104,
63,
8270,
63,
1278,
26,
272,
340,
1104,
63,
8270,
63,
711,
315,
1072,
26,
267,
1980,
267,
327,
870,
1104,
63,
8270,
63,
711,
435,
298,
1990,
1911,
315,
314,
641,
1636,
1534,
769,
2,
272,
587,
26,
267,
870,
1104,
63,
8270,
63,
711,
435,
298,
1990,
2845,
1911,
315,
314,
641,
1636,
1534,
769,
2,
199,
199,
3,
870,
63,
6971,
342,
199,
3,
870,
730,
8,
576,
9,
221,
327,
3918,
365,
282,
2600,
199,
3,
870,
666,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
666,
459,
785,
17,
2545,
698,
18,
418,
275,
283,
1222,
574,
7,
199,
3,
870,
666,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
666,
459,
785,
18,
418,
275,
791,
698,
56,
356,
283,
585,
57,
297,
283,
698,
58,
356,
25454,
2167,
14,
2824,
93,
199,
3,
870,
63,
1001,
63,
785,
8,
576,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
340,
283,
785,
19,
7,
440,
315,
666,
26,
199,
3,
258,
666,
459,
785,
19,
418,
275,
1052,
199,
3,
870,
63,
1001,
63,
785,
8,
576,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
340,
283,
785,
18,
7,
440,
315,
666,
26,
199,
3,
258,
666,
459,
785,
18,
418,
275,
1052,
199,
3,
587,
26,
199,
3,
258,
666,
459,
785,
18,
2545,
698,
58,
418,
275,
1749,
1876,
2824,
14,
1082,
199,
3,
870,
63,
1001,
63,
785,
8,
576,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
7283,
63,
1001,
63,
1199,
63,
493,
275,
1994,
2791,
15,
5869,
63,
1199,
14,
1001,
7,
199,
3,
3354,
63,
1001,
63,
475,
63,
493,
8,
5869,
63,
1001,
63,
1199,
63,
493,
12,
666,
9,
199,
3,
4072,
63,
1618,
63,
493,
63,
73,
63,
4764,
63,
8420,
275,
2248,
63,
1001,
63,
504,
63,
493,
8,
5869,
63,
1001,
63,
1199,
63,
493,
9,
199,
3,
870,
63,
1001,
63,
785,
8,
4407,
63,
1618,
63,
493,
63,
73,
63,
4764,
63,
8420,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
2690,
63,
576,
275,
359,
199,
3,
258,
2420,
1287,
582,
298,
7852,
401,
298,
498,
582,
298,
12231,
401,
298,
4423,
582,
3388,
1386,
199,
3,
258,
2420,
1287,
582,
298,
19978,
323,
6646,
401,
298,
498,
582,
298,
19600,
63,
5801,
401,
298,
4423,
582,
3388,
1386,
199,
3,
258,
2420,
1287,
582,
298,
19978,
323,
31534,
401,
298,
498,
582,
298,
19600,
63,
25797,
401,
298,
4423,
582,
3388,
1386,
199,
3,
258,
2420,
1287,
582,
298,
1002,
687,
11977,
401,
298,
498,
582,
298,
8677,
401,
298,
4423,
582
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
421,
199,
624,
199,
4718,
7399,
7735,
1263,
2341,
503,
3245,
465,
4840,
4008,
14,
283,
3571,
9147,
15,
872,
3571,
9147,
7,
3062,
365,
812,
9418,
8837,
199,
3284,
26,
199,
446,
2022,
14,
912,
8,
576,
63,
493,
9,
10541,
30367,
376,
909,
687,
282,
3814,
199,
446,
2022,
14,
3640,
8,
1001,
63,
305,
63,
875,
9,
10541,
30367,
376,
909,
687,
282,
1059,
6144,
282,
4840,
909,
199,
3534,
26,
199,
446,
2022,
14,
2724,
8,
1001,
63,
785,
12,
1347,
63,
493,
9,
10541,
29026,
1565,
909,
1901,
314,
570,
199,
446,
2022,
14,
4180,
8,
1001,
63,
785,
9,
10541,
1803,
314,
4840,
6935,
315,
2399,
2624,
6025,
199,
624,
199,
646,
2022,
199,
199,
504,
5951,
492,
2494,
199,
199,
6971,
275,
378,
421,
199,
318,
2248,
63,
1001,
63,
504,
63,
493,
8,
1210,
63,
493,
63,
354,
304,
272,
543,
1551,
8,
1210,
63,
493,
63,
354,
9,
465,
666,
63,
493,
26,
267,
372,
2022,
14,
912,
8,
576,
63,
493,
9,
421,
199,
318,
3354,
63,
1001,
63,
475,
63,
493,
8,
1199,
63,
493,
12,
2022,
63,
785,
304,
272,
543,
1551,
8,
1199,
63,
493,
12,
283,
87,
358,
465,
4386,
26,
267,
2022,
14,
2724,
8,
1001,
63,
785,
12,
4386,
9,
421,
199,
318,
870,
63,
1001,
63,
785,
8,
1001,
63,
785,
304,
272,
870,
2022,
14,
4180,
8,
1001,
63,
785,
12,
4363,
29,
549,
12,
4069,
63,
1612,
29,
549,
9,
421,
199,
318,
870,
63,
6971,
837,
272,
2288,
7669,
272,
870,
283,
532,
13382,
450,
68,
24768,
534,
450,
7669,
272,
7669,
847,
413,
421,
199,
8270,
63,
5087,
63,
2861,
63,
513,
275,
2248,
63,
1001,
63,
504,
63,
493,
2336,
12117,
15,
82,
6065,
1187,
15,
2791,
15,
8270,
18,
15,
8270,
63,
5087,
63,
2861,
14,
1001,
358,
199,
199,
264,
9316,
275,
11095,
63,
5087,
63,
2861,
63,
513,
905,
264,
9316,
937,
199,
1199,
275,
2494,
342,
199,
199,
509,
25931,
315,
295,
9316,
26,
272,
4458,
63,
3185,
275,
25931,
905,
2224,
63,
3185,
937,
272,
340,
4458,
63,
3185,
59,
16,
61,
508,
298,
16857,
627,
27344,
582,
267,
1980,
272,
327,
870,
25931,
905,
18544,
937,
272,
340,
298,
269,
63,
7423,
2,
315,
25931,
26,
267,
503,
63,
7423,
275,
25931,
905,
269,
63,
7423,
937,
267,
327,
870,
503,
63,
7423,
267,
367,
3384,
315,
503,
63,
7423,
26,
288,
340,
7815,
315,
3384,
26,
355,
3384,
275,
3384,
59,
16,
26,
711,
14,
1080,
6176,
5440,
355,
1072,
14,
525,
8,
711,
9,
272,
340,
298,
2224,
63,
7423,
2,
315,
25931,
26,
267,
4458,
63,
7423,
275,
25931,
905,
2224,
63,
7423,
937,
267,
327,
870,
4458,
63,
7423,
267,
367,
3384,
315,
4458,
63,
7423,
26,
288,
340,
7815,
315,
3384,
26,
355,
1072,
14,
525,
8,
711,
9,
199,
199,
1361,
298,
452,
11095,
7149,
1568,
365,
26,
298,
435,
620,
334,
1199,
855,
552,
29133,
199,
1361,
1072,
199,
199,
1074,
63,
8270,
63,
493,
275,
1551,
4769,
12117,
15,
82,
6065,
1187,
15,
2791,
15,
8270,
18,
15,
1074,
13,
8270,
14,
6142,
401,
298,
82,
531,
199,
1074,
63,
8270,
63,
1278,
275,
1104,
63,
8270,
63,
493,
14,
9684,
342,
199,
199,
509,
1104,
63,
8270,
63,
711,
315,
1104,
63,
8270,
63,
1278,
26,
272,
340,
1104,
63,
8270,
63,
711,
315,
1072,
26,
267,
1980,
267,
327,
870,
1104,
63,
8270,
63,
711,
435,
298,
1990,
1911,
315,
314,
641,
1636,
1534,
769,
2,
272,
587,
26,
267,
870,
1104,
63,
8270,
63,
711,
435,
298,
1990,
2845,
1911,
315,
314,
641,
1636,
1534,
769,
2,
199,
199,
3,
870,
63,
6971,
342,
199,
3,
870,
730,
8,
576,
9,
221,
327,
3918,
365,
282,
2600,
199,
3,
870,
666,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
666,
459,
785,
17,
2545,
698,
18,
418,
275,
283,
1222,
574,
7,
199,
3,
870,
666,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
666,
459,
785,
18,
418,
275,
791,
698,
56,
356,
283,
585,
57,
297,
283,
698,
58,
356,
25454,
2167,
14,
2824,
93,
199,
3,
870,
63,
1001,
63,
785,
8,
576,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
340,
283,
785,
19,
7,
440,
315,
666,
26,
199,
3,
258,
666,
459,
785,
19,
418,
275,
1052,
199,
3,
870,
63,
1001,
63,
785,
8,
576,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
340,
283,
785,
18,
7,
440,
315,
666,
26,
199,
3,
258,
666,
459,
785,
18,
418,
275,
1052,
199,
3,
587,
26,
199,
3,
258,
666,
459,
785,
18,
2545,
698,
58,
418,
275,
1749,
1876,
2824,
14,
1082,
199,
3,
870,
63,
1001,
63,
785,
8,
576,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
7283,
63,
1001,
63,
1199,
63,
493,
275,
1994,
2791,
15,
5869,
63,
1199,
14,
1001,
7,
199,
3,
3354,
63,
1001,
63,
475,
63,
493,
8,
5869,
63,
1001,
63,
1199,
63,
493,
12,
666,
9,
199,
3,
4072,
63,
1618,
63,
493,
63,
73,
63,
4764,
63,
8420,
275,
2248,
63,
1001,
63,
504,
63,
493,
8,
5869,
63,
1001,
63,
1199,
63,
493,
9,
199,
3,
870,
63,
1001,
63,
785,
8,
4407,
63,
1618,
63,
493,
63,
73,
63,
4764,
63,
8420,
9,
199,
3,
199,
3,
870,
63,
6971,
342,
199,
3,
2690,
63,
576,
275,
359,
199,
3,
258,
2420,
1287,
582,
298,
7852,
401,
298,
498,
582,
298,
12231,
401,
298,
4423,
582,
3388,
1386,
199,
3,
258,
2420,
1287,
582,
298,
19978,
323,
6646,
401,
298,
498,
582,
298,
19600,
63,
5801,
401,
298,
4423,
582,
3388,
1386,
199,
3,
258,
2420,
1287,
582,
298,
19978,
323,
31534,
401,
298,
498,
582,
298,
19600,
63,
25797,
401,
298,
4423,
582,
3388,
1386,
199,
3,
258,
2420,
1287,
582,
298,
1002,
687,
11977,
401,
298,
498,
582,
298,
8677,
401,
298,
4423,
582,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
schwartzmx/ansible-modules-extras
|
database/misc/redis.py
|
41
|
10582
|
#!/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: redis
short_description: Various redis commands, slave and flush
description:
- Unified utility to interact with redis instances.
'slave' sets a redis instance in slave or master mode.
'flush' flushes all the instance or a specified db.
'config' (new in 1.6), ensures a configuration setting on an instance.
version_added: "1.3"
options:
command:
description:
- The selected redis command
required: true
default: null
choices: [ "slave", "flush", "config" ]
login_password:
description:
- The password used to authenticate with (usually not used)
required: false
default: null
login_host:
description:
- The host running the database
required: false
default: localhost
login_port:
description:
- The port to connect to
required: false
default: 6379
master_host:
description:
- The host of the master instance [slave command]
required: false
default: null
master_port:
description:
- The port of the master instance [slave command]
required: false
default: null
slave_mode:
description:
- the mode of the redis instance [slave command]
required: false
default: slave
choices: [ "master", "slave" ]
db:
description:
- The database to flush (used in db mode) [flush command]
required: false
default: null
flush_mode:
description:
- Type of flush (all the dbs in a redis instance or a specific one)
[flush command]
required: false
default: all
choices: [ "all", "db" ]
name:
version_added: 1.6
description:
- A redis config key.
required: false
default: null
value:
version_added: 1.6
description:
- A redis config value.
required: false
default: null
notes:
- Requires the redis-py Python package on the remote host. You can
install it with pip (pip install redis) or with a package manager.
https://github.com/andymccurdy/redis-py
- If the redis master instance we are making slave of is password protected
this needs to be in the redis.conf in the masterauth variable
requirements: [ redis ]
author: Xabier Larrakoetxea
'''
EXAMPLES = '''
# Set local redis instance to be slave of melee.island on port 6377
- redis: command=slave master_host=melee.island master_port=6377
# Deactivate slave mode
- redis: command=slave slave_mode=master
# Flush all the redis db
- redis: command=flush flush_mode=all
# Flush only one db in a redis instance
- redis: command=flush db=1 flush_mode=db
# Configure local redis to have 10000 max clients
- redis: command=config name=maxclients value=10000
# Configure local redis to have lua time limit of 100 ms
- redis: command=config name=lua-time-limit value=100
'''
try:
import redis
except ImportError:
redis_found = False
else:
redis_found = True
# ===========================================
# Redis module specific support methods.
#
def set_slave_mode(client, master_host, master_port):
try:
return client.slaveof(master_host, master_port)
except Exception:
return False
def set_master_mode(client):
try:
return client.slaveof()
except Exception:
return False
def flush(client, db=None):
try:
if type(db) != int:
return client.flushall()
else:
# The passed client has been connected to the database already
return client.flushdb()
except Exception:
return False
# ===========================================
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec = dict(
command=dict(default=None, choices=['slave', 'flush', 'config']),
login_password=dict(default=None),
login_host=dict(default='localhost'),
login_port=dict(default='6379'),
master_host=dict(default=None),
master_port=dict(default=None),
slave_mode=dict(default='slave', choices=['master', 'slave']),
db=dict(default=None),
flush_mode=dict(default='all', choices=['all', 'db']),
name=dict(default=None),
value=dict(default=None)
),
supports_check_mode = True
)
if not redis_found:
module.fail_json(msg="python redis module is required")
login_password = module.params['login_password']
login_host = module.params['login_host']
login_port = int(module.params['login_port'])
command = module.params['command']
# Slave Command section -----------
if command == "slave":
master_host = module.params['master_host']
master_port = module.params['master_port']
try:
master_port = int(module.params['master_port'])
except Exception:
pass
mode = module.params['slave_mode']
#Check if we have all the data
if mode == "slave": # Only need data if we want to be slave
if not master_host:
module.fail_json(
msg='In slave mode master host must be provided')
if not master_port:
module.fail_json(
msg='In slave mode master port must be provided')
#Connect and check
r = redis.StrictRedis(host=login_host,
port=login_port,
password=login_password)
try:
r.ping()
except Exception, e:
module.fail_json(msg="unable to connect to database: %s" % e)
#Check if we are already in the mode that we want
info = r.info()
if mode == "master" and info["role"] == "master":
module.exit_json(changed=False, mode=mode)
elif mode == "slave" and\
info["role"] == "slave" and\
info["master_host"] == master_host and\
info["master_port"] == master_port:
status = {
'status': mode,
'master_host': master_host,
'master_port': master_port,
}
module.exit_json(changed=False, mode=status)
else:
# Do the stuff
# (Check Check_mode before commands so the commands aren't evaluated
# if not necessary)
if mode == "slave":
if module.check_mode or\
set_slave_mode(r, master_host, master_port):
info = r.info()
status = {
'status': mode,
'master_host': master_host,
'master_port': master_port,
}
module.exit_json(changed=True, mode=status)
else:
module.fail_json(msg='Unable to set slave mode')
else:
if module.check_mode or set_master_mode(r):
module.exit_json(changed=True, mode=mode)
else:
module.fail_json(msg='Unable to set master mode')
# flush Command section -----------
elif command == "flush":
try:
db = int(module.params['db'])
except Exception:
db = 0
mode = module.params['flush_mode']
#Check if we have all the data
if mode == "db":
if type(db) != int:
module.fail_json(
msg="In db mode the db number must be provided")
#Connect and check
r = redis.StrictRedis(host=login_host,
port=login_port,
password=login_password,
db=db)
try:
r.ping()
except Exception, e:
module.fail_json(msg="unable to connect to database: %s" % e)
# Do the stuff
# (Check Check_mode before commands so the commands aren't evaluated
# if not necessary)
if mode == "all":
if module.check_mode or flush(r):
module.exit_json(changed=True, flushed=True)
else: # Flush never fails :)
module.fail_json(msg="Unable to flush all databases")
else:
if module.check_mode or flush(r, db):
module.exit_json(changed=True, flushed=True, db=db)
else: # Flush never fails :)
module.fail_json(msg="Unable to flush '%d' database" % db)
elif command == 'config':
name = module.params['name']
value = module.params['value']
r = redis.StrictRedis(host=login_host,
port=login_port,
password=login_password)
try:
r.ping()
except Exception, e:
module.fail_json(msg="unable to connect to database: %s" % e)
try:
old_value = r.config_get(name)[name]
except Exception, e:
module.fail_json(msg="unable to read config: %s" % e)
changed = old_value != value
if module.check_mode or not changed:
module.exit_json(changed=changed, name=name, value=value)
else:
try:
r.config_set(name, value)
except Exception, e:
module.fail_json(msg="unable to write config: %s" % e)
module.exit_json(changed=changed, name=name, value=value)
else:
module.fail_json(msg='A valid command must be provided')
# 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,
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,
16967,
199,
3612,
63,
1802,
26,
21107,
1785,
16967,
3718,
12,
15494,
436,
8976,
199,
1802,
26,
2043,
446,
1910,
4541,
11420,
370,
17232,
543,
16967,
4454,
14,
1362,
283,
12384,
7,
5951,
282,
16967,
1256,
315,
15494,
503,
5288,
818,
14,
1362,
283,
4939,
7,
8976,
397,
1006,
314,
1256,
503,
282,
2013,
1592,
14,
1362,
283,
888,
7,
334,
1222,
315,
413,
14,
22,
395,
15620,
282,
2897,
4260,
641,
376,
1256,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
19,
2,
199,
1419,
26,
272,
1414,
26,
267,
1369,
26,
288,
446,
710,
4895,
16967,
1414,
267,
1415,
26,
2549,
267,
849,
26,
2973,
267,
3415,
26,
359,
298,
12384,
401,
298,
4939,
401,
298,
888,
2,
1622,
272,
4676,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
2505,
1202,
370,
12895,
543,
334,
25118,
440,
1202,
9,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
4676,
63,
1102,
26,
267,
1369,
26,
288,
446,
710,
1591,
3879,
314,
3050,
267,
1415,
26,
3055,
267,
849,
26,
11667,
272,
4676,
63,
719,
26,
267,
1369,
26,
288,
446,
710,
1844,
370,
4907,
370,
267,
1415,
26,
3055,
267,
849,
26,
1227,
12015,
272,
5288,
63,
1102,
26,
267,
1369,
26,
288,
446,
710,
1591,
402,
314,
5288,
1256,
359,
12384,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
5288,
63,
719,
26,
267,
1369,
26,
288,
446,
710,
1844,
402,
314,
5288,
1256,
359,
12384,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
15494,
63,
632,
26,
267,
1369,
26,
288,
446,
314,
818,
402,
314,
16967,
1256,
359,
12384,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
15494,
267,
3415,
26,
359,
298,
4133,
401,
298,
12384,
2,
1622,
272,
1592,
26,
267,
1369,
26,
288,
446,
710,
3050,
370,
8976,
334,
2972,
315,
1592,
818,
9,
359,
4939,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
8976,
63,
632,
26,
267,
1369,
26,
288,
446,
2434,
402,
8976,
334,
452,
314,
366,
1533,
315,
282,
16967,
1256,
503,
282,
2488,
1373,
9,
1598,
359,
4939,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
1006,
267,
3415,
26,
359,
298,
452,
401,
298,
697,
2,
1622,
272,
536,
26,
267,
1015,
63,
3270,
26,
413,
14,
22,
267,
1369,
26,
288,
446,
437,
16967,
1101,
790,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
574,
26,
267,
1015,
63,
3270,
26,
413,
14,
22,
267,
1369,
26,
288,
446,
437,
16967,
1101,
574,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
421,
199,
5983,
26,
2043,
446,
15127,
314,
16967,
13,
647,
2018,
2559,
641,
314,
3982,
1591,
14,
2047,
883,
1362,
3907,
652,
543,
7305,
334,
9983,
3907,
16967,
9,
503,
543,
282,
2559,
5256,
14,
1362,
4178,
921,
5031,
14,
957,
15,
460,
89,
5466,
895,
8161,
15,
15369,
13,
647,
2043,
446,
982,
314,
16967,
5288,
1256,
781,
787,
10663,
15494,
402,
365,
2505,
17819,
1362,
642,
4839,
370,
506,
315,
314,
16967,
14,
2190,
315,
314,
28065,
2967,
762,
1750,
199,
199,
7538,
26,
359,
16967,
1622,
199,
2502,
26,
1323,
371,
4446,
491,
285,
345,
7697,
386,
10656,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2494,
2257,
16967,
1256,
370,
506,
15494,
402,
562,
18387,
14,
374,
9688,
641,
1844,
1227,
7332,
199,
13,
16967,
26,
1414,
29,
12384,
5288,
63,
1102,
29,
278,
18387,
14,
374,
9688,
5288,
63,
719,
29,
2766,
1138,
199,
199,
3,
1487,
8222,
15494,
818,
199,
13,
16967,
26,
1414,
29,
12384,
15494,
63,
632,
29,
4133,
199,
199,
3,
11040,
2084,
1006,
314,
16967,
1592,
199,
13,
16967,
26,
1414,
29,
4939,
8976,
63,
632,
29,
452,
199,
199,
3,
11040,
2084,
1454,
1373,
1592,
315,
282,
16967,
1256,
199,
13,
16967,
26,
1414,
29,
4939,
1592,
29,
17,
8976,
63,
632,
29,
697,
199,
199,
3,
15453,
2257,
16967,
370,
1172,
11630,
1390,
13431,
199,
13,
16967,
26,
1414,
29,
888,
536,
29,
988,
14555,
574,
29,
9943,
199,
199,
3,
15453,
2257,
16967,
370,
1172,
634,
1458,
900,
2304,
402,
2948,
6605,
199,
13,
16967,
26,
1414,
29,
888,
536,
29,
76,
1458,
13,
521,
13,
3097,
574,
29,
1960,
199,
2344,
199,
199,
893,
26,
272,
492,
16967,
199,
2590,
3545,
26,
272,
16967,
63,
4214,
275,
756,
199,
2836,
26,
272,
16967,
63,
4214,
275,
715,
421,
199,
3,
19469,
17575,
199,
3,
25496,
859,
2488,
2291,
3102,
14,
199,
3,
199,
199,
318,
663,
63,
12384,
63,
632,
8,
1258,
12,
5288,
63,
1102,
12,
5288,
63,
719,
304,
272,
862,
26,
267,
372,
1890,
14,
12384,
1618,
8,
4133,
63,
1102,
12,
5288,
63,
719,
9,
272,
871,
2186,
26,
267,
372,
756,
421,
199,
318,
663,
63,
4133,
63,
632,
8,
1258,
304,
272,
862,
26,
267,
372,
1890,
14,
12384,
1618,
342,
272,
871,
2186,
26,
267,
372,
756,
421,
199,
318,
8976,
8,
1258,
12,
1592,
29,
403,
304,
272,
862,
26,
267,
340,
730,
8,
697,
9
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
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,
16967,
199,
3612,
63,
1802,
26,
21107,
1785,
16967,
3718,
12,
15494,
436,
8976,
199,
1802,
26,
2043,
446,
1910,
4541,
11420,
370,
17232,
543,
16967,
4454,
14,
1362,
283,
12384,
7,
5951,
282,
16967,
1256,
315,
15494,
503,
5288,
818,
14,
1362,
283,
4939,
7,
8976,
397,
1006,
314,
1256,
503,
282,
2013,
1592,
14,
1362,
283,
888,
7,
334,
1222,
315,
413,
14,
22,
395,
15620,
282,
2897,
4260,
641,
376,
1256,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
19,
2,
199,
1419,
26,
272,
1414,
26,
267,
1369,
26,
288,
446,
710,
4895,
16967,
1414,
267,
1415,
26,
2549,
267,
849,
26,
2973,
267,
3415,
26,
359,
298,
12384,
401,
298,
4939,
401,
298,
888,
2,
1622,
272,
4676,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
2505,
1202,
370,
12895,
543,
334,
25118,
440,
1202,
9,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
4676,
63,
1102,
26,
267,
1369,
26,
288,
446,
710,
1591,
3879,
314,
3050,
267,
1415,
26,
3055,
267,
849,
26,
11667,
272,
4676,
63,
719,
26,
267,
1369,
26,
288,
446,
710,
1844,
370,
4907,
370,
267,
1415,
26,
3055,
267,
849,
26,
1227,
12015,
272,
5288,
63,
1102,
26,
267,
1369,
26,
288,
446,
710,
1591,
402,
314,
5288,
1256,
359,
12384,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
5288,
63,
719,
26,
267,
1369,
26,
288,
446,
710,
1844,
402,
314,
5288,
1256,
359,
12384,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
15494,
63,
632,
26,
267,
1369,
26,
288,
446,
314,
818,
402,
314,
16967,
1256,
359,
12384,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
15494,
267,
3415,
26,
359,
298,
4133,
401,
298,
12384,
2,
1622,
272,
1592,
26,
267,
1369,
26,
288,
446,
710,
3050,
370,
8976,
334,
2972,
315,
1592,
818,
9,
359,
4939,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
8976,
63,
632,
26,
267,
1369,
26,
288,
446,
2434,
402,
8976,
334,
452,
314,
366,
1533,
315,
282,
16967,
1256,
503,
282,
2488,
1373,
9,
1598,
359,
4939,
1414,
61,
267,
1415,
26,
3055,
267,
849,
26,
1006,
267,
3415,
26,
359,
298,
452,
401,
298,
697,
2,
1622,
272,
536,
26,
267,
1015,
63,
3270,
26,
413,
14,
22,
267,
1369,
26,
288,
446,
437,
16967,
1101,
790,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
574,
26,
267,
1015,
63,
3270,
26,
413,
14,
22,
267,
1369,
26,
288,
446,
437,
16967,
1101,
574,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
421,
199,
5983,
26,
2043,
446,
15127,
314,
16967,
13,
647,
2018,
2559,
641,
314,
3982,
1591,
14,
2047,
883,
1362,
3907,
652,
543,
7305,
334,
9983,
3907,
16967,
9,
503,
543,
282,
2559,
5256,
14,
1362,
4178,
921,
5031,
14,
957,
15,
460,
89,
5466,
895,
8161,
15,
15369,
13,
647,
2043,
446,
982,
314,
16967,
5288,
1256,
781,
787,
10663,
15494,
402,
365,
2505,
17819,
1362,
642,
4839,
370,
506,
315,
314,
16967,
14,
2190,
315,
314,
28065,
2967,
762,
1750,
199,
199,
7538,
26,
359,
16967,
1622,
199,
2502,
26,
1323,
371,
4446,
491,
285,
345,
7697,
386,
10656,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2494,
2257,
16967,
1256,
370,
506,
15494,
402,
562,
18387,
14,
374,
9688,
641,
1844,
1227,
7332,
199,
13,
16967,
26,
1414,
29,
12384,
5288,
63,
1102,
29,
278,
18387,
14,
374,
9688,
5288,
63,
719,
29,
2766,
1138,
199,
199,
3,
1487,
8222,
15494,
818,
199,
13,
16967,
26,
1414,
29,
12384,
15494,
63,
632,
29,
4133,
199,
199,
3,
11040,
2084,
1006,
314,
16967,
1592,
199,
13,
16967,
26,
1414,
29,
4939,
8976,
63,
632,
29,
452,
199,
199,
3,
11040,
2084,
1454,
1373,
1592,
315,
282,
16967,
1256,
199,
13,
16967,
26,
1414,
29,
4939,
1592,
29,
17,
8976,
63,
632,
29,
697,
199,
199,
3,
15453,
2257,
16967,
370,
1172,
11630,
1390,
13431,
199,
13,
16967,
26,
1414,
29,
888,
536,
29,
988,
14555,
574,
29,
9943,
199,
199,
3,
15453,
2257,
16967,
370,
1172,
634,
1458,
900,
2304,
402,
2948,
6605,
199,
13,
16967,
26,
1414,
29,
888,
536,
29,
76,
1458,
13,
521,
13,
3097,
574,
29,
1960,
199,
2344,
199,
199,
893,
26,
272,
492,
16967,
199,
2590,
3545,
26,
272,
16967,
63,
4214,
275,
756,
199,
2836,
26,
272,
16967,
63,
4214,
275,
715,
421,
199,
3,
19469,
17575,
199,
3,
25496,
859,
2488,
2291,
3102,
14,
199,
3,
199,
199,
318,
663,
63,
12384,
63,
632,
8,
1258,
12,
5288,
63,
1102,
12,
5288,
63,
719,
304,
272,
862,
26,
267,
372,
1890,
14,
12384,
1618,
8,
4133,
63,
1102,
12,
5288,
63,
719,
9,
272,
871,
2186,
26,
267,
372,
756,
421,
199,
318,
663,
63,
4133,
63,
632,
8,
1258,
304,
272,
862,
26,
267,
372,
1890,
14,
12384,
1618,
342,
272,
871,
2186,
26,
267,
372,
756,
421,
199,
318,
8976,
8,
1258,
12,
1592,
29,
403,
304,
272,
862,
26,
267,
340,
730,
8,
697,
9,
0
] |
[
1,
1,
1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ordQuery
|
src/prepare.py
|
1
|
4014
|
#-*- coding:utf-8 -*-
#
# Copyright © 2016–2017 Liang Feng <finalion@gmail.com>
#
# Support: Report an issue at https://github.com/finalion/WordQuery/issues
#
# 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
# any later version; http://www.gnu.org/copyleft/gpl.html.
#
# 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 anki
import aqt
from aqt import mw
from aqt.qt import *
from anki.hooks import addHook, wrap
from aqt.addcards import AddCards
from aqt.utils import showInfo, shortcut
from .ui import show_options
from .query import query_from_browser, query_from_editor_all_fields, query_from_editor_current_field
from .context import config, app_icon
############## other config here ##################
# update all fields ignoring the original field content
update_all = False
# shortcut
my_shortcut = 'Ctrl+Q'
###################################################
have_setup = False
def query_decor(func, obj):
def callback():
return func(obj)
return callback
def add_query_button(self):
bb = self.form.buttonBox
ar = QDialogButtonBox.ActionRole
self.queryButton = bb.addButton(_(u"Query"), ar)
self.queryButton.clicked.connect(query_decor(
query_from_editor_all_fields, self.editor))
self.queryButton.setShortcut(QKeySequence(my_shortcut))
self.queryButton.setToolTip(
shortcut(_(u"Query (shortcut: %s)" % my_shortcut)))
def setup_browser_menu():
def on_setup_menus(browser):
menu = QMenu("WordQuery", browser.form.menubar)
browser.form.menubar.addMenu(menu)
action_queryselected = QAction("Query Selected", browser)
action_queryselected.triggered.connect(query_decor(
query_from_browser, browser))
action_queryselected.setShortcut(QKeySequence(my_shortcut))
action_options = QAction("Options", browser)
action_options.triggered.connect(show_options)
menu.addAction(action_queryselected)
menu.addAction(action_options)
anki.hooks.addHook('browser.setupMenus', on_setup_menus)
def setup_context_menu():
def on_setup_menus(web_view, menu):
"""
add context menu to webview
"""
wqmenu = menu.addMenu('Word Query')
action1 = wqmenu.addAction('Query All Fields')
action2 = wqmenu.addAction('Query Current Field')
action3 = wqmenu.addAction('Options')
action1.triggered.connect(query_decor(
query_from_editor_all_fields, web_view.editor))
action2.triggered.connect(query_decor(
query_from_editor_current_field, web_view.editor))
action3.triggered.connect(show_options)
needs_separator = True
# menu.addMenu(submenu)
anki.hooks.addHook('EditorWebView.contextMenuEvent', on_setup_menus)
# shortcuts = [(my_shortcut, query), ]
# anki.hooks.addHook('setupEditorShortcuts', shortcuts)
def customize_addcards():
AddCards.setupButtons = wrap(
AddCards.setupButtons, add_query_button, "before")
def setup_options_menu():
# add options submenu to Tools menu
action = QAction(app_icon, "WordQuery...", mw)
action.triggered.connect(show_options)
mw.form.menuTools.addAction(action)
global have_setup
have_setup = True
# def start_here():
# # config.read()
# if not have_setup:
# setup_options_menu()
# customize_addcards()
# setup_browser_menu()
# setup_context_menu()
# # wquery.start_services()
# addHook("profileLoaded", start_here)
|
gpl-3.0
|
[
3,
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
3,
199,
3,
1898,
22405,
103,
7800,
8477,
242,
10680,
24157,
621,
481,
7420,
665,
5094,
1636,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
12502,
26,
11774,
376,
4976,
737,
4178,
921,
5031,
14,
957,
15,
5094,
1636,
15,
10155,
3227,
15,
10115,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
1263,
2945,
1015,
27,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
1574,
3039,
15,
11692,
14,
1360,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
646,
376,
8810,
199,
646,
282,
8440,
199,
504,
282,
8440,
492,
23530,
199,
504,
282,
8440,
14,
8440,
492,
627,
199,
504,
376,
8810,
14,
7922,
492,
1050,
8481,
12,
4816,
199,
504,
282,
8440,
14,
525,
13761,
492,
2654,
35,
5596,
199,
504,
282,
8440,
14,
1208,
492,
2498,
2354,
12,
17522,
199,
504,
1275,
1907,
492,
2498,
63,
1419,
199,
504,
1275,
1131,
492,
1827,
63,
504,
63,
5750,
12,
1827,
63,
504,
63,
7515,
63,
452,
63,
955,
12,
1827,
63,
504,
63,
7515,
63,
1818,
63,
698,
199,
504,
1275,
1100,
492,
1101,
12,
1145,
63,
4677,
421,
199,
516,
3726,
1163,
1101,
2348,
21905,
309,
199,
3,
1678,
1006,
1504,
17289,
314,
3379,
901,
1564,
199,
873,
63,
452,
275,
756,
199,
3,
17522,
199,
1662,
63,
24231,
275,
283,
9778,
11,
49,
7,
199,
22529,
5680,
199,
199,
7804,
63,
2758,
275,
756,
421,
199,
318,
1827,
63,
6518,
8,
1532,
12,
1559,
304,
272,
347,
3233,
837,
267,
372,
2562,
8,
1113,
9,
272,
372,
3233,
421,
199,
318,
1050,
63,
1131,
63,
3887,
8,
277,
304,
272,
14027,
275,
291,
14,
964,
14,
3887,
3532,
272,
601,
275,
1413,
5619,
4259,
3532,
14,
3310,
7422,
272,
291,
14,
1131,
4259,
275,
14027,
14,
525,
4259,
27594,
85,
2,
3227,
1288,
601,
9,
272,
291,
14,
1131,
4259,
14,
11276,
14,
2242,
8,
1131,
63,
6518,
8,
267,
1827,
63,
504,
63,
7515,
63,
452,
63,
955,
12,
291,
14,
7515,
430,
272,
291,
14,
1131,
4259,
14,
409,
28301,
8,
49,
1197,
5826,
8,
1662,
63,
24231,
430,
272,
291,
14,
1131,
4259,
14,
29892,
8,
267,
17522,
27594,
85,
2,
3227,
334,
24231,
26,
450,
83,
2924,
450,
3002,
63,
24231,
1724,
421,
199,
318,
3272,
63,
5750,
63,
4470,
837,
339,
347,
641,
63,
2758,
63,
30969,
8,
5750,
304,
267,
6269,
275,
1413,
5977,
480,
10155,
3227,
401,
7042,
14,
964,
14,
31680,
9,
267,
7042,
14,
964,
14,
31680,
14,
525,
5977,
8,
4470,
9,
267,
1595,
63,
1131,
5511,
275,
1413,
3310,
480,
3227,
3240,
2820,
401,
7042,
9,
267,
1595,
63,
1131,
5511,
14,
21142,
14,
2242,
8,
1131,
63,
6518,
8,
288,
1827,
63,
504,
63,
5750,
12,
7042,
430,
267,
1595,
63,
1131,
5511,
14,
409,
28301,
8,
49,
1197,
5826,
8,
1662,
63,
24231,
430,
267,
1595,
63,
1419,
275,
1413,
3310,
480,
4558,
401,
7042,
9,
267,
1595,
63,
1419,
14,
21142,
14,
2242,
8,
2384,
63,
1419,
9,
267,
6269,
14,
19006,
8,
1287,
63,
1131,
5511,
9,
267,
6269,
14,
19006,
8,
1287,
63,
1419,
9,
339,
376,
8810,
14,
7922,
14,
525,
8481,
360,
5750,
14,
2758,
29230,
527,
297,
641,
63,
2758,
63,
30969,
9,
421,
199,
318,
3272,
63,
1100,
63,
4470,
837,
339,
347,
641,
63,
2758,
63,
30969,
8,
2520,
63,
1345,
12,
6269,
304,
267,
408,
267,
1050,
1067,
6269,
370,
3330,
1345,
267,
408,
267,
336,
81,
4470,
275,
6269,
14,
525,
5977,
360,
10155,
8133,
358,
267,
1595,
17,
275,
336,
81,
4470,
14,
19006,
360,
3227,
2900,
16424,
358,
267,
1595,
18,
275,
336,
81,
4470,
14,
19006,
360,
3227,
9338,
5024,
358,
267,
1595,
19,
275,
336,
81,
4470,
14,
19006,
360,
4558,
358,
267,
1595,
17,
14,
21142,
14,
2242,
8,
1131,
63,
6518,
8,
288,
1827,
63,
504,
63,
7515,
63,
452,
63,
955,
12,
3330,
63,
1345,
14,
7515,
430,
267,
1595,
18,
14,
21142,
14,
2242,
8,
1131,
63,
6518,
8,
288,
1827,
63,
504,
63,
7515,
63,
1818,
63,
698,
12,
3330,
63,
1345,
14,
7515,
430,
267,
1595,
19,
14,
21142,
14,
2242,
8,
2384,
63,
1419,
9,
267,
4839,
63,
9896,
275,
715,
267,
327,
6269,
14,
525,
5977,
8,
954,
4470,
9,
272,
376,
8810,
14,
7922,
14,
525,
8481,
360,
10423,
5926,
2768,
14,
1100,
5977,
2390,
297,
641,
63,
2758,
63,
30969,
9,
272,
327,
3974,
12946,
275,
3842,
1662,
63,
24231,
12,
1827,
395,
1622,
272,
327,
376,
8810,
14,
7922,
14,
525,
8481,
360,
2758,
10423,
10039,
12946,
297,
3974,
12946,
9,
421,
199,
318,
17551,
63,
525,
13761,
837,
272,
2654,
35,
5596,
14,
2758,
24021,
275,
4816,
8,
267,
2654,
35,
5596,
14,
2758,
24021,
12,
1050,
63,
1131,
63,
3887,
12,
298,
5182,
531,
421,
199,
318,
3272,
63,
1419,
63,
4470,
837,
272,
327,
1050,
1511,
1007,
4470,
370,
23228,
6269,
272,
1595,
275,
1413,
3310,
8,
571,
63,
4677,
12,
298,
10155,
3227,
23966,
23530,
9,
272,
1595,
14,
21142,
14,
2242,
8,
2384,
63,
1419,
9,
272,
23530,
14,
964,
14,
4470,
11654,
14,
19006,
8,
1287,
9,
272,
2288,
1172,
63,
2758,
272,
1172,
63,
2758,
275,
715,
421,
199,
3,
347,
1343,
63,
1681,
837,
199,
3,
258,
327,
1101,
14,
739,
342,
199,
3,
258,
340
] |
[
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
3,
199,
3,
1898,
22405,
103,
7800,
8477,
242,
10680,
24157,
621,
481,
7420,
665,
5094,
1636,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
12502,
26,
11774,
376,
4976,
737,
4178,
921,
5031,
14,
957,
15,
5094,
1636,
15,
10155,
3227,
15,
10115,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
1263,
2945,
1015,
27,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
1574,
3039,
15,
11692,
14,
1360,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
646,
376,
8810,
199,
646,
282,
8440,
199,
504,
282,
8440,
492,
23530,
199,
504,
282,
8440,
14,
8440,
492,
627,
199,
504,
376,
8810,
14,
7922,
492,
1050,
8481,
12,
4816,
199,
504,
282,
8440,
14,
525,
13761,
492,
2654,
35,
5596,
199,
504,
282,
8440,
14,
1208,
492,
2498,
2354,
12,
17522,
199,
504,
1275,
1907,
492,
2498,
63,
1419,
199,
504,
1275,
1131,
492,
1827,
63,
504,
63,
5750,
12,
1827,
63,
504,
63,
7515,
63,
452,
63,
955,
12,
1827,
63,
504,
63,
7515,
63,
1818,
63,
698,
199,
504,
1275,
1100,
492,
1101,
12,
1145,
63,
4677,
421,
199,
516,
3726,
1163,
1101,
2348,
21905,
309,
199,
3,
1678,
1006,
1504,
17289,
314,
3379,
901,
1564,
199,
873,
63,
452,
275,
756,
199,
3,
17522,
199,
1662,
63,
24231,
275,
283,
9778,
11,
49,
7,
199,
22529,
5680,
199,
199,
7804,
63,
2758,
275,
756,
421,
199,
318,
1827,
63,
6518,
8,
1532,
12,
1559,
304,
272,
347,
3233,
837,
267,
372,
2562,
8,
1113,
9,
272,
372,
3233,
421,
199,
318,
1050,
63,
1131,
63,
3887,
8,
277,
304,
272,
14027,
275,
291,
14,
964,
14,
3887,
3532,
272,
601,
275,
1413,
5619,
4259,
3532,
14,
3310,
7422,
272,
291,
14,
1131,
4259,
275,
14027,
14,
525,
4259,
27594,
85,
2,
3227,
1288,
601,
9,
272,
291,
14,
1131,
4259,
14,
11276,
14,
2242,
8,
1131,
63,
6518,
8,
267,
1827,
63,
504,
63,
7515,
63,
452,
63,
955,
12,
291,
14,
7515,
430,
272,
291,
14,
1131,
4259,
14,
409,
28301,
8,
49,
1197,
5826,
8,
1662,
63,
24231,
430,
272,
291,
14,
1131,
4259,
14,
29892,
8,
267,
17522,
27594,
85,
2,
3227,
334,
24231,
26,
450,
83,
2924,
450,
3002,
63,
24231,
1724,
421,
199,
318,
3272,
63,
5750,
63,
4470,
837,
339,
347,
641,
63,
2758,
63,
30969,
8,
5750,
304,
267,
6269,
275,
1413,
5977,
480,
10155,
3227,
401,
7042,
14,
964,
14,
31680,
9,
267,
7042,
14,
964,
14,
31680,
14,
525,
5977,
8,
4470,
9,
267,
1595,
63,
1131,
5511,
275,
1413,
3310,
480,
3227,
3240,
2820,
401,
7042,
9,
267,
1595,
63,
1131,
5511,
14,
21142,
14,
2242,
8,
1131,
63,
6518,
8,
288,
1827,
63,
504,
63,
5750,
12,
7042,
430,
267,
1595,
63,
1131,
5511,
14,
409,
28301,
8,
49,
1197,
5826,
8,
1662,
63,
24231,
430,
267,
1595,
63,
1419,
275,
1413,
3310,
480,
4558,
401,
7042,
9,
267,
1595,
63,
1419,
14,
21142,
14,
2242,
8,
2384,
63,
1419,
9,
267,
6269,
14,
19006,
8,
1287,
63,
1131,
5511,
9,
267,
6269,
14,
19006,
8,
1287,
63,
1419,
9,
339,
376,
8810,
14,
7922,
14,
525,
8481,
360,
5750,
14,
2758,
29230,
527,
297,
641,
63,
2758,
63,
30969,
9,
421,
199,
318,
3272,
63,
1100,
63,
4470,
837,
339,
347,
641,
63,
2758,
63,
30969,
8,
2520,
63,
1345,
12,
6269,
304,
267,
408,
267,
1050,
1067,
6269,
370,
3330,
1345,
267,
408,
267,
336,
81,
4470,
275,
6269,
14,
525,
5977,
360,
10155,
8133,
358,
267,
1595,
17,
275,
336,
81,
4470,
14,
19006,
360,
3227,
2900,
16424,
358,
267,
1595,
18,
275,
336,
81,
4470,
14,
19006,
360,
3227,
9338,
5024,
358,
267,
1595,
19,
275,
336,
81,
4470,
14,
19006,
360,
4558,
358,
267,
1595,
17,
14,
21142,
14,
2242,
8,
1131,
63,
6518,
8,
288,
1827,
63,
504,
63,
7515,
63,
452,
63,
955,
12,
3330,
63,
1345,
14,
7515,
430,
267,
1595,
18,
14,
21142,
14,
2242,
8,
1131,
63,
6518,
8,
288,
1827,
63,
504,
63,
7515,
63,
1818,
63,
698,
12,
3330,
63,
1345,
14,
7515,
430,
267,
1595,
19,
14,
21142,
14,
2242,
8,
2384,
63,
1419,
9,
267,
4839,
63,
9896,
275,
715,
267,
327,
6269,
14,
525,
5977,
8,
954,
4470,
9,
272,
376,
8810,
14,
7922,
14,
525,
8481,
360,
10423,
5926,
2768,
14,
1100,
5977,
2390,
297,
641,
63,
2758,
63,
30969,
9,
272,
327,
3974,
12946,
275,
3842,
1662,
63,
24231,
12,
1827,
395,
1622,
272,
327,
376,
8810,
14,
7922,
14,
525,
8481,
360,
2758,
10423,
10039,
12946,
297,
3974,
12946,
9,
421,
199,
318,
17551,
63,
525,
13761,
837,
272,
2654,
35,
5596,
14,
2758,
24021,
275,
4816,
8,
267,
2654,
35,
5596,
14,
2758,
24021,
12,
1050,
63,
1131,
63,
3887,
12,
298,
5182,
531,
421,
199,
318,
3272,
63,
1419,
63,
4470,
837,
272,
327,
1050,
1511,
1007,
4470,
370,
23228,
6269,
272,
1595,
275,
1413,
3310,
8,
571,
63,
4677,
12,
298,
10155,
3227,
23966,
23530,
9,
272,
1595,
14,
21142,
14,
2242,
8,
2384,
63,
1419,
9,
272,
23530,
14,
964,
14,
4470,
11654,
14,
19006,
8,
1287,
9,
272,
2288,
1172,
63,
2758,
272,
1172,
63,
2758,
275,
715,
421,
199,
3,
347,
1343,
63,
1681,
837,
199,
3,
258,
327,
1101,
14,
739,
342,
199,
3,
258,
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,
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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
] |
openiitbombayx/edx-platform
|
lms/djangoapps/foldit/tests.py
|
104
|
14019
|
"""Tests for the FoldIt module"""
import json
import logging
from functools import partial
from django.test import TestCase
from django.test.client import RequestFactory
from django.core.urlresolvers import reverse
from foldit.views import foldit_ops, verify_code
from foldit.models import PuzzleComplete, Score
from student.models import unique_id_for_user, CourseEnrollment
from student.tests.factories import UserFactory
from datetime import datetime, timedelta
from pytz import UTC
from opaque_keys.edx.locations import SlashSeparatedCourseKey
log = logging.getLogger(__name__)
class FolditTestCase(TestCase):
"""Tests for various responses of the FoldIt module"""
def setUp(self):
super(FolditTestCase, self).setUp()
self.factory = RequestFactory()
self.url = reverse('foldit_ops')
self.course_id = SlashSeparatedCourseKey('course', 'id', '1')
self.course_id2 = SlashSeparatedCourseKey('course', 'id', '2')
self.user = UserFactory.create()
self.user2 = UserFactory.create()
CourseEnrollment.enroll(self.user, self.course_id)
CourseEnrollment.enroll(self.user2, self.course_id2)
now = datetime.now(UTC)
self.tomorrow = now + timedelta(days=1)
self.yesterday = now - timedelta(days=1)
def make_request(self, post_data, user=None):
"""Makes a request to foldit_ops with the given post data and user (if specified)"""
request = self.factory.post(self.url, post_data)
request.user = self.user if not user else user
return request
def make_puzzle_score_request(self, puzzle_ids, best_scores, user=None):
"""
Given lists of puzzle_ids and best_scores (must have same length), make a
SetPlayerPuzzleScores request and return the response.
"""
if not isinstance(best_scores, list):
best_scores = [best_scores]
if not isinstance(puzzle_ids, list):
puzzle_ids = [puzzle_ids]
user = self.user if not user else user
def score_dict(puzzle_id, best_score):
"""Returns a valid json-parsable score dict"""
return {"PuzzleID": puzzle_id,
"ScoreType": "score",
"BestScore": best_score,
# current scores don't actually matter
"CurrentScore": best_score + 0.01,
"ScoreVersion": 23}
scores = [score_dict(pid, bs) for pid, bs in zip(puzzle_ids, best_scores)]
scores_str = json.dumps(scores)
verify = {"Verify": verify_code(user.email, scores_str),
"VerifyMethod": "FoldItVerify"}
data = {'SetPlayerPuzzleScoresVerify': json.dumps(verify),
'SetPlayerPuzzleScores': scores_str}
request = self.make_request(data, user)
response = foldit_ops(request)
self.assertEqual(response.status_code, 200)
return response
def test_SetPlayerPuzzleScores(self): # pylint: disable=invalid-name
puzzle_id = 994391
best_score = 0.078034
response = self.make_puzzle_score_request(puzzle_id, [best_score])
self.assertEqual(response.content, json.dumps(
[{"OperationID": "SetPlayerPuzzleScores",
"Value": [{
"PuzzleID": puzzle_id,
"Status": "Success"}]}]))
# There should now be a score in the db.
top_10 = Score.get_tops_n(10, puzzle_id)
self.assertEqual(len(top_10), 1)
self.assertEqual(top_10[0]['score'], Score.display_score(best_score))
def test_SetPlayerPuzzleScores_many(self): # pylint: disable=invalid-name
response = self.make_puzzle_score_request([1, 2], [0.078034, 0.080000])
self.assertEqual(response.content, json.dumps(
[{
"OperationID": "SetPlayerPuzzleScores",
"Value": [
{
"PuzzleID": 1,
"Status": "Success"
}, {
"PuzzleID": 2,
"Status": "Success"
}
]
}]
))
def test_SetPlayerPuzzleScores_multiple(self): # pylint: disable=invalid-name
"""
Check that multiple posts with the same id are handled properly
(keep latest for each user, have multiple users work properly)
"""
orig_score = 0.07
puzzle_id = '1'
self.make_puzzle_score_request([puzzle_id], [orig_score])
# There should now be a score in the db.
top_10 = Score.get_tops_n(10, puzzle_id)
self.assertEqual(len(top_10), 1)
self.assertEqual(top_10[0]['score'], Score.display_score(orig_score))
# Reporting a better score should overwrite
better_score = 0.06
self.make_puzzle_score_request([1], [better_score])
top_10 = Score.get_tops_n(10, puzzle_id)
self.assertEqual(len(top_10), 1)
# Floats always get in the way, so do almostequal
self.assertAlmostEqual(
top_10[0]['score'],
Score.display_score(better_score),
delta=0.5
)
# reporting a worse score shouldn't
worse_score = 0.065
self.make_puzzle_score_request([1], [worse_score])
top_10 = Score.get_tops_n(10, puzzle_id)
self.assertEqual(len(top_10), 1)
# should still be the better score
self.assertAlmostEqual(
top_10[0]['score'],
Score.display_score(better_score),
delta=0.5
)
def test_SetPlayerPuzzleScores_multiple_courses(self): # pylint: disable=invalid-name
puzzle_id = "1"
player1_score = 0.05
player2_score = 0.06
course_list_1 = [self.course_id]
course_list_2 = [self.course_id2]
self.make_puzzle_score_request(puzzle_id, player1_score, self.user)
course_1_top_10 = Score.get_tops_n(10, puzzle_id, course_list_1)
course_2_top_10 = Score.get_tops_n(10, puzzle_id, course_list_2)
total_top_10 = Score.get_tops_n(10, puzzle_id)
# player1 should now be in the top 10 of course 1 and not in course 2
self.assertEqual(len(course_1_top_10), 1)
self.assertEqual(len(course_2_top_10), 0)
self.assertEqual(len(total_top_10), 1)
self.make_puzzle_score_request(puzzle_id, player2_score, self.user2)
course_2_top_10 = Score.get_tops_n(10, puzzle_id, course_list_2)
total_top_10 = Score.get_tops_n(10, puzzle_id)
# player2 should now be in the top 10 of course 2 and not in course 1
self.assertEqual(len(course_1_top_10), 1)
self.assertEqual(len(course_2_top_10), 1)
self.assertEqual(len(total_top_10), 2)
def test_SetPlayerPuzzleScores_many_players(self): # pylint: disable=invalid-name
"""
Check that when we send scores from multiple users, the correct order
of scores is displayed. Note that, before being processed by
display_score, lower scores are better.
"""
puzzle_id = ['1']
player1_score = 0.08
player2_score = 0.02
self.make_puzzle_score_request(puzzle_id, player1_score, self.user)
# There should now be a score in the db.
top_10 = Score.get_tops_n(10, puzzle_id)
self.assertEqual(len(top_10), 1)
self.assertEqual(top_10[0]['score'], Score.display_score(player1_score))
self.make_puzzle_score_request(puzzle_id, player2_score, self.user2)
# There should now be two scores in the db
top_10 = Score.get_tops_n(10, puzzle_id)
self.assertEqual(len(top_10), 2)
# Top score should be player2_score. Second should be player1_score
self.assertAlmostEqual(
top_10[0]['score'],
Score.display_score(player2_score),
delta=0.5
)
self.assertAlmostEqual(
top_10[1]['score'],
Score.display_score(player1_score),
delta=0.5
)
# Top score user should be self.user2.username
self.assertEqual(top_10[0]['username'], self.user2.username)
def test_SetPlayerPuzzleScores_error(self): # pylint: disable=invalid-name
scores = [{
"PuzzleID": 994391,
"ScoreType": "score",
"BestScore": 0.078034,
"CurrentScore": 0.080035,
"ScoreVersion": 23
}]
validation_str = json.dumps(scores)
verify = {
"Verify": verify_code(self.user.email, validation_str),
"VerifyMethod": "FoldItVerify"
}
# change the real string -- should get an error
scores[0]['ScoreVersion'] = 22
scores_str = json.dumps(scores)
data = {
'SetPlayerPuzzleScoresVerify': json.dumps(verify),
'SetPlayerPuzzleScores': scores_str
}
request = self.make_request(data)
response = foldit_ops(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content,
json.dumps([{
"OperationID": "SetPlayerPuzzleScores",
"Success": "false",
"ErrorString": "Verification failed",
"ErrorCode": "VerifyFailed"}]))
def make_puzzles_complete_request(self, puzzles):
"""
Make a puzzles complete request, given an array of
puzzles. E.g.
[ {"PuzzleID": 13, "Set": 1, "SubSet": 2},
{"PuzzleID": 53524, "Set": 1, "SubSet": 1} ]
"""
puzzles_str = json.dumps(puzzles)
verify = {
"Verify": verify_code(self.user.email, puzzles_str),
"VerifyMethod": "FoldItVerify"
}
data = {
'SetPuzzlesCompleteVerify': json.dumps(verify),
'SetPuzzlesComplete': puzzles_str
}
request = self.make_request(data)
response = foldit_ops(request)
self.assertEqual(response.status_code, 200)
return response
@staticmethod
def set_puzzle_complete_response(values):
"""Returns a json response of a Puzzle Complete message"""
return json.dumps([{"OperationID": "SetPuzzlesComplete",
"Value": values}])
def test_SetPlayerPuzzlesComplete(self): # pylint: disable=invalid-name
puzzles = [
{"PuzzleID": 13, "Set": 1, "SubSet": 2},
{"PuzzleID": 53524, "Set": 1, "SubSet": 1}
]
response = self.make_puzzles_complete_request(puzzles)
self.assertEqual(response.content,
self.set_puzzle_complete_response([13, 53524]))
def test_SetPlayerPuzzlesComplete_multiple(self): # pylint: disable=invalid-name
"""Check that state is stored properly"""
puzzles = [
{"PuzzleID": 13, "Set": 1, "SubSet": 2},
{"PuzzleID": 53524, "Set": 1, "SubSet": 1}
]
response = self.make_puzzles_complete_request(puzzles)
self.assertEqual(response.content,
self.set_puzzle_complete_response([13, 53524]))
puzzles = [
{"PuzzleID": 14, "Set": 1, "SubSet": 3},
{"PuzzleID": 15, "Set": 1, "SubSet": 1}
]
response = self.make_puzzles_complete_request(puzzles)
self.assertEqual(
response.content,
self.set_puzzle_complete_response([13, 14, 15, 53524])
)
def test_SetPlayerPuzzlesComplete_level_complete(self): # pylint: disable=invalid-name
"""Check that the level complete function works"""
puzzles = [
{"PuzzleID": 13, "Set": 1, "SubSet": 2},
{"PuzzleID": 53524, "Set": 1, "SubSet": 1}
]
response = self.make_puzzles_complete_request(puzzles)
self.assertEqual(response.content,
self.set_puzzle_complete_response([13, 53524]))
puzzles = [
{"PuzzleID": 14, "Set": 1, "SubSet": 3},
{"PuzzleID": 15, "Set": 1, "SubSet": 1}
]
response = self.make_puzzles_complete_request(puzzles)
self.assertEqual(response.content,
self.set_puzzle_complete_response([13, 14, 15, 53524]))
is_complete = partial(
PuzzleComplete.is_level_complete, unique_id_for_user(self.user))
self.assertTrue(is_complete(1, 1))
self.assertTrue(is_complete(1, 3))
self.assertTrue(is_complete(1, 2))
self.assertFalse(is_complete(4, 5))
puzzles = [{"PuzzleID": 74, "Set": 4, "SubSet": 5}]
response = self.make_puzzles_complete_request(puzzles)
self.assertTrue(is_complete(4, 5))
# Now check due dates
self.assertTrue(is_complete(1, 1, due=self.tomorrow))
self.assertFalse(is_complete(1, 1, due=self.yesterday))
def test_SetPlayerPuzzlesComplete_error(self): # pylint: disable=invalid-name
puzzles = [
{"PuzzleID": 13, "Set": 1, "SubSet": 2},
{"PuzzleID": 53524, "Set": 1, "SubSet": 1}
]
puzzles_str = json.dumps(puzzles)
verify = {
"Verify": verify_code(self.user.email, puzzles_str + "x"),
"VerifyMethod": "FoldItVerify"
}
data = {
'SetPuzzlesCompleteVerify': json.dumps(verify),
'SetPuzzlesComplete': puzzles_str
}
request = self.make_request(data)
response = foldit_ops(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content,
json.dumps([{
"OperationID": "SetPuzzlesComplete",
"Success": "false",
"ErrorString": "Verification failed",
"ErrorCode": "VerifyFailed"}]))
|
agpl-3.0
|
[
624,
2925,
367,
314,
481,
1753,
7940,
859,
624,
199,
646,
2022,
199,
646,
2050,
199,
504,
9143,
492,
7417,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
18638,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
1699,
1741,
14,
4196,
492,
1699,
1741,
63,
1483,
12,
4911,
63,
600,
199,
504,
1699,
1741,
14,
992,
492,
510,
85,
17622,
14175,
12,
25318,
199,
504,
6474,
14,
992,
492,
3747,
63,
344,
63,
509,
63,
751,
12,
18946,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
15444,
492,
12174,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
481,
393,
1741,
1746,
8,
1746,
304,
272,
408,
2925,
367,
7750,
9320,
402,
314,
481,
1753,
7940,
859,
624,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
38,
393,
1741,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
3702,
275,
18638,
342,
267,
291,
14,
633,
275,
3837,
360,
5900,
1741,
63,
1483,
358,
398,
291,
14,
1972,
63,
344,
275,
30687,
360,
1972,
297,
283,
344,
297,
283,
17,
358,
267,
291,
14,
1972,
63,
344,
18,
275,
30687,
360,
1972,
297,
283,
344,
297,
283,
18,
358,
398,
291,
14,
751,
275,
16047,
14,
981,
342,
267,
291,
14,
751,
18,
275,
16047,
14,
981,
342,
398,
18946,
14,
14695,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
9,
267,
18946,
14,
14695,
8,
277,
14,
751,
18,
12,
291,
14,
1972,
63,
344,
18,
9,
398,
3063,
275,
2197,
14,
2131,
8,
11288,
9,
267,
291,
14,
3151,
19598,
275,
3063,
435,
6871,
8,
4899,
29,
17,
9,
267,
291,
14,
5066,
25297,
275,
3063,
446,
6871,
8,
4899,
29,
17,
9,
339,
347,
1852,
63,
1069,
8,
277,
12,
2963,
63,
576,
12,
922,
29,
403,
304,
267,
408,
27142,
282,
1056,
370,
1699,
1741,
63,
1483,
543,
314,
1627,
2963,
666,
436,
922,
334,
692,
2013,
9471,
267,
1056,
275,
291,
14,
3702,
14,
1932,
8,
277,
14,
633,
12,
2963,
63,
576,
9,
267,
1056,
14,
751,
275,
291,
14,
751,
340,
440,
922,
587,
922,
267,
372,
1056,
339,
347,
1852,
63,
3165,
17622,
63,
3397,
63,
1069,
8,
277,
12,
18848,
17622,
63,
1580,
12,
5526,
63,
7107,
12,
922,
29,
403,
304,
267,
408,
267,
9138,
5548,
402,
18848,
17622,
63,
1580,
436,
5526,
63,
7107,
334,
7790,
1172,
2011,
2582,
395,
1852,
282,
267,
2494,
10921,
26607,
17622,
29654,
1056,
436,
372,
314,
1177,
14,
267,
408,
267,
340,
440,
1228,
8,
7010,
63,
7107,
12,
769,
304,
288,
5526,
63,
7107,
275,
359,
7010,
63,
7107,
61,
267,
340,
440,
1228,
8,
3165,
17622,
63,
1580,
12,
769,
304,
288,
18848,
17622,
63,
1580,
275,
359,
3165,
17622,
63,
1580,
61,
267,
922,
275,
291,
14,
751,
340,
440,
922,
587,
922,
398,
347,
5396,
63,
807,
8,
3165,
17622,
63,
344,
12,
5526,
63,
3397,
304,
288,
408,
3407,
282,
1686,
2022,
13,
21152,
461,
5396,
1211,
624,
288,
372,
2420,
26607,
17622,
998,
582,
18848,
17622,
63,
344,
12,
490,
298,
12642,
804,
582,
298,
3397,
401,
490,
298,
19478,
12642,
582,
5526,
63,
3397,
12,
490,
327,
1453,
9342,
2793,
1133,
5965,
17247,
490,
298,
5639,
12642,
582,
5526,
63,
3397,
435,
378,
14,
614,
12,
490,
298,
12642,
3353,
582,
6546,
93,
267,
9342,
275,
359,
3397,
63,
807,
8,
3150,
12,
9922,
9,
367,
4422,
12,
9922,
315,
3482,
8,
3165,
17622,
63,
1580,
12,
5526,
63,
7107,
1874,
267,
9342,
63,
495,
275,
2022,
14,
4180,
8,
7107,
9,
398,
4911,
275,
2420,
7496,
582,
4911,
63,
600,
8,
751,
14,
2123,
12,
9342,
63,
495,
395,
2116,
298,
7496,
3767,
582,
298,
27985,
7940,
7496,
3570,
267,
666,
275,
791,
1084,
10921,
26607,
17622,
29654,
7496,
356,
2022,
14,
4180,
8,
4712,
395,
355,
283,
1084,
10921,
26607,
17622,
29654,
356,
9342,
63,
495,
93,
398,
1056,
275,
291,
14,
1875,
63,
1069,
8,
576,
12,
922,
9,
398,
1177,
275,
1699,
1741,
63,
1483,
8,
1069,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
372,
1177,
339,
347,
511,
63,
1084,
10921,
26607,
17622,
29654,
8,
277,
304,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
398,
18848,
17622,
63,
344,
275,
8806,
20,
16959,
267,
5526,
63,
3397,
275,
378,
14,
1780,
1257,
1082,
267,
1177,
275,
291,
14,
1875,
63,
3165,
17622,
63,
3397,
63,
1069,
8,
3165,
17622,
63,
344,
12,
359,
7010,
63,
3397,
566,
398,
291,
14,
629,
8,
1310,
14,
1317,
12,
2022,
14,
4180,
8,
288,
16870,
6044,
998,
582,
298,
1084,
10921,
26607,
17622,
29654,
401,
1598,
298,
1110,
582,
8910,
2116,
298,
26607,
17622,
998,
582,
18848,
17622,
63,
344,
12,
2116,
298,
3694,
582,
298,
8300,
3570,
9420,
2459,
398,
327,
6006,
1077,
3063,
506,
282,
5396,
315,
314,
1592,
14,
267,
2746,
63,
709,
275,
25318,
14,
362,
63,
84,
1483,
63,
78,
8,
709,
12,
18848,
17622,
63,
344,
9,
267,
291,
14,
629,
8,
552,
8,
2119,
63,
709,
395,
413,
9,
267,
291,
14,
629,
8,
2119,
63,
709,
59,
16,
2733,
3397,
995,
25318,
14,
2918,
63,
3397,
8,
7010,
63,
3397,
430,
339,
347,
511,
63,
1084,
10921,
26607,
17622,
29654,
63,
3479,
8,
277,
304,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
398,
1177,
275,
291,
14,
1875,
63,
3165,
17622,
63,
3397,
63,
1069,
779,
17,
12,
499,
467,
359,
16,
14,
1780,
1257,
1082,
12,
378,
14,
2036,
993,
566,
398,
291,
14,
629,
8,
1310,
14,
1317,
12,
2022,
14,
4180,
8,
288,
8910,
355,
298,
6044,
998,
582,
298,
1084,
10921,
26607,
17622,
29654,
401,
355,
298,
1110,
582,
359,
490,
469,
717,
298,
26607,
17622,
998,
582,
413,
12,
717,
298,
3694,
582,
298,
8300,
2,
490,
1660,
469,
717,
298,
26607,
17622,
998,
582,
499,
12,
717,
298,
3694,
582,
298
] |
[
2925,
367,
314,
481,
1753,
7940,
859,
624,
199,
646,
2022,
199,
646,
2050,
199,
504,
9143,
492,
7417,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
18638,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
1699,
1741,
14,
4196,
492,
1699,
1741,
63,
1483,
12,
4911,
63,
600,
199,
504,
1699,
1741,
14,
992,
492,
510,
85,
17622,
14175,
12,
25318,
199,
504,
6474,
14,
992,
492,
3747,
63,
344,
63,
509,
63,
751,
12,
18946,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
15444,
492,
12174,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
481,
393,
1741,
1746,
8,
1746,
304,
272,
408,
2925,
367,
7750,
9320,
402,
314,
481,
1753,
7940,
859,
624,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
38,
393,
1741,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
3702,
275,
18638,
342,
267,
291,
14,
633,
275,
3837,
360,
5900,
1741,
63,
1483,
358,
398,
291,
14,
1972,
63,
344,
275,
30687,
360,
1972,
297,
283,
344,
297,
283,
17,
358,
267,
291,
14,
1972,
63,
344,
18,
275,
30687,
360,
1972,
297,
283,
344,
297,
283,
18,
358,
398,
291,
14,
751,
275,
16047,
14,
981,
342,
267,
291,
14,
751,
18,
275,
16047,
14,
981,
342,
398,
18946,
14,
14695,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
9,
267,
18946,
14,
14695,
8,
277,
14,
751,
18,
12,
291,
14,
1972,
63,
344,
18,
9,
398,
3063,
275,
2197,
14,
2131,
8,
11288,
9,
267,
291,
14,
3151,
19598,
275,
3063,
435,
6871,
8,
4899,
29,
17,
9,
267,
291,
14,
5066,
25297,
275,
3063,
446,
6871,
8,
4899,
29,
17,
9,
339,
347,
1852,
63,
1069,
8,
277,
12,
2963,
63,
576,
12,
922,
29,
403,
304,
267,
408,
27142,
282,
1056,
370,
1699,
1741,
63,
1483,
543,
314,
1627,
2963,
666,
436,
922,
334,
692,
2013,
9471,
267,
1056,
275,
291,
14,
3702,
14,
1932,
8,
277,
14,
633,
12,
2963,
63,
576,
9,
267,
1056,
14,
751,
275,
291,
14,
751,
340,
440,
922,
587,
922,
267,
372,
1056,
339,
347,
1852,
63,
3165,
17622,
63,
3397,
63,
1069,
8,
277,
12,
18848,
17622,
63,
1580,
12,
5526,
63,
7107,
12,
922,
29,
403,
304,
267,
408,
267,
9138,
5548,
402,
18848,
17622,
63,
1580,
436,
5526,
63,
7107,
334,
7790,
1172,
2011,
2582,
395,
1852,
282,
267,
2494,
10921,
26607,
17622,
29654,
1056,
436,
372,
314,
1177,
14,
267,
408,
267,
340,
440,
1228,
8,
7010,
63,
7107,
12,
769,
304,
288,
5526,
63,
7107,
275,
359,
7010,
63,
7107,
61,
267,
340,
440,
1228,
8,
3165,
17622,
63,
1580,
12,
769,
304,
288,
18848,
17622,
63,
1580,
275,
359,
3165,
17622,
63,
1580,
61,
267,
922,
275,
291,
14,
751,
340,
440,
922,
587,
922,
398,
347,
5396,
63,
807,
8,
3165,
17622,
63,
344,
12,
5526,
63,
3397,
304,
288,
408,
3407,
282,
1686,
2022,
13,
21152,
461,
5396,
1211,
624,
288,
372,
2420,
26607,
17622,
998,
582,
18848,
17622,
63,
344,
12,
490,
298,
12642,
804,
582,
298,
3397,
401,
490,
298,
19478,
12642,
582,
5526,
63,
3397,
12,
490,
327,
1453,
9342,
2793,
1133,
5965,
17247,
490,
298,
5639,
12642,
582,
5526,
63,
3397,
435,
378,
14,
614,
12,
490,
298,
12642,
3353,
582,
6546,
93,
267,
9342,
275,
359,
3397,
63,
807,
8,
3150,
12,
9922,
9,
367,
4422,
12,
9922,
315,
3482,
8,
3165,
17622,
63,
1580,
12,
5526,
63,
7107,
1874,
267,
9342,
63,
495,
275,
2022,
14,
4180,
8,
7107,
9,
398,
4911,
275,
2420,
7496,
582,
4911,
63,
600,
8,
751,
14,
2123,
12,
9342,
63,
495,
395,
2116,
298,
7496,
3767,
582,
298,
27985,
7940,
7496,
3570,
267,
666,
275,
791,
1084,
10921,
26607,
17622,
29654,
7496,
356,
2022,
14,
4180,
8,
4712,
395,
355,
283,
1084,
10921,
26607,
17622,
29654,
356,
9342,
63,
495,
93,
398,
1056,
275,
291,
14,
1875,
63,
1069,
8,
576,
12,
922,
9,
398,
1177,
275,
1699,
1741,
63,
1483,
8,
1069,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
372,
1177,
339,
347,
511,
63,
1084,
10921,
26607,
17622,
29654,
8,
277,
304,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
398,
18848,
17622,
63,
344,
275,
8806,
20,
16959,
267,
5526,
63,
3397,
275,
378,
14,
1780,
1257,
1082,
267,
1177,
275,
291,
14,
1875,
63,
3165,
17622,
63,
3397,
63,
1069,
8,
3165,
17622,
63,
344,
12,
359,
7010,
63,
3397,
566,
398,
291,
14,
629,
8,
1310,
14,
1317,
12,
2022,
14,
4180,
8,
288,
16870,
6044,
998,
582,
298,
1084,
10921,
26607,
17622,
29654,
401,
1598,
298,
1110,
582,
8910,
2116,
298,
26607,
17622,
998,
582,
18848,
17622,
63,
344,
12,
2116,
298,
3694,
582,
298,
8300,
3570,
9420,
2459,
398,
327,
6006,
1077,
3063,
506,
282,
5396,
315,
314,
1592,
14,
267,
2746,
63,
709,
275,
25318,
14,
362,
63,
84,
1483,
63,
78,
8,
709,
12,
18848,
17622,
63,
344,
9,
267,
291,
14,
629,
8,
552,
8,
2119,
63,
709,
395,
413,
9,
267,
291,
14,
629,
8,
2119,
63,
709,
59,
16,
2733,
3397,
995,
25318,
14,
2918,
63,
3397,
8,
7010,
63,
3397,
430,
339,
347,
511,
63,
1084,
10921,
26607,
17622,
29654,
63,
3479,
8,
277,
304,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
398,
1177,
275,
291,
14,
1875,
63,
3165,
17622,
63,
3397,
63,
1069,
779,
17,
12,
499,
467,
359,
16,
14,
1780,
1257,
1082,
12,
378,
14,
2036,
993,
566,
398,
291,
14,
629,
8,
1310,
14,
1317,
12,
2022,
14,
4180,
8,
288,
8910,
355,
298,
6044,
998,
582,
298,
1084,
10921,
26607,
17622,
29654,
401,
355,
298,
1110,
582,
359,
490,
469,
717,
298,
26607,
17622,
998,
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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
] |
ossdemura/django-miniblog
|
Lib/site-packages/django/contrib/admindocs/urls.py
|
97
|
1192
|
from django.conf.urls import url
from django.contrib.admindocs import views
urlpatterns = [
url(r'^$',
views.BaseAdminDocsView.as_view(template_name='admin_doc/index.html'),
name='django-admindocs-docroot'),
url(r'^bookmarklets/$',
views.BookmarkletsView.as_view(),
name='django-admindocs-bookmarklets'),
url(r'^tags/$',
views.TemplateTagIndexView.as_view(),
name='django-admindocs-tags'),
url(r'^filters/$',
views.TemplateFilterIndexView.as_view(),
name='django-admindocs-filters'),
url(r'^views/$',
views.ViewIndexView.as_view(),
name='django-admindocs-views-index'),
url(r'^views/(?P<view>[^/]+)/$',
views.ViewDetailView.as_view(),
name='django-admindocs-views-detail'),
url(r'^models/$',
views.ModelIndexView.as_view(),
name='django-admindocs-models-index'),
url(r'^models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$',
views.ModelDetailView.as_view(),
name='django-admindocs-models-detail'),
url(r'^templates/(?P<template>.*)/$',
views.TemplateDetailView.as_view(),
name='django-admindocs-templates'),
]
|
mit
|
[
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
2828,
14,
14464,
688,
14851,
492,
6858,
199,
199,
20050,
275,
359,
272,
1166,
8,
82,
4289,
4268,
267,
6858,
14,
1563,
4880,
27858,
2768,
14,
305,
63,
1345,
8,
1160,
63,
354,
534,
2113,
63,
1301,
15,
1080,
14,
1360,
659,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
1301,
1231,
659,
272,
1166,
8,
82,
4289,
17341,
16537,
10884,
267,
6858,
14,
8696,
1657,
16537,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
17341,
16537,
659,
272,
1166,
8,
82,
4289,
2969,
10884,
267,
6858,
14,
4231,
1931,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
2969,
659,
272,
1166,
8,
82,
4289,
4273,
10884,
267,
6858,
14,
4231,
4131,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4273,
659,
272,
1166,
8,
82,
4289,
4196,
10884,
267,
6858,
14,
2768,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
1080,
659,
272,
1166,
8,
82,
4289,
4196,
9448,
48,
28,
1345,
26906,
2447,
4268,
267,
6858,
14,
2768,
28539,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
5506,
659,
272,
1166,
8,
82,
4289,
992,
10884,
267,
6858,
14,
1685,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
1080,
659,
272,
1166,
8,
82,
4289,
992,
9448,
48,
28,
571,
63,
1302,
13489,
4537,
18096,
14,
2229,
48,
28,
1238,
63,
354,
26906,
2447,
4268,
267,
6858,
14,
1685,
28539,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
5506,
659,
272,
1166,
8,
82,
4289,
5876,
9448,
48,
28,
1160,
23742,
2447,
4268,
267,
6858,
14,
4231,
28539,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
5876,
659,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
2828,
14,
14464,
688,
14851,
492,
6858,
199,
199,
20050,
275,
359,
272,
1166,
8,
82,
4289,
4268,
267,
6858,
14,
1563,
4880,
27858,
2768,
14,
305,
63,
1345,
8,
1160,
63,
354,
534,
2113,
63,
1301,
15,
1080,
14,
1360,
659,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
1301,
1231,
659,
272,
1166,
8,
82,
4289,
17341,
16537,
10884,
267,
6858,
14,
8696,
1657,
16537,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
17341,
16537,
659,
272,
1166,
8,
82,
4289,
2969,
10884,
267,
6858,
14,
4231,
1931,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
2969,
659,
272,
1166,
8,
82,
4289,
4273,
10884,
267,
6858,
14,
4231,
4131,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4273,
659,
272,
1166,
8,
82,
4289,
4196,
10884,
267,
6858,
14,
2768,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
1080,
659,
272,
1166,
8,
82,
4289,
4196,
9448,
48,
28,
1345,
26906,
2447,
4268,
267,
6858,
14,
2768,
28539,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
5506,
659,
272,
1166,
8,
82,
4289,
992,
10884,
267,
6858,
14,
1685,
2681,
2768,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
1080,
659,
272,
1166,
8,
82,
4289,
992,
9448,
48,
28,
571,
63,
1302,
13489,
4537,
18096,
14,
2229,
48,
28,
1238,
63,
354,
26906,
2447,
4268,
267,
6858,
14,
1685,
28539,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
5506,
659,
272,
1166,
8,
82,
4289,
5876,
9448,
48,
28,
1160,
23742,
2447,
4268,
267,
6858,
14,
4231,
28539,
14,
305,
63,
1345,
1062,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
5876,
659,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Alwnikrotikz/pyglet
|
contrib/scene2d/examples/invaders.py
|
29
|
3055
|
import os
import math
import pyglet.window
from resource import *
from pyglet.window import key
from pyglet import clock
from scene2d import *
class PlayerSprite(Sprite):
bullets = []
def update(self, dt):
self.x += (keyboard[key.RIGHT] - keyboard[key.LEFT]) * 200 * dt
if self.left < 0: self.left = 0
if self.right > w.width: self.right = w.width
if self.properties['fired']:
self.properties['fired'] = max(0, self.properties['fired'] - dt)
if keyboard[key.SPACE]:
if not self.properties['fired']:
self.properties['fired'] = 1
shot = Sprite.from_image(0, 0, r['player-bullet'])
shot.midbottom = self.midtop
view.sprites.append(shot)
self.bullets.append(shot)
class EnemySprite(Sprite):
bullets = []
def update(self, dt):
self.x += self.properties['dx'] * dt
if self.right > w.width:
self.right = w.width
self.properties['dx'] *= -1
if self.x < 0:
self.x = 0
self.properties['dx'] *= -1
if not self.properties['fired']:
self.properties['fired'] = 5
shot = Sprite.from_image(0, 0, r['enemy-bullet1'])
shot.midtop = self.midbottom
view.sprites.append(shot)
self.bullets.append(shot)
else:
self.properties['fired'] = max(0, self.properties['fired'] - dt)
w = pyglet.window.Window(width=512, height=512)
w.set_exclusive_mouse()
clock.set_fps_limit(30)
# load the map and car and set up the view
dirname = os.path.dirname(__file__)
r = Resource.load(os.path.join(dirname, 'invaders.xml'))
player = PlayerSprite.from_image(0, 0, r['player'], properties=dict(fired=0))
clock.schedule(player.update)
view = FlatView.from_window(w, fx=w.width/2, fy=w.height/2,
sprites=[player])
dead = False
enemies = [
EnemySprite.from_image(100, 400, r['enemy1'],
properties={'dx': 150, 'fired': 0})
]
for enemy in enemies:
view.sprites.append(enemy)
clock.schedule(enemy.update)
keyboard = key.KeyStateHandler()
w.push_handlers(keyboard)
while not (w.has_exit or dead):
dt = clock.tick()
w.dispatch_events()
# collision detection
for shot in list(enemies[0].bullets):
shot.y -= 200 * dt
if shot.overlaps(player):
print 'YOU LOST!'
dead = True
break
if shot.y < 0:
enemies[0].bullets.remove(shot)
view.sprites.remove(shot)
for shot in list(player.bullets):
shot.y += 200 * dt
for enemy in list(enemies):
if shot.overlaps(enemy):
view.sprites.remove(enemy)
enemies.remove(enemy)
clock.unschedule(enemy.update)
if shot.y > 512:
player.bullets.remove(shot)
view.sprites.remove(shot)
# end game
if not enemies:
print 'YOU WON!'
break
view.clear()
view.draw()
w.flip()
w.close()
|
bsd-3-clause
|
[
646,
747,
199,
646,
3473,
199,
199,
646,
23409,
14,
3806,
199,
504,
2073,
492,
627,
199,
504,
23409,
14,
3806,
492,
790,
199,
504,
23409,
492,
12516,
199,
504,
13856,
18,
68,
492,
627,
199,
199,
533,
25610,
30185,
8,
30185,
304,
272,
330,
348,
16537,
275,
942,
272,
347,
1678,
8,
277,
12,
4487,
304,
267,
291,
14,
88,
847,
334,
19553,
59,
498,
14,
12811,
61,
446,
18716,
59,
498,
14,
9894,
566,
627,
1926,
627,
4487,
267,
340,
291,
14,
3039,
665,
378,
26,
291,
14,
3039,
275,
378,
267,
340,
291,
14,
1019,
690,
336,
14,
2063,
26,
291,
14,
1019,
275,
336,
14,
2063,
267,
340,
291,
14,
3282,
459,
329,
581,
2565,
288,
291,
14,
3282,
459,
329,
581,
418,
275,
1390,
8,
16,
12,
291,
14,
3282,
459,
329,
581,
418,
446,
4487,
9,
267,
340,
18716,
59,
498,
14,
11658,
2189,
288,
340,
440,
291,
14,
3282,
459,
329,
581,
2565,
355,
291,
14,
3282,
459,
329,
581,
418,
275,
413,
355,
1033,
357,
275,
8360,
752,
14,
504,
63,
1569,
8,
16,
12,
378,
12,
519,
459,
6147,
13,
20520,
1105,
355,
1033,
357,
14,
8523,
8305,
275,
291,
14,
8523,
2119,
355,
2455,
14,
27495,
14,
740,
8,
2782,
9,
355,
291,
14,
25792,
16537,
14,
740,
8,
2782,
9,
199,
199,
533,
662,
685,
1662,
30185,
8,
30185,
304,
272,
330,
348,
16537,
275,
942,
272,
347,
1678,
8,
277,
12,
4487,
304,
267,
291,
14,
88,
847,
291,
14,
3282,
459,
8373,
418,
627,
4487,
267,
340,
291,
14,
1019,
690,
336,
14,
2063,
26,
288,
291,
14,
1019,
275,
336,
14,
2063,
288,
291,
14,
3282,
459,
8373,
418,
9000,
446,
17,
267,
340,
291,
14,
88,
665,
378,
26,
288,
291,
14,
88,
275,
378,
288,
291,
14,
3282,
459,
8373,
418,
9000,
446,
17,
267,
340,
440,
291,
14,
3282,
459,
329,
581,
2565,
288,
291,
14,
3282,
459,
329,
581,
418,
275,
959,
288,
1033,
357,
275,
8360,
752,
14,
504,
63,
1569,
8,
16,
12,
378,
12,
519,
459,
6349,
1662,
13,
20520,
17,
1105,
288,
1033,
357,
14,
8523,
2119,
275,
291,
14,
8523,
8305,
288,
2455,
14,
27495,
14,
740,
8,
2782,
9,
288,
291,
14,
25792,
16537,
14,
740,
8,
2782,
9,
267,
587,
26,
288,
291,
14,
3282,
459,
329,
581,
418,
275,
1390,
8,
16,
12,
291,
14,
3282,
459,
329,
581,
418,
446,
4487,
9,
199,
199,
87,
275,
23409,
14,
3806,
14,
4301,
8,
2063,
29,
7736,
12,
4569,
29,
7736,
9,
199,
87,
14,
409,
63,
12730,
63,
10544,
342,
199,
9597,
14,
409,
63,
24709,
63,
3097,
8,
1216,
9,
199,
199,
3,
2248,
314,
2341,
436,
9590,
436,
663,
1536,
314,
2455,
199,
3475,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
82,
275,
7337,
14,
912,
8,
736,
14,
515,
14,
904,
8,
3475,
12,
283,
5350,
669,
83,
14,
1652,
1333,
199,
6147,
275,
25610,
30185,
14,
504,
63,
1569,
8,
16,
12,
378,
12,
519,
459,
6147,
995,
4382,
29,
807,
8,
329,
581,
29,
16,
430,
199,
9597,
14,
7211,
8,
6147,
14,
873,
9,
199,
1345,
275,
19005,
2768,
14,
504,
63,
3806,
8,
87,
12,
28020,
29,
87,
14,
2063,
15,
18,
12,
289,
89,
29,
87,
14,
3333,
15,
18,
12,
272,
25328,
1524,
6147,
566,
199,
199,
10957,
275,
756,
199,
287,
5633,
1500,
275,
359,
272,
662,
685,
1662,
30185,
14,
504,
63,
1569,
8,
1960,
12,
8290,
12,
519,
459,
6349,
1662,
17,
995,
267,
4382,
3713,
8373,
356,
14711,
12,
283,
329,
581,
356,
378,
1552,
199,
61,
199,
509,
655,
69,
1662,
315,
655,
5633,
1500,
26,
272,
2455,
14,
27495,
14,
740,
8,
6349,
1662,
9,
272,
12516,
14,
7211,
8,
6349,
1662,
14,
873,
9,
199,
199,
19553,
275,
790,
14,
1197,
2223,
2461,
342,
199,
87,
14,
5335,
63,
5586,
8,
19553,
9,
199,
199,
6710,
440,
334,
87,
14,
1989,
63,
2224,
503,
12314,
304,
272,
4487,
275,
12516,
14,
8284,
342,
272,
336,
14,
6052,
63,
4368,
342,
339,
327,
25061,
15212,
272,
367,
1033,
357,
315,
769,
8,
287,
5633,
1500,
59,
16,
1055,
25792,
16537,
304,
267,
1033,
357,
14,
89,
4862,
1926,
627,
4487,
267,
340,
1033,
357,
14,
20798,
8,
6147,
304,
288,
870,
283,
57,
22050,
3412,
840,
11213,
288,
12314,
275,
715,
288,
2059,
267,
340,
1033,
357,
14,
89,
665,
378,
26,
288,
655,
5633,
1500,
59,
16,
1055,
25792,
16537,
14,
2168,
8,
2782,
9,
288,
2455,
14,
27495,
14,
2168,
8,
2782,
9,
272,
367,
1033,
357,
315,
769,
8,
6147,
14,
25792,
16537,
304,
267,
1033,
357,
14,
89,
847,
1926,
627,
4487,
267,
367,
655,
69,
1662,
315,
769,
8,
287,
5633,
1500,
304,
288,
340,
1033,
357,
14,
20798,
8,
6349,
1662,
304,
355,
2455,
14,
27495,
14,
2168,
8,
6349,
1662,
9,
355,
655,
5633,
1500,
14,
2168,
8,
6349,
1662,
9,
355,
12516,
14,
324,
7211,
8,
6349,
1662,
14,
873,
9,
267,
340,
1033,
357,
14,
89,
690,
10574,
26,
288,
7748,
14,
25792,
16537,
14,
2168,
8,
2782,
9,
288,
2455,
14,
27495,
14,
2168,
8,
2782,
9,
339,
327,
1284,
9219,
272,
340,
440,
655,
5633,
1500,
26,
267,
870,
283,
57,
22050,
644,
615,
11213,
267,
2059,
339,
2455,
14,
3584,
342,
272,
2455,
14,
5485,
342,
272,
336,
14,
16114,
342,
199,
87,
14,
1600,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
3473,
199,
199,
646,
23409,
14,
3806,
199,
504,
2073,
492,
627,
199,
504,
23409,
14,
3806,
492,
790,
199,
504,
23409,
492,
12516,
199,
504,
13856,
18,
68,
492,
627,
199,
199,
533,
25610,
30185,
8,
30185,
304,
272,
330,
348,
16537,
275,
942,
272,
347,
1678,
8,
277,
12,
4487,
304,
267,
291,
14,
88,
847,
334,
19553,
59,
498,
14,
12811,
61,
446,
18716,
59,
498,
14,
9894,
566,
627,
1926,
627,
4487,
267,
340,
291,
14,
3039,
665,
378,
26,
291,
14,
3039,
275,
378,
267,
340,
291,
14,
1019,
690,
336,
14,
2063,
26,
291,
14,
1019,
275,
336,
14,
2063,
267,
340,
291,
14,
3282,
459,
329,
581,
2565,
288,
291,
14,
3282,
459,
329,
581,
418,
275,
1390,
8,
16,
12,
291,
14,
3282,
459,
329,
581,
418,
446,
4487,
9,
267,
340,
18716,
59,
498,
14,
11658,
2189,
288,
340,
440,
291,
14,
3282,
459,
329,
581,
2565,
355,
291,
14,
3282,
459,
329,
581,
418,
275,
413,
355,
1033,
357,
275,
8360,
752,
14,
504,
63,
1569,
8,
16,
12,
378,
12,
519,
459,
6147,
13,
20520,
1105,
355,
1033,
357,
14,
8523,
8305,
275,
291,
14,
8523,
2119,
355,
2455,
14,
27495,
14,
740,
8,
2782,
9,
355,
291,
14,
25792,
16537,
14,
740,
8,
2782,
9,
199,
199,
533,
662,
685,
1662,
30185,
8,
30185,
304,
272,
330,
348,
16537,
275,
942,
272,
347,
1678,
8,
277,
12,
4487,
304,
267,
291,
14,
88,
847,
291,
14,
3282,
459,
8373,
418,
627,
4487,
267,
340,
291,
14,
1019,
690,
336,
14,
2063,
26,
288,
291,
14,
1019,
275,
336,
14,
2063,
288,
291,
14,
3282,
459,
8373,
418,
9000,
446,
17,
267,
340,
291,
14,
88,
665,
378,
26,
288,
291,
14,
88,
275,
378,
288,
291,
14,
3282,
459,
8373,
418,
9000,
446,
17,
267,
340,
440,
291,
14,
3282,
459,
329,
581,
2565,
288,
291,
14,
3282,
459,
329,
581,
418,
275,
959,
288,
1033,
357,
275,
8360,
752,
14,
504,
63,
1569,
8,
16,
12,
378,
12,
519,
459,
6349,
1662,
13,
20520,
17,
1105,
288,
1033,
357,
14,
8523,
2119,
275,
291,
14,
8523,
8305,
288,
2455,
14,
27495,
14,
740,
8,
2782,
9,
288,
291,
14,
25792,
16537,
14,
740,
8,
2782,
9,
267,
587,
26,
288,
291,
14,
3282,
459,
329,
581,
418,
275,
1390,
8,
16,
12,
291,
14,
3282,
459,
329,
581,
418,
446,
4487,
9,
199,
199,
87,
275,
23409,
14,
3806,
14,
4301,
8,
2063,
29,
7736,
12,
4569,
29,
7736,
9,
199,
87,
14,
409,
63,
12730,
63,
10544,
342,
199,
9597,
14,
409,
63,
24709,
63,
3097,
8,
1216,
9,
199,
199,
3,
2248,
314,
2341,
436,
9590,
436,
663,
1536,
314,
2455,
199,
3475,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
82,
275,
7337,
14,
912,
8,
736,
14,
515,
14,
904,
8,
3475,
12,
283,
5350,
669,
83,
14,
1652,
1333,
199,
6147,
275,
25610,
30185,
14,
504,
63,
1569,
8,
16,
12,
378,
12,
519,
459,
6147,
995,
4382,
29,
807,
8,
329,
581,
29,
16,
430,
199,
9597,
14,
7211,
8,
6147,
14,
873,
9,
199,
1345,
275,
19005,
2768,
14,
504,
63,
3806,
8,
87,
12,
28020,
29,
87,
14,
2063,
15,
18,
12,
289,
89,
29,
87,
14,
3333,
15,
18,
12,
272,
25328,
1524,
6147,
566,
199,
199,
10957,
275,
756,
199,
287,
5633,
1500,
275,
359,
272,
662,
685,
1662,
30185,
14,
504,
63,
1569,
8,
1960,
12,
8290,
12,
519,
459,
6349,
1662,
17,
995,
267,
4382,
3713,
8373,
356,
14711,
12,
283,
329,
581,
356,
378,
1552,
199,
61,
199,
509,
655,
69,
1662,
315,
655,
5633,
1500,
26,
272,
2455,
14,
27495,
14,
740,
8,
6349,
1662,
9,
272,
12516,
14,
7211,
8,
6349,
1662,
14,
873,
9,
199,
199,
19553,
275,
790,
14,
1197,
2223,
2461,
342,
199,
87,
14,
5335,
63,
5586,
8,
19553,
9,
199,
199,
6710,
440,
334,
87,
14,
1989,
63,
2224,
503,
12314,
304,
272,
4487,
275,
12516,
14,
8284,
342,
272,
336,
14,
6052,
63,
4368,
342,
339,
327,
25061,
15212,
272,
367,
1033,
357,
315,
769,
8,
287,
5633,
1500,
59,
16,
1055,
25792,
16537,
304,
267,
1033,
357,
14,
89,
4862,
1926,
627,
4487,
267,
340,
1033,
357,
14,
20798,
8,
6147,
304,
288,
870,
283,
57,
22050,
3412,
840,
11213,
288,
12314,
275,
715,
288,
2059,
267,
340,
1033,
357,
14,
89,
665,
378,
26,
288,
655,
5633,
1500,
59,
16,
1055,
25792,
16537,
14,
2168,
8,
2782,
9,
288,
2455,
14,
27495,
14,
2168,
8,
2782,
9,
272,
367,
1033,
357,
315,
769,
8,
6147,
14,
25792,
16537,
304,
267,
1033,
357,
14,
89,
847,
1926,
627,
4487,
267,
367,
655,
69,
1662,
315,
769,
8,
287,
5633,
1500,
304,
288,
340,
1033,
357,
14,
20798,
8,
6349,
1662,
304,
355,
2455,
14,
27495,
14,
2168,
8,
6349,
1662,
9,
355,
655,
5633,
1500,
14,
2168,
8,
6349,
1662,
9,
355,
12516,
14,
324,
7211,
8,
6349,
1662,
14,
873,
9,
267,
340,
1033,
357,
14,
89,
690,
10574,
26,
288,
7748,
14,
25792,
16537,
14,
2168,
8,
2782,
9,
288,
2455,
14,
27495,
14,
2168,
8,
2782,
9,
339,
327,
1284,
9219,
272,
340,
440,
655,
5633,
1500,
26,
267,
870,
283,
57,
22050,
644,
615,
11213,
267,
2059,
339,
2455,
14,
3584,
342,
272,
2455,
14,
5485,
342,
272,
336,
14,
16114,
342,
199,
87,
14,
1600,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kfox1111/horizon
|
openstack_dashboard/dashboards/project/instances/tests.py
|
8
|
195767
|
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# 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 json
import sys
from django.conf import settings
from django.core.urlresolvers import reverse
from django.forms import widgets
from django import http
import django.test
from django.utils.datastructures import SortedDict
from django.utils import encoding
from django.utils.http import urlencode
from mox import IgnoreArg # noqa
from mox import IsA # noqa
from horizon import exceptions
from horizon import forms
from horizon.workflows import views
from openstack_dashboard import api
from openstack_dashboard.api import cinder
from openstack_dashboard.dashboards.project.instances import console
from openstack_dashboard.dashboards.project.instances import tables
from openstack_dashboard.dashboards.project.instances import tabs
from openstack_dashboard.dashboards.project.instances import workflows
from openstack_dashboard.test import helpers
from openstack_dashboard.usage import quotas
INDEX_URL = reverse('horizon:project:instances:index')
SEC_GROUP_ROLE_PREFIX = \
workflows.update_instance.INSTANCE_SEC_GROUP_SLUG + "_role_"
AVAILABLE = api.cinder.VOLUME_STATE_AVAILABLE
VOLUME_SEARCH_OPTS = dict(status=AVAILABLE, bootable=1)
SNAPSHOT_SEARCH_OPTS = dict(status=AVAILABLE)
class InstanceTests(helpers.TestCase):
@helpers.create_stubs({
api.nova: (
'flavor_list',
'server_list',
'tenant_absolute_limits',
'extension_supported',
),
api.glance: ('image_list_detailed',),
api.network: (
'floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',
),
})
def _get_index(self):
servers = self.servers.list()
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
return self.client.get(INDEX_URL)
def test_index(self):
res = self._get_index()
self.assertTemplateUsed(res,
'project/instances/index.html')
instances = res.context['instances_table'].data
self.assertItemsEqual(instances, self.servers.list())
self.assertNotContains(res, "Launch Instance (Quota exceeded)")
@helpers.create_stubs({api.nova: ('server_list',
'tenant_absolute_limits',)})
def test_index_server_list_exception(self):
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndRaise(self.exceptions.nova)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'project/instances/index.html')
self.assertEqual(len(res.context['instances_table'].data), 0)
self.assertMessageCount(res, error=1)
@helpers.create_stubs({
api.nova: ('flavor_list', 'server_list', 'flavor_get',
'tenant_absolute_limits', 'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',),
})
def test_index_flavor_list_exception(self):
servers = self.servers.list()
flavors = self.flavors.list()
full_flavors = SortedDict([(f.id, f) for f in flavors])
search_opts = {'marker': None, 'paginate': True}
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndRaise(self.exceptions.nova)
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
for server in servers:
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \
AndReturn(full_flavors[server.flavor["id"]])
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'project/instances/index.html')
instances = res.context['instances_table'].data
self.assertItemsEqual(instances, self.servers.list())
@helpers.create_stubs({
api.nova: ('flavor_list', 'server_list', 'tenant_absolute_limits',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',),
})
def test_index_with_instance_booted_from_volume(self):
volume_server = self.servers.first()
volume_server.image = ""
volume_server.image_name = "(not found)"
servers = self.servers.list()
servers[0] = volume_server
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'project/instances/index.html')
instances = res.context['instances_table'].data
self.assertEqual(len(instances), len(servers))
self.assertContains(res, "(not found)")
def test_index_with_console_link(self):
res = self._get_index()
instances_table = res.context['instances_table']
instances = res.context['instances_table'].data
console_link_rendered = False
for instance in instances:
for action in instances_table.get_row_actions(instance):
if isinstance(action, tables.ConsoleLink):
console_link_rendered = True
break
if console_link_rendered:
break
self.assertTrue(console_link_rendered)
@django.test.utils.override_settings(CONSOLE_TYPE=None)
def test_index_without_console_link(self):
res = self._get_index()
instances_table = res.context['instances_table']
instances = res.context['instances_table'].data
for instance in instances:
for action in instances_table.get_row_actions(instance):
self.assertNotIsInstance(action, tables.ConsoleLink)
@helpers.create_stubs({api.nova: ('server_list',
'flavor_list',
'server_delete',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_terminate_instance(self):
servers = self.servers.list()
server = servers[0]
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
api.nova.server_delete(IsA(http.HttpRequest), server.id)
self.mox.ReplayAll()
formData = {'action': 'instances__terminate__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_list',
'flavor_list',
'server_delete',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_terminate_instance_exception(self):
servers = self.servers.list()
server = servers[0]
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
api.nova.server_delete(IsA(http.HttpRequest), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__terminate__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_pause',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_pause_instance(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_pause(IsA(http.HttpRequest), server.id)
self.mox.ReplayAll()
formData = {'action': 'instances__pause__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_pause',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_pause_instance_exception(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_pause(IsA(http.HttpRequest), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__pause__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_unpause',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_unpause_instance(self):
servers = self.servers.list()
server = servers[0]
server.status = "PAUSED"
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_unpause(IsA(http.HttpRequest), server.id)
self.mox.ReplayAll()
formData = {'action': 'instances__pause__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_unpause',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_unpause_instance_exception(self):
servers = self.servers.list()
server = servers[0]
server.status = "PAUSED"
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_unpause(IsA(http.HttpRequest), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__pause__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_reboot',
'server_list',
'flavor_list',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_reboot_instance(self):
servers = self.servers.list()
server = servers[0]
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_reboot(IsA(http.HttpRequest), server.id,
soft_reboot=False)
self.mox.ReplayAll()
formData = {'action': 'instances__reboot__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_reboot',
'server_list',
'flavor_list',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_reboot_instance_exception(self):
servers = self.servers.list()
server = servers[0]
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_reboot(IsA(http.HttpRequest), server.id,
soft_reboot=False) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__reboot__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_reboot',
'server_list',
'flavor_list',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_soft_reboot_instance(self):
servers = self.servers.list()
server = servers[0]
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_reboot(IsA(http.HttpRequest), server.id,
soft_reboot=True)
self.mox.ReplayAll()
formData = {'action': 'instances__soft_reboot__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_suspend',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_suspend_instance(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_suspend(IsA(http.HttpRequest), unicode(server.id))
self.mox.ReplayAll()
formData = {'action': 'instances__suspend__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_suspend',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_suspend_instance_exception(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_suspend(IsA(http.HttpRequest), unicode(server.id)) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__suspend__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_resume',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_resume_instance(self):
servers = self.servers.list()
server = servers[0]
server.status = "SUSPENDED"
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_resume(IsA(http.HttpRequest), unicode(server.id))
self.mox.ReplayAll()
formData = {'action': 'instances__suspend__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_resume',
'server_list',
'flavor_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_resume_instance_exception(self):
servers = self.servers.list()
server = servers[0]
server.status = "SUSPENDED"
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_resume(IsA(http.HttpRequest),
unicode(server.id)) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__suspend__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_lock',
'server_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_lock_instance(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions', IsA(
http.HttpRequest)).MultipleTimes().AndReturn(True)
api.glance.image_list_detailed(IgnoreArg()).AndReturn((
self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(
IsA(http.HttpRequest),
search_opts=search_opts).AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_lock(IsA(http.HttpRequest), server.id)
self.mox.ReplayAll()
formData = {'action': 'instances__lock__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_lock',
'server_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_lock_instance_exception(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions', IsA(
http.HttpRequest)).MultipleTimes().AndReturn(True)
api.glance.image_list_detailed(IgnoreArg()).AndReturn((
self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(
IsA(http.HttpRequest),
search_opts=search_opts).AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_lock(IsA(http.HttpRequest), server.id).AndRaise(
self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__lock__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_unlock',
'server_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_unlock_instance(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions', IsA(
http.HttpRequest)).MultipleTimes().AndReturn(True)
api.glance.image_list_detailed(IgnoreArg()).AndReturn((
self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(
IsA(http.HttpRequest),
search_opts=search_opts).AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_unlock(IsA(http.HttpRequest), server.id)
self.mox.ReplayAll()
formData = {'action': 'instances__unlock__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_unlock',
'server_list',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_unlock_instance_exception(self):
servers = self.servers.list()
server = servers[0]
api.nova.extension_supported('AdminActions', IsA(
http.HttpRequest)).MultipleTimes().AndReturn(True)
api.glance.image_list_detailed(IgnoreArg()).AndReturn((
self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(
IsA(http.HttpRequest),
search_opts=search_opts).AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.server_unlock(IsA(http.HttpRequest), server.id).AndRaise(
self.exceptions.nova)
self.mox.ReplayAll()
formData = {'action': 'instances__unlock__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({
api.nova: (
"server_get",
"instance_volumes_list",
"flavor_get",
"extension_supported"
),
api.network: (
"server_security_groups",
"servers_update_addresses",
"floating_ip_simple_associate_supported",
"floating_ip_supported"
)
})
def _get_instance_details(self, server, qs=None,
flavor_return=None, volumes_return=None,
security_groups_return=None,
flavor_exception=False):
url = reverse('horizon:project:instances:detail', args=[server.id])
if qs:
url += qs
if flavor_return is None:
flavor_return = self.flavors.first()
if volumes_return is None:
volumes_return = []
if security_groups_return is None:
security_groups_return = self.security_groups.list()
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.network.servers_update_addresses(IsA(http.HttpRequest),
IgnoreArg())
api.nova.instance_volumes_list(IsA(http.HttpRequest),
server.id).AndReturn(volumes_return)
if flavor_exception:
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor['id']) \
.AndRaise(self.exceptions.nova)
else:
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor['id']) \
.AndReturn(flavor_return)
api.network.server_security_groups(IsA(http.HttpRequest), server.id) \
.AndReturn(security_groups_return)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
return self.client.get(url)
def test_instance_details_volumes(self):
server = self.servers.first()
volumes = [self.volumes.list()[1]]
security_groups = self.security_groups.list()
res = self._get_instance_details(
server, volumes_return=volumes,
security_groups_return=security_groups)
self.assertItemsEqual(res.context['instance'].volumes, volumes)
self.assertItemsEqual(res.context['instance'].volumes, volumes)
def test_instance_details_volume_sorting(self):
server = self.servers.first()
volumes = self.volumes.list()[1:3]
security_groups = self.security_groups.list()
res = self._get_instance_details(
server, volumes_return=volumes,
security_groups_return=security_groups)
self.assertItemsEqual(res.context['instance'].volumes, volumes)
self.assertEqual(res.context['instance'].volumes[0].device,
"/dev/hda")
self.assertEqual(res.context['instance'].volumes[1].device,
"/dev/hdk")
def test_instance_details_metadata(self):
server = self.servers.first()
tg = tabs.InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("overview").get_id())
res = self._get_instance_details(server, qs)
self.assertContains(res, "<dd>keyName</dd>", 1)
self.assertContains(res, "<dt>someMetaLabel</dt>", 1)
self.assertContains(res, "<dd>someMetaData</dd>", 1)
self.assertContains(res, "<dt>some<b>html</b>label</dt>",
1)
self.assertContains(res, "<dd><!--</dd>", 1)
self.assertContains(res, "<dt>empty</dt>", 1)
# TODO(david-lyle): uncomment when fixed with Django 1.6
# self.assertContains(res, "<dd><em>N/A</em></dd>", 1)
def test_instance_details_fault(self):
server = self.servers.first()
server.status = 'ERROR'
server.fault = {"message": "NoValidHost",
"code": 500,
"details": "No valid host was found. \n "
"File \"/mnt/stack/nova/nova/"
"scheduler/filter_scheduler.py\", "
"line 105, in schedule_run_instance\n "
"raise exception.NoValidHost"
"(reason=\"\")\n",
"created": "2013-10-07T00:08:32Z"}
res = self._get_instance_details(server)
self.assertItemsEqual(res.context['instance'].fault, server.fault)
def test_instance_details_console_tab(self):
server = self.servers.first()
tg = tabs.InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("console").get_id())
res = self._get_instance_details(server, qs)
self.assertIn(tabs.ConsoleTab, res.context_data['tab_group'].tabs)
self.assertTemplateUsed(res,
'project/instances/_detail_console.html')
console_tab_rendered = False
for tab in res.context_data['tab_group'].get_loaded_tabs():
if isinstance(tab, tabs.ConsoleTab):
console_tab_rendered = True
break
self.assertTrue(console_tab_rendered)
@django.test.utils.override_settings(CONSOLE_TYPE=None)
def test_instance_details_console_tab_deactivated(self):
server = self.servers.first()
tg = tabs.InstanceDetailTabs(self.request, instance=server)
self.assertIsNone(tg.get_tab("console"))
res = self._get_instance_details(server)
self.assertTemplateNotUsed(res,
'project/instances/_detail_console.html')
for tab in res.context_data['tab_group'].get_loaded_tabs():
self.assertNotIsInstance(tab, tabs.ConsoleTab)
@helpers.create_stubs({api.nova: ('server_get',)})
def test_instance_details_exception(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:detail',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ("server_get",)})
def test_instance_details_unauthorized(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id)\
.AndRaise(self.exceptions.nova_unauthorized)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:detail',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_instance_details_flavor_not_found(self):
server = self.servers.first()
res = self._get_instance_details(server, flavor_exception=True)
self.assertTemplateUsed(res,
'project/instances/_detail_overview.html')
self.assertContains(res, "Not available")
@helpers.create_stubs({api.nova: ('server_console_output',)})
def test_instance_log(self):
server = self.servers.first()
CONSOLE_OUTPUT = 'output'
api.nova.server_console_output(IsA(http.HttpRequest),
server.id, tail_length=None) \
.AndReturn(CONSOLE_OUTPUT)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:console',
args=[server.id])
tg = tabs.InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("log").get_id())
res = self.client.get(url + qs)
self.assertNoMessages()
self.assertIsInstance(res, http.HttpResponse)
self.assertContains(res, CONSOLE_OUTPUT)
@helpers.create_stubs({api.nova: ('server_console_output',)})
def test_instance_log_exception(self):
server = self.servers.first()
api.nova.server_console_output(IsA(http.HttpRequest),
server.id, tail_length=None) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:console',
args=[server.id])
tg = tabs.InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("log").get_id())
res = self.client.get(url + qs)
self.assertContains(res, "Unable to get log for")
def test_instance_log_invalid_input(self):
server = self.servers.first()
url = reverse('horizon:project:instances:console',
args=[server.id])
tg = tabs.InstanceDetailTabs(self.request, instance=server)
for length in ["-5", "x"]:
qs = "?%s=%s&length=%s" % (tg.param_name,
tg.get_tab("log").get_id(),
length)
res = self.client.get(url + qs)
self.assertContains(res, "Unable to get log for")
def test_instance_vnc(self):
server = self.servers.first()
CONSOLE_OUTPUT = '/vncserver'
CONSOLE_TITLE = '&title=%s(%s)' % (server.name, server.id)
CONSOLE_URL = CONSOLE_OUTPUT + CONSOLE_TITLE
console_mock = self.mox.CreateMock(api.nova.VNCConsole)
console_mock.url = CONSOLE_OUTPUT
self.mox.StubOutWithMock(api.nova, 'server_get')
self.mox.StubOutWithMock(console, 'get_console')
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
console.get_console(IgnoreArg(), 'VNC', server) \
.AndReturn(('VNC', CONSOLE_URL))
self.mox.ReplayAll()
url = reverse('horizon:project:instances:vnc',
args=[server.id])
res = self.client.get(url)
redirect = CONSOLE_URL
self.assertRedirectsNoFollow(res, redirect)
def test_instance_vnc_error(self):
server = self.servers.first()
self.mox.StubOutWithMock(api.nova, 'server_get')
self.mox.StubOutWithMock(console, 'get_console')
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
console.get_console(IgnoreArg(), 'VNC', server) \
.AndRaise(exceptions.NotAvailable('console'))
self.mox.ReplayAll()
url = reverse('horizon:project:instances:vnc',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_instance_spice(self):
server = self.servers.first()
CONSOLE_OUTPUT = '/spiceserver'
CONSOLE_TITLE = '&title=%s(%s)' % (server.name, server.id)
CONSOLE_URL = CONSOLE_OUTPUT + CONSOLE_TITLE
console_mock = self.mox.CreateMock(api.nova.SPICEConsole)
console_mock.url = CONSOLE_OUTPUT
self.mox.StubOutWithMock(console, 'get_console')
self.mox.StubOutWithMock(api.nova, 'server_get')
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
console.get_console(IgnoreArg(), 'SPICE', server) \
.AndReturn(('SPICE', CONSOLE_URL))
self.mox.ReplayAll()
url = reverse('horizon:project:instances:spice',
args=[server.id])
res = self.client.get(url)
redirect = CONSOLE_URL
self.assertRedirectsNoFollow(res, redirect)
def test_instance_spice_exception(self):
server = self.servers.first()
self.mox.StubOutWithMock(console, 'get_console')
self.mox.StubOutWithMock(api.nova, 'server_get')
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
console.get_console(IgnoreArg(), 'SPICE', server) \
.AndRaise(exceptions.NotAvailable('console'))
self.mox.ReplayAll()
url = reverse('horizon:project:instances:spice',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_instance_rdp(self):
server = self.servers.first()
CONSOLE_OUTPUT = '/rdpserver'
CONSOLE_TITLE = '&title=%s(%s)' % (server.name, server.id)
CONSOLE_URL = CONSOLE_OUTPUT + CONSOLE_TITLE
console_mock = self.mox.CreateMock(api.nova.RDPConsole)
console_mock.url = CONSOLE_OUTPUT
self.mox.StubOutWithMock(console, 'get_console')
self.mox.StubOutWithMock(api.nova, 'server_get')
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
console.get_console(IgnoreArg(), 'RDP', server) \
.AndReturn(('RDP', CONSOLE_URL))
self.mox.ReplayAll()
url = reverse('horizon:project:instances:rdp',
args=[server.id])
res = self.client.get(url)
redirect = CONSOLE_URL
self.assertRedirectsNoFollow(res, redirect)
def test_instance_rdp_exception(self):
server = self.servers.first()
self.mox.StubOutWithMock(console, 'get_console')
self.mox.StubOutWithMock(api.nova, 'server_get')
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
console.get_console(IgnoreArg(), 'RDP', server) \
.AndRaise(exceptions.NotAvailable('console'))
self.mox.ReplayAll()
url = reverse('horizon:project:instances:rdp',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_get',
'snapshot_create',
'server_list',
'flavor_list',
'server_delete'),
api.glance: ('image_list_detailed',)})
def test_create_instance_snapshot(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.nova.snapshot_create(IsA(http.HttpRequest),
server.id,
"snapshot1").AndReturn(self.snapshots.first())
api.glance.image_list_detailed(IsA(http.HttpRequest),
marker=None).AndReturn([[], False,
False])
self.mox.ReplayAll()
formData = {'instance_id': server.id,
'method': 'CreateSnapshot',
'name': 'snapshot1'}
url = reverse('horizon:project:images:snapshots:create',
args=[server.id])
redir_url = reverse('horizon:project:images:index')
res = self.client.post(url, formData)
self.assertRedirects(res, redir_url)
@django.test.utils.override_settings(
OPENSTACK_ENABLE_PASSWORD_RETRIEVE=False)
def test_instances_index_retrieve_password_action_disabled(self):
self. _test_instances_index_retrieve_password_action()
@django.test.utils.override_settings(
OPENSTACK_ENABLE_PASSWORD_RETRIEVE=True)
def test_instances_index_retrieve_password_action_enabled(self):
self._test_instances_index_retrieve_password_action()
@helpers.create_stubs({
api.nova: ('flavor_list', 'server_list', 'tenant_absolute_limits',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',),
})
def _test_instances_index_retrieve_password_action(self):
servers = self.servers.list()
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:index')
res = self.client.get(url)
for server in servers:
_action_id = ''.join(["instances__row_",
server.id,
"__action_decryptpassword"])
if settings.OPENSTACK_ENABLE_PASSWORD_RETRIEVE and \
server.status == "ACTIVE" and \
server.key_name is not None:
self.assertContains(res, _action_id)
else:
self.assertNotContains(res, _action_id)
@helpers.create_stubs({api.nova: ('get_password',)})
def test_decrypt_instance_password(self):
server = self.servers.first()
enc_password = "azerty"
api.nova.get_password(IsA(http.HttpRequest), server.id)\
.AndReturn(enc_password)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:decryptpassword',
args=[server.id,
server.key_name])
res = self.client.get(url)
self.assertTemplateUsed(res, 'project/instances/decryptpassword.html')
@helpers.create_stubs({api.nova: ('get_password',)})
def test_decrypt_instance_get_exception(self):
server = self.servers.first()
keypair = self.keypairs.first()
api.nova.get_password(IsA(http.HttpRequest), server.id)\
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:decryptpassword',
args=[server.id,
keypair])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
instance_update_get_stubs = {
api.nova: ('server_get',),
api.network: ('security_group_list',
'server_security_groups',)}
@helpers.create_stubs(instance_update_get_stubs)
def test_instance_update_get(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn([])
api.network.server_security_groups(IsA(http.HttpRequest),
server.id).AndReturn([])
self.mox.ReplayAll()
url = reverse('horizon:project:instances:update', args=[server.id])
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
@helpers.create_stubs(instance_update_get_stubs)
def test_instance_update_get_server_get_exception(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:update',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
def _instance_update_post(self, server_id, server_name, secgroups):
default_role_field_name = 'default_' + \
workflows.update_instance.INSTANCE_SEC_GROUP_SLUG + '_role'
formData = {'name': server_name,
default_role_field_name: 'member',
SEC_GROUP_ROLE_PREFIX + 'member': secgroups}
url = reverse('horizon:project:instances:update',
args=[server_id])
return self.client.post(url, formData)
instance_update_post_stubs = {
api.nova: ('server_get', 'server_update'),
api.network: ('security_group_list',
'server_security_groups',
'server_update_security_groups')}
@helpers.create_stubs(instance_update_post_stubs)
def test_instance_update_post(self):
server = self.servers.first()
secgroups = self.security_groups.list()[:3]
server_groups = [secgroups[0], secgroups[1]]
wanted_groups = [secgroups[1].id, secgroups[2].id]
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(secgroups)
api.network.server_security_groups(IsA(http.HttpRequest),
server.id).AndReturn(server_groups)
api.nova.server_update(IsA(http.HttpRequest),
server.id,
server.name).AndReturn(server)
api.network.server_update_security_groups(IsA(http.HttpRequest),
server.id,
wanted_groups)
self.mox.ReplayAll()
res = self._instance_update_post(server.id, server.name, wanted_groups)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs(instance_update_post_stubs)
def test_instance_update_post_api_exception(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn([])
api.network.server_security_groups(IsA(http.HttpRequest),
server.id).AndReturn([])
api.nova.server_update(IsA(http.HttpRequest), server.id, server.name) \
.AndRaise(self.exceptions.nova)
api.network.server_update_security_groups(
IsA(http.HttpRequest), server.id, [])
self.mox.ReplayAll()
res = self._instance_update_post(server.id, server.name, [])
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs(instance_update_post_stubs)
def test_instance_update_post_secgroup_api_exception(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id).AndReturn(server)
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn([])
api.network.server_security_groups(IsA(http.HttpRequest),
server.id).AndReturn([])
api.nova.server_update(IsA(http.HttpRequest),
server.id,
server.name).AndReturn(server)
api.network.server_update_security_groups(
IsA(http.HttpRequest),
server.id, []).AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
res = self._instance_update_post(server.id, server.name, [])
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_snapshot_list',
'volume_list',),
api.neutron: ('network_list',
'profile_list',),
api.glance: ('image_list_detailed',)})
def test_launch_instance_get(self,
expect_password_fields=True,
block_device_mapping_v2=True,
custom_flavor_sort=None,
only_one_network=False,
disk_config=True,
config_drive=True,
test_with_profile=False):
image = self.images.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(block_device_mapping_v2)
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
if only_one_network:
api.neutron.network_list(IsA(http.HttpRequest),
shared=True).AndReturn([])
else:
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(disk_config)
api.nova.extension_supported(
'ConfigDrive', IsA(http.HttpRequest)).AndReturn(config_drive)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
.AndReturn(self.limits['absolute'])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
self.mox.ReplayAll()
url = reverse('horizon:project:instances:launch')
params = urlencode({"source_type": "image_id",
"source_id": image.id})
res = self.client.get("%s?%s" % (url, params))
workflow = res.context['workflow']
self.assertTemplateUsed(res, views.WorkflowView.template_name)
self.assertEqual(res.context['workflow'].name,
workflows.LaunchInstance.name)
step = workflow.get_step("setinstancedetailsaction")
self.assertEqual(step.action.initial['image_id'], image.id)
self.assertQuerysetEqual(
workflow.steps,
['<SetInstanceDetails: setinstancedetailsaction>',
'<SetAccessControls: setaccesscontrolsaction>',
'<SetNetwork: setnetworkaction>',
'<PostCreationStep: customizeaction>',
'<SetAdvanced: setadvancedaction>'])
if custom_flavor_sort == 'id':
# Reverse sorted by id
sorted_flavors = (
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'm1.metadata'),
('dddddddd-dddd-dddd-dddd-dddddddddddd', 'm1.secret'),
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'm1.massive'),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'm1.tiny'),
)
elif custom_flavor_sort == 'name':
sorted_flavors = (
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'm1.massive'),
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'm1.metadata'),
('dddddddd-dddd-dddd-dddd-dddddddddddd', 'm1.secret'),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'm1.tiny'),
)
elif custom_flavor_sort == helpers.my_custom_sort:
sorted_flavors = (
('dddddddd-dddd-dddd-dddd-dddddddddddd', 'm1.secret'),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'm1.tiny'),
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'm1.massive'),
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'm1.metadata'),
)
else:
# Default - sorted by RAM
sorted_flavors = (
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'm1.tiny'),
('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'm1.massive'),
('dddddddd-dddd-dddd-dddd-dddddddddddd', 'm1.secret'),
('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'm1.metadata'),
)
select_options = '\n'.join([
'<option value="%s">%s</option>' % (f[0], f[1])
for f in sorted_flavors
])
self.assertContains(res, select_options)
password_field_label = 'Admin Pass'
if expect_password_fields:
self.assertContains(res, password_field_label)
else:
self.assertNotContains(res, password_field_label)
boot_from_image_field_label = 'Boot from image (creates a new volume)'
if block_device_mapping_v2:
self.assertContains(res, boot_from_image_field_label)
else:
self.assertNotContains(res, boot_from_image_field_label)
checked_label = '<label for="id_network_0"><input checked="checked"'
if only_one_network:
self.assertContains(res, checked_label)
else:
self.assertNotContains(res, checked_label)
disk_config_field_label = 'Disk Partition'
if disk_config:
self.assertContains(res, disk_config_field_label)
else:
self.assertNotContains(res, disk_config_field_label)
config_drive_field_label = 'Configuration Drive'
if config_drive:
self.assertContains(res, config_drive_field_label)
else:
self.assertNotContains(res, config_drive_field_label)
@django.test.utils.override_settings(
OPENSTACK_HYPERVISOR_FEATURES={'can_set_password': False})
def test_launch_instance_get_without_password(self):
self.test_launch_instance_get(expect_password_fields=False)
def test_launch_instance_get_no_block_device_mapping_v2_supported(self):
self.test_launch_instance_get(block_device_mapping_v2=False)
def test_launch_instance_get_no_disk_config_supported(self):
self.test_launch_instance_get(disk_config=False)
def test_launch_instance_get_no_config_drive_supported(self):
self.test_launch_instance_get(config_drive=False)
@django.test.utils.override_settings(
CREATE_INSTANCE_FLAVOR_SORT={
'key': 'id',
'reverse': True,
})
def test_launch_instance_get_custom_flavor_sort_by_id(self):
self.test_launch_instance_get(custom_flavor_sort='id')
@django.test.utils.override_settings(
CREATE_INSTANCE_FLAVOR_SORT={
'key': 'name',
'reverse': False,
})
def test_launch_instance_get_custom_flavor_sort_by_name(self):
self.test_launch_instance_get(custom_flavor_sort='name')
@django.test.utils.override_settings(
CREATE_INSTANCE_FLAVOR_SORT={
'key': helpers.my_custom_sort,
'reverse': False,
})
def test_launch_instance_get_custom_flavor_sort_by_callable(self):
self.test_launch_instance_get(
custom_flavor_sort=helpers.my_custom_sort)
@django.test.utils.override_settings(
CREATE_INSTANCE_FLAVOR_SORT={
'key': 'no_such_column',
'reverse': False,
})
def test_launch_instance_get_custom_flavor_sort_by_missing_column(self):
self.test_launch_instance_get(custom_flavor_sort='no_such_column')
def test_launch_instance_get_with_only_one_network(self):
self.test_launch_instance_get(only_one_network=True)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_instance_get_with_profile(self):
self.test_launch_instance_get(test_with_profile=True)
@helpers.create_stubs({api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_snapshot_list',
'volume_list',),
api.neutron: ('network_list',
'profile_list',),
api.glance: ('image_list_detailed',)})
def test_launch_instance_get_bootable_volumes(self,
block_device_mapping_v2=True,
only_one_network=False,
disk_config=True,
config_drive=True,
test_with_profile=False):
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(block_device_mapping_v2)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
if only_one_network:
api.neutron.network_list(IsA(http.HttpRequest),
shared=True).AndReturn([])
else:
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(disk_config)
api.nova.extension_supported(
'ConfigDrive', IsA(http.HttpRequest)).AndReturn(config_drive)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
.AndReturn(self.limits['absolute'])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
self.mox.ReplayAll()
url = reverse('horizon:project:instances:launch')
res = self.client.get(url)
bootable_volumes = [v.id for v in self.volumes.list()
if (v.bootable == 'true' and
v.status == 'available')]
volume_sources = (res.context_data['workflow'].steps[0].
action.fields['volume_id'].choices)
volume_sources_ids = []
for volume in volume_sources:
self.assertTrue(volume[0].split(":vol")[0] in bootable_volumes or
volume[0] == '')
if volume[0] != '':
volume_sources_ids.append(volume[0].split(":vol")[0])
for volume in bootable_volumes:
self.assertTrue(volume in volume_sources_ids)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_instance_get_bootable_volumes_with_profile(self):
self.test_launch_instance_get_bootable_volumes(test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'server_create',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_instance_post(self,
disk_config=True,
config_drive=True,
test_with_profile=False,
test_with_multi_nics=False):
flavor = self.flavors.first()
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
nics = [{"net-id": self.networks.first().id, "v4-fixed-ip": ''}]
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
policy_profile_id = self.policy_profiles.first().id
port_one = self.ports.first()
nics = [{"port-id": port_one.id}]
api.neutron.profile_list(
IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.neutron.port_create(IsA(http.HttpRequest),
self.networks.first().id,
policy_profile_id=policy_profile_id) \
.AndReturn(port_one)
if test_with_multi_nics:
port_two = self.ports.get(name="port5")
nics = [{"port-id": port_one.id},
{"port-id": port_two.id}]
# Add a second port to test multiple nics
api.neutron.port_create(IsA(http.HttpRequest),
self.networks.get(name="net4")['id'],
policy_profile_id=policy_profile_id) \
.AndReturn(port_two)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(disk_config)
api.nova.extension_supported(
'ConfigDrive', IsA(http.HttpRequest)).AndReturn(config_drive)
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
if disk_config:
disk_config_value = u'AUTO'
else:
disk_config_value = None
if config_drive:
config_drive_value = True
else:
config_drive_value = None
api.nova.server_create(IsA(http.HttpRequest),
server.name,
image.id,
flavor.id,
keypair.name,
customization_script,
[sec_group.name],
block_device_mapping=None,
block_device_mapping_v2=None,
nics=nics,
availability_zone=avail_zone.zoneName,
instance_count=IsA(int),
admin_pass=u'',
disk_config=disk_config_value,
config_drive=config_drive_value)
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'image_id': image.id,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'availability_zone': avail_zone.zoneName,
'volume_type': '',
'network': self.networks.first().id,
'count': 1}
if disk_config:
form_data['disk_config'] = 'AUTO'
if config_drive:
form_data['config_drive'] = True
if test_with_profile:
form_data['profile'] = self.policy_profiles.first().id
if test_with_multi_nics:
form_data['network'] = [self.networks.first().id,
self.networks.get(name="net4")['id']]
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_launch_instance_post_no_disk_config_supported(self):
self.test_launch_instance_post(disk_config=False)
def test_launch_instance_post_no_config_drive_supported(self):
self.test_launch_instance_post(config_drive=False)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_instance_post_with_profile(self):
self.test_launch_instance_post(test_with_profile=True)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_instance_post_with_profile_and_multi_nics(self):
self.test_launch_instance_post(test_with_profile=True,
test_with_multi_nics=True)
def _test_launch_instance_post_with_profile_and_port_error(
self,
test_with_multi_nics=False,
):
flavor = self.flavors.first()
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(IsA(http.HttpRequest),
filters={'is_public': True,
'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
policy_profiles = self.policy_profiles.list()
policy_profile_id = self.policy_profiles.first().id
port_one = self.ports.first()
api.neutron.profile_list(
IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
if test_with_multi_nics:
api.neutron.port_create(IsA(http.HttpRequest),
self.networks.first().id,
policy_profile_id=policy_profile_id) \
.AndReturn(port_one)
# Add a second port which has the exception to test multiple nics
api.neutron.port_create(IsA(http.HttpRequest),
self.networks.get(name="net4")['id'],
policy_profile_id=policy_profile_id) \
.AndRaise(self.exceptions.neutron)
# Delete the first port
api.neutron.port_delete(IsA(http.HttpRequest),
port_one.id)
else:
api.neutron.port_create(IsA(http.HttpRequest),
self.networks.first().id,
policy_profile_id=policy_profile_id) \
.AndRaise(self.exceptions.neutron)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'image_id': image.id,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'availability_zone': avail_zone.zoneName,
'volume_type': '',
'network': self.networks.first().id,
'count': 1,
'disk_config': 'AUTO',
'config_drive': True,
'profile': self.policy_profiles.first().id}
if test_with_multi_nics:
form_data['network'] = [self.networks.first().id,
self.networks.get(name="net4")['id']]
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create',
'port_delete',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_instance_post_with_profile_and_port_error(self):
self._test_launch_instance_post_with_profile_and_port_error()
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create',
'port_delete',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_lnch_inst_post_w_profile_and_multi_nics_w_port_error(self):
self._test_launch_instance_post_with_profile_and_port_error(
test_with_multi_nics=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'server_create',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_instance_post_boot_from_volume(self,
test_with_profile=False):
flavor = self.flavors.first()
keypair = self.keypairs.first()
server = self.servers.first()
volume = self.volumes.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
device_name = u'vda'
volume_choice = "%s:vol" % volume.id
block_device_mapping = {device_name: u"%s::0" % volume_choice}
nics = [{"net-id": self.networks.first().id, "v4-fixed-ip": ''}]
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
if test_with_profile:
policy_profiles = self.policy_profiles.list()
policy_profile_id = self.policy_profiles.first().id
port = self.ports.first()
api.neutron.profile_list(
IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.neutron.port_create(
IsA(http.HttpRequest),
self.networks.first().id,
policy_profile_id=policy_profile_id).AndReturn(port)
nics = [{"port-id": port.id}]
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.server_create(IsA(http.HttpRequest),
server.name,
'',
flavor.id,
keypair.name,
customization_script,
[sec_group.name],
block_device_mapping=block_device_mapping,
block_device_mapping_v2=None,
nics=nics,
availability_zone=avail_zone.zoneName,
instance_count=IsA(int),
admin_pass=u'',
disk_config=u'AUTO',
config_drive=True)
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'volume_id',
'source_id': volume_choice,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'availability_zone': avail_zone.zoneName,
'volume_size': '1',
'volume_id': volume_choice,
'device_name': device_name,
'network': self.networks.first().id,
'count': 1,
'disk_config': 'AUTO',
'config_drive': True}
if test_with_profile:
form_data['profile'] = self.policy_profiles.first().id
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_instance_post_boot_from_volume_with_profile(self):
self.test_launch_instance_post_boot_from_volume(test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create'),
api.nova: ('server_create',
'extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'tenant_absolute_limits',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_instance_post_no_images_available_boot_from_volume(
self,
test_with_profile=False,
):
flavor = self.flavors.first()
keypair = self.keypairs.first()
server = self.servers.first()
volume = self.volumes.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
device_name = u'vda'
volume_choice = "%s:vol" % volume.id
block_device_mapping = {device_name: u"%s::0" % volume_choice}
nics = [{"net-id": self.networks.first().id, "v4-fixed-ip": ''}]
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
if test_with_profile:
policy_profiles = self.policy_profiles.list()
policy_profile_id = self.policy_profiles.first().id
port = self.ports.first()
api.neutron.profile_list(
IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.neutron.port_create(
IsA(http.HttpRequest),
self.networks.first().id,
policy_profile_id=policy_profile_id).AndReturn(port)
nics = [{"port-id": port.id}]
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.server_create(IsA(http.HttpRequest),
server.name,
'',
flavor.id,
keypair.name,
customization_script,
[sec_group.name],
block_device_mapping=block_device_mapping,
block_device_mapping_v2=None,
nics=nics,
availability_zone=avail_zone.zoneName,
instance_count=IsA(int),
admin_pass=u'',
disk_config='MANUAL',
config_drive=True)
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'volume_id',
# 'image_id': '',
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'availability_zone': avail_zone.zoneName,
'network': self.networks.first().id,
'volume_type': 'volume_id',
'volume_id': volume_choice,
'device_name': device_name,
'count': 1,
'disk_config': 'MANUAL',
'config_drive': True}
if test_with_profile:
form_data['profile'] = self.policy_profiles.first().id
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_lnch_inst_post_no_images_avail_boot_from_vol_with_profile(self):
self.test_launch_instance_post_no_images_available_boot_from_volume(
test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'tenant_absolute_limits',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_instance_post_no_images_available(self,
test_with_profile=False):
flavor = self.flavors.first()
keypair = self.keypairs.first()
server = self.servers.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
api.glance.image_list_detailed(IsA(http.HttpRequest),
filters={'is_public': True,
'status': 'active'}) \
.AndReturn([[], False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'image_id': '',
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'availability_zone': avail_zone.zoneName,
'volume_type': '',
'count': 1}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertFormErrors(res, 1, "You must select an image.")
self.assertTemplateUsed(res, views.WorkflowView.template_name)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_instance_post_no_images_available_with_profile(self):
self.test_launch_instance_post_no_images_available(
test_with_profile=True)
@helpers.create_stubs({
api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'server_create',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_instance_post_boot_from_snapshot(
self,
test_with_profile=False,
):
flavor = self.flavors.first()
keypair = self.keypairs.first()
server = self.servers.first()
avail_zone = self.availability_zones.first()
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IsA(http.HttpRequest),
filters={'is_public': True,
'status': 'active'}) \
.AndReturn([[], False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
self.mox.ReplayAll()
bad_snapshot_id = 'a-bogus-id'
form_data = {'flavor': flavor.id,
'source_type': 'instance_snapshot_id',
'instance_snapshot_id': bad_snapshot_id,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'availability_zone': avail_zone.zoneName,
'network': self.networks.first().id,
'volume_id': '',
'volume_snapshot_id': '',
'image_id': '',
'device_name': 'vda',
'count': 1,
'profile': '',
'customization_script': ''}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertFormErrors(res, 1, "You must select a snapshot.")
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
api.network: ('security_group_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',)})
def test_launch_flavorlist_error(self,
test_with_profile=False):
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndRaise(self.exceptions.nova)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndRaise(self.exceptions.nova)
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
self.mox.ReplayAll()
url = reverse('horizon:project:instances:launch')
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_flavorlist_error_with_profile(self):
self.test_launch_flavorlist_error(test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',
'port_create',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'server_create',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_form_keystone_exception(self,
test_with_profile=False):
flavor = self.flavors.first()
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
nics = [{"net-id": self.networks.first().id, "v4-fixed-ip": ''}]
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE)]
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn(volumes)
api.nova.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
api.nova.keypair_list(IgnoreArg()).AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
policy_profile_id = self.policy_profiles.first().id
port = self.ports.first()
api.neutron.profile_list(
IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.neutron.port_create(
IsA(http.HttpRequest),
self.networks.first().id,
policy_profile_id=policy_profile_id).AndReturn(port)
nics = [{"port-id": port.id}]
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
api.nova.server_create(IsA(http.HttpRequest),
server.name,
image.id,
flavor.id,
keypair.name,
customization_script,
[sec_group.name],
block_device_mapping=None,
block_device_mapping_v2=None,
nics=nics,
availability_zone=avail_zone.zoneName,
instance_count=IsA(int),
admin_pass='password',
disk_config='AUTO',
config_drive=False) \
.AndRaise(self.exceptions.keystone)
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'source_id': image.id,
'volume_size': '1',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_type': '',
'network': self.networks.first().id,
'count': 1,
'admin_pass': 'password',
'confirm_admin_pass': 'password',
'disk_config': 'AUTO',
'config_drive': False}
if test_with_profile:
form_data['profile'] = self.policy_profiles.first().id
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_form_keystone_exception_with_profile(self):
self.test_launch_form_keystone_exception(test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_form_instance_count_error(self,
test_with_profile=False):
flavor = self.flavors.first()
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
volume = self.volumes.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
device_name = u'vda'
volume_choice = "%s:vol" % volume.id
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_type': 'volume_id',
'volume_id': volume_choice,
'device_name': device_name,
'count': 0}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertContains(res, "greater than or equal to 1")
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def _test_launch_form_count_error(self, resource,
avail, test_with_profile=False):
flavor = self.flavors.first()
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
volume = self.volumes.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
device_name = u'vda'
volume_choice = "%s:vol" % volume.id
quota_usages = self.quota_usages.first()
if resource == 'both':
quota_usages['cores']['available'] = avail
quota_usages['ram']['available'] = 512
else:
quota_usages[resource]['available'] = avail
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_type': 'volume_id',
'volume_id': volume_choice,
'device_name': device_name,
'count': 2}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
if resource == 'ram':
msg = ("The following requested resource(s) exceed quota(s): "
"RAM(Available: %s" % avail)
if resource == 'cores':
msg = ("The following requested resource(s) exceed quota(s): "
"Cores(Available: %s" % avail)
if resource == 'both':
msg = ("The following requested resource(s) exceed quota(s): "
"Cores(Available: %(avail)s, Requested: 2), RAM(Available: "
"512, Requested: 1024)" % {'avail': avail})
self.assertContains(res, msg)
def test_launch_form_cores_count_error(self):
self._test_launch_form_count_error('cores', 1, test_with_profile=False)
def test_launch_form_ram_count_error(self):
self._test_launch_form_count_error('ram', 512, test_with_profile=False)
def test_launch_form_ram_cores_count_error(self):
self._test_launch_form_count_error('both', 1, test_with_profile=False)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_form_instance_count_error_with_profile(self):
self.test_launch_form_instance_count_error(test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def _test_launch_form_instance_requirement_error(self, image, flavor,
test_with_profile=False):
keypair = self.keypairs.first()
server = self.servers.first()
volume = self.volumes.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
device_name = u'vda'
volume_choice = "%s:vol" % volume.id
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'image_id',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_type': 'volume_id',
'volume_id': volume_choice,
'device_name': device_name,
'count': 1}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
msg = "The flavor '%s' is too small" % flavor.name
self.assertContains(res, msg)
def test_launch_form_instance_requirement_error_disk(
self,
test_with_profile=False,
):
flavor = self.flavors.first()
image = self.images.first()
image.min_ram = flavor.ram
image.min_disk = flavor.disk + 1
self._test_launch_form_instance_requirement_error(image, flavor,
test_with_profile)
def test_launch_form_instance_requirement_error_ram(
self,
test_with_profile=False,
):
flavor = self.flavors.first()
image = self.images.first()
image.min_ram = flavor.ram + 1
image.min_disk = flavor.disk
self._test_launch_form_instance_requirement_error(image, flavor,
test_with_profile)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_form_instance_requirement_error_disk_with_profile(self):
self.test_launch_form_instance_requirement_error_disk(
test_with_profile=True)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_form_instance_requirement_error_ram_with_profile(self):
self.test_launch_form_instance_requirement_error_ram(
test_with_profile=True)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def _test_launch_form_instance_show_device_name(self, device_name,
widget_class,
widget_attrs):
flavor = self.flavors.first()
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
volume = self.volumes.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
volume_choice = "%s:vol" % volume.id
quota_usages = self.quota_usages.first()
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)).AndReturn(True)
api.nova.flavor_list(
IsA(http.HttpRequest)).AndReturn(self.flavors.list())
api.nova.keypair_list(
IsA(http.HttpRequest)).AndReturn(self.keypairs.list())
api.network.security_group_list(
IsA(http.HttpRequest)).AndReturn(self.security_groups.list())
api.nova.availability_zone_list(
IsA(http.HttpRequest)).AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True,
'status': 'active'}).AndReturn(
[self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}).AndReturn([[], False, False])
api.neutron.network_list(
IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False).AndReturn(self.networks.list()[:1])
api.neutron.network_list(
IsA(http.HttpRequest),
shared=True).AndReturn(self.networks.list()[1:])
api.nova.extension_supported(
'DiskConfig', IsA(http.HttpRequest)).AndReturn(True)
api.nova.extension_supported(
'ConfigDrive', IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.flavor_list(
IsA(http.HttpRequest)).AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(
IsA(http.HttpRequest)).AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(
IsA(http.HttpRequest)).AndReturn(quota_usages)
api.nova.flavor_list(
IsA(http.HttpRequest)).AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {'flavor': flavor.id,
'source_type': 'volume_image_id',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'customization_script': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_type': 'volume_id',
'volume_id': volume_choice,
'volume_size': max(
image.min_disk, image.size / 1024 ** 3),
'device_name': device_name,
'count': 1}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertNoFormErrors(res)
widget_content = widget_class().render(**widget_attrs)
# In django 1.4, the widget's html attributes are not always rendered
# in the same order and checking the fully rendered widget fails.
for widget_part in widget_content.split():
self.assertContains(res, widget_part)
@django.test.utils.override_settings(
OPENSTACK_HYPERVISOR_FEATURES={'can_set_mount_point': True})
def test_launch_form_instance_device_name_showed(self):
self._test_launch_form_instance_show_device_name(
u'vda', widgets.TextInput, {
'name': 'device_name', 'value': 'vda',
'attrs': {'id': 'id_device_name'}}
)
@django.test.utils.override_settings(
OPENSTACK_HYPERVISOR_FEATURES={'can_set_mount_point': False})
def test_launch_form_instance_device_name_hidden(self):
self._test_launch_form_instance_show_device_name(
u'', widgets.HiddenInput, {
'name': 'device_name', 'value': '',
'attrs': {'id': 'id_device_name'}}
)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',
'profile_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'tenant_absolute_limits',
'availability_zone_list',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def _test_launch_form_instance_volume_size(self, image, volume_size, msg,
test_with_profile=False,
volumes=None):
flavor = self.flavors.get(name='m1.massive')
keypair = self.keypairs.first()
server = self.servers.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
device_name = u'vda'
quota_usages = self.quota_usages.first()
quota_usages['cores']['available'] = 2000
if volumes is not None:
quota_usages['volumes']['available'] = volumes
else:
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
self.mox.ReplayAll()
form_data = {
'flavor': flavor.id,
'source_type': 'volume_image_id',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_size': volume_size,
'device_name': device_name,
'count': 1
}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertContains(res, msg)
def test_launch_form_instance_volume_size_error(self,
test_with_profile=False):
image = self.images.get(name='protected_images')
volume_size = image.min_disk / 2
msg = ("The Volume size is too small for the '%s' image" %
image.name)
self._test_launch_form_instance_volume_size(image, volume_size, msg,
test_with_profile)
def test_launch_form_instance_non_int_volume_size(self,
test_with_profile=False):
image = self.images.get(name='protected_images')
msg = "Enter a whole number."
self._test_launch_form_instance_volume_size(image, 1.5, msg,
test_with_profile)
def test_launch_form_instance_volume_exceed_quota(self):
image = self.images.get(name='protected_images')
msg = "Requested volume exceeds quota: Available: 0, Requested: 1"
self._test_launch_form_instance_volume_size(image, image.min_disk,
msg, False, 0)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_form_instance_volume_size_error_with_profile(self):
self.test_launch_form_instance_volume_size_error(
test_with_profile=True)
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_launch_form_instance_non_int_volume_size_with_profile(self):
self.test_launch_form_instance_non_int_volume_size(
test_with_profile=True)
@helpers.create_stubs({
api.nova: ('flavor_list', 'server_list', 'tenant_absolute_limits',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',),
})
def test_launch_button_disabled_when_quota_exceeded(self):
servers = self.servers.list()
limits = self.limits['absolute']
limits['totalInstancesUsed'] = limits['maxTotalInstances']
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(limits)
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
launch = tables.LaunchLink()
url = launch.get_link_url()
classes = list(launch.get_default_classes()) + list(launch.classes)
link_name = "%s (%s)" % (unicode(launch.verbose_name),
"Quota exceeded")
res = self.client.get(INDEX_URL)
expected_string = encoding.smart_str(u'''
<a href="%s" title="%s" class="%s disabled"
data-update-url=
"/project/instances/?action=launch&table=instances"
id="instances__action_launch">
<span class="fa fa-cloud-upload"></span>%s</a>
''' % (url, link_name, " ".join(classes), link_name), res._charset)
self.assertContains(res, expected_string, html=True,
msg_prefix="The launch button is not disabled")
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.neutron: ('network_list',),
api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'tenant_absolute_limits',
'server_create',),
api.network: ('security_group_list',),
cinder: ('volume_list',
'volume_snapshot_list',),
quotas: ('tenant_quota_usages',)})
def test_launch_with_empty_device_name_allowed(self):
flavor = self.flavors.get(name='m1.massive')
image = self.images.first()
keypair = self.keypairs.first()
server = self.servers.first()
sec_group = self.security_groups.first()
avail_zone = self.availability_zones.first()
customization_script = 'user data'
nics = [{'net-id': self.networks.first().id, 'v4-fixed-ip': ''}]
device_name = u''
quota_usages = self.quota_usages.first()
quota_usages['cores']['available'] = 2000
device_mapping_v2 = [{'device_name': None, # device_name must be None
'source_type': 'image',
'destination_type': 'volume',
'delete_on_termination': 0,
'uuid': image.id,
'boot_index': '0',
'volume_size': image.size}]
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn(self.keypairs.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
volumes = [v for v in self.volumes.list()
if (v.status == AVAILABLE and v.bootable == 'true')]
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn(volumes)
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
api.nova.server_create(IsA(http.HttpRequest),
server.name,
'',
flavor.id,
keypair.name,
customization_script,
[sec_group.name],
block_device_mapping=None,
block_device_mapping_v2=device_mapping_v2,
nics=nics,
availability_zone=avail_zone.zoneName,
instance_count=IsA(int),
admin_pass=u'',
config_drive=False,
disk_config=u'')
self.mox.ReplayAll()
form_data = {
'flavor': flavor.id,
'source_type': 'volume_image_id',
'image_id': image.id,
'availability_zone': avail_zone.zoneName,
'keypair': keypair.name,
'name': server.name,
'script_source': 'raw',
'script_data': customization_script,
'project_id': self.tenants.first().id,
'user_id': self.user.id,
'groups': sec_group.name,
'volume_size': image.size,
'device_name': device_name,
'network': self.networks.first().id,
'count': 1
}
url = reverse('horizon:project:instances:launch')
res = self.client.post(url, form_data)
self.assertNoFormErrors(res)
@helpers.create_stubs({
api.nova: ('flavor_list', 'server_list', 'tenant_absolute_limits',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',),
})
def test_index_options_after_migrate(self):
servers = self.servers.list()
server = self.servers.first()
server.status = "VERIFY_RESIZE"
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertContains(res, "instances__confirm")
self.assertContains(res, "instances__revert")
@helpers.create_stubs({api.nova: ('extension_supported',
'flavor_list',
'keypair_list',
'availability_zone_list',
'tenant_absolute_limits',),
api.network: ('security_group_list',),
cinder: ('volume_snapshot_list',
'volume_list',),
api.neutron: ('network_list',
'profile_list'),
api.glance: ('image_list_detailed',)})
def test_select_default_keypair_if_only_one(self,
test_with_profile=False):
keypair = self.keypairs.first()
cinder.volume_list(IsA(http.HttpRequest),
search_opts=VOLUME_SEARCH_OPTS) \
.AndReturn([])
cinder.volume_snapshot_list(IsA(http.HttpRequest),
search_opts=SNAPSHOT_SEARCH_OPTS) \
.AndReturn([])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False) \
.AndReturn(self.networks.list()[:1])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True) \
.AndReturn(self.networks.list()[1:])
if test_with_profile:
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.extension_supported('ConfigDrive',
IsA(http.HttpRequest)).AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.keypair_list(IsA(http.HttpRequest)) \
.AndReturn([keypair])
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.nova.availability_zone_list(IsA(http.HttpRequest)) \
.AndReturn(self.availability_zones.list())
self.mox.ReplayAll()
url = reverse('horizon:project:instances:launch')
res = self.client.get(url)
self.assertContains(
res, "<option selected='selected' value='%(key)s'>"
"%(key)s</option>" % {'key': keypair.name},
html=True,
msg_prefix="The default key pair was not selected.")
@helpers.update_settings(
OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'})
def test_select_default_keypair_if_only_one_with_profile(self):
self.test_select_default_keypair_if_only_one(test_with_profile=True)
@helpers.create_stubs({api.network: ('floating_ip_target_get_by_instance',
'tenant_floating_ip_allocate',
'floating_ip_associate',
'servers_update_addresses',),
api.glance: ('image_list_detailed',),
api.nova: ('server_list',
'flavor_list')})
def test_associate_floating_ip(self):
servers = self.servers.list()
server = servers[0]
fip = self.q_floating_ips.first()
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
api.network.floating_ip_target_get_by_instance(
IsA(http.HttpRequest),
server.id).AndReturn(server.id)
api.network.tenant_floating_ip_allocate(
IsA(http.HttpRequest)).AndReturn(fip)
api.network.floating_ip_associate(
IsA(http.HttpRequest), fip.id, server.id)
self.mox.ReplayAll()
formData = {'action': 'instances__associate-simple__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.network: ('floating_ip_target_list_by_instance',
'tenant_floating_ip_list',
'floating_ip_disassociate',
'servers_update_addresses',),
api.glance: ('image_list_detailed',),
api.nova: ('server_list',
'flavor_list')})
def test_disassociate_floating_ip(self):
servers = self.servers.list()
server = servers[0]
fip = self.q_floating_ips.first()
fip.port_id = server.id
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers, False])
api.network.servers_update_addresses(IsA(http.HttpRequest), servers)
api.nova.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
api.network.floating_ip_target_list_by_instance(
IsA(http.HttpRequest),
server.id).AndReturn([server.id, ])
api.network.tenant_floating_ip_list(
IsA(http.HttpRequest)).AndReturn([fip])
api.network.floating_ip_disassociate(
IsA(http.HttpRequest), fip.id)
self.mox.ReplayAll()
formData = {'action': 'instances__disassociate__%s' % server.id}
res = self.client.post(INDEX_URL, formData)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_get',
'flavor_list',
'tenant_absolute_limits',
'extension_supported')})
def test_instance_resize_get(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:resize', args=[server.id])
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
config_drive_field_label = 'Configuration Drive'
self.assertNotContains(res, config_drive_field_label)
option = '<option value="%s">%s</option>'
for flavor in self.flavors.list():
if flavor.id == server.flavor['id']:
self.assertNotContains(res, option % (flavor.id, flavor.name))
else:
self.assertContains(res, option % (flavor.id, flavor.name))
@helpers.create_stubs({api.nova: ('server_get',
'flavor_list',)})
def test_instance_resize_get_server_get_exception(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:resize',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_get',
'flavor_list',)})
def test_instance_resize_get_flavor_list_exception(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:resize',
args=[server.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.nova: ('server_get',
'flavor_list',
'flavor_get',
'tenant_absolute_limits',
'extension_supported')})
def test_instance_resize_get_current_flavor_not_found(self):
server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn([])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn([])
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor['id']) \
.AndRaise(self.exceptions.nova)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.limits['absolute'])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:resize', args=[server.id])
res = self.client.get(url)
self.assertTemplateUsed(res, views.WorkflowView.template_name)
def _instance_resize_post(self, server_id, flavor_id, disk_config):
formData = {'flavor': flavor_id,
'default_role': 'member',
'disk_config': disk_config}
url = reverse('horizon:project:instances:resize',
args=[server_id])
return self.client.post(url, formData)
instance_resize_post_stubs = {
api.nova: ('server_get', 'server_resize',
'flavor_list', 'flavor_get',
'extension_supported')}
@helpers.create_stubs(instance_resize_post_stubs)
def test_instance_resize_post(self):
server = self.servers.first()
flavors = [flavor for flavor in self.flavors.list()
if flavor.id != server.flavor['id']]
flavor = flavors[0]
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.server_resize(IsA(http.HttpRequest), server.id, flavor.id,
'AUTO').AndReturn([])
self.mox.ReplayAll()
res = self._instance_resize_post(server.id, flavor.id, u'AUTO')
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs(instance_resize_post_stubs)
def test_instance_resize_post_api_exception(self):
server = self.servers.first()
flavors = [flavor for flavor in self.flavors.list()
if flavor.id != server.flavor['id']]
flavor = flavors[0]
api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.server_resize(IsA(http.HttpRequest), server.id, flavor.id,
'AUTO') \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
res = self._instance_resize_post(server.id, flavor.id, 'AUTO')
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs({api.glance: ('image_list_detailed',),
api.nova: ('extension_supported',)})
def test_rebuild_instance_get(self, expect_password_fields=True):
server = self.servers.first()
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
self.mox.ReplayAll()
url = reverse('horizon:project:instances:rebuild', args=[server.id])
res = self.client.get(url)
self.assertTemplateUsed(res, 'project/instances/rebuild.html')
password_field_label = 'Rebuild Password'
if expect_password_fields:
self.assertContains(res, password_field_label)
else:
self.assertNotContains(res, password_field_label)
@django.test.utils.override_settings(
OPENSTACK_HYPERVISOR_FEATURES={'can_set_password': False})
def test_rebuild_instance_get_without_set_password(self):
self.test_rebuild_instance_get(expect_password_fields=False)
def _instance_rebuild_post(self, server_id, image_id,
password=None, confirm_password=None,
disk_config=None):
form_data = {'instance_id': server_id,
'image': image_id,
'disk_config': disk_config}
if password is not None:
form_data.update(password=password)
if confirm_password is not None:
form_data.update(confirm_password=confirm_password)
url = reverse('horizon:project:instances:rebuild',
args=[server_id])
return self.client.post(url, form_data)
instance_rebuild_post_stubs = {
api.nova: ('server_rebuild',
'extension_supported'),
api.glance: ('image_list_detailed',)}
@helpers.create_stubs(instance_rebuild_post_stubs)
def test_rebuild_instance_post_with_password(self):
server = self.servers.first()
image = self.images.first()
password = u'testpass'
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.server_rebuild(IsA(http.HttpRequest),
server.id,
image.id,
password,
'AUTO').AndReturn([])
self.mox.ReplayAll()
res = self._instance_rebuild_post(server.id, image.id,
password=password,
confirm_password=password,
disk_config='AUTO')
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs(instance_rebuild_post_stubs)
def test_rebuild_instance_post_with_password_equals_none(self):
server = self.servers.first()
image = self.images.first()
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.server_rebuild(IsA(http.HttpRequest),
server.id,
image.id,
None,
'AUTO') \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
res = self._instance_rebuild_post(server.id, image.id,
password=None,
confirm_password=None,
disk_config='AUTO')
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs(instance_rebuild_post_stubs)
def test_rebuild_instance_post_password_do_not_match(self):
server = self.servers.first()
image = self.images.first()
pass1 = u'somepass'
pass2 = u'notsomepass'
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
self.mox.ReplayAll()
res = self._instance_rebuild_post(server.id, image.id,
password=pass1,
confirm_password=pass2,
disk_config='MANUAL')
self.assertContains(res, "Passwords do not match.")
@helpers.create_stubs(instance_rebuild_post_stubs)
def test_rebuild_instance_post_with_empty_string(self):
server = self.servers.first()
image = self.images.first()
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.server_rebuild(IsA(http.HttpRequest),
server.id,
image.id,
None,
'AUTO').AndReturn([])
self.mox.ReplayAll()
res = self._instance_rebuild_post(server.id, image.id,
password=u'',
confirm_password=u'',
disk_config=u'AUTO')
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@helpers.create_stubs(instance_rebuild_post_stubs)
def test_rebuild_instance_post_api_exception(self):
server = self.servers.first()
image = self.images.first()
password = u'testpass'
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'is_public': True, 'status': 'active'}) \
.AndReturn([self.images.list(), False, False])
api.glance.image_list_detailed(
IsA(http.HttpRequest),
filters={'property-owner_id': self.tenant.id,
'status': 'active'}) \
.AndReturn([[], False, False])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
.AndReturn(True)
api.nova.server_rebuild(IsA(http.HttpRequest),
server.id,
image.id,
password,
'AUTO') \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
res = self._instance_rebuild_post(server.id, image.id,
password=password,
confirm_password=password,
disk_config='AUTO')
self.assertRedirectsNoFollow(res, INDEX_URL)
@django.test.utils.override_settings(API_RESULT_PAGE_SIZE=2)
@helpers.create_stubs({
api.nova: ('flavor_list', 'server_list', 'tenant_absolute_limits',
'extension_supported',),
api.glance: ('image_list_detailed',),
api.network: ('floating_ip_simple_associate_supported',
'floating_ip_supported',
'servers_update_addresses',),
})
def test_index_form_action_with_pagination(self):
"""The form action on the next page should have marker
object from the previous page last element.
"""
page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 2)
servers = self.servers.list()[:3]
api.nova.extension_supported('AdminActions',
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.MultipleTimes().AndReturn((self.images.list(), False, False))
search_opts = {'marker': None, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers[:page_size], True])
api.network.servers_update_addresses(
IsA(http.HttpRequest), servers[:page_size])
api.nova.server_list(IsA(http.HttpRequest), search_opts={
'marker': servers[page_size - 1].id, 'paginate': True}) \
.AndReturn([servers[page_size:], False])
api.network.servers_update_addresses(
IsA(http.HttpRequest), servers[page_size:])
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.MultipleTimes().AndReturn(self.limits['absolute'])
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(True)
api.network.floating_ip_simple_associate_supported(
IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'project/instances/index.html')
# get first page with 2 items
self.assertEqual(len(res.context['instances_table'].data), page_size)
# update INDEX_URL with marker object
params = "=".join([tables.InstancesTable._meta.pagination_param,
servers[page_size - 1].id])
next_page_url = "?".join([reverse('horizon:project:instances:index'),
params])
form_action = 'action="%s"' % next_page_url
res = self.client.get(next_page_url)
# get next page with remaining items (item 3)
self.assertEqual(len(res.context['instances_table'].data), 1)
# ensure that marker object exists in form action
self.assertContains(res, form_action, count=1)
@django.test.utils.override_settings(API_RESULT_PAGE_SIZE=2)
@helpers.create_stubs({api.nova: ('server_list',
'flavor_list',
'server_delete',),
api.glance: ('image_list_detailed',),
api.network: ('servers_update_addresses',)})
def test_terminate_instance_with_pagination(self):
"""Instance should be deleted from
the next page.
"""
page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 2)
servers = self.servers.list()[:3]
server = servers[-1]
search_opts = {'marker': servers[page_size - 1].id, 'paginate': True}
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts) \
.AndReturn([servers[page_size:], False])
api.network.servers_update_addresses(IsA(http.HttpRequest),
servers[page_size:])
api.nova.flavor_list(IgnoreArg()).AndReturn(self.flavors.list())
api.glance.image_list_detailed(IgnoreArg()) \
.AndReturn((self.images.list(), False, False))
api.nova.server_delete(IsA(http.HttpRequest), server.id)
self.mox.ReplayAll()
# update INDEX_URL with marker object
params = "=".join([tables.InstancesTable._meta.pagination_param,
servers[page_size - 1].id])
next_page_url = "?".join([reverse('horizon:project:instances:index'),
params])
formData = {'action': 'instances__terminate__%s' % server.id}
res = self.client.post(next_page_url, formData)
self.assertRedirectsNoFollow(res, next_page_url)
self.assertMessageCount(success=1)
class SimpleFile(object):
def __init__(self, name, data, size):
self.name = name
self.data = data
self._size = size
def read(self):
return self.data
def test_clean_file_upload_form_oversize_data(self):
t = workflows.create_instance.CustomizeAction(self.request, {})
upload_str = 'user data'
files = {'script_upload':
self.SimpleFile('script_name',
upload_str,
(16 * 1024) + 1)}
self.assertRaises(
forms.ValidationError,
t.clean_uploaded_files,
'script',
files)
def test_clean_file_upload_form_invalid_data(self):
t = workflows.create_instance.CustomizeAction(self.request, {})
upload_str = '\x81'
files = {'script_upload':
self.SimpleFile('script_name',
upload_str,
sys.getsizeof(upload_str))}
self.assertRaises(
forms.ValidationError,
t.clean_uploaded_files,
'script',
files)
def test_clean_file_upload_form_valid_data(self):
t = workflows.create_instance.CustomizeAction(self.request, {})
precleaned = 'user data'
upload_str = 'user data'
files = {'script_upload':
self.SimpleFile('script_name',
upload_str,
sys.getsizeof(upload_str))}
cleaned = t.clean_uploaded_files('script', files)
self.assertEqual(
cleaned,
precleaned)
class InstanceAjaxTests(helpers.TestCase):
@helpers.create_stubs({api.nova: ("server_get",
"flavor_get",
"extension_supported"),
api.neutron: ("is_extension_supported",)})
def test_row_update(self):
server = self.servers.first()
instance_id = server.id
flavor_id = server.flavor["id"]
flavors = self.flavors.list()
full_flavors = SortedDict([(f.id, f) for f in flavors])
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest))\
.MultipleTimes().AndReturn(True)
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'security-group')\
.MultipleTimes().AndReturn(True)
api.nova.server_get(IsA(http.HttpRequest), instance_id)\
.AndReturn(server)
api.nova.flavor_get(IsA(http.HttpRequest), flavor_id)\
.AndReturn(full_flavors[flavor_id])
self.mox.ReplayAll()
params = {'action': 'row_update',
'table': 'instances',
'obj_id': instance_id,
}
res = self.client.get('?'.join((INDEX_URL, urlencode(params))),
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertContains(res, server.name)
@helpers.create_stubs({api.nova: ("server_get",
"flavor_get",
"extension_supported"),
api.neutron: ("is_extension_supported",)})
def test_row_update_instance_error(self):
server = self.servers.first()
instance_id = server.id
flavor_id = server.flavor["id"]
flavors = self.flavors.list()
full_flavors = SortedDict([(f.id, f) for f in flavors])
server.status = 'ERROR'
server.fault = {"message": "NoValidHost",
"code": 500,
"details": "No valid host was found. \n "
"File \"/mnt/stack/nova/nova/"
"scheduler/filter_scheduler.py\", "
"line 105, in schedule_run_instance\n "
"raise exception.NoValidHost"
"(reason=\"\")\n",
"created": "2013-10-07T00:08:32Z"}
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest))\
.MultipleTimes().AndReturn(True)
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'security-group')\
.MultipleTimes().AndReturn(True)
api.nova.server_get(IsA(http.HttpRequest), instance_id)\
.AndReturn(server)
api.nova.flavor_get(IsA(http.HttpRequest), flavor_id)\
.AndReturn(full_flavors[flavor_id])
self.mox.ReplayAll()
params = {'action': 'row_update',
'table': 'instances',
'obj_id': instance_id,
}
res = self.client.get('?'.join((INDEX_URL, urlencode(params))),
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertContains(res, server.name)
self.assertTrue(res.has_header('X-Horizon-Messages'))
messages = json.loads(res['X-Horizon-Messages'])
self.assertEqual(len(messages), 1)
# (Pdb) messages
# [[u'error', u'Failed to launch instance "server_1": \
# There is not enough capacity for this flavor in the \
# selected availability zone. Try again later or select \
# a different availability zone.', u'']]
self.assertEqual(messages[0][0], 'error')
self.assertTrue(messages[0][1].startswith('Failed'))
@helpers.create_stubs({api.nova: ("server_get",
"flavor_get",
"extension_supported"),
api.neutron: ("is_extension_supported",)})
def test_row_update_flavor_not_found(self):
server = self.servers.first()
instance_id = server.id
api.nova.extension_supported('AdminActions', IsA(http.HttpRequest))\
.MultipleTimes().AndReturn(True)
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'security-group')\
.MultipleTimes().AndReturn(True)
api.nova.server_get(IsA(http.HttpRequest), instance_id)\
.AndReturn(server)
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor["id"])\
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
params = {'action': 'row_update',
'table': 'instances',
'obj_id': instance_id,
}
res = self.client.get('?'.join((INDEX_URL, urlencode(params))),
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertContains(res, server.name)
self.assertContains(res, "Not available")
class ConsoleManagerTests(helpers.TestCase):
def setup_consoles(self):
# Need to refresh with mocks or will fail since mox do not detect
# the api_call() as mocked.
console.CONSOLES = SortedDict([
('VNC', api.nova.server_vnc_console),
('SPICE', api.nova.server_spice_console),
('RDP', api.nova.server_rdp_console),
('SERIAL', api.nova.server_serial_console)])
def _get_console_vnc(self, server):
console_mock = self.mox.CreateMock(api.nova.VNCConsole)
console_mock.url = '/VNC'
self.mox.StubOutWithMock(api.nova, 'server_vnc_console')
api.nova.server_vnc_console(IgnoreArg(), server.id) \
.AndReturn(console_mock)
self.mox.ReplayAll()
self.setup_consoles()
def test_get_console_vnc(self):
server = self.servers.first()
self._get_console_vnc(server)
url = '/VNC&title=%s(%s)' % (server.name, server.id)
data = console.get_console(self.request, 'VNC', server)[1]
self.assertEqual(data, url)
def _get_console_spice(self, server):
console_mock = self.mox.CreateMock(api.nova.SPICEConsole)
console_mock.url = '/SPICE'
self.mox.StubOutWithMock(api.nova, 'server_spice_console')
api.nova.server_spice_console(IgnoreArg(), server.id) \
.AndReturn(console_mock)
self.mox.ReplayAll()
self.setup_consoles()
def test_get_console_spice(self):
server = self.servers.first()
self._get_console_spice(server)
url = '/SPICE&title=%s(%s)' % (server.name, server.id)
data = console.get_console(self.request, 'SPICE', server)[1]
self.assertEqual(data, url)
def _get_console_rdp(self, server):
console_mock = self.mox.CreateMock(api.nova.RDPConsole)
console_mock.url = '/RDP'
self.mox.StubOutWithMock(api.nova, 'server_rdp_console')
api.nova.server_rdp_console(IgnoreArg(), server.id) \
.AndReturn(console_mock)
self.mox.ReplayAll()
self.setup_consoles()
def test_get_console_rdp(self):
server = self.servers.first()
self._get_console_rdp(server)
url = '/RDP&title=%s(%s)' % (server.name, server.id)
data = console.get_console(self.request, 'RDP', server)[1]
self.assertEqual(data, url)
def _get_console_serial(self, server):
console_mock = self.mox.CreateMock(api.nova.SerialConsole)
console_mock.url = '/SERIAL'
self.mox.StubOutWithMock(api.nova, 'server_serial_console')
api.nova.server_serial_console(IgnoreArg(), server.id) \
.AndReturn(console_mock)
self.mox.ReplayAll()
self.setup_consoles()
def test_get_console_serial(self):
server = self.servers.first()
self._get_console_serial(server)
url = '/SERIAL'
data = console.get_console(self.request, 'SERIAL', server)[1]
self.assertEqual(data, url)
def test_get_console_auto_iterate_available(self):
server = self.servers.first()
console_mock = self.mox.CreateMock(api.nova.RDPConsole)
console_mock.url = '/RDP'
self.mox.StubOutWithMock(api.nova, 'server_vnc_console')
api.nova.server_vnc_console(IgnoreArg(), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.StubOutWithMock(api.nova, 'server_spice_console')
api.nova.server_spice_console(IgnoreArg(), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.StubOutWithMock(api.nova, 'server_rdp_console')
api.nova.server_rdp_console(IgnoreArg(), server.id) \
.AndReturn(console_mock)
self.mox.ReplayAll()
self.setup_consoles()
url = '/RDP&title=%s(%s)' % (server.name, server.id)
data = console.get_console(self.request, 'AUTO', server)[1]
self.assertEqual(data, url)
def test_get_console_auto_iterate_serial_available(self):
server = self.servers.first()
console_mock = self.mox.CreateMock(api.nova.SerialConsole)
console_mock.url = '/SERIAL'
self.mox.StubOutWithMock(api.nova, 'server_vnc_console')
api.nova.server_vnc_console(IgnoreArg(), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.StubOutWithMock(api.nova, 'server_spice_console')
api.nova.server_spice_console(IgnoreArg(), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.StubOutWithMock(api.nova, 'server_rdp_console')
api.nova.server_rdp_console(IgnoreArg(), server.id) \
.AndRaise(self.exceptions.nova)
self.mox.StubOutWithMock(api.nova, 'server_serial_console')
api.nova.server_serial_console(IgnoreArg(), server.id) \
.AndReturn(console_mock)
self.mox.ReplayAll()
self.setup_consoles()
url = '/SERIAL'
data = console.get_console(self.request, 'AUTO', server)[1]
self.assertEqual(data, url)
def test_invalid_console_type_raise_value_error(self):
self.assertRaises(exceptions.NotAvailable,
console.get_console, None, 'FAKE', None)
|
apache-2.0
|
[
3,
1898,
6029,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
1898,
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,
2022,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
3351,
492,
11114,
199,
504,
1639,
492,
1455,
199,
646,
1639,
14,
396,
199,
504,
1639,
14,
1208,
14,
23004,
492,
27432,
2141,
199,
504,
1639,
14,
1208,
492,
2644,
199,
504,
1639,
14,
1208,
14,
1014,
492,
16511,
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,
492,
4513,
199,
504,
21726,
14,
25964,
492,
6858,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
1246,
492,
13069,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
8559,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
6716,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
12187,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
10431,
83,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
199,
504,
13869,
63,
9743,
14,
3807,
492,
22874,
421,
199,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
1715,
26,
5990,
26,
1080,
358,
199,
15048,
63,
7823,
63,
15468,
63,
6351,
275,
971,
272,
10431,
83,
14,
873,
63,
842,
14,
18235,
63,
15048,
63,
7823,
63,
4929,
10134,
435,
2668,
3756,
12172,
199,
17377,
275,
2986,
14,
12372,
14,
16689,
63,
6689,
63,
17377,
199,
16689,
63,
15962,
63,
25636,
275,
1211,
8,
1205,
29,
17377,
12,
8498,
461,
29,
17,
9,
199,
30728,
63,
15962,
63,
25636,
275,
1211,
8,
1205,
29,
17377,
9,
421,
199,
533,
10066,
2925,
8,
7546,
14,
1746,
304,
272,
768,
7546,
14,
981,
63,
8957,
2561,
267,
2986,
14,
6765,
26,
334,
288,
283,
6081,
63,
513,
297,
288,
283,
1000,
63,
513,
297,
288,
283,
4647,
63,
6116,
63,
9368,
297,
288,
283,
3435,
63,
4946,
297,
267,
2318,
267,
2986,
14,
18773,
26,
661,
1569,
63,
513,
63,
19170,
5529,
267,
2986,
14,
1200,
26,
334,
288,
283,
7774,
63,
711,
63,
4129,
63,
16021,
63,
4946,
297,
288,
283,
7774,
63,
711,
63,
4946,
297,
288,
283,
5871,
63,
873,
63,
7423,
297,
267,
2318,
272,
3828,
272,
347,
485,
362,
63,
1080,
8,
277,
304,
267,
8037,
275,
291,
14,
5871,
14,
513,
342,
267,
2986,
14,
6765,
14,
3435,
63,
4946,
360,
4880,
9303,
297,
3660,
29719,
8,
1014,
14,
10441,
430,
971,
288,
1275,
8433,
17687,
1252,
8572,
8,
549,
9,
267,
2986,
14,
6765,
14,
6081,
63,
513,
8,
14104,
8,
1014,
14,
10441,
430,
971,
288,
1275,
8572,
8,
277,
14,
18664,
14,
513,
1012,
267,
2986,
14,
18773,
14,
1569,
63,
513,
63,
19170,
8,
19288,
1012,
971,
288,
1275,
8572,
1332,
277,
14,
4782,
14,
513,
1062,
756,
12,
756,
430,
267,
2754,
63,
3291,
275,
791,
4211,
356,
488,
12,
283,
30979,
356,
715,
93,
267,
2986,
14,
6765,
14,
1000,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
2754,
63,
3291,
29,
1733,
63,
3291,
9,
971,
288,
1275,
8572,
779,
5871,
12,
756,
566,
267,
2986,
14,
1200,
14,
5871,
63,
873,
63,
7423,
8,
14104,
8,
1014,
14,
10441,
395,
8037,
9,
267,
2986,
14,
6765,
14,
4647,
63,
6116,
63,
9368,
8,
14104,
8,
1014,
14,
10441,
395,
4644,
29,
549,
9,
971,
1779,
1275,
8433,
17687,
1252,
8572,
8,
277,
14,
9368,
459,
6116,
1105,
267,
2986,
14,
1200,
14,
7774,
63,
711,
63,
4946,
8,
14104,
8,
1014,
14,
10441,
430,
971,
288,
1275,
8433,
17687,
1252,
8572,
8,
549,
9,
267,
2986,
14,
1200,
14,
7774,
63,
711,
63,
4129,
63,
16021,
63,
4946,
8,
288,
29719,
8,
1014,
14,
10441,
4992,
8433,
17687,
1252,
8572,
8,
549,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
372,
291,
14,
1258,
14,
362,
8,
10215,
63,
2632,
9,
339,
347,
511,
63,
1080,
8,
277,
304,
398,
522,
275,
291,
423,
362,
63,
1080,
342,
398,
291,
14,
19661,
8,
470,
12,
1816,
283,
1715,
15,
5990,
15,
1080,
14,
1360,
358,
267,
4454,
275,
522,
14,
1100,
459,
5990,
63,
1224,
2278,
576,
398,
291,
14,
19673,
8,
5990,
12,
291,
14,
5871,
14,
513,
1012,
267,
291,
14,
23218,
8,
470,
12,
298,
18543,
10066,
334,
17610,
22007,
6320,
339,
768,
7546,
14,
981,
63,
8957,
2561,
1246,
14,
6765,
26,
661,
1000,
63,
513,
297,
4228,
283,
4647,
63,
6116,
63,
9368,
9538,
1552,
272,
347,
511,
63,
1080,
63,
1000,
63,
513,
63,
1971,
8,
277,
304,
267,
2754,
63,
3291,
275,
791,
4211,
356,
488,
12,
283,
30979,
356,
715,
93,
267,
2986,
14,
6765,
14,
1000,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
2754,
63,
3291,
29,
1733,
63,
3291,
9,
971,
288,
1275,
3325,
18111,
8,
277,
14,
3924,
14,
6765,
9,
267,
2986,
14,
6765,
14,
4647,
63,
6116,
63,
9368,
8,
14104,
8,
1014,
14,
10441,
395,
4644,
29
] |
[
1898,
6029,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
1898,
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,
2022,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
3351,
492,
11114,
199,
504,
1639,
492,
1455,
199,
646,
1639,
14,
396,
199,
504,
1639,
14,
1208,
14,
23004,
492,
27432,
2141,
199,
504,
1639,
14,
1208,
492,
2644,
199,
504,
1639,
14,
1208,
14,
1014,
492,
16511,
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,
492,
4513,
199,
504,
21726,
14,
25964,
492,
6858,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
1246,
492,
13069,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
8559,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
6716,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
12187,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
5990,
492,
10431,
83,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
199,
504,
13869,
63,
9743,
14,
3807,
492,
22874,
421,
199,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
1715,
26,
5990,
26,
1080,
358,
199,
15048,
63,
7823,
63,
15468,
63,
6351,
275,
971,
272,
10431,
83,
14,
873,
63,
842,
14,
18235,
63,
15048,
63,
7823,
63,
4929,
10134,
435,
2668,
3756,
12172,
199,
17377,
275,
2986,
14,
12372,
14,
16689,
63,
6689,
63,
17377,
199,
16689,
63,
15962,
63,
25636,
275,
1211,
8,
1205,
29,
17377,
12,
8498,
461,
29,
17,
9,
199,
30728,
63,
15962,
63,
25636,
275,
1211,
8,
1205,
29,
17377,
9,
421,
199,
533,
10066,
2925,
8,
7546,
14,
1746,
304,
272,
768,
7546,
14,
981,
63,
8957,
2561,
267,
2986,
14,
6765,
26,
334,
288,
283,
6081,
63,
513,
297,
288,
283,
1000,
63,
513,
297,
288,
283,
4647,
63,
6116,
63,
9368,
297,
288,
283,
3435,
63,
4946,
297,
267,
2318,
267,
2986,
14,
18773,
26,
661,
1569,
63,
513,
63,
19170,
5529,
267,
2986,
14,
1200,
26,
334,
288,
283,
7774,
63,
711,
63,
4129,
63,
16021,
63,
4946,
297,
288,
283,
7774,
63,
711,
63,
4946,
297,
288,
283,
5871,
63,
873,
63,
7423,
297,
267,
2318,
272,
3828,
272,
347,
485,
362,
63,
1080,
8,
277,
304,
267,
8037,
275,
291,
14,
5871,
14,
513,
342,
267,
2986,
14,
6765,
14,
3435,
63,
4946,
360,
4880,
9303,
297,
3660,
29719,
8,
1014,
14,
10441,
430,
971,
288,
1275,
8433,
17687,
1252,
8572,
8,
549,
9,
267,
2986,
14,
6765,
14,
6081,
63,
513,
8,
14104,
8,
1014,
14,
10441,
430,
971,
288,
1275,
8572,
8,
277,
14,
18664,
14,
513,
1012,
267,
2986,
14,
18773,
14,
1569,
63,
513,
63,
19170,
8,
19288,
1012,
971,
288,
1275,
8572,
1332,
277,
14,
4782,
14,
513,
1062,
756,
12,
756,
430,
267,
2754,
63,
3291,
275,
791,
4211,
356,
488,
12,
283,
30979,
356,
715,
93,
267,
2986,
14,
6765,
14,
1000,
63,
513,
8,
14104,
8,
1014,
14,
10441,
395,
2754,
63,
3291,
29,
1733,
63,
3291,
9,
971,
288,
1275,
8572,
779,
5871,
12,
756,
566,
267,
2986,
14,
1200,
14,
5871,
63,
873,
63,
7423,
8,
14104,
8,
1014,
14,
10441,
395,
8037,
9,
267,
2986,
14,
6765,
14,
4647,
63,
6116,
63,
9368,
8,
14104,
8,
1014,
14,
10441,
395,
4644,
29,
549,
9,
971,
1779,
1275,
8433,
17687,
1252,
8572,
8,
277,
14,
9368,
459,
6116,
1105,
267,
2986,
14,
1200,
14,
7774,
63,
711,
63,
4946,
8,
14104,
8,
1014,
14,
10441,
430,
971,
288,
1275,
8433,
17687,
1252,
8572,
8,
549,
9,
267,
2986,
14,
1200,
14,
7774,
63,
711,
63,
4129,
63,
16021,
63,
4946,
8,
288,
29719,
8,
1014,
14,
10441,
4992,
8433,
17687,
1252,
8572,
8,
549,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
372,
291,
14,
1258,
14,
362,
8,
10215,
63,
2632,
9,
339,
347,
511,
63,
1080,
8,
277,
304,
398,
522,
275,
291,
423,
362,
63,
1080,
342,
398,
291,
14,
19661,
8,
470,
12,
1816,
283,
1715,
15,
5990,
15,
1080,
14,
1360,
358,
267,
4454,
275,
522,
14,
1100,
459,
5990,
63,
1224,
2278,
576,
398,
291,
14,
19673,
8,
5990,
12,
291,
14,
5871,
14,
513,
1012,
267,
291,
14,
23218,
8,
470,
12,
298,
18543,
10066,
334,
17610,
22007,
6320,
339,
768,
7546,
14,
981,
63,
8957,
2561,
1246,
14,
6765,
26,
661,
1000,
63,
513,
297,
4228,
283,
4647,
63,
6116,
63,
9368,
9538,
1552,
272,
347,
511,
63,
1080,
63,
1000,
63,
513,
63,
1971,
8,
277,
304,
267,
2754,
63,
3291,
275,
791,
4211,
356,
488,
12,
283,
30979,
356,
715,
93,
267,
2986,
14,
6765,
14,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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
] |
TheTypoMaster/chromium-crosswalk
|
build/android/pylib/gtest/test_package_exe.py
|
4
|
6058
|
# 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.
"""Defines TestPackageExecutable to help run stand-alone executables."""
import logging
import os
import posixpath
import sys
import tempfile
from pylib import cmd_helper
from pylib import constants
from pylib import pexpect
from pylib.device import device_errors
from pylib.gtest import gtest_test_instance
from pylib.gtest.test_package import TestPackage
class TestPackageExecutable(TestPackage):
"""A helper class for running stand-alone executables."""
_TEST_RUNNER_RET_VAL_FILE = 'gtest_retval'
def __init__(self, suite_name):
"""
Args:
suite_name: Name of the test suite (e.g. base_unittests).
"""
TestPackage.__init__(self, suite_name)
self.suite_path = os.path.join(constants.GetOutDirectory(), suite_name)
self._symbols_dir = os.path.join(constants.GetOutDirectory(),
'lib.target')
#override
def GetGTestReturnCode(self, device):
ret = None
ret_code = 1 # Assume failure if we can't find it
ret_code_file = tempfile.NamedTemporaryFile()
try:
if not device.PullFile(
constants.TEST_EXECUTABLE_DIR + '/' +
TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE,
ret_code_file.name):
logging.critical('Unable to pull gtest ret val file %s',
ret_code_file.name)
raise ValueError
ret_code = file(ret_code_file.name).read()
ret = int(ret_code)
except ValueError:
logging.critical('Error reading gtest ret val file %s [%s]',
ret_code_file.name, ret_code)
ret = 1
return ret
@staticmethod
def _AddNativeCoverageExports(device):
# export GCOV_PREFIX set the path for native coverage results
# export GCOV_PREFIX_STRIP indicates how many initial directory
# names to strip off the hardwired absolute paths.
# This value is calculated in buildbot.sh and
# depends on where the tree is built.
# Ex: /usr/local/google/code/chrome will become
# /code/chrome if GCOV_PREFIX_STRIP=3
try:
depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
export_string = ('export GCOV_PREFIX="%s/gcov"\n' %
device.GetExternalStoragePath())
export_string += 'export GCOV_PREFIX_STRIP=%s\n' % depth
return export_string
except KeyError:
logging.info('NATIVE_COVERAGE_DEPTH_STRIP is not defined: '
'No native coverage.')
return ''
except device_errors.CommandFailedError:
logging.info('No external storage found: No native coverage.')
return ''
#override
def ClearApplicationState(self, device):
device.KillAll(self.suite_name, blocking=True, timeout=30, quiet=True)
#override
def CreateCommandLineFileOnDevice(self, device, test_filter, test_arguments):
tool_wrapper = self.tool.GetTestWrapper()
sh_script_file = tempfile.NamedTemporaryFile()
# We need to capture the exit status from the script since adb shell won't
# propagate to us.
sh_script_file.write(
'cd %s\n'
'%s'
'%s LD_LIBRARY_PATH=%s/%s_deps %s/%s --gtest_filter=%s %s\n'
'echo $? > %s' %
(constants.TEST_EXECUTABLE_DIR,
self._AddNativeCoverageExports(device),
tool_wrapper,
constants.TEST_EXECUTABLE_DIR,
self.suite_name,
constants.TEST_EXECUTABLE_DIR,
self.suite_name,
test_filter, test_arguments,
TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
sh_script_file.flush()
cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
device.PushChangedFiles([(
sh_script_file.name,
constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')])
logging.info('Conents of the test runner script: ')
for line in open(sh_script_file.name).readlines():
logging.info(' ' + line.rstrip())
#override
def GetAllTests(self, device):
lib_path = posixpath.join(
constants.TEST_EXECUTABLE_DIR, '%s_deps' % self.suite_name)
cmd = []
for wrapper in (device.GetDevicePieWrapper(), self.tool.GetTestWrapper()):
if wrapper:
cmd.append(wrapper)
cmd.extend([
posixpath.join(constants.TEST_EXECUTABLE_DIR, self.suite_name),
'--gtest_list_tests'])
output = device.RunShellCommand(
cmd, check_return=True, env={'LD_LIBRARY_PATH': lib_path})
return gtest_test_instance.ParseGTestListTests(output)
#override
def SpawnTestProcess(self, device):
args = ['adb', '-s', str(device), 'shell', 'sh',
constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh']
logging.info(args)
return pexpect.spawn(args[0], args[1:], logfile=sys.stdout)
#override
def Install(self, device):
if self.tool.NeedsDebugInfo():
target_name = self.suite_path
else:
target_name = self.suite_path + '_stripped'
if not os.path.isfile(target_name):
raise Exception('Did not find %s, build target %s' %
(target_name, self.suite_name + '_stripped'))
target_mtime = os.stat(target_name).st_mtime
source_mtime = os.stat(self.suite_path).st_mtime
if target_mtime < source_mtime:
raise Exception(
'stripped binary (%s, timestamp %d) older than '
'source binary (%s, timestamp %d), build target %s' %
(target_name, target_mtime, self.suite_path, source_mtime,
self.suite_name + '_stripped'))
test_binary_path = constants.TEST_EXECUTABLE_DIR + '/' + self.suite_name
device.PushChangedFiles([(target_name, test_binary_path)])
deps_path = self.suite_path + '_deps'
if os.path.isdir(deps_path):
device.PushChangedFiles([(deps_path, test_binary_path + '_deps')])
#override
def PullAppFiles(self, device, files, directory):
pass
|
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,
199,
624,
23891,
1379,
8599,
18039,
370,
1720,
1255,
10584,
13,
10636,
31172,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
15454,
199,
646,
984,
199,
646,
5549,
199,
199,
504,
29219,
492,
2088,
63,
3676,
199,
504,
29219,
492,
5262,
199,
504,
29219,
492,
28855,
199,
504,
29219,
14,
1782,
492,
2243,
63,
2550,
199,
504,
29219,
14,
8385,
492,
9088,
63,
396,
63,
842,
199,
504,
29219,
14,
8385,
14,
396,
63,
2491,
492,
1379,
8599,
421,
199,
533,
1379,
8599,
18039,
8,
774,
8599,
304,
523,
408,
33,
5922,
1021,
367,
3879,
10584,
13,
10636,
31172,
1041,
819,
485,
2864,
63,
9390,
15215,
63,
7341,
63,
3204,
63,
3817,
275,
283,
8385,
63,
18476,
7,
819,
347,
636,
826,
721,
277,
12,
5241,
63,
354,
304,
272,
408,
272,
3033,
26,
489,
5241,
63,
354,
26,
2812,
402,
314,
511,
5241,
334,
69,
14,
71,
14,
1300,
63,
31053,
680,
272,
408,
272,
1379,
8599,
855,
826,
721,
277,
12,
5241,
63,
354,
9,
272,
291,
14,
5768,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5559,
14,
1002,
2204,
6231,
1062,
5241,
63,
354,
9,
272,
291,
423,
7450,
63,
694,
275,
747,
14,
515,
14,
904,
8,
5559,
14,
1002,
2204,
6231,
1062,
3660,
283,
773,
14,
1375,
358,
819,
327,
4415,
523,
347,
2372,
39,
774,
30212,
8,
277,
12,
2243,
304,
272,
2203,
275,
488,
272,
2203,
63,
600,
275,
413,
221,
327,
16269,
5988,
340,
781,
883,
1133,
2342,
652,
272,
2203,
63,
600,
63,
493,
275,
5549,
14,
19320,
342,
272,
862,
26,
489,
340,
440,
2243,
14,
27318,
1173,
8,
881,
5262,
14,
2864,
63,
21623,
63,
3022,
435,
7324,
435,
881,
1379,
8599,
18039,
423,
2864,
63,
9390,
15215,
63,
7341,
63,
3204,
63,
3817,
12,
881,
2203,
63,
600,
63,
493,
14,
354,
304,
267,
2050,
14,
13138,
360,
6005,
370,
10299,
9088,
2203,
1139,
570,
450,
83,
297,
586,
2203,
63,
600,
63,
493,
14,
354,
9,
267,
746,
1722,
489,
2203,
63,
600,
275,
570,
8,
3292,
63,
600,
63,
493,
14,
354,
680,
739,
342,
489,
2203,
275,
1109,
8,
3292,
63,
600,
9,
272,
871,
1722,
26,
489,
2050,
14,
13138,
360,
547,
7664,
9088,
2203,
1139,
570,
450,
83,
8978,
83,
4300,
2432,
2203,
63,
600,
63,
493,
14,
354,
12,
2203,
63,
600,
9,
489,
2203,
275,
413,
272,
372,
2203,
819,
768,
4639,
523,
347,
485,
1123,
19675,
27444,
920,
5203,
8,
1782,
304,
272,
327,
4843,
598,
1439,
54,
63,
6351,
663,
314,
931,
367,
5438,
11745,
2058,
272,
327,
4843,
598,
1439,
54,
63,
6351,
63,
31296,
9126,
4212,
5002,
2536,
2082,
272,
327,
14516,
1561,
370,
6202,
2331,
314,
7508,
14249,
581,
3679,
3792,
14,
272,
327,
14516,
961,
574,
365,
12950,
315,
21306,
14,
609,
436,
272,
327,
14516,
8350,
641,
2382,
314,
3123,
365,
6137,
14,
272,
327,
1316,
26,
1182,
2647,
15,
1832,
15,
3098,
15,
600,
15,
9887,
911,
8649,
272,
327,
258,
1182,
600,
15,
9887,
340,
598,
1439,
54,
63,
6351,
63,
31296,
29,
19,
272,
862,
26,
489,
5818,
275,
747,
14,
2314,
459,
46,
14277,
63,
19052,
2962,
63,
19715,
63,
31296,
418,
489,
4843,
63,
875,
275,
661,
3790,
598,
1439,
54,
63,
6351,
5961,
83,
15,
71,
8695,
3212,
78,
7,
450,
2432,
2243,
14,
1002,
11389,
6408,
2042,
1012,
489,
4843,
63,
875,
847,
283,
3790,
598,
1439,
54,
63,
6351,
63,
31296,
2458,
83,
60,
78,
7,
450,
5818,
489,
372,
4843,
63,
875,
272,
871,
4067,
26,
489,
2050,
14,
815,
360,
46,
14277,
63,
19052,
2962,
63,
19715,
63,
31296,
365,
440,
3247,
26,
283,
673,
283,
1944,
5438,
11745,
2659,
489,
372,
2125,
272,
871,
2243,
63,
2550,
14,
3110,
4276,
547,
26,
489,
2050,
14,
815,
360,
1944,
5957,
4887,
1911,
26,
3091,
5438,
11745,
2659,
489,
372,
2125,
819,
327,
4415,
523,
347,
14836,
5039,
2223,
8,
277,
12,
2243,
304,
272,
2243,
14,
31464,
2422,
8,
277,
14,
5768,
63,
354,
12,
14592,
29,
549,
12,
2653,
29,
1216,
12,
11971,
29,
549,
9,
819,
327,
4415,
523,
347,
2790,
16926,
1173,
3314,
2510,
8,
277,
12,
2243,
12,
511,
63,
1541,
12,
511,
63,
4958,
304,
272,
4744,
63,
5029,
275,
291,
14,
3557,
14,
28967,
4590,
342,
272,
1033,
63,
1579,
63,
493,
275,
5549,
14,
19320,
342,
272,
327,
2136,
1929,
370,
12296,
314,
4458,
2004,
687,
314,
2884,
3967,
28173,
5218,
7859,
1133,
272,
327,
19843,
370,
2739,
14,
272,
1033,
63,
1579,
63,
493,
14,
952,
8,
267,
283,
2866,
450,
83,
60,
78,
7,
267,
1543,
83,
7,
267,
1543,
83,
16978,
63,
16983,
63,
3243,
2458,
83,
3149,
83,
63,
5846,
450,
83,
3149,
83,
1553,
8385,
63,
1541,
2458,
83,
450,
83,
60,
78,
7,
267,
283,
7878,
2672,
31,
690,
450,
83,
7,
450,
267,
334,
5559,
14,
2864,
63,
21623,
63,
3022,
12,
268,
291,
423,
1123,
19675,
27444,
920,
5203,
8,
1782,
395,
268,
4744,
63,
5029,
12,
268,
5262,
14,
2864,
63,
21623,
63,
3022,
12,
268,
291,
14,
5768,
63,
354,
12,
268,
5262,
14,
2864,
63,
21623,
63,
3022,
12,
268,
291,
14,
5768,
63,
354,
12,
268,
511,
63,
1541,
12,
511,
63,
4958,
12,
268,
1379,
8599,
18039,
423,
2864,
63,
9390,
15215,
63,
7341,
63,
3204,
63,
3817,
430,
272,
1033,
63,
1579,
63,
493,
14,
4939,
342,
272,
2088,
63,
3676,
14,
2540,
7874,
2941,
11693,
297,
6681,
88,
297,
1033,
63,
1579,
63,
493,
14,
354,
566,
272,
2243,
14,
10731,
6970,
5535,
7694,
267,
1033,
63,
1579,
63,
493,
14,
354,
12,
267,
5262,
14,
2864,
63,
21623,
63,
3022,
435,
1994,
9887,
63,
396,
63,
5933,
14,
609,
2023,
272,
2050,
14,
815,
360,
714,
24871,
402,
314,
511,
7876,
2884,
26,
5320,
272,
367,
1004,
315,
1551,
8
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
23891,
1379,
8599,
18039,
370,
1720,
1255,
10584,
13,
10636,
31172,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
15454,
199,
646,
984,
199,
646,
5549,
199,
199,
504,
29219,
492,
2088,
63,
3676,
199,
504,
29219,
492,
5262,
199,
504,
29219,
492,
28855,
199,
504,
29219,
14,
1782,
492,
2243,
63,
2550,
199,
504,
29219,
14,
8385,
492,
9088,
63,
396,
63,
842,
199,
504,
29219,
14,
8385,
14,
396,
63,
2491,
492,
1379,
8599,
421,
199,
533,
1379,
8599,
18039,
8,
774,
8599,
304,
523,
408,
33,
5922,
1021,
367,
3879,
10584,
13,
10636,
31172,
1041,
819,
485,
2864,
63,
9390,
15215,
63,
7341,
63,
3204,
63,
3817,
275,
283,
8385,
63,
18476,
7,
819,
347,
636,
826,
721,
277,
12,
5241,
63,
354,
304,
272,
408,
272,
3033,
26,
489,
5241,
63,
354,
26,
2812,
402,
314,
511,
5241,
334,
69,
14,
71,
14,
1300,
63,
31053,
680,
272,
408,
272,
1379,
8599,
855,
826,
721,
277,
12,
5241,
63,
354,
9,
272,
291,
14,
5768,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5559,
14,
1002,
2204,
6231,
1062,
5241,
63,
354,
9,
272,
291,
423,
7450,
63,
694,
275,
747,
14,
515,
14,
904,
8,
5559,
14,
1002,
2204,
6231,
1062,
3660,
283,
773,
14,
1375,
358,
819,
327,
4415,
523,
347,
2372,
39,
774,
30212,
8,
277,
12,
2243,
304,
272,
2203,
275,
488,
272,
2203,
63,
600,
275,
413,
221,
327,
16269,
5988,
340,
781,
883,
1133,
2342,
652,
272,
2203,
63,
600,
63,
493,
275,
5549,
14,
19320,
342,
272,
862,
26,
489,
340,
440,
2243,
14,
27318,
1173,
8,
881,
5262,
14,
2864,
63,
21623,
63,
3022,
435,
7324,
435,
881,
1379,
8599,
18039,
423,
2864,
63,
9390,
15215,
63,
7341,
63,
3204,
63,
3817,
12,
881,
2203,
63,
600,
63,
493,
14,
354,
304,
267,
2050,
14,
13138,
360,
6005,
370,
10299,
9088,
2203,
1139,
570,
450,
83,
297,
586,
2203,
63,
600,
63,
493,
14,
354,
9,
267,
746,
1722,
489,
2203,
63,
600,
275,
570,
8,
3292,
63,
600,
63,
493,
14,
354,
680,
739,
342,
489,
2203,
275,
1109,
8,
3292,
63,
600,
9,
272,
871,
1722,
26,
489,
2050,
14,
13138,
360,
547,
7664,
9088,
2203,
1139,
570,
450,
83,
8978,
83,
4300,
2432,
2203,
63,
600,
63,
493,
14,
354,
12,
2203,
63,
600,
9,
489,
2203,
275,
413,
272,
372,
2203,
819,
768,
4639,
523,
347,
485,
1123,
19675,
27444,
920,
5203,
8,
1782,
304,
272,
327,
4843,
598,
1439,
54,
63,
6351,
663,
314,
931,
367,
5438,
11745,
2058,
272,
327,
4843,
598,
1439,
54,
63,
6351,
63,
31296,
9126,
4212,
5002,
2536,
2082,
272,
327,
14516,
1561,
370,
6202,
2331,
314,
7508,
14249,
581,
3679,
3792,
14,
272,
327,
14516,
961,
574,
365,
12950,
315,
21306,
14,
609,
436,
272,
327,
14516,
8350,
641,
2382,
314,
3123,
365,
6137,
14,
272,
327,
1316,
26,
1182,
2647,
15,
1832,
15,
3098,
15,
600,
15,
9887,
911,
8649,
272,
327,
258,
1182,
600,
15,
9887,
340,
598,
1439,
54,
63,
6351,
63,
31296,
29,
19,
272,
862,
26,
489,
5818,
275,
747,
14,
2314,
459,
46,
14277,
63,
19052,
2962,
63,
19715,
63,
31296,
418,
489,
4843,
63,
875,
275,
661,
3790,
598,
1439,
54,
63,
6351,
5961,
83,
15,
71,
8695,
3212,
78,
7,
450,
2432,
2243,
14,
1002,
11389,
6408,
2042,
1012,
489,
4843,
63,
875,
847,
283,
3790,
598,
1439,
54,
63,
6351,
63,
31296,
2458,
83,
60,
78,
7,
450,
5818,
489,
372,
4843,
63,
875,
272,
871,
4067,
26,
489,
2050,
14,
815,
360,
46,
14277,
63,
19052,
2962,
63,
19715,
63,
31296,
365,
440,
3247,
26,
283,
673,
283,
1944,
5438,
11745,
2659,
489,
372,
2125,
272,
871,
2243,
63,
2550,
14,
3110,
4276,
547,
26,
489,
2050,
14,
815,
360,
1944,
5957,
4887,
1911,
26,
3091,
5438,
11745,
2659,
489,
372,
2125,
819,
327,
4415,
523,
347,
14836,
5039,
2223,
8,
277,
12,
2243,
304,
272,
2243,
14,
31464,
2422,
8,
277,
14,
5768,
63,
354,
12,
14592,
29,
549,
12,
2653,
29,
1216,
12,
11971,
29,
549,
9,
819,
327,
4415,
523,
347,
2790,
16926,
1173,
3314,
2510,
8,
277,
12,
2243,
12,
511,
63,
1541,
12,
511,
63,
4958,
304,
272,
4744,
63,
5029,
275,
291,
14,
3557,
14,
28967,
4590,
342,
272,
1033,
63,
1579,
63,
493,
275,
5549,
14,
19320,
342,
272,
327,
2136,
1929,
370,
12296,
314,
4458,
2004,
687,
314,
2884,
3967,
28173,
5218,
7859,
1133,
272,
327,
19843,
370,
2739,
14,
272,
1033,
63,
1579,
63,
493,
14,
952,
8,
267,
283,
2866,
450,
83,
60,
78,
7,
267,
1543,
83,
7,
267,
1543,
83,
16978,
63,
16983,
63,
3243,
2458,
83,
3149,
83,
63,
5846,
450,
83,
3149,
83,
1553,
8385,
63,
1541,
2458,
83,
450,
83,
60,
78,
7,
267,
283,
7878,
2672,
31,
690,
450,
83,
7,
450,
267,
334,
5559,
14,
2864,
63,
21623,
63,
3022,
12,
268,
291,
423,
1123,
19675,
27444,
920,
5203,
8,
1782,
395,
268,
4744,
63,
5029,
12,
268,
5262,
14,
2864,
63,
21623,
63,
3022,
12,
268,
291,
14,
5768,
63,
354,
12,
268,
5262,
14,
2864,
63,
21623,
63,
3022,
12,
268,
291,
14,
5768,
63,
354,
12,
268,
511,
63,
1541,
12,
511,
63,
4958,
12,
268,
1379,
8599,
18039,
423,
2864,
63,
9390,
15215,
63,
7341,
63,
3204,
63,
3817,
430,
272,
1033,
63,
1579,
63,
493,
14,
4939,
342,
272,
2088,
63,
3676,
14,
2540,
7874,
2941,
11693,
297,
6681,
88,
297,
1033,
63,
1579,
63,
493,
14,
354,
566,
272,
2243,
14,
10731,
6970,
5535,
7694,
267,
1033,
63,
1579,
63,
493,
14,
354,
12,
267,
5262,
14,
2864,
63,
21623,
63,
3022,
435,
1994,
9887,
63,
396,
63,
5933,
14,
609,
2023,
272,
2050,
14,
815,
360,
714,
24871,
402,
314,
511,
7876,
2884,
26,
5320,
272,
367,
1004,
315,
1551,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alperyeg/elephant
|
elephant/test/test_spade.py
|
2
|
32565
|
"""
Unit tests for the spade module.
:copyright: Copyright 2014-2016 by the Elephant team, see `doc/authors.rst`.
:license: Modified BSD, see LICENSE.txt for details.
"""
from __future__ import division
import sys
import unittest
import random
import neo
import numpy as np
import quantities as pq
from numpy.testing.utils import assert_array_equal
import elephant.conversion as conv
import elephant.spade as spade
import elephant.spike_train_generation as stg
try:
import statsmodels
HAVE_STATSMODELS = True
except ImportError:
HAVE_STATSMODELS = False
python_version_major = sys.version_info.major
HAVE_FIM = spade.HAVE_FIM
class SpadeTestCase(unittest.TestCase):
def setUp(self):
np.random.seed(0)
# Spade parameters
self.bin_size = 1 * pq.ms
self.winlen = 10
self.n_subset = 10
self.n_surr = 10
self.alpha = 0.05
self.stability_thresh = [0.1, 0.1]
self.psr_param = [0, 0, 0]
self.min_occ = 4
self.min_spikes = 4
self.max_occ = 4
self.max_spikes = 4
self.min_neu = 4
# Test data parameters
# CPP parameters
self.n_neu = 100
self.amplitude = [0] * self.n_neu + [1]
self.cpp = stg.cpp(
rate=3 * pq.Hz,
amplitude_distribution=self.amplitude,
t_stop=5 * pq.s)
# Number of patterns' occurrences
self.n_occ1 = 10
self.n_occ2 = 12
self.n_occ3 = 15
# Patterns lags
self.lags1 = [2]
self.lags2 = [1, 3]
self.lags3 = [1, 2, 4, 5, 7]
# Length of the spiketrain
self.t_stop = 3000
# Patterns times
self.patt1_times = neo.SpikeTrain(
np.arange(
0, 1000, 1000 // self.n_occ1) *
pq.ms, t_stop=self.t_stop * pq.ms)
self.patt2_times = neo.SpikeTrain(
np.arange(
1000, 2000, 1000 // self.n_occ2)[:-1] *
pq.ms, t_stop=self.t_stop * pq.ms)
self.patt3_times = neo.SpikeTrain(
np.arange(
2000, 3000, 1000 // self.n_occ3)[:-1] *
pq.ms, t_stop=self.t_stop * pq.ms)
# Patterns
self.patt1 = [self.patt1_times] + [neo.SpikeTrain(
self.patt1_times.view(pq.Quantity) + lag * pq.ms,
t_stop=self.t_stop * pq.ms) for lag in self.lags1]
self.patt2 = [self.patt2_times] + [neo.SpikeTrain(
self.patt2_times.view(pq.Quantity) + lag * pq.ms,
t_stop=self.t_stop * pq.ms) for lag in self.lags2]
self.patt3 = [self.patt3_times] + [neo.SpikeTrain(
self.patt3_times.view(pq.Quantity) + lag * pq.ms,
t_stop=self.t_stop * pq.ms) for lag in self.lags3]
# Data
self.msip = self.patt1 + self.patt2 + self.patt3
# Expected results
self.n_spk1 = len(self.lags1) + 1
self.n_spk2 = len(self.lags2) + 1
self.n_spk3 = len(self.lags3) + 1
self.elements1 = list(range(self.n_spk1))
self.elements2 = list(range(self.n_spk2))
self.elements3 = list(range(self.n_spk3))
self.elements_msip = [
self.elements1,
list(
range(
self.n_spk1,
self.n_spk1 +
self.n_spk2)),
list(
range(
self.n_spk1 +
self.n_spk2,
self.n_spk1 +
self.n_spk2 +
self.n_spk3))]
self.occ1 = np.unique(conv.BinnedSpikeTrain(
self.patt1_times, self.bin_size).spike_indices[0])
self.occ2 = np.unique(conv.BinnedSpikeTrain(
self.patt2_times, self.bin_size).spike_indices[0])
self.occ3 = np.unique(conv.BinnedSpikeTrain(
self.patt3_times, self.bin_size).spike_indices[0])
self.occ_msip = [
list(self.occ1), list(self.occ2), list(self.occ3)]
self.lags_msip = [self.lags1, self.lags2, self.lags3]
self.patt_psr = self.patt3 + [self.patt3[-1][:3]]
# Testing cpp
@unittest.skipUnless(HAVE_FIM, "Time consuming with pythonic FIM")
def test_spade_cpp(self):
output_cpp = spade.spade(self.cpp, self.bin_size, 1,
approx_stab_pars=dict(
n_subsets=self.n_subset,
stability_thresh=self.stability_thresh),
n_surr=self.n_surr, alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
elements_cpp = []
lags_cpp = []
# collecting spade output
for out in output_cpp:
elements_cpp.append(sorted(out['neurons']))
lags_cpp.append(list(out['lags'].magnitude))
# check neurons in the patterns
assert_array_equal(elements_cpp, [range(self.n_neu)])
# check the lags
assert_array_equal(lags_cpp, [np.array([0] * (self.n_neu - 1))])
# Testing spectrum cpp
def test_spade_spectrum_cpp(self):
# Computing Spectrum
spectrum_cpp = spade.concepts_mining(self.cpp, self.bin_size,
1, report='#')[0]
# Check spectrum
assert_array_equal(
spectrum_cpp,
[(len(self.cpp),
np.sum(conv.BinnedSpikeTrain(
self.cpp[0], self.bin_size).to_bool_array()), 1)])
# Testing with multiple patterns input
def test_spade_msip(self):
output_msip = spade.spade(self.msip, self.bin_size, self.winlen,
approx_stab_pars=dict(
n_subsets=self.n_subset,
stability_thresh=self.stability_thresh),
n_surr=self.n_surr, alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
elements_msip = []
occ_msip = []
lags_msip = []
# collecting spade output
for out in output_msip:
elements_msip.append(out['neurons'])
occ_msip.append(list(out['times'].magnitude))
lags_msip.append(list(out['lags'].magnitude))
elements_msip = sorted(elements_msip, key=len)
occ_msip = sorted(occ_msip, key=len)
lags_msip = sorted(lags_msip, key=len)
# check neurons in the patterns
assert_array_equal(elements_msip, self.elements_msip)
# check the occurrences time of the patters
assert_array_equal(occ_msip, self.occ_msip)
# check the lags
assert_array_equal(lags_msip, self.lags_msip)
@unittest.skipUnless(python_version_major == 3, "assertWarns requires 3.2")
def test_parameters(self):
"""
Test under different configuration of parameters than the default one
"""
# test min_spikes parameter
with self.assertWarns(UserWarning):
# n_surr=0 and alpha=0.05 spawns expected UserWarning
output_msip_min_spikes = spade.spade(
self.msip,
self.bin_size,
self.winlen,
min_spikes=self.min_spikes,
approx_stab_pars=dict(n_subsets=self.n_subset),
n_surr=0,
alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
# collecting spade output
elements_msip_min_spikes = []
for out in output_msip_min_spikes:
elements_msip_min_spikes.append(out['neurons'])
elements_msip_min_spikes = sorted(
elements_msip_min_spikes, key=len)
lags_msip_min_spikes = []
for out in output_msip_min_spikes:
lags_msip_min_spikes.append(list(out['lags'].magnitude))
pvalue = out['pvalue']
lags_msip_min_spikes = sorted(
lags_msip_min_spikes, key=len)
# check the lags
assert_array_equal(lags_msip_min_spikes, [
l for l in self.lags_msip if len(l) + 1 >= self.min_spikes])
# check the neurons in the patterns
assert_array_equal(elements_msip_min_spikes, [
el for el in self.elements_msip if len(el) >= self.min_neu and len(
el) >= self.min_spikes])
# check that the p-values assigned are equal to -1 (n_surr=0)
assert_array_equal(-1, pvalue)
# test min_occ parameter
output_msip_min_occ = spade.spade(
self.msip,
self.bin_size,
self.winlen,
min_occ=self.min_occ,
approx_stab_pars=dict(
n_subsets=self.n_subset),
n_surr=self.n_surr,
alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
# collect spade output
occ_msip_min_occ = []
for out in output_msip_min_occ:
occ_msip_min_occ.append(list(out['times'].magnitude))
occ_msip_min_occ = sorted(occ_msip_min_occ, key=len)
# test occurrences time
assert_array_equal(occ_msip_min_occ, [
occ for occ in self.occ_msip if len(occ) >= self.min_occ])
# test max_spikes parameter
output_msip_max_spikes = spade.spade(
self.msip,
self.bin_size,
self.winlen,
max_spikes=self.max_spikes,
approx_stab_pars=dict(
n_subsets=self.n_subset),
n_surr=self.n_surr,
alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
# collecting spade output
elements_msip_max_spikes = []
for out in output_msip_max_spikes:
elements_msip_max_spikes.append(out['neurons'])
elements_msip_max_spikes = sorted(
elements_msip_max_spikes, key=len)
lags_msip_max_spikes = []
for out in output_msip_max_spikes:
lags_msip_max_spikes.append(list(out['lags'].magnitude))
lags_msip_max_spikes = sorted(
lags_msip_max_spikes, key=len)
# check the lags
assert_array_equal(
[len(lags) < self.max_spikes
for lags in lags_msip_max_spikes],
[True] * len(lags_msip_max_spikes))
# test max_occ parameter
output_msip_max_occ = spade.spade(
self.msip,
self.bin_size,
self.winlen,
max_occ=self.max_occ,
approx_stab_pars=dict(
n_subsets=self.n_subset),
n_surr=self.n_surr,
alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
# collect spade output
occ_msip_max_occ = []
for out in output_msip_max_occ:
occ_msip_max_occ.append(list(out['times'].magnitude))
occ_msip_max_occ = sorted(occ_msip_max_occ, key=len)
# test occurrences time
assert_array_equal(occ_msip_max_occ, [
occ for occ in self.occ_msip if len(occ) <= self.max_occ])
# test to compare the python and the C implementation of FIM
# skip this test if C code not available
@unittest.skipIf(not HAVE_FIM, 'Requires fim.so')
def test_fpgrowth_fca(self):
print("fim.so is found.")
binary_matrix = conv.BinnedSpikeTrain(
self.patt1, self.bin_size).to_sparse_bool_array().tocoo()
context, transactions, rel_matrix = spade._build_context(
binary_matrix, self.winlen)
# mining the data with python fast_fca
mining_results_fpg = spade._fpgrowth(
transactions,
rel_matrix=rel_matrix)
# mining the data with C fim
mining_results_ffca = spade._fast_fca(context)
# testing that the outputs are identical
assert_array_equal(sorted(mining_results_ffca[0][0]), sorted(
mining_results_fpg[0][0]))
assert_array_equal(sorted(mining_results_ffca[0][1]), sorted(
mining_results_fpg[0][1]))
# Tests 3d spectrum
# Testing with multiple patterns input
def test_spade_msip_3d(self):
output_msip = spade.spade(self.msip, self.bin_size, self.winlen,
approx_stab_pars=dict(
n_subsets=self.n_subset,
stability_thresh=self.stability_thresh),
n_surr=self.n_surr, spectrum='3d#',
alpha=self.alpha, psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
elements_msip = []
occ_msip = []
lags_msip = []
# collecting spade output
for out in output_msip:
elements_msip.append(out['neurons'])
occ_msip.append(list(out['times'].magnitude))
lags_msip.append(list(out['lags'].magnitude))
elements_msip = sorted(elements_msip, key=len)
occ_msip = sorted(occ_msip, key=len)
lags_msip = sorted(lags_msip, key=len)
# check neurons in the patterns
assert_array_equal(elements_msip, self.elements_msip)
# check the occurrences time of the patters
assert_array_equal(occ_msip, self.occ_msip)
# check the lags
assert_array_equal(lags_msip, self.lags_msip)
# test under different configuration of parameters than the default one
def test_parameters_3d(self):
# test min_spikes parameter
output_msip_min_spikes = spade.spade(
self.msip,
self.bin_size,
self.winlen,
min_spikes=self.min_spikes,
approx_stab_pars=dict(
n_subsets=self.n_subset),
n_surr=self.n_surr,
spectrum='3d#',
alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
# collecting spade output
elements_msip_min_spikes = []
for out in output_msip_min_spikes:
elements_msip_min_spikes.append(out['neurons'])
elements_msip_min_spikes = sorted(
elements_msip_min_spikes, key=len)
lags_msip_min_spikes = []
for out in output_msip_min_spikes:
lags_msip_min_spikes.append(list(out['lags'].magnitude))
lags_msip_min_spikes = sorted(
lags_msip_min_spikes, key=len)
# check the lags
assert_array_equal(lags_msip_min_spikes, [
l for l in self.lags_msip if len(l) + 1 >= self.min_spikes])
# check the neurons in the patterns
assert_array_equal(elements_msip_min_spikes, [
el for el in self.elements_msip if len(el) >= self.min_neu and len(
el) >= self.min_spikes])
# test min_occ parameter
output_msip_min_occ = spade.spade(
self.msip,
self.bin_size,
self.winlen,
min_occ=self.min_occ,
approx_stab_pars=dict(
n_subsets=self.n_subset),
n_surr=self.n_surr,
spectrum='3d#',
alpha=self.alpha,
psr_param=self.psr_param,
stat_corr='no',
output_format='patterns')['patterns']
# collect spade output
occ_msip_min_occ = []
for out in output_msip_min_occ:
occ_msip_min_occ.append(list(out['times'].magnitude))
occ_msip_min_occ = sorted(occ_msip_min_occ, key=len)
# test occurrences time
assert_array_equal(occ_msip_min_occ, [
occ for occ in self.occ_msip if len(occ) >= self.min_occ])
# Test computation spectrum
def test_spectrum(self):
# test 2d spectrum
spectrum = spade.concepts_mining(self.patt1, self.bin_size,
self.winlen, report='#')[0]
# test 3d spectrum
assert_array_equal(spectrum, [[len(self.lags1) + 1, self.n_occ1, 1]])
spectrum_3d = spade.concepts_mining(self.patt1, self.bin_size,
self.winlen, report='3d#')[0]
assert_array_equal(spectrum_3d, [
[len(self.lags1) + 1, self.n_occ1, max(self.lags1), 1]])
def test_spade_raise_error(self):
# Test list not using neo.Spiketrain
self.assertRaises(TypeError, spade.spade, [
[1, 2, 3], [3, 4, 5]], 1 * pq.ms, 4, stat_corr='no')
self.assertRaises(TypeError, spade.concepts_mining, [
[1, 2, 3], [3, 4, 5]], 1 * pq.ms, 4)
# Test neo.Spiketrain with different t_stop
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
1 * pq.ms, 4, stat_corr='no')
# Test bin_size not pq.Quantity
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1., winlen=4, stat_corr='no')
# Test winlen not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4.1, stat_corr='no')
# Test min_spikes not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, min_spikes=3.4, stat_corr='no')
# Test min_occ not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, min_occ=3.4, stat_corr='no')
# Test max_spikes not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, max_spikes=3.4, stat_corr='no')
# Test max_occ not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, max_occ=3.4, stat_corr='no')
# Test min_neu not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, min_neu=3.4, stat_corr='no')
# Test wrong stability params
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, approx_stab_pars={'wrong key': 0},
stat_corr='no')
# Test n_surr not int
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=3.4, stat_corr='no')
# Test dither not pq.Quantity
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=100, alpha=0.05,
dither=15., stat_corr='no')
# Test wrong alpha
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=100, alpha='5 %',
dither=15.*pq.ms, stat_corr='no')
# Test wrong statistical correction
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=100, alpha=0.05,
dither=15.*pq.ms, stat_corr='wrong correction')
# Test wrong psr_params
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=100, alpha=0.05,
dither=15.*pq.ms, stat_corr='no', psr_param=(2.5, 3.4, 2.1))
# Test wrong psr_params
self.assertRaises(
TypeError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=100, alpha=0.05,
dither=15.*pq.ms, stat_corr='no', psr_param=3.1)
# Test output format
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
bin_size=1.*pq.ms, winlen=4, n_surr=100, alpha=0.05,
dither=15.*pq.ms, stat_corr='no', output_format='wrong_output')
# Test wrong spectrum parameter
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
1 * pq.ms, 4, n_surr=1, stat_corr='no',
spectrum='invalid_key')
self.assertRaises(
ValueError, spade.concepts_mining,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
1 * pq.ms, 4, report='invalid_key')
self.assertRaises(
ValueError, spade.pvalue_spectrum,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=6 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=6 * pq.s)],
1 * pq.ms, 4, dither=10*pq.ms, n_surr=1,
spectrum='invalid_key')
# Test negative minimum number of spikes
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=5 * pq.s)],
1 * pq.ms, 4, min_neu=-3, stat_corr='no')
# Test wrong dither method
self.assertRaises(
ValueError, spade.spade,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=5 * pq.s)],
1 * pq.ms, 4, surr_method='invalid_key', stat_corr='no')
# Test negative number of surrogates
self.assertRaises(
ValueError, spade.pvalue_spectrum,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=5 * pq.s)],
1 * pq.ms, 4, dither=10*pq.ms, n_surr=100,
surr_method='invalid_key')
# Test negative number of surrogates
self.assertRaises(
ValueError, spade.pvalue_spectrum,
[neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s),
neo.SpikeTrain([3, 4, 5] * pq.s, t_stop=5 * pq.s)],
1 * pq.ms, 4, 3 * pq.ms, n_surr=-3)
# Test wrong correction parameter
self.assertRaises(ValueError, spade.test_signature_significance,
pv_spec=((2, 3, 0.2), (2, 4, 0.1)),
concepts=([[(2, 3), (1, 2, 3)]]),
alpha=0.01,
winlen=1,
corr='invalid_key')
# Test negative number of subset for stability
self.assertRaises(ValueError, spade.approximate_stability, (),
np.array([]), n_subsets=-3)
def test_pattern_set_reduction(self):
winlen = 6
# intent(concept1) is a superset of intent(concept2)
# extent(concept1) is a subset of extent(concept2)
# intent(concept2) is a subset of intent(concept3)
# when taking into account the shift due to the window positions
# intent(concept1) has a non-empty intersection with intent(concept3)
# when taking into account the shift due to the window positions
# intent(concept4) is disjoint from all others
concept1 = ((12, 19, 26), (2, 10, 18))
concept2 = ((12, 19), (2, 10, 18, 26))
concept3 = ((0, 7, 14, 21), (0, 8))
concept4 = ((1, 6), (0, 8))
# reject concept2 using min_occ
# make sure to keep concept1 by setting k_superset_filtering = 1
concepts = spade.pattern_set_reduction([concept1, concept2],
ns_signatures=[],
winlen=winlen, spectrum='#',
h_subset_filtering=0, min_occ=2,
k_superset_filtering=1)
self.assertEqual(concepts, [concept1])
# keep concept2 by increasing h_subset_filtering
concepts = spade.pattern_set_reduction([concept1, concept2],
ns_signatures=[],
winlen=winlen, spectrum='#',
h_subset_filtering=2, min_occ=2,
k_superset_filtering=1)
self.assertEqual(concepts, [concept1, concept2])
# reject concept1 using min_spikes
concepts = spade.pattern_set_reduction([concept1, concept2],
ns_signatures=[],
winlen=winlen, spectrum='#',
h_subset_filtering=2,
min_spikes=2,
k_superset_filtering=0)
self.assertEqual(concepts, [concept2])
# reject concept2 using ns_signatures
concepts = spade.pattern_set_reduction([concept1, concept2],
ns_signatures=[(2, 2)],
winlen=winlen, spectrum='#',
h_subset_filtering=1, min_occ=2,
k_superset_filtering=1)
self.assertEqual(concepts, [concept1])
# reject concept1 using ns_signatures
# make sure to keep concept2 by increasing h_subset_filtering
concepts = spade.pattern_set_reduction([concept1, concept2],
ns_signatures=[(2, 3)],
winlen=winlen, spectrum='#',
h_subset_filtering=3,
min_spikes=2,
min_occ=2,
k_superset_filtering=1)
self.assertEqual(concepts, [concept2])
# reject concept2 using the covered spikes criterion
concepts = spade.pattern_set_reduction([concept1, concept2],
ns_signatures=[(2, 2)],
winlen=winlen, spectrum='#',
h_subset_filtering=0,
min_occ=2,
k_superset_filtering=0,
l_covered_spikes=0)
self.assertEqual(concepts, [concept1])
# reject concept1 using superset filtering
# (case with non-empty intersection but no superset)
concepts = spade.pattern_set_reduction([concept1, concept3],
ns_signatures=[], min_spikes=2,
winlen=winlen, spectrum='#',
k_superset_filtering=0)
self.assertEqual(concepts, [concept3])
# keep concept1 by increasing k_superset_filtering
concepts = spade.pattern_set_reduction([concept1, concept3],
ns_signatures=[], min_spikes=2,
winlen=winlen, spectrum='#',
k_superset_filtering=1)
self.assertEqual(concepts, [concept1, concept3])
# reject concept3 using ns_signatures
concepts = spade.pattern_set_reduction([concept1, concept3],
ns_signatures=[(3, 2)],
min_spikes=2,
winlen=winlen, spectrum='#',
k_superset_filtering=1)
self.assertEqual(concepts, [concept1])
# reject concept3 using the covered spikes criterion
concepts = spade.pattern_set_reduction([concept1, concept3],
ns_signatures=[(3, 2), (2, 3)],
min_spikes=2,
winlen=winlen, spectrum='#',
k_superset_filtering=1,
l_covered_spikes=0)
self.assertEqual(concepts, [concept1])
# check that two concepts with disjoint intents are both kept
concepts = spade.pattern_set_reduction([concept3, concept4],
ns_signatures=[],
winlen=winlen, spectrum='#')
self.assertEqual(concepts, [concept3, concept4])
@unittest.skipUnless(HAVE_STATSMODELS,
"'fdr_bh' stat corr requires statsmodels")
def test_signature_significance_fdr_bh_corr(self):
"""
A typical corr='fdr_bh' scenario, that requires statsmodels.
"""
sig_spectrum = spade.test_signature_significance(
pv_spec=((2, 3, 0.2), (2, 4, 0.05)),
concepts=([[(2, 3), (1, 2, 3)],
[(2, 4), (1, 2, 3, 4)]]),
alpha=0.15, winlen=1, corr='fdr_bh')
self.assertEqual(sig_spectrum, [(2., 3., False), (2., 4., True)])
def test_different_surrogate_method(self):
np.random.seed(0)
random.seed(0)
spiketrains = [stg.homogeneous_poisson_process(rate=20*pq.Hz)
for _ in range(2)]
surr_methods = ('dither_spikes', 'joint_isi_dithering',
'bin_shuffling',
'dither_spikes_with_refractory_period')
pv_specs = {'dither_spikes': [[2, 2, 0.8], [2, 3, 0.2]],
'joint_isi_dithering': [[2, 2, 0.8]],
'bin_shuffling': [[2, 2, 1.0], [2, 3, 0.2]],
'dither_spikes_with_refractory_period':
[[2, 2, 0.8]]}
for surr_method in surr_methods:
pv_spec = spade.pvalue_spectrum(
spiketrains, bin_size=self.bin_size,
winlen=self.winlen, dither=15*pq.ms,
n_surr=5, surr_method=surr_method)
self.assertEqual(pv_spec, pv_specs[surr_method])
def suite():
suite = unittest.makeSuite(SpadeTestCase, 'test')
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite())
|
bsd-3-clause
|
[
624,
199,
5072,
2295,
367,
314,
5844,
271,
859,
14,
199,
199,
26,
7307,
26,
1898,
6927,
13,
9261,
701,
314,
662,
274,
838,
867,
8099,
12,
1937,
658,
1301,
15,
8149,
14,
8332,
2313,
199,
26,
1682,
26,
22016,
6289,
12,
1937,
5113,
14,
2424,
367,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
984,
199,
646,
2882,
199,
646,
2196,
199,
199,
646,
1279,
79,
199,
646,
2680,
465,
980,
199,
646,
13621,
1417,
465,
29158,
199,
504,
2680,
14,
4776,
14,
1208,
492,
702,
63,
1144,
63,
1452,
199,
199,
646,
12993,
838,
867,
14,
15083,
465,
8260,
199,
646,
12993,
838,
867,
14,
3770,
271,
465,
5844,
271,
199,
646,
12993,
838,
867,
14,
29774,
63,
2834,
63,
15043,
465,
410,
71,
199,
199,
893,
26,
272,
492,
5020,
992,
272,
25227,
63,
19202,
11429,
51,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
19202,
11429,
51,
275,
756,
199,
199,
1548,
63,
1023,
63,
8452,
275,
984,
14,
1023,
63,
815,
14,
8452,
199,
199,
10767,
63,
38,
1469,
275,
5844,
271,
14,
10767,
63,
38,
1469,
421,
199,
533,
17812,
271,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
980,
14,
2355,
14,
5176,
8,
16,
9,
267,
327,
17812,
271,
2633,
267,
291,
14,
1393,
63,
890,
275,
413,
627,
29158,
14,
706,
267,
291,
14,
2676,
552,
275,
1616,
267,
291,
14,
78,
63,
9401,
275,
1616,
267,
291,
14,
78,
63,
5105,
82,
275,
1616,
267,
291,
14,
4468,
275,
378,
14,
1717,
267,
291,
14,
270,
3616,
63,
14898,
275,
359,
16,
14,
17,
12,
378,
14,
17,
61,
267,
291,
14,
1190,
82,
63,
635,
275,
359,
16,
12,
378,
12,
378,
61,
267,
291,
14,
827,
63,
679,
67,
275,
841,
267,
291,
14,
827,
63,
32757,
397,
275,
841,
267,
291,
14,
988,
63,
679,
67,
275,
841,
267,
291,
14,
988,
63,
32757,
397,
275,
841,
267,
291,
14,
827,
63,
685,
85,
275,
841,
267,
327,
1379,
666,
2633,
267,
327,
28635,
2633,
267,
291,
14,
78,
63,
685,
85,
275,
2948,
267,
291,
14,
31928,
275,
359,
16,
61,
627,
291,
14,
78,
63,
685,
85,
435,
359,
17,
61,
267,
291,
14,
5910,
275,
410,
71,
14,
5910,
8,
288,
6634,
29,
19,
627,
29158,
14,
13026,
12,
288,
30727,
63,
4972,
29,
277,
14,
31928,
12,
288,
307,
63,
2379,
29,
21,
627,
29158,
14,
83,
9,
267,
327,
4860,
402,
7970,
7,
22099,
267,
291,
14,
78,
63,
679,
67,
17,
275,
1616,
267,
291,
14,
78,
63,
679,
67,
18,
275,
3144,
267,
291,
14,
78,
63,
679,
67,
19,
275,
4114,
267,
327,
510,
4823,
1127,
458,
267,
291,
14,
1550,
17,
275,
359,
18,
61,
267,
291,
14,
1550,
18,
275,
359,
17,
12,
650,
61,
267,
291,
14,
1550,
19,
275,
359,
17,
12,
499,
12,
841,
12,
959,
12,
1520,
61,
267,
327,
19893,
402,
314,
19441,
75,
386,
6322,
267,
291,
14,
84,
63,
2379,
275,
29664,
267,
327,
510,
4823,
5431,
267,
291,
14,
80,
6796,
17,
63,
4508,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
288,
980,
14,
5605,
8,
355,
378,
12,
5198,
12,
5198,
5001,
291,
14,
78,
63,
679,
67,
17,
9,
627,
288,
29158,
14,
706,
12,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
267,
291,
14,
80,
6796,
18,
63,
4508,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
288,
980,
14,
5605,
8,
355,
5198,
12,
12293,
12,
5198,
5001,
291,
14,
78,
63,
679,
67,
18,
31280,
17,
61,
627,
288,
29158,
14,
706,
12,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
267,
291,
14,
80,
6796,
19,
63,
4508,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
288,
980,
14,
5605,
8,
355,
12293,
12,
29664,
12,
5198,
5001,
291,
14,
78,
63,
679,
67,
19,
31280,
17,
61,
627,
288,
29158,
14,
706,
12,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
267,
327,
510,
4823,
267,
291,
14,
80,
6796,
17,
275,
359,
277,
14,
80,
6796,
17,
63,
4508,
61,
435,
359,
685,
79,
14,
51,
1038,
415,
18591,
8,
288,
291,
14,
80,
6796,
17,
63,
4508,
14,
1345,
8,
26295,
14,
19703,
9,
435,
17891,
627,
29158,
14,
706,
12,
288,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
367,
17891,
315,
291,
14,
1550,
17,
61,
267,
291,
14,
80,
6796,
18,
275,
359,
277,
14,
80,
6796,
18,
63,
4508,
61,
435,
359,
685,
79,
14,
51,
1038,
415,
18591,
8,
288,
291,
14,
80,
6796,
18,
63,
4508,
14,
1345,
8,
26295,
14,
19703,
9,
435,
17891,
627,
29158,
14,
706,
12,
288,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
367,
17891,
315,
291,
14,
1550,
18,
61,
267,
291,
14,
80,
6796,
19,
275,
359,
277,
14,
80,
6796,
19,
63,
4508,
61,
435,
359,
685,
79,
14,
51,
1038,
415,
18591,
8,
288,
291,
14,
80,
6796,
19,
63,
4508,
14,
1345,
8,
26295,
14,
19703,
9,
435,
17891,
627,
29158,
14,
706,
12,
288,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
367,
17891,
315,
291,
14,
1550,
19,
61,
267,
327,
3918,
267,
291,
14,
77,
17839,
275,
291,
14,
80,
6796,
17,
435,
291,
14,
80,
6796,
18,
435,
291,
14,
80,
6796,
19,
267,
327,
13796,
2058,
267,
291,
14,
78,
63,
681,
75,
17,
275,
822,
8,
277,
14,
1550,
17,
9,
435,
413,
267,
291,
14,
78,
63,
681,
75,
18,
275,
822,
8,
277,
14,
1550,
18,
9,
435,
413,
267,
291,
14,
78,
63,
681,
75,
19,
275,
822,
8,
277,
14,
1550,
19,
9,
435,
413,
267,
291,
14,
5527,
17,
275,
769,
8,
1842,
8,
277,
14,
78,
63,
681,
75,
17,
430,
267,
291,
14,
5527,
18,
275,
769,
8,
1842,
8,
277
] |
[
199,
5072,
2295,
367,
314,
5844,
271,
859,
14,
199,
199,
26,
7307,
26,
1898,
6927,
13,
9261,
701,
314,
662,
274,
838,
867,
8099,
12,
1937,
658,
1301,
15,
8149,
14,
8332,
2313,
199,
26,
1682,
26,
22016,
6289,
12,
1937,
5113,
14,
2424,
367,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
984,
199,
646,
2882,
199,
646,
2196,
199,
199,
646,
1279,
79,
199,
646,
2680,
465,
980,
199,
646,
13621,
1417,
465,
29158,
199,
504,
2680,
14,
4776,
14,
1208,
492,
702,
63,
1144,
63,
1452,
199,
199,
646,
12993,
838,
867,
14,
15083,
465,
8260,
199,
646,
12993,
838,
867,
14,
3770,
271,
465,
5844,
271,
199,
646,
12993,
838,
867,
14,
29774,
63,
2834,
63,
15043,
465,
410,
71,
199,
199,
893,
26,
272,
492,
5020,
992,
272,
25227,
63,
19202,
11429,
51,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
19202,
11429,
51,
275,
756,
199,
199,
1548,
63,
1023,
63,
8452,
275,
984,
14,
1023,
63,
815,
14,
8452,
199,
199,
10767,
63,
38,
1469,
275,
5844,
271,
14,
10767,
63,
38,
1469,
421,
199,
533,
17812,
271,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
980,
14,
2355,
14,
5176,
8,
16,
9,
267,
327,
17812,
271,
2633,
267,
291,
14,
1393,
63,
890,
275,
413,
627,
29158,
14,
706,
267,
291,
14,
2676,
552,
275,
1616,
267,
291,
14,
78,
63,
9401,
275,
1616,
267,
291,
14,
78,
63,
5105,
82,
275,
1616,
267,
291,
14,
4468,
275,
378,
14,
1717,
267,
291,
14,
270,
3616,
63,
14898,
275,
359,
16,
14,
17,
12,
378,
14,
17,
61,
267,
291,
14,
1190,
82,
63,
635,
275,
359,
16,
12,
378,
12,
378,
61,
267,
291,
14,
827,
63,
679,
67,
275,
841,
267,
291,
14,
827,
63,
32757,
397,
275,
841,
267,
291,
14,
988,
63,
679,
67,
275,
841,
267,
291,
14,
988,
63,
32757,
397,
275,
841,
267,
291,
14,
827,
63,
685,
85,
275,
841,
267,
327,
1379,
666,
2633,
267,
327,
28635,
2633,
267,
291,
14,
78,
63,
685,
85,
275,
2948,
267,
291,
14,
31928,
275,
359,
16,
61,
627,
291,
14,
78,
63,
685,
85,
435,
359,
17,
61,
267,
291,
14,
5910,
275,
410,
71,
14,
5910,
8,
288,
6634,
29,
19,
627,
29158,
14,
13026,
12,
288,
30727,
63,
4972,
29,
277,
14,
31928,
12,
288,
307,
63,
2379,
29,
21,
627,
29158,
14,
83,
9,
267,
327,
4860,
402,
7970,
7,
22099,
267,
291,
14,
78,
63,
679,
67,
17,
275,
1616,
267,
291,
14,
78,
63,
679,
67,
18,
275,
3144,
267,
291,
14,
78,
63,
679,
67,
19,
275,
4114,
267,
327,
510,
4823,
1127,
458,
267,
291,
14,
1550,
17,
275,
359,
18,
61,
267,
291,
14,
1550,
18,
275,
359,
17,
12,
650,
61,
267,
291,
14,
1550,
19,
275,
359,
17,
12,
499,
12,
841,
12,
959,
12,
1520,
61,
267,
327,
19893,
402,
314,
19441,
75,
386,
6322,
267,
291,
14,
84,
63,
2379,
275,
29664,
267,
327,
510,
4823,
5431,
267,
291,
14,
80,
6796,
17,
63,
4508,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
288,
980,
14,
5605,
8,
355,
378,
12,
5198,
12,
5198,
5001,
291,
14,
78,
63,
679,
67,
17,
9,
627,
288,
29158,
14,
706,
12,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
267,
291,
14,
80,
6796,
18,
63,
4508,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
288,
980,
14,
5605,
8,
355,
5198,
12,
12293,
12,
5198,
5001,
291,
14,
78,
63,
679,
67,
18,
31280,
17,
61,
627,
288,
29158,
14,
706,
12,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
267,
291,
14,
80,
6796,
19,
63,
4508,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
288,
980,
14,
5605,
8,
355,
12293,
12,
29664,
12,
5198,
5001,
291,
14,
78,
63,
679,
67,
19,
31280,
17,
61,
627,
288,
29158,
14,
706,
12,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
267,
327,
510,
4823,
267,
291,
14,
80,
6796,
17,
275,
359,
277,
14,
80,
6796,
17,
63,
4508,
61,
435,
359,
685,
79,
14,
51,
1038,
415,
18591,
8,
288,
291,
14,
80,
6796,
17,
63,
4508,
14,
1345,
8,
26295,
14,
19703,
9,
435,
17891,
627,
29158,
14,
706,
12,
288,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
367,
17891,
315,
291,
14,
1550,
17,
61,
267,
291,
14,
80,
6796,
18,
275,
359,
277,
14,
80,
6796,
18,
63,
4508,
61,
435,
359,
685,
79,
14,
51,
1038,
415,
18591,
8,
288,
291,
14,
80,
6796,
18,
63,
4508,
14,
1345,
8,
26295,
14,
19703,
9,
435,
17891,
627,
29158,
14,
706,
12,
288,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
367,
17891,
315,
291,
14,
1550,
18,
61,
267,
291,
14,
80,
6796,
19,
275,
359,
277,
14,
80,
6796,
19,
63,
4508,
61,
435,
359,
685,
79,
14,
51,
1038,
415,
18591,
8,
288,
291,
14,
80,
6796,
19,
63,
4508,
14,
1345,
8,
26295,
14,
19703,
9,
435,
17891,
627,
29158,
14,
706,
12,
288,
307,
63,
2379,
29,
277,
14,
84,
63,
2379,
627,
29158,
14,
706,
9,
367,
17891,
315,
291,
14,
1550,
19,
61,
267,
327,
3918,
267,
291,
14,
77,
17839,
275,
291,
14,
80,
6796,
17,
435,
291,
14,
80,
6796,
18,
435,
291,
14,
80,
6796,
19,
267,
327,
13796,
2058,
267,
291,
14,
78,
63,
681,
75,
17,
275,
822,
8,
277,
14,
1550,
17,
9,
435,
413,
267,
291,
14,
78,
63,
681,
75,
18,
275,
822,
8,
277,
14,
1550,
18,
9,
435,
413,
267,
291,
14,
78,
63,
681,
75,
19,
275,
822,
8,
277,
14,
1550,
19,
9,
435,
413,
267,
291,
14,
5527,
17,
275,
769,
8,
1842,
8,
277,
14,
78,
63,
681,
75,
17,
430,
267,
291,
14,
5527,
18,
275,
769,
8,
1842,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
telefonicaid/selenium
|
wire.py
|
22
|
83032
|
# Copyright 2008-2010 WebDriver committers
# Copyright 2008-2010 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Script for generating the wire protocol wiki documentation.
This script is probably overkill, but it ensures commands are documented with
consistent formatting.
Usage:
python trunk/wire.py --help
"""
import logging
import optparse
import os
import re
import sys
DEFAULT_WIKI_PATH = os.path.join('..', 'wiki', 'JsonWireProtocol.wiki')
class Resource(object):
def __init__(self, path):
self.path = path
self.methods = []
def __getattribute__(self, attr):
try:
return super(Resource, self).__getattribute__(attr)
except AttributeError, e:
if self.methods:
return self.methods[len(self.methods) - 1].__getattribute__(attr)
raise e
def Post(self, summary):
return self.AddMethod(Method(self, 'POST', summary))
def Get(self, summary):
return self.AddMethod(Method(self, 'GET', summary))
def Delete(self, summary):
return self.AddMethod(Method(self, 'DELETE', summary))
def AddMethod(self, method):
self.methods.append(method)
return self
def ToWikiString(self):
str = '=== %s ===\n' % self.path
for method in self.methods:
str = '%s%s' % (str, method.ToWikiString(self.path))
return str
def ToWikiTableString(self):
return ''.join(m.ToWikiTableString() for m in self.methods)
class SessionResource(Resource):
def AddMethod(self, method):
return (Resource.AddMethod(self, method).
AddUrlParameter(':sessionId',
'ID of the session to route the command to.'))
class ElementResource(SessionResource):
def AddMethod(self, method):
return (SessionResource.AddMethod(self, method).
AddUrlParameter(':id',
'ID of the element to route the command to.').
AddError('StaleElementReference',
'If the element referenced by `:id` is no longer attached '
'to the page\'s DOM.'))
def RequiresVisibility(self):
return self.AddError('ElementNotVisible',
'If the referenced element is not visible on the page '
'(either is hidden by CSS, has 0-width, or has 0-height)')
def RequiresEnabledState(self):
return self.AddError('InvalidElementState',
'If the referenced element is disabled.')
class Method(object):
def __init__(self, parent, method, summary):
self.parent = parent
self.method = method
self.summary = summary
self.url_parameters = []
self.json_parameters = []
self.return_type = None
self.errors = {}
def AddUrlParameter(self, name, description):
self.url_parameters.append({
'name': name,
'desc': description})
return self.parent
def AddJsonParameter(self, name, type, description):
self.json_parameters.append({
'name': name,
'type': type,
'desc': description})
return self.parent
def AddError(self, type, summary):
self.errors[type] = {'type': type, 'summary': summary}
return self.parent
def SetReturnType(self, type, description):
self.return_type = {
'type': type,
'desc': description}
return self.parent
def _GetUrlParametersWikiString(self):
if not self.url_parameters:
return ''
return '''
<dd>
<dl>
<dt>*URL Parameters:*</dt>
%s
</dl>
</dd>''' % '\n'.join('<dd>`%s` - %s</dd>' %
(param['name'], param['desc'])
for param in self.url_parameters)
def _GetJsonParametersWikiString(self):
if not self.json_parameters:
return ''
return '''
<dd>
<dl>
<dt>*JSON Parameters:*</dt>
%s
</dl>
</dd>''' % '\n'.join('<dd>`%s` - `%s` %s</dd>' %
(param['name'], param['type'], param['desc'])
for param in self.json_parameters)
def _GetReturnTypeWikiString(self):
if not self.return_type:
return ''
type = ''
if self.return_type['type']:
type = '`%s` ' % self.return_type['type']
return '''
<dd>
<dl>
<dt>*Returns:*</dt>
<dd>%s%s</dd>
</dl>
</dd>''' % (type, self.return_type['desc'])
def _GetErrorWikiString(self):
if not self.errors.values():
return ''
return '''
<dd>
<dl>
<dt>*Potential Errors:*</dt>
%s
</dl>
</dd>''' % '\n'.join('<dd>`%s` - %s</dd>' %
(error['type'], error['summary'])
for error in self.errors.values())
def ToWikiString(self, path):
return '''
<dl>
<dd>
==== %s %s ====
</dd>
<dd>
<dl>
<dd>%s</dd>%s%s%s%s
</dl>
</dd>
</dl>
''' % (self.method, path, self.summary,
self._GetUrlParametersWikiString(),
self._GetJsonParametersWikiString(),
self._GetReturnTypeWikiString(),
self._GetErrorWikiString())
def ToWikiTableString(self):
return '|| %s || [#%s_%s %s] || %s ||\n' % (
self.method, self.method, self.parent.path, self.parent.path,
self.summary[:self.summary.find('.') + 1].replace('\n', '').strip())
class ErrorCode(object):
def __init__(self, code, summary, detail):
self.code = code
self.summary = summary
self.detail = detail
def ToWikiTableString(self):
return '|| %d || `%s` || %s ||' % (self.code, self.summary, self.detail)
class AbstractErrorCodeGatherer(object):
def __init__(self, name, path_to_error_codes, regex):
self.name = name
self.path_to_error_codes = path_to_error_codes
self.regex = regex
def __str__(self):
return self.name
def get_error_codes(self):
error_codes = {}
error_codes_file = open(self.path_to_error_codes, 'r')
try:
for line in error_codes_file:
match = self.regex.match(line)
if match is not None:
name, code = self.extract_from_match(match)
error_codes[code] = name
finally:
error_codes_file.close()
return error_codes
def extract_from_match(self, match):
raise NotImplementedError
class JavaErrorCodeGatherer(AbstractErrorCodeGatherer):
def __init__(self, path_to_error_codes):
super(JavaErrorCodeGatherer, self).__init__( \
'Java',
path_to_error_codes, \
re.compile('^\s*public static final int ([A-Z_]+) = (\d+);$'))
def extract_from_match(self, match):
return match.group(1), int(match.group(2))
class JavascriptErrorCodeGatherer(AbstractErrorCodeGatherer):
def __init__(self, path_to_error_codes, name):
super(JavascriptErrorCodeGatherer, self).__init__( \
name,
path_to_error_codes, \
re.compile('^\s*([A-Z_]+): (\d+)'))
def extract_from_match(self, match):
return match.group(1), int(match.group(2))
class RubyErrorCodeGatherer(AbstractErrorCodeGatherer):
def __init__(self, path_to_error_codes):
super(RubyErrorCodeGatherer, self).__init__( \
'Ruby',
path_to_error_codes, \
re.compile('^\s*(([A-Z][a-z]*)+),?\s*# (\d+)$'))
def extract_from_match(self, match):
return match.group(1), int(match.group(len(match.groups())))
class PythonErrorCodeGatherer(AbstractErrorCodeGatherer):
def __init__(self, path_to_error_codes):
super(PythonErrorCodeGatherer, self).__init__( \
'Python',
path_to_error_codes, \
re.compile('^\s*([A-Z_]+) = (\d+)$'))
def extract_from_match(self, match):
return match.group(1), int(match.group(2))
class CErrorCodeGatherer(AbstractErrorCodeGatherer):
def __init__(self, path_to_error_codes):
super(CErrorCodeGatherer, self).__init__( \
'C',
path_to_error_codes, \
re.compile('^#define ([A-Z]+)\s+(\d+)$'))
def extract_from_match(self, match):
return match.group(1), int(match.group(2))
class CSharpErrorCodeGatherer(AbstractErrorCodeGatherer):
def __init__(self, path_to_error_codes):
super(CSharpErrorCodeGatherer, self).__init__( \
'C#',
path_to_error_codes, \
re.compile('^\s*(([A-Z][a-z]*)+) = (\d+)'))
def extract_from_match(self, match):
return match.group(1), int(match.group(len(match.groups())))
class ErrorCodeChecker(object):
def __init__(self):
self.gatherers = []
self.inconsistencies = {}
def using(self, gatherer):
self.gatherers.append(gatherer)
return self
def check_error_codes_are_consistent(self, json_error_codes):
logging.info('Checking error codes are consistent across languages and \
browsers')
num_missing = 0
for gatherer in self.gatherers:
if not os.path.exists(gatherer.path_to_error_codes):
logging.warn(' Unable to locate error codes for %s (//%s)',
gatherer, gatherer.path_to_error_codes)
num_missing += 1
else:
self.compare(gatherer, json_error_codes)
if not num_missing and not self.inconsistencies:
logging.info('All error codes are consistent')
return False
for code,(present,missing) in self.inconsistencies.items():
logging.error('Error code %d was present in %s but not %s',
code, present, missing)
return True
def add_inconsistency(self, code, present_in, missing_from):
if self.inconsistencies.has_key(code):
already_present, already_missing = self.inconsistencies[code]
already_present.add(present_in)
already_missing.add(missing_from)
else:
self.inconsistencies[code] = (set([present_in]), set([missing_from]))
def compare(self, gatherer, raw_json_error_codes):
logging.info('Checking %s (%s)' % (gatherer, gatherer.path_to_error_codes))
gathered_error_codes = gatherer.get_error_codes()
json_error_codes = map(lambda code: code.code, raw_json_error_codes)
for json_error_code in json_error_codes:
if not gathered_error_codes.has_key(json_error_code):
self.add_inconsistency(json_error_code, 'JSON', str(gatherer))
for gathered_code,_ in gathered_error_codes.items():
if not gathered_code in json_error_codes:
self.add_inconsistency(gathered_code, str(gatherer), 'JSON')
def GetDefaultWikiPath():
dirname = os.path.dirname(__file__)
if not dirname:
return DEFAULT_WIKI_PATH
return os.path.join('.', dirname, DEFAULT_WIKI_PATH)
def ChangeToTrunk():
dirname = os.path.dirname(__file__)
if dirname:
logging.info('Changing to %s', os.path.abspath(dirname))
os.chdir(dirname)
def main():
logging.basicConfig(format='[ %(filename)s ] %(message)s',
level=logging.INFO)
default_path = GetDefaultWikiPath()
parser = optparse.OptionParser('Usage: %prog [options]')
parser.add_option('-c', '--check_error_codes', dest='check_errors',
default=False,
help='Whether to abort if error codes are inconsistent.')
parser.add_option('-w', '--wiki', dest='wiki', metavar='FILE',
default=default_path,
help='Which file to write to. Defaults to %default')
(options, args) = parser.parse_args()
wiki_path = options.wiki
if wiki_path is not default_path:
wiki_path = os.path.abspath(wiki_path)
if not os.path.exists(wiki_path):
logging.error('Unable to locate wiki file: %s', wiki_path)
parser.print_help()
sys.exit(2)
wiki_path = os.path.abspath(wiki_path)
ChangeToTrunk()
error_codes = [
ErrorCode(0, 'Success', 'The command executed successfully.'),
ErrorCode(6, 'NoSuchDriver', 'A session is either terminated or not started'),
ErrorCode(7, 'NoSuchElement', 'An element could not be located on the \
page using the given search parameters.'),
ErrorCode(8, 'NoSuchFrame', 'A request to switch to a frame could not be \
satisfied because the frame could not be found.'),
ErrorCode(9, 'UnknownCommand', 'The requested resource could not be \
found, or a request was received using an HTTP method that is not supported \
by the mapped resource.'),
ErrorCode(10, 'StaleElementReference', 'An element command failed \
because the referenced element is no longer attached to the DOM.'),
ErrorCode(11, 'ElementNotVisible', 'An element command could not \
be completed because the element is not visible on the page.'),
ErrorCode(12, 'InvalidElementState', 'An element command could not be \
completed because the element is in an invalid state (e.g. attempting to \
click a disabled element).'),
ErrorCode(13, 'UnknownError', 'An unknown server-side error occurred \
while processing the command.'),
ErrorCode(15, 'ElementIsNotSelectable', 'An attempt was made to select \
an element that cannot be selected.'),
ErrorCode(17, 'JavaScriptError', 'An error occurred while executing user \
supplied !JavaScript.'),
ErrorCode(19, 'XPathLookupError', 'An error occurred while searching for \
an element by XPath.'),
ErrorCode(21, 'Timeout', 'An operation did not complete before its \
timeout expired.'),
ErrorCode(23, 'NoSuchWindow', 'A request to switch to a different window \
could not be satisfied because the window could not be found.'),
ErrorCode(24, 'InvalidCookieDomain', 'An illegal attempt was made to set \
a cookie under a different domain than the current page.'),
ErrorCode(25, 'UnableToSetCookie', 'A request to set a cookie\'s value \
could not be satisfied.'),
ErrorCode(26, 'UnexpectedAlertOpen', 'A modal dialog was open, blocking \
this operation'),
ErrorCode(27, 'NoAlertOpenError', 'An attempt was made to operate on a \
modal dialog when one was not open.'),
ErrorCode(28, 'ScriptTimeout', 'A script did not complete before its \
timeout expired.'),
ErrorCode(29, 'InvalidElementCoordinates', 'The coordinates provided to \
an interactions operation are invalid.'),
ErrorCode(30, 'IMENotAvailable', 'IME was not available.'),
ErrorCode(31, 'IMEEngineActivationFailed', 'An IME engine could not be \
started.'),
ErrorCode(32, 'InvalidSelector', 'Argument was an invalid selector \
(e.g. XPath/CSS).'),
ErrorCode(33, 'SessionNotCreatedException', 'A new session could not be created.'),
ErrorCode(34, 'MoveTargetOutOfBounds', 'Target provided for a move action is out of bounds.')
]
error_checker = ErrorCodeChecker() \
.using(JavaErrorCodeGatherer('java/client/src/org/openqa/selenium/remote/ErrorCodes.java')) \
.using(JavascriptErrorCodeGatherer('javascript/atoms/error.js', 'Javascript atoms')) \
.using(JavascriptErrorCodeGatherer('javascript/firefox-driver/js/errorcode.js', 'Javascript firefox driver')) \
.using(RubyErrorCodeGatherer('rb/lib/selenium/webdriver/common/error.rb')) \
.using(PythonErrorCodeGatherer('py/selenium/webdriver/remote/errorhandler.py')) \
.using(CErrorCodeGatherer('cpp/webdriver-interactions/errorcodes.h')) \
.using(CSharpErrorCodeGatherer('dotnet/src/WebDriver/WebDriverResult.cs'))
if (not error_checker.check_error_codes_are_consistent(error_codes)
and options.check_errors):
sys.exit(1)
resources = []
resources.append(Resource('/status').
Get('''
Query the server\'s current status. The server should respond with a general \
"HTTP 200 OK" response if it is alive and accepting commands. The response \
body should be a JSON object describing the state of the server. All server \
implementations should return two basic objects describing the server's \
current platform and when the server was built. All fields are optional; \
if omitted, the client should assume the value is uknown. Furthermore, \
server implementations may include additional fields not listed here.
|| *Key* || *Type* || *Description* ||
|| build || object || ||
|| build.version || string || A generic release label (i.e. "2.0rc3") ||
|| build.revision || string || The revision of the local source control client \
from which the server was built ||
|| build.time || string || A timestamp from when the server was built. ||
|| os || object || ||
|| os.arch || string || The current system architecture. ||
|| os.name || string || The name of the operating system the server is \
currently running on: "windows", "linux", etc. ||
|| os.version || string || The operating system version. ||
''').
SetReturnType('{object}',
'An object describing the general status of the server.'))
resources.append(
Resource('/session').
Post('''
Create a new session. The server should attempt to create a session that most \
closely matches the desired and required capabilities. Required capabilities \
have higher priority than desired capabilities and must be set for the session \
to be created.''').
AddJsonParameter('desiredCapabilities',
'{object}',
'An object describing the session\'s '
'[#Desired_Capabilities desired capabilities].').
AddJsonParameter('requiredCapabilities',
'{object}',
'An object describing the session\'s '
'[#Desired_Capabilities required capabilities] (Optional).').
SetReturnType('{object}',
'An object describing the session\'s '
'[#Actual_Capabilities capabilities].').
AddError('SessionNotCreatedException', 'If a required capability could not be set.'))
resources.append(
Resource('/sessions').
Get('''
Returns a list of the currently active sessions. Each session will be \
returned as a list of JSON objects with the following keys:
|| *Key* || *Type* || *Description ||
|| id || string || The session ID. ||
|| capabilities || object || An object describing the session's \
[#Actual_Capabilities capabilities]. ||
''').
SetReturnType('{Array.<Object>}',
'A list of the currently active sessions.'))
resources.append(
SessionResource('/session/:sessionId').
Get('Retrieve the capabilities of the specified session.').
SetReturnType('{object}',
'An object describing the session\'s '
'[#Actual_Capabilities capabilities].').
Delete('Delete the session.'))
resources.append(
SessionResource('/session/:sessionId/timeouts').
Post('''
Configure the amount of time that a particular type of operation can execute \
for before they are aborted and a |Timeout| error is returned to the \
client.''').
AddJsonParameter('type', '{string}',
'The type of operation to set the timeout for. Valid \
values are: "script" for script timeouts, "implicit" for modifying the \
implicit wait timeout and "page load" for setting a page load timeout.').
AddJsonParameter('ms', '{number}',
'The amount of time, in milliseconds, that time-limited'
' commands are permitted to run.'))
resources.append(
SessionResource('/session/:sessionId/timeouts/async_script').
Post('''Set the amount of time, in milliseconds, that asynchronous \
scripts executed by `/session/:sessionId/execute_async` are permitted to run \
before they are aborted and a |Timeout| error is returned to the client.''').
AddJsonParameter('ms', '{number}',
'The amount of time, in milliseconds, that time-limited'
' commands are permitted to run.'))
resources.append(
SessionResource('/session/:sessionId/timeouts/implicit_wait').
Post('''Set the amount of time the driver should wait when searching for \
elements. When
searching for a single element, the driver should poll the page until an \
element is found or
the timeout expires, whichever occurs first. When searching for multiple \
elements, the driver
should poll the page until at least one element is found or the timeout \
expires, at which point
it should return an empty list.
If this command is never sent, the driver should default to an implicit wait of\
0ms.''').
AddJsonParameter('ms', '{number}',
'The amount of time to wait, in milliseconds. This value'
' has a lower bound of 0.'))
resources.append(
SessionResource('/session/:sessionId/window_handle').
Get('Retrieve the current window handle.').
SetReturnType('{string}', 'The current window handle.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/window_handles').
Get('Retrieve the list of all window handles available to the session.').
SetReturnType('{Array.<string>}', 'A list of window handles.'))
resources.append(
SessionResource('/session/:sessionId/url').
Get('Retrieve the URL of the current page.').
SetReturnType('{string}', 'The current URL.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
Post('Navigate to a new URL.').
AddJsonParameter('url', '{string}', 'The URL to navigate to.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/forward').
Post('Navigate forwards in the browser history, if possible.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/back').
Post('Navigate backwards in the browser history, if possible.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/refresh').
Post('Refresh the current page.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/execute').
Post('''
Inject a snippet of !JavaScript into the page for execution in the context of \
the currently selected frame. The executed script is assumed to be \
synchronous and the result of evaluating the script is returned to the client.
The `script` argument defines the script to execute in the form of a \
function body. The value returned by that function will be returned to the \
client. The function will be invoked with the provided `args` array and the \
values may be accessed via the `arguments` object in the order specified.
Arguments may be any JSON-primitive, array, or JSON object. JSON objects that \
define a [#WebElement_JSON_Object WebElement reference] will be converted to \
the corresponding DOM element. Likewise, any !WebElements in the script result \
will be returned to the client as [#WebElement_JSON_Object WebElement \
JSON objects].''').
AddJsonParameter('script', '{string}', 'The script to execute.').
AddJsonParameter('args', '{Array.<*>}', 'The script arguments.').
AddError('JavaScriptError', 'If the script throws an Error.').
AddError('StaleElementReference',
'If one of the script arguments is a !WebElement that is not '
'attached to the page\'s DOM.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
SetReturnType('{*}', 'The script result.'))
resources.append(
SessionResource('/session/:sessionId/execute_async').
Post('''
Inject a snippet of !JavaScript into the page for execution in the context of \
the currently selected frame. The executed script is assumed to be \
asynchronous and must signal that is done by invoking the provided callback, \
which is always provided as the final argument to the function. The value \
to this callback will be returned to the client.
Asynchronous script commands may not span page loads. If an `unload` event is \
fired while waiting for a script result, an error should be returned to the \
client.
The `script` argument defines the script to execute in teh form of a function \
body. The function will be invoked with the provided `args` array and the \
values may be accessed via the `arguments` object in the order specified. The \
final argument will always be a callback function that must be invoked to \
signal that the script has finished.
Arguments may be any JSON-primitive, array, or JSON object. JSON objects that \
define a [#WebElement_JSON_Object WebElement reference] will be converted to \
the corresponding DOM element. Likewise, any !WebElements in the script result \
will be returned to the client as [#WebElement_JSON_Object WebElement \
JSON objects].''').
AddJsonParameter('script', '{string}', 'The script to execute.').
AddJsonParameter('args', '{Array.<*>}', 'The script arguments.').
AddError('JavaScriptError',
'If the script throws an Error or if an `unload` event is '
'fired while waiting for the script to finish.').
AddError('StaleElementReference',
'If one of the script arguments is a !WebElement that is not '
'attached to the page\'s DOM.').
AddError('Timeout',
'If the script callback is not invoked before the timout '
'expires. Timeouts are controlled by the '
'`/session/:sessionId/timeout/async_script` command.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
SetReturnType('{*}', 'The script result.'))
resources.append(
SessionResource('/session/:sessionId/screenshot').
Get('Take a screenshot of the current page.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
SetReturnType('{string}', 'The screenshot as a base64 encoded PNG.'))
resources.append(
SessionResource('/session/:sessionId/ime/available_engines').
Get('List all available engines on the machine. To use an engine, it has to be present in this list.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetReturnType('{Array.<string>}', 'A list of available engines'))
resources.append(
SessionResource('/session/:sessionId/ime/active_engine').
Get('Get the name of the active IME engine. The name string is platform specific.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetReturnType('{string}', 'The name of the active IME engine.'))
resources.append(
SessionResource('/session/:sessionId/ime/activated').
Get('Indicates whether IME input is active at the moment (not if it\'s available.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetReturnType('{boolean}',
'true if IME input is available and currently active, false otherwise'))
resources.append(
SessionResource('/session/:sessionId/ime/deactivate').
Post('De-activates the currently-active IME engine.').
AddError('ImeNotAvailableException', 'If the host does not support IME'))
resources.append(
SessionResource('/session/:sessionId/ime/activate').
Post('''Make an engines that is available (appears on the list
returned by getAvailableEngines) active. After this call, the engine will
be added to the list of engines loaded in the IME daemon and the input sent
using sendKeys will be converted by the active engine.
Note that this is a platform-independent method of activating IME
(the platform-specific way being using keyboard shortcuts''').
AddJsonParameter('engine', '{string}',
'Name of the engine to activate.').
AddError('ImeActivationFailedException',
'If the engine is not available or if the activation fails for other reasons.').
AddError('ImeNotAvailableException', 'If the host does not support IME'))
resources.append(
SessionResource('/session/:sessionId/frame').
Post('''Change focus to another frame on the page. If the frame `id` is \
`null`, the server
should switch to the page's default content.''').
AddJsonParameter('id', '{string|number|null|WebElement JSON Object}',
'Identifier for the frame to change focus to.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
AddError('NoSuchFrame', 'If the frame specified by `id` cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/frame/parent').
Post('''Change focus to the parent context. If the current context is the top level \
browsing context, the context remains unchanged.'''))
resources.append(
SessionResource('/session/:sessionId/window').
Post('''Change focus to another window. The window to change focus to \
may be specified by its
server assigned window handle, or by the value of its `name` attribute.''').
AddJsonParameter('name', '{string}', 'The window to change focus to.').
AddError('NoSuchWindow', 'If the window specified by `name` cannot be found.').
Delete('''Close the current window.''').
AddError('NoSuchWindow', 'If the currently selected window is already closed'))
resources.append(
SessionResource('/session/:sessionId/window/:windowHandle/size').
Post('''Change the size of the specified window. If the :windowHandle URL \
parameter is "current", the currently active window will be resized.''').
AddJsonParameter('width', '{number}', 'The new window width.').
AddJsonParameter('height', '{number}', 'The new window height.').
Get('''Get the size of the specified window. If the :windowHandle URL \
parameter is "current", the size of the currently active window will be returned.''').
SetReturnType('{width: number, height: number}', 'The size of the window.').
AddError('NoSuchWindow', 'If the specified window cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/window/:windowHandle/position').
Post('''Change the position of the specified window. If the :windowHandle URL \
parameter is "current", the currently active window will be moved.''').
AddJsonParameter('x', '{number}', 'The X coordinate to position the window at, \
relative to the upper left corner of the screen.').
AddJsonParameter('y', '{number}', 'The Y coordinate to position the window at, \
relative to the upper left corner of the screen.') .
AddError('NoSuchWindow', 'If the specified window cannot be found.').
Get('''Get the position of the specified window. If the :windowHandle URL \
parameter is "current", the position of the currently active window will be returned.''').
SetReturnType('{x: number, y: number}', 'The X and Y coordinates for the window, \
relative to the upper left corner of the screen.').
AddError('NoSuchWindow', 'If the specified window cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/window/:windowHandle/maximize').
Post('''Maximize the specified window if not already maximized. If the \
:windowHandle URL parameter is "current", the currently active window will be \
maximized.''').
AddError('NoSuchWindow', 'If the specified window cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/cookie').
Get('Retrieve all cookies visible to the current page.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
SetReturnType('{Array.<object>}', 'A list of [#Cookie_JSON_Object cookies].').
Post('''Set a cookie. If the [#Cookie_JSON_Object cookie] path is not \
specified, it should be set to `"/"`. Likewise, if the domain is omitted, it \
should default to the current page's domain.''').
AddJsonParameter('cookie', '{object}',
'A [#Cookie_JSON_Object JSON object] defining the '
'cookie to add.').
Delete('''Delete all cookies visible to the current page.''').
AddError('InvalidCookieDomain',
'If the cookie\'s `domain` is not visible from the current page.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
AddError('UnableToSetCookie',
'If attempting to set a cookie on a page that does not support '
'cookies (e.g. pages with mime-type `text/plain`).'))
resources.append(
SessionResource('/session/:sessionId/cookie/:name').
Delete('''Delete the cookie with the given name. This command should be \
a no-op if there is no
such cookie visible to the current page.''').
AddUrlParameter(':name', 'The name of the cookie to delete.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/source').
Get('Get the current page source.').
SetReturnType('{string}', 'The current page source.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/title').
Get('Get the current page title.').
SetReturnType('{string}', 'The current page title.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/element').
Post('''Search for an element on the page, starting from the document \
root. The located element will be returned as a WebElement JSON object. \
The table below lists the locator strategies that each server should support. \
Each locator must return the first matching element located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns an element whose class name contains the search \
value; compound class names are not permitted. ||
|| css selector || Returns an element matching a CSS selector. ||
|| id || Returns an element whose ID attribute matches the search value. ||
|| name || Returns an element whose NAME attribute matches the search value. ||
|| link text || Returns an anchor element whose visible text matches the \
search value. ||
|| partial link text || Returns an anchor element whose visible text \
partially matches the search value. ||
|| tag name || Returns an element whose tag name matches the search value. ||
|| xpath || Returns an element matching an XPath expression. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{ELEMENT:string}',
'A WebElement JSON object for the located element.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.').
AddError('NoSuchElement', 'If the element cannot be found.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/elements').
Post('''Search for multiple elements on the page, starting from the \
document root. The located elements will be returned as a WebElement JSON \
objects. The table below lists the locator strategies that each server should \
support. Elements should be returned in the order located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns all elements whose class name contains the search \
value; compound class names are not permitted. ||
|| css selector || Returns all elements matching a CSS selector. ||
|| id || Returns all elements whose ID attribute matches the search value. ||
|| name || Returns all elements whose NAME attribute matches the search value. ||
|| link text || Returns all anchor elements whose visible text matches the \
search value. ||
|| partial link text || Returns all anchor elements whose visible text \
partially matches the search value. ||
|| tag name || Returns all elements whose tag name matches the search value. ||
|| xpath || Returns all elements matching an XPath expression. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{Array.<{ELEMENT:string}>}',
'A list of WebElement JSON objects for the located elements.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/element/active').
Post('Get the element on the page that currently has focus. The element will be returned as '
'a WebElement JSON object.').
SetReturnType('{ELEMENT:string}', 'A WebElement JSON object for the active element.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id').
Get('''Describe the identified element.
*Note:* This command is reserved for future use; its return type is currently \
undefined.''').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/element').
Post('''Search for an element on the page, starting from the identified \
element. The located element will be returned as a WebElement JSON object. \
The table below lists the locator strategies that each server should support. \
Each locator must return the first matching element located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns an element whose class name contains the search \
value; compound class names are not permitted. ||
|| css selector || Returns an element matching a CSS selector. ||
|| id || Returns an element whose ID attribute matches the search value. ||
|| name || Returns an element whose NAME attribute matches the search value. ||
|| link text || Returns an anchor element whose visible text matches the \
search value. ||
|| partial link text || Returns an anchor element whose visible text \
partially matches the search value. ||
|| tag name || Returns an element whose tag name matches the search value. ||
|| xpath || Returns an element matching an XPath expression. The provided \
XPath expression must be applied to the server "as is"; if the expression is \
not relative to the element root, the server should not modify it. \
Consequently, an XPath query may return elements not contained in the root \
element's subtree. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{ELEMENT:string}',
'A WebElement JSON object for the located element.').
AddError('NoSuchElement', 'If the element cannot be found.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/elements').
Post('''Search for multiple elements on the page, starting from the \
identified element. The located elements will be returned as a WebElement \
JSON objects. The table below lists the locator strategies that each server \
should support. Elements should be returned in the order located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns all elements whose class name contains the search \
value; compound class names are not permitted. ||
|| css selector || Returns all elements matching a CSS selector. ||
|| id || Returns all elements whose ID attribute matches the search value. ||
|| name || Returns all elements whose NAME attribute matches the search value. ||
|| link text || Returns all anchor elements whose visible text matches the \
search value. ||
|| partial link text || Returns all anchor elements whose visible text \
partially matches the search value. ||
|| tag name || Returns all elements whose tag name matches the search value. ||
|| xpath || Returns all elements matching an XPath expression. The provided \
XPath expression must be applied to the server "as is"; if the expression is \
not relative to the element root, the server should not modify it. \
Consequently, an XPath query may return elements not contained in the root \
element's subtree. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{Array.<{ELEMENT:string}>}',
'A list of WebElement JSON objects for the located elements.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/click').
Post('Click on an element.').
RequiresVisibility().
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/submit').
Post('Submit a `FORM` element. The submit command may also be applied to any element that is '
'a descendant of a `FORM` element.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/text').
Get('Returns the visible text for the element.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/value').
Post('''Send a sequence of key strokes to an element.
Any UTF-8 character may be specified, however, if the server does not support \
native key events, it should simulate key strokes for a standard US keyboard \
layout. The Unicode [http://unicode.org/faq/casemap_charprop.html#8 Private Use\
Area] code points, 0xE000-0xF8FF, are used to represent pressable, non-text \
keys (see table below).
<table cellspacing=5 cellpadding=5>
<tbody><tr><td valign=top>
|| *Key* || *Code* ||
|| NULL || U+E000 ||
|| Cancel || U+E001 ||
|| Help || U+E002 ||
|| Back space || U+E003 ||
|| Tab || U+E004 ||
|| Clear || U+E005 ||
|| Return^1^ || U+E006 ||
|| Enter^1^ || U+E007 ||
|| Shift || U+E008 ||
|| Control || U+E009 ||
|| Alt || U+E00A ||
|| Pause || U+E00B ||
|| Escape || U+E00C ||
</td><td valign=top>
|| *Key* || *Code* ||
|| Space || U+E00D ||
|| Pageup || U+E00E ||
|| Pagedown || U+E00F ||
|| End || U+E010 ||
|| Home || U+E011 ||
|| Left arrow || U+E012 ||
|| Up arrow || U+E013 ||
|| Right arrow || U+E014 ||
|| Down arrow || U+E015 ||
|| Insert || U+E016 ||
|| Delete || U+E017 ||
|| Semicolon || U+E018 ||
|| Equals || U+E019 ||
</td><td valign=top>
|| *Key* || *Code* ||
|| Numpad 0 || U+E01A ||
|| Numpad 1 || U+E01B ||
|| Numpad 2 || U+E01C ||
|| Numpad 3 || U+E01D ||
|| Numpad 4 || U+E01E ||
|| Numpad 5 || U+E01F ||
|| Numpad 6 || U+E020 ||
|| Numpad 7 || U+E021 ||
|| Numpad 8 || U+E022 ||
|| Numpad 9 || U+E023 ||
</td><td valign=top>
|| *Key* || *Code* ||
|| Multiply || U+E024 ||
|| Add || U+E025 ||
|| Separator || U+E026 ||
|| Subtract || U+E027 ||
|| Decimal || U+E028 ||
|| Divide || U+E029 ||
</td><td valign=top>
|| *Key* || *Code* ||
|| F1 || U+E031 ||
|| F2 || U+E032 ||
|| F3 || U+E033 ||
|| F4 || U+E034 ||
|| F5 || U+E035 ||
|| F6 || U+E036 ||
|| F7 || U+E037 ||
|| F8 || U+E038 ||
|| F9 || U+E039 ||
|| F10 || U+E03A ||
|| F11 || U+E03B ||
|| F12 || U+E03C ||
|| Command/Meta || U+E03D ||
</td></tr>
<tr><td colspan=5>^1^ The return key is _not the same_ as the \
[http://en.wikipedia.org/wiki/Enter_key enter key].</td></tr></tbody></table>
The server must process the key sequence as follows:
* Each key that appears on the keyboard without requiring modifiers are sent \
as a keydown followed by a key up.
* If the server does not support native events and must simulate key strokes \
with !JavaScript, it must generate keydown, keypress, and keyup events, in that\
order. The keypress event should only be fired when the corresponding key is \
for a printable character.
* If a key requires a modifier key (e.g. "!" on a standard US keyboard), the \
sequence is: <var>modifier</var> down, <var>key</var> down, <var>key</var> up, \
<var>modifier</var> up, where <var>key</var> is the ideal unmodified key value \
(using the previous example, a "1").
* Modifier keys (Ctrl, Shift, Alt, and Command/Meta) are assumed to be \
"sticky"; each modifier should be held down (e.g. only a keydown event) until \
either the modifier is encountered again in the sequence, or the `NULL` \
(U+E000) key is encountered.
* Each key sequence is terminated with an implicit `NULL` key. Subsequently, \
all depressed modifier keys must be released (with corresponding keyup events) \
at the end of the sequence.
''').
RequiresVisibility().
AddJsonParameter('value', '{Array.<string>}',
'The sequence of keys to type. An array must be provided. '
'The server should flatten the array items to a single '
'string to be typed.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/keys').
Post('Send a sequence of key strokes to the active element. This '
'command is similar to the '
'[JsonWireProtocol#/session/:sessionId/element/:id/value'
' send keys] command in every aspect except the implicit '
'termination: The modifiers are *not* released at the end of the '
'call. Rather, the state of the modifier keys is kept between '
'calls, so mouse interactions can be performed while modifier '
'keys are depressed.').
AddJsonParameter('value', '{Array.<string>}',
'The keys sequence to be sent. The sequence is defined '
'in the'
'[JsonWireProtocol#/session/:sessionId/element/:id/value'
' send keys] command.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/name').
Get('Query for an element\'s tag name.').
SetReturnType('{string}', 'The element\'s tag name, as a lowercase string.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/clear').
Post('Clear a `TEXTAREA` or `text INPUT` element\'s value.').
RequiresVisibility().
RequiresEnabledState().
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/selected').
Get('Determine if an `OPTION` element, or an `INPUT` element of type `checkbox` or '
'`radiobutton` is currently selected.').
SetReturnType('{boolean}', 'Whether the element is selected.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/enabled').
Get('Determine if an element is currently enabled.').
SetReturnType('{boolean}', 'Whether the element is enabled.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/attribute/:name').
Get('Get the value of an element\'s attribute.').
SetReturnType('{string|null}',
'The value of the attribute, or null if it is not set on the element.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/equals/:other').
Get('Test if two element IDs refer to the same DOM element.').
AddUrlParameter(':other', 'ID of the element to compare against.').
SetReturnType('{boolean}', 'Whether the two IDs refer to the same element.').
AddError('StaleElementReference',
'If either the element refered to by `:id` or `:other` is no '
'longer attached to the page\'s DOM.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/displayed').
Get('Determine if an element is currently displayed.').
SetReturnType('{boolean}', 'Whether the element is displayed.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/location').
Get('Determine an element\'s location on the page. The point `(0, 0)` refers to the '
'upper-left corner of the page. The element\'s coordinates are returned as a JSON object '
'with `x` and `y` properties.').
SetReturnType('{x:number, y:number}', 'The X and Y coordinates for the element on the page.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/location_in_view').
Get('''Determine an element\'s location on the screen once it has been \
scrolled into view.
*Note:* This is considered an internal command and should *only* be used to \
determine an element's
location for correctly generating native events.''').
SetReturnType('{x:number, y:number}', 'The X and Y coordinates for the element.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/size').
Get('Determine an element\'s size in pixels. The size will be returned as a JSON object '
' with `width` and `height` properties.').
SetReturnType('{width:number, height:number}', 'The width and height of the element, in pixels.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/css/:propertyName').
Get('Query the value of an element\'s computed CSS property. The CSS property to query should'
' be specified using the CSS property name, *not* the !JavaScript property name (e.g. '
'`background-color` instead of `backgroundColor`).').
SetReturnType('{string}', 'The value of the specified CSS property.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/orientation').
Get('Get the current browser orientation. The server should return a '
'valid orientation value as defined in [http://selenium.googlecode.'
'com/git/docs/api/java/org/openqa/selenium/ScreenOrientation'
'.html ScreenOrientation]: `{LANDSCAPE|PORTRAIT}`.').
SetReturnType('{string}', 'The current browser orientation corresponding'
' to a value defined in [http://selenium.googlecode.com/'
'git/docs/api/java/org/openqa/selenium/'
'ScreenOrientation.html ScreenOrientation]: '
'`{LANDSCAPE|PORTRAIT}`.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
Post('Set the browser orientation. The orientation should be specified '
'as defined in [http://selenium.googlecode.com/git/docs/api/'
'java/org/openqa/selenium/ScreenOrientation.html ScreenOrientation]'
': `{LANDSCAPE|PORTRAIT}`.').
AddJsonParameter('orientation', '{string}',
'The new browser orientation as defined in '
'[http://selenium.googlecode.com/git/docs/api/'
'java/org/openqa/selenium/ScreenOrientation.html '
'ScreenOrientation]: `{LANDSCAPE|PORTRAIT}`.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/alert_text').
Get('Gets the text of the currently displayed JavaScript `alert()`, `confirm()`, '
'or `prompt()` dialog.').
SetReturnType('{string}', 'The text of the currently displayed alert.').
AddError('NoAlertPresent', 'If there is no alert displayed.').
Post('Sends keystrokes to a JavaScript `prompt()` dialog.').
AddJsonParameter('text', '{string}', 'Keystrokes to send to the `prompt()` dialog.').
AddError('NoAlertPresent', 'If there is no alert displayed.'))
resources.append(
SessionResource('/session/:sessionId/accept_alert').
Post('Accepts the currently displayed alert dialog. Usually, this is equivalent '
'to clicking on the \'OK\' button in the dialog.').
AddError('NoAlertPresent', 'If there is no alert displayed.'))
resources.append(
SessionResource('/session/:sessionId/dismiss_alert').
Post('Dismisses the currently displayed alert dialog. For `confirm()` and `prompt()` '
'dialogs, this is equivalent to clicking the \'Cancel\' button. For `alert()` '
'dialogs, this is equivalent to clicking the \'OK\' button.').
AddError('NoAlertPresent', 'If there is no alert displayed.'))
resources.append(
SessionResource('/session/:sessionId/moveto').
Post('Move the mouse by an offset of the specificed element. If no element '
'is specified, the move is relative to the current mouse cursor. If an '
'element is provided but no offset, the mouse will be moved to the center'
' of the element. If the element is not visible, it will be scrolled into view.').
AddJsonParameter('element', '{string}', 'Opaque ID assigned to the element to move to, as '
'described in the WebElement JSON Object. If not specified'
' or is null, the offset is relative to current position of the mouse.').
AddJsonParameter('xoffset', '{number}', 'X offset to move to, relative to the top-left '
'corner of the element. If not specified, the mouse'
' will move to the middle of the element.').
AddJsonParameter('yoffset', '{number}', 'Y offset to move to, relative to the top-left '
'corner of the element. If not specified, the mouse'
' will move to the middle of the element.'))
resources.append(
SessionResource('/session/:sessionId/click').
Post('Click any mouse button (at the coordinates set by the last moveto command). Note '
'that calling this command after calling buttondown and before calling button up '
'(or any out-of-order interactions sequence) will yield undefined behaviour).').
AddJsonParameter('button', '{number}', 'Which button, enum: `{LEFT = 0, MIDDLE = 1 '
', RIGHT = 2}`. Defaults to the left mouse button if not specified.'))
resources.append(
SessionResource('/session/:sessionId/buttondown').
Post('Click and hold the left mouse button (at the coordinates set by the last moveto '
'command). Note that the next mouse-related command that should follow is buttonup'
' . Any other mouse command (such as click or another call to buttondown) will yield'
' undefined behaviour.').
AddJsonParameter('button', '{number}', 'Which button, enum: `{LEFT = 0, MIDDLE = 1 '
', RIGHT = 2}`. Defaults to the left mouse button if not specified.'))
resources.append(
SessionResource('/session/:sessionId/buttonup').
Post('Releases the mouse button previously held (where the mouse is currently at). '
'Must be called once for every buttondown command issued. See the note in click and '
'buttondown about implications of out-of-order commands.').
AddJsonParameter('button', '{number}', 'Which button, enum: `{LEFT = 0, MIDDLE = 1 '
', RIGHT = 2}`. Defaults to the left mouse button if not specified.'))
resources.append(
SessionResource('/session/:sessionId/doubleclick').
Post('Double-clicks at the current mouse coordinates (set by moveto).'))
resources.append(
SessionResource('/session/:sessionId/touch/click').
Post('Single tap on the touch enabled device.').
AddJsonParameter('element', '{string}', 'ID of the element to single tap '
'on.'))
resources.append(
SessionResource('/session/:sessionId/touch/down').
Post('Finger down on the screen.').
AddJsonParameter('x', '{number}', 'X coordinate on the screen.').
AddJsonParameter('y', '{number}', 'Y coordinate on the screen.'))
resources.append(
SessionResource('/session/:sessionId/touch/up').
Post('Finger up on the screen.').
AddJsonParameter('x', '{number}', 'X coordinate on the screen.').
AddJsonParameter('y', '{number}', 'Y coordinate on the screen.'))
resources.append(
SessionResource('session/:sessionId/touch/move').
Post('Finger move on the screen.').
AddJsonParameter('x', '{number}', 'X coordinate on the screen.').
AddJsonParameter('y', '{number}', 'Y coordinate on the screen.'))
resources.append(
SessionResource('session/:sessionId/touch/scroll').
Post('Scroll on the touch screen using finger based motion events. Use '
'this command to start scrolling at a particular screen location.').
AddJsonParameter('element', '{string}', 'ID of the element where the '
'scroll starts.').
AddJsonParameter('xoffset', '{number}', 'The x offset in pixels to scroll '
'by.').
AddJsonParameter('yoffset', '{number}', 'The y offset in pixels to scroll '
'by.'))
resources.append(
SessionResource('session/:sessionId/touch/scroll').
Post('Scroll on the touch screen using finger based motion events. Use '
'this command if you don\'t care where the scroll starts on the '
'screen.').
AddJsonParameter('xoffset', '{number}', 'The x offset in pixels to scroll'
'by.').
AddJsonParameter('yoffset', '{number}', 'The y offset in pixels to scroll'
'by.'))
resources.append(
SessionResource('session/:sessionId/touch/doubleclick').
Post('Double tap on the touch screen using finger motion events.').
AddJsonParameter('element', '{string}', 'ID of the element to double tap '
'on.'))
resources.append(
SessionResource('session/:sessionId/touch/longclick').
Post('Long press on the touch screen using finger motion events.').
AddJsonParameter('element', '{string}', 'ID of the element to long press '
'on.'))
resources.append(
SessionResource('session/:sessionId/touch/flick').
Post('Flick on the touch screen using finger motion events. This flick'
'command starts at a particulat screen location.').
AddJsonParameter('element', '{string}', 'ID of the element where the '
'flick starts.').
AddJsonParameter('xoffset', '{number}', 'The x offset in pixels to flick '
'by.').
AddJsonParameter('yoffset', '{number}', 'The y offset in pixels to flick '
'by.').
AddJsonParameter('speed', '{number}', 'The speed in pixels per seconds.'))
resources.append(
SessionResource('session/:sessionId/touch/flick').
Post('Flick on the touch screen using finger motion events. Use this '
'flick command if you don\'t care where the flick starts on the screen.').
AddJsonParameter('xspeed', '{number}', 'The x speed in pixels per '
'second.').
AddJsonParameter('yspeed', '{number}', 'The y speed in pixels per '
'second.'))
resources.append(
SessionResource('/session/:sessionId/location').
Get('Get the current geo location.').
SetReturnType('{latitude: number, longitude: number, altitude: number}', 'The current geo location.').
Post('Set the current geo location.').
AddJsonParameter('location', '{latitude: number, longitude: number, altitude: number}', 'The new location.'))
resources.append(
SessionResource('/session/:sessionId/local_storage').
Get('Get all keys of the storage.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
SetReturnType('{Array.<string>}', 'The list of keys.').
Post('Set the storage item for the given key.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
AddJsonParameter('key', '{string}', 'The key to set.').
AddJsonParameter('value', '{string}', 'The value to set.').
Delete('Clear the storage.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/local_storage/key/:key').
Get('Get the storage item for the given key.').
AddUrlParameter(':key', 'The key to get.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
Delete('Remove the storage item for the given key.').
AddUrlParameter(':key', 'The key to remove.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/local_storage/size').
Get('Get the number of items in the storage.').
SetReturnType('{number}', 'The number of items in the storage.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/session_storage').
Get('Get all keys of the storage.').
SetReturnType('{Array.<string>}', 'The list of keys.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
Post('Set the storage item for the given key.').
AddJsonParameter('key', '{string}', 'The key to set.').
AddJsonParameter('value', '{string}', 'The value to set.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
Delete('Clear the storage.') .
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/session_storage/key/:key').
Get('Get the storage item for the given key.').
AddUrlParameter(':key', 'The key to get.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.').
Delete('Remove the storage item for the given key.').
AddUrlParameter(':key', 'The key to remove.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/session_storage/size').
Get('Get the number of items in the storage.').
SetReturnType('{number}', 'The number of items in the storage.').
AddError('NoSuchWindow',
'If the currently selected window has been closed.'))
resources.append(
SessionResource('/session/:sessionId/log').
Post('Get the log for a given log type. Log buffer is reset after each request.').
AddJsonParameter('type', '{string}', 'The [#Log_Type log type]. This must be provided.').
SetReturnType('{Array.<object>}', 'The list of [#Log_Entry_JSON_Object log entries].'))
resources.append(
SessionResource('/session/:sessionId/log/types').
Get('Get available log types.').
SetReturnType('{Array.<string>}', 'The list of available [#Log_Type log types].'))
resources.append(
SessionResource('/session/:sessionId/application_cache/status').
Get('Get the status of the html5 application cache.').
SetReturnType('{number}', 'Status code for application cache: {UNCACHED = 0, IDLE = 1, '
'CHECKING = 2, DOWNLOADING = 3, UPDATE_READY = 4, OBSOLETE = 5}'))
logging.info('Generating %s', wiki_path)
f = open(wiki_path, 'wb')
try:
f.write('''#summary A description of the protocol used by WebDriver to \
communicate with remote instances
#labels WebDriver
<wiki:comment>
========================================================
========================================================
DO NOT EDIT THIS WIKI PAGE THROUGH THE UI.
Instead, use http://selenium.googlecode.com/git/wire.py
$ svn co https://selenium.googlecode.com/svn/ --depth=empty wire_protocol
$ cd wire_protocol
$ svn update --depth=infinity ./wiki
$ svn update --depth=files ./trunk
# modify ./trunk/wire.py
$ python ./trunk/wire.py
$ svn commit ./trunk/wire.py ./wiki/JsonWireProtocol.wiki
========================================================
========================================================
</wiki:comment>
<font size=6>*The !WebDriver Wire Protocol*</font>
<font size=3>*Status:* _DRAFT_</font>
<wiki:toc max_depth="3" />
= Introduction =
All implementations of WebDriver that communicate with the browser, or a \
RemoteWebDriver server shall use a common wire protocol. This wire protocol \
defines a [http://www.google.com?q=RESTful+web+service RESTful web service] \
using [http://www.json.org JSON] over HTTP.
The protocol will assume that the WebDriver API has been "flattened", but there\
is an expectation that client implementations will take a more Object-Oriented\
approach, as demonstrated in the existing Java API. The wire protocol is\
implemented in request/response pairs of "commands" and "responses".
== Basic Terms and Concepts ==
<dl>
<dt>
==== Client ====
</dt>
<dd>The machine on which the !WebDriver API is being used.
</dd>
<dt>
==== Server ====
</dt>
<dd>The machine running the RemoteWebDriver. This term may also refer to a \
specific browser that implements the wire protocol directly, such as the \
FirefoxDriver or IPhoneDriver.
</dd>
<dt>
==== Session ====
</dt>
<dd>The server should maintain one browser per session. Commands sent to a \
session will be directed to the corresponding browser.
</dd>
<dt>
==== !WebElement ====
</dt>
<dd>An object in the !WebDriver API that represents a DOM element on the page.
</dd>
<dt>
==== !WebElement JSON Object ====
</dt>
<dd>The JSON representation of a !WebElement for transmission over the wire. \
This object will have the following properties:
|| *Key* || *Type* || *Description* ||
|| ELEMENT || string || The opaque ID assigned to the element by the server. \
This ID should be used in all subsequent commands issued against the element. ||
</dd>
<dt>
==== Capabilities JSON Object ====
</dt>
<dd>Not all server implementations will support every !WebDriver feature. \
Therefore, the client and server should use JSON objects with the properties \
listed below when describing which features a session supports.
|| *Key* || *Type* || *Description* ||
|| browserName || string || The name of the browser being used; should be one \
of `{chrome|firefox|htmlunit|internet explorer|iphone}`. ||
|| version || string || The browser version, or the empty string if unknown. ||
|| platform || string || A key specifying which platform the browser is running \
on. This value should be one of `{WINDOWS|XP|VISTA|MAC|LINUX|UNIX}`. When \
requesting a new session, the client may specify `ANY` to indicate any \
available platform may be used. ||
|| javascriptEnabled || boolean || Whether the session supports executing user \
supplied JavaScript in the context of the current page. ||
|| takesScreenshot || boolean || Whether the session supports taking \
screenshots of the current page. ||
|| handlesAlerts || boolean || Whether the session can interact with modal \
popups, such as `window.alert` and `window.confirm`. ||
|| databaseEnabled || boolean || Whether the session can interact \
database storage. ||
|| locationContextEnabled || boolean || Whether the session can set and query \
the browser's location context. ||
|| applicationCacheEnabled || boolean || Whether the session can interact with \
the application cache. ||
|| browserConnectionEnabled || boolean || Whether the session can query for \
the browser's connectivity and disable it if desired. ||
|| cssSelectorsEnabled || boolean || Whether the session supports CSS \
selectors when searching for elements. ||
|| webStorageEnabled || boolean || Whether the session supports interactions \
with [http://www.w3.org/TR/2009/WD-webstorage-20091029/ storage objects]. ||
|| rotatable || boolean || Whether the session can rotate the current page's \
current layout between portrait and landscape orientations (only applies to \
mobile platforms). ||
|| acceptSslCerts || boolean || Whether the session should accept all SSL \
certs by default. ||
|| nativeEvents || boolean || Whether the session is capable of generating \
native events when simulating user input. ||
|| proxy || proxy object || Details of any proxy to use. If no proxy is \
specified, whatever the system's current or default state is used. The format \
is specified under Proxy JSON Object. ||
</dd>
<dt>
==== Desired Capabilities ====
</dt>
<dd>A Capabilities JSON Object sent by the client describing the capabilities \
a new session created by the server should possess. Any omitted keys implicitly \
indicate the corresponding capability is irrelevant.</dd>
<dt>
==== Actual Capabilities ====
</dt>
<dd>A Capabilities JSON Object returned by the server describing what \
features a session actually supports. Any omitted keys implicitly indicate \
the corresponding capability is not supported.</dd>
<dt>
==== Cookie JSON Object ====
</dt>
<dd>
A JSON object describing a Cookie.
|| *Key* || *Type* || *Description* ||
|| name || string || The name of the cookie. ||
|| value || string || The cookie value. ||
|| path || string || (Optional) The cookie path.^1^ ||
|| domain || string || (Optional) The domain the cookie is visible to.^1^ ||
|| secure || boolean || (Optional) Whether the cookie is a secure cookie.^1^ ||
|| httpOnly || boolean || (Optional) Whether the cookie is an httpOnly cookie.^1^ ||
|| expiry || number || (Optional) When the cookie expires, specified in \
seconds since midnight, January 1, 1970 UTC.^1^ ||
^1^ When returning Cookie objects, the server should only omit an optional \
field if it is incapable of providing the information.</dd>
<dt>
==== Log Entry JSON Object ====
</dt>
<dd>
A JSON object describing a log entry.
|| *Key* || *Type* || *Description* ||
|| timestamp || number || The timestamp of the entry. ||
|| level || string || The log level of the entry, for example, "INFO" (see [#Log_Levels log levels]). ||
|| message || string || The log message. ||
</dd>
<dt>
==== Log Levels ====
</dt>
<dd>
Log levels in order, with finest level on top and coarsest level at the bottom.
|| *Level* || *Description* ||
|| ALL || All log messages. Used for fetching of logs and configuration of logging. ||
|| DEBUG || Messages for debugging. ||
|| INFO || Messages with user information. ||
|| WARNING || Messages corresponding to non-critical problems. ||
|| SEVERE || Messages corresponding to critical errors. ||
|| OFF || No log messages. Used for configuration of logging. ||
</dd>
<dt>
==== Log Type ====
</dt>
<dd>
The table below lists common log types. Other log types, for instance, for
performance logging may also be available.
|| *Log Type* || *Description* ||
|| client || Logs from the client. ||
|| driver || Logs from the webdriver. ||
|| browser || Logs from the browser. ||
|| server || Logs from the server. ||
</dd>
<dt>
=== Proxy JSON Object ===
</dt>
<dd>
A JSON object describing a Proxy configuration.
|| *Key* || *Type* || *Description* ||
|| proxyType || string || (Required) The type of proxy being used. Possible \
values are: *direct* - A direct connection - no proxy in use, *manual* - \
Manual proxy settings configured, e.g. setting a proxy for HTTP, a proxy for \
FTP, etc, *pac* - Proxy autoconfiguration from a URL, *autodetect* - Proxy \
autodetection, probably with WPAD, *system* - Use system settings ||
|| proxyAutoconfigUrl || string || (Required if proxyType == *pac*, Ignored \
otherwise) Specifies the URL to be used for proxy autoconfiguration. \
Expected format example: http://hostname.com:1234/pacfile ||
|| ftpProxy, httpProxy, sslProxy, socksProxy || string || (Optional, Ignored if proxyType \
!= *manual*) Specifies the proxies to be used for FTP, HTTP, HTTPS and SOCKS requests \
respectively. Behaviour is undefined if a request is made, where the proxy \
for the particular protocol is undefined, if proxyType is *manual*. Expected \
format example: hostname.com:1234 ||
|| socksUsername || string || (Optional, Ignored if proxyType != *manual* and \
socksProxy is not set) Specifies SOCKS proxy username. ||
|| socksPassword || string || (Optional, Ignored if proxyType != *manual* and \
socksProxy is not set) Specifies SOCKS proxy password. ||
|| noProxy || string || (Optional, Ignored if proxyType != *manual*) \
Specifies proxy bypass addresses. Format is driver specific. ||
</dd>
</dl>
= Messages =
== Commands ==
!WebDriver command messages should conform to the [http://www.w3.org/Protocols/\
rfc2616/rfc2616-sec5.html#sec5 HTTP/1.1 request specification]. Although the \
server may be extended to respond to other content-types, the wire protocol \
dictates that all commands accept a content-type of \
`application/json;charset=UTF-8`. Likewise, the message bodies for POST and PUT\
request must use an `application/json;charset=UTF-8` content-type.
Each command in the WebDriver service will be mapped to an HTTP method at a \
specific path. Path segments prefixed with a colon (:) indicate that segment \
is a variable used to further identify the underlying resource. For example, \
consider an arbitrary resource mapped as:
{{{
GET /favorite/color/:name
}}}
Given this mapping, the server should respond to GET requests sent to \
"/favorite/color/Jack" and "/favorite/color/Jill", with the variable `:name` \
set to "Jack" and "Jill", respectively.
== Responses ==
Command responses shall be sent as \
[http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6 HTTP/1.1 response \
messages]. If the remote server must return a 4xx response, the response body \
shall have a Content-Type of text/plain and the message body shall be a \
descriptive message of the bad request. For all other cases, if a response \
includes a message body, it must have a Content-Type of \
application/json;charset=UTF-8 and will be a JSON object with the following \
properties:
|| *Key* || *Type* || *Description* ||
|| sessionId || string|null || An opaque handle used by the server to \
determine where to route session-specific commands. This ID should be included \
in all future session-commands in place of the :sessionId path segment \
variable. ||
|| status || number || A status code summarizing the result of the command. \
A non-zero value indicates that the command failed. ||
|| value || `*` || The response JSON value. ||
=== Response Status Codes ===
The wire protocol will inherit its status codes from those used by the \
InternetExplorerDriver:
|| *Code* || *Summary* || *Detail* ||
%s
The client should interpret a 404 Not Found response from the server as an \
"Unknown command" response. All other 4xx and 5xx responses from the server \
that do not define a status field should be interpreted as "Unknown error" \
responses.
== Error Handling ==
There are two levels of error handling specified by the wire protocol: invalid \
requests and failed commands.
=== Invalid Requests ===
All invalid requests should result in the server returning a 4xx HTTP \
response. The response Content-Type should be set to text/plain and the \
message body should be a descriptive error message. The categories of invalid \
requests are as follows:
<dl>
<dt>*Unknown Commands*</dt>
<dd>If the server receives a command request whose path is not mapped to a \
resource in the REST service, it should respond with a `404 Not Found` message.
</dd>
<dt>*Unimplemented Commands*</dt>
<dd>Every server implementing the WebDriver wire protocol must respond to \
every defined command. If an individual command has not been implemented on \
the server, the server should respond with a `501 Not Implemented` error \
message. Note this is the only error in the Invalid Request category that does \
not return a `4xx` status code.
</dd>
<dt>*Variable Resource Not Found*</dt>
<dd>If a request path maps to a variable resource, but that resource does not \
exist, then the server should respond with a `404 Not Found`. For example, if \
ID `my-session` is not a valid session ID on the server, and a command is sent \
to `GET /session/my-session HTTP/1.1`, then the server should gracefully \
return a `404`.
</dd>
<dt>*Invalid Command Method*</dt>
<dd>If a request path maps to a valid resource, but that resource does not \
respond to the request method, the server should respond with a `405 Method \
Not Allowed`. The response must include an Allows header with a list of the \
allowed methods for the requested resource.
</dd>
<dt>*Missing Command Parameters*</dt>
<dd>If a POST/PUT command maps to a resource that expects a set of JSON \
parameters, and the response body does not include one of those parameters, \
the server should respond with a `400 Bad Request`. The response body should \
list the missing parameters.
</dd>
</dl>
=== Failed Commands ===
If a request maps to a valid command and contains all of the expected \
parameters in the request body, yet fails to execute successfully, then the \
server should send a 500 Internal Server Error. This response should have a \
Content-Type of `application/json;charset=UTF-8` and the response body should \
be a well formed JSON response object.
The response status should be one of the defined status codes and the response \
value should be another JSON object with detailed information for the failing \
command:
|| Key || Type || Description ||
|| message || string || A descriptive message for the command failure. ||
|| screen || string || (Optional) If included, a screenshot of the current \
page as a base64 encoded string. ||
|| class || string || (Optional) If included, specifies the fully qualified \
class name for the exception that was thrown when the command failed. ||
|| stackTrace || array || (Optional) If included, specifies an array of JSON \
objects describing the stack trace for the exception that was thrown when the \
command failed. The zeroeth element of the array represents the top of the \
stack. ||
Each JSON object in the stackTrace array must contain the following properties:
|| *Key* || *Type* || *Description* ||
|| fileName || string || The name of the source file containing the line \
represented by this frame. ||
|| className || string || The fully qualified class name for the class active \
in this frame. If the class name cannot be determined, or is not applicable \
for the language the server is implemented in, then this property should be \
set to the empty string. ||
|| methodName || string || The name of the method active in this frame, or \
the empty string if unknown/not applicable. ||
|| lineNumber || number || The line number in the original source file for the \
frame, or 0 if unknown. ||
= Resource Mapping =
Resources in the WebDriver REST service are mapped to individual URL patterns. \
Each resource may respond to one or more HTTP request methods. If a resource \
responds to a GET request, then it should also respond to HEAD requests. All \
resources should respond to OPTIONS requests with an `Allow` header field, \
whose value is a list of all methods that resource responds to.
If a resource is mapped to a URL containing a variable path segment name, that \
path segment should be used to further route the request. Variable path \
segments are indicated in the resource mapping by a colon-prefix. For example, \
consider the following:
{{{
/favorite/color/:person
}}}
A resource mapped to this URL should parse the value of the `:person` path \
segment to further determine how to respond to the request. If this resource \
received a request for `/favorite/color/Jack`, then it should return Jack's \
favorite color. Likewise, the server should return Jill's favorite color for \
any requests to `/favorite/color/Jill`.
Two resources may only be mapped to the same URL pattern if one of those \
resources' patterns contains variable path segments, and the other does not. In\
these cases, the server should always route requests to the resource whose \
path is the best match for the request. Consider the following two resource \
paths:
# `/session/:sessionId/element/active`
# `/session/:sessionId/element/:id`
Given these mappings, the server should always route requests whose final path \
segment is active to the first resource. All other requests should be routed to\
second.
= Command Reference =
== Command Summary ==
|| *HTTP Method* || *Path* || *Summary* ||
%s
== Command Detail ==
%s''' % ('\n'.join(e.ToWikiTableString() for e in error_codes),
''.join(r.ToWikiTableString() for r in resources),
'\n----\n\n'.join(r.ToWikiString() for r in resources)))
finally:
f.close()
logging.info('ALL DONE!')
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3,
1898,
9079,
13,
6542,
27104,
5532,
878,
199,
3,
1898,
9079,
13,
6542,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
5229,
367,
12999,
314,
11799,
4113,
17195,
3794,
14,
199,
199,
2765,
2884,
365,
8646,
1806,
8997,
12,
1325,
652,
15620,
3718,
787,
22751,
543,
199,
15478,
10803,
14,
199,
199,
7692,
26,
819,
2366,
24764,
15,
11239,
14,
647,
1553,
3437,
199,
624,
199,
199,
646,
2050,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
984,
421,
199,
3472,
63,
18759,
16944,
63,
3243,
275,
747,
14,
515,
14,
904,
24893,
297,
283,
6797,
297,
283,
9653,
25791,
3658,
14,
6797,
358,
421,
199,
533,
7337,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
931,
304,
272,
291,
14,
515,
275,
931,
272,
291,
14,
2474,
275,
942,
819,
347,
636,
18480,
721,
277,
12,
1921,
304,
272,
862,
26,
489,
372,
1613,
8,
4031,
12,
291,
2843,
18480,
721,
962,
9,
272,
871,
4281,
12,
325,
26,
489,
340,
291,
14,
2474,
26,
267,
372,
291,
14,
2474,
59,
552,
8,
277,
14,
2474,
9,
446,
413,
17979,
18480,
721,
962,
9,
489,
746,
325,
819,
347,
7711,
8,
277,
12,
6212,
304,
272,
372,
291,
14,
1123,
3767,
8,
3767,
8,
277,
12,
283,
4030,
297,
6212,
430,
819,
347,
2372,
8,
277,
12,
6212,
304,
272,
372,
291,
14,
1123,
3767,
8,
3767,
8,
277,
12,
283,
2970,
297,
6212,
430,
819,
347,
8496,
8,
277,
12,
6212,
304,
272,
372,
291,
14,
1123,
3767,
8,
3767,
8,
277,
12,
283,
7014,
297,
6212,
430,
819,
347,
2654,
3767,
8,
277,
12,
1083,
304,
272,
291,
14,
2474,
14,
740,
8,
765,
9,
272,
372,
291,
819,
347,
4005,
26198,
1558,
8,
277,
304,
272,
620,
275,
283,
5918,
450,
83,
24768,
60,
78,
7,
450,
291,
14,
515,
272,
367,
1083,
315,
291,
14,
2474,
26,
489,
620,
275,
1543,
83,
5,
83,
7,
450,
334,
495,
12,
1083,
14,
1378,
26198,
1558,
8,
277,
14,
515,
430,
272,
372,
620,
819,
347,
4005,
26198,
3186,
1558,
8,
277,
304,
272,
372,
6522,
904,
8,
77,
14,
1378,
26198,
3186,
1558,
342,
367,
333,
315,
291,
14,
2474,
9,
421,
199,
533,
8596,
4031,
8,
4031,
304,
523,
347,
2654,
3767,
8,
277,
12,
1083,
304,
272,
372,
334,
4031,
14,
1123,
3767,
8,
277,
12,
1083,
680,
288,
2654,
6417,
4720,
6176,
1730,
1304,
297,
1169,
283,
998,
402,
314,
2351,
370,
7475,
314,
1414,
370,
12459,
421,
199,
533,
6566,
4031,
8,
4434,
4031,
304,
523,
347,
2654,
3767,
8,
277,
12,
1083,
304,
272,
372,
334,
4434,
4031,
14,
1123,
3767,
8,
277,
12,
1083,
680,
288,
2654,
6417,
4720,
6176,
344,
297,
1169,
283,
998,
402,
314,
1819,
370,
7475,
314,
1414,
370,
14,
1959,
288,
2654,
547,
360,
3391,
274,
2162,
5083,
297,
2151,
283,
3917,
314,
1819,
11812,
701,
658,
26,
344,
64,
365,
949,
8088,
10102,
283,
2151,
283,
475,
314,
2034,
3985,
83,
14316,
12459,
819,
347,
15127,
24735,
8,
277,
304,
272,
372,
291,
14,
1123,
547,
360,
2162,
1763,
14917,
297,
586,
283,
3917,
314,
11812,
1819,
365,
440,
8917,
641,
314,
2034,
283,
586,
8189,
22051,
365,
8752,
701,
15750,
12,
965,
378,
13,
2063,
12,
503,
965,
378,
13,
3333,
5942,
819,
347,
15127,
6589,
2223,
8,
277,
304,
272,
372,
291,
14,
1123,
547,
360,
3364,
2162,
2223,
297,
586,
283,
3917,
314,
11812,
1819,
365,
6980,
2659,
421,
199,
533,
9075,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
1676,
12,
1083,
12,
6212,
304,
272,
291,
14,
1708,
275,
1676,
272,
291,
14,
765,
275,
1083,
272,
291,
14,
4705,
275,
6212,
272,
291,
14,
633,
63,
3214,
275,
942,
272,
291,
14,
1001,
63,
3214,
275,
942,
272,
291,
14,
1107,
63,
466,
275,
488,
272,
291,
14,
2550,
275,
1052,
819,
347,
2654,
6417,
4720,
8,
277,
12,
536,
12,
1369,
304,
272,
291,
14,
633,
63,
3214,
14,
740,
2561,
267,
283,
354,
356,
536,
12,
267,
283,
3257,
356,
1369,
1552,
272,
372,
291,
14,
1708,
819,
347,
2654,
9653,
4720,
8,
277,
12,
536,
12,
730,
12,
1369,
304,
272,
291,
14,
1001,
63,
3214,
14,
740,
2561,
267,
283,
354,
356,
536,
12,
267,
283,
466,
356,
730,
12,
267,
283,
3257,
356,
1369,
1552,
272,
372,
291,
14,
1708,
819,
347,
2654,
547,
8,
277,
12,
730,
12,
6212,
304,
272,
291,
14,
2550,
59,
466,
61,
275,
791,
466,
356,
730,
12,
283,
4705,
356,
6212,
93,
272,
372,
291,
14,
1708,
819,
347,
2494,
1767,
804,
8,
277,
12,
730,
12,
1369,
304,
272,
291,
14,
1107,
63,
466,
275,
469,
267,
283,
466,
356,
730,
12,
267,
283,
3257,
356,
1369,
93,
272,
372,
291,
14,
1708,
819,
347,
485,
1002,
6417,
5976,
26198,
1558,
8,
277,
304,
272,
340,
440,
291,
14,
633,
63,
3214,
26,
489,
372,
2125,
272,
372,
1449,
199,
28,
617,
30,
199,
28,
5030,
30,
199,
28,
3583,
30,
10,
2632,
3897,
27344,
1108,
3583,
30,
199,
5,
83,
199,
1108,
5030,
30,
199,
1108,
617,
26934,
450,
1557,
78,
1370,
904,
4827,
617,
8637,
5,
83,
64,
446,
450,
83,
1108,
617,
3524,
450,
2151,
334,
635,
459,
354,
995,
1215,
459,
3257,
1105,
2151
] |
[
1898,
9079,
13,
6542,
27104,
5532,
878,
199,
3,
1898,
9079,
13,
6542,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
5229,
367,
12999,
314,
11799,
4113,
17195,
3794,
14,
199,
199,
2765,
2884,
365,
8646,
1806,
8997,
12,
1325,
652,
15620,
3718,
787,
22751,
543,
199,
15478,
10803,
14,
199,
199,
7692,
26,
819,
2366,
24764,
15,
11239,
14,
647,
1553,
3437,
199,
624,
199,
199,
646,
2050,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
984,
421,
199,
3472,
63,
18759,
16944,
63,
3243,
275,
747,
14,
515,
14,
904,
24893,
297,
283,
6797,
297,
283,
9653,
25791,
3658,
14,
6797,
358,
421,
199,
533,
7337,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
931,
304,
272,
291,
14,
515,
275,
931,
272,
291,
14,
2474,
275,
942,
819,
347,
636,
18480,
721,
277,
12,
1921,
304,
272,
862,
26,
489,
372,
1613,
8,
4031,
12,
291,
2843,
18480,
721,
962,
9,
272,
871,
4281,
12,
325,
26,
489,
340,
291,
14,
2474,
26,
267,
372,
291,
14,
2474,
59,
552,
8,
277,
14,
2474,
9,
446,
413,
17979,
18480,
721,
962,
9,
489,
746,
325,
819,
347,
7711,
8,
277,
12,
6212,
304,
272,
372,
291,
14,
1123,
3767,
8,
3767,
8,
277,
12,
283,
4030,
297,
6212,
430,
819,
347,
2372,
8,
277,
12,
6212,
304,
272,
372,
291,
14,
1123,
3767,
8,
3767,
8,
277,
12,
283,
2970,
297,
6212,
430,
819,
347,
8496,
8,
277,
12,
6212,
304,
272,
372,
291,
14,
1123,
3767,
8,
3767,
8,
277,
12,
283,
7014,
297,
6212,
430,
819,
347,
2654,
3767,
8,
277,
12,
1083,
304,
272,
291,
14,
2474,
14,
740,
8,
765,
9,
272,
372,
291,
819,
347,
4005,
26198,
1558,
8,
277,
304,
272,
620,
275,
283,
5918,
450,
83,
24768,
60,
78,
7,
450,
291,
14,
515,
272,
367,
1083,
315,
291,
14,
2474,
26,
489,
620,
275,
1543,
83,
5,
83,
7,
450,
334,
495,
12,
1083,
14,
1378,
26198,
1558,
8,
277,
14,
515,
430,
272,
372,
620,
819,
347,
4005,
26198,
3186,
1558,
8,
277,
304,
272,
372,
6522,
904,
8,
77,
14,
1378,
26198,
3186,
1558,
342,
367,
333,
315,
291,
14,
2474,
9,
421,
199,
533,
8596,
4031,
8,
4031,
304,
523,
347,
2654,
3767,
8,
277,
12,
1083,
304,
272,
372,
334,
4031,
14,
1123,
3767,
8,
277,
12,
1083,
680,
288,
2654,
6417,
4720,
6176,
1730,
1304,
297,
1169,
283,
998,
402,
314,
2351,
370,
7475,
314,
1414,
370,
12459,
421,
199,
533,
6566,
4031,
8,
4434,
4031,
304,
523,
347,
2654,
3767,
8,
277,
12,
1083,
304,
272,
372,
334,
4434,
4031,
14,
1123,
3767,
8,
277,
12,
1083,
680,
288,
2654,
6417,
4720,
6176,
344,
297,
1169,
283,
998,
402,
314,
1819,
370,
7475,
314,
1414,
370,
14,
1959,
288,
2654,
547,
360,
3391,
274,
2162,
5083,
297,
2151,
283,
3917,
314,
1819,
11812,
701,
658,
26,
344,
64,
365,
949,
8088,
10102,
283,
2151,
283,
475,
314,
2034,
3985,
83,
14316,
12459,
819,
347,
15127,
24735,
8,
277,
304,
272,
372,
291,
14,
1123,
547,
360,
2162,
1763,
14917,
297,
586,
283,
3917,
314,
11812,
1819,
365,
440,
8917,
641,
314,
2034,
283,
586,
8189,
22051,
365,
8752,
701,
15750,
12,
965,
378,
13,
2063,
12,
503,
965,
378,
13,
3333,
5942,
819,
347,
15127,
6589,
2223,
8,
277,
304,
272,
372,
291,
14,
1123,
547,
360,
3364,
2162,
2223,
297,
586,
283,
3917,
314,
11812,
1819,
365,
6980,
2659,
421,
199,
533,
9075,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
1676,
12,
1083,
12,
6212,
304,
272,
291,
14,
1708,
275,
1676,
272,
291,
14,
765,
275,
1083,
272,
291,
14,
4705,
275,
6212,
272,
291,
14,
633,
63,
3214,
275,
942,
272,
291,
14,
1001,
63,
3214,
275,
942,
272,
291,
14,
1107,
63,
466,
275,
488,
272,
291,
14,
2550,
275,
1052,
819,
347,
2654,
6417,
4720,
8,
277,
12,
536,
12,
1369,
304,
272,
291,
14,
633,
63,
3214,
14,
740,
2561,
267,
283,
354,
356,
536,
12,
267,
283,
3257,
356,
1369,
1552,
272,
372,
291,
14,
1708,
819,
347,
2654,
9653,
4720,
8,
277,
12,
536,
12,
730,
12,
1369,
304,
272,
291,
14,
1001,
63,
3214,
14,
740,
2561,
267,
283,
354,
356,
536,
12,
267,
283,
466,
356,
730,
12,
267,
283,
3257,
356,
1369,
1552,
272,
372,
291,
14,
1708,
819,
347,
2654,
547,
8,
277,
12,
730,
12,
6212,
304,
272,
291,
14,
2550,
59,
466,
61,
275,
791,
466,
356,
730,
12,
283,
4705,
356,
6212,
93,
272,
372,
291,
14,
1708,
819,
347,
2494,
1767,
804,
8,
277,
12,
730,
12,
1369,
304,
272,
291,
14,
1107,
63,
466,
275,
469,
267,
283,
466,
356,
730,
12,
267,
283,
3257,
356,
1369,
93,
272,
372,
291,
14,
1708,
819,
347,
485,
1002,
6417,
5976,
26198,
1558,
8,
277,
304,
272,
340,
440,
291,
14,
633,
63,
3214,
26,
489,
372,
2125,
272,
372,
1449,
199,
28,
617,
30,
199,
28,
5030,
30,
199,
28,
3583,
30,
10,
2632,
3897,
27344,
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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
] |
manics/ansible-modules-core
|
cloud/openstack/os_floating_ip.py
|
22
|
8639
|
#!/usr/bin/python
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
# Author: Davide Guerri <davide.guerri@hp.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/>.
try:
import shade
from shade import meta
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
DOCUMENTATION = '''
---
module: os_floating_ip
version_added: "2.0"
short_description: Add/Remove floating IP from an instance
extends_documentation_fragment: openstack
description:
- Add or Remove a floating IP to an instance
options:
server:
description:
- The name or ID of the instance to which the IP address
should be assigned.
required: true
network:
description:
- The name or ID of a neutron external network or a nova pool name.
required: false
floating_ip_address:
description:
- A floating IP address to attach or to detach. Required only if I(state)
is absent. When I(state) is present can be used to specify a IP address
to attach.
required: false
reuse:
description:
- When I(state) is present, and I(floating_ip_address) is not present,
this parameter can be used to specify whether we should try to reuse
a floating IP address already allocated to the project.
required: false
default: false
fixed_address:
description:
- To which fixed IP of server the floating IP address should be
attached to.
required: false
wait:
description:
- When attaching a floating IP address, specify whether we should
wait for it to appear as attached.
required: false
default: false
timeout:
description:
- Time to wait for an IP address to appear as attached. See wait.
required: false
default: 60
state:
description:
- Should the resource be present or absent.
choices: [present, absent]
required: false
default: present
purge:
description:
- When I(state) is absent, indicates whether or not to delete the floating
IP completely, or only detach it from the server. Default is to detach only.
required: false
default: false
version_added: "2.1"
requirements: ["shade"]
'''
EXAMPLES = '''
# Assign a floating IP to the fist interface of `cattle001` from an exiting
# external network or nova pool. A new floating IP from the first available
# external network is allocated to the project.
- os_floating_ip:
cloud: dguerri
server: cattle001
# Assign a new floating IP to the instance fixed ip `192.0.2.3` of
# `cattle001`. If a free floating IP is already allocated to the project, it is
# reused; if not, a new one is created.
- os_floating_ip:
cloud: dguerri
state: present
reuse: yes
server: cattle001
network: ext_net
fixed_address: 192.0.2.3
wait: true
timeout: 180
# Detach a floating IP address from a server
- os_floating_ip:
cloud: dguerri
state: absent
floating_ip_address: 203.0.113.2
server: cattle001
'''
def _get_floating_ip(cloud, floating_ip_address):
f_ips = cloud.search_floating_ips(
filters={'floating_ip_address': floating_ip_address})
if not f_ips:
return None
return f_ips[0]
def main():
argument_spec = openstack_full_argument_spec(
server=dict(required=True),
state=dict(default='present', choices=['absent', 'present']),
network=dict(required=False, default=None),
floating_ip_address=dict(required=False, default=None),
reuse=dict(required=False, type='bool', default=False),
fixed_address=dict(required=False, default=None),
wait=dict(required=False, type='bool', default=False),
timeout=dict(required=False, type='int', default=60),
purge=dict(required=False, type='bool', default=False),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
server_name_or_id = module.params['server']
state = module.params['state']
network = module.params['network']
floating_ip_address = module.params['floating_ip_address']
reuse = module.params['reuse']
fixed_address = module.params['fixed_address']
wait = module.params['wait']
timeout = module.params['timeout']
purge = module.params['purge']
cloud = shade.openstack_cloud(**module.params)
try:
server = cloud.get_server(server_name_or_id)
if server is None:
module.fail_json(
msg="server {0} not found".format(server_name_or_id))
if state == 'present':
# If f_ip already assigned to server, check that it matches
# requirements.
public_ip = cloud.get_server_public_ip(server)
f_ip = _get_floating_ip(cloud, public_ip) if public_ip else public_ip
if f_ip:
if network:
network_id = cloud.get_network(name_or_id=network)["id"]
else:
network_id = None
if all([fixed_address, f_ip.fixed_ip_address == fixed_address,
network, f_ip.network != network_id]):
# Current state definitely conflicts with requirements
module.fail_json(msg="server {server} already has a "
"floating-ip on requested "
"interface but it doesn't match "
"requested network {network: {fip}"
.format(server=server_name_or_id,
network=network,
fip=remove_values(f_ip,
module.no_log_values)))
if not network or f_ip.network == network_id:
# Requirements are met
module.exit_json(changed=False, floating_ip=f_ip)
# Requirments are vague enough to ignore exisitng f_ip and try
# to create a new f_ip to the server.
server = cloud.add_ips_to_server(
server=server, ips=floating_ip_address, ip_pool=network,
reuse=reuse, fixed_address=fixed_address, wait=wait,
timeout=timeout)
fip_address = cloud.get_server_public_ip(server)
# Update the floating IP status
f_ip = _get_floating_ip(cloud, fip_address)
module.exit_json(changed=True, floating_ip=f_ip)
elif state == 'absent':
if floating_ip_address is None:
if not server_name_or_id:
module.fail_json(msg="either server or floating_ip_address are required")
server = cloud.get_server(server_name_or_id)
floating_ip_address = cloud.get_server_public_ip(server)
f_ip = _get_floating_ip(cloud, floating_ip_address)
if not f_ip:
# Nothing to detach
module.exit_json(changed=False)
changed = False
if f_ip["fixed_ip_address"]:
cloud.detach_ip_from_server(
server_id=server['id'], floating_ip_id=f_ip['id'])
# Update the floating IP status
f_ip = cloud.get_floating_ip(id=f_ip['id'])
changed = True
if purge:
cloud.delete_floating_ip(f_ip['id'])
module.exit_json(changed=True)
module.exit_json(changed=changed, floating_ip=f_ip)
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e), extra_data=e.extra_data)
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import *
from ansible.module_utils.openstack import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
6529,
26,
577,
65,
5624,
12436,
281,
322,
665,
983,
5624,
14,
6051,
281,
322,
32,
12025,
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,
893,
26,
272,
492,
32250,
272,
687,
32250,
492,
3404,
339,
7509,
63,
8461,
1093,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8461,
1093,
275,
756,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
7774,
63,
711,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
3612,
63,
1802,
26,
2654,
15,
5587,
8402,
3531,
687,
376,
1256,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1802,
26,
2043,
446,
2654,
503,
5852,
282,
8402,
3531,
370,
376,
1256,
199,
1419,
26,
2043,
1654,
26,
1362,
1369,
26,
267,
446,
710,
536,
503,
2870,
402,
314,
1256,
370,
1314,
314,
3531,
2287,
881,
1077,
506,
7943,
14,
1362,
1415,
26,
2549,
2043,
2784,
26,
1362,
1369,
26,
267,
446,
710,
536,
503,
2870,
402,
282,
8224,
5957,
2784,
503,
282,
5913,
4203,
536,
14,
1362,
1415,
26,
3055,
2043,
8402,
63,
711,
63,
1562,
26,
1362,
1369,
26,
267,
446,
437,
8402,
3531,
2287,
370,
6554,
503,
370,
21236,
14,
11105,
1454,
340,
473,
8,
929,
9,
881,
365,
9552,
14,
3979,
473,
8,
929,
9,
365,
3451,
883,
506,
1202,
370,
4165,
282,
3531,
2287,
881,
370,
6554,
14,
1362,
1415,
26,
3055,
2043,
12598,
26,
1362,
1369,
26,
267,
446,
3979,
473,
8,
929,
9,
365,
3451,
12,
436,
473,
8,
7774,
63,
711,
63,
1562,
9,
365,
440,
3451,
12,
881,
642,
2725,
883,
506,
1202,
370,
4165,
3775,
781,
1077,
862,
370,
12598,
881,
282,
8402,
3531,
2287,
2575,
17659,
370,
314,
2199,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
2043,
6317,
63,
1562,
26,
1362,
1369,
26,
267,
446,
4005,
1314,
6317,
3531,
402,
1654,
314,
8402,
3531,
2287,
1077,
506,
881,
10102,
370,
14,
1362,
1415,
26,
3055,
2043,
3618,
26,
1362,
1369,
26,
267,
446,
3979,
6554,
316,
282,
8402,
3531,
2287,
12,
4165,
3775,
781,
1077,
881,
3618,
367,
652,
370,
7468,
465,
10102,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
2043,
2653,
26,
1362,
1369,
26,
267,
446,
4703,
370,
3618,
367,
376,
3531,
2287,
370,
7468,
465,
10102,
14,
1666,
3618,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
5212,
2043,
1174,
26,
1362,
1369,
26,
2126,
446,
7719,
314,
2073,
506,
3451,
503,
9552,
14,
1362,
3415,
26,
359,
1881,
12,
9552,
61,
1362,
1415,
26,
3055,
1362,
849,
26,
3451,
2043,
18503,
26,
1362,
1369,
26,
267,
446,
3979,
473,
8,
929,
9,
365,
9552,
12,
9126,
3775,
503,
440,
370,
3145,
314,
8402,
881,
3531,
14793,
12,
503,
1454,
21236,
652,
687,
314,
1654,
14,
3758,
365,
370,
21236,
1454,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
1362,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
7538,
26,
2097,
31170,
937,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
16927,
282,
8402,
3531,
370,
314,
289,
631,
3217,
402,
658,
3385,
1118,
4587,
64,
687,
376,
24234,
199,
3,
5957,
2784,
503,
5913,
4203,
14,
437,
892,
8402,
3531,
687,
314,
1642,
2808,
199,
3,
5957,
2784,
365,
17659,
370,
314,
2199,
14,
199,
13,
747,
63,
7774,
63,
711,
26,
1362,
8002,
26,
366,
6051,
281,
322,
1362,
1654,
26,
6230,
1118,
4587,
199,
199,
3,
16927,
282,
892,
8402,
3531,
370,
314,
1256,
6317,
3384,
658,
5756,
14,
16,
14,
18,
14,
19,
64,
402,
199,
3,
658,
3385,
1118,
4587,
2313,
982,
282,
2867,
8402,
3531,
365,
2575,
17659,
370,
314,
2199,
12,
652,
365,
199,
3,
24826,
27,
340,
440,
12,
282,
892,
1373,
365,
2737,
14,
199,
13,
747,
63,
7774,
63,
711,
26,
1362,
8002,
26,
366,
6051,
281,
322,
1362,
1174,
26,
3451,
1362,
12598,
26,
9456,
1362,
1654,
26,
6230,
1118,
4587,
1362,
2784,
26,
1599,
63,
846,
1362,
6317,
63,
1562,
26,
13567,
14,
16,
14,
18,
14,
19,
1362,
3618,
26,
2549,
1362,
2653,
26,
13576,
199,
199,
3,
577,
386,
1225,
282,
8402,
3531,
2287,
687,
282,
1654,
199,
13,
747,
63,
7774,
63,
711,
26,
1362,
8002,
26,
366,
6051,
281,
322,
1362,
1174,
26,
9552,
1362,
8402,
63,
711,
63,
1562,
26,
29202,
14,
16,
14,
9225,
14,
18,
1362,
1654,
26,
6230,
1118,
4587,
199,
2344,
421,
199,
318,
485,
362,
63,
7774,
63,
711,
8,
4091,
12,
8402,
63,
711,
63,
1562,
304,
272,
289,
63,
6142,
275,
8002,
14,
1733,
63,
7774,
63,
6142,
8,
267,
4766,
3713,
7774,
63,
711,
63,
1562,
356,
8402,
63,
711,
63,
1562,
1552,
272,
340,
440,
289,
63,
6142,
26,
267,
372,
488,
339,
372,
289,
63,
6142,
59,
16,
61,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
1654,
29,
807,
8,
2427,
29,
549,
395,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
2784,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
395,
267,
8402,
63,
711,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
6529,
26,
577,
65,
5624,
12436,
281,
322,
665,
983,
5624,
14,
6051,
281,
322,
32,
12025,
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,
893,
26,
272,
492,
32250,
272,
687,
32250,
492,
3404,
339,
7509,
63,
8461,
1093,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8461,
1093,
275,
756,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
7774,
63,
711,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
3612,
63,
1802,
26,
2654,
15,
5587,
8402,
3531,
687,
376,
1256,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1802,
26,
2043,
446,
2654,
503,
5852,
282,
8402,
3531,
370,
376,
1256,
199,
1419,
26,
2043,
1654,
26,
1362,
1369,
26,
267,
446,
710,
536,
503,
2870,
402,
314,
1256,
370,
1314,
314,
3531,
2287,
881,
1077,
506,
7943,
14,
1362,
1415,
26,
2549,
2043,
2784,
26,
1362,
1369,
26,
267,
446,
710,
536,
503,
2870,
402,
282,
8224,
5957,
2784,
503,
282,
5913,
4203,
536,
14,
1362,
1415,
26,
3055,
2043,
8402,
63,
711,
63,
1562,
26,
1362,
1369,
26,
267,
446,
437,
8402,
3531,
2287,
370,
6554,
503,
370,
21236,
14,
11105,
1454,
340,
473,
8,
929,
9,
881,
365,
9552,
14,
3979,
473,
8,
929,
9,
365,
3451,
883,
506,
1202,
370,
4165,
282,
3531,
2287,
881,
370,
6554,
14,
1362,
1415,
26,
3055,
2043,
12598,
26,
1362,
1369,
26,
267,
446,
3979,
473,
8,
929,
9,
365,
3451,
12,
436,
473,
8,
7774,
63,
711,
63,
1562,
9,
365,
440,
3451,
12,
881,
642,
2725,
883,
506,
1202,
370,
4165,
3775,
781,
1077,
862,
370,
12598,
881,
282,
8402,
3531,
2287,
2575,
17659,
370,
314,
2199,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
2043,
6317,
63,
1562,
26,
1362,
1369,
26,
267,
446,
4005,
1314,
6317,
3531,
402,
1654,
314,
8402,
3531,
2287,
1077,
506,
881,
10102,
370,
14,
1362,
1415,
26,
3055,
2043,
3618,
26,
1362,
1369,
26,
267,
446,
3979,
6554,
316,
282,
8402,
3531,
2287,
12,
4165,
3775,
781,
1077,
881,
3618,
367,
652,
370,
7468,
465,
10102,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
2043,
2653,
26,
1362,
1369,
26,
267,
446,
4703,
370,
3618,
367,
376,
3531,
2287,
370,
7468,
465,
10102,
14,
1666,
3618,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
5212,
2043,
1174,
26,
1362,
1369,
26,
2126,
446,
7719,
314,
2073,
506,
3451,
503,
9552,
14,
1362,
3415,
26,
359,
1881,
12,
9552,
61,
1362,
1415,
26,
3055,
1362,
849,
26,
3451,
2043,
18503,
26,
1362,
1369,
26,
267,
446,
3979,
473,
8,
929,
9,
365,
9552,
12,
9126,
3775,
503,
440,
370,
3145,
314,
8402,
881,
3531,
14793,
12,
503,
1454,
21236,
652,
687,
314,
1654,
14,
3758,
365,
370,
21236,
1454,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
1362,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
7538,
26,
2097,
31170,
937,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
16927,
282,
8402,
3531,
370,
314,
289,
631,
3217,
402,
658,
3385,
1118,
4587,
64,
687,
376,
24234,
199,
3,
5957,
2784,
503,
5913,
4203,
14,
437,
892,
8402,
3531,
687,
314,
1642,
2808,
199,
3,
5957,
2784,
365,
17659,
370,
314,
2199,
14,
199,
13,
747,
63,
7774,
63,
711,
26,
1362,
8002,
26,
366,
6051,
281,
322,
1362,
1654,
26,
6230,
1118,
4587,
199,
199,
3,
16927,
282,
892,
8402,
3531,
370,
314,
1256,
6317,
3384,
658,
5756,
14,
16,
14,
18,
14,
19,
64,
402,
199,
3,
658,
3385,
1118,
4587,
2313,
982,
282,
2867,
8402,
3531,
365,
2575,
17659,
370,
314,
2199,
12,
652,
365,
199,
3,
24826,
27,
340,
440,
12,
282,
892,
1373,
365,
2737,
14,
199,
13,
747,
63,
7774,
63,
711,
26,
1362,
8002,
26,
366,
6051,
281,
322,
1362,
1174,
26,
3451,
1362,
12598,
26,
9456,
1362,
1654,
26,
6230,
1118,
4587,
1362,
2784,
26,
1599,
63,
846,
1362,
6317,
63,
1562,
26,
13567,
14,
16,
14,
18,
14,
19,
1362,
3618,
26,
2549,
1362,
2653,
26,
13576,
199,
199,
3,
577,
386,
1225,
282,
8402,
3531,
2287,
687,
282,
1654,
199,
13,
747,
63,
7774,
63,
711,
26,
1362,
8002,
26,
366,
6051,
281,
322,
1362,
1174,
26,
9552,
1362,
8402,
63,
711,
63,
1562,
26,
29202,
14,
16,
14,
9225,
14,
18,
1362,
1654,
26,
6230,
1118,
4587,
199,
2344,
421,
199,
318,
485,
362,
63,
7774,
63,
711,
8,
4091,
12,
8402,
63,
711,
63,
1562,
304,
272,
289,
63,
6142,
275,
8002,
14,
1733,
63,
7774,
63,
6142,
8,
267,
4766,
3713,
7774,
63,
711,
63,
1562,
356,
8402,
63,
711,
63,
1562,
1552,
272,
340,
440,
289,
63,
6142,
26,
267,
372,
488,
339,
372,
289,
63,
6142,
59,
16,
61,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
1654,
29,
807,
8,
2427,
29,
549,
395,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
2784,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
395,
267,
8402,
63,
711,
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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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
] |
goodwinos/linux-dm
|
tools/perf/scripts/python/event_analyzing_sample.py
|
4719
|
7393
|
# event_analyzing_sample.py: general event handler in python
#
# Current perf report is already very powerful with the annotation integrated,
# and this script is not trying to be as powerful as perf report, but
# providing end user/developer a flexible way to analyze the events other
# than trace points.
#
# The 2 database related functions in this script just show how to gather
# the basic information, and users can modify and write their own functions
# according to their specific requirement.
#
# The first function "show_general_events" just does a basic grouping for all
# generic events with the help of sqlite, and the 2nd one "show_pebs_ll" is
# for a x86 HW PMU event: PEBS with load latency data.
#
import os
import sys
import math
import struct
import sqlite3
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from EventClass import *
#
# If the perf.data has a big number of samples, then the insert operation
# will be very time consuming (about 10+ minutes for 10000 samples) if the
# .db database is on disk. Move the .db file to RAM based FS to speedup
# the handling, which will cut the time down to several seconds.
#
con = sqlite3.connect("/dev/shm/perf.db")
con.isolation_level = None
def trace_begin():
print "In trace_begin:\n"
#
# Will create several tables at the start, pebs_ll is for PEBS data with
# load latency info, while gen_events is for general event.
#
con.execute("""
create table if not exists gen_events (
name text,
symbol text,
comm text,
dso text
);""")
con.execute("""
create table if not exists pebs_ll (
name text,
symbol text,
comm text,
dso text,
flags integer,
ip integer,
status integer,
dse integer,
dla integer,
lat integer
);""")
#
# Create and insert event object to a database so that user could
# do more analysis with simple database commands.
#
def process_event(param_dict):
event_attr = param_dict["attr"]
sample = param_dict["sample"]
raw_buf = param_dict["raw_buf"]
comm = param_dict["comm"]
name = param_dict["ev_name"]
# Symbol and dso info are not always resolved
if (param_dict.has_key("dso")):
dso = param_dict["dso"]
else:
dso = "Unknown_dso"
if (param_dict.has_key("symbol")):
symbol = param_dict["symbol"]
else:
symbol = "Unknown_symbol"
# Create the event object and insert it to the right table in database
event = create_event(name, comm, dso, symbol, raw_buf)
insert_db(event)
def insert_db(event):
if event.ev_type == EVTYPE_GENERIC:
con.execute("insert into gen_events values(?, ?, ?, ?)",
(event.name, event.symbol, event.comm, event.dso))
elif event.ev_type == EVTYPE_PEBS_LL:
event.ip &= 0x7fffffffffffffff
event.dla &= 0x7fffffffffffffff
con.execute("insert into pebs_ll values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(event.name, event.symbol, event.comm, event.dso, event.flags,
event.ip, event.status, event.dse, event.dla, event.lat))
def trace_end():
print "In trace_end:\n"
# We show the basic info for the 2 type of event classes
show_general_events()
show_pebs_ll()
con.close()
#
# As the event number may be very big, so we can't use linear way
# to show the histogram in real number, but use a log2 algorithm.
#
def num2sym(num):
# Each number will have at least one '#'
snum = '#' * (int)(math.log(num, 2) + 1)
return snum
def show_general_events():
# Check the total record number in the table
count = con.execute("select count(*) from gen_events")
for t in count:
print "There is %d records in gen_events table" % t[0]
if t[0] == 0:
return
print "Statistics about the general events grouped by thread/symbol/dso: \n"
# Group by thread
commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)")
print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
for row in commq:
print "%16s %8d %s" % (row[0], row[1], num2sym(row[1]))
# Group by symbol
print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)")
for row in symbolq:
print "%32s %8d %s" % (row[0], row[1], num2sym(row[1]))
# Group by dso
print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)
dsoq = con.execute("select dso, count(dso) from gen_events group by dso order by -count(dso)")
for row in dsoq:
print "%40s %8d %s" % (row[0], row[1], num2sym(row[1]))
#
# This function just shows the basic info, and we could do more with the
# data in the tables, like checking the function parameters when some
# big latency events happen.
#
def show_pebs_ll():
count = con.execute("select count(*) from pebs_ll")
for t in count:
print "There is %d records in pebs_ll table" % t[0]
if t[0] == 0:
return
print "Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n"
# Group by thread
commq = con.execute("select comm, count(comm) from pebs_ll group by comm order by -count(comm)")
print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
for row in commq:
print "%16s %8d %s" % (row[0], row[1], num2sym(row[1]))
# Group by symbol
print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
symbolq = con.execute("select symbol, count(symbol) from pebs_ll group by symbol order by -count(symbol)")
for row in symbolq:
print "%32s %8d %s" % (row[0], row[1], num2sym(row[1]))
# Group by dse
dseq = con.execute("select dse, count(dse) from pebs_ll group by dse order by -count(dse)")
print "\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58)
for row in dseq:
print "%32s %8d %s" % (row[0], row[1], num2sym(row[1]))
# Group by latency
latq = con.execute("select lat, count(lat) from pebs_ll group by lat order by lat")
print "\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58)
for row in latq:
print "%32s %8d %s" % (row[0], row[1], num2sym(row[1]))
def trace_unhandled(event_name, context, event_fields_dict):
print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
|
gpl-2.0
|
[
3,
1566,
63,
4797,
20135,
63,
3271,
14,
647,
26,
8605,
1566,
3016,
315,
2366,
199,
3,
199,
3,
9338,
8582,
3622,
365,
2575,
7437,
7074,
1893,
543,
314,
11262,
17806,
972,
12,
199,
3,
436,
642,
2884,
365,
440,
9936,
370,
506,
465,
7074,
1893,
465,
8582,
3622,
12,
1325,
199,
3,
13070,
1284,
922,
15,
11071,
282,
26841,
4340,
370,
19897,
314,
4474,
1163,
199,
3,
2419,
3307,
4501,
14,
199,
3,
199,
3,
710,
499,
3050,
4048,
3423,
315,
642,
2884,
2951,
2498,
4212,
370,
13082,
199,
3,
314,
5678,
2556,
12,
436,
4390,
883,
2811,
436,
2218,
3932,
5705,
3423,
199,
3,
7182,
370,
3932,
2488,
10685,
14,
199,
3,
199,
3,
710,
1642,
805,
298,
2384,
63,
10706,
63,
4368,
2,
2951,
1630,
282,
5678,
17786,
367,
1006,
199,
3,
7809,
4474,
543,
314,
1720,
402,
11723,
12,
436,
314,
499,
977,
1373,
298,
2384,
63,
321,
1533,
63,
914,
2,
365,
199,
3,
367,
282,
671,
1184,
869,
55,
27320,
53,
1566,
26,
19599,
11087,
543,
2248,
23967,
666,
14,
199,
3,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3473,
199,
646,
2702,
199,
646,
11723,
19,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
267,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
6763,
2543,
492,
627,
199,
199,
3,
199,
3,
982,
314,
8582,
14,
576,
965,
282,
7282,
1329,
402,
5845,
12,
2066,
314,
5518,
3439,
199,
3,
911,
506,
7437,
900,
406,
26745,
334,
10254,
1616,
11,
9395,
367,
11630,
5845,
9,
340,
314,
199,
3,
1275,
697,
3050,
365,
641,
4543,
14,
14171,
314,
1275,
697,
570,
370,
30207,
4079,
27500,
370,
8112,
384,
199,
3,
314,
7252,
12,
1314,
911,
10415,
314,
900,
3224,
370,
9978,
4696,
14,
199,
3,
199,
388,
275,
11723,
19,
14,
2242,
4769,
2374,
15,
609,
77,
15,
9452,
14,
697,
531,
199,
388,
14,
20808,
63,
1896,
275,
488,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
607,
3307,
63,
5037,
3427,
78,
2,
398,
327,
267,
327,
12823,
1218,
9978,
6716,
737,
314,
1343,
12,
4837,
1533,
63,
914,
365,
367,
19599,
11087,
666,
543,
267,
327,
2248,
23967,
2256,
12,
1830,
3805,
63,
4368,
365,
367,
8605,
1566,
14,
267,
327,
267,
406,
14,
2526,
4852,
355,
1218,
1817,
340,
440,
3495,
3805,
63,
4368,
334,
717,
536,
1318,
12,
717,
5272,
1318,
12,
717,
1923,
1318,
12,
717,
25547,
1318,
355,
20682,
6141,
267,
406,
14,
2526,
4852,
355,
1218,
1817,
340,
440,
3495,
4837,
1533,
63,
914,
334,
717,
536,
1318,
12,
717,
5272,
1318,
12,
717,
1923,
1318,
12,
717,
25547,
1318,
12,
717,
3285,
3000,
12,
717,
3384,
3000,
12,
717,
2004,
3000,
12,
717,
366,
261,
3000,
12,
717,
366,
416,
3000,
12,
717,
8396,
3000,
355,
20682,
6141,
199,
199,
3,
199,
3,
2790,
436,
5518,
1566,
909,
370,
282,
3050,
880,
626,
922,
4293,
199,
3,
886,
1655,
11284,
543,
3486,
3050,
3718,
14,
199,
3,
199,
318,
2112,
63,
1430,
8,
635,
63,
807,
304,
267,
1566,
63,
962,
275,
1215,
63,
807,
905,
962,
937,
267,
2690,
258,
275,
1215,
63,
807,
905,
3271,
937,
267,
3066,
63,
1436,
259,
275,
1215,
63,
807,
905,
1773,
63,
1436,
937,
267,
1923,
755,
275,
1215,
63,
807,
905,
1404,
937,
267,
536,
755,
275,
1215,
63,
807,
905,
6857,
63,
354,
937,
398,
327,
10080,
436,
25547,
2256,
787,
440,
3544,
12152,
267,
340,
334,
635,
63,
807,
14,
1989,
63,
498,
480,
32211,
14150,
355,
25547,
275,
1215,
63,
807,
905,
32211,
937,
267,
587,
26,
355,
25547,
275,
298,
5912,
63,
32211,
2,
398,
340,
334,
635,
63,
807,
14,
1989,
63,
498,
480,
5155,
14150,
355,
5272,
275,
1215,
63,
807,
905,
5155,
937,
267,
587,
26,
355,
5272,
275,
298,
5912,
63,
5155,
2,
398,
327,
2790,
314,
1566,
909,
436,
5518,
652,
370,
314,
2451,
1817,
315,
3050,
267,
1566,
275,
1218,
63,
1430,
8,
354,
12,
1923,
12,
25547,
12,
5272,
12,
3066,
63,
1436,
9,
267,
5518,
63,
697,
8,
1430,
9,
199,
199,
318,
5518,
63,
697,
8,
1430,
304,
267,
340,
1566,
14,
6857,
63,
466,
508,
30069,
2711,
63,
29395,
26,
355,
406,
14,
2526,
480,
3176,
1901,
3805,
63,
4368,
1338,
2229,
12,
21259,
21259,
5805,
4186,
1816,
334,
1430,
14,
354,
12,
1566,
14,
5155,
12,
1566,
14,
1404,
12,
1566,
14,
32211,
430,
267,
916,
1566,
14,
6857,
63,
466,
508,
30069,
2711,
63,
1510,
11087,
63,
4464,
26,
355,
1566,
14,
711,
18415,
378,
88,
23,
15798,
12596,
70,
355,
1566,
14,
68,
416,
18415,
378,
88,
23,
15798,
12596,
70,
355,
406,
14,
2526,
480,
3176,
1901,
4837,
1533,
63,
914,
1338,
7558,
12,
21259,
21259,
21259,
21259,
21259,
21259,
21259,
21259,
5805,
4186,
717,
334,
1430,
14,
354,
12,
1566,
14,
5155,
12,
1566,
14,
1404,
12,
1566,
14,
32211,
12,
1566,
14,
2469,
12,
1816,
1566,
14,
711,
12,
1566,
14,
1205,
12,
1566,
14,
68,
261,
12,
1566,
14,
68,
416,
12,
1566,
14,
4452,
430,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
298,
607,
3307,
63,
500,
3427,
78,
2,
267,
327,
2136,
2498,
314,
5678,
2256,
367,
314,
499,
730,
402,
1566,
3992,
267,
2498,
63,
10706,
63,
4368,
342,
267,
2498,
63,
321,
1533,
63,
914,
342,
267,
406,
14,
1600,
342,
199,
199,
3,
199,
3,
3709,
314,
1566,
1329,
1443,
506,
7437,
7282,
12,
880,
781,
883,
1133,
675,
7798,
4340,
199,
3,
370,
2498,
314,
15379,
315,
3363,
1329,
12,
1325,
675,
282,
943,
18,
5563,
14,
199,
3,
199,
199,
318,
1967,
18,
3840,
8,
1507,
304,
267,
327,
7048,
1329,
911,
1172,
737,
5210,
1373,
19619,
267,
308,
1507,
275,
19619,
627,
334,
442,
5130,
3442,
14,
793,
8,
1507,
12,
499,
9,
435,
413,
9,
267,
372,
308,
1507,
199,
199,
318,
2498,
63,
10706,
63,
4368,
837
] |
[
1566,
63,
4797,
20135,
63,
3271,
14,
647,
26,
8605,
1566,
3016,
315,
2366,
199,
3,
199,
3,
9338,
8582,
3622,
365,
2575,
7437,
7074,
1893,
543,
314,
11262,
17806,
972,
12,
199,
3,
436,
642,
2884,
365,
440,
9936,
370,
506,
465,
7074,
1893,
465,
8582,
3622,
12,
1325,
199,
3,
13070,
1284,
922,
15,
11071,
282,
26841,
4340,
370,
19897,
314,
4474,
1163,
199,
3,
2419,
3307,
4501,
14,
199,
3,
199,
3,
710,
499,
3050,
4048,
3423,
315,
642,
2884,
2951,
2498,
4212,
370,
13082,
199,
3,
314,
5678,
2556,
12,
436,
4390,
883,
2811,
436,
2218,
3932,
5705,
3423,
199,
3,
7182,
370,
3932,
2488,
10685,
14,
199,
3,
199,
3,
710,
1642,
805,
298,
2384,
63,
10706,
63,
4368,
2,
2951,
1630,
282,
5678,
17786,
367,
1006,
199,
3,
7809,
4474,
543,
314,
1720,
402,
11723,
12,
436,
314,
499,
977,
1373,
298,
2384,
63,
321,
1533,
63,
914,
2,
365,
199,
3,
367,
282,
671,
1184,
869,
55,
27320,
53,
1566,
26,
19599,
11087,
543,
2248,
23967,
666,
14,
199,
3,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3473,
199,
646,
2702,
199,
646,
11723,
19,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
267,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
6763,
2543,
492,
627,
199,
199,
3,
199,
3,
982,
314,
8582,
14,
576,
965,
282,
7282,
1329,
402,
5845,
12,
2066,
314,
5518,
3439,
199,
3,
911,
506,
7437,
900,
406,
26745,
334,
10254,
1616,
11,
9395,
367,
11630,
5845,
9,
340,
314,
199,
3,
1275,
697,
3050,
365,
641,
4543,
14,
14171,
314,
1275,
697,
570,
370,
30207,
4079,
27500,
370,
8112,
384,
199,
3,
314,
7252,
12,
1314,
911,
10415,
314,
900,
3224,
370,
9978,
4696,
14,
199,
3,
199,
388,
275,
11723,
19,
14,
2242,
4769,
2374,
15,
609,
77,
15,
9452,
14,
697,
531,
199,
388,
14,
20808,
63,
1896,
275,
488,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
607,
3307,
63,
5037,
3427,
78,
2,
398,
327,
267,
327,
12823,
1218,
9978,
6716,
737,
314,
1343,
12,
4837,
1533,
63,
914,
365,
367,
19599,
11087,
666,
543,
267,
327,
2248,
23967,
2256,
12,
1830,
3805,
63,
4368,
365,
367,
8605,
1566,
14,
267,
327,
267,
406,
14,
2526,
4852,
355,
1218,
1817,
340,
440,
3495,
3805,
63,
4368,
334,
717,
536,
1318,
12,
717,
5272,
1318,
12,
717,
1923,
1318,
12,
717,
25547,
1318,
355,
20682,
6141,
267,
406,
14,
2526,
4852,
355,
1218,
1817,
340,
440,
3495,
4837,
1533,
63,
914,
334,
717,
536,
1318,
12,
717,
5272,
1318,
12,
717,
1923,
1318,
12,
717,
25547,
1318,
12,
717,
3285,
3000,
12,
717,
3384,
3000,
12,
717,
2004,
3000,
12,
717,
366,
261,
3000,
12,
717,
366,
416,
3000,
12,
717,
8396,
3000,
355,
20682,
6141,
199,
199,
3,
199,
3,
2790,
436,
5518,
1566,
909,
370,
282,
3050,
880,
626,
922,
4293,
199,
3,
886,
1655,
11284,
543,
3486,
3050,
3718,
14,
199,
3,
199,
318,
2112,
63,
1430,
8,
635,
63,
807,
304,
267,
1566,
63,
962,
275,
1215,
63,
807,
905,
962,
937,
267,
2690,
258,
275,
1215,
63,
807,
905,
3271,
937,
267,
3066,
63,
1436,
259,
275,
1215,
63,
807,
905,
1773,
63,
1436,
937,
267,
1923,
755,
275,
1215,
63,
807,
905,
1404,
937,
267,
536,
755,
275,
1215,
63,
807,
905,
6857,
63,
354,
937,
398,
327,
10080,
436,
25547,
2256,
787,
440,
3544,
12152,
267,
340,
334,
635,
63,
807,
14,
1989,
63,
498,
480,
32211,
14150,
355,
25547,
275,
1215,
63,
807,
905,
32211,
937,
267,
587,
26,
355,
25547,
275,
298,
5912,
63,
32211,
2,
398,
340,
334,
635,
63,
807,
14,
1989,
63,
498,
480,
5155,
14150,
355,
5272,
275,
1215,
63,
807,
905,
5155,
937,
267,
587,
26,
355,
5272,
275,
298,
5912,
63,
5155,
2,
398,
327,
2790,
314,
1566,
909,
436,
5518,
652,
370,
314,
2451,
1817,
315,
3050,
267,
1566,
275,
1218,
63,
1430,
8,
354,
12,
1923,
12,
25547,
12,
5272,
12,
3066,
63,
1436,
9,
267,
5518,
63,
697,
8,
1430,
9,
199,
199,
318,
5518,
63,
697,
8,
1430,
304,
267,
340,
1566,
14,
6857,
63,
466,
508,
30069,
2711,
63,
29395,
26,
355,
406,
14,
2526,
480,
3176,
1901,
3805,
63,
4368,
1338,
2229,
12,
21259,
21259,
5805,
4186,
1816,
334,
1430,
14,
354,
12,
1566,
14,
5155,
12,
1566,
14,
1404,
12,
1566,
14,
32211,
430,
267,
916,
1566,
14,
6857,
63,
466,
508,
30069,
2711,
63,
1510,
11087,
63,
4464,
26,
355,
1566,
14,
711,
18415,
378,
88,
23,
15798,
12596,
70,
355,
1566,
14,
68,
416,
18415,
378,
88,
23,
15798,
12596,
70,
355,
406,
14,
2526,
480,
3176,
1901,
4837,
1533,
63,
914,
1338,
7558,
12,
21259,
21259,
21259,
21259,
21259,
21259,
21259,
21259,
5805,
4186,
717,
334,
1430,
14,
354,
12,
1566,
14,
5155,
12,
1566,
14,
1404,
12,
1566,
14,
32211,
12,
1566,
14,
2469,
12,
1816,
1566,
14,
711,
12,
1566,
14,
1205,
12,
1566,
14,
68,
261,
12,
1566,
14,
68,
416,
12,
1566,
14,
4452,
430,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
298,
607,
3307,
63,
500,
3427,
78,
2,
267,
327,
2136,
2498,
314,
5678,
2256,
367,
314,
499,
730,
402,
1566,
3992,
267,
2498,
63,
10706,
63,
4368,
342,
267,
2498,
63,
321,
1533,
63,
914,
342,
267,
406,
14,
1600,
342,
199,
199,
3,
199,
3,
3709,
314,
1566,
1329,
1443,
506,
7437,
7282,
12,
880,
781,
883,
1133,
675,
7798,
4340,
199,
3,
370,
2498,
314,
15379,
315,
3363,
1329,
12,
1325,
675,
282,
943,
18,
5563,
14,
199,
3,
199,
199,
318,
1967,
18,
3840,
8,
1507,
304,
267,
327,
7048,
1329,
911,
1172,
737,
5210,
1373,
19619,
267,
308,
1507,
275,
19619,
627,
334,
442,
5130,
3442,
14,
793,
8,
1507,
12,
499,
9,
435,
413,
9,
267,
372,
308,
1507,
199,
199,
318,
2498,
63,
10706,
63,
4368,
837,
0
] |
[
1,
1,
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bard/fishfeedtime
|
fishfeedtime.py
|
1
|
4825
|
#!/usr/bin/python
#
# Fishfeedtime powers down Powerheads/Filters/Pumps of your choice (which are connected to 433.92MHz power socket controllers)
# for a set duration.
#
## GPIO Pin Definitions
# Pin with button circuit GPIO Pullup
BUTTON = 25
# LED Pin if present...
LED = True
LEDPIN = 11
# Pin connect to 434MHz transmit Data Line. -- NOT CONFIGURABLE, connect to *** PIN26 // GPIO7 ***
##TRANS = 7
# Seconds to turn everything off for on button push: ## 900s = 15mins
OFFTIME = 900
# Time (s) before OFFTIME to sound alert.
WARNTIME = 60
# Do we have a buzzer here?
BUZZER = True
# If "True" - which GPIO Pin to use it?
BUZPIN = 8
# Where can the https://github.com/dmcg/raspberry-strogonanoff script be found?
switchscript = "~fishfeedtime/fishfeedtime/switch"
# List of dictionaries detailing channel and buttons for the desired controlled sockets:
## Socket 1 controls the two Powerheads.
## Socket 2 is the Canister Filter
## Socket 3 is Skimmer
SOCKETS = [ {"socket": "1"}, {"socket": "2"}, {"socket": "3"} ]
# Set verbosity ## True//False
VERBOSE = False
## Import needed modules
import time, os, sys
import RPi.GPIO as GPIO
## Detect early on that we're running with root permissions!
if not os.geteuid() == 0:
sys.exit('Script must run as root')
# Setup GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
if BUZZER == True:
GPIO.setup(BUZPIN, GPIO.OUT, False)
if LED == True:
GPIO.setup(LEDPIN, GPIO.OUT, False)
GPIO.setup(BUTTON, GPIO.IN)
def sockets(state):
if state == "on" or state == "off":
if VERBOSE == True:
print("Switching Sockets " + str(state))
for a in SOCKETS:
sock = str(a['socket'])
switchcmd = str(switchscript) + " " + str(sock) + " " + str(state)
if VERBOSE == True:
print(switchcmd)
os.system(switchcmd)
else:
print("Invalid state sent to sockets(): " + str(state))
raise
## Put sockets on initially (Useful if Pi init script is restarted with
## sockets in an off state.
print("Initialising: ensuring sockets are ON...")
sockets("on")
def button_state():
# If button not pressed (Open)
if (GPIO.input(BUTTON)):
return "Open"
else:
return "Closed"
def ledswitch(ledstate):
if LED == True:
if ledstate == "on":
GPIO.output(LEDPIN, True)
elif ledstate == "off":
GPIO.output(LEDPIN, False)
else:
print("Invalid state passed to ledswitch: " + str(ledstate))
raise
else:
if VERBOSE == True:
print("LED not configured.")
def sound_buzzer():
if BUZZER == True:
# Make some noise!
if VERBOSE == True:
print("Beep")
GPIO.output(BUZPIN, True)
time.sleep(0.1)
GPIO.output(BUZPIN, False)
else:
if VERBOSE == True:
print("Buzzer not configured.")
def run_timer():
print("Feed Time Started")
ledswitch("on")
sound_buzzer()
sockets("off")
start = time.time()
# Insert a small time delay to ensure that devices are not immediately switched back on if button is held down.
delay = 2
time.sleep(delay)
fulltime = int(OFFTIME - delay)
warntime = int(fulltime - WARNTIME)
warned = False
count = 0
GPIO.add_event_detect(BUTTON, GPIO.RISING, bouncetime=200)
while time.time() - start < fulltime:
if VERBOSE == True:
print("Count: " + str(count))
count = count + 1
if GPIO.event_detected(BUTTON):
if VERBOSE == True:
print("Button Push Override Detected.")
GPIO.remove_event_detect(BUTTON)
break
if time.time() - start > warntime and warned == False:
if VERBOSE == True:
print("Warning Time Reached.")
sound_buzzer()
time.sleep(0.3)
sound_buzzer()
time.sleep(0.3)
sound_buzzer()
warned = True
else:
time.sleep(1)
print("Feed Time Ended.")
GPIO.remove_event_detect(BUTTON)
sound_buzzer()
sockets("on")
ledswitch("off")
## Actual run
# Check switchcode exists:
### NEEDS FIXING
#if not os.path.isfile(switchscript):
# print("Failed to locate " + str(switchscript))
# sys.exit(1)
try:
while True:
print("Listening for feeding time...")
#GPIO.add_event_detect(BUTTON, GPIO.RISING, bouncetime=200)
GPIO.wait_for_edge(BUTTON, GPIO.RISING)
GPIO.remove_event_detect(BUTTON)
run_timer()
except KeyboardInterrupt:
print("\n\nKeyboard Interrupt. Ensuring sockets are Enabled...")
sound_buzzer()
time.sleep(0.2)
sound_buzzer()
sockets("on")
ledswitch("off")
GPIO.cleanup()
print("Exiting...")
sys.exit(0)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
481,
2453,
3871,
521,
13131,
1192,
3224,
18879,
17033,
15,
18053,
15,
48,
1220,
83,
402,
2195,
7141,
334,
6777,
787,
8539,
370,
841,
1153,
14,
2942,
22860,
7074,
2838,
27325,
9,
199,
3,
367,
282,
663,
7373,
14,
199,
3,
199,
199,
309,
20899,
26486,
22659,
852,
199,
3,
26486,
543,
5528,
20304,
20899,
27705,
384,
199,
13272,
275,
5661,
199,
3,
491,
1149,
26486,
340,
3451,
1396,
199,
5290,
275,
715,
199,
5290,
30929,
275,
4119,
199,
3,
26486,
4907,
370,
841,
1082,
22860,
27754,
3918,
7030,
14,
1553,
2845,
15869,
1230,
2617,
12,
4907,
370,
19688,
510,
568,
1479,
5001,
20899,
23,
19688,
199,
309,
12191,
275,
1520,
199,
3,
3240,
2776,
370,
7485,
8137,
2331,
367,
641,
5528,
6675,
26,
925,
27151,
83,
275,
4114,
29361,
199,
7517,
4961,
275,
27151,
199,
3,
4703,
334,
83,
9,
2544,
1634,
2161,
3465,
370,
20453,
10459,
14,
199,
17449,
4961,
275,
5212,
199,
3,
4226,
781,
1172,
282,
1032,
90,
2282,
2348,
31,
199,
2910,
9909,
540,
275,
715,
199,
3,
982,
298,
549,
2,
446,
1314,
20899,
26486,
370,
675,
652,
31,
199,
2910,
58,
30929,
275,
1695,
199,
3,
17685,
883,
314,
4178,
921,
5031,
14,
957,
15,
68,
5466,
71,
15,
6360,
80,
605,
651,
13,
270,
19029,
265,
290,
1997,
2884,
506,
1911,
31,
199,
5656,
1579,
275,
26810,
16056,
3871,
521,
15,
16056,
3871,
521,
15,
5656,
2,
199,
3,
3820,
402,
11196,
10093,
316,
3623,
436,
15766,
367,
314,
6387,
22284,
18772,
26,
199,
309,
17766,
413,
13467,
314,
2877,
18879,
17033,
14,
199,
309,
17766,
499,
365,
314,
6855,
1429,
9388,
199,
309,
17766,
650,
365,
29201,
1017,
2626,
199,
17462,
51,
275,
359,
2420,
3450,
582,
298,
17,
6018,
2420,
3450,
582,
298,
18,
6018,
2420,
3450,
582,
298,
19,
3570,
1622,
199,
199,
3,
2494,
8661,
925,
715,
501,
797,
199,
16075,
275,
756,
199,
199,
309,
3161,
4346,
4621,
199,
646,
900,
12,
747,
12,
984,
199,
646,
820,
10542,
14,
21071,
465,
20899,
199,
199,
309,
30577,
14670,
641,
626,
781,
3984,
3879,
543,
1738,
3443,
1,
199,
692,
440,
747,
14,
31508,
1535,
342,
508,
378,
26,
267,
984,
14,
2224,
360,
5229,
1471,
1255,
465,
1738,
358,
199,
199,
3,
12439,
20899,
199,
21071,
14,
409,
632,
8,
21071,
14,
6265,
45,
9,
199,
21071,
14,
409,
5451,
8,
797,
9,
199,
692,
16331,
9909,
540,
508,
715,
26,
272,
20899,
14,
2758,
8,
2910,
58,
30929,
12,
20899,
14,
1877,
12,
756,
9,
199,
692,
491,
1149,
508,
715,
26,
272,
20899,
14,
2758,
8,
5290,
30929,
12,
20899,
14,
1877,
12,
756,
9,
199,
21071,
14,
2758,
8,
13272,
12,
20899,
14,
568,
9,
199,
199,
318,
18772,
8,
929,
304,
272,
340,
1174,
508,
298,
265,
2,
503,
1174,
508,
298,
1997,
582,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
10167,
316,
17766,
83,
298,
435,
620,
8,
929,
430,
267,
367,
282,
315,
3562,
15244,
51,
26,
288,
6771,
275,
620,
8,
65,
459,
3450,
1105,
288,
6258,
1760,
275,
620,
8,
5656,
1579,
9,
435,
298,
298,
435,
620,
8,
5096,
9,
435,
298,
298,
435,
620,
8,
929,
9,
288,
340,
12348,
14607,
508,
715,
26,
355,
870,
8,
5656,
1760,
9,
288,
747,
14,
2253,
8,
5656,
1760,
9,
272,
587,
26,
267,
870,
480,
3364,
1174,
4847,
370,
18772,
837,
298,
435,
620,
8,
929,
430,
267,
746,
199,
199,
309,
16280,
18772,
641,
22801,
334,
6119,
1893,
340,
19835,
4205,
2884,
365,
32277,
543,
199,
309,
18772,
315,
376,
2331,
1174,
14,
199,
1361,
480,
5733,
11136,
26,
12889,
4039,
18772,
787,
5258,
12594,
199,
20517,
480,
265,
531,
199,
199,
318,
5528,
63,
929,
837,
272,
327,
982,
5528,
440,
25167,
334,
4299,
9,
272,
340,
334,
21071,
14,
1210,
8,
13272,
2298,
267,
372,
298,
4299,
2,
272,
587,
26,
267,
372,
298,
15190,
2,
199,
199,
318,
1026,
795,
3111,
8,
1146,
929,
304,
272,
340,
491,
1149,
508,
715,
26,
267,
340,
29239,
929,
508,
298,
265,
582,
288,
20899,
14,
1199,
8,
5290,
30929,
12,
715,
9,
267,
916,
29239,
929,
508,
298,
1997,
582,
288,
20899,
14,
1199,
8,
5290,
30929,
12,
756,
9,
267,
587,
26,
288,
870,
480,
3364,
1174,
3032,
370,
1026,
795,
3111,
26,
298,
435,
620,
8,
1146,
929,
430,
288,
746,
272,
587,
26,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
5290,
440,
7526,
2685,
489,
199,
318,
20453,
63,
464,
90,
2282,
837,
272,
340,
16331,
9909,
540,
508,
715,
26,
267,
327,
4155,
2005,
11145,
1,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
34,
7840,
531,
267,
20899,
14,
1199,
8,
2910,
58,
30929,
12,
715,
9,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
20899,
14,
1199,
8,
2910,
58,
30929,
12,
756,
9,
272,
587,
26,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
1713,
90,
2282,
440,
7526,
2685,
199,
199,
318,
1255,
63,
7414,
837,
272,
870,
480,
7658,
4703,
1933,
5015,
531,
272,
1026,
795,
3111,
480,
265,
531,
272,
20453,
63,
464,
90,
2282,
342,
272,
18772,
480,
1997,
531,
272,
1343,
275,
900,
14,
521,
342,
272,
327,
15496,
282,
7425,
900,
7339,
370,
4868,
626,
7256,
787,
440,
9939,
308,
28986,
1771,
641,
340,
5528,
365,
23608,
3224,
14,
272,
7339,
275,
499,
272,
900,
14,
4532,
8,
5814,
9,
272,
2615,
521,
275,
1109,
8,
7517,
4961,
446,
7339,
9,
272,
7987,
521,
275,
1109,
8,
2861,
521,
446,
13253,
46,
4961,
9,
272,
7987,
379,
275,
756,
272,
2338,
275,
378,
272,
20899,
14,
525,
63,
1430,
63,
13552,
8,
13272,
12,
20899,
14,
50,
6978,
12,
1234,
10222,
521,
29,
1840,
9,
272,
1830,
900,
14,
521,
342,
446,
1343,
665,
2615,
521,
26,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
2353,
26,
298,
435,
620,
8,
835,
430,
288,
2338,
275,
2338,
435,
413,
267,
340,
20899,
14,
1430,
63,
25577,
8,
13272,
304,
288,
340,
12348,
14607
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
481,
2453,
3871,
521,
13131,
1192,
3224,
18879,
17033,
15,
18053,
15,
48,
1220,
83,
402,
2195,
7141,
334,
6777,
787,
8539,
370,
841,
1153,
14,
2942,
22860,
7074,
2838,
27325,
9,
199,
3,
367,
282,
663,
7373,
14,
199,
3,
199,
199,
309,
20899,
26486,
22659,
852,
199,
3,
26486,
543,
5528,
20304,
20899,
27705,
384,
199,
13272,
275,
5661,
199,
3,
491,
1149,
26486,
340,
3451,
1396,
199,
5290,
275,
715,
199,
5290,
30929,
275,
4119,
199,
3,
26486,
4907,
370,
841,
1082,
22860,
27754,
3918,
7030,
14,
1553,
2845,
15869,
1230,
2617,
12,
4907,
370,
19688,
510,
568,
1479,
5001,
20899,
23,
19688,
199,
309,
12191,
275,
1520,
199,
3,
3240,
2776,
370,
7485,
8137,
2331,
367,
641,
5528,
6675,
26,
925,
27151,
83,
275,
4114,
29361,
199,
7517,
4961,
275,
27151,
199,
3,
4703,
334,
83,
9,
2544,
1634,
2161,
3465,
370,
20453,
10459,
14,
199,
17449,
4961,
275,
5212,
199,
3,
4226,
781,
1172,
282,
1032,
90,
2282,
2348,
31,
199,
2910,
9909,
540,
275,
715,
199,
3,
982,
298,
549,
2,
446,
1314,
20899,
26486,
370,
675,
652,
31,
199,
2910,
58,
30929,
275,
1695,
199,
3,
17685,
883,
314,
4178,
921,
5031,
14,
957,
15,
68,
5466,
71,
15,
6360,
80,
605,
651,
13,
270,
19029,
265,
290,
1997,
2884,
506,
1911,
31,
199,
5656,
1579,
275,
26810,
16056,
3871,
521,
15,
16056,
3871,
521,
15,
5656,
2,
199,
3,
3820,
402,
11196,
10093,
316,
3623,
436,
15766,
367,
314,
6387,
22284,
18772,
26,
199,
309,
17766,
413,
13467,
314,
2877,
18879,
17033,
14,
199,
309,
17766,
499,
365,
314,
6855,
1429,
9388,
199,
309,
17766,
650,
365,
29201,
1017,
2626,
199,
17462,
51,
275,
359,
2420,
3450,
582,
298,
17,
6018,
2420,
3450,
582,
298,
18,
6018,
2420,
3450,
582,
298,
19,
3570,
1622,
199,
199,
3,
2494,
8661,
925,
715,
501,
797,
199,
16075,
275,
756,
199,
199,
309,
3161,
4346,
4621,
199,
646,
900,
12,
747,
12,
984,
199,
646,
820,
10542,
14,
21071,
465,
20899,
199,
199,
309,
30577,
14670,
641,
626,
781,
3984,
3879,
543,
1738,
3443,
1,
199,
692,
440,
747,
14,
31508,
1535,
342,
508,
378,
26,
267,
984,
14,
2224,
360,
5229,
1471,
1255,
465,
1738,
358,
199,
199,
3,
12439,
20899,
199,
21071,
14,
409,
632,
8,
21071,
14,
6265,
45,
9,
199,
21071,
14,
409,
5451,
8,
797,
9,
199,
692,
16331,
9909,
540,
508,
715,
26,
272,
20899,
14,
2758,
8,
2910,
58,
30929,
12,
20899,
14,
1877,
12,
756,
9,
199,
692,
491,
1149,
508,
715,
26,
272,
20899,
14,
2758,
8,
5290,
30929,
12,
20899,
14,
1877,
12,
756,
9,
199,
21071,
14,
2758,
8,
13272,
12,
20899,
14,
568,
9,
199,
199,
318,
18772,
8,
929,
304,
272,
340,
1174,
508,
298,
265,
2,
503,
1174,
508,
298,
1997,
582,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
10167,
316,
17766,
83,
298,
435,
620,
8,
929,
430,
267,
367,
282,
315,
3562,
15244,
51,
26,
288,
6771,
275,
620,
8,
65,
459,
3450,
1105,
288,
6258,
1760,
275,
620,
8,
5656,
1579,
9,
435,
298,
298,
435,
620,
8,
5096,
9,
435,
298,
298,
435,
620,
8,
929,
9,
288,
340,
12348,
14607,
508,
715,
26,
355,
870,
8,
5656,
1760,
9,
288,
747,
14,
2253,
8,
5656,
1760,
9,
272,
587,
26,
267,
870,
480,
3364,
1174,
4847,
370,
18772,
837,
298,
435,
620,
8,
929,
430,
267,
746,
199,
199,
309,
16280,
18772,
641,
22801,
334,
6119,
1893,
340,
19835,
4205,
2884,
365,
32277,
543,
199,
309,
18772,
315,
376,
2331,
1174,
14,
199,
1361,
480,
5733,
11136,
26,
12889,
4039,
18772,
787,
5258,
12594,
199,
20517,
480,
265,
531,
199,
199,
318,
5528,
63,
929,
837,
272,
327,
982,
5528,
440,
25167,
334,
4299,
9,
272,
340,
334,
21071,
14,
1210,
8,
13272,
2298,
267,
372,
298,
4299,
2,
272,
587,
26,
267,
372,
298,
15190,
2,
199,
199,
318,
1026,
795,
3111,
8,
1146,
929,
304,
272,
340,
491,
1149,
508,
715,
26,
267,
340,
29239,
929,
508,
298,
265,
582,
288,
20899,
14,
1199,
8,
5290,
30929,
12,
715,
9,
267,
916,
29239,
929,
508,
298,
1997,
582,
288,
20899,
14,
1199,
8,
5290,
30929,
12,
756,
9,
267,
587,
26,
288,
870,
480,
3364,
1174,
3032,
370,
1026,
795,
3111,
26,
298,
435,
620,
8,
1146,
929,
430,
288,
746,
272,
587,
26,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
5290,
440,
7526,
2685,
489,
199,
318,
20453,
63,
464,
90,
2282,
837,
272,
340,
16331,
9909,
540,
508,
715,
26,
267,
327,
4155,
2005,
11145,
1,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
34,
7840,
531,
267,
20899,
14,
1199,
8,
2910,
58,
30929,
12,
715,
9,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
20899,
14,
1199,
8,
2910,
58,
30929,
12,
756,
9,
272,
587,
26,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
1713,
90,
2282,
440,
7526,
2685,
199,
199,
318,
1255,
63,
7414,
837,
272,
870,
480,
7658,
4703,
1933,
5015,
531,
272,
1026,
795,
3111,
480,
265,
531,
272,
20453,
63,
464,
90,
2282,
342,
272,
18772,
480,
1997,
531,
272,
1343,
275,
900,
14,
521,
342,
272,
327,
15496,
282,
7425,
900,
7339,
370,
4868,
626,
7256,
787,
440,
9939,
308,
28986,
1771,
641,
340,
5528,
365,
23608,
3224,
14,
272,
7339,
275,
499,
272,
900,
14,
4532,
8,
5814,
9,
272,
2615,
521,
275,
1109,
8,
7517,
4961,
446,
7339,
9,
272,
7987,
521,
275,
1109,
8,
2861,
521,
446,
13253,
46,
4961,
9,
272,
7987,
379,
275,
756,
272,
2338,
275,
378,
272,
20899,
14,
525,
63,
1430,
63,
13552,
8,
13272,
12,
20899,
14,
50,
6978,
12,
1234,
10222,
521,
29,
1840,
9,
272,
1830,
900,
14,
521,
342,
446,
1343,
665,
2615,
521,
26,
267,
340,
12348,
14607,
508,
715,
26,
288,
870,
480,
2353,
26,
298,
435,
620,
8,
835,
430,
288,
2338,
275,
2338,
435,
413,
267,
340,
20899,
14,
1430,
63,
25577,
8,
13272,
304,
288,
340,
12348,
14607,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
laborautonomo/django-extensions
|
django_extensions/management/utils.py
|
8
|
2237
|
from django.conf import settings
import os
import sys
import logging
try:
from importlib import import_module
except ImportError:
try:
from django.utils.importlib import import_module
except ImportError:
def import_module(module):
return __import__(module, {}, {}, [''])
def get_project_root():
""" get the project root directory """
django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE')
if not django_settings_module:
module_str = settings.SETTINGS_MODULE
else:
module_str = django_settings_module.split(".")[0]
mod = import_module(module_str)
return os.path.dirname(os.path.abspath(mod.__file__))
def _make_writeable(filename):
"""
Make sure that the file is writeable. Useful if our source is
read-only.
"""
import stat
if sys.platform.startswith('java'):
# On Jython there is no os.access()
return
if not os.access(filename, os.W_OK):
st = os.stat(filename)
new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
os.chmod(filename, new_permissions)
def setup_logger(logger, stream, filename=None, fmt=None):
"""Sets up a logger (if no handlers exist) for console output,
and file 'tee' output if desired."""
if len(logger.handlers) < 1:
console = logging.StreamHandler(stream)
console.setLevel(logging.DEBUG)
console.setFormatter(logging.Formatter(fmt))
logger.addHandler(console)
logger.setLevel(logging.DEBUG)
if filename:
outfile = logging.FileHandler(filename)
outfile.setLevel(logging.INFO)
outfile.setFormatter(logging.Formatter("%(asctime)s " + (fmt if fmt else '%(message)s')))
logger.addHandler(outfile)
class RedirectHandler(logging.Handler):
"""Redirect logging sent to one logger (name) to another."""
def __init__(self, name, level=logging.DEBUG):
# Contemplate feasibility of copying a destination (allow original handler) and redirecting.
logging.Handler.__init__(self, level)
self.name = name
self.logger = logging.getLogger(name)
def emit(self, record):
self.logger.handle(record)
|
mit
|
[
504,
1639,
14,
2190,
492,
2202,
199,
646,
747,
199,
646,
984,
199,
646,
2050,
199,
199,
893,
26,
272,
687,
14802,
492,
492,
63,
578,
199,
2590,
3545,
26,
272,
862,
26,
267,
687,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
272,
871,
3545,
26,
267,
347,
492,
63,
578,
8,
578,
304,
288,
372,
636,
646,
721,
578,
12,
5479,
5479,
788,
1105,
421,
199,
318,
664,
63,
1715,
63,
1231,
837,
272,
408,
664,
314,
2199,
1738,
2082,
408,
272,
1639,
63,
1751,
63,
578,
275,
747,
14,
2314,
14,
362,
360,
22848,
63,
13931,
63,
10001,
358,
272,
340,
440,
1639,
63,
1751,
63,
578,
26,
267,
859,
63,
495,
275,
2202,
14,
13931,
63,
10001,
272,
587,
26,
267,
859,
63,
495,
275,
1639,
63,
1751,
63,
578,
14,
1294,
15857,
59,
16,
61,
272,
3413,
275,
492,
63,
578,
8,
578,
63,
495,
9,
272,
372,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1494,
855,
493,
8964,
421,
199,
318,
485,
1875,
63,
952,
461,
8,
1501,
304,
272,
408,
272,
4155,
3238,
626,
314,
570,
365,
2218,
461,
14,
18491,
340,
4154,
1350,
365,
272,
1586,
13,
2118,
14,
339,
408,
272,
492,
5672,
272,
340,
984,
14,
3246,
14,
2460,
360,
6138,
735,
267,
327,
4068,
25333,
2337,
365,
949,
747,
14,
2732,
342,
267,
372,
272,
340,
440,
747,
14,
2732,
8,
1501,
12,
747,
14,
55,
63,
3593,
304,
267,
410,
275,
747,
14,
3736,
8,
1501,
9,
267,
892,
63,
6060,
275,
5672,
14,
51,
63,
1469,
9125,
8,
270,
14,
270,
63,
632,
9,
1204,
5672,
14,
51,
63,
22275,
22592,
267,
747,
14,
11693,
8,
1501,
12,
892,
63,
6060,
9,
421,
199,
318,
3272,
63,
2921,
8,
2921,
12,
2547,
12,
1788,
29,
403,
12,
7104,
29,
403,
304,
272,
408,
9899,
1536,
282,
2512,
334,
692,
949,
8297,
2187,
9,
367,
8559,
1072,
12,
272,
436,
570,
283,
15557,
7,
1072,
340,
6387,
1041,
272,
340,
822,
8,
2921,
14,
5586,
9,
665,
413,
26,
267,
8559,
275,
2050,
14,
22482,
8,
1745,
9,
267,
8559,
14,
13548,
8,
4806,
14,
5287,
9,
267,
8559,
14,
26076,
8,
4806,
14,
7772,
8,
5045,
430,
267,
2512,
14,
18826,
8,
6614,
9,
267,
2512,
14,
13548,
8,
4806,
14,
5287,
9,
398,
340,
1788,
26,
288,
4386,
275,
2050,
14,
21982,
8,
1501,
9,
288,
4386,
14,
13548,
8,
4806,
14,
4531,
9,
288,
4386,
14,
26076,
8,
4806,
14,
7772,
480,
2840,
18331,
9,
83,
298,
435,
334,
5045,
340,
7104,
587,
9487,
1188,
9,
83,
7058,
288,
2512,
14,
18826,
8,
4984,
9,
421,
199,
533,
18532,
2461,
8,
4806,
14,
2461,
304,
272,
408,
7071,
2050,
4847,
370,
1373,
2512,
334,
354,
9,
370,
4573,
1041,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2166,
29,
4806,
14,
5287,
304,
267,
327,
1448,
1160,
1964,
305,
29524,
402,
16743,
282,
5724,
334,
3306,
3379,
3016,
9,
436,
4660,
316,
14,
267,
2050,
14,
2461,
855,
826,
721,
277,
12,
2166,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
2921,
275,
2050,
14,
5572,
8,
354,
9,
339,
347,
8689,
8,
277,
12,
2777,
304,
267,
291,
14,
2921,
14,
2479,
8,
3059,
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
] |
[
1639,
14,
2190,
492,
2202,
199,
646,
747,
199,
646,
984,
199,
646,
2050,
199,
199,
893,
26,
272,
687,
14802,
492,
492,
63,
578,
199,
2590,
3545,
26,
272,
862,
26,
267,
687,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
272,
871,
3545,
26,
267,
347,
492,
63,
578,
8,
578,
304,
288,
372,
636,
646,
721,
578,
12,
5479,
5479,
788,
1105,
421,
199,
318,
664,
63,
1715,
63,
1231,
837,
272,
408,
664,
314,
2199,
1738,
2082,
408,
272,
1639,
63,
1751,
63,
578,
275,
747,
14,
2314,
14,
362,
360,
22848,
63,
13931,
63,
10001,
358,
272,
340,
440,
1639,
63,
1751,
63,
578,
26,
267,
859,
63,
495,
275,
2202,
14,
13931,
63,
10001,
272,
587,
26,
267,
859,
63,
495,
275,
1639,
63,
1751,
63,
578,
14,
1294,
15857,
59,
16,
61,
272,
3413,
275,
492,
63,
578,
8,
578,
63,
495,
9,
272,
372,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1494,
855,
493,
8964,
421,
199,
318,
485,
1875,
63,
952,
461,
8,
1501,
304,
272,
408,
272,
4155,
3238,
626,
314,
570,
365,
2218,
461,
14,
18491,
340,
4154,
1350,
365,
272,
1586,
13,
2118,
14,
339,
408,
272,
492,
5672,
272,
340,
984,
14,
3246,
14,
2460,
360,
6138,
735,
267,
327,
4068,
25333,
2337,
365,
949,
747,
14,
2732,
342,
267,
372,
272,
340,
440,
747,
14,
2732,
8,
1501,
12,
747,
14,
55,
63,
3593,
304,
267,
410,
275,
747,
14,
3736,
8,
1501,
9,
267,
892,
63,
6060,
275,
5672,
14,
51,
63,
1469,
9125,
8,
270,
14,
270,
63,
632,
9,
1204,
5672,
14,
51,
63,
22275,
22592,
267,
747,
14,
11693,
8,
1501,
12,
892,
63,
6060,
9,
421,
199,
318,
3272,
63,
2921,
8,
2921,
12,
2547,
12,
1788,
29,
403,
12,
7104,
29,
403,
304,
272,
408,
9899,
1536,
282,
2512,
334,
692,
949,
8297,
2187,
9,
367,
8559,
1072,
12,
272,
436,
570,
283,
15557,
7,
1072,
340,
6387,
1041,
272,
340,
822,
8,
2921,
14,
5586,
9,
665,
413,
26,
267,
8559,
275,
2050,
14,
22482,
8,
1745,
9,
267,
8559,
14,
13548,
8,
4806,
14,
5287,
9,
267,
8559,
14,
26076,
8,
4806,
14,
7772,
8,
5045,
430,
267,
2512,
14,
18826,
8,
6614,
9,
267,
2512,
14,
13548,
8,
4806,
14,
5287,
9,
398,
340,
1788,
26,
288,
4386,
275,
2050,
14,
21982,
8,
1501,
9,
288,
4386,
14,
13548,
8,
4806,
14,
4531,
9,
288,
4386,
14,
26076,
8,
4806,
14,
7772,
480,
2840,
18331,
9,
83,
298,
435,
334,
5045,
340,
7104,
587,
9487,
1188,
9,
83,
7058,
288,
2512,
14,
18826,
8,
4984,
9,
421,
199,
533,
18532,
2461,
8,
4806,
14,
2461,
304,
272,
408,
7071,
2050,
4847,
370,
1373,
2512,
334,
354,
9,
370,
4573,
1041,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2166,
29,
4806,
14,
5287,
304,
267,
327,
1448,
1160,
1964,
305,
29524,
402,
16743,
282,
5724,
334,
3306,
3379,
3016,
9,
436,
4660,
316,
14,
267,
2050,
14,
2461,
855,
826,
721,
277,
12,
2166,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
2921,
275,
2050,
14,
5572,
8,
354,
9,
339,
347,
8689,
8,
277,
12,
2777,
304,
267,
291,
14,
2921,
14,
2479,
8,
3059,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
skyostil/albumart
|
lib/albumart/yahoo/search/webservices.py
|
1
|
48639
|
"""Yahoo Search Web Services
This module implements a set of classes and functions to work with the
Yahoo Search Web Services. All results from these services are properly
formatted XML, and this package facilitates for proper parsing of these
result sets. Some of the features include:
* Extendandable API, with replaceable backend XML parsers, and
I/O interface.
* Type and value checking on search parameters, including
automatic type conversion (when appropriate and possible)
* Flexible return format, including DOM objects, or fully
parsed result objects
You can either instantiate a search object directly, or use the factory
function create_search() in this module (see below). The supported classes
of searches are:
VideoSearch - Video Search
ImageSearch - Image Search
WebSearch - Web Search
NewsSearch - News Search
LocalSearch - Local Search
RelatedSuggestion - Web Search Related Suggestion
SpellingSuggestion - Web Search Spelling Suggestion
TermExtraction - Term Extraction service
ContextSearch - Web Search with a context
The different sub-classes of Search supports different sets of query
parameters. They all require an application ID parameter (app_id). The
following tables describes all other allowed parameters for each of the
supported services:
Web Related Spelling Context Term
----- ------- -------- ------- ------
query [X] [X] [X] [X] [X]
type [X] . . [X]
results [X] [X] . [X]
start [X] . . [X]
format [X] . . [X]
adult_ok [X] . . [X]
similar_ok [X] . . [X]
language [X] . . [X]
country [X] . . [X]
context . . . [X] [X]
Image Video News Local
----- ----- ----- -----
query [X] [X] [X] [X]
type [X] [X] [X] .
results [X] [X] [X] [X]
start [X] [X] [X] [X]
format [X] [X] . .
adult_ok [X] [X] . .
language . . . [X]
country . . . .
sort . . [X] [X]
coloration [X] . . .
radius . . . [X]
street . . . [X]
city . . . [X]
state . . . [X]
zip . . . [X]
location . . . [X]
longitude . . . [X]
latitude . . . [X]
List Folders List URLs
------------ ---------
folder . [X]
yahooid [X] [X]
results [X] [X]
start [X] [X]
Each of these parameter is implemented as an attribute of each
respective class. For example, you can set parameters like:
from yahoo.search.webservices import WebSearch
app_id = "something"
srch = WebSearch(app_id)
srch.query = "Leif Hedstrom"
srch.results = 40
or, if you are using the factory function:
from yahoo.search.webservices import create_search
app_id = "something"
srch = create_search("Web", app_id, query="Leif Hedstrom", results=40)
or, the last alternative, a combination of the previous two:
from yahoo.search.webservices import WebSearch
app_id = "something"
srch = WebSearch(app_id, query="Leif Hedstrom", results=40)
To retrieve a certain parameter value, simply access it as any normal
attribute:
print "Searched for ", srch.query
For more information on these parameters, and their allowed values, please
see the official Yahoo Search Services documentation (XXX missing URL?)
Once the webservice object has been created, you can retrieve a parsed
object (typically a DOM object) using the get_results() method:
dom = srch.get_results()
This DOM object contains all results, and can be used as is. For easier
use of the results, you can use the built-in results factory, which will
traverse the entire DOM object, and create a list of results objects.
results = srch.parse_results(dom)
or, by using the implicit call to get_results():
results = srch.parse_results()
The default XML parser and results factories should be adequate for most
users, so use the parse_results() when possible. However, both the XML
parser and the results parser can easily be overriden.
EXAMPLE:
#!/usr/bin/python
import sys
from yahoo.search.webservices import create_search
service = argv[1]
query = " ".join(sys.argv[2:])
app_id = "something"
x = create_search(service, app_id, query=query, results=5)
if x is None:
x = create_search("Web", app_id, query=query, results=5)
dom = srch.get_results()
results = srch.parse_results(dom)
for res in results:
url = res.Url
summary = res['Summary']
print "%s -> %s" (summary, url)
"""
from yahoo.search import domparsers
from yahoo.search import debug
import urllib
import urllib2
import types
import string
import re
__version__ = "$Revision: 1.1 $"
__author__ = "Leif Hedstrom <leif@ogre.com>"
__date__ = "Thu Apr 28 21:38:39 PDT 2005"
#
# List of all supported languages
#
LANGUAGES = {'default':'english', 'ar':'arabic', 'bg':'bulgarian',
'ca':'catalan', 'szh':'chinese-simplified',
'tzh':'chinese-traditional', 'hr':'croatian', 'cs':'czech',
'da':'danish', 'nl':'dutch', 'en':'english', 'et':'estonian',
'fi':'finnish', 'fr':'french', 'de':'german', 'el':'greek',
'he':'hebrew', 'hu':'hungarian', 'is':'icelandic',
'id':'indonesian', 'it':'italian', 'ja':'japanese', 'ko':'korean',
'lv':'latvian', 'lt':'lithuanian', 'no':'norwegian', 'fa':'persian',
'pl':'polish', 'pt':'portuguese', 'ro':'romanian', 'ru':'russian',
'sk':'slovak', 'sr':'serbian', 'sl':'slovenian', 'es':'spanish',
'sv':'swedish', 'th':'thai', 'tr':'turkish'}
COUNTRIES = {'default':'any', 'any':'any', 'ar':'Argentina', 'au':'Australia',
'at':'Austria', 'be':'Belgium', 'br':'Brazil', 'ca':'Canada',
'cn':'China', 'cz':'Czechoslovakia', 'dk':'Denmark', 'fi':'Finland',
'fr':'France', 'de':'Germany', 'it':'Italy', 'jp':'Japan',
'kr':'Korea', 'nl':'Netherlands', 'no':'Norway', 'pl':'Poland',
'rf':'Russian Federation', 'es':'Spain','se':'Swdeden',
'ch':'Switzerland', 'tw':'Taiwan', 'uk':'United Kingdom',
'us':'United States'}
CC_LICENSES = {'cc_any' : 'Any',
'cc_commercial' : 'Commercial',
'cc_modifiable' : 'Modifiable'}
APPID_REGEX = re.compile("^[a-zA-Z0-9 _()\[\]*+\-=,.:\\\@]{8,40}$")
#
# Exceptions and error handling
#
class Error(Exception):
"""Base class for all Yahoo Web Services exceptions."""
class ParameterError(Error):
"""A parameter is missing, or has bad value"""
pass
class ServerError(Error):
"""The Yahoo server is unavailable."""
pass
class ClassError(Error):
"""This can only occur if the APIs aren't installed or configured
properly. If it happens, please contact the author."""
class SearchError(Error):
"""An exception/error occured in the search."""
def __init__(self, err):
# ToDo XXX: Do we need to call Error.__init() here ?
self.msg = "unknown error"
for line in err.readlines():
start = line.find("<Message>")
if start > -1:
stop = line.find("</Message>")
if stop > -1:
self.msg = line[start+9:stop]
def __str__(self):
return self.msg
#
# First a couple of base classes for the Search services. Most of them
# are almost identical, so good candidates to sub-class one of these.
#
class _Search(debug.Debuggable):
"""Yahoo Search WebService - base class
This class implements the core functionality of all Yahoo Search
Services.
"""
NAME = "Search"
SERVICE = "Search"
PROTOCOL = "http"
SERVER = "api.search.yahoo.com"
VERSION = "V1"
METHOD = "GET"
_NEXT_QID = 1
_RESULT_FACTORY = None
def __init__(self, app_id, opener=None, xml_parser=None,
result_factory=None, debug=0, **args):
"""The app_id is a required argument, the Yahoo search services
will not accept requests without a proper app_id. A valid app_id
is a combination of 8 - 40 characters, matching the regexp
"^[a-zA-Z0-9 _()\[\]*+\-=,.:\\\@]{8,40}$"). Please visit
http://developer.yahoo.net/ to request an App ID for your own
software or application.
Four optional arguments can also be passed to the constructor:
opener - Opener for urllib2
xml_parser - Function to parse XML (default: minidom)
result_factory - Result factory class (default: none)
debug - Debug level (if any)
All other "named" arguments are passed into as a dictionary to the
set_params() method.
The result factory is specific to the particular web service used,
e.g. the different Yahoo Search services will each implement their
own factory class.
Both of these settings can be controlled via their respective
install method (see below).
"""
super(_Search, self).__init__(debug)
self._service = {'name' : self.NAME,
'protocol' : self.PROTOCOL,
'server' : self.SERVER,
'version' : self.VERSION,
'service' : self.SERVICE}
self._app_id = app_id
self._valid_params = {}
self._urllib_opener = opener
self._xml_parser = xml_parser
if result_factory:
self._result_factory = result_factory
else:
self._result_factory = self._RESULT_FACTORY
if self._xml_parser is None:
import xml.dom.minidom
self._xml_parser = xml.dom.minidom.parse
self._qid = self._NEXT_QID
self._NEXT_QID += 1
self._init_valid_params()
self.reset()
if args:
self.set_params(args)
# Implement the attribute handlers, to avoid confusion
def __setattr__(self, name, value):
if (hasattr(getattr(self.__class__, name, None), '__set__') or
name[0] == '_'):
super(_Search, self).__setattr__(name, value)
else:
self.set_param(name, value)
def __getattr__(self, name):
if (hasattr(getattr(self.__class__, name, None), '__get__') or
name[0] == '_'):
return super(_Search, self).__getattr__(name)
else:
return self.get_param(name)
def _init_valid_params(self):
err = "Yahoo Search Service class %s must implement a _init_valid_params()" % (
self.svc_name)
raise ClassError, err
def reset(self):
self._params = {}
def _get_svc_name(self):
return self._service['name']
def _set_svc_name(self, value):
self._service['name'] = value
svc_name = property(_get_svc_name, _set_svc_name, None,
"Descriptive name of the service")
def _get_svc_protocol(self):
return self._service['protocol']
def _set_svc_protocol(self, value):
self._service['protocol'] = value
svc_protocol = property(_get_svc_protocol, _set_svc_protocol, None,
"Service protocol (e.g. HTTP)")
def _get_svc_service(self):
return self._service['service']
def _set_svc_service(self, value):
self._service['service'] = value
svc_service = property(_get_svc_service, _set_svc_service, None, "Service path")
def _get_svc_server(self):
return self._service['server']
def _set_svc_server(self, value):
self._service['server'] = value
svc_server = property(_get_svc_server, _set_svc_server, None,
"Service server name or IP")
def _get_svc_version(self):
return self._service['version']
def _set_svc_version(self, value):
self._service['version'] = value
svc_version = property(_get_svc_version, _set_svc_version, None,
"Service version string")
def _get_app_id(self):
return self._app_id
def _set_app_id(self, app_id):
if (isinstance(app_id, types.StringTypes) and
(APPID_REGEX.match(app_id) is not None)):
self._app_id = app_id
else:
raise ValueError, "`app_id' can only contain a-zA-Z0-9 _()\[\]*+\-=,.:\\\@"
app_id = property(_get_app_id, _set_app_id, None,
"Application ID (issued by Yahoo)")
appid = property(_get_app_id, _set_app_id, None,
"Application ID (issued by Yahoo)")
# Manage service parameters
def set_params(self, args):
"""Set one or several query parameters from a dictionary"""
for (param, value) in args.items():
self.set_param(param, value)
def get_param(self, param):
"""Get the value of a query parameter, or the default value if unset"""
if not self._valid_params.has_key(param):
err = "`%s' is not a valid parameter for `%s'" % (param,
self._service['name'])
raise ParameterError, err
if self._params.has_key(param):
return self._params[param]
else:
return self._valid_params[param][1]
def set_param(self, param, value):
"""Set the value of a query parameter"""
if not self._valid_params.has_key(param):
err = "`%s' is not a valid parameter for `%s'" % (param,
self._service['name'])
raise ParameterError, err
pinfo = self._valid_params[param]
if value is None:
err = "`%s' can not have an undefined value" % (param)
raise ValueError, err
# Do explicit type conversions (if possible)
if pinfo[2] is not None:
try:
if isinstance(value, (types.ListType, types.TupleType)):
value = map(lambda x: pinfo[2](x), value)
# ToDo XXX: Should we make sure each value is unique?
else:
value = pinfo[2](value)
except:
pass
# Check the type validity of the value
err = False
if isinstance(value, (types.ListType, types.TupleType)):
for val in value:
if not isinstance(val, pinfo[0]):
err = True
break
elif not isinstance(value, pinfo[0]):
err = True
if err:
raise TypeError, "`%s' only takes values of type %s" % (param, str(pinfo[0]))
# Check validity of the value (if possible)
err = False
if callable(pinfo[3]):
if isinstance(value, (types.ListType, types.TupleType)):
for val in value:
if not pinfo[3](val):
err = True
break
else:
if not pinfo[3](value):
err = True
elif isinstance(pinfo[3], (types.TupleType, types.ListType)):
if isinstance(value, (types.ListType, types.TupleType)):
for val in value:
if not val in pinfo[3]:
err = True
break
elif not value in pinfo[3]:
err = True
if err:
raise ValueError, "`%s' only handles values in: %s" % (param, str(pinfo[3]))
# Update the parameter only if it's different from the default
if value != pinfo[1]:
self._params[param] = value
elif self._params.has_key(param):
self._params.pop(param)
def get_valid_params(self):
"""Return a list of all valid parameters for this search"""
return self._valid_params.keys()
# Manage (install) the Opener, XML parser and result factory (parser)
def install_opener(self, opener):
"""Install a URL opener (for use with urllib2), overriding the
default opener. This is rarely required.
"""
self._urllib_opener = opener
def install_xml_parser(self, xml_parser):
"""Install an XML parser that will be used for all results for this
object. The parser is expected to "read" the data from the supplied
stream argument. To uninstall the parser (e.g. to make sure we
return raw XML data) simply call this method with an argument of
None.
"""
self._xml_parser = xml_parser
def install_result_factory(self, result_factory):
"""Install a python class (not an instance!) that should be used as a
factory for creating result(s) objects.
"""
self._result_factory = result_factory
# Methods working on connection handling etc.
def encode_params(self):
params = self._params.copy()
params.update({'appid' : self._app_id})
return urllib.urlencode(params, 1)
def get_url(self, with_params=True):
"""Return the URL for this request object"""
url = "%s://%s/%s/%s/%s" % (self._service['protocol'],
self._service['server'],
self._service['service'],
self._service['version'],
self._service['name'])
if with_params:
return "%s?%s" % (url, self.encode_params())
else:
return url
def open(self, opener=None):
"""Open a connection to the webservice server, and request the URL.
The return value is a "stream", which can be read calling the
read(), readline() or readlines() methods.
"""
if opener is not None:
urllib2.install_opener(opener)
elif self._urllib_opener is not None:
urllib2.install_opener(opener)
if self.METHOD == "POST":
url = self.get_url(with_params=False)
data = self.encode_params()
else:
url = self.get_url(with_params=True)
data = None
self._debug_msg("Opening URL = %s", debug.DEBUG_LEVELS['HTTP'], url)
if data:
self._debug_msg("POSTing data = %s", debug.DEBUG_LEVELS['HTTP'], data)
# XXX ToDo: This needs to be properly implemented?
try:
resp = urllib2.urlopen(url, data)
except urllib2.HTTPError, err:
if err.code == 503:
raise ServerError("Internal WebService error, temporarily unavailable")
else:
raise SearchError(err)
raise ServerError("WebService server unavailable")
return resp
def get_results(self, stream=None, xml_parser=None, close=True):
"""Read the stream (if provided) and either return the raw XML, or
send the data to the provided XML parser for further processing.
If no stream is provided, it will call the open() method using the
default opener. The stream will be closed upon return from this
method, unless the close=False is passed as an argument.
"""
self._debug_msg("VALID_PARAMS = %s", debug.DEBUG_LEVELS['PARAMS'],
self._valid_params.keys())
if stream is None:
stream = self.open()
if xml_parser is None:
xml_parser = self._xml_parser
res = xml_parser(stream)
self._debug_msg("XML results are:\n%s", debug.DEBUG_LEVELS['RAWXML'],
res.toprettyxml())
if close:
stream.close()
return res
def parse_results(self, xml=None):
"""Get the result from the request, and instantiate the appropriate
result class. This class will be populated with all the data from
the XML object.
"""
if self._result_factory is None:
return None
if xml is None:
xml = self.get_results()
res = self._result_factory(service=self)
res.parse_results(xml)
return res
def _get_debug_level(self):
return self._debug_level
def _set_debug_level(self, level):
self._debug_level = level
debug_level = property(_get_debug_level, _set_debug_level, None,
"Set and modify the debug level")
#
# Basic parameters, supported by all regular search classes
#
class _BasicParams(object):
"""Yahoo Search WebService - common basic params
Setup the basic CGI parameters that all (normal) search services
supports. This is used by most services (classes) to provision for
the basic parameters they all use.
"""
def _init_valid_params(self):
self._valid_params.update({
"query" : (types.StringTypes, None, None, None),
"results" : (types.IntType, 10, int, range(1, 51)),
"start" : (types.IntType, 1, int, lambda x: x > -1 and x < 1001),
})
#
# Common search parameters, shared by several classes, but not all.
#
class _CommonParams(_BasicParams):
"""Several search services share a few non-basic parameters, so
this sub-class of _BasicParams saves some typing.
"""
def _init_valid_params(self):
super(_CommonParams, self)._init_valid_params()
self._valid_params.update({
"type" : (types.StringTypes, "any", string.lower,
("all", "any", "phrase")),
"format" : (types.StringTypes, "any", string.lower,
("all", "any")),
"adult_ok" : (types.IntType, None, int, (1,)),
})
#
# My Web parameters, shared
#
class _MyWebParams(object):
"""My Web Params - common parameters
Setup the basic CGI parameters that all My Web services supports.
"""
def _init_valid_params(self):
self._valid_params = {
"yahooid" : (types.StringTypes, None, None, None),
"results" : (types.IntType, 10, int, range(1, 51)),
"start" : (types.IntType, 1, int, lambda x: x > -1 and x < 1001),
}
#
# These are the interesting classes, one for each of the major
# search services
#
class VideoSearch(_CommonParams, _Search):
"""VideoSearch - perform a Yahoo Video Search
This class implements the Video Search web service APIs. Allowed
parameters are:
query - The query to search for
type - The kind of search to submit (all, any or phrase)
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
format - Specifies the kind of video file to search for
adult_ok - The service filters out adult content by default.
Enter a 1 to allow adult content
Full documentation for this service is available at:
http://developer.yahoo.net/video/V1/videoSearch.html
"""
NAME = "videoSearch"
SERVICE = "VideoSearchService"
_RESULT_FACTORY = domparsers.VideoSearch
def _init_valid_params(self):
super(VideoSearch, self)._init_valid_params()
self._valid_params.update({
"format" : (types.StringTypes, "any", string.lower,
("all", "all", "avi", "flash", "mpeg", "msmedia",
"quicktime", "realmedia")),
})
class ImageSearch(_CommonParams, _Search):
"""ImageSearch - perform a Yahoo Image Search
This class implements the Image Search web service APIs. Allowed
parameters are:
query - The query to search for
type - The kind of search to submit (all, any or phrase)
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
format - Specifies the kind of image file to search for
adult_ok - The service filters out adult content by default.
Enter a 1 to allow adult content
coloration - The coloration type of the images (default, bw or
color)
Full documentation for this service is available at:
http://developer.yahoo.net/image/V1/imageSearch.html
"""
NAME = "imageSearch"
SERVICE = "ImageSearchService"
_RESULT_FACTORY = domparsers.ImageSearch
def _init_valid_params(self):
super(ImageSearch, self)._init_valid_params()
self._valid_params.update({
"format" : (types.StringTypes, "any", string.lower,
("all", "any", "bmp", "gif", "jpeg", "png")),
"coloration" : (types.StringTypes, "default", string.lower,
("default", "bw", "color", "colour"))
})
class WebSearch(_CommonParams, _Search):
"""WebSearch - perform a Yahoo Web Search
This class implements the Web Search web service APIs. Allowed
parameters are:
query - The query to search for
type - The kind of search to submit (all, any or phrase)
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
format - Specifies the kind of web file to search for
adult_ok - The service filters out adult content by default.
Enter a 1 to allow adult content
similar_ok - Specifies whether to allow multiple results with
similar content. Enter a 1 to allow similar content
language - The language the results are written in
country - he country code for the country the website is
located in.
license - The Creative Commons license that the contents are
licensed under. You may submit multiple values (e.g.
license=cc_commercial&license=cc_modifiable).
Full documentation for this service is available at:
http://developer.yahoo.net/web/V1/webSearch.html
"""
NAME = "webSearch"
SERVICE = "WebSearchService"
_RESULT_FACTORY = domparsers.WebSearch
def _init_valid_params(self):
super(WebSearch, self)._init_valid_params()
self._valid_params.update({
"similar_ok" : (types.IntType, None, int, (1,)),
"format" : (types.StringTypes, "any", string.lower,
("all", "any", "html", "pdf", "ppt", "msword",
"rss", "txt")),
"language" : (types.StringTypes, "en", string.lower,
LANGUAGES.keys()),
"country" : (types.StringTypes, "default", string.lower,
COUNTRIES.keys()),
"license" : (types.StringTypes, [], string.lower,
CC_LICENSES.keys())
})
class ContextSearch(WebSearch):
"""ContextSearch - perform a Yahoo Web Search with a context
This class implements the Contextual Web Search service APIs, which is
very similar to a regular web search. Allowed parameters are:
query - The query to search for
context - The context to extract meaning from (UTF-8 encoded)
type - The kind of search to submit (all, any or phrase)
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
format - Specifies the kind of web file to search for
adult_ok - The service filters out adult content by default.
Enter a 1 to allow adult content
similar_ok - Specifies whether to allow multiple results with
similar content. Enter a 1 to allow similar content
language - The language the results are written in
country - he country code for the country the website is
located in.
license - The Creative Commons license that the contents are
licensed under. You may submit multiple values (e.g.
license=cc_commercial&license=cc_modifiable).
Full documentation for this service is available at:
http://developer.yahoo.net/web/V1/contextSearch.html
"""
NAME = "contextSearch"
METHOD = "POST"
def _init_valid_params(self):
super(ContextSearch, self)._init_valid_params()
self._valid_params.update({
"context" : (types.StringTypes, None, None, None),
})
class RelatedSuggestion(_Search):
"""RelatedSuggestion - perform a Yahoo Web Related Suggestions search
This class implements the Web Search Related Suggestion web service
APIs. The only allowed parameters are:
query - The query to get related searches from
results - The number of results to return
Full documentation for this service is available at:
http://developer.yahoo.net/web/V1/relatedSuggestion.html
"""
NAME = "relatedSuggestion"
SERVICE = "WebSearchService"
_RESULT_FACTORY = domparsers.RelatedSuggestion
def _init_valid_params(self):
self._valid_params.update({
"query" : (types.StringTypes, None, None, None),
"results" : (types.IntType, 10, int, range(1, 51)),
})
class SpellingSuggestion(_Search):
"""SpellingSuggestion - perform a Yahoo Web Spelling Suggestion search
This class implements the Web Search Spelling Suggestion web service
APIs. The only allowed parameter is:
query - The query to get spelling suggestions for
Full documentation for this service is available at:
http://developer.yahoo.net/web/V1/spellingSuggestion.html
"""
NAME = "spellingSuggestion"
SERVICE = "WebSearchService"
_RESULT_FACTORY = domparsers.SpellingSuggestion
def _init_valid_params(self):
self._valid_params.update({
"query" : (types.StringTypes, None, None, None),
})
class TermExtraction(_Search):
"""TermExtraction - Extract words or phrases from a larger content
This class implements the Web Search Spelling Suggestion web service
APIs. The only allowed parameter is:
query - An optional query to help with the extraction
process
context - The context to extract terms from (UTF-8 encoded)
The Term Extraction service provides a list of significant words or
phrases extracted from a larger content. It is one of the technologies
used in Y!Q. Full documentation for this service is available at:
http://developer.yahoo.net/content/V1/termExtraction.html
"""
NAME = "termExtraction"
SERVICE = "ContentAnalysisService"
METHOD = "POST"
_RESULT_FACTORY = domparsers.TermExtraction
def _init_valid_params(self):
self._valid_params.update({
"query" : (types.StringTypes, "", None, None),
"context" : (types.StringTypes, None, None, None),
})
class NewsSearch(_BasicParams, _Search):
"""NewsSearch - perform a Yahoo News Search
This class implements the News Search web service APIs. Allowed
parameters are:
query - The query to search for
type - The kind of search to submit (all, any or phrase)
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
sort - Sort articles by relevance ('rank') or most-recent
('date'). Default is by relevance
language - The language the results are written in
Full documentation for this service is available at:
http://developer.yahoo.net/news/V1/newsSearch.html
"""
NAME = "newsSearch"
SERVICE = "NewsSearchService"
_RESULT_FACTORY = domparsers.NewsSearch
def _init_valid_params(self):
super(NewsSearch, self)._init_valid_params()
self._valid_params.update({
"type" : (types.StringTypes, "any", string.lower,
("all", "any", "phrase")),
"sort" : (types.StringTypes, "rank", string.lower, ("date", "rank")),
"language" : (types.StringTypes, "en", string.lower,
LANGUAGES.keys()),
})
class LocalSearch(_BasicParams, _Search):
"""LocalSearch - perform a Yahoo Local Search
This class implements the Local Search web service APIs. Allowed
parameters are:
query - The query to search for
results - The number of results to return (1-20)
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
radius - How far from the specified location to search for
the query terms
sort - Sorts the results by the chosen criteria
street - Street name. The number is optional
city - City name
state - The United States state. You can spell out the
full state name or you can use the two-letter
abbreviation
zip - The five-digit zip code, or the five-digit code
plus four-digit extension
location - Free form field for location (see below)
latitude - Latitude of the starting location (-90.0 - 90.0)
longitude - Longitude of the starting location (-180.0 - 180.0)
If both latitude and longitude are specified, they will take priority
over all other location data. If only one of latitude or longitude is
specified, both will be ignored.
Full documentation for this service is available at:
http://developer.yahoo.net/local/V1/localSearch.html
"""
NAME = "localSearch"
SERVICE = "LocalSearchService"
SERVER = "api.local.yahoo.com"
_RESULT_FACTORY = domparsers.LocalSearch
def _init_valid_params(self):
super(LocalSearch, self)._init_valid_params()
self._valid_params.update({
"results" : (types.IntType, 10, int, range(1, 21)),
"sort" : (types.StringTypes, "relevance", string.lower,
("relevance", "title", "distance", "rating")),
"radius" : (types.FloatType, None, float, None),
"street" : (types.StringTypes, None, None, None),
"city" : (types.StringTypes, None, None, None),
"state" : (types.StringTypes, None, None, None),
"zip" : (types.StringTypes, None, None, None),
"location" : (types.StringTypes, None, None, None),
"latitude" : (types.FloatType, None, float,
lambda x: x > (-90) and x < 90,
"-90 < val < 90"),
"longitude" : (types.FloatType, None, float,
lambda x: x > (-180) and x < 180,
"-180 < val < 180"),
})
class ListFolders(_MyWebParams, _Search):
"""List Folders - Retrieving public folders
This class implements the My Web service to retrieve public folders.
Allowed parameters are:
yahooid - The Yahoo! user who owns the folder being accessed
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
Full documentation for this service is available at:
http://developer.yahoo.net/myweb/V1/listFolders.html
"""
NAME = "listFolders"
SERVICE = "MyWebService"
_RESULT_FACTORY = domparsers.ListFolders
class ListUrls(_MyWebParams, _Search):
"""List Urls - Retrieving public URL stores
This class implements the My Web service to retrieve URLs from a
public folder. Allowed parameters are:
folder - The folder to retreive queries from. The folder
must be set to "Public" in order to be accessed.
yahooid - The Yahoo! user who owns the folder being accessed
results - The number of results to return
start - The starting result position to return (1-based).
The finishing position (start + results - 1) cannot
exceed 1000.
Full documentation for this service is available at:
http://developer.yahoo.net/myweb/V1/listUrls.html
"""
NAME = "listUrls"
SERVICE = "MyWebService"
_RESULT_FACTORY = domparsers.ListUrls
def _init_valid_params(self):
super(ListUrls, self)._init_valid_params()
self._valid_params.update({
"folder" : (types.StringTypes, None, None, None),
})
#
# This is a "convenience" dictionary, providing a (very) short
# description of all available Search classes. The factory function
# uses this dictionary to make a "simple" interface to instantiate
# and configure a search object in one call.
#
SERVICES = {'video' : (VideoSearch, "Video Search"),
'image' : (ImageSearch, "Image Search"),
'web' : (WebSearch, "Web Search"),
'context' : (ContextSearch, "Contextual Web Search"),
'news' : (NewsSearch, "News Search"),
'local' : (LocalSearch, "Local Search"),
'related' : (RelatedSuggestion, "Web Search Related Suggestion"),
'spelling' : (SpellingSuggestion, "Web Search Spelling Suggestion"),
'term' : (TermExtraction, "Term extraction service"),
'listfolders' : (ListFolders, "Retrieving public MyWeb folders"),
'listurls' : (ListUrls, "Retrieving public MyWeb URL stores"),
}
def create_search(name, app_id, xml_parser=None, result_factory=None, debug=0, **args):
"""Create a Yahoo Web Services object, and configure it
This is a simple "factory" function to instantiate and configure
a Yahoo Web Services object. For example:
app_id = "something"
srch = create_search("Web", app_id, query="Leif Hedstrom", results=4)
dom = srch.get_results()
The first argument is one of the following "classes" of searches:
Web - Web search
Context - Contextual Web search
Video - Video search
Image - Image search
News - News search
Local - Local search
Related - Web search Related Suggestions
Spelling - Web search Spelling Suggestions
Term - Term extraction service
ListFolders - Retrieving public MyWeb folders
ListUrls - Retrieving public MyWeb URL stores
The second argument, app_id (or appid), is an application specific
identifier, provided by Yahoo. The web services will not accept
requests without a proper AppID.
All other arguments must be valid named arguments, and the allowed
set of parameters depends on the specific class of search being
instantiated. See <XXX TODO: URL here?> for a comprehensive list and
documentation of allowed parameters for all types of searches.
"""
name = name.lower()
if not SERVICES.has_key(name):
return None
obj = SERVICES[name][0](app_id, xml_parser=xml_parser,
result_factory=result_factory, debug=debug)
if obj and args:
obj.set_params(args)
return obj
#
# The rest of this module is a PyUnit regression test suite. It's still
# work in progress, but it'll get there, eventually...
#
import unittest
#
# These are "shared" tests, across all the services
#
class __ServiceTestCase(object):
SERVICE = None
NUM_PARAMS = 999
def setUp(self):
try:
self.srch = self.SERVICE('YahooDemo')
except:
self.srch = None
# First some very basic tests
def testInstantiation(self):
"""Instantiate a search object"""
self.assertNotEqual(self.srch, None)
def testValidParams(self):
"""Verify that the allowed parameters are correct"""
params = self.srch.get_valid_params()
self.assertEqual(len(params), self.NUM_PARAMS)
def testQueryParam(self):
"""Verify that the query parameter is accepted"""
self.srch.query = "Yahoo"
self.assertEqual(self.srch.query, "Yahoo")
def testUnknownParam(self):
"""Make sure an exception is raised on bad parameters"""
self.assertRaises(ParameterError, self.srch.set_param, "FooBar", "Fum")
# Now test a simple query, this will be overriden where appropriate
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.query = "Yahoo"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertFalse(res.total_results_available == 0)
self.assertTrue(res.first_result_position > 0)
def testProperties(self):
self.assertEqual(self.srch.appid, 'YahooDemo')
self.assertEqual(self.srch.app_id, 'YahooDemo')
#
# Test for video search
#
class __VideoSearchTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = VideoSearch
NUM_PARAMS = 6
#
# Test for image search
#
class __ImageSearchTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = ImageSearch
NUM_PARAMS = 7
#
# Test for web search
#
class __WebSearchTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = WebSearch
NUM_PARAMS = 10
def testBadParamValues(self):
self.assertRaises(ValueError, self.srch.set_param, "results", "100")
self.assertRaises(ValueError, self.srch.set_param, "start", -1)
self.assertRaises(ValueError, self.srch.set_param, "similar_ok", 3)
self.assertRaises(ValueError, self.srch.set_param, "format", "foo")
self.assertRaises(ValueError, self.srch.set_param, "language", "Here")
self.assertRaises(ValueError, self.srch.set_param, "country", "there")
self.assertRaises(ValueError, self.srch.set_param, "license", "cc_none")
#
# Test for context search
#
class __ContextSearchTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = ContextSearch
NUM_PARAMS = 11
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.query = "Yahoo"
self.srch.context = "Web Search APIs developers"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertFalse(res.total_results_available == 0)
self.assertTrue(res.first_result_position > 0)
#
# Test for related suggestion
#
class __RelatedSuggestionTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = RelatedSuggestion
NUM_PARAMS = 2
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.query = "yahoo"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertTrue(res.total_results_available == 10)
self.assertTrue(res.first_result_position == 1)
#
# Test for spelling suggestion
#
class __SpellingSuggestionTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = SpellingSuggestion
NUM_PARAMS = 1
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.query = "yahok"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertTrue(res.total_results_available == 1)
self.assertTrue(res.first_result_position == 1)
#
# Test for news search
#
class __NewsSearchTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = NewsSearch
NUM_PARAMS = 6
#
# Test for local search
#
class __LocalSearchTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = LocalSearch
NUM_PARAMS = 12
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.query = "yahoo"
self.srch.zip = "94019"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertFalse(res.total_results_available == 0)
self.assertTrue(res.first_result_position > 0)
#
# Test for Term extractions
#
class __TermExtractionTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = TermExtraction
NUM_PARAMS = 2
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.query = "Yahoo"
self.srch.context = "Web Search APIs developers"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertFalse(res.total_results_available == 0)
self.assertTrue(res.first_result_position > 0)
#
# Test for MyWeb List Folders
#
class __ListFoldersTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = ListFolders
NUM_PARAMS = 3
# This is weird, but wth ...
def testQueryParam(self):
"""Verify that the yahooid parameter is accepted"""
self.srch.yahooid = "Yahoo"
self.assertEqual(self.srch.yahooid, "Yahoo")
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.yahooid = "janesmith306"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertFalse(res.total_results_available == 0)
self.assertTrue(res.first_result_position > 0)
#
# Tests for MyWeb List URLs
#
class __ListUrlsTestCase(__ServiceTestCase, unittest.TestCase):
SERVICE = ListUrls
NUM_PARAMS = 4
def testQueryParam(self):
"""Verify that the yahooid parameter is accepted"""
self.srch.yahooid = "Yahoo"
self.assertEqual(self.srch.yahooid, "Yahoo")
def testSimpleQuery(self):
"""Test one simple query, make sure the XML is returned"""
import xml.dom.minidom
self.srch.yahooid = "janesmith306"
self.srch.folder = "Shared"
dom = self.srch.get_results()
self.assertTrue(isinstance(dom, xml.dom.minidom.Document))
res = self.srch.parse_results(dom)
self.assertFalse(res.total_results_available == 0)
self.assertTrue(res.first_result_position > 0)
#
# Finally, run all the tests
#
if __name__ == '__main__':
unittest.main()
#
# local variables:
# mode: python
# indent-tabs-mode: nil
# py-indent-offset: 4
# end:
|
gpl-2.0
|
[
624,
28786,
19112,
8730,
6001,
21813,
199,
199,
2765,
859,
9031,
282,
663,
402,
3992,
436,
3423,
370,
1736,
543,
314,
199,
28786,
19112,
8730,
6001,
21813,
14,
2900,
2058,
687,
3520,
8500,
787,
7684,
199,
15317,
4692,
12,
436,
642,
2559,
30242,
1051,
2335,
367,
5576,
6057,
402,
3520,
199,
1099,
5951,
14,
6601,
402,
314,
4534,
2387,
26,
339,
627,
1316,
7169,
460,
461,
3261,
12,
543,
3350,
461,
4865,
4692,
21295,
12,
436,
489,
473,
15,
47,
3217,
14,
272,
627,
2434,
436,
574,
7907,
641,
2754,
2633,
12,
5893,
489,
4834,
730,
8603,
334,
6526,
5827,
436,
3962,
9,
272,
627,
481,
8196,
372,
1475,
12,
5893,
14316,
2251,
12,
503,
9999,
489,
4565,
754,
2251,
421,
199,
5556,
883,
1902,
17321,
282,
2754,
909,
5370,
12,
503,
675,
314,
6434,
199,
1593,
1218,
63,
1733,
342,
315,
642,
859,
334,
3239,
5084,
680,
710,
3748,
3992,
199,
1618,
21858,
787,
26,
2286,
15709,
5278,
198,
13,
15709,
8730,
272,
6047,
5278,
198,
13,
6047,
8730,
272,
6001,
5278,
198,
13,
6001,
8730,
272,
30951,
5278,
198,
13,
30951,
8730,
272,
10111,
5278,
198,
13,
10111,
8730,
339,
20116,
51,
11914,
1636,
198,
13,
6001,
8730,
20116,
428,
11914,
1636,
272,
428,
321,
10564,
51,
11914,
1636,
198,
13,
6001,
8730,
428,
321,
10564,
428,
11914,
1636,
339,
13861,
77,
4942,
6156,
446,
13861,
77,
7255,
6156,
2435,
272,
9470,
5278,
221,
446,
6001,
8730,
543,
282,
1067,
421,
199,
1918,
3365,
1007,
13,
2888,
402,
8730,
5171,
3365,
5951,
402,
1827,
199,
3214,
14,
9322,
1006,
4409,
376,
4223,
2870,
2725,
334,
571,
63,
344,
680,
710,
199,
21589,
6716,
23369,
1006,
1163,
4370,
2633,
367,
1924,
402,
314,
199,
4946,
8500,
26,
2234,
6001,
257,
20116,
221,
428,
321,
10564,
221,
9470,
257,
13861,
77,
2049,
9063,
221,
5514,
221,
3001,
221,
5514,
221,
21397,
272,
1827,
755,
359,
56,
61,
258,
359,
56,
61,
755,
359,
56,
61,
420,
359,
56,
61,
420,
359,
56,
61,
272,
730,
263,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
2058,
258,
359,
56,
61,
258,
359,
56,
61,
263,
1275,
755,
359,
56,
61,
272,
1343,
755,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
339,
1475,
420,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
1503,
427,
63,
745,
259,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
8545,
63,
745,
221,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
2637,
259,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
9023,
258,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
1067,
420,
1275,
755,
1275,
260,
1275,
755,
359,
56,
61,
420,
359,
56,
61,
421,
2234,
6047,
221,
15709,
221,
30951,
257,
10111,
355,
9063,
221,
9063,
221,
9063,
221,
9063,
272,
1827,
263,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
272,
730,
260,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
258,
1275,
5591,
2058,
420,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
272,
1343,
263,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
339,
1475,
755,
359,
56,
61,
259,
359,
56,
61,
258,
1275,
420,
1275,
272,
1503,
427,
63,
745,
258,
359,
56,
61,
259,
359,
56,
61,
258,
1275,
420,
1275,
272,
2637,
420,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
9023,
755,
1275,
420,
1275,
420,
1275,
420,
1275,
272,
4069,
3515,
1275,
420,
1275,
258,
359,
56,
61,
259,
359,
56,
61,
272,
3164,
425,
257,
359,
56,
61,
258,
1275,
420,
1275,
420,
1275,
339,
9362,
263,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
410,
7936,
263,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
14492,
3515,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
1174,
260,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
3482,
3698,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
2909,
420,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
18154,
258,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
18896,
420,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
421,
1362,
355,
3820,
29121,
83,
221,
3820,
10867,
355,
3001,
375,
221,
3001,
13,
272,
4922,
3698,
1275,
3698,
359,
56,
61,
272,
612,
65,
526,
1170,
260,
359,
56,
61,
3515,
359,
56,
61,
272,
2058,
260,
359,
56,
61,
3515,
359,
56,
61,
272,
1343,
3698,
359,
56,
61,
3515,
359,
56,
61,
4388,
199,
22321,
402,
3520,
2725,
365,
6366,
465,
376,
2225,
402,
1924,
199,
470,
32759,
1021,
14,
2104,
2893,
12,
1265,
883,
663,
2633,
2839,
26,
339,
687,
612,
65,
19112,
14,
1733,
14,
2520,
5950,
492,
6001,
5278,
339,
1145,
63,
344,
275,
298,
10297,
2,
272,
11483,
335,
275,
6001,
5278,
8,
571,
63,
344,
9,
272,
11483,
335,
14,
1131,
275,
298,
2553,
692,
869,
379,
31672,
2,
272,
11483,
335,
14,
2604,
275,
6335,
199,
199,
269,
12,
340,
1265,
787,
1808,
314,
6434,
805,
26,
2286,
687,
612,
65,
19112,
14,
1733,
14,
2520,
5950,
492,
1218,
63,
1733,
339,
1145,
63,
344,
275,
298,
10297,
2,
272,
11483,
335,
275,
1218,
63,
1733,
480,
5926,
401,
1145,
63,
344,
12,
1827,
628,
2553,
692,
869,
379,
31672,
401,
2058,
29,
2167,
9,
199,
199,
269,
12,
314,
2061,
13943,
12,
282,
14665,
402,
314,
4136,
2877,
26,
339,
687,
612,
65,
19112,
14,
1733,
14,
2520,
5950,
492,
6001,
5278,
339,
1145,
63,
344,
275,
298,
10297,
2,
272,
11483,
335,
275,
6001,
5278,
8,
571,
63,
344,
12,
1827,
628,
2553,
692,
869,
379,
31672,
401,
2058,
29,
2167,
9,
199,
199,
1378,
8044,
282,
9842,
2725,
574,
12,
9329,
2879,
652,
465,
1263,
3293,
199,
3215,
26,
339,
870,
298,
5278,
379,
367,
3872,
11483,
335,
14,
1131,
421,
199,
1858,
1655,
2556,
641,
3520,
2633,
12
] |
[
28786,
19112,
8730,
6001,
21813,
199,
199,
2765,
859,
9031,
282,
663,
402,
3992,
436,
3423,
370,
1736,
543,
314,
199,
28786,
19112,
8730,
6001,
21813,
14,
2900,
2058,
687,
3520,
8500,
787,
7684,
199,
15317,
4692,
12,
436,
642,
2559,
30242,
1051,
2335,
367,
5576,
6057,
402,
3520,
199,
1099,
5951,
14,
6601,
402,
314,
4534,
2387,
26,
339,
627,
1316,
7169,
460,
461,
3261,
12,
543,
3350,
461,
4865,
4692,
21295,
12,
436,
489,
473,
15,
47,
3217,
14,
272,
627,
2434,
436,
574,
7907,
641,
2754,
2633,
12,
5893,
489,
4834,
730,
8603,
334,
6526,
5827,
436,
3962,
9,
272,
627,
481,
8196,
372,
1475,
12,
5893,
14316,
2251,
12,
503,
9999,
489,
4565,
754,
2251,
421,
199,
5556,
883,
1902,
17321,
282,
2754,
909,
5370,
12,
503,
675,
314,
6434,
199,
1593,
1218,
63,
1733,
342,
315,
642,
859,
334,
3239,
5084,
680,
710,
3748,
3992,
199,
1618,
21858,
787,
26,
2286,
15709,
5278,
198,
13,
15709,
8730,
272,
6047,
5278,
198,
13,
6047,
8730,
272,
6001,
5278,
198,
13,
6001,
8730,
272,
30951,
5278,
198,
13,
30951,
8730,
272,
10111,
5278,
198,
13,
10111,
8730,
339,
20116,
51,
11914,
1636,
198,
13,
6001,
8730,
20116,
428,
11914,
1636,
272,
428,
321,
10564,
51,
11914,
1636,
198,
13,
6001,
8730,
428,
321,
10564,
428,
11914,
1636,
339,
13861,
77,
4942,
6156,
446,
13861,
77,
7255,
6156,
2435,
272,
9470,
5278,
221,
446,
6001,
8730,
543,
282,
1067,
421,
199,
1918,
3365,
1007,
13,
2888,
402,
8730,
5171,
3365,
5951,
402,
1827,
199,
3214,
14,
9322,
1006,
4409,
376,
4223,
2870,
2725,
334,
571,
63,
344,
680,
710,
199,
21589,
6716,
23369,
1006,
1163,
4370,
2633,
367,
1924,
402,
314,
199,
4946,
8500,
26,
2234,
6001,
257,
20116,
221,
428,
321,
10564,
221,
9470,
257,
13861,
77,
2049,
9063,
221,
5514,
221,
3001,
221,
5514,
221,
21397,
272,
1827,
755,
359,
56,
61,
258,
359,
56,
61,
755,
359,
56,
61,
420,
359,
56,
61,
420,
359,
56,
61,
272,
730,
263,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
2058,
258,
359,
56,
61,
258,
359,
56,
61,
263,
1275,
755,
359,
56,
61,
272,
1343,
755,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
339,
1475,
420,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
1503,
427,
63,
745,
259,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
8545,
63,
745,
221,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
2637,
259,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
9023,
258,
359,
56,
61,
420,
1275,
260,
1275,
755,
359,
56,
61,
272,
1067,
420,
1275,
755,
1275,
260,
1275,
755,
359,
56,
61,
420,
359,
56,
61,
421,
2234,
6047,
221,
15709,
221,
30951,
257,
10111,
355,
9063,
221,
9063,
221,
9063,
221,
9063,
272,
1827,
263,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
272,
730,
260,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
258,
1275,
5591,
2058,
420,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
272,
1343,
263,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
259,
359,
56,
61,
339,
1475,
755,
359,
56,
61,
259,
359,
56,
61,
258,
1275,
420,
1275,
272,
1503,
427,
63,
745,
258,
359,
56,
61,
259,
359,
56,
61,
258,
1275,
420,
1275,
272,
2637,
420,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
9023,
755,
1275,
420,
1275,
420,
1275,
420,
1275,
272,
4069,
3515,
1275,
420,
1275,
258,
359,
56,
61,
259,
359,
56,
61,
272,
3164,
425,
257,
359,
56,
61,
258,
1275,
420,
1275,
420,
1275,
339,
9362,
263,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
410,
7936,
263,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
14492,
3515,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
1174,
260,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
3482,
3698,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
2909,
420,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
18154,
258,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
272,
18896,
420,
1275,
420,
1275,
420,
1275,
258,
359,
56,
61,
421,
1362,
355,
3820,
29121,
83,
221,
3820,
10867,
355,
3001,
375,
221,
3001,
13,
272,
4922,
3698,
1275,
3698,
359,
56,
61,
272,
612,
65,
526,
1170,
260,
359,
56,
61,
3515,
359,
56,
61,
272,
2058,
260,
359,
56,
61,
3515,
359,
56,
61,
272,
1343,
3698,
359,
56,
61,
3515,
359,
56,
61,
4388,
199,
22321,
402,
3520,
2725,
365,
6366,
465,
376,
2225,
402,
1924,
199,
470,
32759,
1021,
14,
2104,
2893,
12,
1265,
883,
663,
2633,
2839,
26,
339,
687,
612,
65,
19112,
14,
1733,
14,
2520,
5950,
492,
6001,
5278,
339,
1145,
63,
344,
275,
298,
10297,
2,
272,
11483,
335,
275,
6001,
5278,
8,
571,
63,
344,
9,
272,
11483,
335,
14,
1131,
275,
298,
2553,
692,
869,
379,
31672,
2,
272,
11483,
335,
14,
2604,
275,
6335,
199,
199,
269,
12,
340,
1265,
787,
1808,
314,
6434,
805,
26,
2286,
687,
612,
65,
19112,
14,
1733,
14,
2520,
5950,
492,
1218,
63,
1733,
339,
1145,
63,
344,
275,
298,
10297,
2,
272,
11483,
335,
275,
1218,
63,
1733,
480,
5926,
401,
1145,
63,
344,
12,
1827,
628,
2553,
692,
869,
379,
31672,
401,
2058,
29,
2167,
9,
199,
199,
269,
12,
314,
2061,
13943,
12,
282,
14665,
402,
314,
4136,
2877,
26,
339,
687,
612,
65,
19112,
14,
1733,
14,
2520,
5950,
492,
6001,
5278,
339,
1145,
63,
344,
275,
298,
10297,
2,
272,
11483,
335,
275,
6001,
5278,
8,
571,
63,
344,
12,
1827,
628,
2553,
692,
869,
379,
31672,
401,
2058,
29,
2167,
9,
199,
199,
1378,
8044,
282,
9842,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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
] |
viciantomas/TTSFB
|
lib/sleekxmpp/xmlstream/matcher/stanzapath.py
|
14
|
1566
|
# -*- coding: utf-8 -*-
"""
sleekxmpp.xmlstream.matcher.stanzapath
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Part of SleekXMPP: The Sleek XMPP Library
:copyright: (c) 2011 Nathanael C. Fritz
:license: MIT, see LICENSE for more details
"""
from sleekxmpp.xmlstream.matcher.base import MatcherBase
from sleekxmpp.xmlstream.stanzabase import fix_ns
class StanzaPath(MatcherBase):
"""
The StanzaPath matcher selects stanzas that match a given "stanza path",
which is similar to a normal XPath except that it uses the interfaces and
plugins of the stanza instead of the actual, underlying XML.
:param criteria: Object to compare some aspect of a stanza against.
"""
def __init__(self, criteria):
self._criteria = fix_ns(criteria, split=True,
propagate_ns=False,
default_ns='jabber:client')
self._raw_criteria = criteria
def match(self, stanza):
"""
Compare a stanza against a "stanza path". A stanza path is similar to
an XPath expression, but uses the stanza's interfaces and plugins
instead of the underlying XML. See the documentation for the stanza
:meth:`~sleekxmpp.xmlstream.stanzabase.ElementBase.match()` method
for more information.
:param stanza: The :class:`~sleekxmpp.xmlstream.stanzabase.ElementBase`
stanza to compare against.
"""
return stanza.match(self._criteria) or stanza.match(self._raw_criteria)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
26220,
5711,
26608,
14,
1652,
1745,
14,
16135,
14,
29455,
515,
272,
18294,
9753,
2878,
1714,
339,
14320,
402,
428,
274,
5711,
56,
1658,
48,
26,
710,
428,
274,
5711,
1323,
1658,
48,
11243,
339,
520,
7307,
26,
334,
67,
9,
7760,
653,
1619,
6738,
352,
445,
14,
31712,
3903,
272,
520,
1682,
26,
10697,
12,
1937,
5113,
367,
1655,
2436,
199,
624,
199,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
16135,
14,
1095,
492,
9814,
281,
1563,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
9746,
90,
371,
482,
492,
5325,
63,
561,
421,
199,
533,
1933,
19024,
2042,
8,
16073,
1563,
304,
339,
408,
272,
710,
1933,
19024,
2042,
15990,
24750,
410,
290,
90,
305,
626,
1336,
282,
1627,
298,
29455,
931,
401,
272,
1314,
365,
8545,
370,
282,
3293,
1323,
2042,
871,
626,
652,
4440,
314,
8386,
436,
272,
8963,
402,
314,
24267,
3140,
402,
314,
3503,
12,
8793,
4692,
14,
339,
520,
635,
15647,
26,
6935,
370,
6540,
2005,
17435,
402,
282,
24267,
6169,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
15647,
304,
267,
291,
423,
20525,
275,
5325,
63,
561,
8,
20525,
12,
3715,
29,
549,
12,
5101,
19843,
63,
561,
29,
797,
12,
5101,
849,
63,
561,
534,
25075,
26,
1258,
358,
267,
291,
423,
1773,
63,
20525,
275,
15647,
339,
347,
1336,
8,
277,
12,
24267,
304,
267,
408,
267,
18955,
282,
24267,
6169,
282,
298,
29455,
931,
1674,
437,
24267,
931,
365,
8545,
370,
267,
376,
1323,
2042,
3965,
12,
1325,
4440,
314,
24267,
1159,
8386,
436,
8963,
267,
3140,
402,
314,
8793,
4692,
14,
1666,
314,
3794,
367,
314,
24267,
267,
520,
5247,
6054,
23042,
5711,
26608,
14,
1652,
1745,
14,
9746,
90,
371,
482,
14,
2162,
1563,
14,
1431,
11995,
1083,
267,
367,
1655,
2556,
14,
398,
520,
635,
24267,
26,
710,
520,
533,
6054,
23042,
5711,
26608,
14,
1652,
1745,
14,
9746,
90,
371,
482,
14,
2162,
1563,
64,
2432,
24267,
370,
6540,
6169,
14,
267,
408,
267,
372,
24267,
14,
1431,
8,
277,
423,
20525,
9,
503,
24267,
14,
1431,
8,
277,
423,
1773,
63,
20525,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
26220,
5711,
26608,
14,
1652,
1745,
14,
16135,
14,
29455,
515,
272,
18294,
9753,
2878,
1714,
339,
14320,
402,
428,
274,
5711,
56,
1658,
48,
26,
710,
428,
274,
5711,
1323,
1658,
48,
11243,
339,
520,
7307,
26,
334,
67,
9,
7760,
653,
1619,
6738,
352,
445,
14,
31712,
3903,
272,
520,
1682,
26,
10697,
12,
1937,
5113,
367,
1655,
2436,
199,
624,
199,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
16135,
14,
1095,
492,
9814,
281,
1563,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
9746,
90,
371,
482,
492,
5325,
63,
561,
421,
199,
533,
1933,
19024,
2042,
8,
16073,
1563,
304,
339,
408,
272,
710,
1933,
19024,
2042,
15990,
24750,
410,
290,
90,
305,
626,
1336,
282,
1627,
298,
29455,
931,
401,
272,
1314,
365,
8545,
370,
282,
3293,
1323,
2042,
871,
626,
652,
4440,
314,
8386,
436,
272,
8963,
402,
314,
24267,
3140,
402,
314,
3503,
12,
8793,
4692,
14,
339,
520,
635,
15647,
26,
6935,
370,
6540,
2005,
17435,
402,
282,
24267,
6169,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
15647,
304,
267,
291,
423,
20525,
275,
5325,
63,
561,
8,
20525,
12,
3715,
29,
549,
12,
5101,
19843,
63,
561,
29,
797,
12,
5101,
849,
63,
561,
534,
25075,
26,
1258,
358,
267,
291,
423,
1773,
63,
20525,
275,
15647,
339,
347,
1336,
8,
277,
12,
24267,
304,
267,
408,
267,
18955,
282,
24267,
6169,
282,
298,
29455,
931,
1674,
437,
24267,
931,
365,
8545,
370,
267,
376,
1323,
2042,
3965,
12,
1325,
4440,
314,
24267,
1159,
8386,
436,
8963,
267,
3140,
402,
314,
8793,
4692,
14,
1666,
314,
3794,
367,
314,
24267,
267,
520,
5247,
6054,
23042,
5711,
26608,
14,
1652,
1745,
14,
9746,
90,
371,
482,
14,
2162,
1563,
14,
1431,
11995,
1083,
267,
367,
1655,
2556,
14,
398,
520,
635,
24267,
26,
710,
520,
533,
6054,
23042,
5711,
26608,
14,
1652,
1745,
14,
9746,
90,
371,
482,
14,
2162,
1563,
64,
2432,
24267,
370,
6540,
6169,
14,
267,
408,
267,
372,
24267,
14,
1431,
8,
277,
423,
20525,
9,
503,
24267,
14,
1431,
8,
277,
423,
1773,
63,
20525,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fishstamp82/loprop
|
test/test_h2o_rot.py
|
2
|
13738
|
import os
import numpy as np
from ..loprop import MolFrag, penalty_function, xtang, pairs
from ..daltools.util import full
import re
thisdir = os.path.dirname(__file__)
case = "h2o_rot"
tmpdir=os.path.join(thisdir, case, 'tmp')
exec('import %s_data as ref'%case)
def assert_(this, ref, atol=1e-5, text=None):
if text: print text,
print this, ref
print "Max deviation", np.amax(this - ref)
assert np.allclose(this, ref, atol=atol)
def assert_str(this, ref, text=None):
if text: print text,
print this, ref
assert this == ref
def setup():
global m
global ff
# modify Gagliardi penalty function to include unit conversion bug
m = MolFrag(tmpdir, pf=penalty_function(2.0/xtang**2))
ff = ref.ff
def test_nuclear_charge():
Z = m.Z
assert_(Z, ref.Z)
def test_coordinates_au():
R = m.R
assert_(R, ref.R)
def test_default_gauge():
assert_(ref.Rc, m.Rc)
def test_total_charge():
Qtot = m.Qab.sum()
assert_(Qtot, ref.Qtot)
def test_charge():
Qaa = m.Qa
assert_(ref.Q, Qaa)
def test_total_dipole():
assert_(m.Dtot, ref.Dtot)
def test_dipole_allbonds():
D = full.matrix(ref.D.shape)
Dab = m.Dab
for ab, a, b in pairs(m.noa):
D[:, ab] += Dab[:, a, b ]
if a != b: D[:, ab] += Dab[:, b, a]
assert_(D, ref.D)
def test_dipole_allbonds_sym():
Dsym = m.Dsym
assert_(Dsym, ref.D)
def test_dipole_nobonds():
Daa = m.Dab.sum(axis=2).view(full.matrix)
assert_(Daa, ref.Daa)
def test_quadrupole_total():
rrab=full.matrix((6, m.noa, m.noa))
rRab=full.matrix((6, m.noa, m.noa))
RRab=full.matrix((6, m.noa, m.noa))
Rabc = 1.0*m.Rab
for a in range(m.noa):
for b in range(m.noa):
Rabc[a,b,:] -= m.Rc
for a in range(m.noa):
for b in range(m.noa):
ij = 0
for i in range(3):
for j in range(i,3):
rRab[ij, a, b] = m.Dab[i, a, b]*Rabc[a, b, j]\
+ m.Dab[j, a, b]*Rabc[a, b, i]
RRab[ij, a, b] = m.Qab[a, b]*(m.R[a, i] - m.Rc[i])*(m.R[b, j] - m.Rc[j])
ij += 1
QUcab = m.QUab + rRab + RRab
QUc = QUcab.sum(axis=2).sum(axis=1).view(full.matrix)
assert_(QUc, ref.QUc)
def test_nuclear_quadrupole():
QUN = m.QUN
assert_(QUN, ref.QUN)
def test_quadrupole_allbonds():
QU = full.matrix(ref.QU.shape)
QUab = m.QUab
for ab, a, b in pairs(m.noa):
QU[:, ab] += QUab[:, a, b ]
if a != b: QU[:, ab] += QUab[:, b, a]
assert_(QU, ref.QU)
def test_quadrupole_allbonds_sym():
QUsym = m.QUsym
assert_(QUsym, ref.QU)
def test_quadrupole_nobonds():
QUaa = (m.QUab + m.dQUab).sum(axis=2).view(full.matrix)
assert_(QUaa, ref.QUaa)
def test_Fab():
Fab = m.Fab
assert_(Fab, ref.Fab)
def test_molcas_shift():
Fab = m.Fab
Lab = Fab + m.sf(Fab)
assert_(Lab, ref.Lab)
def test_total_charge_shift():
dQ = m.dQa[0].sum(axis=0).view(full.matrix)
dQref = [0., 0., 0.]
assert_(dQref, dQ)
def test_atomic_charge_shift():
dQa = m.dQa[0]
dQaref = (ref.dQa[:, 1::2] - ref.dQa[:, 2::2])/(2*ff)
assert_(dQa, dQaref, .006)
def test_lagrangian():
# values per "perturbation" as in atomic_charge_shift below
la = m.la[0]
laref = (ref.la[:,0:6:2] - ref.la[:,1:6:2])/(2*ff)
# The sign difference is because mocas sets up rhs with opposite sign
assert_(-laref, la, atol=100)
def test_bond_charge_shift():
dQab = m.dQab[0]
noa = m.noa
dQabref = (ref.dQab[:, 1:7:2] - ref.dQab[:, 2:7:2])/(2*ff)
dQabcmp = full.matrix((3, 3))
ab = 0
for a in range(noa):
for b in range(a):
dQabcmp[ab, :] = dQab[a, b, :]
ab += 1
# The sign difference is because mocas sets up rhs with opposite sign
assert_(-dQabref, dQabcmp, 0.006)
def test_bond_charge_shift_sum():
dQa = m.dQab[0].sum(axis=1).view(full.matrix)
dQaref = m.dQa[0]
assert_(dQa, dQaref)
def test_polarizability_total():
Am = m.Am[0]
assert_(Am, ref.Am, 0.015)
def test_polarizability_allbonds_molcas_internal():
O = ref.O
H1O = ref.H1O
H1 = ref.H1
H2O = ref.H2O
H2H1 = ref.H2H1
H2 = ref.H2
rMP = ref.rMP
RO, RH1, RH2 = m.R
ROx, ROy, ROz = RO
RH1x, RH1y, RH1z = RH1
RH2x, RH2y, RH2z = RH2
ihff = 1/(2*ff)
q, x, y, z = range(4)
dx1, dx2, dy1, dy2, dz1, dz2 = 1, 2, 3, 4, 5, 6
o, h1o, h1, h2o, h2h1, h2 = range(6)
Oxx = ihff*(rMP[x, dx1, o] - rMP[x, dx2, o])
Oyx = ihff*(rMP[y, dx1, o] - rMP[y, dx2, o]
+ rMP[x, dy1, o] - rMP[x, dy2, o])/2
Oyy = ihff*(rMP[y, dy1, o] - rMP[y, dy2, o])
Ozx = ihff*(rMP[z, dx1, o] - rMP[z, dx2, o]
+ rMP[x, dz1, o] - rMP[x, dz2, o])/2
Ozy = ihff*(rMP[z, dy1, o] - rMP[z, dy2, o]
+ rMP[y, dz1, o] - rMP[y, dz2, o])/2
Ozz = ihff*(rMP[z, dz1, o] - rMP[z, dz2, o])
H1Oxx = ihff*(rMP[x, dx1, h1o] - rMP[x, dx2, h1o] \
- (rMP[q, dx1, h1o] - rMP[q, dx2, h1o])*(RH1x-ROx))
H1Oyx = ihff*(
(rMP[y, dx1, h1o] - rMP[y, dx2, h1o]
+ rMP[x, dy1, h1o] - rMP[x, dy2, h1o])/2
- (rMP[q, dx1, h1o] - rMP[q, dx2, h1o])*(RH1y-ROy)
# - (rMP[0, dy1, h1o] - rMP[0, dy2, h1o])*(RH1x-ROx) THIS IS REALLY... A BUG?
)
H1Oyy = ihff*(rMP[y, dy1, h1o] - rMP[y, dy2, h1o] - (rMP[q, dy1, h1o] - rMP[q, dy2, h1o])*(RH1y-ROy))
H1Ozx = ihff*(
(rMP[z, dx1, h1o] - rMP[z, dx2, h1o]
+ rMP[x, dz1, h1o] - rMP[x, dz2, h1o])/2
- (rMP[q, dx1, h1o] - rMP[q, dx2, h1o])*(RH1z-ROz)
# - (rMP[q, dz1, h1o] - rMP[q, dz2, h1o])*(RH1x-ROx) #THIS IS REALLY... A BUG?
)
H1Ozy = ihff*(
(rMP[z, dy1, h1o] - rMP[z, dy2, h1o]
+ rMP[y, dz1, h1o] - rMP[y, dz2, h1o])/2
- (rMP[q, dy1, h1o] - rMP[q, dy2, h1o])*(RH1z-ROz)
# - (rMP[q, dz1, h1o] - rMP[q, dz2, h1o])*(RH1y-ROy) THIS IS REALLY... A BUG?
)
H1Ozz = ihff*(rMP[z, dz1, h1o] - rMP[z, dz2, h1o] - (rMP[q, dz1, h1o] - rMP[q, dz2, h1o])*(RH1z-ROz))
H1xx = ihff*(rMP[x, dx1, h1] - rMP[x, dx2, h1])
H1yx = (ihff*(rMP[y, dx1, h1] - rMP[y, dx2, h1])
+ ihff*(rMP[x, dy1, h1] - rMP[x, dy2, h1]))/2
H1yy = ihff*(rMP[y, dy1, h1] - rMP[y, dy2, h1])
H1zx = (ihff*(rMP[z, dx1, h1] - rMP[z, dx2, h1])
+ ihff*(rMP[x, dz1, h1] - rMP[x, dz2, h1]))/2
H1zy = (ihff*(rMP[z, dy1, h1] - rMP[z, dy2, h1])
+ ihff*(rMP[y, dz1, h1] - rMP[y, dz2, h1]))/2
H1zz = ihff*(rMP[z, dz1, h1] - rMP[z, dz2, h1])
H2Oxx = ihff*(rMP[x, dx1, h2o] - rMP[x, dx2, h2o] - (rMP[q, dx1, h2o] - rMP[q, dx2, h2o])*(RH2x-ROx))
H2Oyx = ihff*(
(rMP[y, dx1, h2o] - rMP[y, dx2, h2o]
+ rMP[x, dy1, h2o] - rMP[x, dy2, h2o])/2
- (rMP[q, dx1, h2o] - rMP[q, dx2, h2o])*(RH2y-ROy)
# - (rMP[q, dy1, h1o] - rMP[q, dy2, h1o])*(RH2x-ROx) THIS IS REALLY... A BUG?
)
H2Oyy = ihff*(rMP[y, dy1, h2o] - rMP[y, dy2, h2o] - (rMP[q, dy1, h2o] - rMP[q, dy2, h2o])*(RH2y-ROy))
H2Ozx = ihff*(
(rMP[z, dx1, h2o] - rMP[z, dx2, h2o]
+ rMP[x, dz1, h2o] - rMP[x, dz2, h2o])/2
- (rMP[q, dx1, h2o] - rMP[q, dx2, h2o])*(RH2z-ROz)
# - (rMP[q, dz1, h1o] - rMP[q, dz2, h1o])*(RH2x-ROx) #THIS IS REALLY... A BUG?
)
H2Ozy = ihff*(
(rMP[z, dy1, h2o] - rMP[z, dy2, h2o]
+ rMP[y, dz1, h2o] - rMP[y, dz2, h2o])/2
- (rMP[q, dy1, h2o] - rMP[q, dy2, h2o])*(RH2z-ROz)
# - (rMP[q, dz1, h2o] - rMP[q, dz2, h2o])*(RH2y-ROy) THIS IS REALLY... A BUG?
)
H2Ozz = ihff*(rMP[z, dz1, h2o] - rMP[z, dz2, h2o] - (rMP[q, dz1, h2o] - rMP[q, dz2, h2o])*(RH2z-ROz))
H2H1xx = ihff*(rMP[x, dx1, h2h1] - rMP[x, dx2, h2h1] - (rMP[q, dx1, h2h1] - rMP[q, dx2, h2h1])*(RH2x-RH1x))
H2H1yx = ihff*(
(rMP[y, dx1, h2h1] - rMP[y, dx2, h2h1]
+ rMP[x, dy1, h2h1] - rMP[x, dy2, h2h1])/2
- (rMP[q, dx1, h2h1] - rMP[q, dx2, h2h1])*(RH1y-ROy)
# - (rMP[q, dy1, h2h1] - rMP[q, dy2, h2h1])*(RH1x-ROx) THIS IS REALLY... A BUG?
)
H2H1yy = ihff*(rMP[y, dy1, h2h1] - rMP[y, dy2, h2h1] - (rMP[q, dy1, h2h1] - rMP[q, dy2, h2h1])*(RH2y-RH1y))
H2H1zx = ihff*(
(rMP[z, dx1, h2h1] - rMP[z, dx2, h2h1]
+ rMP[x, dz1, h2h1] - rMP[x, dz2, h2h1])/2
- (rMP[q, dx1, h2h1] - rMP[q, dx2, h2h1])*(RH1z-ROz)
# - (rMP[q, dz1, h2h1] - rMP[q, dz2, h2h1])*(RH1x-ROx) #THIS IS REALLY... A BUG?
)
H2H1zy = ihff*(
(rMP[z, dy1, h2h1] - rMP[z, dy2, h2h1]
+ rMP[y, dz1, h2h1] - rMP[y, dz2, h2h1])/2
- (rMP[q, dy1, h2h1] - rMP[q, dy2, h2h1])*(RH1z-ROz)
# - (rMP[q, dz1, h2h1] - rMP[q, dz2, h2h1])*(RH1y-RO[1]) THIS IS REALLY... A BUG?
)
H2H1zz = ihff*(rMP[z, dz1, h2h1] - rMP[z, dz2, h2h1] - (rMP[q, dz1, h2h1] - rMP[q, dz2, h2h1])*(RH2z-RH1z))
H2xx = ihff*(rMP[x, dx1, h2] - rMP[x, dx2, h2])
H2yx = (ihff*(rMP[y, dx1, h2] - rMP[y, dx2, h2])
+ ihff*(rMP[x, dy1, h2] - rMP[x, dy2, h2]))/2
H2yy = ihff*(rMP[y, dy1, h2] - rMP[y, dy2, h2])
H2zx = (ihff*(rMP[z, dx1, h2] - rMP[z, dx2, h2])
+ ihff*(rMP[x, dz1, h2] - rMP[x, dz2, h2]))/2
H2zy = (ihff*(rMP[z, dy1, h2] - rMP[z, dy2, h2])
+ ihff*(rMP[y, dz1, h2] - rMP[y, dz2, h2]))/2
H2zz = ihff*(rMP[z, dz1, h2] - rMP[z, dz2, h2])
comp = ("XX", "yx", "yy", "zx", "zy", "zz")
bond = ("O", "H1O", "H1", "H2O", "H2H1", "H2")
assert_(O[0], Oxx, text="Oxx")
assert_(O[1], Oyx, text="Oyx")
assert_(O[2], Oyy, text="Oyy")
assert_(O[3], Ozx, text="Ozx")
assert_(O[4], Ozy, text="Ozy")
assert_(O[5], Ozz, text="Ozz")
assert_(H1O[0], H1Oxx, text="H1Oxx")
assert_(H1O[1], H1Oyx, text="H1Oyx")
assert_(H1O[2], H1Oyy, text="H1Oyy")
assert_(H1O[3], H1Ozx, text="H1Ozx")
assert_(H1O[4], H1Ozy, text="H1Ozy")
assert_(H1O[5], H1Ozz, text="H1Ozz")
assert_(H1[0], H1xx, text="H1xx")
assert_(H1[1], H1yx, text="H1yx")
assert_(H1[2], H1yy, text="H1yy")
assert_(H1[3], H1zx, text="H1zx")
assert_(H1[4], H1zy, text="H1zy")
assert_(H1[5], H1zz, text="H1zz")
assert_(H2O[0], H2Oxx, text="H2Oxx")
assert_(H2O[1], H2Oyx, text="H2Oyx")
assert_(H2O[2], H2Oyy, text="H2Oyy")
assert_(H2O[3], H2Ozx, text="H2Ozx")
assert_(H2O[4], H2Ozy, text="H2Ozy")
assert_(H2O[5], H2Ozz, text="H2Ozz")
assert_(H2H1[0], H2H1xx, text="H2H1xx")
assert_(H2H1[1], H2H1yx, text="H2H1yx")
assert_(H2H1[2], H2H1yy, text="H2H1yy")
assert_(H2H1[3], H2H1zx, text="H2H1zx")
assert_(H2H1[4], H2H1zy, text="H2H1zy")
assert_(H2H1[5], H2H1zz, text="H2H1zz")
assert_(H2[0], H2xx, text="H2xx")
assert_(H2[1], H2yx, text="H2yx")
assert_(H2[2], H2yy, text="H2yy")
assert_(H2[3], H2zx, text="H2zx")
assert_(H2[4], H2zy, text="H2zy")
assert_(H2[5], H2zz, text="H2zz")
def test_altint():
R = m.R
rMP = ref.rMP
diff = [(1, 2), (3, 4), (5, 6)]
atoms = (0, 2, 5)
bonds = (1, 3, 4)
ablab = ("O", "H1O", "H1", "H2O", "H2H1", "H2")
ijlab = ("xx", "yx", "yy", "zx", "zy", "zz")
pol = np.zeros((6, m.noa*(m.noa+1)//2))
for ab, a, b in pairs(m.noa):
for ij, i, j in pairs(3):
#from pdb import set_trace; set_trace()
i1, i2 = diff[i]
j1, j2 = diff[j]
pol[ij, ab] += (rMP[i+1, j1, ab] - rMP[i+1, j2, ab]
+ rMP[j+1, i1, ab] - rMP[j+1, i2, ab])/(4*ff)
if ab in bonds:
pol[ij, ab] -= (R[a][i]-R[b][i])*(rMP[0, j1, ab] - rMP[0, j2, ab])/(2*ff)
assert_(ref.Aab[ij, ab], pol[ij, ab], text="%s%s"%(ablab[ab], ijlab[ij]))
def test_polarizability_allbonds_atoms():
Aab = m.Aab[0] #+ m.dAab
noa = m.noa
Acmp=full.matrix(ref.Aab.shape)
ab = 0
for a in range(noa):
for b in range(a):
Acmp[:, ab] = (Aab[:, :, a, b] + Aab[:, :, b, a]).pack()
ab += 1
Acmp[:, ab] = Aab[:, :, a, a].pack()
ab += 1
# atoms
assert_(ref.Aab[:, 0], Acmp[:, 0], .005)
assert_(ref.Aab[:, 2], Acmp[:, 2], .005)
assert_(ref.Aab[:, 5], Acmp[:, 5], .005)
def test_polarizability_allbonds_bonds():
Aab = m.Aab[0] + m.dAab[0]/2
noa = m.noa
Acmp=full.matrix(ref.Aab.shape)
ab = 0
for a in range(noa):
for b in range(a):
Acmp[:, ab] = (Aab[:, :, a, b] + Aab[:, :, b, a]).pack()
ab += 1
Acmp[:, ab] = Aab[:, :, a, a].pack()
ab += 1
# atoms
assert_(ref.Aab[:, 1], Acmp[:, 1], .150, 'H1O')
assert_(ref.Aab[:, 3], Acmp[:, 3], .150, 'H2O')
assert_(ref.Aab[:, 4], Acmp[:, 4], .005, 'H2H1')
def test_polarizability_nobonds():
Aab = m.Aab[0] + m.dAab[0]/2
noa = m.noa
Acmp = full.matrix((6, noa ))
Aa = Aab.sum(axis=3).view(full.matrix)
ab = 0
for a in range(noa):
Acmp[:, a,] = Aa[:, :, a].pack()
# atoms
assert_(Acmp, ref.Aa, 0.07)
def test_potfile_PAn0():
PAn0 = m.output_potential_file(maxl=-1, pol=0, hyper=0)
assert_str(PAn0, ref.PAn0)
def test_potfile_PA00():
PA00 = m.output_potential_file(maxl=0, pol=0, hyper=0)
assert_str(PA00, ref.PA00)
def test_potfile_PA10():
PA10 = m.output_potential_file(maxl=1, pol=0, hyper=0)
assert_str(PA10, ref.PA10)
def test_potfile_PA20():
PA20 = m.output_potential_file(maxl=2, pol=0, hyper=0)
assert_str(PA20, ref.PA20)
def test_potfile_PA21():
PA21 = m.output_potential_file(maxl=2, pol=1, hyper=0)
assert_str(PA21, ref.PA21)
def test_potfile_PA22():
PA22 = m.output_potential_file(maxl=2, pol=2, hyper=0)
assert_str(PA22, ref.PA22)
if __name__ == "__main__":
import sys
setup()
exec("%s()"%sys.argv[1])
|
gpl-3.0
|
[
646,
747,
221,
199,
646,
2680,
465,
980,
199,
504,
2508,
320,
4469,
492,
603,
393,
24552,
12,
21251,
63,
1593,
12,
25158,
621,
12,
6342,
199,
504,
2508,
12390,
2537,
14,
1974,
492,
2615,
199,
199,
646,
295,
199,
3749,
694,
221,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
2546,
275,
298,
72,
18,
79,
63,
4571,
2,
199,
8616,
29,
736,
14,
515,
14,
904,
8,
3749,
694,
12,
1930,
12,
283,
2791,
358,
199,
1628,
360,
646,
450,
83,
63,
576,
465,
2984,
5956,
2546,
9,
421,
199,
318,
702,
2531,
3749,
12,
2984,
12,
9543,
29,
17,
69,
13,
21,
12,
1318,
29,
403,
304,
272,
340,
1318,
26,
870,
1318,
12,
272,
870,
642,
12,
2984,
272,
870,
298,
4261,
18458,
401,
980,
14,
65,
988,
8,
3749,
446,
2984,
9,
272,
702,
980,
14,
7520,
8,
3749,
12,
2984,
12,
9543,
29,
24504,
9,
199,
199,
318,
702,
63,
495,
8,
3749,
12,
2984,
12,
1318,
29,
403,
304,
272,
340,
1318,
26,
870,
1318,
12,
272,
870,
642,
12,
2984,
272,
702,
642,
508,
2984,
421,
199,
318,
3272,
837,
272,
2288,
333,
272,
2288,
16328,
199,
3,
2811,
598,
643,
317,
18980,
21251,
805,
370,
2387,
4137,
8603,
6519,
272,
333,
275,
603,
393,
24552,
8,
8616,
12,
18258,
29,
26264,
63,
1593,
8,
18,
14,
16,
15,
400,
621,
538,
18,
430,
272,
16328,
275,
2984,
14,
556,
199,
199,
318,
511,
63,
30984,
4025,
63,
16441,
837,
272,
3107,
275,
333,
14,
58,
272,
702,
2531,
58,
12,
2984,
14,
58,
9,
199,
199,
318,
511,
63,
12924,
63,
3844,
837,
272,
820,
275,
333,
14,
50,
272,
702,
2531,
50,
12,
2984,
14,
50,
9,
199,
199,
318,
511,
63,
885,
63,
26775,
837,
272,
702,
2531,
1121,
14,
19360,
12,
333,
14,
19360,
9,
199,
199,
318,
511,
63,
2923,
63,
16441,
837,
272,
3959,
357,
275,
333,
14,
49,
371,
14,
1838,
342,
272,
702,
2531,
4238,
357,
12,
2984,
14,
4238,
357,
9,
199,
199,
318,
511,
63,
16441,
837,
272,
1413,
2158,
275,
333,
14,
49,
65,
272,
702,
2531,
1121,
14,
49,
12,
1413,
2158,
9,
199,
199,
318,
511,
63,
2923,
63,
328,
25903,
837,
272,
702,
2531,
77,
14,
36,
13280,
12,
2984,
14,
36,
13280,
9,
199,
199,
318,
511,
63,
328,
25903,
63,
452,
27816,
837,
272,
577,
275,
2615,
14,
3642,
8,
1121,
14,
36,
14,
1392,
9,
272,
577,
371,
275,
333,
14,
36,
371,
272,
367,
2236,
12,
282,
12,
330,
315,
6342,
8,
77,
14,
889,
65,
304,
267,
577,
3981,
2236,
61,
847,
577,
371,
3981,
282,
12,
330,
1622,
4960,
340,
282,
1137,
330,
26,
577,
3981,
2236,
61,
847,
577,
371,
3981,
330,
12,
282,
61,
5591,
702,
2531,
36,
12,
2984,
14,
36,
9,
199,
199,
318,
511,
63,
328,
25903,
63,
452,
27816,
63,
3840,
837,
272,
577,
3840,
275,
333,
14,
36,
3840,
272,
702,
2531,
36,
3840,
12,
2984,
14,
36,
9,
199,
199,
318,
511,
63,
328,
25903,
63,
889,
27816,
837,
272,
577,
2158,
275,
333,
14,
36,
371,
14,
1838,
8,
3127,
29,
18,
680,
1345,
8,
2861,
14,
3642,
9,
272,
702,
2531,
36,
2158,
12,
2984,
14,
36,
2158,
9,
199,
199,
318,
511,
63,
14567,
5505,
16721,
63,
2923,
837,
272,
519,
14411,
29,
2861,
14,
3642,
1332,
22,
12,
333,
14,
889,
65,
12,
333,
14,
889,
65,
430,
272,
519,
50,
371,
29,
2861,
14,
3642,
1332,
22,
12,
333,
14,
889,
65,
12,
333,
14,
889,
65,
430,
272,
27222,
371,
29,
2861,
14,
3642,
1332,
22,
12,
333,
14,
889,
65,
12,
333,
14,
889,
65,
430,
272,
820,
3175,
275,
413,
14,
16,
10,
77,
14,
50,
371,
272,
367,
282,
315,
1425,
8,
77,
14,
889,
65,
304,
267,
367,
330,
315,
1425,
8,
77,
14,
889,
65,
304,
288,
820,
3175,
59,
65,
12,
66,
21063,
4862,
333,
14,
19360,
272,
367,
282,
315,
1425,
8,
77,
14,
889,
65,
304,
267,
367,
330,
315,
1425,
8,
77,
14,
889,
65,
304,
288,
284,
74,
275,
378,
288,
367,
284,
315,
1425,
8,
19,
304,
355,
367,
1335,
315,
1425,
8,
73,
12,
19,
304,
490,
519,
50,
371,
59,
7879,
12,
282,
12,
330,
61,
275,
333,
14,
36,
371,
59,
73,
12,
282,
12,
330,
3672,
50,
3175,
59,
65,
12,
330,
12,
1335,
7272,
3521,
435,
333,
14,
36,
371,
59,
74,
12,
282,
12,
330,
3672,
50,
3175,
59,
65,
12,
330,
12,
284,
61,
490,
27222,
371,
59,
7879,
12,
282,
12,
330,
61,
275,
333,
14,
49,
371,
59,
65,
12,
330,
3672,
8,
77,
14,
50,
59,
65,
12,
284,
61,
446,
333,
14,
19360,
59,
73,
566,
5830,
77,
14,
50,
59,
66,
12,
1335,
61,
446,
333,
14,
19360,
59,
74,
566,
490,
284,
74,
847,
413,
272,
7813,
26481,
275,
333,
14,
2328,
371,
435,
519,
50,
371,
435,
27222,
371,
272,
7813,
67,
275,
7813,
26481,
14,
1838,
8,
3127,
29,
18,
680,
1838,
8,
3127,
29,
17,
680,
1345,
8,
2861,
14,
3642,
9,
272,
702,
2531,
2328,
67,
12,
2984,
14,
2328,
67,
9,
1362,
199,
318,
511,
63,
30984,
4025,
63,
14567,
5505,
16721,
837,
272,
1413,
1734,
275,
333,
14,
49,
1734,
272,
702,
2531,
49,
1734,
12,
2984,
14,
49,
1734,
9,
199,
199,
318,
511,
63,
14567,
5505,
16721,
63,
452,
27816,
837,
272,
7813,
275,
2615,
14,
3642,
8,
1121,
14,
2328,
14,
1392,
9,
272,
7813,
371,
275,
333,
14,
2328,
371,
272,
367,
2236,
12,
282,
12,
330,
315,
6342,
8,
77,
14,
889,
65,
304,
267,
7813,
3981,
2236,
61,
847,
7813,
371,
3981,
282,
12,
330,
1622,
4960,
340,
282,
1137,
330,
26,
7813,
3981,
2236,
61,
847,
7813,
371,
3981,
330,
12,
282,
61,
5591,
702,
2531,
2328,
12,
2984,
14,
2328,
9,
199,
199,
318,
511,
63,
14567,
5505,
16721,
63,
452,
27816,
63,
3840,
837,
272,
7813,
3840,
275,
333,
14,
2328,
3840,
272,
702,
2531,
2328,
3840,
12,
2984,
14,
2328
] |
[
747,
221,
199,
646,
2680,
465,
980,
199,
504,
2508,
320,
4469,
492,
603,
393,
24552,
12,
21251,
63,
1593,
12,
25158,
621,
12,
6342,
199,
504,
2508,
12390,
2537,
14,
1974,
492,
2615,
199,
199,
646,
295,
199,
3749,
694,
221,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
2546,
275,
298,
72,
18,
79,
63,
4571,
2,
199,
8616,
29,
736,
14,
515,
14,
904,
8,
3749,
694,
12,
1930,
12,
283,
2791,
358,
199,
1628,
360,
646,
450,
83,
63,
576,
465,
2984,
5956,
2546,
9,
421,
199,
318,
702,
2531,
3749,
12,
2984,
12,
9543,
29,
17,
69,
13,
21,
12,
1318,
29,
403,
304,
272,
340,
1318,
26,
870,
1318,
12,
272,
870,
642,
12,
2984,
272,
870,
298,
4261,
18458,
401,
980,
14,
65,
988,
8,
3749,
446,
2984,
9,
272,
702,
980,
14,
7520,
8,
3749,
12,
2984,
12,
9543,
29,
24504,
9,
199,
199,
318,
702,
63,
495,
8,
3749,
12,
2984,
12,
1318,
29,
403,
304,
272,
340,
1318,
26,
870,
1318,
12,
272,
870,
642,
12,
2984,
272,
702,
642,
508,
2984,
421,
199,
318,
3272,
837,
272,
2288,
333,
272,
2288,
16328,
199,
3,
2811,
598,
643,
317,
18980,
21251,
805,
370,
2387,
4137,
8603,
6519,
272,
333,
275,
603,
393,
24552,
8,
8616,
12,
18258,
29,
26264,
63,
1593,
8,
18,
14,
16,
15,
400,
621,
538,
18,
430,
272,
16328,
275,
2984,
14,
556,
199,
199,
318,
511,
63,
30984,
4025,
63,
16441,
837,
272,
3107,
275,
333,
14,
58,
272,
702,
2531,
58,
12,
2984,
14,
58,
9,
199,
199,
318,
511,
63,
12924,
63,
3844,
837,
272,
820,
275,
333,
14,
50,
272,
702,
2531,
50,
12,
2984,
14,
50,
9,
199,
199,
318,
511,
63,
885,
63,
26775,
837,
272,
702,
2531,
1121,
14,
19360,
12,
333,
14,
19360,
9,
199,
199,
318,
511,
63,
2923,
63,
16441,
837,
272,
3959,
357,
275,
333,
14,
49,
371,
14,
1838,
342,
272,
702,
2531,
4238,
357,
12,
2984,
14,
4238,
357,
9,
199,
199,
318,
511,
63,
16441,
837,
272,
1413,
2158,
275,
333,
14,
49,
65,
272,
702,
2531,
1121,
14,
49,
12,
1413,
2158,
9,
199,
199,
318,
511,
63,
2923,
63,
328,
25903,
837,
272,
702,
2531,
77,
14,
36,
13280,
12,
2984,
14,
36,
13280,
9,
199,
199,
318,
511,
63,
328,
25903,
63,
452,
27816,
837,
272,
577,
275,
2615,
14,
3642,
8,
1121,
14,
36,
14,
1392,
9,
272,
577,
371,
275,
333,
14,
36,
371,
272,
367,
2236,
12,
282,
12,
330,
315,
6342,
8,
77,
14,
889,
65,
304,
267,
577,
3981,
2236,
61,
847,
577,
371,
3981,
282,
12,
330,
1622,
4960,
340,
282,
1137,
330,
26,
577,
3981,
2236,
61,
847,
577,
371,
3981,
330,
12,
282,
61,
5591,
702,
2531,
36,
12,
2984,
14,
36,
9,
199,
199,
318,
511,
63,
328,
25903,
63,
452,
27816,
63,
3840,
837,
272,
577,
3840,
275,
333,
14,
36,
3840,
272,
702,
2531,
36,
3840,
12,
2984,
14,
36,
9,
199,
199,
318,
511,
63,
328,
25903,
63,
889,
27816,
837,
272,
577,
2158,
275,
333,
14,
36,
371,
14,
1838,
8,
3127,
29,
18,
680,
1345,
8,
2861,
14,
3642,
9,
272,
702,
2531,
36,
2158,
12,
2984,
14,
36,
2158,
9,
199,
199,
318,
511,
63,
14567,
5505,
16721,
63,
2923,
837,
272,
519,
14411,
29,
2861,
14,
3642,
1332,
22,
12,
333,
14,
889,
65,
12,
333,
14,
889,
65,
430,
272,
519,
50,
371,
29,
2861,
14,
3642,
1332,
22,
12,
333,
14,
889,
65,
12,
333,
14,
889,
65,
430,
272,
27222,
371,
29,
2861,
14,
3642,
1332,
22,
12,
333,
14,
889,
65,
12,
333,
14,
889,
65,
430,
272,
820,
3175,
275,
413,
14,
16,
10,
77,
14,
50,
371,
272,
367,
282,
315,
1425,
8,
77,
14,
889,
65,
304,
267,
367,
330,
315,
1425,
8,
77,
14,
889,
65,
304,
288,
820,
3175,
59,
65,
12,
66,
21063,
4862,
333,
14,
19360,
272,
367,
282,
315,
1425,
8,
77,
14,
889,
65,
304,
267,
367,
330,
315,
1425,
8,
77,
14,
889,
65,
304,
288,
284,
74,
275,
378,
288,
367,
284,
315,
1425,
8,
19,
304,
355,
367,
1335,
315,
1425,
8,
73,
12,
19,
304,
490,
519,
50,
371,
59,
7879,
12,
282,
12,
330,
61,
275,
333,
14,
36,
371,
59,
73,
12,
282,
12,
330,
3672,
50,
3175,
59,
65,
12,
330,
12,
1335,
7272,
3521,
435,
333,
14,
36,
371,
59,
74,
12,
282,
12,
330,
3672,
50,
3175,
59,
65,
12,
330,
12,
284,
61,
490,
27222,
371,
59,
7879,
12,
282,
12,
330,
61,
275,
333,
14,
49,
371,
59,
65,
12,
330,
3672,
8,
77,
14,
50,
59,
65,
12,
284,
61,
446,
333,
14,
19360,
59,
73,
566,
5830,
77,
14,
50,
59,
66,
12,
1335,
61,
446,
333,
14,
19360,
59,
74,
566,
490,
284,
74,
847,
413,
272,
7813,
26481,
275,
333,
14,
2328,
371,
435,
519,
50,
371,
435,
27222,
371,
272,
7813,
67,
275,
7813,
26481,
14,
1838,
8,
3127,
29,
18,
680,
1838,
8,
3127,
29,
17,
680,
1345,
8,
2861,
14,
3642,
9,
272,
702,
2531,
2328,
67,
12,
2984,
14,
2328,
67,
9,
1362,
199,
318,
511,
63,
30984,
4025,
63,
14567,
5505,
16721,
837,
272,
1413,
1734,
275,
333,
14,
49,
1734,
272,
702,
2531,
49,
1734,
12,
2984,
14,
49,
1734,
9,
199,
199,
318,
511,
63,
14567,
5505,
16721,
63,
452,
27816,
837,
272,
7813,
275,
2615,
14,
3642,
8,
1121,
14,
2328,
14,
1392,
9,
272,
7813,
371,
275,
333,
14,
2328,
371,
272,
367,
2236,
12,
282,
12,
330,
315,
6342,
8,
77,
14,
889,
65,
304,
267,
7813,
3981,
2236,
61,
847,
7813,
371,
3981,
282,
12,
330,
1622,
4960,
340,
282,
1137,
330,
26,
7813,
3981,
2236,
61,
847,
7813,
371,
3981,
330,
12,
282,
61,
5591,
702,
2531,
2328,
12,
2984,
14,
2328,
9,
199,
199,
318,
511,
63,
14567,
5505,
16721,
63,
452,
27816,
63,
3840,
837,
272,
7813,
3840,
275,
333,
14,
2328,
3840,
272,
702,
2531,
2328,
3840,
12,
2984,
14,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1,
1,
1,
1
] |
javiplx/cobbler-debian
|
cobbler/modules/authz_allowall.py
|
6
|
1400
|
"""
Authorization module that allows everything, which is the default
for new cobbler installs.
Copyright 2007-2008, Red Hat, Inc
Michael DeHaan <mdehaan@redhat.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
"""
import distutils.sysconfig
import ConfigParser
import sys
from utils import _
plib = distutils.sysconfig.get_python_lib()
mod_path="%s/cobbler" % plib
sys.path.insert(0, mod_path)
import cexceptions
import utils
def register():
"""
The mandatory cobbler module registration hook.
"""
return "authz"
def authorize(api_handle,user,resource,arg1=None,arg2=None,acl_engine=None):
"""
Validate a user against a resource.
NOTE: acls are not enforced as there is no group support in this module
"""
return True
|
gpl-2.0
|
[
624,
199,
11626,
859,
626,
6127,
8137,
12,
1314,
365,
314,
849,
199,
509,
892,
512,
26722,
25801,
14,
199,
199,
7384,
10219,
13,
9300,
12,
9572,
13002,
12,
3277,
199,
45,
11781,
22453,
665,
77,
24247,
32,
17164,
14,
957,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
996,
6019,
13,
10067,
221,
8217,
199,
624,
199,
199,
646,
7065,
14,
24030,
199,
646,
14196,
199,
646,
984,
199,
504,
3778,
492,
485,
199,
199,
80,
773,
275,
7065,
14,
24030,
14,
362,
63,
1548,
63,
773,
342,
199,
1494,
63,
515,
5961,
83,
15,
331,
26722,
2,
450,
299,
773,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
3413,
63,
515,
9,
199,
199,
646,
286,
3924,
199,
646,
3778,
421,
199,
318,
2274,
837,
272,
408,
272,
710,
15230,
512,
26722,
859,
10991,
5759,
14,
272,
408,
272,
372,
298,
1178,
90,
2,
199,
199,
318,
20210,
8,
1246,
63,
2479,
12,
751,
12,
1927,
12,
1273,
17,
29,
403,
12,
1273,
18,
29,
403,
12,
5853,
63,
3908,
29,
403,
304,
272,
408,
272,
12134,
282,
922,
6169,
282,
2073,
14,
272,
6944,
26,
282,
1886,
787,
440,
30163,
465,
2337,
365,
949,
1572,
2291,
315,
642,
859,
272,
408,
272,
372,
715,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
11626,
859,
626,
6127,
8137,
12,
1314,
365,
314,
849,
199,
509,
892,
512,
26722,
25801,
14,
199,
199,
7384,
10219,
13,
9300,
12,
9572,
13002,
12,
3277,
199,
45,
11781,
22453,
665,
77,
24247,
32,
17164,
14,
957,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
996,
6019,
13,
10067,
221,
8217,
199,
624,
199,
199,
646,
7065,
14,
24030,
199,
646,
14196,
199,
646,
984,
199,
504,
3778,
492,
485,
199,
199,
80,
773,
275,
7065,
14,
24030,
14,
362,
63,
1548,
63,
773,
342,
199,
1494,
63,
515,
5961,
83,
15,
331,
26722,
2,
450,
299,
773,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
3413,
63,
515,
9,
199,
199,
646,
286,
3924,
199,
646,
3778,
421,
199,
318,
2274,
837,
272,
408,
272,
710,
15230,
512,
26722,
859,
10991,
5759,
14,
272,
408,
272,
372,
298,
1178,
90,
2,
199,
199,
318,
20210,
8,
1246,
63,
2479,
12,
751,
12,
1927,
12,
1273,
17,
29,
403,
12,
1273,
18,
29,
403,
12,
5853,
63,
3908,
29,
403,
304,
272,
408,
272,
12134,
282,
922,
6169,
282,
2073,
14,
272,
6944,
26,
282,
1886,
787,
440,
30163,
465,
2337,
365,
949,
1572,
2291,
315,
642,
859,
272,
408,
272,
372,
715,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
raqqun/tweetcommander
|
packages/requests/packages/charade/gb2312freq.py
|
3132
|
36011
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
# GB2312 most frequently used character table
#
# Char to FreqOrder table , from hz6763
# 512 --> 0.79 -- 0.79
# 1024 --> 0.92 -- 0.13
# 2048 --> 0.98 -- 0.06
# 6768 --> 1.00 -- 0.02
#
# Ideal Distribution Ratio = 0.79135/(1-0.79135) = 3.79
# Random Distribution Ration = 512 / (3755 - 512) = 0.157
#
# Typical Distribution Ratio about 25% of Ideal one, still much higher that RDR
GB2312_TYPICAL_DISTRIBUTION_RATIO = 0.9
GB2312_TABLE_SIZE = 3760
GB2312CharToFreqOrder = (
1671, 749,1443,2364,3924,3807,2330,3921,1704,3463,2691,1511,1515, 572,3191,2205,
2361, 224,2558, 479,1711, 963,3162, 440,4060,1905,2966,2947,3580,2647,3961,3842,
2204, 869,4207, 970,2678,5626,2944,2956,1479,4048, 514,3595, 588,1346,2820,3409,
249,4088,1746,1873,2047,1774, 581,1813, 358,1174,3590,1014,1561,4844,2245, 670,
1636,3112, 889,1286, 953, 556,2327,3060,1290,3141, 613, 185,3477,1367, 850,3820,
1715,2428,2642,2303,2732,3041,2562,2648,3566,3946,1349, 388,3098,2091,1360,3585,
152,1687,1539, 738,1559, 59,1232,2925,2267,1388,1249,1741,1679,2960, 151,1566,
1125,1352,4271, 924,4296, 385,3166,4459, 310,1245,2850, 70,3285,2729,3534,3575,
2398,3298,3466,1960,2265, 217,3647, 864,1909,2084,4401,2773,1010,3269,5152, 853,
3051,3121,1244,4251,1895, 364,1499,1540,2313,1180,3655,2268, 562, 715,2417,3061,
544, 336,3768,2380,1752,4075, 950, 280,2425,4382, 183,2759,3272, 333,4297,2155,
1688,2356,1444,1039,4540, 736,1177,3349,2443,2368,2144,2225, 565, 196,1482,3406,
927,1335,4147, 692, 878,1311,1653,3911,3622,1378,4200,1840,2969,3149,2126,1816,
2534,1546,2393,2760, 737,2494, 13, 447, 245,2747, 38,2765,2129,2589,1079, 606,
360, 471,3755,2890, 404, 848, 699,1785,1236, 370,2221,1023,3746,2074,2026,2023,
2388,1581,2119, 812,1141,3091,2536,1519, 804,2053, 406,1596,1090, 784, 548,4414,
1806,2264,2936,1100, 343,4114,5096, 622,3358, 743,3668,1510,1626,5020,3567,2513,
3195,4115,5627,2489,2991, 24,2065,2697,1087,2719, 48,1634, 315, 68, 985,2052,
198,2239,1347,1107,1439, 597,2366,2172, 871,3307, 919,2487,2790,1867, 236,2570,
1413,3794, 906,3365,3381,1701,1982,1818,1524,2924,1205, 616,2586,2072,2004, 575,
253,3099, 32,1365,1182, 197,1714,2454,1201, 554,3388,3224,2748, 756,2587, 250,
2567,1507,1517,3529,1922,2761,2337,3416,1961,1677,2452,2238,3153, 615, 911,1506,
1474,2495,1265,1906,2749,3756,3280,2161, 898,2714,1759,3450,2243,2444, 563, 26,
3286,2266,3769,3344,2707,3677, 611,1402, 531,1028,2871,4548,1375, 261,2948, 835,
1190,4134, 353, 840,2684,1900,3082,1435,2109,1207,1674, 329,1872,2781,4055,2686,
2104, 608,3318,2423,2957,2768,1108,3739,3512,3271,3985,2203,1771,3520,1418,2054,
1681,1153, 225,1627,2929, 162,2050,2511,3687,1954, 124,1859,2431,1684,3032,2894,
585,4805,3969,2869,2704,2088,2032,2095,3656,2635,4362,2209, 256, 518,2042,2105,
3777,3657, 643,2298,1148,1779, 190, 989,3544, 414, 11,2135,2063,2979,1471, 403,
3678, 126, 770,1563, 671,2499,3216,2877, 600,1179, 307,2805,4937,1268,1297,2694,
252,4032,1448,1494,1331,1394, 127,2256, 222,1647,1035,1481,3056,1915,1048, 873,
3651, 210, 33,1608,2516, 200,1520, 415, 102, 0,3389,1287, 817, 91,3299,2940,
836,1814, 549,2197,1396,1669,2987,3582,2297,2848,4528,1070, 687, 20,1819, 121,
1552,1364,1461,1968,2617,3540,2824,2083, 177, 948,4938,2291, 110,4549,2066, 648,
3359,1755,2110,2114,4642,4845,1693,3937,3308,1257,1869,2123, 208,1804,3159,2992,
2531,2549,3361,2418,1350,2347,2800,2568,1291,2036,2680, 72, 842,1990, 212,1233,
1154,1586, 75,2027,3410,4900,1823,1337,2710,2676, 728,2810,1522,3026,4995, 157,
755,1050,4022, 710, 785,1936,2194,2085,1406,2777,2400, 150,1250,4049,1206, 807,
1910, 534, 529,3309,1721,1660, 274, 39,2827, 661,2670,1578, 925,3248,3815,1094,
4278,4901,4252, 41,1150,3747,2572,2227,4501,3658,4902,3813,3357,3617,2884,2258,
887, 538,4187,3199,1294,2439,3042,2329,2343,2497,1255, 107, 543,1527, 521,3478,
3568, 194,5062, 15, 961,3870,1241,1192,2664, 66,5215,3260,2111,1295,1127,2152,
3805,4135, 901,1164,1976, 398,1278, 530,1460, 748, 904,1054,1966,1426, 53,2909,
509, 523,2279,1534, 536,1019, 239,1685, 460,2353, 673,1065,2401,3600,4298,2272,
1272,2363, 284,1753,3679,4064,1695, 81, 815,2677,2757,2731,1386, 859, 500,4221,
2190,2566, 757,1006,2519,2068,1166,1455, 337,2654,3203,1863,1682,1914,3025,1252,
1409,1366, 847, 714,2834,2038,3209, 964,2970,1901, 885,2553,1078,1756,3049, 301,
1572,3326, 688,2130,1996,2429,1805,1648,2930,3421,2750,3652,3088, 262,1158,1254,
389,1641,1812, 526,1719, 923,2073,1073,1902, 468, 489,4625,1140, 857,2375,3070,
3319,2863, 380, 116,1328,2693,1161,2244, 273,1212,1884,2769,3011,1775,1142, 461,
3066,1200,2147,2212, 790, 702,2695,4222,1601,1058, 434,2338,5153,3640, 67,2360,
4099,2502, 618,3472,1329, 416,1132, 830,2782,1807,2653,3211,3510,1662, 192,2124,
296,3979,1739,1611,3684, 23, 118, 324, 446,1239,1225, 293,2520,3814,3795,2535,
3116, 17,1074, 467,2692,2201, 387,2922, 45,1326,3055,1645,3659,2817, 958, 243,
1903,2320,1339,2825,1784,3289, 356, 576, 865,2315,2381,3377,3916,1088,3122,1713,
1655, 935, 628,4689,1034,1327, 441, 800, 720, 894,1979,2183,1528,5289,2702,1071,
4046,3572,2399,1571,3281, 79, 761,1103, 327, 134, 758,1899,1371,1615, 879, 442,
215,2605,2579, 173,2048,2485,1057,2975,3317,1097,2253,3801,4263,1403,1650,2946,
814,4968,3487,1548,2644,1567,1285, 2, 295,2636, 97, 946,3576, 832, 141,4257,
3273, 760,3821,3521,3156,2607, 949,1024,1733,1516,1803,1920,2125,2283,2665,3180,
1501,2064,3560,2171,1592, 803,3518,1416, 732,3897,4258,1363,1362,2458, 119,1427,
602,1525,2608,1605,1639,3175, 694,3064, 10, 465, 76,2000,4846,4208, 444,3781,
1619,3353,2206,1273,3796, 740,2483, 320,1723,2377,3660,2619,1359,1137,1762,1724,
2345,2842,1850,1862, 912, 821,1866, 612,2625,1735,2573,3369,1093, 844, 89, 937,
930,1424,3564,2413,2972,1004,3046,3019,2011, 711,3171,1452,4178, 428, 801,1943,
432, 445,2811, 206,4136,1472, 730, 349, 73, 397,2802,2547, 998,1637,1167, 789,
396,3217, 154,1218, 716,1120,1780,2819,4826,1931,3334,3762,2139,1215,2627, 552,
3664,3628,3232,1405,2383,3111,1356,2652,3577,3320,3101,1703, 640,1045,1370,1246,
4996, 371,1575,2436,1621,2210, 984,4033,1734,2638, 16,4529, 663,2755,3255,1451,
3917,2257,1253,1955,2234,1263,2951, 214,1229, 617, 485, 359,1831,1969, 473,2310,
750,2058, 165, 80,2864,2419, 361,4344,2416,2479,1134, 796,3726,1266,2943, 860,
2715, 938, 390,2734,1313,1384, 248, 202, 877,1064,2854, 522,3907, 279,1602, 297,
2357, 395,3740, 137,2075, 944,4089,2584,1267,3802, 62,1533,2285, 178, 176, 780,
2440, 201,3707, 590, 478,1560,4354,2117,1075, 30, 74,4643,4004,1635,1441,2745,
776,2596, 238,1077,1692,1912,2844, 605, 499,1742,3947, 241,3053, 980,1749, 936,
2640,4511,2582, 515,1543,2162,5322,2892,2993, 890,2148,1924, 665,1827,3581,1032,
968,3163, 339,1044,1896, 270, 583,1791,1720,4367,1194,3488,3669, 43,2523,1657,
163,2167, 290,1209,1622,3378, 550, 634,2508,2510, 695,2634,2384,2512,1476,1414,
220,1469,2341,2138,2852,3183,2900,4939,2865,3502,1211,3680, 854,3227,1299,2976,
3172, 186,2998,1459, 443,1067,3251,1495, 321,1932,3054, 909, 753,1410,1828, 436,
2441,1119,1587,3164,2186,1258, 227, 231,1425,1890,3200,3942, 247, 959, 725,5254,
2741, 577,2158,2079, 929, 120, 174, 838,2813, 591,1115, 417,2024, 40,3240,1536,
1037, 291,4151,2354, 632,1298,2406,2500,3535,1825,1846,3451, 205,1171, 345,4238,
18,1163, 811, 685,2208,1217, 425,1312,1508,1175,4308,2552,1033, 587,1381,3059,
2984,3482, 340,1316,4023,3972, 792,3176, 519, 777,4690, 918, 933,4130,2981,3741,
90,3360,2911,2200,5184,4550, 609,3079,2030, 272,3379,2736, 363,3881,1130,1447,
286, 779, 357,1169,3350,3137,1630,1220,2687,2391, 747,1277,3688,2618,2682,2601,
1156,3196,5290,4034,3102,1689,3596,3128, 874, 219,2783, 798, 508,1843,2461, 269,
1658,1776,1392,1913,2983,3287,2866,2159,2372, 829,4076, 46,4253,2873,1889,1894,
915,1834,1631,2181,2318, 298, 664,2818,3555,2735, 954,3228,3117, 527,3511,2173,
681,2712,3033,2247,2346,3467,1652, 155,2164,3382, 113,1994, 450, 899, 494, 994,
1237,2958,1875,2336,1926,3727, 545,1577,1550, 633,3473, 204,1305,3072,2410,1956,
2471, 707,2134, 841,2195,2196,2663,3843,1026,4940, 990,3252,4997, 368,1092, 437,
3212,3258,1933,1829, 675,2977,2893, 412, 943,3723,4644,3294,3283,2230,2373,5154,
2389,2241,2661,2323,1404,2524, 593, 787, 677,3008,1275,2059, 438,2709,2609,2240,
2269,2246,1446, 36,1568,1373,3892,1574,2301,1456,3962, 693,2276,5216,2035,1143,
2720,1919,1797,1811,2763,4137,2597,1830,1699,1488,1198,2090, 424,1694, 312,3634,
3390,4179,3335,2252,1214, 561,1059,3243,2295,2561, 975,5155,2321,2751,3772, 472,
1537,3282,3398,1047,2077,2348,2878,1323,3340,3076, 690,2906, 51, 369, 170,3541,
1060,2187,2688,3670,2541,1083,1683, 928,3918, 459, 109,4427, 599,3744,4286, 143,
2101,2730,2490, 82,1588,3036,2121, 281,1860, 477,4035,1238,2812,3020,2716,3312,
1530,2188,2055,1317, 843, 636,1808,1173,3495, 649, 181,1002, 147,3641,1159,2414,
3750,2289,2795, 813,3123,2610,1136,4368, 5,3391,4541,2174, 420, 429,1728, 754,
1228,2115,2219, 347,2223,2733, 735,1518,3003,2355,3134,1764,3948,3329,1888,2424,
1001,1234,1972,3321,3363,1672,1021,1450,1584, 226, 765, 655,2526,3404,3244,2302,
3665, 731, 594,2184, 319,1576, 621, 658,2656,4299,2099,3864,1279,2071,2598,2739,
795,3086,3699,3908,1707,2352,2402,1382,3136,2475,1465,4847,3496,3865,1085,3004,
2591,1084, 213,2287,1963,3565,2250, 822, 793,4574,3187,1772,1789,3050, 595,1484,
1959,2770,1080,2650, 456, 422,2996, 940,3322,4328,4345,3092,2742, 965,2784, 739,
4124, 952,1358,2498,2949,2565, 332,2698,2378, 660,2260,2473,4194,3856,2919, 535,
1260,2651,1208,1428,1300,1949,1303,2942, 433,2455,2450,1251,1946, 614,1269, 641,
1306,1810,2737,3078,2912, 564,2365,1419,1415,1497,4460,2367,2185,1379,3005,1307,
3218,2175,1897,3063, 682,1157,4040,4005,1712,1160,1941,1399, 394, 402,2952,1573,
1151,2986,2404, 862, 299,2033,1489,3006, 346, 171,2886,3401,1726,2932, 168,2533,
47,2507,1030,3735,1145,3370,1395,1318,1579,3609,4560,2857,4116,1457,2529,1965,
504,1036,2690,2988,2405, 745,5871, 849,2397,2056,3081, 863,2359,3857,2096, 99,
1397,1769,2300,4428,1643,3455,1978,1757,3718,1440, 35,4879,3742,1296,4228,2280,
160,5063,1599,2013, 166, 520,3479,1646,3345,3012, 490,1937,1545,1264,2182,2505,
1096,1188,1369,1436,2421,1667,2792,2460,1270,2122, 727,3167,2143, 806,1706,1012,
1800,3037, 960,2218,1882, 805, 139,2456,1139,1521, 851,1052,3093,3089, 342,2039,
744,5097,1468,1502,1585,2087, 223, 939, 326,2140,2577, 892,2481,1623,4077, 982,
3708, 135,2131, 87,2503,3114,2326,1106, 876,1616, 547,2997,2831,2093,3441,4530,
4314, 9,3256,4229,4148, 659,1462,1986,1710,2046,2913,2231,4090,4880,5255,3392,
3274,1368,3689,4645,1477, 705,3384,3635,1068,1529,2941,1458,3782,1509, 100,1656,
2548, 718,2339, 408,1590,2780,3548,1838,4117,3719,1345,3530, 717,3442,2778,3220,
2898,1892,4590,3614,3371,2043,1998,1224,3483, 891, 635, 584,2559,3355, 733,1766,
1729,1172,3789,1891,2307, 781,2982,2271,1957,1580,5773,2633,2005,4195,3097,1535,
3213,1189,1934,5693,3262, 586,3118,1324,1598, 517,1564,2217,1868,1893,4445,3728,
2703,3139,1526,1787,1992,3882,2875,1549,1199,1056,2224,1904,2711,5098,4287, 338,
1993,3129,3489,2689,1809,2815,1997, 957,1855,3898,2550,3275,3057,1105,1319, 627,
1505,1911,1883,3526, 698,3629,3456,1833,1431, 746, 77,1261,2017,2296,1977,1885,
125,1334,1600, 525,1798,1109,2222,1470,1945, 559,2236,1186,3443,2476,1929,1411,
2411,3135,1777,3372,2621,1841,1613,3229, 668,1430,1839,2643,2916, 195,1989,2671,
2358,1387, 629,3205,2293,5256,4439, 123,1310, 888,1879,4300,3021,3605,1003,1162,
3192,2910,2010, 140,2395,2859, 55,1082,2012,2901, 662, 419,2081,1438, 680,2774,
4654,3912,1620,1731,1625,5035,4065,2328, 512,1344, 802,5443,2163,2311,2537, 524,
3399, 98,1155,2103,1918,2606,3925,2816,1393,2465,1504,3773,2177,3963,1478,4346,
180,1113,4655,3461,2028,1698, 833,2696,1235,1322,1594,4408,3623,3013,3225,2040,
3022, 541,2881, 607,3632,2029,1665,1219, 639,1385,1686,1099,2803,3231,1938,3188,
2858, 427, 676,2772,1168,2025, 454,3253,2486,3556, 230,1950, 580, 791,1991,1280,
1086,1974,2034, 630, 257,3338,2788,4903,1017, 86,4790, 966,2789,1995,1696,1131,
259,3095,4188,1308, 179,1463,5257, 289,4107,1248, 42,3413,1725,2288, 896,1947,
774,4474,4254, 604,3430,4264, 392,2514,2588, 452, 237,1408,3018, 988,4531,1970,
3034,3310, 540,2370,1562,1288,2990, 502,4765,1147, 4,1853,2708, 207, 294,2814,
4078,2902,2509, 684, 34,3105,3532,2551, 644, 709,2801,2344, 573,1727,3573,3557,
2021,1081,3100,4315,2100,3681, 199,2263,1837,2385, 146,3484,1195,2776,3949, 997,
1939,3973,1008,1091,1202,1962,1847,1149,4209,5444,1076, 493, 117,5400,2521, 972,
1490,2934,1796,4542,2374,1512,2933,2657, 413,2888,1135,2762,2314,2156,1355,2369,
766,2007,2527,2170,3124,2491,2593,2632,4757,2437, 234,3125,3591,1898,1750,1376,
1942,3468,3138, 570,2127,2145,3276,4131, 962, 132,1445,4196, 19, 941,3624,3480,
3366,1973,1374,4461,3431,2629, 283,2415,2275, 808,2887,3620,2112,2563,1353,3610,
955,1089,3103,1053, 96, 88,4097, 823,3808,1583, 399, 292,4091,3313, 421,1128,
642,4006, 903,2539,1877,2082, 596, 29,4066,1790, 722,2157, 130, 995,1569, 769,
1485, 464, 513,2213, 288,1923,1101,2453,4316, 133, 486,2445, 50, 625, 487,2207,
57, 423, 481,2962, 159,3729,1558, 491, 303, 482, 501, 240,2837, 112,3648,2392,
1783, 362, 8,3433,3422, 610,2793,3277,1390,1284,1654, 21,3823, 734, 367, 623,
193, 287, 374,1009,1483, 816, 476, 313,2255,2340,1262,2150,2899,1146,2581, 782,
2116,1659,2018,1880, 255,3586,3314,1110,2867,2137,2564, 986,2767,5185,2006, 650,
158, 926, 762, 881,3157,2717,2362,3587, 306,3690,3245,1542,3077,2427,1691,2478,
2118,2985,3490,2438, 539,2305, 983, 129,1754, 355,4201,2386, 827,2923, 104,1773,
2838,2771, 411,2905,3919, 376, 767, 122,1114, 828,2422,1817,3506, 266,3460,1007,
1609,4998, 945,2612,4429,2274, 726,1247,1964,2914,2199,2070,4002,4108, 657,3323,
1422, 579, 455,2764,4737,1222,2895,1670, 824,1223,1487,2525, 558, 861,3080, 598,
2659,2515,1967, 752,2583,2376,2214,4180, 977, 704,2464,4999,2622,4109,1210,2961,
819,1541, 142,2284, 44, 418, 457,1126,3730,4347,4626,1644,1876,3671,1864, 302,
1063,5694, 624, 723,1984,3745,1314,1676,2488,1610,1449,3558,3569,2166,2098, 409,
1011,2325,3704,2306, 818,1732,1383,1824,1844,3757, 999,2705,3497,1216,1423,2683,
2426,2954,2501,2726,2229,1475,2554,5064,1971,1794,1666,2014,1343, 783, 724, 191,
2434,1354,2220,5065,1763,2752,2472,4152, 131, 175,2885,3434, 92,1466,4920,2616,
3871,3872,3866, 128,1551,1632, 669,1854,3682,4691,4125,1230, 188,2973,3290,1302,
1213, 560,3266, 917, 763,3909,3249,1760, 868,1958, 764,1782,2097, 145,2277,3774,
4462, 64,1491,3062, 971,2132,3606,2442, 221,1226,1617, 218, 323,1185,3207,3147,
571, 619,1473,1005,1744,2281, 449,1887,2396,3685, 275, 375,3816,1743,3844,3731,
845,1983,2350,4210,1377, 773, 967,3499,3052,3743,2725,4007,1697,1022,3943,1464,
3264,2855,2722,1952,1029,2839,2467, 84,4383,2215, 820,1391,2015,2448,3672, 377,
1948,2168, 797,2545,3536,2578,2645, 94,2874,1678, 405,1259,3071, 771, 546,1315,
470,1243,3083, 895,2468, 981, 969,2037, 846,4181, 653,1276,2928, 14,2594, 557,
3007,2474, 156, 902,1338,1740,2574, 537,2518, 973,2282,2216,2433,1928, 138,2903,
1293,2631,1612, 646,3457, 839,2935, 111, 496,2191,2847, 589,3186, 149,3994,2060,
4031,2641,4067,3145,1870, 37,3597,2136,1025,2051,3009,3383,3549,1121,1016,3261,
1301, 251,2446,2599,2153, 872,3246, 637, 334,3705, 831, 884, 921,3065,3140,4092,
2198,1944, 246,2964, 108,2045,1152,1921,2308,1031, 203,3173,4170,1907,3890, 810,
1401,2003,1690, 506, 647,1242,2828,1761,1649,3208,2249,1589,3709,2931,5156,1708,
498, 666,2613, 834,3817,1231, 184,2851,1124, 883,3197,2261,3710,1765,1553,2658,
1178,2639,2351, 93,1193, 942,2538,2141,4402, 235,1821, 870,1591,2192,1709,1871,
3341,1618,4126,2595,2334, 603, 651, 69, 701, 268,2662,3411,2555,1380,1606, 503,
448, 254,2371,2646, 574,1187,2309,1770, 322,2235,1292,1801, 305, 566,1133, 229,
2067,2057, 706, 167, 483,2002,2672,3295,1820,3561,3067, 316, 378,2746,3452,1112,
136,1981, 507,1651,2917,1117, 285,4591, 182,2580,3522,1304, 335,3303,1835,2504,
1795,1792,2248, 674,1018,2106,2449,1857,2292,2845, 976,3047,1781,2600,2727,1389,
1281, 52,3152, 153, 265,3950, 672,3485,3951,4463, 430,1183, 365, 278,2169, 27,
1407,1336,2304, 209,1340,1730,2202,1852,2403,2883, 979,1737,1062, 631,2829,2542,
3876,2592, 825,2086,2226,3048,3625, 352,1417,3724, 542, 991, 431,1351,3938,1861,
2294, 826,1361,2927,3142,3503,1738, 463,2462,2723, 582,1916,1595,2808, 400,3845,
3891,2868,3621,2254, 58,2492,1123, 910,2160,2614,1372,1603,1196,1072,3385,1700,
3267,1980, 696, 480,2430, 920, 799,1570,2920,1951,2041,4047,2540,1321,4223,2469,
3562,2228,1271,2602, 401,2833,3351,2575,5157, 907,2312,1256, 410, 263,3507,1582,
996, 678,1849,2316,1480, 908,3545,2237, 703,2322, 667,1826,2849,1531,2604,2999,
2407,3146,2151,2630,1786,3711, 469,3542, 497,3899,2409, 858, 837,4446,3393,1274,
786, 620,1845,2001,3311, 484, 308,3367,1204,1815,3691,2332,1532,2557,1842,2020,
2724,1927,2333,4440, 567, 22,1673,2728,4475,1987,1858,1144,1597, 101,1832,3601,
12, 974,3783,4391, 951,1412, 1,3720, 453,4608,4041, 528,1041,1027,3230,2628,
1129, 875,1051,3291,1203,2262,1069,2860,2799,2149,2615,3278, 144,1758,3040, 31,
475,1680, 366,2685,3184, 311,1642,4008,2466,5036,1593,1493,2809, 216,1420,1668,
233, 304,2128,3284, 232,1429,1768,1040,2008,3407,2740,2967,2543, 242,2133, 778,
1565,2022,2620, 505,2189,2756,1098,2273, 372,1614, 708, 553,2846,2094,2278, 169,
3626,2835,4161, 228,2674,3165, 809,1454,1309, 466,1705,1095, 900,3423, 880,2667,
3751,5258,2317,3109,2571,4317,2766,1503,1342, 866,4447,1118, 63,2076, 314,1881,
1348,1061, 172, 978,3515,1747, 532, 511,3970, 6, 601, 905,2699,3300,1751, 276,
1467,3725,2668, 65,4239,2544,2779,2556,1604, 578,2451,1802, 992,2331,2624,1320,
3446, 713,1513,1013, 103,2786,2447,1661, 886,1702, 916, 654,3574,2031,1556, 751,
2178,2821,2179,1498,1538,2176, 271, 914,2251,2080,1325, 638,1953,2937,3877,2432,
2754, 95,3265,1716, 260,1227,4083, 775, 106,1357,3254, 426,1607, 555,2480, 772,
1985, 244,2546, 474, 495,1046,2611,1851,2061, 71,2089,1675,2590, 742,3758,2843,
3222,1433, 267,2180,2576,2826,2233,2092,3913,2435, 956,1745,3075, 856,2113,1116,
451, 3,1988,2896,1398, 993,2463,1878,2049,1341,2718,2721,2870,2108, 712,2904,
4363,2753,2324, 277,2872,2349,2649, 384, 987, 435, 691,3000, 922, 164,3939, 652,
1500,1184,4153,2482,3373,2165,4848,2335,3775,3508,3154,2806,2830,1554,2102,1664,
2530,1434,2408, 893,1547,2623,3447,2832,2242,2532,3169,2856,3223,2078, 49,3770,
3469, 462, 318, 656,2259,3250,3069, 679,1629,2758, 344,1138,1104,3120,1836,1283,
3115,2154,1437,4448, 934, 759,1999, 794,2862,1038, 533,2560,1722,2342, 855,2626,
1197,1663,4476,3127, 85,4240,2528, 25,1111,1181,3673, 407,3470,4561,2679,2713,
768,1925,2841,3986,1544,1165, 932, 373,1240,2146,1930,2673, 721,4766, 354,4333,
391,2963, 187, 61,3364,1442,1102, 330,1940,1767, 341,3809,4118, 393,2496,2062,
2211, 105, 331, 300, 439, 913,1332, 626, 379,3304,1557, 328, 689,3952, 309,1555,
931, 317,2517,3027, 325, 569, 686,2107,3084, 60,1042,1333,2794, 264,3177,4014,
1628, 258,3712, 7,4464,1176,1043,1778, 683, 114,1975, 78,1492, 383,1886, 510,
386, 645,5291,2891,2069,3305,4138,3867,2939,2603,2493,1935,1066,1848,3588,1015,
1282,1289,4609, 697,1453,3044,2666,3611,1856,2412, 54, 719,1330, 568,3778,2459,
1748, 788, 492, 551,1191,1000, 488,3394,3763, 282,1799, 348,2016,1523,3155,2390,
1049, 382,2019,1788,1170, 729,2968,3523, 897,3926,2785,2938,3292, 350,2319,3238,
1718,1717,2655,3453,3143,4465, 161,2889,2980,2009,1421, 56,1908,1640,2387,2232,
1917,1874,2477,4921, 148, 83,3438, 592,4245,2882,1822,1055, 741, 115,1496,1624,
381,1638,4592,1020, 516,3214, 458, 947,4575,1432, 211,1514,2926,1865,2142, 189,
852,1221,1400,1486, 882,2299,4036, 351, 28,1122, 700,6479,6480,6481,6482,6483, # last 512
#Everything below is of no interest for detection purpose
5508,6484,3900,3414,3974,4441,4024,3537,4037,5628,5099,3633,6485,3148,6486,3636,
5509,3257,5510,5973,5445,5872,4941,4403,3174,4627,5873,6276,2286,4230,5446,5874,
5122,6102,6103,4162,5447,5123,5323,4849,6277,3980,3851,5066,4246,5774,5067,6278,
3001,2807,5695,3346,5775,5974,5158,5448,6487,5975,5976,5776,3598,6279,5696,4806,
4211,4154,6280,6488,6489,6490,6281,4212,5037,3374,4171,6491,4562,4807,4722,4827,
5977,6104,4532,4079,5159,5324,5160,4404,3858,5359,5875,3975,4288,4610,3486,4512,
5325,3893,5360,6282,6283,5560,2522,4231,5978,5186,5449,2569,3878,6284,5401,3578,
4415,6285,4656,5124,5979,2506,4247,4449,3219,3417,4334,4969,4329,6492,4576,4828,
4172,4416,4829,5402,6286,3927,3852,5361,4369,4830,4477,4867,5876,4173,6493,6105,
4657,6287,6106,5877,5450,6494,4155,4868,5451,3700,5629,4384,6288,6289,5878,3189,
4881,6107,6290,6495,4513,6496,4692,4515,4723,5100,3356,6497,6291,3810,4080,5561,
3570,4430,5980,6498,4355,5697,6499,4724,6108,6109,3764,4050,5038,5879,4093,3226,
6292,5068,5217,4693,3342,5630,3504,4831,4377,4466,4309,5698,4431,5777,6293,5778,
4272,3706,6110,5326,3752,4676,5327,4273,5403,4767,5631,6500,5699,5880,3475,5039,
6294,5562,5125,4348,4301,4482,4068,5126,4593,5700,3380,3462,5981,5563,3824,5404,
4970,5511,3825,4738,6295,6501,5452,4516,6111,5881,5564,6502,6296,5982,6503,4213,
4163,3454,6504,6112,4009,4450,6113,4658,6297,6114,3035,6505,6115,3995,4904,4739,
4563,4942,4110,5040,3661,3928,5362,3674,6506,5292,3612,4791,5565,4149,5983,5328,
5259,5021,4725,4577,4564,4517,4364,6298,5405,4578,5260,4594,4156,4157,5453,3592,
3491,6507,5127,5512,4709,4922,5984,5701,4726,4289,6508,4015,6116,5128,4628,3424,
4241,5779,6299,4905,6509,6510,5454,5702,5780,6300,4365,4923,3971,6511,5161,3270,
3158,5985,4100, 867,5129,5703,6117,5363,3695,3301,5513,4467,6118,6512,5455,4232,
4242,4629,6513,3959,4478,6514,5514,5329,5986,4850,5162,5566,3846,4694,6119,5456,
4869,5781,3779,6301,5704,5987,5515,4710,6302,5882,6120,4392,5364,5705,6515,6121,
6516,6517,3736,5988,5457,5989,4695,2457,5883,4551,5782,6303,6304,6305,5130,4971,
6122,5163,6123,4870,3263,5365,3150,4871,6518,6306,5783,5069,5706,3513,3498,4409,
5330,5632,5366,5458,5459,3991,5990,4502,3324,5991,5784,3696,4518,5633,4119,6519,
4630,5634,4417,5707,4832,5992,3418,6124,5993,5567,4768,5218,6520,4595,3458,5367,
6125,5635,6126,4202,6521,4740,4924,6307,3981,4069,4385,6308,3883,2675,4051,3834,
4302,4483,5568,5994,4972,4101,5368,6309,5164,5884,3922,6127,6522,6523,5261,5460,
5187,4164,5219,3538,5516,4111,3524,5995,6310,6311,5369,3181,3386,2484,5188,3464,
5569,3627,5708,6524,5406,5165,4677,4492,6312,4872,4851,5885,4468,5996,6313,5709,
5710,6128,2470,5886,6314,5293,4882,5785,3325,5461,5101,6129,5711,5786,6525,4906,
6526,6527,4418,5887,5712,4808,2907,3701,5713,5888,6528,3765,5636,5331,6529,6530,
3593,5889,3637,4943,3692,5714,5787,4925,6315,6130,5462,4405,6131,6132,6316,5262,
6531,6532,5715,3859,5716,5070,4696,5102,3929,5788,3987,4792,5997,6533,6534,3920,
4809,5000,5998,6535,2974,5370,6317,5189,5263,5717,3826,6536,3953,5001,4883,3190,
5463,5890,4973,5999,4741,6133,6134,3607,5570,6000,4711,3362,3630,4552,5041,6318,
6001,2950,2953,5637,4646,5371,4944,6002,2044,4120,3429,6319,6537,5103,4833,6538,
6539,4884,4647,3884,6003,6004,4758,3835,5220,5789,4565,5407,6540,6135,5294,4697,
4852,6320,6321,3206,4907,6541,6322,4945,6542,6136,6543,6323,6005,4631,3519,6544,
5891,6545,5464,3784,5221,6546,5571,4659,6547,6324,6137,5190,6548,3853,6549,4016,
4834,3954,6138,5332,3827,4017,3210,3546,4469,5408,5718,3505,4648,5790,5131,5638,
5791,5465,4727,4318,6325,6326,5792,4553,4010,4698,3439,4974,3638,4335,3085,6006,
5104,5042,5166,5892,5572,6327,4356,4519,5222,5573,5333,5793,5043,6550,5639,5071,
4503,6328,6139,6551,6140,3914,3901,5372,6007,5640,4728,4793,3976,3836,4885,6552,
4127,6553,4451,4102,5002,6554,3686,5105,6555,5191,5072,5295,4611,5794,5296,6556,
5893,5264,5894,4975,5466,5265,4699,4976,4370,4056,3492,5044,4886,6557,5795,4432,
4769,4357,5467,3940,4660,4290,6141,4484,4770,4661,3992,6329,4025,4662,5022,4632,
4835,4070,5297,4663,4596,5574,5132,5409,5895,6142,4504,5192,4664,5796,5896,3885,
5575,5797,5023,4810,5798,3732,5223,4712,5298,4084,5334,5468,6143,4052,4053,4336,
4977,4794,6558,5335,4908,5576,5224,4233,5024,4128,5469,5225,4873,6008,5045,4729,
4742,4633,3675,4597,6559,5897,5133,5577,5003,5641,5719,6330,6560,3017,2382,3854,
4406,4811,6331,4393,3964,4946,6561,2420,3722,6562,4926,4378,3247,1736,4442,6332,
5134,6333,5226,3996,2918,5470,4319,4003,4598,4743,4744,4485,3785,3902,5167,5004,
5373,4394,5898,6144,4874,1793,3997,6334,4085,4214,5106,5642,4909,5799,6009,4419,
4189,3330,5899,4165,4420,5299,5720,5227,3347,6145,4081,6335,2876,3930,6146,3293,
3786,3910,3998,5900,5300,5578,2840,6563,5901,5579,6147,3531,5374,6564,6565,5580,
4759,5375,6566,6148,3559,5643,6336,6010,5517,6337,6338,5721,5902,3873,6011,6339,
6567,5518,3868,3649,5722,6568,4771,4947,6569,6149,4812,6570,2853,5471,6340,6341,
5644,4795,6342,6012,5723,6343,5724,6013,4349,6344,3160,6150,5193,4599,4514,4493,
5168,4320,6345,4927,3666,4745,5169,5903,5005,4928,6346,5725,6014,4730,4203,5046,
4948,3395,5170,6015,4150,6016,5726,5519,6347,5047,3550,6151,6348,4197,4310,5904,
6571,5581,2965,6152,4978,3960,4291,5135,6572,5301,5727,4129,4026,5905,4853,5728,
5472,6153,6349,4533,2700,4505,5336,4678,3583,5073,2994,4486,3043,4554,5520,6350,
6017,5800,4487,6351,3931,4103,5376,6352,4011,4321,4311,4190,5136,6018,3988,3233,
4350,5906,5645,4198,6573,5107,3432,4191,3435,5582,6574,4139,5410,6353,5411,3944,
5583,5074,3198,6575,6354,4358,6576,5302,4600,5584,5194,5412,6577,6578,5585,5413,
5303,4248,5414,3879,4433,6579,4479,5025,4854,5415,6355,4760,4772,3683,2978,4700,
3797,4452,3965,3932,3721,4910,5801,6580,5195,3551,5907,3221,3471,3029,6019,3999,
5908,5909,5266,5267,3444,3023,3828,3170,4796,5646,4979,4259,6356,5647,5337,3694,
6357,5648,5338,4520,4322,5802,3031,3759,4071,6020,5586,4836,4386,5048,6581,3571,
4679,4174,4949,6154,4813,3787,3402,3822,3958,3215,3552,5268,4387,3933,4950,4359,
6021,5910,5075,3579,6358,4234,4566,5521,6359,3613,5049,6022,5911,3375,3702,3178,
4911,5339,4521,6582,6583,4395,3087,3811,5377,6023,6360,6155,4027,5171,5649,4421,
4249,2804,6584,2270,6585,4000,4235,3045,6156,5137,5729,4140,4312,3886,6361,4330,
6157,4215,6158,3500,3676,4929,4331,3713,4930,5912,4265,3776,3368,5587,4470,4855,
3038,4980,3631,6159,6160,4132,4680,6161,6362,3923,4379,5588,4255,6586,4121,6587,
6363,4649,6364,3288,4773,4774,6162,6024,6365,3543,6588,4274,3107,3737,5050,5803,
4797,4522,5589,5051,5730,3714,4887,5378,4001,4523,6163,5026,5522,4701,4175,2791,
3760,6589,5473,4224,4133,3847,4814,4815,4775,3259,5416,6590,2738,6164,6025,5304,
3733,5076,5650,4816,5590,6591,6165,6592,3934,5269,6593,3396,5340,6594,5804,3445,
3602,4042,4488,5731,5732,3525,5591,4601,5196,6166,6026,5172,3642,4612,3202,4506,
4798,6366,3818,5108,4303,5138,5139,4776,3332,4304,2915,3415,4434,5077,5109,4856,
2879,5305,4817,6595,5913,3104,3144,3903,4634,5341,3133,5110,5651,5805,6167,4057,
5592,2945,4371,5593,6596,3474,4182,6367,6597,6168,4507,4279,6598,2822,6599,4777,
4713,5594,3829,6169,3887,5417,6170,3653,5474,6368,4216,2971,5228,3790,4579,6369,
5733,6600,6601,4951,4746,4555,6602,5418,5475,6027,3400,4665,5806,6171,4799,6028,
5052,6172,3343,4800,4747,5006,6370,4556,4217,5476,4396,5229,5379,5477,3839,5914,
5652,5807,4714,3068,4635,5808,6173,5342,4192,5078,5419,5523,5734,6174,4557,6175,
4602,6371,6176,6603,5809,6372,5735,4260,3869,5111,5230,6029,5112,6177,3126,4681,
5524,5915,2706,3563,4748,3130,6178,4018,5525,6604,6605,5478,4012,4837,6606,4534,
4193,5810,4857,3615,5479,6030,4082,3697,3539,4086,5270,3662,4508,4931,5916,4912,
5811,5027,3888,6607,4397,3527,3302,3798,2775,2921,2637,3966,4122,4388,4028,4054,
1633,4858,5079,3024,5007,3982,3412,5736,6608,3426,3236,5595,3030,6179,3427,3336,
3279,3110,6373,3874,3039,5080,5917,5140,4489,3119,6374,5812,3405,4494,6031,4666,
4141,6180,4166,6032,5813,4981,6609,5081,4422,4982,4112,3915,5653,3296,3983,6375,
4266,4410,5654,6610,6181,3436,5082,6611,5380,6033,3819,5596,4535,5231,5306,5113,
6612,4952,5918,4275,3113,6613,6376,6182,6183,5814,3073,4731,4838,5008,3831,6614,
4888,3090,3848,4280,5526,5232,3014,5655,5009,5737,5420,5527,6615,5815,5343,5173,
5381,4818,6616,3151,4953,6617,5738,2796,3204,4360,2989,4281,5739,5174,5421,5197,
3132,5141,3849,5142,5528,5083,3799,3904,4839,5480,2880,4495,3448,6377,6184,5271,
5919,3771,3193,6034,6035,5920,5010,6036,5597,6037,6378,6038,3106,5422,6618,5423,
5424,4142,6619,4889,5084,4890,4313,5740,6620,3437,5175,5307,5816,4199,5198,5529,
5817,5199,5656,4913,5028,5344,3850,6185,2955,5272,5011,5818,4567,4580,5029,5921,
3616,5233,6621,6622,6186,4176,6039,6379,6380,3352,5200,5273,2908,5598,5234,3837,
5308,6623,6624,5819,4496,4323,5309,5201,6625,6626,4983,3194,3838,4167,5530,5922,
5274,6381,6382,3860,3861,5599,3333,4292,4509,6383,3553,5481,5820,5531,4778,6187,
3955,3956,4324,4389,4218,3945,4325,3397,2681,5923,4779,5085,4019,5482,4891,5382,
5383,6040,4682,3425,5275,4094,6627,5310,3015,5483,5657,4398,5924,3168,4819,6628,
5925,6629,5532,4932,4613,6041,6630,4636,6384,4780,4204,5658,4423,5821,3989,4683,
5822,6385,4954,6631,5345,6188,5425,5012,5384,3894,6386,4490,4104,6632,5741,5053,
6633,5823,5926,5659,5660,5927,6634,5235,5742,5824,4840,4933,4820,6387,4859,5928,
4955,6388,4143,3584,5825,5346,5013,6635,5661,6389,5014,5484,5743,4337,5176,5662,
6390,2836,6391,3268,6392,6636,6042,5236,6637,4158,6638,5744,5663,4471,5347,3663,
4123,5143,4293,3895,6639,6640,5311,5929,5826,3800,6189,6393,6190,5664,5348,3554,
3594,4749,4603,6641,5385,4801,6043,5827,4183,6642,5312,5426,4761,6394,5665,6191,
4715,2669,6643,6644,5533,3185,5427,5086,5930,5931,5386,6192,6044,6645,4781,4013,
5745,4282,4435,5534,4390,4267,6045,5746,4984,6046,2743,6193,3501,4087,5485,5932,
5428,4184,4095,5747,4061,5054,3058,3862,5933,5600,6646,5144,3618,6395,3131,5055,
5313,6396,4650,4956,3855,6194,3896,5202,4985,4029,4225,6195,6647,5828,5486,5829,
3589,3002,6648,6397,4782,5276,6649,6196,6650,4105,3803,4043,5237,5830,6398,4096,
3643,6399,3528,6651,4453,3315,4637,6652,3984,6197,5535,3182,3339,6653,3096,2660,
6400,6654,3449,5934,4250,4236,6047,6401,5831,6655,5487,3753,4062,5832,6198,6199,
6656,3766,6657,3403,4667,6048,6658,4338,2897,5833,3880,2797,3780,4326,6659,5748,
5015,6660,5387,4351,5601,4411,6661,3654,4424,5935,4339,4072,5277,4568,5536,6402,
6662,5238,6663,5349,5203,6200,5204,6201,5145,4536,5016,5056,4762,5834,4399,4957,
6202,6403,5666,5749,6664,4340,6665,5936,5177,5667,6666,6667,3459,4668,6404,6668,
6669,4543,6203,6670,4276,6405,4480,5537,6671,4614,5205,5668,6672,3348,2193,4763,
6406,6204,5937,5602,4177,5669,3419,6673,4020,6205,4443,4569,5388,3715,3639,6407,
6049,4058,6206,6674,5938,4544,6050,4185,4294,4841,4651,4615,5488,6207,6408,6051,
5178,3241,3509,5835,6208,4958,5836,4341,5489,5278,6209,2823,5538,5350,5206,5429,
6675,4638,4875,4073,3516,4684,4914,4860,5939,5603,5389,6052,5057,3237,5490,3791,
6676,6409,6677,4821,4915,4106,5351,5058,4243,5539,4244,5604,4842,4916,5239,3028,
3716,5837,5114,5605,5390,5940,5430,6210,4332,6678,5540,4732,3667,3840,6053,4305,
3408,5670,5541,6410,2744,5240,5750,6679,3234,5606,6680,5607,5671,3608,4283,4159,
4400,5352,4783,6681,6411,6682,4491,4802,6211,6412,5941,6413,6414,5542,5751,6683,
4669,3734,5942,6684,6415,5943,5059,3328,4670,4144,4268,6685,6686,6687,6688,4372,
3603,6689,5944,5491,4373,3440,6416,5543,4784,4822,5608,3792,4616,5838,5672,3514,
5391,6417,4892,6690,4639,6691,6054,5673,5839,6055,6692,6056,5392,6212,4038,5544,
5674,4497,6057,6693,5840,4284,5675,4021,4545,5609,6418,4454,6419,6213,4113,4472,
5314,3738,5087,5279,4074,5610,4959,4063,3179,4750,6058,6420,6214,3476,4498,4716,
5431,4960,4685,6215,5241,6694,6421,6216,6695,5841,5945,6422,3748,5946,5179,3905,
5752,5545,5947,4374,6217,4455,6423,4412,6218,4803,5353,6696,3832,5280,6219,4327,
4702,6220,6221,6059,4652,5432,6424,3749,4751,6425,5753,4986,5393,4917,5948,5030,
5754,4861,4733,6426,4703,6697,6222,4671,5949,4546,4961,5180,6223,5031,3316,5281,
6698,4862,4295,4934,5207,3644,6427,5842,5950,6428,6429,4570,5843,5282,6430,6224,
5088,3239,6060,6699,5844,5755,6061,6431,2701,5546,6432,5115,5676,4039,3993,3327,
4752,4425,5315,6433,3941,6434,5677,4617,4604,3074,4581,6225,5433,6435,6226,6062,
4823,5756,5116,6227,3717,5678,4717,5845,6436,5679,5846,6063,5847,6064,3977,3354,
6437,3863,5117,6228,5547,5394,4499,4524,6229,4605,6230,4306,4500,6700,5951,6065,
3693,5952,5089,4366,4918,6701,6231,5548,6232,6702,6438,4704,5434,6703,6704,5953,
4168,6705,5680,3420,6706,5242,4407,6066,3812,5757,5090,5954,4672,4525,3481,5681,
4618,5395,5354,5316,5955,6439,4962,6707,4526,6440,3465,4673,6067,6441,5682,6708,
5435,5492,5758,5683,4619,4571,4674,4804,4893,4686,5493,4753,6233,6068,4269,6442,
6234,5032,4705,5146,5243,5208,5848,6235,6443,4963,5033,4640,4226,6236,5849,3387,
6444,6445,4436,4437,5850,4843,5494,4785,4894,6709,4361,6710,5091,5956,3331,6237,
4987,5549,6069,6711,4342,3517,4473,5317,6070,6712,6071,4706,6446,5017,5355,6713,
6714,4988,5436,6447,4734,5759,6715,4735,4547,4456,4754,6448,5851,6449,6450,3547,
5852,5318,6451,6452,5092,4205,6716,6238,4620,4219,5611,6239,6072,4481,5760,5957,
5958,4059,6240,6453,4227,4537,6241,5761,4030,4186,5244,5209,3761,4457,4876,3337,
5495,5181,6242,5959,5319,5612,5684,5853,3493,5854,6073,4169,5613,5147,4895,6074,
5210,6717,5182,6718,3830,6243,2798,3841,6075,6244,5855,5614,3604,4606,5496,5685,
5118,5356,6719,6454,5960,5357,5961,6720,4145,3935,4621,5119,5962,4261,6721,6455,
4786,5963,4375,4582,6245,6246,6247,6076,5437,4877,5856,3376,4380,6248,4160,6722,
5148,6456,5211,6457,6723,4718,6458,6724,6249,5358,4044,3297,6459,6250,5857,5615,
5497,5245,6460,5498,6725,6251,6252,5550,3793,5499,2959,5396,6461,6462,4572,5093,
5500,5964,3806,4146,6463,4426,5762,5858,6077,6253,4755,3967,4220,5965,6254,4989,
5501,6464,4352,6726,6078,4764,2290,5246,3906,5438,5283,3767,4964,2861,5763,5094,
6255,6256,4622,5616,5859,5860,4707,6727,4285,4708,4824,5617,6257,5551,4787,5212,
4965,4935,4687,6465,6728,6466,5686,6079,3494,4413,2995,5247,5966,5618,6729,5967,
5764,5765,5687,5502,6730,6731,6080,5397,6467,4990,6258,6732,4538,5060,5619,6733,
4719,5688,5439,5018,5149,5284,5503,6734,6081,4607,6259,5120,3645,5861,4583,6260,
4584,4675,5620,4098,5440,6261,4863,2379,3306,4585,5552,5689,4586,5285,6735,4864,
6736,5286,6082,6737,4623,3010,4788,4381,4558,5621,4587,4896,3698,3161,5248,4353,
4045,6262,3754,5183,4588,6738,6263,6739,6740,5622,3936,6741,6468,6742,6264,5095,
6469,4991,5968,6743,4992,6744,6083,4897,6745,4256,5766,4307,3108,3968,4444,5287,
3889,4343,6084,4510,6085,4559,6086,4898,5969,6746,5623,5061,4919,5249,5250,5504,
5441,6265,5320,4878,3242,5862,5251,3428,6087,6747,4237,5624,5442,6266,5553,4539,
6748,2585,3533,5398,4262,6088,5150,4736,4438,6089,6267,5505,4966,6749,6268,6750,
6269,5288,5554,3650,6090,6091,4624,6092,5690,6751,5863,4270,5691,4277,5555,5864,
6752,5692,4720,4865,6470,5151,4688,4825,6753,3094,6754,6471,3235,4653,6755,5213,
5399,6756,3201,4589,5865,4967,6472,5866,6473,5019,3016,6757,5321,4756,3957,4573,
6093,4993,5767,4721,6474,6758,5625,6759,4458,6475,6270,6760,5556,4994,5214,5252,
6271,3875,5768,6094,5034,5506,4376,5769,6761,2120,6476,5253,5770,6762,5771,5970,
3990,5971,5557,5558,5772,6477,6095,2787,4641,5972,5121,6096,6097,6272,6763,3703,
5867,5507,6273,4206,6274,4789,6098,6764,3619,3646,3833,3804,2394,3788,4936,3978,
4866,4899,6099,6100,5559,6478,6765,3599,5868,6101,5869,5870,6275,6766,4527,6767)
# flake8: noqa
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
18553,
16909,
4750,
28914,
590,
1202,
4528,
1817,
199,
3,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
687,
394,
90,
1822,
2766,
199,
199,
3,
10574,
221,
10541,
378,
14,
1965,
221,
1553,
378,
14,
1965,
199,
3,
6619,
10541,
378,
14,
2942,
221,
1553,
378,
14,
969,
199,
3,
18427,
10541,
378,
14,
2905,
221,
1553,
378,
14,
1690,
199,
3,
1227,
14408,
10541,
413,
14,
383,
221,
1553,
378,
14,
996,
199,
3,
199,
3,
473,
21245,
11839,
820,
32736,
275,
378,
14,
1965,
8312,
7985,
17,
13,
16,
14,
1965,
8312,
9,
275,
650,
14,
1965,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
1401,
1229,
446,
10574,
9,
275,
378,
14,
10823,
199,
3,
199,
3,
29267,
11839,
820,
32736,
3595,
5661,
5,
402,
473,
21245,
1373,
12,
5139,
8298,
10948,
626,
820,
4564,
199,
199,
6487,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
378,
14,
25,
199,
199,
6487,
16909,
63,
8723,
63,
4305,
275,
650,
19036,
199,
199,
6487,
16909,
18139,
13875,
4738,
275,
334,
199,
975,
3172,
12,
9720,
25,
12,
1079,
2824,
12,
1789,
772,
12,
1355,
1194,
12,
19,
11369,
12,
10034,
16,
12,
1355,
2025,
12,
1196,
966,
12,
1082,
2766,
12,
1479,
3328,
12,
1046,
845,
12,
1046,
1046,
12,
959,
2819,
12,
19,
12632,
12,
1081,
1717,
12,
199,
10008,
17,
12,
18565,
12,
821,
2010,
12,
841,
1965,
12,
1196,
845,
12,
1749,
2766,
12,
19,
12438,
12,
841,
2167,
12,
13344,
16,
12,
1167,
1717,
12,
1398,
1272,
12,
1398,
2417,
12,
1276,
1257,
12,
18,
8557,
12,
1355,
2976,
12,
8188,
18,
12,
199,
1081,
966,
12,
10300,
25,
12,
20,
10744,
12,
1749,
2760,
12,
1479,
2277,
12,
1367,
1479,
12,
1398,
1602,
12,
1398,
1367,
12,
1079,
1965,
12,
5188,
24,
12,
959,
1079,
12,
1276,
2720,
12,
959,
1299,
12,
969,
2466,
12,
1651,
1165,
12,
1082,
1643,
12,
199,
499,
1887,
12,
2167,
1299,
12,
1196,
2466,
12,
1085,
2898,
12,
6686,
23,
12,
8881,
20,
12,
959,
2835,
12,
1085,
969,
12,
650,
2010,
12,
845,
1342,
12,
1276,
2710,
12,
4893,
20,
12,
1046,
2976,
12,
20,
16042,
12,
1081,
2322,
12,
1227,
2760,
12,
199,
975,
1344,
12,
2192,
713,
12,
10523,
25,
12,
713,
1184,
12,
1749,
2481,
12,
31074,
12,
8001,
23,
12,
1216,
2259,
12,
713,
2710,
12,
8988,
17,
12,
1227,
969,
12,
413,
2426,
12,
1082,
1138,
12,
969,
1822,
12,
1695,
1400,
12,
1703,
1165,
12,
199,
1196,
1046,
12,
1194,
1651,
12,
9408,
18,
12,
9687,
19,
12,
1465,
708,
12,
8533,
17,
12,
821,
2789,
12,
9408,
24,
12,
1276,
1272,
12,
1355,
2466,
12,
969,
1887,
12,
650,
1299,
12,
1216,
2905,
12,
1165,
3328,
12,
969,
2259,
12,
1276,
2426,
12,
199,
413,
2528,
12,
975,
1555,
12,
1046,
1355,
12,
1520,
1703,
12,
1046,
1427,
12,
221,
8155,
12,
713,
708,
12,
1398,
821,
12,
1081,
1822,
12,
969,
1299,
12,
713,
1887,
12,
1196,
2953,
12,
975,
1965,
12,
1398,
2259,
12,
413,
2869,
12,
1046,
1272,
12,
199,
6094,
21,
12,
969,
2528,
12,
20,
16344,
12,
1749,
1194,
12,
20,
11700,
12,
650,
2426,
12,
19,
10642,
12,
1602,
1427,
12,
650,
709,
12,
713,
2322,
12,
1651,
1400,
12,
221,
10045,
12,
708,
2426,
12,
1465,
1398,
12,
1276,
1082,
12,
1276,
2194,
12,
199,
9803,
24,
12,
708,
2905,
12,
1082,
1272,
12,
1167,
2259,
12,
30209,
12,
499,
1196,
12,
19,
8557,
12,
1695,
772,
12,
1167,
1643,
12,
1165,
1349,
12,
1602,
614,
12,
9963,
19,
12,
4893,
16,
12,
708,
1876,
12,
21,
11024,
12,
1695,
2481,
12,
199,
1216,
2869,
12,
19,
10753,
12,
713,
1602,
12,
20,
12140,
12,
1085,
2720,
12,
650,
772,
12,
1079,
1020,
12,
1046,
2167,
12,
1789,
969,
12,
845,
1257,
12,
1344,
1229,
12,
1081,
2333,
12,
959,
2789,
12,
1520,
1046,
12,
1194,
1196,
12,
1216,
2976,
12,
199,
959,
1602,
12,
650,
1344,
12,
1401,
2333,
12,
1789,
1257,
12,
1196,
2528,
12,
12641,
21,
12,
1749,
1400,
12,
499,
1257,
12,
1194,
821,
12,
20,
16244,
12,
413,
2658,
12,
1465,
1427,
12,
708,
2819,
12,
23792,
12,
20,
12615,
12,
7842,
21,
12,
199,
975,
1299,
12,
8276,
22,
12,
1079,
1602,
12,
709,
1355,
12,
12383,
16,
12,
1520,
1344,
12,
845,
1138,
12,
8425,
25,
12,
1194,
2824,
12,
10008,
24,
12,
6886,
20,
12,
1081,
821,
12,
959,
2182,
12,
32132,
12,
1079,
2564,
12,
1082,
1690,
12,
199,
1749,
1465,
12,
969,
1276,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
18553,
16909,
4750,
28914,
590,
1202,
4528,
1817,
199,
3,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
687,
394,
90,
1822,
2766,
199,
199,
3,
10574,
221,
10541,
378,
14,
1965,
221,
1553,
378,
14,
1965,
199,
3,
6619,
10541,
378,
14,
2942,
221,
1553,
378,
14,
969,
199,
3,
18427,
10541,
378,
14,
2905,
221,
1553,
378,
14,
1690,
199,
3,
1227,
14408,
10541,
413,
14,
383,
221,
1553,
378,
14,
996,
199,
3,
199,
3,
473,
21245,
11839,
820,
32736,
275,
378,
14,
1965,
8312,
7985,
17,
13,
16,
14,
1965,
8312,
9,
275,
650,
14,
1965,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
1401,
1229,
446,
10574,
9,
275,
378,
14,
10823,
199,
3,
199,
3,
29267,
11839,
820,
32736,
3595,
5661,
5,
402,
473,
21245,
1373,
12,
5139,
8298,
10948,
626,
820,
4564,
199,
199,
6487,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
378,
14,
25,
199,
199,
6487,
16909,
63,
8723,
63,
4305,
275,
650,
19036,
199,
199,
6487,
16909,
18139,
13875,
4738,
275,
334,
199,
975,
3172,
12,
9720,
25,
12,
1079,
2824,
12,
1789,
772,
12,
1355,
1194,
12,
19,
11369,
12,
10034,
16,
12,
1355,
2025,
12,
1196,
966,
12,
1082,
2766,
12,
1479,
3328,
12,
1046,
845,
12,
1046,
1046,
12,
959,
2819,
12,
19,
12632,
12,
1081,
1717,
12,
199,
10008,
17,
12,
18565,
12,
821,
2010,
12,
841,
1965,
12,
1196,
845,
12,
1749,
2766,
12,
19,
12438,
12,
841,
2167,
12,
13344,
16,
12,
1167,
1717,
12,
1398,
1272,
12,
1398,
2417,
12,
1276,
1257,
12,
18,
8557,
12,
1355,
2976,
12,
8188,
18,
12,
199,
1081,
966,
12,
10300,
25,
12,
20,
10744,
12,
1749,
2760,
12,
1479,
2277,
12,
1367,
1479,
12,
1398,
1602,
12,
1398,
1367,
12,
1079,
1965,
12,
5188,
24,
12,
959,
1079,
12,
1276,
2720,
12,
959,
1299,
12,
969,
2466,
12,
1651,
1165,
12,
1082,
1643,
12,
199,
499,
1887,
12,
2167,
1299,
12,
1196,
2466,
12,
1085,
2898,
12,
6686,
23,
12,
8881,
20,
12,
959,
2835,
12,
1085,
969,
12,
650,
2010,
12,
845,
1342,
12,
1276,
2710,
12,
4893,
20,
12,
1046,
2976,
12,
20,
16042,
12,
1081,
2322,
12,
1227,
2760,
12,
199,
975,
1344,
12,
2192,
713,
12,
10523,
25,
12,
713,
1184,
12,
1749,
2481,
12,
31074,
12,
8001,
23,
12,
1216,
2259,
12,
713,
2710,
12,
8988,
17,
12,
1227,
969,
12,
413,
2426,
12,
1082,
1138,
12,
969,
1822,
12,
1695,
1400,
12,
1703,
1165,
12,
199,
1196,
1046,
12,
1194,
1651,
12,
9408,
18,
12,
9687,
19,
12,
1465,
708,
12,
8533,
17,
12,
821,
2789,
12,
9408,
24,
12,
1276,
1272,
12,
1355,
2466,
12,
969,
1887,
12,
650,
1299,
12,
1216,
2905,
12,
1165,
3328,
12,
969,
2259,
12,
1276,
2426,
12,
199,
413,
2528,
12,
975,
1555,
12,
1046,
1355,
12,
1520,
1703,
12,
1046,
1427,
12,
221,
8155,
12,
713,
708,
12,
1398,
821,
12,
1081,
1822,
12,
969,
1299,
12,
713,
1887,
12,
1196,
2953,
12,
975,
1965,
12,
1398,
2259,
12,
413,
2869,
12,
1046,
1272,
12,
199,
6094,
21,
12,
969,
2528,
12,
20,
16344,
12,
1749,
1194,
12,
20,
11700,
12,
650,
2426,
12,
19,
10642,
12,
1602,
1427,
12,
650,
709,
12,
713,
2322,
12,
1651,
1400,
12,
221,
10045,
12,
708,
2426,
12,
1465,
1398,
12,
1276,
1082,
12,
1276,
2194,
12,
199,
9803,
24,
12,
708,
2905,
12,
1082,
1272,
12,
1167,
2259,
12,
30209,
12,
499,
1196,
12,
19,
8557,
12,
1695,
772,
12,
1167,
1643,
12,
1165,
1349,
12,
1602,
614,
12,
9963,
19,
12,
4893,
16,
12,
708,
1876,
12,
21,
11024,
12,
1695,
2481,
12,
199,
1216,
2869,
12,
19,
10753,
12,
713,
1602,
12,
20,
12140,
12,
1085,
2720,
12,
650,
772,
12,
1079,
1020,
12,
1046,
2167,
12,
1789,
969,
12,
845,
1257,
12,
1344,
1229,
12,
1081,
2333,
12,
959,
2789,
12,
1520,
1046,
12,
1194,
1196,
12,
1216,
2976,
12,
199,
959,
1602,
12,
650,
1344,
12,
1401,
2333,
12,
1789,
1257,
12,
1196,
2528,
12,
12641,
21,
12,
1749,
1400,
12,
499,
1257,
12,
1194,
821,
12,
20,
16244,
12,
413,
2658,
12,
1465,
1427,
12,
708,
2819,
12,
23792,
12,
20,
12615,
12,
7842,
21,
12,
199,
975,
1299,
12,
8276,
22,
12,
1079,
1602,
12,
709,
1355,
12,
12383,
16,
12,
1520,
1344,
12,
845,
1138,
12,
8425,
25,
12,
1194,
2824,
12,
10008,
24,
12,
6886,
20,
12,
1081,
821,
12,
959,
2182,
12,
32132,
12,
1079,
2564,
12,
1082,
1690,
12,
199,
1749,
1465,
12,
969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
1,
1,
1,
1,
1
] |
8l/beri
|
cheritest/trunk/tests/mem/test_ll_unalign.py
|
2
|
2396
|
#-
# Copyright (c) 2011 Robert N. M. Watson
# All rights reserved.
#
# This software was developed by SRI International and the University of
# Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
# ("CTSRD"), as part of the DARPA CRASH research programme.
#
# @BERI_LICENSE_HEADER_START@
#
# Licensed to BERI Open Systems C.I.C. (BERI) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. BERI licenses this
# file to you under the BERI Hardware-Software License, Version 1.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.beri-open-systems.org/legal/license-1-0.txt
#
# Unless required by applicable law or agreed to in writing, Work 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.
#
# @BERI_LICENSE_HEADER_END@
#
from beritest_tools import BaseBERITestCase
from nose.plugins.attrib import attr
class test_ll_unalign(BaseBERITestCase):
@attr('llsc')
def test_epc(self):
self.assertRegisterEqual(self.MIPS.a0, self.MIPS.a5, "Unexpected EPC")
@attr('llsc')
def test_returned(self):
self.assertRegisterEqual(self.MIPS.a1, 1, "flow broken by ll instruction")
@attr('llsc')
def test_handled(self):
self.assertRegisterEqual(self.MIPS.a2, 1, "ll exception handler not run")
@attr('llsc')
def test_exl_in_handler(self):
self.assertRegisterEqual((self.MIPS.a3 >> 1) & 0x1, 1, "EXL not set in exception handler")
@attr('llsc')
def test_badvaddr(self):
self.assertRegisterEqual(self.MIPS.a7, self.MIPS.s0, "BadVAddr equal to Unaligned Address")
@attr('llsc')
def test_cause_bd(self):
self.assertRegisterEqual((self.MIPS.a4 >> 31) & 0x1, 0, "Branch delay (BD) flag improperly set")
@attr('llsc')
def test_cause_code(self):
self.assertRegisterEqual((self.MIPS.a4 >> 2) & 0x1f, 4, "Code not set to AdEl")
@attr('llsc')
def test_not_exl_after_handler(self):
self.assertRegisterEqual((self.MIPS.a6 >> 1) & 0x1, 0, "EXL still set after ERET")
|
apache-2.0
|
[
3,
13,
199,
3,
1898,
334,
67,
9,
7760,
6848,
12504,
653,
14,
603,
14,
644,
292,
834,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
1990,
477,
27813,
701,
428,
6129,
28220,
436,
314,
15904,
402,
199,
3,
445,
455,
9528,
3599,
2699,
16871,
31671,
1334,
577,
689,
8470,
15,
5699,
2431,
16077,
481,
33,
1555,
1400,
13,
709,
13,
35,
13,
996,
1401,
199,
3,
1689,
1028,
5943,
36,
1288,
465,
1777,
402,
314,
577,
689,
8470,
17101,
8100,
295,
1733,
2240,
278,
14,
199,
3,
199,
3,
768,
12003,
41,
63,
3961,
63,
7311,
63,
7363,
32,
199,
3,
199,
3,
3909,
370,
699,
540,
41,
3232,
15285,
445,
14,
41,
14,
35,
14,
334,
12003,
41,
9,
1334,
1373,
503,
1655,
11615,
199,
3,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
642,
1736,
367,
199,
3,
4722,
2556,
12602,
4248,
12715,
14,
221,
699,
540,
41,
12378,
642,
199,
3,
570,
370,
1265,
1334,
314,
699,
540,
41,
22825,
1068,
13,
10337,
844,
12,
3394,
413,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
199,
3,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
26,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
605,
73,
13,
1490,
13,
19135,
14,
1308,
15,
9666,
15,
1682,
13,
17,
13,
16,
14,
2424,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
9361,
1854,
199,
3,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
199,
3,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
768,
12003,
41,
63,
3961,
63,
7311,
63,
3902,
32,
199,
3,
199,
199,
504,
330,
281,
73,
396,
63,
2537,
492,
3523,
12003,
649,
27309,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
533,
511,
63,
914,
63,
324,
5743,
8,
1563,
12003,
649,
27309,
304,
272,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
1545,
67,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
16,
12,
291,
14,
45,
12346,
14,
65,
21,
12,
298,
8708,
662,
4222,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
19065,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
17,
12,
413,
12,
298,
1659,
10529,
701,
18338,
16329,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
11217,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
18,
12,
413,
12,
298,
914,
1919,
3016,
440,
1255,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
476,
76,
63,
262,
63,
2232,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
19,
4331,
413,
9,
1253,
378,
88,
17,
12,
413,
12,
298,
1438,
44,
440,
663,
315,
1919,
3016,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
4087,
86,
2697,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
23,
12,
291,
14,
45,
12346,
14,
83,
16,
12,
298,
5725,
54,
11404,
4472,
370,
1910,
19175,
9906,
531,
5493,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
2651,
63,
3691,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
20,
4331,
7105,
9,
1253,
378,
88,
17,
12,
378,
12,
298,
12526,
7339,
334,
11156,
9,
3305,
1742,
10567,
663,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
2651,
63,
600,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
20,
4331,
499,
9,
1253,
378,
88,
17,
70,
12,
841,
12,
298,
3034,
440,
663,
370,
4431,
10420,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
1397,
63,
476,
76,
63,
4399,
63,
2232,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
22,
4331,
413,
9,
1253,
378,
88,
17,
12,
378,
12,
298,
1438,
44,
5139,
663,
2410,
221,
540,
775,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13,
199,
3,
1898,
334,
67,
9,
7760,
6848,
12504,
653,
14,
603,
14,
644,
292,
834,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
1990,
477,
27813,
701,
428,
6129,
28220,
436,
314,
15904,
402,
199,
3,
445,
455,
9528,
3599,
2699,
16871,
31671,
1334,
577,
689,
8470,
15,
5699,
2431,
16077,
481,
33,
1555,
1400,
13,
709,
13,
35,
13,
996,
1401,
199,
3,
1689,
1028,
5943,
36,
1288,
465,
1777,
402,
314,
577,
689,
8470,
17101,
8100,
295,
1733,
2240,
278,
14,
199,
3,
199,
3,
768,
12003,
41,
63,
3961,
63,
7311,
63,
7363,
32,
199,
3,
199,
3,
3909,
370,
699,
540,
41,
3232,
15285,
445,
14,
41,
14,
35,
14,
334,
12003,
41,
9,
1334,
1373,
503,
1655,
11615,
199,
3,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
642,
1736,
367,
199,
3,
4722,
2556,
12602,
4248,
12715,
14,
221,
699,
540,
41,
12378,
642,
199,
3,
570,
370,
1265,
1334,
314,
699,
540,
41,
22825,
1068,
13,
10337,
844,
12,
3394,
413,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
199,
3,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
26,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
605,
73,
13,
1490,
13,
19135,
14,
1308,
15,
9666,
15,
1682,
13,
17,
13,
16,
14,
2424,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
9361,
1854,
199,
3,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
199,
3,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
768,
12003,
41,
63,
3961,
63,
7311,
63,
3902,
32,
199,
3,
199,
199,
504,
330,
281,
73,
396,
63,
2537,
492,
3523,
12003,
649,
27309,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
533,
511,
63,
914,
63,
324,
5743,
8,
1563,
12003,
649,
27309,
304,
272,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
1545,
67,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
16,
12,
291,
14,
45,
12346,
14,
65,
21,
12,
298,
8708,
662,
4222,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
19065,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
17,
12,
413,
12,
298,
1659,
10529,
701,
18338,
16329,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
11217,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
18,
12,
413,
12,
298,
914,
1919,
3016,
440,
1255,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
476,
76,
63,
262,
63,
2232,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
19,
4331,
413,
9,
1253,
378,
88,
17,
12,
413,
12,
298,
1438,
44,
440,
663,
315,
1919,
3016,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
4087,
86,
2697,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
8,
277,
14,
45,
12346,
14,
65,
23,
12,
291,
14,
45,
12346,
14,
83,
16,
12,
298,
5725,
54,
11404,
4472,
370,
1910,
19175,
9906,
531,
5493,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
2651,
63,
3691,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
20,
4331,
7105,
9,
1253,
378,
88,
17,
12,
378,
12,
298,
12526,
7339,
334,
11156,
9,
3305,
1742,
10567,
663,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
2651,
63,
600,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
20,
4331,
499,
9,
1253,
378,
88,
17,
70,
12,
841,
12,
298,
3034,
440,
663,
370,
4431,
10420,
531,
339,
768,
962,
360,
76,
478,
67,
358,
272,
347,
511,
63,
1397,
63,
476,
76,
63,
4399,
63,
2232,
8,
277,
304,
267,
291,
14,
479,
7099,
591,
1332,
277,
14,
45,
12346,
14,
65,
22,
4331,
413,
9,
1253,
378,
88,
17,
12,
378,
12,
298,
1438,
44,
5139,
663,
2410,
221,
540,
775,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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
0,
0,
0,
0,
0,
0,
0,
0
] |
rjschwei/azure-sdk-for-python
|
azure-mgmt-redis/setup.py
|
1
|
2428
|
#!/usr/bin/env python
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------
from setuptools import setup
from io import open
import re
# azure v0.x is not compatible with this package
# azure v0.x used to have a __version__ attribute (newer versions don't)
try:
import azure
try:
ver = azure.__version__
raise Exception(
'This package is incompatible with azure=={}. '.format(ver) +
'Uninstall it with "pip uninstall azure".'
)
except AttributeError:
pass
except ImportError:
pass
# Version extraction inspired from 'requests'
with open('azure/mgmt/redis/version.py', 'r') as fd:
version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)
if not version:
raise RuntimeError('Cannot find version information')
with open('README.rst', encoding='utf-8') as f:
readme = f.read()
with open('HISTORY.rst', encoding='utf-8') as f:
history = f.read()
setup(
name='azure-mgmt-redis',
version=version,
description='Microsoft Azure Redis Cache Resource Management Client Library for Python',
long_description=readme + '\n\n' + history,
license='MIT License',
author='Microsoft Corporation',
author_email='ptvshelp@microsoft.com',
url='https://github.com/Azure/azure-sdk-for-python',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'License :: OSI Approved :: MIT License',
],
zip_safe=False,
packages=[
'azure',
'azure.mgmt',
'azure.mgmt.redis',
'azure.mgmt.redis.models',
'azure.mgmt.redis.operations',
],
install_requires=[
'azure-common~=1.1.4',
'msrestazure~=0.4.6',
'azure-mgmt-nspkg',
],
)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
25812,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
7656,
9460,
199,
199,
504,
9116,
492,
3272,
199,
504,
5890,
492,
1551,
199,
646,
295,
199,
199,
3,
13601,
373,
16,
14,
88,
365,
440,
9025,
543,
642,
2559,
199,
3,
13601,
373,
16,
14,
88,
1202,
370,
1172,
282,
636,
1023,
363,
2225,
334,
1222,
281,
5459,
2793,
1133,
9,
199,
893,
26,
272,
492,
13601,
272,
862,
26,
267,
809,
275,
13601,
855,
1023,
363,
267,
746,
2186,
8,
288,
283,
2765,
2559,
365,
18457,
543,
13601,
389,
31270,
1987,
908,
8,
422,
9,
435,
288,
283,
1358,
3174,
652,
543,
298,
9983,
22199,
13601,
24217,
267,
776,
272,
871,
4281,
26,
267,
986,
199,
2590,
3545,
26,
272,
986,
199,
199,
3,
3394,
19967,
315,
8721,
581,
687,
283,
6615,
7,
199,
1045,
1551,
360,
9078,
15,
9752,
15,
15369,
15,
1023,
14,
647,
297,
283,
82,
358,
465,
6111,
26,
272,
1015,
275,
295,
14,
1733,
8,
82,
4289,
4612,
60,
83,
23440,
83,
23033,
3985,
937,
7059,
3985,
937,
10,
2788,
3985,
23793,
717,
6111,
14,
739,
1062,
295,
14,
16661,
680,
923,
8,
17,
9,
199,
199,
692,
440,
1015,
26,
272,
746,
6064,
360,
6612,
2342,
1015,
2556,
358,
199,
199,
1045,
1551,
360,
18195,
14,
8332,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
272,
1586,
278,
275,
289,
14,
739,
342,
199,
1045,
1551,
360,
30895,
14,
8332,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
272,
7994,
275,
289,
14,
739,
342,
199,
199,
2758,
8,
272,
536,
534,
9078,
13,
9752,
13,
15369,
297,
272,
1015,
29,
1023,
12,
272,
1369,
534,
12940,
15474,
25496,
11977,
7337,
8259,
6810,
11243,
367,
2018,
297,
272,
1846,
63,
1802,
29,
32709,
435,
1557,
78,
60,
78,
7,
435,
7994,
12,
272,
4190,
534,
13965,
844,
297,
272,
4132,
534,
12940,
11098,
297,
272,
4132,
63,
2123,
534,
541,
86,
609,
1357,
32,
17040,
14,
957,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
22386,
15,
9078,
13,
9277,
13,
509,
13,
1548,
297,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
19,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
21,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
22,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
272,
2156,
272,
3482,
63,
3489,
29,
797,
12,
272,
6117,
1524,
267,
283,
9078,
297,
267,
283,
9078,
14,
9752,
297,
267,
283,
9078,
14,
9752,
14,
15369,
297,
267,
283,
9078,
14,
9752,
14,
15369,
14,
992,
297,
267,
283,
9078,
14,
9752,
14,
15369,
14,
8170,
297,
1057,
272,
2156,
272,
3907,
63,
6537,
1524,
267,
283,
9078,
13,
2330,
94,
29,
17,
14,
17,
14,
20,
297,
267,
283,
706,
264,
1207,
7895,
94,
29,
16,
14,
20,
14,
22,
297,
267,
283,
9078,
13,
9752,
13,
561,
4600,
297,
272,
2156,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
25812,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
7656,
9460,
199,
199,
504,
9116,
492,
3272,
199,
504,
5890,
492,
1551,
199,
646,
295,
199,
199,
3,
13601,
373,
16,
14,
88,
365,
440,
9025,
543,
642,
2559,
199,
3,
13601,
373,
16,
14,
88,
1202,
370,
1172,
282,
636,
1023,
363,
2225,
334,
1222,
281,
5459,
2793,
1133,
9,
199,
893,
26,
272,
492,
13601,
272,
862,
26,
267,
809,
275,
13601,
855,
1023,
363,
267,
746,
2186,
8,
288,
283,
2765,
2559,
365,
18457,
543,
13601,
389,
31270,
1987,
908,
8,
422,
9,
435,
288,
283,
1358,
3174,
652,
543,
298,
9983,
22199,
13601,
24217,
267,
776,
272,
871,
4281,
26,
267,
986,
199,
2590,
3545,
26,
272,
986,
199,
199,
3,
3394,
19967,
315,
8721,
581,
687,
283,
6615,
7,
199,
1045,
1551,
360,
9078,
15,
9752,
15,
15369,
15,
1023,
14,
647,
297,
283,
82,
358,
465,
6111,
26,
272,
1015,
275,
295,
14,
1733,
8,
82,
4289,
4612,
60,
83,
23440,
83,
23033,
3985,
937,
7059,
3985,
937,
10,
2788,
3985,
23793,
717,
6111,
14,
739,
1062,
295,
14,
16661,
680,
923,
8,
17,
9,
199,
199,
692,
440,
1015,
26,
272,
746,
6064,
360,
6612,
2342,
1015,
2556,
358,
199,
199,
1045,
1551,
360,
18195,
14,
8332,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
272,
1586,
278,
275,
289,
14,
739,
342,
199,
1045,
1551,
360,
30895,
14,
8332,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
272,
7994,
275,
289,
14,
739,
342,
199,
199,
2758,
8,
272,
536,
534,
9078,
13,
9752,
13,
15369,
297,
272,
1015,
29,
1023,
12,
272,
1369,
534,
12940,
15474,
25496,
11977,
7337,
8259,
6810,
11243,
367,
2018,
297,
272,
1846,
63,
1802,
29,
32709,
435,
1557,
78,
60,
78,
7,
435,
7994,
12,
272,
4190,
534,
13965,
844,
297,
272,
4132,
534,
12940,
11098,
297,
272,
4132,
63,
2123,
534,
541,
86,
609,
1357,
32,
17040,
14,
957,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
22386,
15,
9078,
13,
9277,
13,
509,
13,
1548,
297,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
19,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
21,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
22,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
272,
2156,
272,
3482,
63,
3489,
29,
797,
12,
272,
6117,
1524,
267,
283,
9078,
297,
267,
283,
9078,
14,
9752,
297,
267,
283,
9078,
14,
9752,
14,
15369,
297,
267,
283,
9078,
14,
9752,
14,
15369,
14,
992,
297,
267,
283,
9078,
14,
9752,
14,
15369,
14,
8170,
297,
1057,
272,
2156,
272,
3907,
63,
6537,
1524,
267,
283,
9078,
13,
2330,
94,
29,
17,
14,
17,
14,
20,
297,
267,
283,
706,
264,
1207,
7895,
94,
29,
16,
14,
20,
14,
22,
297,
267,
283,
9078,
13,
9752,
13,
561,
4600,
297,
272,
2156,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alekz112/statsmodels
|
statsmodels/regression/tests/lme_r_results.py
|
33
|
14824
|
import numpy as np
coef_ml_drf_0 = np.array([-0.9887517])
vcov_ml_drf_0 = np.array([0.001317148]).reshape(1,1, order='F')
cov_re_ml_drf_0 = np.array([0.2522485]).reshape(1,1, order='F')
scale_ml_drf_0 = np.array([0.2718486])
loglike_ml_drf_0 = np.array([-240.1254])
ranef_mean_ml_drf_0 = np.array([0.04977167])
ranef_condvar_ml_drf_0 = np.array([0.130841])
coef_reml_drf_0 = np.array([-0.9887533])
vcov_reml_drf_0 = np.array([0.001323559]).reshape(1,1, order='F')
cov_re_reml_drf_0 = np.array([0.2524129]).reshape(1,1, order='F')
scale_reml_drf_0 = np.array([0.2733467])
loglike_reml_drf_0 = np.array([-242.5214])
ranef_mean_reml_drf_0 = np.array([0.04964696])
ranef_condvar_reml_drf_0 = np.array([0.1312315])
coef_ml_drf_1 = np.array([-0.9115929])
vcov_ml_drf_1 = np.array([0.01340632]).reshape(1,1, order='F')
cov_re_ml_drf_1 = np.array([0]).reshape(1,1, order='F')
scale_ml_drf_1 = np.array([4.050921])
loglike_ml_drf_1 = np.array([-538.0763])
ranef_mean_ml_drf_1 = np.array([0])
ranef_condvar_ml_drf_1 = np.array([0])
coef_reml_drf_1 = np.array([-0.9115929])
vcov_reml_drf_1 = np.array([0.01345931]).reshape(1,1, order='F')
cov_re_reml_drf_1 = np.array([2.839777e-14]).reshape(1,1, order='F')
scale_reml_drf_1 = np.array([4.066932])
loglike_reml_drf_1 = np.array([-539.3124])
ranef_mean_reml_drf_1 = np.array([2.424384e-14])
ranef_condvar_reml_drf_1 = np.array([2.839777e-14])
coef_ml_drf_2 = np.array([-1.012044,0.9789052])
vcov_ml_drf_2 = np.array([0.00117849,1.458744e-05,1.458744e-05,0.001054926]).reshape(2,2, order='F')
cov_re_ml_drf_2 = np.array([0.1596058]).reshape(1,1, order='F')
scale_ml_drf_2 = np.array([0.2129146])
loglike_ml_drf_2 = np.array([-200.319])
ranef_mean_ml_drf_2 = np.array([0.3197174])
ranef_condvar_ml_drf_2 = np.array([0.09122291])
coef_reml_drf_2 = np.array([-1.012137,0.9790792])
vcov_reml_drf_2 = np.array([0.001190455,1.482666e-05,1.482666e-05,0.001066002]).reshape(2,2, order='F')
cov_re_reml_drf_2 = np.array([0.1595015]).reshape(1,1, order='F')
scale_reml_drf_2 = np.array([0.2154276])
loglike_reml_drf_2 = np.array([-205.275])
ranef_mean_reml_drf_2 = np.array([0.3172978])
ranef_condvar_reml_drf_2 = np.array([0.09164674])
coef_ml_drf_3 = np.array([-1.028053,0.8602685])
vcov_ml_drf_3 = np.array([0.01398831,0.001592619,0.001592619,0.01602274]).reshape(2,2, order='F')
cov_re_ml_drf_3 = np.array([0.8130996]).reshape(1,1, order='F')
scale_ml_drf_3 = np.array([3.100447])
loglike_ml_drf_3 = np.array([-477.1707])
ranef_mean_ml_drf_3 = np.array([-0.2641747])
ranef_condvar_ml_drf_3 = np.array([0.6441656])
coef_reml_drf_3 = np.array([-1.027583,0.8605714])
vcov_reml_drf_3 = np.array([0.01411922,0.001607343,0.001607343,0.01617574]).reshape(2,2, order='F')
cov_re_reml_drf_3 = np.array([0.8117898]).reshape(1,1, order='F')
scale_reml_drf_3 = np.array([3.13369])
loglike_reml_drf_3 = np.array([-479.5354])
ranef_mean_reml_drf_3 = np.array([-0.2614875])
ranef_condvar_reml_drf_3 = np.array([0.6447625])
coef_ml_drf_4 = np.array([-1.005151,-0.003657404,1.054786])
vcov_ml_drf_4 = np.array([0.001190639,-5.327162e-05,5.992985e-05,-5.327162e-05,0.001460303,-2.662532e-05,5.992985e-05,-2.662532e-05,0.00148609]).reshape(3,3, order='F')
cov_re_ml_drf_4 = np.array([0.1703249]).reshape(1,1, order='F')
scale_ml_drf_4 = np.array([0.251763])
loglike_ml_drf_4 = np.array([-231.6389])
ranef_mean_ml_drf_4 = np.array([-0.2063164])
ranef_condvar_ml_drf_4 = np.array([0.0459578])
coef_reml_drf_4 = np.array([-1.005067,-0.003496032,1.054666])
vcov_reml_drf_4 = np.array([0.001206925,-5.4182e-05,6.073475e-05,-5.4182e-05,0.001479871,-2.723494e-05,6.073475e-05,-2.723494e-05,0.001506198]).reshape(3,3, order='F')
cov_re_reml_drf_4 = np.array([0.1705659]).reshape(1,1, order='F')
scale_reml_drf_4 = np.array([0.2556394])
loglike_reml_drf_4 = np.array([-238.761])
ranef_mean_reml_drf_4 = np.array([-0.2055303])
ranef_condvar_reml_drf_4 = np.array([0.04649027])
coef_ml_drf_5 = np.array([-0.8949725,0.08141558,1.052529])
vcov_ml_drf_5 = np.array([0.01677563,0.0008077524,-0.001255011,0.0008077524,0.01719346,0.0009266736,-0.001255011,0.0009266736,0.01608435]).reshape(3,3, order='F')
cov_re_ml_drf_5 = np.array([0.3444677]).reshape(1,1, order='F')
scale_ml_drf_5 = np.array([4.103944])
loglike_ml_drf_5 = np.array([-579.4568])
ranef_mean_ml_drf_5 = np.array([0.08254713])
ranef_condvar_ml_drf_5 = np.array([0.3177935])
coef_reml_drf_5 = np.array([-0.8946164,0.08134261,1.052486])
vcov_reml_drf_5 = np.array([0.0169698,0.0008162714,-0.001268635,0.0008162714,0.01739219,0.0009345538,-0.001268635,0.0009345538,0.01627074]).reshape(3,3, order='F')
cov_re_reml_drf_5 = np.array([0.3420993]).reshape(1,1, order='F')
scale_reml_drf_5 = np.array([4.155737])
loglike_reml_drf_5 = np.array([-582.8377])
ranef_mean_reml_drf_5 = np.array([0.08111449])
ranef_condvar_reml_drf_5 = np.array([0.3160797])
coef_ml_drf_6 = np.array([-0.8885425])
vcov_ml_drf_6 = np.array([0.002443738]).reshape(1,1, order='F')
cov_re_ml_drf_6 = np.array([0.2595201,0.04591071,0.04591071,2.204612]).reshape(2,2, order='F')
scale_ml_drf_6 = np.array([0.243133])
loglike_ml_drf_6 = np.array([-382.551])
ranef_mean_ml_drf_6 = np.array([-0.0597406,0.6037288])
ranef_condvar_ml_drf_6 = np.array([0.2420741,0.2222169,0.2222169,0.4228908]).reshape(2,2, order='F')
coef_reml_drf_6 = np.array([-0.8883881])
vcov_reml_drf_6 = np.array([0.002461581]).reshape(1,1, order='F')
cov_re_reml_drf_6 = np.array([0.2595767,0.04590012,0.04590012,2.204822]).reshape(2,2, order='F')
scale_reml_drf_6 = np.array([0.2453537])
loglike_reml_drf_6 = np.array([-384.6373])
ranef_mean_reml_drf_6 = np.array([-0.05969892,0.6031793])
ranef_condvar_reml_drf_6 = np.array([0.2421365,0.2221108,0.2221108,0.4244443]).reshape(2,2, order='F')
coef_ml_irf_6 = np.array([-0.8874992])
vcov_ml_irf_6 = np.array([0.002445505]).reshape(1,1, order='F')
cov_re_ml_irf_6 = np.array([0.2587624,0,0,2.188653]).reshape(2,2, order='F')
scale_ml_irf_6 = np.array([0.2432694])
loglike_ml_irf_6 = np.array([-382.6581])
coef_reml_irf_6 = np.array([-0.8873394])
vcov_reml_irf_6 = np.array([0.002463375]).reshape(1,1, order='F')
cov_re_reml_irf_6 = np.array([0.2588157,0,0,2.188876]).reshape(2,2, order='F')
scale_reml_irf_6 = np.array([0.2454935])
loglike_reml_irf_6 = np.array([-384.7441])
coef_ml_drf_7 = np.array([-0.9645281])
vcov_ml_drf_7 = np.array([0.01994]).reshape(1,1, order='F')
cov_re_ml_drf_7 = np.array([0.2051329,0.0734377,0.0734377,3.285381]).reshape(2,2, order='F')
scale_ml_drf_7 = np.array([3.423247])
loglike_ml_drf_7 = np.array([-587.7101])
ranef_mean_ml_drf_7 = np.array([0.07007965,-0.2920284])
ranef_condvar_ml_drf_7 = np.array([0.1823183,0.02247519,0.02247519,1.125011]).reshape(2,2, order='F')
coef_reml_drf_7 = np.array([-0.9647862])
vcov_reml_drf_7 = np.array([0.02002546]).reshape(1,1, order='F')
cov_re_reml_drf_7 = np.array([0.2056226,0.0726139,0.0726139,3.2876]).reshape(2,2, order='F')
scale_reml_drf_7 = np.array([3.440244])
loglike_reml_drf_7 = np.array([-588.7476])
ranef_mean_reml_drf_7 = np.array([0.07000628,-0.2916737])
ranef_condvar_reml_drf_7 = np.array([0.1828266,0.02229138,0.02229138,1.128947]).reshape(2,2, order='F')
coef_ml_irf_7 = np.array([-0.9665524])
vcov_ml_irf_7 = np.array([0.01998144]).reshape(1,1, order='F')
cov_re_ml_irf_7 = np.array([0.2021561,0,0,3.270735]).reshape(2,2, order='F')
scale_ml_irf_7 = np.array([3.423186])
loglike_ml_irf_7 = np.array([-587.7456])
coef_reml_irf_7 = np.array([-0.9667854])
vcov_reml_irf_7 = np.array([0.02006657]).reshape(1,1, order='F')
cov_re_reml_irf_7 = np.array([0.2026938,0,0,3.273129]).reshape(2,2, order='F')
scale_reml_irf_7 = np.array([3.440197])
loglike_reml_irf_7 = np.array([-588.782])
coef_ml_drf_8 = np.array([-1.083882,0.8955623])
vcov_ml_drf_8 = np.array([0.002491643,0.0001693531,0.0001693531,0.00253309]).reshape(2,2, order='F')
cov_re_ml_drf_8 = np.array([0.1506188,0.126091,0.126091,2.485462]).reshape(2,2, order='F')
scale_ml_drf_8 = np.array([0.2586519])
loglike_ml_drf_8 = np.array([-363.6234])
ranef_mean_ml_drf_8 = np.array([0.2852326,-0.5047804])
ranef_condvar_ml_drf_8 = np.array([0.05400391,0.002330104,0.002330104,0.122761]).reshape(2,2, order='F')
coef_reml_drf_8 = np.array([-1.083938,0.8956893])
vcov_reml_drf_8 = np.array([0.002528969,0.0001712206,0.0001712206,0.002573335]).reshape(2,2, order='F')
cov_re_reml_drf_8 = np.array([0.1505098,0.1256311,0.1256311,2.484219]).reshape(2,2, order='F')
scale_reml_drf_8 = np.array([0.2635901])
loglike_reml_drf_8 = np.array([-367.7667])
ranef_mean_reml_drf_8 = np.array([0.2829798,-0.5042857])
ranef_condvar_reml_drf_8 = np.array([0.05463632,0.002393538,0.002393538,0.1249828]).reshape(2,2, order='F')
coef_ml_irf_8 = np.array([-1.079481,0.898216])
vcov_ml_irf_8 = np.array([0.002511536,0.0001812511,0.0001812511,0.002573405]).reshape(2,2, order='F')
cov_re_ml_irf_8 = np.array([0.1498568,0,0,2.403849]).reshape(2,2, order='F')
scale_ml_irf_8 = np.array([0.2605245])
loglike_ml_irf_8 = np.array([-364.4824])
coef_reml_irf_8 = np.array([-1.07952,0.8983678])
vcov_reml_irf_8 = np.array([0.002549354,0.0001833386,0.0001833386,0.002614672]).reshape(2,2, order='F')
cov_re_reml_irf_8 = np.array([0.1497193,0,0,2.403076]).reshape(2,2, order='F')
scale_reml_irf_8 = np.array([0.2655558])
loglike_reml_irf_8 = np.array([-368.6141])
coef_ml_drf_9 = np.array([-1.272698,0.8617471])
vcov_ml_drf_9 = np.array([0.02208544,0.001527479,0.001527479,0.02597528]).reshape(2,2, order='F')
cov_re_ml_drf_9 = np.array([0.510175,0.08826114,0.08826114,3.342888]).reshape(2,2, order='F')
scale_ml_drf_9 = np.array([3.722112])
loglike_ml_drf_9 = np.array([-589.8274])
ranef_mean_ml_drf_9 = np.array([0.03253644,0.224043])
ranef_condvar_ml_drf_9 = np.array([0.3994872,0.02478884,0.02478884,1.195077]).reshape(2,2, order='F')
coef_reml_drf_9 = np.array([-1.272483,0.861814])
vcov_reml_drf_9 = np.array([0.02228589,0.001535598,0.001535598,0.0262125]).reshape(2,2, order='F')
cov_re_reml_drf_9 = np.array([0.5123204,0.08897376,0.08897376,3.341722]).reshape(2,2, order='F')
scale_reml_drf_9 = np.array([3.764058])
loglike_reml_drf_9 = np.array([-591.7188])
ranef_mean_reml_drf_9 = np.array([0.03239688,0.2230525])
ranef_condvar_reml_drf_9 = np.array([0.401762,0.02521271,0.02521271,1.203536]).reshape(2,2, order='F')
coef_ml_irf_9 = np.array([-1.277018,0.86395])
vcov_ml_irf_9 = np.array([0.02205706,0.001509887,0.001509887,0.02599941]).reshape(2,2, order='F')
cov_re_ml_irf_9 = np.array([0.5086816,0,0,3.312757]).reshape(2,2, order='F')
scale_ml_irf_9 = np.array([3.72105])
loglike_ml_irf_9 = np.array([-589.8628])
coef_reml_irf_9 = np.array([-1.276822,0.8640243])
vcov_reml_irf_9 = np.array([0.02225705,0.001517774,0.001517774,0.02623682]).reshape(2,2, order='F')
cov_re_reml_irf_9 = np.array([0.5107725,0,0,3.31152]).reshape(2,2, order='F')
scale_reml_irf_9 = np.array([3.762967])
loglike_reml_irf_9 = np.array([-591.7543])
coef_ml_drf_10 = np.array([-0.9419566,-0.02359824,1.085796])
vcov_ml_drf_10 = np.array([0.001963536,-0.0003221793,0.0001950186,-0.0003221793,0.002534251,0.0004107718,0.0001950186,0.0004107718,0.002580736]).reshape(3,3, order='F')
cov_re_ml_drf_10 = np.array([0.2040541,0.09038325,0.09038325,2.218903]).reshape(2,2, order='F')
scale_ml_drf_10 = np.array([0.2558286])
loglike_ml_drf_10 = np.array([-379.6591])
ranef_mean_ml_drf_10 = np.array([0.03876325,-0.725853])
ranef_condvar_ml_drf_10 = np.array([0.1988816,0.1872403,0.1872403,0.4052274]).reshape(2,2, order='F')
coef_reml_drf_10 = np.array([-0.9426367,-0.02336203,1.085733])
vcov_reml_drf_10 = np.array([0.002011348,-0.0003300612,0.0002002948,-0.0003300612,0.002589149,0.000418987,0.0002002948,0.000418987,0.002637433]).reshape(3,3, order='F')
cov_re_reml_drf_10 = np.array([0.2034827,0.09063836,0.09063836,2.219191]).reshape(2,2, order='F')
scale_reml_drf_10 = np.array([0.2630213])
loglike_reml_drf_10 = np.array([-386.0008])
ranef_mean_reml_drf_10 = np.array([0.03838686,-0.7240812])
ranef_condvar_reml_drf_10 = np.array([0.1983981,0.1865469,0.1865469,0.4100937]).reshape(2,2, order='F')
coef_ml_irf_10 = np.array([-0.9441033,-0.01755913,1.088568])
vcov_ml_irf_10 = np.array([0.001960114,-0.0003215658,0.0001944005,-0.0003215658,0.00253441,0.0004061179,0.0001944005,0.0004061179,0.002589158]).reshape(3,3, order='F')
cov_re_ml_irf_10 = np.array([0.2032228,0,0,2.192893]).reshape(2,2, order='F')
scale_ml_irf_10 = np.array([0.2553399])
loglike_ml_irf_10 = np.array([-380.162])
coef_reml_irf_10 = np.array([-0.9448257,-0.01722993,1.088557])
vcov_reml_irf_10 = np.array([0.00200783,-0.0003294349,0.0001996613,-0.0003294349,0.00258937,0.0004141667,0.0001996613,0.0004141667,0.002646242]).reshape(3,3, order='F')
cov_re_reml_irf_10 = np.array([0.2026653,0,0,2.193124]).reshape(2,2, order='F')
scale_reml_irf_10 = np.array([0.2625147])
loglike_reml_irf_10 = np.array([-386.5024])
coef_ml_drf_11 = np.array([-1.36971,0.1596278,0.8588724])
vcov_ml_drf_11 = np.array([0.0232326,0.00172214,0.002275343,0.00172214,0.02318941,0.0004755663,0.002275343,0.0004755663,0.02123474]).reshape(3,3, order='F')
cov_re_ml_drf_11 = np.array([0.3719096,0.332198,0.332198,1.120588]).reshape(2,2, order='F')
scale_ml_drf_11 = np.array([4.849781])
loglike_ml_drf_11 = np.array([-601.6432])
ranef_mean_ml_drf_11 = np.array([-0.4256917,-0.3907759])
ranef_condvar_ml_drf_11 = np.array([0.2987928,0.1992074,0.1992074,0.7477486]).reshape(2,2, order='F')
coef_reml_drf_11 = np.array([-1.370236,0.1597671,0.8585994])
vcov_reml_drf_11 = np.array([0.02351795,0.001749756,0.002301599,0.001749756,0.02346869,0.0004785668,0.002301599,0.0004785668,0.02149093]).reshape(3,3, order='F')
cov_re_reml_drf_11 = np.array([0.3680346,0.3324419,0.3324419,1.118623]).reshape(2,2, order='F')
scale_reml_drf_11 = np.array([4.922222])
loglike_reml_drf_11 = np.array([-604.5746])
ranef_mean_reml_drf_11 = np.array([-0.4168539,-0.3879533])
ranef_condvar_reml_drf_11 = np.array([0.2965372,0.2010191,0.2010191,0.7503986]).reshape(2,2, order='F')
coef_ml_irf_11 = np.array([-1.370117,0.1414964,0.8466083])
vcov_ml_irf_11 = np.array([0.02319951,0.001705996,0.002265252,0.001705996,0.02345623,0.000514879,0.002265252,0.000514879,0.02153162]).reshape(3,3, order='F')
cov_re_ml_irf_11 = np.array([0.4004789,0,0,1.108087]).reshape(2,2, order='F')
scale_ml_irf_11 = np.array([4.78776])
loglike_ml_irf_11 = np.array([-602.308])
coef_reml_irf_11 = np.array([-1.370663,0.1417561,0.8464232])
vcov_reml_irf_11 = np.array([0.02348548,0.001734072,0.002291519,0.001734072,0.02373715,0.0005177618,0.002291519,0.0005177618,0.02178966]).reshape(3,3, order='F')
cov_re_reml_irf_11 = np.array([0.3966454,0,0,1.106551]).reshape(2,2, order='F')
scale_reml_irf_11 = np.array([4.860342])
loglike_reml_irf_11 = np.array([-605.2274])
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
199,
8009,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
16,
14,
31024,
2194,
1196,
566,
199,
199,
86,
8695,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
24250,
1196,
10834,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
821,
1081,
21956,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
1465,
10078,
1184,
566,
199,
199,
793,
2930,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
9873,
14,
31195,
566,
199,
199,
1312,
2829,
63,
3670,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
12809,
1138,
10806,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
9056,
19211,
566,
199,
199,
8009,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
16,
14,
31024,
2194,
1153,
566,
199,
199,
86,
8695,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
4587,
708,
10156,
25,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
27752,
7263,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
1465,
8425,
1822,
566,
199,
199,
793,
2930,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
13212,
14,
2528,
1079,
566,
199,
199,
1312,
2829,
63,
3670,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
12809,
772,
15154,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
969,
4288,
1046,
566,
199,
199,
8009,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
16,
14,
25,
845,
1427,
1398,
566,
199,
199,
86,
8695,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
14,
614,
1082,
1690,
708,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
20,
14,
16,
6576,
2025,
566,
199,
199,
793,
2930,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
32747,
14,
1780,
2766,
566,
199,
199,
1312,
2829,
63,
3670,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
566,
199,
199,
8009,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
16,
14,
25,
845,
1427,
1398,
566,
199,
199,
86,
8695,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
14,
614,
1082,
1427,
2192,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
18,
14,
29304,
11956,
69,
13,
1079,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
20,
14,
14045,
27251,
566,
199,
199,
793,
2930,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
25391,
14,
19,
7214,
566,
199,
199,
1312,
2829,
63,
3670,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
18,
14,
21089,
8188,
69,
13,
1079,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
18,
14,
29304,
11956,
69,
13,
1079,
566,
199,
199,
8009,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
11468,
17,
14,
614,
6686,
20,
12,
16,
14,
2576,
1407,
19730,
566,
199,
199,
86,
8695,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
383,
7362,
14866,
12,
17,
14,
28645,
15839,
69,
13,
1717,
12,
17,
14,
28645,
15839,
69,
13,
1717,
12,
16,
14,
17657,
15419,
1479,
6575,
5217,
8,
18,
12,
18,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
1046,
2534,
18009,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
18,
7263,
11432,
566,
199,
199,
793,
2930,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
11468,
1840,
14,
23538,
566,
199,
199,
1312,
2829,
63,
3670,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
19,
11165,
9892,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
1643,
713,
1081,
3328,
566,
199,
199,
8009,
63,
264,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
11468,
17,
14,
11533,
7498,
12,
16,
14,
31955,
1780,
2942,
566,
199,
199,
86,
8695,
63,
264,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
383,
7119,
966,
1229,
12,
17,
14,
2006,
9969,
22,
69,
13,
1717,
12,
17,
14,
2006,
9969,
22,
69,
13,
1717,
12,
16,
14,
17657,
1272,
7432,
6575,
5217,
8,
18,
12,
18,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
264,
757,
63,
68,
3941,
63,
18
] |
[
2680,
465,
980,
199,
199,
8009,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
16,
14,
31024,
2194,
1196,
566,
199,
199,
86,
8695,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
24250,
1196,
10834,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
821,
1081,
21956,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
1465,
10078,
1184,
566,
199,
199,
793,
2930,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
9873,
14,
31195,
566,
199,
199,
1312,
2829,
63,
3670,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
12809,
1138,
10806,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
9056,
19211,
566,
199,
199,
8009,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
16,
14,
31024,
2194,
1153,
566,
199,
199,
86,
8695,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
4587,
708,
10156,
25,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
27752,
7263,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
1465,
8425,
1822,
566,
199,
199,
793,
2930,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
11468,
13212,
14,
2528,
1079,
566,
199,
199,
1312,
2829,
63,
3670,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
12809,
772,
15154,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
264,
757,
63,
68,
3941,
63,
16,
275,
980,
14,
1144,
779,
16,
14,
969,
4288,
1046,
566,
199,
199,
8009,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
16,
14,
25,
845,
1427,
1398,
566,
199,
199,
86,
8695,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
14,
614,
1082,
1690,
708,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
20,
14,
16,
6576,
2025,
566,
199,
199,
793,
2930,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
32747,
14,
1780,
2766,
566,
199,
199,
1312,
2829,
63,
3670,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
566,
199,
199,
8009,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
16,
14,
25,
845,
1427,
1398,
566,
199,
199,
86,
8695,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
16,
14,
614,
1082,
1427,
2192,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
18,
14,
29304,
11956,
69,
13,
1079,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
20,
14,
14045,
27251,
566,
199,
199,
793,
2930,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
11468,
25391,
14,
19,
7214,
566,
199,
199,
1312,
2829,
63,
3670,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
18,
14,
21089,
8188,
69,
13,
1079,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
264,
757,
63,
68,
3941,
63,
17,
275,
980,
14,
1144,
779,
18,
14,
29304,
11956,
69,
13,
1079,
566,
199,
199,
8009,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
11468,
17,
14,
614,
6686,
20,
12,
16,
14,
2576,
1407,
19730,
566,
199,
199,
86,
8695,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
383,
7362,
14866,
12,
17,
14,
28645,
15839,
69,
13,
1717,
12,
17,
14,
28645,
15839,
69,
13,
1717,
12,
16,
14,
17657,
15419,
1479,
6575,
5217,
8,
18,
12,
18,
12,
1865,
534,
38,
358,
199,
199,
8695,
63,
264,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
1046,
2534,
18009,
6575,
5217,
8,
17,
12,
17,
12,
1865,
534,
38,
358,
199,
199,
3467,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
18,
7263,
11432,
566,
199,
199,
793,
2930,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
11468,
1840,
14,
23538,
566,
199,
199,
1312,
2829,
63,
3670,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
19,
11165,
9892,
566,
199,
199,
1312,
2829,
63,
2067,
1391,
63,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
1643,
713,
1081,
3328,
566,
199,
199,
8009,
63,
264,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
11468,
17,
14,
11533,
7498,
12,
16,
14,
31955,
1780,
2942,
566,
199,
199,
86,
8695,
63,
264,
757,
63,
68,
3941,
63,
18,
275,
980,
14,
1144,
779,
16,
14,
383,
7119,
966,
1229,
12,
17,
14,
2006,
9969,
22,
69,
13,
1717,
12,
17,
14,
2006,
9969,
22,
69,
13,
1717,
12,
16,
14,
17657,
1272,
7432,
6575,
5217,
8,
18,
12,
18,
12,
1865,
534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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
orbitfp7/horizon
|
openstack_dashboard/dashboards/project/data_processing/data_image_registry/forms.py
|
10
|
4212
|
# 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 json
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from openstack_dashboard.api import glance
from openstack_dashboard.api import sahara as saharaclient
class ImageForm(forms.SelfHandlingForm):
image_id = forms.CharField(widget=forms.HiddenInput())
tags_list = forms.CharField(widget=forms.HiddenInput())
user_name = forms.CharField(max_length=80, label=_("User Name"))
description = forms.CharField(max_length=80,
label=_("Description"),
required=False,
widget=forms.Textarea(attrs={'rows': 4}))
def handle(self, request, data):
try:
image_id = data['image_id']
user_name = data['user_name']
desc = data['description']
saharaclient.image_update(request, image_id, user_name, desc)
image_tags = json.loads(data["tags_list"])
saharaclient.image_tags_update(request, image_id, image_tags)
messages.success(request,
_("Successfully updated image."))
return True
except Exception:
exceptions.handle(request,
_("Failed to update image."))
return False
class EditTagsForm(ImageForm):
image_id = forms.CharField(widget=forms.HiddenInput())
class RegisterImageForm(ImageForm):
image_id = forms.ChoiceField(label=_("Image"))
def __init__(self, request, *args, **kwargs):
super(RegisterImageForm, self).__init__(request, *args, **kwargs)
self._populate_image_id_choices()
def _populate_image_id_choices(self):
images = self._get_available_images(self.request)
choices = [(image.id, image.name)
for image in images
if image.properties.get("image_type", '') != "snapshot"]
if choices:
choices.insert(0, ("", _("Select Image")))
else:
choices.insert(0, ("", _("No images available.")))
self.fields['image_id'].choices = choices
def _get_images(self, request, filter):
try:
images, _more, _prev = (
glance.image_list_detailed(request, filters=filter))
except Exception:
images = []
exceptions.handle(request,
_("Unable to retrieve images with filter %s.") %
filter)
return images
def _get_public_images(self, request):
filter = {"is_public": True,
"status": "active"}
return self._get_images(request, filter)
def _get_tenant_images(self, request):
filter = {"owner": request.user.tenant_id,
"status": "active"}
return self._get_images(request, filter)
def _get_available_images(self, request):
images = self._get_tenant_images(request)
if request.user.is_superuser:
images += self._get_public_images(request)
final_images = []
try:
image_ids = set(img.id for img in saharaclient.image_list(request))
except Exception:
image_ids = set()
exceptions.handle(request,
_("Unable to fetch available images."))
for image in images:
if (image not in final_images and
image.id not in image_ids and
image.container_format not in ('aki', 'ari')):
final_images.append(image)
return final_images
|
apache-2.0
|
[
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2022,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
199,
504,
13869,
63,
9743,
14,
1246,
492,
21785,
199,
504,
13869,
63,
9743,
14,
1246,
492,
2937,
27314,
465,
2937,
8210,
645,
864,
421,
199,
533,
6047,
2821,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
1834,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
3762,
63,
513,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
922,
63,
354,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1257,
12,
1768,
9384,
1899,
2812,
2237,
272,
1369,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1257,
12,
3303,
1768,
9384,
5831,
1288,
3303,
1415,
29,
797,
12,
3303,
3938,
29,
3351,
14,
1872,
6789,
8,
3288,
3713,
3838,
356,
841,
12466,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
862,
26,
288,
1834,
63,
344,
275,
666,
459,
1569,
63,
344,
418,
288,
922,
63,
354,
275,
666,
459,
751,
63,
354,
418,
288,
4328,
275,
666,
459,
1802,
418,
288,
2937,
8210,
645,
864,
14,
1569,
63,
873,
8,
1069,
12,
1834,
63,
344,
12,
922,
63,
354,
12,
4328,
9,
953,
1834,
63,
2969,
275,
2022,
14,
3640,
8,
576,
905,
2969,
63,
513,
3135,
288,
2937,
8210,
645,
864,
14,
1569,
63,
2969,
63,
873,
8,
1069,
12,
1834,
63,
344,
12,
1834,
63,
2969,
9,
953,
3788,
14,
3742,
8,
1069,
12,
2490,
3824,
25001,
4588,
1834,
13853,
953,
372,
715,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
3824,
4276,
370,
1678,
1834,
13853,
288,
372,
756,
421,
199,
533,
16407,
9440,
2821,
8,
3491,
2821,
304,
272,
1834,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
421,
199,
533,
11828,
3491,
2821,
8,
3491,
2821,
304,
272,
1834,
63,
344,
275,
4513,
14,
15792,
8,
1302,
9384,
3491,
2237,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
7099,
3491,
2821,
12,
291,
2843,
826,
721,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
423,
13817,
63,
1569,
63,
344,
63,
4577,
342,
339,
347,
485,
13817,
63,
1569,
63,
344,
63,
4577,
8,
277,
304,
267,
5935,
275,
291,
423,
362,
63,
4561,
63,
4782,
8,
277,
14,
1069,
9,
267,
3415,
275,
3842,
1569,
14,
344,
12,
1834,
14,
354,
9,
673,
367,
1834,
315,
5935,
673,
340,
1834,
14,
3282,
14,
362,
480,
1569,
63,
466,
401,
4074,
1137,
298,
4753,
937,
267,
340,
3415,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
5446,
6047,
13324,
267,
587,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
1944,
5935,
2808,
2122,
1724,
267,
291,
14,
955,
459,
1569,
63,
344,
2278,
4577,
275,
3415,
339,
347,
485,
362,
63,
4782,
8,
277,
12,
1056,
12,
2457,
304,
267,
862,
26,
288,
5935,
12,
485,
6878,
12,
485,
5701,
275,
334,
355,
21785,
14,
1569,
63,
513,
63,
19170,
8,
1069,
12,
4766,
29,
1541,
430,
267,
871,
2186,
26,
288,
5935,
275,
942,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
3824,
6005,
370,
8044,
5935,
543,
2457,
450,
83,
2685,
450,
2892,
2457,
9,
267,
372,
5935,
339,
347,
485,
362,
63,
3455,
63,
4782,
8,
277,
12,
1056,
304,
267,
2457,
275,
2420,
374,
63,
3455,
582,
715,
12,
2116,
298,
1205,
582,
298,
2682,
3570,
267,
372,
291,
423,
362,
63,
4782,
8,
1069,
12,
2457,
9,
339,
347,
485,
362,
63,
4647,
63,
4782,
8,
277,
12,
1056,
304,
267,
2457,
275,
2420,
4597,
582,
1056,
14,
751,
14,
4647,
63,
344,
12,
2116,
298,
1205,
582,
298,
2682,
3570,
267,
372,
291,
423,
362,
63,
4782,
8,
1069,
12,
2457,
9,
339,
347,
485,
362,
63,
4561,
63,
4782,
8,
277,
12,
1056,
304,
398,
5935,
275,
291,
423,
362,
63,
4647,
63,
4782,
8,
1069,
9,
267,
340,
1056,
14,
751,
14,
374,
63,
11434,
26,
288,
5935,
847,
291,
423,
362,
63,
3455,
63,
4782,
8,
1069,
9,
398,
4242,
63,
4782,
275,
942,
398,
862,
26,
288,
1834,
63,
1580,
275,
663,
8,
4060,
14,
344,
367,
6050,
315,
2937,
8210,
645,
864,
14,
1569,
63,
513,
8,
1069,
430,
267,
871,
2186,
26,
288,
1834,
63,
1580,
275,
663,
342,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
3824,
6005,
370,
5267,
2808,
5935,
13853,
398,
367,
1834,
315,
5935,
26,
288,
340,
334,
1569,
440,
315,
4242,
63,
4782,
436,
490,
1834,
14,
344,
440,
315,
1834,
63,
1580,
436,
490,
1834,
14,
3600,
63,
908,
440,
315,
661,
27387,
297,
283,
759,
8109,
355,
4242,
63,
4782,
14,
740,
8,
1569,
9,
267,
372,
4242,
63,
4782,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2022,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
199,
504,
13869,
63,
9743,
14,
1246,
492,
21785,
199,
504,
13869,
63,
9743,
14,
1246,
492,
2937,
27314,
465,
2937,
8210,
645,
864,
421,
199,
533,
6047,
2821,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
1834,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
3762,
63,
513,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
922,
63,
354,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1257,
12,
1768,
9384,
1899,
2812,
2237,
272,
1369,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1257,
12,
3303,
1768,
9384,
5831,
1288,
3303,
1415,
29,
797,
12,
3303,
3938,
29,
3351,
14,
1872,
6789,
8,
3288,
3713,
3838,
356,
841,
12466,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
862,
26,
288,
1834,
63,
344,
275,
666,
459,
1569,
63,
344,
418,
288,
922,
63,
354,
275,
666,
459,
751,
63,
354,
418,
288,
4328,
275,
666,
459,
1802,
418,
288,
2937,
8210,
645,
864,
14,
1569,
63,
873,
8,
1069,
12,
1834,
63,
344,
12,
922,
63,
354,
12,
4328,
9,
953,
1834,
63,
2969,
275,
2022,
14,
3640,
8,
576,
905,
2969,
63,
513,
3135,
288,
2937,
8210,
645,
864,
14,
1569,
63,
2969,
63,
873,
8,
1069,
12,
1834,
63,
344,
12,
1834,
63,
2969,
9,
953,
3788,
14,
3742,
8,
1069,
12,
2490,
3824,
25001,
4588,
1834,
13853,
953,
372,
715,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
3824,
4276,
370,
1678,
1834,
13853,
288,
372,
756,
421,
199,
533,
16407,
9440,
2821,
8,
3491,
2821,
304,
272,
1834,
63,
344,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
421,
199,
533,
11828,
3491,
2821,
8,
3491,
2821,
304,
272,
1834,
63,
344,
275,
4513,
14,
15792,
8,
1302,
9384,
3491,
2237,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
7099,
3491,
2821,
12,
291,
2843,
826,
721,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
423,
13817,
63,
1569,
63,
344,
63,
4577,
342,
339,
347,
485,
13817,
63,
1569,
63,
344,
63,
4577,
8,
277,
304,
267,
5935,
275,
291,
423,
362,
63,
4561,
63,
4782,
8,
277,
14,
1069,
9,
267,
3415,
275,
3842,
1569,
14,
344,
12,
1834,
14,
354,
9,
673,
367,
1834,
315,
5935,
673,
340,
1834,
14,
3282,
14,
362,
480,
1569,
63,
466,
401,
4074,
1137,
298,
4753,
937,
267,
340,
3415,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
5446,
6047,
13324,
267,
587,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
1944,
5935,
2808,
2122,
1724,
267,
291,
14,
955,
459,
1569,
63,
344,
2278,
4577,
275,
3415,
339,
347,
485,
362,
63,
4782,
8,
277,
12,
1056,
12,
2457,
304,
267,
862,
26,
288,
5935,
12,
485,
6878,
12,
485,
5701,
275,
334,
355,
21785,
14,
1569,
63,
513,
63,
19170,
8,
1069,
12,
4766,
29,
1541,
430,
267,
871,
2186,
26,
288,
5935,
275,
942,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
3824,
6005,
370,
8044,
5935,
543,
2457,
450,
83,
2685,
450,
2892,
2457,
9,
267,
372,
5935,
339,
347,
485,
362,
63,
3455,
63,
4782,
8,
277,
12,
1056,
304,
267,
2457,
275,
2420,
374,
63,
3455,
582,
715,
12,
2116,
298,
1205,
582,
298,
2682,
3570,
267,
372,
291,
423,
362,
63,
4782,
8,
1069,
12,
2457,
9,
339,
347,
485,
362,
63,
4647,
63,
4782,
8,
277,
12,
1056,
304,
267,
2457,
275,
2420,
4597,
582,
1056,
14,
751,
14,
4647,
63,
344,
12,
2116,
298,
1205,
582,
298,
2682,
3570,
267,
372,
291,
423,
362,
63,
4782,
8,
1069,
12,
2457,
9,
339,
347,
485,
362,
63,
4561,
63,
4782,
8,
277,
12,
1056,
304,
398,
5935,
275,
291,
423,
362,
63,
4647,
63,
4782,
8,
1069,
9,
267,
340,
1056,
14,
751,
14,
374,
63,
11434,
26,
288,
5935,
847,
291,
423,
362,
63,
3455,
63,
4782,
8,
1069,
9,
398,
4242,
63,
4782,
275,
942,
398,
862,
26,
288,
1834,
63,
1580,
275,
663,
8,
4060,
14,
344,
367,
6050,
315,
2937,
8210,
645,
864,
14,
1569,
63,
513,
8,
1069,
430,
267,
871,
2186,
26,
288,
1834,
63,
1580,
275,
663,
342,
288,
4967,
14,
2479,
8,
1069,
12,
2892,
3824,
6005,
370,
5267,
2808,
5935,
13853,
398,
367,
1834,
315,
5935,
26,
288,
340,
334,
1569,
440,
315,
4242,
63,
4782,
436,
490,
1834,
14,
344,
440,
315,
1834,
63,
1580,
436,
490,
1834,
14,
3600,
63,
908,
440,
315,
661,
27387,
297,
283,
759,
8109,
355,
4242,
63,
4782,
14,
740,
8,
1569,
9,
267,
372,
4242,
63,
4782,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
abzaloid/maps
|
django-project/lib/python2.7/site-packages/pip/_vendor/requests/packages/chardet/euckrfreq.py
|
3121
|
45978
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
# Sampling from about 20M text materials include literature and computer technology
# 128 --> 0.79
# 256 --> 0.92
# 512 --> 0.986
# 1024 --> 0.99944
# 2048 --> 0.99999
#
# Idea Distribution Ratio = 0.98653 / (1-0.98653) = 73.24
# Random Distribution Ration = 512 / (2350-512) = 0.279.
#
# Typical Distribution Ratio
EUCKR_TYPICAL_DISTRIBUTION_RATIO = 6.0
EUCKR_TABLE_SIZE = 2352
# Char to FreqOrder table ,
EUCKRCharToFreqOrder = ( \
13, 130, 120,1396, 481,1719,1720, 328, 609, 212,1721, 707, 400, 299,1722, 87,
1397,1723, 104, 536,1117,1203,1724,1267, 685,1268, 508,1725,1726,1727,1728,1398,
1399,1729,1730,1731, 141, 621, 326,1057, 368,1732, 267, 488, 20,1733,1269,1734,
945,1400,1735, 47, 904,1270,1736,1737, 773, 248,1738, 409, 313, 786, 429,1739,
116, 987, 813,1401, 683, 75,1204, 145,1740,1741,1742,1743, 16, 847, 667, 622,
708,1744,1745,1746, 966, 787, 304, 129,1747, 60, 820, 123, 676,1748,1749,1750,
1751, 617,1752, 626,1753,1754,1755,1756, 653,1757,1758,1759,1760,1761,1762, 856,
344,1763,1764,1765,1766, 89, 401, 418, 806, 905, 848,1767,1768,1769, 946,1205,
709,1770,1118,1771, 241,1772,1773,1774,1271,1775, 569,1776, 999,1777,1778,1779,
1780, 337, 751,1058, 28, 628, 254,1781, 177, 906, 270, 349, 891,1079,1782, 19,
1783, 379,1784, 315,1785, 629, 754,1402, 559,1786, 636, 203,1206,1787, 710, 567,
1788, 935, 814,1789,1790,1207, 766, 528,1791,1792,1208,1793,1794,1795,1796,1797,
1403,1798,1799, 533,1059,1404,1405,1156,1406, 936, 884,1080,1800, 351,1801,1802,
1803,1804,1805, 801,1806,1807,1808,1119,1809,1157, 714, 474,1407,1810, 298, 899,
885,1811,1120, 802,1158,1812, 892,1813,1814,1408, 659,1815,1816,1121,1817,1818,
1819,1820,1821,1822, 319,1823, 594, 545,1824, 815, 937,1209,1825,1826, 573,1409,
1022,1827,1210,1828,1829,1830,1831,1832,1833, 556, 722, 807,1122,1060,1834, 697,
1835, 900, 557, 715,1836,1410, 540,1411, 752,1159, 294, 597,1211, 976, 803, 770,
1412,1837,1838, 39, 794,1413, 358,1839, 371, 925,1840, 453, 661, 788, 531, 723,
544,1023,1081, 869, 91,1841, 392, 430, 790, 602,1414, 677,1082, 457,1415,1416,
1842,1843, 475, 327,1024,1417, 795, 121,1844, 733, 403,1418,1845,1846,1847, 300,
119, 711,1212, 627,1848,1272, 207,1849,1850, 796,1213, 382,1851, 519,1852,1083,
893,1853,1854,1855, 367, 809, 487, 671,1856, 663,1857,1858, 956, 471, 306, 857,
1859,1860,1160,1084,1861,1862,1863,1864,1865,1061,1866,1867,1868,1869,1870,1871,
282, 96, 574,1872, 502,1085,1873,1214,1874, 907,1875,1876, 827, 977,1419,1420,
1421, 268,1877,1422,1878,1879,1880, 308,1881, 2, 537,1882,1883,1215,1884,1885,
127, 791,1886,1273,1423,1887, 34, 336, 404, 643,1888, 571, 654, 894, 840,1889,
0, 886,1274, 122, 575, 260, 908, 938,1890,1275, 410, 316,1891,1892, 100,1893,
1894,1123, 48,1161,1124,1025,1895, 633, 901,1276,1896,1897, 115, 816,1898, 317,
1899, 694,1900, 909, 734,1424, 572, 866,1425, 691, 85, 524,1010, 543, 394, 841,
1901,1902,1903,1026,1904,1905,1906,1907,1908,1909, 30, 451, 651, 988, 310,1910,
1911,1426, 810,1216, 93,1912,1913,1277,1217,1914, 858, 759, 45, 58, 181, 610,
269,1915,1916, 131,1062, 551, 443,1000, 821,1427, 957, 895,1086,1917,1918, 375,
1919, 359,1920, 687,1921, 822,1922, 293,1923,1924, 40, 662, 118, 692, 29, 939,
887, 640, 482, 174,1925, 69,1162, 728,1428, 910,1926,1278,1218,1279, 386, 870,
217, 854,1163, 823,1927,1928,1929,1930, 834,1931, 78,1932, 859,1933,1063,1934,
1935,1936,1937, 438,1164, 208, 595,1938,1939,1940,1941,1219,1125,1942, 280, 888,
1429,1430,1220,1431,1943,1944,1945,1946,1947,1280, 150, 510,1432,1948,1949,1950,
1951,1952,1953,1954,1011,1087,1955,1433,1043,1956, 881,1957, 614, 958,1064,1065,
1221,1958, 638,1001, 860, 967, 896,1434, 989, 492, 553,1281,1165,1959,1282,1002,
1283,1222,1960,1961,1962,1963, 36, 383, 228, 753, 247, 454,1964, 876, 678,1965,
1966,1284, 126, 464, 490, 835, 136, 672, 529, 940,1088,1435, 473,1967,1968, 467,
50, 390, 227, 587, 279, 378, 598, 792, 968, 240, 151, 160, 849, 882,1126,1285,
639,1044, 133, 140, 288, 360, 811, 563,1027, 561, 142, 523,1969,1970,1971, 7,
103, 296, 439, 407, 506, 634, 990,1972,1973,1974,1975, 645,1976,1977,1978,1979,
1980,1981, 236,1982,1436,1983,1984,1089, 192, 828, 618, 518,1166, 333,1127,1985,
818,1223,1986,1987,1988,1989,1990,1991,1992,1993, 342,1128,1286, 746, 842,1994,
1995, 560, 223,1287, 98, 8, 189, 650, 978,1288,1996,1437,1997, 17, 345, 250,
423, 277, 234, 512, 226, 97, 289, 42, 167,1998, 201,1999,2000, 843, 836, 824,
532, 338, 783,1090, 182, 576, 436,1438,1439, 527, 500,2001, 947, 889,2002,2003,
2004,2005, 262, 600, 314, 447,2006, 547,2007, 693, 738,1129,2008, 71,1440, 745,
619, 688,2009, 829,2010,2011, 147,2012, 33, 948,2013,2014, 74, 224,2015, 61,
191, 918, 399, 637,2016,1028,1130, 257, 902,2017,2018,2019,2020,2021,2022,2023,
2024,2025,2026, 837,2027,2028,2029,2030, 179, 874, 591, 52, 724, 246,2031,2032,
2033,2034,1167, 969,2035,1289, 630, 605, 911,1091,1168,2036,2037,2038,1441, 912,
2039, 623,2040,2041, 253,1169,1290,2042,1442, 146, 620, 611, 577, 433,2043,1224,
719,1170, 959, 440, 437, 534, 84, 388, 480,1131, 159, 220, 198, 679,2044,1012,
819,1066,1443, 113,1225, 194, 318,1003,1029,2045,2046,2047,2048,1067,2049,2050,
2051,2052,2053, 59, 913, 112,2054, 632,2055, 455, 144, 739,1291,2056, 273, 681,
499,2057, 448,2058,2059, 760,2060,2061, 970, 384, 169, 245,1132,2062,2063, 414,
1444,2064,2065, 41, 235,2066, 157, 252, 877, 568, 919, 789, 580,2067, 725,2068,
2069,1292,2070,2071,1445,2072,1446,2073,2074, 55, 588, 66,1447, 271,1092,2075,
1226,2076, 960,1013, 372,2077,2078,2079,2080,2081,1293,2082,2083,2084,2085, 850,
2086,2087,2088,2089,2090, 186,2091,1068, 180,2092,2093,2094, 109,1227, 522, 606,
2095, 867,1448,1093, 991,1171, 926, 353,1133,2096, 581,2097,2098,2099,1294,1449,
1450,2100, 596,1172,1014,1228,2101,1451,1295,1173,1229,2102,2103,1296,1134,1452,
949,1135,2104,2105,1094,1453,1454,1455,2106,1095,2107,2108,2109,2110,2111,2112,
2113,2114,2115,2116,2117, 804,2118,2119,1230,1231, 805,1456, 405,1136,2120,2121,
2122,2123,2124, 720, 701,1297, 992,1457, 927,1004,2125,2126,2127,2128,2129,2130,
22, 417,2131, 303,2132, 385,2133, 971, 520, 513,2134,1174, 73,1096, 231, 274,
962,1458, 673,2135,1459,2136, 152,1137,2137,2138,2139,2140,1005,1138,1460,1139,
2141,2142,2143,2144, 11, 374, 844,2145, 154,1232, 46,1461,2146, 838, 830, 721,
1233, 106,2147, 90, 428, 462, 578, 566,1175, 352,2148,2149, 538,1234, 124,1298,
2150,1462, 761, 565,2151, 686,2152, 649,2153, 72, 173,2154, 460, 415,2155,1463,
2156,1235, 305,2157,2158,2159,2160,2161,2162, 579,2163,2164,2165,2166,2167, 747,
2168,2169,2170,2171,1464, 669,2172,2173,2174,2175,2176,1465,2177, 23, 530, 285,
2178, 335, 729,2179, 397,2180,2181,2182,1030,2183,2184, 698,2185,2186, 325,2187,
2188, 369,2189, 799,1097,1015, 348,2190,1069, 680,2191, 851,1466,2192,2193, 10,
2194, 613, 424,2195, 979, 108, 449, 589, 27, 172, 81,1031, 80, 774, 281, 350,
1032, 525, 301, 582,1176,2196, 674,1045,2197,2198,1467, 730, 762,2199,2200,2201,
2202,1468,2203, 993,2204,2205, 266,1070, 963,1140,2206,2207,2208, 664,1098, 972,
2209,2210,2211,1177,1469,1470, 871,2212,2213,2214,2215,2216,1471,2217,2218,2219,
2220,2221,2222,2223,2224,2225,2226,2227,1472,1236,2228,2229,2230,2231,2232,2233,
2234,2235,1299,2236,2237, 200,2238, 477, 373,2239,2240, 731, 825, 777,2241,2242,
2243, 521, 486, 548,2244,2245,2246,1473,1300, 53, 549, 137, 875, 76, 158,2247,
1301,1474, 469, 396,1016, 278, 712,2248, 321, 442, 503, 767, 744, 941,1237,1178,
1475,2249, 82, 178,1141,1179, 973,2250,1302,2251, 297,2252,2253, 570,2254,2255,
2256, 18, 450, 206,2257, 290, 292,1142,2258, 511, 162, 99, 346, 164, 735,2259,
1476,1477, 4, 554, 343, 798,1099,2260,1100,2261, 43, 171,1303, 139, 215,2262,
2263, 717, 775,2264,1033, 322, 216,2265, 831,2266, 149,2267,1304,2268,2269, 702,
1238, 135, 845, 347, 309,2270, 484,2271, 878, 655, 238,1006,1478,2272, 67,2273,
295,2274,2275, 461,2276, 478, 942, 412,2277,1034,2278,2279,2280, 265,2281, 541,
2282,2283,2284,2285,2286, 70, 852,1071,2287,2288,2289,2290, 21, 56, 509, 117,
432,2291,2292, 331, 980, 552,1101, 148, 284, 105, 393,1180,1239, 755,2293, 187,
2294,1046,1479,2295, 340,2296, 63,1047, 230,2297,2298,1305, 763,1306, 101, 800,
808, 494,2299,2300,2301, 903,2302, 37,1072, 14, 5,2303, 79, 675,2304, 312,
2305,2306,2307,2308,2309,1480, 6,1307,2310,2311,2312, 1, 470, 35, 24, 229,
2313, 695, 210, 86, 778, 15, 784, 592, 779, 32, 77, 855, 964,2314, 259,2315,
501, 380,2316,2317, 83, 981, 153, 689,1308,1481,1482,1483,2318,2319, 716,1484,
2320,2321,2322,2323,2324,2325,1485,2326,2327, 128, 57, 68, 261,1048, 211, 170,
1240, 31,2328, 51, 435, 742,2329,2330,2331, 635,2332, 264, 456,2333,2334,2335,
425,2336,1486, 143, 507, 263, 943,2337, 363, 920,1487, 256,1488,1102, 243, 601,
1489,2338,2339,2340,2341,2342,2343,2344, 861,2345,2346,2347,2348,2349,2350, 395,
2351,1490,1491, 62, 535, 166, 225,2352,2353, 668, 419,1241, 138, 604, 928,2354,
1181,2355,1492,1493,2356,2357,2358,1143,2359, 696,2360, 387, 307,1309, 682, 476,
2361,2362, 332, 12, 222, 156,2363, 232,2364, 641, 276, 656, 517,1494,1495,1035,
416, 736,1496,2365,1017, 586,2366,2367,2368,1497,2369, 242,2370,2371,2372,1498,
2373, 965, 713,2374,2375,2376,2377, 740, 982,1499, 944,1500,1007,2378,2379,1310,
1501,2380,2381,2382, 785, 329,2383,2384,1502,2385,2386,2387, 932,2388,1503,2389,
2390,2391,2392,1242,2393,2394,2395,2396,2397, 994, 950,2398,2399,2400,2401,1504,
1311,2402,2403,2404,2405,1049, 749,2406,2407, 853, 718,1144,1312,2408,1182,1505,
2409,2410, 255, 516, 479, 564, 550, 214,1506,1507,1313, 413, 239, 444, 339,1145,
1036,1508,1509,1314,1037,1510,1315,2411,1511,2412,2413,2414, 176, 703, 497, 624,
593, 921, 302,2415, 341, 165,1103,1512,2416,1513,2417,2418,2419, 376,2420, 700,
2421,2422,2423, 258, 768,1316,2424,1183,2425, 995, 608,2426,2427,2428,2429, 221,
2430,2431,2432,2433,2434,2435,2436,2437, 195, 323, 726, 188, 897, 983,1317, 377,
644,1050, 879,2438, 452,2439,2440,2441,2442,2443,2444, 914,2445,2446,2447,2448,
915, 489,2449,1514,1184,2450,2451, 515, 64, 427, 495,2452, 583,2453, 483, 485,
1038, 562, 213,1515, 748, 666,2454,2455,2456,2457, 334,2458, 780, 996,1008, 705,
1243,2459,2460,2461,2462,2463, 114,2464, 493,1146, 366, 163,1516, 961,1104,2465,
291,2466,1318,1105,2467,1517, 365,2468, 355, 951,1244,2469,1319,2470, 631,2471,
2472, 218,1320, 364, 320, 756,1518,1519,1321,1520,1322,2473,2474,2475,2476, 997,
2477,2478,2479,2480, 665,1185,2481, 916,1521,2482,2483,2484, 584, 684,2485,2486,
797,2487,1051,1186,2488,2489,2490,1522,2491,2492, 370,2493,1039,1187, 65,2494,
434, 205, 463,1188,2495, 125, 812, 391, 402, 826, 699, 286, 398, 155, 781, 771,
585,2496, 590, 505,1073,2497, 599, 244, 219, 917,1018, 952, 646,1523,2498,1323,
2499,2500, 49, 984, 354, 741,2501, 625,2502,1324,2503,1019, 190, 357, 757, 491,
95, 782, 868,2504,2505,2506,2507,2508,2509, 134,1524,1074, 422,1525, 898,2510,
161,2511,2512,2513,2514, 769,2515,1526,2516,2517, 411,1325,2518, 472,1527,2519,
2520,2521,2522,2523,2524, 985,2525,2526,2527,2528,2529,2530, 764,2531,1245,2532,
2533, 25, 204, 311,2534, 496,2535,1052,2536,2537,2538,2539,2540,2541,2542, 199,
704, 504, 468, 758, 657,1528, 196, 44, 839,1246, 272, 750,2543, 765, 862,2544,
2545,1326,2546, 132, 615, 933,2547, 732,2548,2549,2550,1189,1529,2551, 283,1247,
1053, 607, 929,2552,2553,2554, 930, 183, 872, 616,1040,1147,2555,1148,1020, 441,
249,1075,2556,2557,2558, 466, 743,2559,2560,2561, 92, 514, 426, 420, 526,2562,
2563,2564,2565,2566,2567,2568, 185,2569,2570,2571,2572, 776,1530, 658,2573, 362,
2574, 361, 922,1076, 793,2575,2576,2577,2578,2579,2580,1531, 251,2581,2582,2583,
2584,1532, 54, 612, 237,1327,2585,2586, 275, 408, 647, 111,2587,1533,1106, 465,
3, 458, 9, 38,2588, 107, 110, 890, 209, 26, 737, 498,2589,1534,2590, 431,
202, 88,1535, 356, 287,1107, 660,1149,2591, 381,1536, 986,1150, 445,1248,1151,
974,2592,2593, 846,2594, 446, 953, 184,1249,1250, 727,2595, 923, 193, 883,2596,
2597,2598, 102, 324, 539, 817,2599, 421,1041,2600, 832,2601, 94, 175, 197, 406,
2602, 459,2603,2604,2605,2606,2607, 330, 555,2608,2609,2610, 706,1108, 389,2611,
2612,2613,2614, 233,2615, 833, 558, 931, 954,1251,2616,2617,1537, 546,2618,2619,
1009,2620,2621,2622,1538, 690,1328,2623, 955,2624,1539,2625,2626, 772,2627,2628,
2629,2630,2631, 924, 648, 863, 603,2632,2633, 934,1540, 864, 865,2634, 642,1042,
670,1190,2635,2636,2637,2638, 168,2639, 652, 873, 542,1054,1541,2640,2641,2642, # 512, 256
#Everything below is of no interest for detection purpose
2643,2644,2645,2646,2647,2648,2649,2650,2651,2652,2653,2654,2655,2656,2657,2658,
2659,2660,2661,2662,2663,2664,2665,2666,2667,2668,2669,2670,2671,2672,2673,2674,
2675,2676,2677,2678,2679,2680,2681,2682,2683,2684,2685,2686,2687,2688,2689,2690,
2691,2692,2693,2694,2695,2696,2697,2698,2699,1542, 880,2700,2701,2702,2703,2704,
2705,2706,2707,2708,2709,2710,2711,2712,2713,2714,2715,2716,2717,2718,2719,2720,
2721,2722,2723,2724,2725,1543,2726,2727,2728,2729,2730,2731,2732,1544,2733,2734,
2735,2736,2737,2738,2739,2740,2741,2742,2743,2744,2745,2746,2747,2748,2749,2750,
2751,2752,2753,2754,1545,2755,2756,2757,2758,2759,2760,2761,2762,2763,2764,2765,
2766,1546,2767,1547,2768,2769,2770,2771,2772,2773,2774,2775,2776,2777,2778,2779,
2780,2781,2782,2783,2784,2785,2786,1548,2787,2788,2789,1109,2790,2791,2792,2793,
2794,2795,2796,2797,2798,2799,2800,2801,2802,2803,2804,2805,2806,2807,2808,2809,
2810,2811,2812,1329,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,2824,
2825,2826,2827,2828,2829,2830,2831,2832,2833,2834,2835,2836,2837,2838,2839,2840,
2841,2842,2843,2844,2845,2846,2847,2848,2849,2850,2851,2852,2853,2854,2855,2856,
1549,2857,2858,2859,2860,1550,2861,2862,1551,2863,2864,2865,2866,2867,2868,2869,
2870,2871,2872,2873,2874,1110,1330,2875,2876,2877,2878,2879,2880,2881,2882,2883,
2884,2885,2886,2887,2888,2889,2890,2891,2892,2893,2894,2895,2896,2897,2898,2899,
2900,2901,2902,2903,2904,2905,2906,2907,2908,2909,2910,2911,2912,2913,2914,2915,
2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,1331,
2931,2932,2933,2934,2935,2936,2937,2938,2939,2940,2941,2942,2943,1552,2944,2945,
2946,2947,2948,2949,2950,2951,2952,2953,2954,2955,2956,2957,2958,2959,2960,2961,
2962,2963,2964,1252,2965,2966,2967,2968,2969,2970,2971,2972,2973,2974,2975,2976,
2977,2978,2979,2980,2981,2982,2983,2984,2985,2986,2987,2988,2989,2990,2991,2992,
2993,2994,2995,2996,2997,2998,2999,3000,3001,3002,3003,3004,3005,3006,3007,3008,
3009,3010,3011,3012,1553,3013,3014,3015,3016,3017,1554,3018,1332,3019,3020,3021,
3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,
3038,3039,3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,3050,1555,3051,3052,
3053,1556,1557,3054,3055,3056,3057,3058,3059,3060,3061,3062,3063,3064,3065,3066,
3067,1558,3068,3069,3070,3071,3072,3073,3074,3075,3076,1559,3077,3078,3079,3080,
3081,3082,3083,1253,3084,3085,3086,3087,3088,3089,3090,3091,3092,3093,3094,3095,
3096,3097,3098,3099,3100,3101,3102,3103,3104,3105,3106,3107,3108,1152,3109,3110,
3111,3112,3113,1560,3114,3115,3116,3117,1111,3118,3119,3120,3121,3122,3123,3124,
3125,3126,3127,3128,3129,3130,3131,3132,3133,3134,3135,3136,3137,3138,3139,3140,
3141,3142,3143,3144,3145,3146,3147,3148,3149,3150,3151,3152,3153,3154,3155,3156,
3157,3158,3159,3160,3161,3162,3163,3164,3165,3166,3167,3168,3169,3170,3171,3172,
3173,3174,3175,3176,1333,3177,3178,3179,3180,3181,3182,3183,3184,3185,3186,3187,
3188,3189,1561,3190,3191,1334,3192,3193,3194,3195,3196,3197,3198,3199,3200,3201,
3202,3203,3204,3205,3206,3207,3208,3209,3210,3211,3212,3213,3214,3215,3216,3217,
3218,3219,3220,3221,3222,3223,3224,3225,3226,3227,3228,3229,3230,3231,3232,3233,
3234,1562,3235,3236,3237,3238,3239,3240,3241,3242,3243,3244,3245,3246,3247,3248,
3249,3250,3251,3252,3253,3254,3255,3256,3257,3258,3259,3260,3261,3262,3263,3264,
3265,3266,3267,3268,3269,3270,3271,3272,3273,3274,3275,3276,3277,1563,3278,3279,
3280,3281,3282,3283,3284,3285,3286,3287,3288,3289,3290,3291,3292,3293,3294,3295,
3296,3297,3298,3299,3300,3301,3302,3303,3304,3305,3306,3307,3308,3309,3310,3311,
3312,3313,3314,3315,3316,3317,3318,3319,3320,3321,3322,3323,3324,3325,3326,3327,
3328,3329,3330,3331,3332,3333,3334,3335,3336,3337,3338,3339,3340,3341,3342,3343,
3344,3345,3346,3347,3348,3349,3350,3351,3352,3353,3354,3355,3356,3357,3358,3359,
3360,3361,3362,3363,3364,1335,3365,3366,3367,3368,3369,3370,3371,3372,3373,3374,
3375,3376,3377,3378,3379,3380,3381,3382,3383,3384,3385,3386,3387,1336,3388,3389,
3390,3391,3392,3393,3394,3395,3396,3397,3398,3399,3400,3401,3402,3403,3404,3405,
3406,3407,3408,3409,3410,3411,3412,3413,3414,1337,3415,3416,3417,3418,3419,1338,
3420,3421,3422,1564,1565,3423,3424,3425,3426,3427,3428,3429,3430,3431,1254,3432,
3433,3434,1339,3435,3436,3437,3438,3439,1566,3440,3441,3442,3443,3444,3445,3446,
3447,3448,3449,3450,3451,3452,3453,3454,1255,3455,3456,3457,3458,3459,1567,1191,
3460,1568,1569,3461,3462,3463,1570,3464,3465,3466,3467,3468,1571,3469,3470,3471,
3472,3473,1572,3474,3475,3476,3477,3478,3479,3480,3481,3482,3483,3484,3485,3486,
1340,3487,3488,3489,3490,3491,3492,1021,3493,3494,3495,3496,3497,3498,1573,3499,
1341,3500,3501,3502,3503,3504,3505,3506,3507,3508,3509,3510,3511,1342,3512,3513,
3514,3515,3516,1574,1343,3517,3518,3519,1575,3520,1576,3521,3522,3523,3524,3525,
3526,3527,3528,3529,3530,3531,3532,3533,3534,3535,3536,3537,3538,3539,3540,3541,
3542,3543,3544,3545,3546,3547,3548,3549,3550,3551,3552,3553,3554,3555,3556,3557,
3558,3559,3560,3561,3562,3563,3564,3565,3566,3567,3568,3569,3570,3571,3572,3573,
3574,3575,3576,3577,3578,3579,3580,1577,3581,3582,1578,3583,3584,3585,3586,3587,
3588,3589,3590,3591,3592,3593,3594,3595,3596,3597,3598,3599,3600,3601,3602,3603,
3604,1579,3605,3606,3607,3608,3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,
3619,3620,3621,3622,3623,3624,3625,3626,3627,3628,3629,1580,3630,3631,1581,3632,
3633,3634,3635,3636,3637,3638,3639,3640,3641,3642,3643,3644,3645,3646,3647,3648,
3649,3650,3651,3652,3653,3654,3655,3656,1582,3657,3658,3659,3660,3661,3662,3663,
3664,3665,3666,3667,3668,3669,3670,3671,3672,3673,3674,3675,3676,3677,3678,3679,
3680,3681,3682,3683,3684,3685,3686,3687,3688,3689,3690,3691,3692,3693,3694,3695,
3696,3697,3698,3699,3700,1192,3701,3702,3703,3704,1256,3705,3706,3707,3708,1583,
1257,3709,3710,3711,3712,3713,3714,3715,3716,1584,3717,3718,3719,3720,3721,3722,
3723,3724,3725,3726,3727,3728,3729,3730,3731,3732,3733,3734,3735,3736,3737,3738,
3739,3740,3741,3742,3743,3744,3745,1344,3746,3747,3748,3749,3750,3751,3752,3753,
3754,3755,3756,1585,3757,3758,3759,3760,3761,3762,3763,3764,3765,3766,1586,3767,
3768,3769,3770,3771,3772,3773,3774,3775,3776,3777,3778,1345,3779,3780,3781,3782,
3783,3784,3785,3786,3787,3788,3789,3790,3791,3792,3793,3794,3795,1346,1587,3796,
3797,1588,3798,3799,3800,3801,3802,3803,3804,3805,3806,1347,3807,3808,3809,3810,
3811,1589,3812,3813,3814,3815,3816,3817,3818,3819,3820,3821,1590,3822,3823,1591,
1348,3824,3825,3826,3827,3828,3829,3830,1592,3831,3832,1593,3833,3834,3835,3836,
3837,3838,3839,3840,3841,3842,3843,3844,1349,3845,3846,3847,3848,3849,3850,3851,
3852,3853,3854,3855,3856,3857,3858,1594,3859,3860,3861,3862,3863,3864,3865,3866,
3867,3868,3869,1595,3870,3871,3872,3873,1596,3874,3875,3876,3877,3878,3879,3880,
3881,3882,3883,3884,3885,3886,1597,3887,3888,3889,3890,3891,3892,3893,3894,3895,
1598,3896,3897,3898,1599,1600,3899,1350,3900,1351,3901,3902,1352,3903,3904,3905,
3906,3907,3908,3909,3910,3911,3912,3913,3914,3915,3916,3917,3918,3919,3920,3921,
3922,3923,3924,1258,3925,3926,3927,3928,3929,3930,3931,1193,3932,1601,3933,3934,
3935,3936,3937,3938,3939,3940,3941,3942,3943,1602,3944,3945,3946,3947,3948,1603,
3949,3950,3951,3952,3953,3954,3955,3956,3957,3958,3959,3960,3961,3962,3963,3964,
3965,1604,3966,3967,3968,3969,3970,3971,3972,3973,3974,3975,3976,3977,1353,3978,
3979,3980,3981,3982,3983,3984,3985,3986,3987,3988,3989,3990,3991,1354,3992,3993,
3994,3995,3996,3997,3998,3999,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,
4010,4011,4012,4013,4014,4015,4016,4017,4018,4019,4020,4021,4022,4023,1355,4024,
4025,4026,4027,4028,4029,4030,4031,4032,4033,4034,4035,4036,4037,4038,4039,4040,
1605,4041,4042,4043,4044,4045,4046,4047,4048,4049,4050,4051,4052,4053,4054,4055,
4056,4057,4058,4059,4060,1606,4061,4062,4063,4064,1607,4065,4066,4067,4068,4069,
4070,4071,4072,4073,4074,4075,4076,1194,4077,4078,1608,4079,4080,4081,4082,4083,
4084,4085,4086,4087,1609,4088,4089,4090,4091,4092,4093,4094,4095,4096,4097,4098,
4099,4100,4101,4102,4103,4104,4105,4106,4107,4108,1259,4109,4110,4111,4112,4113,
4114,4115,4116,4117,4118,4119,4120,4121,4122,4123,4124,1195,4125,4126,4127,1610,
4128,4129,4130,4131,4132,4133,4134,4135,4136,4137,1356,4138,4139,4140,4141,4142,
4143,4144,1611,4145,4146,4147,4148,4149,4150,4151,4152,4153,4154,4155,4156,4157,
4158,4159,4160,4161,4162,4163,4164,4165,4166,4167,4168,4169,4170,4171,4172,4173,
4174,4175,4176,4177,4178,4179,4180,4181,4182,4183,4184,4185,4186,4187,4188,4189,
4190,4191,4192,4193,4194,4195,4196,4197,4198,4199,4200,4201,4202,4203,4204,4205,
4206,4207,4208,4209,4210,4211,4212,4213,4214,4215,4216,4217,4218,4219,1612,4220,
4221,4222,4223,4224,4225,4226,4227,1357,4228,1613,4229,4230,4231,4232,4233,4234,
4235,4236,4237,4238,4239,4240,4241,4242,4243,1614,4244,4245,4246,4247,4248,4249,
4250,4251,4252,4253,4254,4255,4256,4257,4258,4259,4260,4261,4262,4263,4264,4265,
4266,4267,4268,4269,4270,1196,1358,4271,4272,4273,4274,4275,4276,4277,4278,4279,
4280,4281,4282,4283,4284,4285,4286,4287,1615,4288,4289,4290,4291,4292,4293,4294,
4295,4296,4297,4298,4299,4300,4301,4302,4303,4304,4305,4306,4307,4308,4309,4310,
4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,4324,4325,4326,
4327,4328,4329,4330,4331,4332,4333,4334,1616,4335,4336,4337,4338,4339,4340,4341,
4342,4343,4344,4345,4346,4347,4348,4349,4350,4351,4352,4353,4354,4355,4356,4357,
4358,4359,4360,1617,4361,4362,4363,4364,4365,1618,4366,4367,4368,4369,4370,4371,
4372,4373,4374,4375,4376,4377,4378,4379,4380,4381,4382,4383,4384,4385,4386,4387,
4388,4389,4390,4391,4392,4393,4394,4395,4396,4397,4398,4399,4400,4401,4402,4403,
4404,4405,4406,4407,4408,4409,4410,4411,4412,4413,4414,4415,4416,1619,4417,4418,
4419,4420,4421,4422,4423,4424,4425,1112,4426,4427,4428,4429,4430,1620,4431,4432,
4433,4434,4435,4436,4437,4438,4439,4440,4441,4442,1260,1261,4443,4444,4445,4446,
4447,4448,4449,4450,4451,4452,4453,4454,4455,1359,4456,4457,4458,4459,4460,4461,
4462,4463,4464,4465,1621,4466,4467,4468,4469,4470,4471,4472,4473,4474,4475,4476,
4477,4478,4479,4480,4481,4482,4483,4484,4485,4486,4487,4488,4489,1055,4490,4491,
4492,4493,4494,4495,4496,4497,4498,4499,4500,4501,4502,4503,4504,4505,4506,4507,
4508,4509,4510,4511,4512,4513,4514,4515,4516,4517,4518,1622,4519,4520,4521,1623,
4522,4523,4524,4525,4526,4527,4528,4529,4530,4531,4532,4533,4534,4535,1360,4536,
4537,4538,4539,4540,4541,4542,4543, 975,4544,4545,4546,4547,4548,4549,4550,4551,
4552,4553,4554,4555,4556,4557,4558,4559,4560,4561,4562,4563,4564,4565,4566,4567,
4568,4569,4570,4571,1624,4572,4573,4574,4575,4576,1625,4577,4578,4579,4580,4581,
4582,4583,4584,1626,4585,4586,4587,4588,4589,4590,4591,4592,4593,4594,4595,1627,
4596,4597,4598,4599,4600,4601,4602,4603,4604,4605,4606,4607,4608,4609,4610,4611,
4612,4613,4614,4615,1628,4616,4617,4618,4619,4620,4621,4622,4623,4624,4625,4626,
4627,4628,4629,4630,4631,4632,4633,4634,4635,4636,4637,4638,4639,4640,4641,4642,
4643,4644,4645,4646,4647,4648,4649,1361,4650,4651,4652,4653,4654,4655,4656,4657,
4658,4659,4660,4661,1362,4662,4663,4664,4665,4666,4667,4668,4669,4670,4671,4672,
4673,4674,4675,4676,4677,4678,4679,4680,4681,4682,1629,4683,4684,4685,4686,4687,
1630,4688,4689,4690,4691,1153,4692,4693,4694,1113,4695,4696,4697,4698,4699,4700,
4701,4702,4703,4704,4705,4706,4707,4708,4709,4710,4711,1197,4712,4713,4714,4715,
4716,4717,4718,4719,4720,4721,4722,4723,4724,4725,4726,4727,4728,4729,4730,4731,
4732,4733,4734,4735,1631,4736,1632,4737,4738,4739,4740,4741,4742,4743,4744,1633,
4745,4746,4747,4748,4749,1262,4750,4751,4752,4753,4754,1363,4755,4756,4757,4758,
4759,4760,4761,4762,4763,4764,4765,4766,4767,4768,1634,4769,4770,4771,4772,4773,
4774,4775,4776,4777,4778,1635,4779,4780,4781,4782,4783,4784,4785,4786,4787,4788,
4789,1636,4790,4791,4792,4793,4794,4795,4796,4797,4798,4799,4800,4801,4802,4803,
4804,4805,4806,1637,4807,4808,4809,1638,4810,4811,4812,4813,4814,4815,4816,4817,
4818,1639,4819,4820,4821,4822,4823,4824,4825,4826,4827,4828,4829,4830,4831,4832,
4833,1077,4834,4835,4836,4837,4838,4839,4840,4841,4842,4843,4844,4845,4846,4847,
4848,4849,4850,4851,4852,4853,4854,4855,4856,4857,4858,4859,4860,4861,4862,4863,
4864,4865,4866,4867,4868,4869,4870,4871,4872,4873,4874,4875,4876,4877,4878,4879,
4880,4881,4882,4883,1640,4884,4885,1641,4886,4887,4888,4889,4890,4891,4892,4893,
4894,4895,4896,4897,4898,4899,4900,4901,4902,4903,4904,4905,4906,4907,4908,4909,
4910,4911,1642,4912,4913,4914,1364,4915,4916,4917,4918,4919,4920,4921,4922,4923,
4924,4925,4926,4927,4928,4929,4930,4931,1643,4932,4933,4934,4935,4936,4937,4938,
4939,4940,4941,4942,4943,4944,4945,4946,4947,4948,4949,4950,4951,4952,4953,4954,
4955,4956,4957,4958,4959,4960,4961,4962,4963,4964,4965,4966,4967,4968,4969,4970,
4971,4972,4973,4974,4975,4976,4977,4978,4979,4980,1644,4981,4982,4983,4984,1645,
4985,4986,1646,4987,4988,4989,4990,4991,4992,4993,4994,4995,4996,4997,4998,4999,
5000,5001,5002,5003,5004,5005,1647,5006,1648,5007,5008,5009,5010,5011,5012,1078,
5013,5014,5015,5016,5017,5018,5019,5020,5021,5022,5023,5024,5025,5026,5027,5028,
1365,5029,5030,5031,5032,5033,5034,5035,5036,5037,5038,5039,1649,5040,5041,5042,
5043,5044,5045,1366,5046,5047,5048,5049,5050,5051,5052,5053,5054,5055,1650,5056,
5057,5058,5059,5060,5061,5062,5063,5064,5065,5066,5067,5068,5069,5070,5071,5072,
5073,5074,5075,5076,5077,1651,5078,5079,5080,5081,5082,5083,5084,5085,5086,5087,
5088,5089,5090,5091,5092,5093,5094,5095,5096,5097,5098,5099,5100,5101,5102,5103,
5104,5105,5106,5107,5108,5109,5110,1652,5111,5112,5113,5114,5115,5116,5117,5118,
1367,5119,5120,5121,5122,5123,5124,5125,5126,5127,5128,5129,1653,5130,5131,5132,
5133,5134,5135,5136,5137,5138,5139,5140,5141,5142,5143,5144,5145,5146,5147,5148,
5149,1368,5150,1654,5151,1369,5152,5153,5154,5155,5156,5157,5158,5159,5160,5161,
5162,5163,5164,5165,5166,5167,5168,5169,5170,5171,5172,5173,5174,5175,5176,5177,
5178,1370,5179,5180,5181,5182,5183,5184,5185,5186,5187,5188,5189,5190,5191,5192,
5193,5194,5195,5196,5197,5198,1655,5199,5200,5201,5202,1656,5203,5204,5205,5206,
1371,5207,1372,5208,5209,5210,5211,1373,5212,5213,1374,5214,5215,5216,5217,5218,
5219,5220,5221,5222,5223,5224,5225,5226,5227,5228,5229,5230,5231,5232,5233,5234,
5235,5236,5237,5238,5239,5240,5241,5242,5243,5244,5245,5246,5247,1657,5248,5249,
5250,5251,1658,1263,5252,5253,5254,5255,5256,1375,5257,5258,5259,5260,5261,5262,
5263,5264,5265,5266,5267,5268,5269,5270,5271,5272,5273,5274,5275,5276,5277,5278,
5279,5280,5281,5282,5283,1659,5284,5285,5286,5287,5288,5289,5290,5291,5292,5293,
5294,5295,5296,5297,5298,5299,5300,1660,5301,5302,5303,5304,5305,5306,5307,5308,
5309,5310,5311,5312,5313,5314,5315,5316,5317,5318,5319,5320,5321,1376,5322,5323,
5324,5325,5326,5327,5328,5329,5330,5331,5332,5333,1198,5334,5335,5336,5337,5338,
5339,5340,5341,5342,5343,1661,5344,5345,5346,5347,5348,5349,5350,5351,5352,5353,
5354,5355,5356,5357,5358,5359,5360,5361,5362,5363,5364,5365,5366,5367,5368,5369,
5370,5371,5372,5373,5374,5375,5376,5377,5378,5379,5380,5381,5382,5383,5384,5385,
5386,5387,5388,5389,5390,5391,5392,5393,5394,5395,5396,5397,5398,1264,5399,5400,
5401,5402,5403,5404,5405,5406,5407,5408,5409,5410,5411,5412,1662,5413,5414,5415,
5416,1663,5417,5418,5419,5420,5421,5422,5423,5424,5425,5426,5427,5428,5429,5430,
5431,5432,5433,5434,5435,5436,5437,5438,1664,5439,5440,5441,5442,5443,5444,5445,
5446,5447,5448,5449,5450,5451,5452,5453,5454,5455,5456,5457,5458,5459,5460,5461,
5462,5463,5464,5465,5466,5467,5468,5469,5470,5471,5472,5473,5474,5475,5476,5477,
5478,1154,5479,5480,5481,5482,5483,5484,5485,1665,5486,5487,5488,5489,5490,5491,
5492,5493,5494,5495,5496,5497,5498,5499,5500,5501,5502,5503,5504,5505,5506,5507,
5508,5509,5510,5511,5512,5513,5514,5515,5516,5517,5518,5519,5520,5521,5522,5523,
5524,5525,5526,5527,5528,5529,5530,5531,5532,5533,5534,5535,5536,5537,5538,5539,
5540,5541,5542,5543,5544,5545,5546,5547,5548,1377,5549,5550,5551,5552,5553,5554,
5555,5556,5557,5558,5559,5560,5561,5562,5563,5564,5565,5566,5567,5568,5569,5570,
1114,5571,5572,5573,5574,5575,5576,5577,5578,5579,5580,5581,5582,5583,5584,5585,
5586,5587,5588,5589,5590,5591,5592,1378,5593,5594,5595,5596,5597,5598,5599,5600,
5601,5602,5603,5604,5605,5606,5607,5608,5609,5610,5611,5612,5613,5614,1379,5615,
5616,5617,5618,5619,5620,5621,5622,5623,5624,5625,5626,5627,5628,5629,5630,5631,
5632,5633,5634,1380,5635,5636,5637,5638,5639,5640,5641,5642,5643,5644,5645,5646,
5647,5648,5649,1381,1056,5650,5651,5652,5653,5654,5655,5656,5657,5658,5659,5660,
1666,5661,5662,5663,5664,5665,5666,5667,5668,1667,5669,1668,5670,5671,5672,5673,
5674,5675,5676,5677,5678,1155,5679,5680,5681,5682,5683,5684,5685,5686,5687,5688,
5689,5690,5691,5692,5693,5694,5695,5696,5697,5698,1669,5699,5700,5701,5702,5703,
5704,5705,1670,5706,5707,5708,5709,5710,1671,5711,5712,5713,5714,1382,5715,5716,
5717,5718,5719,5720,5721,5722,5723,5724,5725,1672,5726,5727,1673,1674,5728,5729,
5730,5731,5732,5733,5734,5735,5736,1675,5737,5738,5739,5740,5741,5742,5743,5744,
1676,5745,5746,5747,5748,5749,5750,5751,1383,5752,5753,5754,5755,5756,5757,5758,
5759,5760,5761,5762,5763,5764,5765,5766,5767,5768,1677,5769,5770,5771,5772,5773,
1678,5774,5775,5776, 998,5777,5778,5779,5780,5781,5782,5783,5784,5785,1384,5786,
5787,5788,5789,5790,5791,5792,5793,5794,5795,5796,5797,5798,5799,5800,1679,5801,
5802,5803,1115,1116,5804,5805,5806,5807,5808,5809,5810,5811,5812,5813,5814,5815,
5816,5817,5818,5819,5820,5821,5822,5823,5824,5825,5826,5827,5828,5829,5830,5831,
5832,5833,5834,5835,5836,5837,5838,5839,5840,5841,5842,5843,5844,5845,5846,5847,
5848,5849,5850,5851,5852,5853,5854,5855,1680,5856,5857,5858,5859,5860,5861,5862,
5863,5864,1681,5865,5866,5867,1682,5868,5869,5870,5871,5872,5873,5874,5875,5876,
5877,5878,5879,1683,5880,1684,5881,5882,5883,5884,1685,5885,5886,5887,5888,5889,
5890,5891,5892,5893,5894,5895,5896,5897,5898,5899,5900,5901,5902,5903,5904,5905,
5906,5907,1686,5908,5909,5910,5911,5912,5913,5914,5915,5916,5917,5918,5919,5920,
5921,5922,5923,5924,5925,5926,5927,5928,5929,5930,5931,5932,5933,5934,5935,1687,
5936,5937,5938,5939,5940,5941,5942,5943,5944,5945,5946,5947,5948,5949,5950,5951,
5952,1688,1689,5953,1199,5954,5955,5956,5957,5958,5959,5960,5961,1690,5962,5963,
5964,5965,5966,5967,5968,5969,5970,5971,5972,5973,5974,5975,5976,5977,5978,5979,
5980,5981,1385,5982,1386,5983,5984,5985,5986,5987,5988,5989,5990,5991,5992,5993,
5994,5995,5996,5997,5998,5999,6000,6001,6002,6003,6004,6005,6006,6007,6008,6009,
6010,6011,6012,6013,6014,6015,6016,6017,6018,6019,6020,6021,6022,6023,6024,6025,
6026,6027,1265,6028,6029,1691,6030,6031,6032,6033,6034,6035,6036,6037,6038,6039,
6040,6041,6042,6043,6044,6045,6046,6047,6048,6049,6050,6051,6052,6053,6054,6055,
6056,6057,6058,6059,6060,6061,6062,6063,6064,6065,6066,6067,6068,6069,6070,6071,
6072,6073,6074,6075,6076,6077,6078,6079,6080,6081,6082,6083,6084,1692,6085,6086,
6087,6088,6089,6090,6091,6092,6093,6094,6095,6096,6097,6098,6099,6100,6101,6102,
6103,6104,6105,6106,6107,6108,6109,6110,6111,6112,6113,6114,6115,6116,6117,6118,
6119,6120,6121,6122,6123,6124,6125,6126,6127,6128,6129,6130,6131,1693,6132,6133,
6134,6135,6136,1694,6137,6138,6139,6140,6141,1695,6142,6143,6144,6145,6146,6147,
6148,6149,6150,6151,6152,6153,6154,6155,6156,6157,6158,6159,6160,6161,6162,6163,
6164,6165,6166,6167,6168,6169,6170,6171,6172,6173,6174,6175,6176,6177,6178,6179,
6180,6181,6182,6183,6184,6185,1696,6186,6187,6188,6189,6190,6191,6192,6193,6194,
6195,6196,6197,6198,6199,6200,6201,6202,6203,6204,6205,6206,6207,6208,6209,6210,
6211,6212,6213,6214,6215,6216,6217,6218,6219,1697,6220,6221,6222,6223,6224,6225,
6226,6227,6228,6229,6230,6231,6232,6233,6234,6235,6236,6237,6238,6239,6240,6241,
6242,6243,6244,6245,6246,6247,6248,6249,6250,6251,6252,6253,1698,6254,6255,6256,
6257,6258,6259,6260,6261,6262,6263,1200,6264,6265,6266,6267,6268,6269,6270,6271, #1024
6272,6273,6274,6275,6276,6277,6278,6279,6280,6281,6282,6283,6284,6285,6286,6287,
6288,6289,6290,6291,6292,6293,6294,6295,6296,6297,6298,6299,6300,6301,6302,1699,
6303,6304,1700,6305,6306,6307,6308,6309,6310,6311,6312,6313,6314,6315,6316,6317,
6318,6319,6320,6321,6322,6323,6324,6325,6326,6327,6328,6329,6330,6331,6332,6333,
6334,6335,6336,6337,6338,6339,1701,6340,6341,6342,6343,6344,1387,6345,6346,6347,
6348,6349,6350,6351,6352,6353,6354,6355,6356,6357,6358,6359,6360,6361,6362,6363,
6364,6365,6366,6367,6368,6369,6370,6371,6372,6373,6374,6375,6376,6377,6378,6379,
6380,6381,6382,6383,6384,6385,6386,6387,6388,6389,6390,6391,6392,6393,6394,6395,
6396,6397,6398,6399,6400,6401,6402,6403,6404,6405,6406,6407,6408,6409,6410,6411,
6412,6413,1702,6414,6415,6416,6417,6418,6419,6420,6421,6422,1703,6423,6424,6425,
6426,6427,6428,6429,6430,6431,6432,6433,6434,6435,6436,6437,6438,1704,6439,6440,
6441,6442,6443,6444,6445,6446,6447,6448,6449,6450,6451,6452,6453,6454,6455,6456,
6457,6458,6459,6460,6461,6462,6463,6464,6465,6466,6467,6468,6469,6470,6471,6472,
6473,6474,6475,6476,6477,6478,6479,6480,6481,6482,6483,6484,6485,6486,6487,6488,
6489,6490,6491,6492,6493,6494,6495,6496,6497,6498,6499,6500,6501,6502,6503,1266,
6504,6505,6506,6507,6508,6509,6510,6511,6512,6513,6514,6515,6516,6517,6518,6519,
6520,6521,6522,6523,6524,6525,6526,6527,6528,6529,6530,6531,6532,6533,6534,6535,
6536,6537,6538,6539,6540,6541,6542,6543,6544,6545,6546,6547,6548,6549,6550,6551,
1705,1706,6552,6553,6554,6555,6556,6557,6558,6559,6560,6561,6562,6563,6564,6565,
6566,6567,6568,6569,6570,6571,6572,6573,6574,6575,6576,6577,6578,6579,6580,6581,
6582,6583,6584,6585,6586,6587,6588,6589,6590,6591,6592,6593,6594,6595,6596,6597,
6598,6599,6600,6601,6602,6603,6604,6605,6606,6607,6608,6609,6610,6611,6612,6613,
6614,6615,6616,6617,6618,6619,6620,6621,6622,6623,6624,6625,6626,6627,6628,6629,
6630,6631,6632,6633,6634,6635,6636,6637,1388,6638,6639,6640,6641,6642,6643,6644,
1707,6645,6646,6647,6648,6649,6650,6651,6652,6653,6654,6655,6656,6657,6658,6659,
6660,6661,6662,6663,1708,6664,6665,6666,6667,6668,6669,6670,6671,6672,6673,6674,
1201,6675,6676,6677,6678,6679,6680,6681,6682,6683,6684,6685,6686,6687,6688,6689,
6690,6691,6692,6693,6694,6695,6696,6697,6698,6699,6700,6701,6702,6703,6704,6705,
6706,6707,6708,6709,6710,6711,6712,6713,6714,6715,6716,6717,6718,6719,6720,6721,
6722,6723,6724,6725,1389,6726,6727,6728,6729,6730,6731,6732,6733,6734,6735,6736,
1390,1709,6737,6738,6739,6740,6741,6742,1710,6743,6744,6745,6746,1391,6747,6748,
6749,6750,6751,6752,6753,6754,6755,6756,6757,1392,6758,6759,6760,6761,6762,6763,
6764,6765,6766,6767,6768,6769,6770,6771,6772,6773,6774,6775,6776,6777,6778,6779,
6780,1202,6781,6782,6783,6784,6785,6786,6787,6788,6789,6790,6791,6792,6793,6794,
6795,6796,6797,6798,6799,6800,6801,6802,6803,6804,6805,6806,6807,6808,6809,1711,
6810,6811,6812,6813,6814,6815,6816,6817,6818,6819,6820,6821,6822,6823,6824,6825,
6826,6827,6828,6829,6830,6831,6832,6833,6834,6835,6836,1393,6837,6838,6839,6840,
6841,6842,6843,6844,6845,6846,6847,6848,6849,6850,6851,6852,6853,6854,6855,6856,
6857,6858,6859,6860,6861,6862,6863,6864,6865,6866,6867,6868,6869,6870,6871,6872,
6873,6874,6875,6876,6877,6878,6879,6880,6881,6882,6883,6884,6885,6886,6887,6888,
6889,6890,6891,6892,6893,6894,6895,6896,6897,6898,6899,6900,6901,6902,1712,6903,
6904,6905,6906,6907,6908,6909,6910,1713,6911,6912,6913,6914,6915,6916,6917,6918,
6919,6920,6921,6922,6923,6924,6925,6926,6927,6928,6929,6930,6931,6932,6933,6934,
6935,6936,6937,6938,6939,6940,6941,6942,6943,6944,6945,6946,6947,6948,6949,6950,
6951,6952,6953,6954,6955,6956,6957,6958,6959,6960,6961,6962,6963,6964,6965,6966,
6967,6968,6969,6970,6971,6972,6973,6974,1714,6975,6976,6977,6978,6979,6980,6981,
6982,6983,6984,6985,6986,6987,6988,1394,6989,6990,6991,6992,6993,6994,6995,6996,
6997,6998,6999,7000,1715,7001,7002,7003,7004,7005,7006,7007,7008,7009,7010,7011,
7012,7013,7014,7015,7016,7017,7018,7019,7020,7021,7022,7023,7024,7025,7026,7027,
7028,1716,7029,7030,7031,7032,7033,7034,7035,7036,7037,7038,7039,7040,7041,7042,
7043,7044,7045,7046,7047,7048,7049,7050,7051,7052,7053,7054,7055,7056,7057,7058,
7059,7060,7061,7062,7063,7064,7065,7066,7067,7068,7069,7070,7071,7072,7073,7074,
7075,7076,7077,7078,7079,7080,7081,7082,7083,7084,7085,7086,7087,7088,7089,7090,
7091,7092,7093,7094,7095,7096,7097,7098,7099,7100,7101,7102,7103,7104,7105,7106,
7107,7108,7109,7110,7111,7112,7113,7114,7115,7116,7117,7118,7119,7120,7121,7122,
7123,7124,7125,7126,7127,7128,7129,7130,7131,7132,7133,7134,7135,7136,7137,7138,
7139,7140,7141,7142,7143,7144,7145,7146,7147,7148,7149,7150,7151,7152,7153,7154,
7155,7156,7157,7158,7159,7160,7161,7162,7163,7164,7165,7166,7167,7168,7169,7170,
7171,7172,7173,7174,7175,7176,7177,7178,7179,7180,7181,7182,7183,7184,7185,7186,
7187,7188,7189,7190,7191,7192,7193,7194,7195,7196,7197,7198,7199,7200,7201,7202,
7203,7204,7205,7206,7207,1395,7208,7209,7210,7211,7212,7213,1717,7214,7215,7216,
7217,7218,7219,7220,7221,7222,7223,7224,7225,7226,7227,7228,7229,7230,7231,7232,
7233,7234,7235,7236,7237,7238,7239,7240,7241,7242,7243,7244,7245,7246,7247,7248,
7249,7250,7251,7252,7253,7254,7255,7256,7257,7258,7259,7260,7261,7262,7263,7264,
7265,7266,7267,7268,7269,7270,7271,7272,7273,7274,7275,7276,7277,7278,7279,7280,
7281,7282,7283,7284,7285,7286,7287,7288,7289,7290,7291,7292,7293,7294,7295,7296,
7297,7298,7299,7300,7301,7302,7303,7304,7305,7306,7307,7308,7309,7310,7311,7312,
7313,1718,7314,7315,7316,7317,7318,7319,7320,7321,7322,7323,7324,7325,7326,7327,
7328,7329,7330,7331,7332,7333,7334,7335,7336,7337,7338,7339,7340,7341,7342,7343,
7344,7345,7346,7347,7348,7349,7350,7351,7352,7353,7354,7355,7356,7357,7358,7359,
7360,7361,7362,7363,7364,7365,7366,7367,7368,7369,7370,7371,7372,7373,7374,7375,
7376,7377,7378,7379,7380,7381,7382,7383,7384,7385,7386,7387,7388,7389,7390,7391,
7392,7393,7394,7395,7396,7397,7398,7399,7400,7401,7402,7403,7404,7405,7406,7407,
7408,7409,7410,7411,7412,7413,7414,7415,7416,7417,7418,7419,7420,7421,7422,7423,
7424,7425,7426,7427,7428,7429,7430,7431,7432,7433,7434,7435,7436,7437,7438,7439,
7440,7441,7442,7443,7444,7445,7446,7447,7448,7449,7450,7451,7452,7453,7454,7455,
7456,7457,7458,7459,7460,7461,7462,7463,7464,7465,7466,7467,7468,7469,7470,7471,
7472,7473,7474,7475,7476,7477,7478,7479,7480,7481,7482,7483,7484,7485,7486,7487,
7488,7489,7490,7491,7492,7493,7494,7495,7496,7497,7498,7499,7500,7501,7502,7503,
7504,7505,7506,7507,7508,7509,7510,7511,7512,7513,7514,7515,7516,7517,7518,7519,
7520,7521,7522,7523,7524,7525,7526,7527,7528,7529,7530,7531,7532,7533,7534,7535,
7536,7537,7538,7539,7540,7541,7542,7543,7544,7545,7546,7547,7548,7549,7550,7551,
7552,7553,7554,7555,7556,7557,7558,7559,7560,7561,7562,7563,7564,7565,7566,7567,
7568,7569,7570,7571,7572,7573,7574,7575,7576,7577,7578,7579,7580,7581,7582,7583,
7584,7585,7586,7587,7588,7589,7590,7591,7592,7593,7594,7595,7596,7597,7598,7599,
7600,7601,7602,7603,7604,7605,7606,7607,7608,7609,7610,7611,7612,7613,7614,7615,
7616,7617,7618,7619,7620,7621,7622,7623,7624,7625,7626,7627,7628,7629,7630,7631,
7632,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643,7644,7645,7646,7647,
7648,7649,7650,7651,7652,7653,7654,7655,7656,7657,7658,7659,7660,7661,7662,7663,
7664,7665,7666,7667,7668,7669,7670,7671,7672,7673,7674,7675,7676,7677,7678,7679,
7680,7681,7682,7683,7684,7685,7686,7687,7688,7689,7690,7691,7692,7693,7694,7695,
7696,7697,7698,7699,7700,7701,7702,7703,7704,7705,7706,7707,7708,7709,7710,7711,
7712,7713,7714,7715,7716,7717,7718,7719,7720,7721,7722,7723,7724,7725,7726,7727,
7728,7729,7730,7731,7732,7733,7734,7735,7736,7737,7738,7739,7740,7741,7742,7743,
7744,7745,7746,7747,7748,7749,7750,7751,7752,7753,7754,7755,7756,7757,7758,7759,
7760,7761,7762,7763,7764,7765,7766,7767,7768,7769,7770,7771,7772,7773,7774,7775,
7776,7777,7778,7779,7780,7781,7782,7783,7784,7785,7786,7787,7788,7789,7790,7791,
7792,7793,7794,7795,7796,7797,7798,7799,7800,7801,7802,7803,7804,7805,7806,7807,
7808,7809,7810,7811,7812,7813,7814,7815,7816,7817,7818,7819,7820,7821,7822,7823,
7824,7825,7826,7827,7828,7829,7830,7831,7832,7833,7834,7835,7836,7837,7838,7839,
7840,7841,7842,7843,7844,7845,7846,7847,7848,7849,7850,7851,7852,7853,7854,7855,
7856,7857,7858,7859,7860,7861,7862,7863,7864,7865,7866,7867,7868,7869,7870,7871,
7872,7873,7874,7875,7876,7877,7878,7879,7880,7881,7882,7883,7884,7885,7886,7887,
7888,7889,7890,7891,7892,7893,7894,7895,7896,7897,7898,7899,7900,7901,7902,7903,
7904,7905,7906,7907,7908,7909,7910,7911,7912,7913,7914,7915,7916,7917,7918,7919,
7920,7921,7922,7923,7924,7925,7926,7927,7928,7929,7930,7931,7932,7933,7934,7935,
7936,7937,7938,7939,7940,7941,7942,7943,7944,7945,7946,7947,7948,7949,7950,7951,
7952,7953,7954,7955,7956,7957,7958,7959,7960,7961,7962,7963,7964,7965,7966,7967,
7968,7969,7970,7971,7972,7973,7974,7975,7976,7977,7978,7979,7980,7981,7982,7983,
7984,7985,7986,7987,7988,7989,7990,7991,7992,7993,7994,7995,7996,7997,7998,7999,
8000,8001,8002,8003,8004,8005,8006,8007,8008,8009,8010,8011,8012,8013,8014,8015,
8016,8017,8018,8019,8020,8021,8022,8023,8024,8025,8026,8027,8028,8029,8030,8031,
8032,8033,8034,8035,8036,8037,8038,8039,8040,8041,8042,8043,8044,8045,8046,8047,
8048,8049,8050,8051,8052,8053,8054,8055,8056,8057,8058,8059,8060,8061,8062,8063,
8064,8065,8066,8067,8068,8069,8070,8071,8072,8073,8074,8075,8076,8077,8078,8079,
8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,
8096,8097,8098,8099,8100,8101,8102,8103,8104,8105,8106,8107,8108,8109,8110,8111,
8112,8113,8114,8115,8116,8117,8118,8119,8120,8121,8122,8123,8124,8125,8126,8127,
8128,8129,8130,8131,8132,8133,8134,8135,8136,8137,8138,8139,8140,8141,8142,8143,
8144,8145,8146,8147,8148,8149,8150,8151,8152,8153,8154,8155,8156,8157,8158,8159,
8160,8161,8162,8163,8164,8165,8166,8167,8168,8169,8170,8171,8172,8173,8174,8175,
8176,8177,8178,8179,8180,8181,8182,8183,8184,8185,8186,8187,8188,8189,8190,8191,
8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8203,8204,8205,8206,8207,
8208,8209,8210,8211,8212,8213,8214,8215,8216,8217,8218,8219,8220,8221,8222,8223,
8224,8225,8226,8227,8228,8229,8230,8231,8232,8233,8234,8235,8236,8237,8238,8239,
8240,8241,8242,8243,8244,8245,8246,8247,8248,8249,8250,8251,8252,8253,8254,8255,
8256,8257,8258,8259,8260,8261,8262,8263,8264,8265,8266,8267,8268,8269,8270,8271,
8272,8273,8274,8275,8276,8277,8278,8279,8280,8281,8282,8283,8284,8285,8286,8287,
8288,8289,8290,8291,8292,8293,8294,8295,8296,8297,8298,8299,8300,8301,8302,8303,
8304,8305,8306,8307,8308,8309,8310,8311,8312,8313,8314,8315,8316,8317,8318,8319,
8320,8321,8322,8323,8324,8325,8326,8327,8328,8329,8330,8331,8332,8333,8334,8335,
8336,8337,8338,8339,8340,8341,8342,8343,8344,8345,8346,8347,8348,8349,8350,8351,
8352,8353,8354,8355,8356,8357,8358,8359,8360,8361,8362,8363,8364,8365,8366,8367,
8368,8369,8370,8371,8372,8373,8374,8375,8376,8377,8378,8379,8380,8381,8382,8383,
8384,8385,8386,8387,8388,8389,8390,8391,8392,8393,8394,8395,8396,8397,8398,8399,
8400,8401,8402,8403,8404,8405,8406,8407,8408,8409,8410,8411,8412,8413,8414,8415,
8416,8417,8418,8419,8420,8421,8422,8423,8424,8425,8426,8427,8428,8429,8430,8431,
8432,8433,8434,8435,8436,8437,8438,8439,8440,8441,8442,8443,8444,8445,8446,8447,
8448,8449,8450,8451,8452,8453,8454,8455,8456,8457,8458,8459,8460,8461,8462,8463,
8464,8465,8466,8467,8468,8469,8470,8471,8472,8473,8474,8475,8476,8477,8478,8479,
8480,8481,8482,8483,8484,8485,8486,8487,8488,8489,8490,8491,8492,8493,8494,8495,
8496,8497,8498,8499,8500,8501,8502,8503,8504,8505,8506,8507,8508,8509,8510,8511,
8512,8513,8514,8515,8516,8517,8518,8519,8520,8521,8522,8523,8524,8525,8526,8527,
8528,8529,8530,8531,8532,8533,8534,8535,8536,8537,8538,8539,8540,8541,8542,8543,
8544,8545,8546,8547,8548,8549,8550,8551,8552,8553,8554,8555,8556,8557,8558,8559,
8560,8561,8562,8563,8564,8565,8566,8567,8568,8569,8570,8571,8572,8573,8574,8575,
8576,8577,8578,8579,8580,8581,8582,8583,8584,8585,8586,8587,8588,8589,8590,8591,
8592,8593,8594,8595,8596,8597,8598,8599,8600,8601,8602,8603,8604,8605,8606,8607,
8608,8609,8610,8611,8612,8613,8614,8615,8616,8617,8618,8619,8620,8621,8622,8623,
8624,8625,8626,8627,8628,8629,8630,8631,8632,8633,8634,8635,8636,8637,8638,8639,
8640,8641,8642,8643,8644,8645,8646,8647,8648,8649,8650,8651,8652,8653,8654,8655,
8656,8657,8658,8659,8660,8661,8662,8663,8664,8665,8666,8667,8668,8669,8670,8671,
8672,8673,8674,8675,8676,8677,8678,8679,8680,8681,8682,8683,8684,8685,8686,8687,
8688,8689,8690,8691,8692,8693,8694,8695,8696,8697,8698,8699,8700,8701,8702,8703,
8704,8705,8706,8707,8708,8709,8710,8711,8712,8713,8714,8715,8716,8717,8718,8719,
8720,8721,8722,8723,8724,8725,8726,8727,8728,8729,8730,8731,8732,8733,8734,8735,
8736,8737,8738,8739,8740,8741)
# flake8: noqa
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
428,
23144,
687,
3595,
3388,
45,
1318,
8418,
2387,
7142,
1463,
436,
24189,
1565,
24731,
199,
199,
3,
7960,
221,
10541,
378,
14,
1965,
199,
3,
7633,
221,
10541,
378,
14,
2942,
199,
3,
10574,
221,
10541,
378,
14,
30292,
199,
3,
6619,
10541,
378,
14,
5637,
1602,
199,
3,
18427,
10541,
378,
14,
27055,
199,
3,
199,
3,
473,
25395,
11839,
820,
32736,
275,
378,
14,
30292,
2481,
1182,
334,
17,
13,
16,
14,
30292,
2481,
9,
275,
18525,
14,
1194,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
8276,
16,
13,
7736,
9,
275,
378,
14,
12987,
14,
199,
3,
221,
199,
3,
29267,
11839,
820,
32736,
257,
199,
199,
23539,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
1227,
14,
16,
199,
199,
23539,
27373,
63,
8723,
63,
4305,
275,
499,
15139,
199,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
221,
199,
23539,
27373,
18139,
13875,
4738,
275,
334,
971,
523,
4944,
12,
21334,
12,
13960,
12,
969,
2534,
12,
841,
2835,
12,
1196,
1167,
12,
1196,
1165,
12,
650,
1651,
12,
1227,
1643,
12,
29532,
12,
1196,
2025,
12,
1520,
1780,
12,
8290,
12,
32730,
12,
1196,
1081,
12,
221,
10513,
12,
199,
969,
2576,
12,
1196,
1789,
12,
21083,
12,
959,
1344,
12,
845,
1196,
12,
713,
1644,
12,
1196,
1194,
12,
713,
1822,
12,
1227,
2426,
12,
713,
2333,
12,
959,
2036,
12,
1196,
821,
12,
1196,
1479,
12,
1196,
1465,
12,
1196,
1651,
12,
969,
2905,
12,
199,
969,
1020,
12,
1196,
1398,
12,
1196,
1216,
12,
1196,
2192,
12,
413,
2953,
12,
1227,
2025,
12,
650,
1479,
12,
709,
1641,
12,
650,
2333,
12,
1196,
708,
12,
499,
1822,
12,
841,
1299,
12,
221,
3388,
12,
1196,
1153,
12,
713,
1876,
12,
1196,
1082,
12,
199,
1749,
2322,
12,
1079,
383,
12,
1196,
1276,
12,
221,
10954,
12,
1749,
966,
12,
713,
2760,
12,
1196,
1344,
12,
1196,
1401,
12,
8375,
19,
12,
499,
2006,
12,
1196,
1703,
12,
21292,
12,
650,
969,
12,
1520,
1184,
12,
17640,
12,
1196,
1355,
12,
199,
25186,
12,
1749,
1555,
12,
1695,
969,
12,
1079,
614,
12,
1227,
2658,
12,
221,
13098,
12,
713,
966,
12,
28818,
12,
1196,
2167,
12,
1196,
2953,
12,
1196,
2260,
12,
1196,
2824,
12,
221,
3193,
12,
8264,
23,
12,
1227,
1822,
12,
1227,
1081,
12,
199,
1520,
2036,
12,
1196,
1602,
12,
1196,
2322,
12,
1196,
2466,
12,
1749,
1272,
12,
1520,
1555,
12,
20398,
12,
25454,
12,
1196,
2417,
12,
221,
5212,
12,
1695,
1165,
12,
11869,
12,
1227,
2114,
12,
1196,
2006,
12,
1196,
1887,
12,
1196,
1400,
12,
199,
1196,
2869,
12,
1227,
1196,
12,
1196,
2528,
12,
1227,
1479,
12,
1196,
2481,
12,
1196,
1477,
12,
1196,
1229,
12,
1196,
1367,
12,
1227,
2481,
12,
1196,
1641,
12,
1196,
2010,
12,
1196,
1427,
12,
1196,
2259,
12,
1196,
2976,
12,
1196,
2789,
12,
1695,
1367,
12,
199,
650,
1602,
12,
1196,
2766,
12,
1196,
772,
12,
1196,
2182,
12,
1196,
1272,
12,
221,
17838,
12,
13952,
12,
841,
1085,
12,
5939,
22,
12,
1749,
1717,
12,
8264,
24,
12,
1196,
1822,
12,
1196,
2333,
12,
1196,
1876,
12,
1749,
2466,
12,
713,
1717,
12,
199,
1520,
1643,
12,
8881,
16,
12,
845,
1085,
12,
8881,
17,
12,
499,
2953,
12,
8881,
18,
12,
8881,
19,
12,
8881,
20,
12,
713,
3172,
12,
8881,
21,
12,
959,
1876,
12,
8881,
22,
12,
22291,
12,
8881,
23,
12,
8881,
24,
12,
8881,
25,
12,
199,
1196,
1257,
12,
650,
1401,
12,
1520,
2869,
12,
709,
2010,
12,
221,
7294,
12,
1227,
1651,
12,
22540,
12,
1196,
2835,
12,
413,
1138,
12,
1749,
1690,
12,
27632,
12,
650,
1887,
12,
221,
15601,
12,
709,
1965,
12,
1196,
2564,
12,
221,
5851,
12,
199,
1196,
2658,
12,
650,
1965,
12,
1196,
1349,
12,
650,
1046,
12,
1196,
2426,
12,
1227,
1398,
12,
1520,
1477,
12,
29840,
12,
959,
1427,
12,
1196,
1184,
12,
1227,
1344,
12,
29202,
12,
713,
1690,
12,
1196,
1555,
12,
1520,
709,
12,
959,
1822,
12,
199,
1196,
1299,
12,
1749,
1276,
12,
1695,
1079,
12,
1196,
1407,
12,
1196,
2710,
12,
713,
1780,
12,
1520,
1272,
12,
959,
1651,
12,
1196,
3328,
12,
1196,
2942,
12,
713,
2036,
12,
1196,
3129,
12,
1196,
2635,
12,
1196,
2720,
12,
1196,
2534,
12,
1196,
2576,
12,
199,
1079,
1644,
12,
1196,
2905,
12,
1196,
1020,
12,
959,
1153,
12,
709,
1427,
12,
1079,
966,
12,
1079,
1717,
12,
845,
1367,
12,
1079,
1690,
12,
1749,
1344,
12,
10523,
20,
12,
23514,
12,
1085,
383,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
428,
23144,
687,
3595,
3388,
45,
1318,
8418,
2387,
7142,
1463,
436,
24189,
1565,
24731,
199,
199,
3,
7960,
221,
10541,
378,
14,
1965,
199,
3,
7633,
221,
10541,
378,
14,
2942,
199,
3,
10574,
221,
10541,
378,
14,
30292,
199,
3,
6619,
10541,
378,
14,
5637,
1602,
199,
3,
18427,
10541,
378,
14,
27055,
199,
3,
199,
3,
473,
25395,
11839,
820,
32736,
275,
378,
14,
30292,
2481,
1182,
334,
17,
13,
16,
14,
30292,
2481,
9,
275,
18525,
14,
1194,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
8276,
16,
13,
7736,
9,
275,
378,
14,
12987,
14,
199,
3,
221,
199,
3,
29267,
11839,
820,
32736,
257,
199,
199,
23539,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
1227,
14,
16,
199,
199,
23539,
27373,
63,
8723,
63,
4305,
275,
499,
15139,
199,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
221,
199,
23539,
27373,
18139,
13875,
4738,
275,
334,
971,
523,
4944,
12,
21334,
12,
13960,
12,
969,
2534,
12,
841,
2835,
12,
1196,
1167,
12,
1196,
1165,
12,
650,
1651,
12,
1227,
1643,
12,
29532,
12,
1196,
2025,
12,
1520,
1780,
12,
8290,
12,
32730,
12,
1196,
1081,
12,
221,
10513,
12,
199,
969,
2576,
12,
1196,
1789,
12,
21083,
12,
959,
1344,
12,
845,
1196,
12,
713,
1644,
12,
1196,
1194,
12,
713,
1822,
12,
1227,
2426,
12,
713,
2333,
12,
959,
2036,
12,
1196,
821,
12,
1196,
1479,
12,
1196,
1465,
12,
1196,
1651,
12,
969,
2905,
12,
199,
969,
1020,
12,
1196,
1398,
12,
1196,
1216,
12,
1196,
2192,
12,
413,
2953,
12,
1227,
2025,
12,
650,
1479,
12,
709,
1641,
12,
650,
2333,
12,
1196,
708,
12,
499,
1822,
12,
841,
1299,
12,
221,
3388,
12,
1196,
1153,
12,
713,
1876,
12,
1196,
1082,
12,
199,
1749,
2322,
12,
1079,
383,
12,
1196,
1276,
12,
221,
10954,
12,
1749,
966,
12,
713,
2760,
12,
1196,
1344,
12,
1196,
1401,
12,
8375,
19,
12,
499,
2006,
12,
1196,
1703,
12,
21292,
12,
650,
969,
12,
1520,
1184,
12,
17640,
12,
1196,
1355,
12,
199,
25186,
12,
1749,
1555,
12,
1695,
969,
12,
1079,
614,
12,
1227,
2658,
12,
221,
13098,
12,
713,
966,
12,
28818,
12,
1196,
2167,
12,
1196,
2953,
12,
1196,
2260,
12,
1196,
2824,
12,
221,
3193,
12,
8264,
23,
12,
1227,
1822,
12,
1227,
1081,
12,
199,
1520,
2036,
12,
1196,
1602,
12,
1196,
2322,
12,
1196,
2466,
12,
1749,
1272,
12,
1520,
1555,
12,
20398,
12,
25454,
12,
1196,
2417,
12,
221,
5212,
12,
1695,
1165,
12,
11869,
12,
1227,
2114,
12,
1196,
2006,
12,
1196,
1887,
12,
1196,
1400,
12,
199,
1196,
2869,
12,
1227,
1196,
12,
1196,
2528,
12,
1227,
1479,
12,
1196,
2481,
12,
1196,
1477,
12,
1196,
1229,
12,
1196,
1367,
12,
1227,
2481,
12,
1196,
1641,
12,
1196,
2010,
12,
1196,
1427,
12,
1196,
2259,
12,
1196,
2976,
12,
1196,
2789,
12,
1695,
1367,
12,
199,
650,
1602,
12,
1196,
2766,
12,
1196,
772,
12,
1196,
2182,
12,
1196,
1272,
12,
221,
17838,
12,
13952,
12,
841,
1085,
12,
5939,
22,
12,
1749,
1717,
12,
8264,
24,
12,
1196,
1822,
12,
1196,
2333,
12,
1196,
1876,
12,
1749,
2466,
12,
713,
1717,
12,
199,
1520,
1643,
12,
8881,
16,
12,
845,
1085,
12,
8881,
17,
12,
499,
2953,
12,
8881,
18,
12,
8881,
19,
12,
8881,
20,
12,
713,
3172,
12,
8881,
21,
12,
959,
1876,
12,
8881,
22,
12,
22291,
12,
8881,
23,
12,
8881,
24,
12,
8881,
25,
12,
199,
1196,
1257,
12,
650,
1401,
12,
1520,
2869,
12,
709,
2010,
12,
221,
7294,
12,
1227,
1651,
12,
22540,
12,
1196,
2835,
12,
413,
1138,
12,
1749,
1690,
12,
27632,
12,
650,
1887,
12,
221,
15601,
12,
709,
1965,
12,
1196,
2564,
12,
221,
5851,
12,
199,
1196,
2658,
12,
650,
1965,
12,
1196,
1349,
12,
650,
1046,
12,
1196,
2426,
12,
1227,
1398,
12,
1520,
1477,
12,
29840,
12,
959,
1427,
12,
1196,
1184,
12,
1227,
1344,
12,
29202,
12,
713,
1690,
12,
1196,
1555,
12,
1520,
709,
12,
959,
1822,
12,
199,
1196,
1299,
12,
1749,
1276,
12,
1695,
1079,
12,
1196,
1407,
12,
1196,
2710,
12,
713,
1780,
12,
1520,
1272,
12,
959,
1651,
12,
1196,
3328,
12,
1196,
2942,
12,
713,
2036,
12,
1196,
3129,
12,
1196,
2635,
12,
1196,
2720,
12,
1196,
2534,
12,
1196,
2576,
12,
199,
1079,
1644,
12,
1196,
2905,
12,
1196,
1020,
12,
959,
1153,
12,
709,
1427,
12,
1079,
966,
12,
1079,
1717,
12,
845,
1367,
12,
1079,
1690,
12,
1749,
1344,
12,
10523,
20,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
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cherylyli/stress-aid
|
env/lib/python3.5/site-packages/werkzeug/urls.py
|
216
|
36710
|
# -*- coding: utf-8 -*-
"""
werkzeug.urls
~~~~~~~~~~~~~
``werkzeug.urls`` used to provide several wrapper functions for Python 2
urlparse, whose main purpose were to work around the behavior of the Py2
stdlib and its lack of unicode support. While this was already a somewhat
inconvenient situation, it got even more complicated because Python 3's
``urllib.parse`` actually does handle unicode properly. In other words,
this module would wrap two libraries with completely different behavior. So
now this module contains a 2-and-3-compatible backport of Python 3's
``urllib.parse``, which is mostly API-compatible.
:copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import os
import re
from werkzeug._compat import text_type, PY2, to_unicode, \
to_native, implements_to_string, try_coerce_native, \
normalize_string_tuple, make_literal_wrapper, \
fix_tuple_repr
from werkzeug._internal import _encode_idna, _decode_idna
from werkzeug.datastructures import MultiDict, iter_multi_items
from collections import namedtuple
# A regular expression for what a valid schema looks like
_scheme_re = re.compile(r'^[a-zA-Z0-9+-.]+$')
# Characters that are safe in any part of an URL.
_always_safe = (b'abcdefghijklmnopqrstuvwxyz'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-+')
_hexdigits = '0123456789ABCDEFabcdef'
_hextobyte = dict(
((a + b).encode(), int(a + b, 16))
for a in _hexdigits for b in _hexdigits
)
_URLTuple = fix_tuple_repr(namedtuple(
'_URLTuple',
['scheme', 'netloc', 'path', 'query', 'fragment']
))
class BaseURL(_URLTuple):
'''Superclass of :py:class:`URL` and :py:class:`BytesURL`.'''
__slots__ = ()
def replace(self, **kwargs):
"""Return an URL with the same values, except for those parameters
given new values by whichever keyword arguments are specified."""
return self._replace(**kwargs)
@property
def host(self):
"""The host part of the URL if available, otherwise `None`. The
host is either the hostname or the IP address mentioned in the
URL. It will not contain the port.
"""
return self._split_host()[0]
@property
def ascii_host(self):
"""Works exactly like :attr:`host` but will return a result that
is restricted to ASCII. If it finds a netloc that is not ASCII
it will attempt to idna decode it. This is useful for socket
operations when the URL might include internationalized characters.
"""
rv = self.host
if rv is not None and isinstance(rv, text_type):
try:
rv = _encode_idna(rv)
except UnicodeError:
rv = rv.encode('ascii', 'ignore')
return to_native(rv, 'ascii', 'ignore')
@property
def port(self):
"""The port in the URL as an integer if it was present, `None`
otherwise. This does not fill in default ports.
"""
try:
rv = int(to_native(self._split_host()[1]))
if 0 <= rv <= 65535:
return rv
except (ValueError, TypeError):
pass
@property
def auth(self):
"""The authentication part in the URL if available, `None`
otherwise.
"""
return self._split_netloc()[0]
@property
def username(self):
"""The username if it was part of the URL, `None` otherwise.
This undergoes URL decoding and will always be a unicode string.
"""
rv = self._split_auth()[0]
if rv is not None:
return _url_unquote_legacy(rv)
@property
def raw_username(self):
"""The username if it was part of the URL, `None` otherwise.
Unlike :attr:`username` this one is not being decoded.
"""
return self._split_auth()[0]
@property
def password(self):
"""The password if it was part of the URL, `None` otherwise.
This undergoes URL decoding and will always be a unicode string.
"""
rv = self._split_auth()[1]
if rv is not None:
return _url_unquote_legacy(rv)
@property
def raw_password(self):
"""The password if it was part of the URL, `None` otherwise.
Unlike :attr:`password` this one is not being decoded.
"""
return self._split_auth()[1]
def decode_query(self, *args, **kwargs):
"""Decodes the query part of the URL. Ths is a shortcut for
calling :func:`url_decode` on the query argument. The arguments and
keyword arguments are forwarded to :func:`url_decode` unchanged.
"""
return url_decode(self.query, *args, **kwargs)
def join(self, *args, **kwargs):
"""Joins this URL with another one. This is just a convenience
function for calling into :meth:`url_join` and then parsing the
return value again.
"""
return url_parse(url_join(self, *args, **kwargs))
def to_url(self):
"""Returns a URL string or bytes depending on the type of the
information stored. This is just a convenience function
for calling :meth:`url_unparse` for this URL.
"""
return url_unparse(self)
def decode_netloc(self):
"""Decodes the netloc part into a string."""
rv = _decode_idna(self.host or '')
if ':' in rv:
rv = '[%s]' % rv
port = self.port
if port is not None:
rv = '%s:%d' % (rv, port)
auth = ':'.join(filter(None, [
_url_unquote_legacy(self.raw_username or '', '/:%@'),
_url_unquote_legacy(self.raw_password or '', '/:%@'),
]))
if auth:
rv = '%s@%s' % (auth, rv)
return rv
def to_uri_tuple(self):
"""Returns a :class:`BytesURL` tuple that holds a URI. This will
encode all the information in the URL properly to ASCII using the
rules a web browser would follow.
It's usually more interesting to directly call :meth:`iri_to_uri` which
will return a string.
"""
return url_parse(iri_to_uri(self).encode('ascii'))
def to_iri_tuple(self):
"""Returns a :class:`URL` tuple that holds a IRI. This will try
to decode as much information as possible in the URL without
losing information similar to how a web browser does it for the
URL bar.
It's usually more interesting to directly call :meth:`uri_to_iri` which
will return a string.
"""
return url_parse(uri_to_iri(self))
def get_file_location(self, pathformat=None):
"""Returns a tuple with the location of the file in the form
``(server, location)``. If the netloc is empty in the URL or
points to localhost, it's represented as ``None``.
The `pathformat` by default is autodetection but needs to be set
when working with URLs of a specific system. The supported values
are ``'windows'`` when working with Windows or DOS paths and
``'posix'`` when working with posix paths.
If the URL does not point to to a local file, the server and location
are both represented as ``None``.
:param pathformat: The expected format of the path component.
Currently ``'windows'`` and ``'posix'`` are
supported. Defaults to ``None`` which is
autodetect.
"""
if self.scheme != 'file':
return None, None
path = url_unquote(self.path)
host = self.netloc or None
if pathformat is None:
if os.name == 'nt':
pathformat = 'windows'
else:
pathformat = 'posix'
if pathformat == 'windows':
if path[:1] == '/' and path[1:2].isalpha() and path[2:3] in '|:':
path = path[1:2] + ':' + path[3:]
windows_share = path[:3] in ('\\' * 3, '/' * 3)
import ntpath
path = ntpath.normpath(path)
# Windows shared drives are represented as ``\\host\\directory``.
# That results in a URL like ``file://///host/directory``, and a
# path like ``///host/directory``. We need to special-case this
# because the path contains the hostname.
if windows_share and host is None:
parts = path.lstrip('\\').split('\\', 1)
if len(parts) == 2:
host, path = parts
else:
host = parts[0]
path = ''
elif pathformat == 'posix':
import posixpath
path = posixpath.normpath(path)
else:
raise TypeError('Invalid path format %s' % repr(pathformat))
if host in ('127.0.0.1', '::1', 'localhost'):
host = None
return host, path
def _split_netloc(self):
if self._at in self.netloc:
return self.netloc.split(self._at, 1)
return None, self.netloc
def _split_auth(self):
auth = self._split_netloc()[0]
if not auth:
return None, None
if self._colon not in auth:
return auth, None
return auth.split(self._colon, 1)
def _split_host(self):
rv = self._split_netloc()[1]
if not rv:
return None, None
if not rv.startswith(self._lbracket):
if self._colon in rv:
return rv.split(self._colon, 1)
return rv, None
idx = rv.find(self._rbracket)
if idx < 0:
return rv, None
host = rv[1:idx]
rest = rv[idx + 1:]
if rest.startswith(self._colon):
return host, rest[1:]
return host, None
@implements_to_string
class URL(BaseURL):
"""Represents a parsed URL. This behaves like a regular tuple but
also has some extra attributes that give further insight into the
URL.
"""
__slots__ = ()
_at = '@'
_colon = ':'
_lbracket = '['
_rbracket = ']'
def __str__(self):
return self.to_url()
def encode_netloc(self):
"""Encodes the netloc part to an ASCII safe URL as bytes."""
rv = self.ascii_host or ''
if ':' in rv:
rv = '[%s]' % rv
port = self.port
if port is not None:
rv = '%s:%d' % (rv, port)
auth = ':'.join(filter(None, [
url_quote(self.raw_username or '', 'utf-8', 'strict', '/:%'),
url_quote(self.raw_password or '', 'utf-8', 'strict', '/:%'),
]))
if auth:
rv = '%s@%s' % (auth, rv)
return to_native(rv)
def encode(self, charset='utf-8', errors='replace'):
"""Encodes the URL to a tuple made out of bytes. The charset is
only being used for the path, query and fragment.
"""
return BytesURL(
self.scheme.encode('ascii'),
self.encode_netloc(),
self.path.encode(charset, errors),
self.query.encode(charset, errors),
self.fragment.encode(charset, errors)
)
class BytesURL(BaseURL):
"""Represents a parsed URL in bytes."""
__slots__ = ()
_at = b'@'
_colon = b':'
_lbracket = b'['
_rbracket = b']'
def __str__(self):
return self.to_url().decode('utf-8', 'replace')
def encode_netloc(self):
"""Returns the netloc unchanged as bytes."""
return self.netloc
def decode(self, charset='utf-8', errors='replace'):
"""Decodes the URL to a tuple made out of strings. The charset is
only being used for the path, query and fragment.
"""
return URL(
self.scheme.decode('ascii'),
self.decode_netloc(),
self.path.decode(charset, errors),
self.query.decode(charset, errors),
self.fragment.decode(charset, errors)
)
def _unquote_to_bytes(string, unsafe=''):
if isinstance(string, text_type):
string = string.encode('utf-8')
if isinstance(unsafe, text_type):
unsafe = unsafe.encode('utf-8')
unsafe = frozenset(bytearray(unsafe))
bits = iter(string.split(b'%'))
result = bytearray(next(bits, b''))
for item in bits:
try:
char = _hextobyte[item[:2]]
if char in unsafe:
raise KeyError()
result.append(char)
result.extend(item[2:])
except KeyError:
result.extend(b'%')
result.extend(item)
return bytes(result)
def _url_encode_impl(obj, charset, encode_keys, sort, key):
iterable = iter_multi_items(obj)
if sort:
iterable = sorted(iterable, key=key)
for key, value in iterable:
if value is None:
continue
if not isinstance(key, bytes):
key = text_type(key).encode(charset)
if not isinstance(value, bytes):
value = text_type(value).encode(charset)
yield url_quote_plus(key) + '=' + url_quote_plus(value)
def _url_unquote_legacy(value, unsafe=''):
try:
return url_unquote(value, charset='utf-8',
errors='strict', unsafe=unsafe)
except UnicodeError:
return url_unquote(value, charset='latin1', unsafe=unsafe)
def url_parse(url, scheme=None, allow_fragments=True):
"""Parses a URL from a string into a :class:`URL` tuple. If the URL
is lacking a scheme it can be provided as second argument. Otherwise,
it is ignored. Optionally fragments can be stripped from the URL
by setting `allow_fragments` to `False`.
The inverse of this function is :func:`url_unparse`.
:param url: the URL to parse.
:param scheme: the default schema to use if the URL is schemaless.
:param allow_fragments: if set to `False` a fragment will be removed
from the URL.
"""
s = make_literal_wrapper(url)
is_text_based = isinstance(url, text_type)
if scheme is None:
scheme = s('')
netloc = query = fragment = s('')
i = url.find(s(':'))
if i > 0 and _scheme_re.match(to_native(url[:i], errors='replace')):
# make sure "iri" is not actually a port number (in which case
# "scheme" is really part of the path)
rest = url[i + 1:]
if not rest or any(c not in s('0123456789') for c in rest):
# not a port number
scheme, url = url[:i].lower(), rest
if url[:2] == s('//'):
delim = len(url)
for c in s('/?#'):
wdelim = url.find(c, 2)
if wdelim >= 0:
delim = min(delim, wdelim)
netloc, url = url[2:delim], url[delim:]
if (s('[') in netloc and s(']') not in netloc) or \
(s(']') in netloc and s('[') not in netloc):
raise ValueError('Invalid IPv6 URL')
if allow_fragments and s('#') in url:
url, fragment = url.split(s('#'), 1)
if s('?') in url:
url, query = url.split(s('?'), 1)
result_type = is_text_based and URL or BytesURL
return result_type(scheme, netloc, url, query, fragment)
def url_quote(string, charset='utf-8', errors='strict', safe='/:', unsafe=''):
"""URL encode a single string with a given encoding.
:param s: the string to quote.
:param charset: the charset to be used.
:param safe: an optional sequence of safe characters.
:param unsafe: an optional sequence of unsafe characters.
.. versionadded:: 0.9.2
The `unsafe` parameter was added.
"""
if not isinstance(string, (text_type, bytes, bytearray)):
string = text_type(string)
if isinstance(string, text_type):
string = string.encode(charset, errors)
if isinstance(safe, text_type):
safe = safe.encode(charset, errors)
if isinstance(unsafe, text_type):
unsafe = unsafe.encode(charset, errors)
safe = frozenset(bytearray(safe) + _always_safe) - frozenset(bytearray(unsafe))
rv = bytearray()
for char in bytearray(string):
if char in safe:
rv.append(char)
else:
rv.extend(('%%%02X' % char).encode('ascii'))
return to_native(bytes(rv))
def url_quote_plus(string, charset='utf-8', errors='strict', safe=''):
"""URL encode a single string with the given encoding and convert
whitespace to "+".
:param s: The string to quote.
:param charset: The charset to be used.
:param safe: An optional sequence of safe characters.
"""
return url_quote(string, charset, errors, safe + ' ', '+').replace(' ', '+')
def url_unparse(components):
"""The reverse operation to :meth:`url_parse`. This accepts arbitrary
as well as :class:`URL` tuples and returns a URL as a string.
:param components: the parsed URL as tuple which should be converted
into a URL string.
"""
scheme, netloc, path, query, fragment = \
normalize_string_tuple(components)
s = make_literal_wrapper(scheme)
url = s('')
# We generally treat file:///x and file:/x the same which is also
# what browsers seem to do. This also allows us to ignore a schema
# register for netloc utilization or having to differenciate between
# empty and missing netloc.
if netloc or (scheme and path.startswith(s('/'))):
if path and path[:1] != s('/'):
path = s('/') + path
url = s('//') + (netloc or s('')) + path
elif path:
url += path
if scheme:
url = scheme + s(':') + url
if query:
url = url + s('?') + query
if fragment:
url = url + s('#') + fragment
return url
def url_unquote(string, charset='utf-8', errors='replace', unsafe=''):
"""URL decode a single string with a given encoding. If the charset
is set to `None` no unicode decoding is performed and raw bytes
are returned.
:param s: the string to unquote.
:param charset: the charset of the query string. If set to `None`
no unicode decoding will take place.
:param errors: the error handling for the charset decoding.
"""
rv = _unquote_to_bytes(string, unsafe)
if charset is not None:
rv = rv.decode(charset, errors)
return rv
def url_unquote_plus(s, charset='utf-8', errors='replace'):
"""URL decode a single string with the given `charset` and decode "+" to
whitespace.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`HTTPUnicodeError` is raised.
:param s: The string to unquote.
:param charset: the charset of the query string. If set to `None`
no unicode decoding will take place.
:param errors: The error handling for the `charset` decoding.
"""
if isinstance(s, text_type):
s = s.replace(u'+', u' ')
else:
s = s.replace(b'+', b' ')
return url_unquote(s, charset, errors)
def url_fix(s, charset='utf-8'):
r"""Sometimes you get an URL by a user that just isn't a real URL because
it contains unsafe characters like ' ' and so on. This function can fix
some of the problems in a similar way browsers handle data entered by the
user:
>>> url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)')
'http://de.wikipedia.org/wiki/Elf%20(Begriffskl%C3%A4rung)'
:param s: the string with the URL to fix.
:param charset: The target charset for the URL if the url was given as
unicode string.
"""
# First step is to switch to unicode processing and to convert
# backslashes (which are invalid in URLs anyways) to slashes. This is
# consistent with what Chrome does.
s = to_unicode(s, charset, 'replace').replace('\\', '/')
# For the specific case that we look like a malformed windows URL
# we want to fix this up manually:
if s.startswith('file://') and s[7:8].isalpha() and s[8:10] in (':/', '|/'):
s = 'file:///' + s[7:]
url = url_parse(s)
path = url_quote(url.path, charset, safe='/%+$!*\'(),')
qs = url_quote_plus(url.query, charset, safe=':&%=+$!*\'(),')
anchor = url_quote_plus(url.fragment, charset, safe=':&%=+$!*\'(),')
return to_native(url_unparse((url.scheme, url.encode_netloc(),
path, qs, anchor)))
def uri_to_iri(uri, charset='utf-8', errors='replace'):
r"""
Converts a URI in a given charset to a IRI.
Examples for URI versus IRI:
>>> uri_to_iri(b'http://xn--n3h.net/')
u'http://\u2603.net/'
>>> uri_to_iri(b'http://%C3%BCser:p%C3%A4ssword@xn--n3h.net/p%C3%A5th')
u'http://\xfcser:p\xe4ssword@\u2603.net/p\xe5th'
Query strings are left unchanged:
>>> uri_to_iri('/?foo=24&x=%26%2f')
u'/?foo=24&x=%26%2f'
.. versionadded:: 0.6
:param uri: The URI to convert.
:param charset: The charset of the URI.
:param errors: The error handling on decode.
"""
if isinstance(uri, tuple):
uri = url_unparse(uri)
uri = url_parse(to_unicode(uri, charset))
path = url_unquote(uri.path, charset, errors, '%/;?')
query = url_unquote(uri.query, charset, errors, '%;/?:@&=+,$#')
fragment = url_unquote(uri.fragment, charset, errors, '%;/?:@&=+,$#')
return url_unparse((uri.scheme, uri.decode_netloc(),
path, query, fragment))
def iri_to_uri(iri, charset='utf-8', errors='strict', safe_conversion=False):
r"""
Converts any unicode based IRI to an acceptable ASCII URI. Werkzeug always
uses utf-8 URLs internally because this is what browsers and HTTP do as
well. In some places where it accepts an URL it also accepts a unicode IRI
and converts it into a URI.
Examples for IRI versus URI:
>>> iri_to_uri(u'http://☃.net/')
'http://xn--n3h.net/'
>>> iri_to_uri(u'http://üser:pässword@☃.net/påth')
'http://%C3%BCser:p%C3%A4ssword@xn--n3h.net/p%C3%A5th'
There is a general problem with IRI and URI conversion with some
protocols that appear in the wild that are in violation of the URI
specification. In places where Werkzeug goes through a forced IRI to
URI conversion it will set the `safe_conversion` flag which will
not perform a conversion if the end result is already ASCII. This
can mean that the return value is not an entirely correct URI but
it will not destroy such invalid URLs in the process.
As an example consider the following two IRIs::
magnet:?xt=uri:whatever
itms-services://?action=download-manifest
The internal representation after parsing of those URLs is the same
and there is no way to reconstruct the original one. If safe
conversion is enabled however this function becomes a noop for both of
those strings as they both can be considered URIs.
.. versionadded:: 0.6
.. versionchanged:: 0.9.6
The `safe_conversion` parameter was added.
:param iri: The IRI to convert.
:param charset: The charset for the URI.
:param safe_conversion: indicates if a safe conversion should take place.
For more information see the explanation above.
"""
if isinstance(iri, tuple):
iri = url_unparse(iri)
if safe_conversion:
try:
native_iri = to_native(iri)
ascii_iri = to_native(iri).encode('ascii')
if ascii_iri.split() == [ascii_iri]:
return native_iri
except UnicodeError:
pass
iri = url_parse(to_unicode(iri, charset, errors))
netloc = iri.encode_netloc()
path = url_quote(iri.path, charset, errors, '/:~+%')
query = url_quote(iri.query, charset, errors, '%&[]:;$*()+,!?*/=')
fragment = url_quote(iri.fragment, charset, errors, '=%&[]:;$()+,!?*/')
return to_native(url_unparse((iri.scheme, netloc,
path, query, fragment)))
def url_decode(s, charset='utf-8', decode_keys=False, include_empty=True,
errors='replace', separator='&', cls=None):
"""
Parse a querystring and return it as :class:`MultiDict`. There is a
difference in key decoding on different Python versions. On Python 3
keys will always be fully decoded whereas on Python 2, keys will
remain bytestrings if they fit into ASCII. On 2.x keys can be forced
to be unicode by setting `decode_keys` to `True`.
If the charset is set to `None` no unicode decoding will happen and
raw bytes will be returned.
Per default a missing value for a key will default to an empty key. If
you don't want that behavior you can set `include_empty` to `False`.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
`HTTPUnicodeError` is raised.
.. versionchanged:: 0.5
In previous versions ";" and "&" could be used for url decoding.
This changed in 0.5 where only "&" is supported. If you want to
use ";" instead a different `separator` can be provided.
The `cls` parameter was added.
:param s: a string with the query string to decode.
:param charset: the charset of the query string. If set to `None`
no unicode decoding will take place.
:param decode_keys: Used on Python 2.x to control whether keys should
be forced to be unicode objects. If set to `True`
then keys will be unicode in all cases. Otherwise,
they remain `str` if they fit into ASCII.
:param include_empty: Set to `False` if you don't want empty values to
appear in the dict.
:param errors: the decoding error behavior.
:param separator: the pair separator to be used, defaults to ``&``
:param cls: an optional dict class to use. If this is not specified
or `None` the default :class:`MultiDict` is used.
"""
if cls is None:
cls = MultiDict
if isinstance(s, text_type) and not isinstance(separator, text_type):
separator = separator.decode(charset or 'ascii')
elif isinstance(s, bytes) and not isinstance(separator, bytes):
separator = separator.encode(charset or 'ascii')
return cls(_url_decode_impl(s.split(separator), charset, decode_keys,
include_empty, errors))
def url_decode_stream(stream, charset='utf-8', decode_keys=False,
include_empty=True, errors='replace', separator='&',
cls=None, limit=None, return_iterator=False):
"""Works like :func:`url_decode` but decodes a stream. The behavior
of stream and limit follows functions like
:func:`~werkzeug.wsgi.make_line_iter`. The generator of pairs is
directly fed to the `cls` so you can consume the data while it's
parsed.
.. versionadded:: 0.8
:param stream: a stream with the encoded querystring
:param charset: the charset of the query string. If set to `None`
no unicode decoding will take place.
:param decode_keys: Used on Python 2.x to control whether keys should
be forced to be unicode objects. If set to `True`,
keys will be unicode in all cases. Otherwise, they
remain `str` if they fit into ASCII.
:param include_empty: Set to `False` if you don't want empty values to
appear in the dict.
:param errors: the decoding error behavior.
:param separator: the pair separator to be used, defaults to ``&``
:param cls: an optional dict class to use. If this is not specified
or `None` the default :class:`MultiDict` is used.
:param limit: the content length of the URL data. Not necessary if
a limited stream is provided.
:param return_iterator: if set to `True` the `cls` argument is ignored
and an iterator over all decoded pairs is
returned
"""
from werkzeug.wsgi import make_chunk_iter
if return_iterator:
cls = lambda x: x
elif cls is None:
cls = MultiDict
pair_iter = make_chunk_iter(stream, separator, limit)
return cls(_url_decode_impl(pair_iter, charset, decode_keys,
include_empty, errors))
def _url_decode_impl(pair_iter, charset, decode_keys, include_empty, errors):
for pair in pair_iter:
if not pair:
continue
s = make_literal_wrapper(pair)
equal = s('=')
if equal in pair:
key, value = pair.split(equal, 1)
else:
if not include_empty:
continue
key = pair
value = s('')
key = url_unquote_plus(key, charset, errors)
if charset is not None and PY2 and not decode_keys:
key = try_coerce_native(key)
yield key, url_unquote_plus(value, charset, errors)
def url_encode(obj, charset='utf-8', encode_keys=False, sort=False, key=None,
separator=b'&'):
"""URL encode a dict/`MultiDict`. If a value is `None` it will not appear
in the result string. Per default only values are encoded into the target
charset strings. If `encode_keys` is set to ``True`` unicode keys are
supported too.
If `sort` is set to `True` the items are sorted by `key` or the default
sorting algorithm.
.. versionadded:: 0.5
`sort`, `key`, and `separator` were added.
:param obj: the object to encode into a query string.
:param charset: the charset of the query string.
:param encode_keys: set to `True` if you have unicode keys. (Ignored on
Python 3.x)
:param sort: set to `True` if you want parameters to be sorted by `key`.
:param separator: the separator to be used for the pairs.
:param key: an optional function to be used for sorting. For more details
check out the :func:`sorted` documentation.
"""
separator = to_native(separator, 'ascii')
return separator.join(_url_encode_impl(obj, charset, encode_keys, sort, key))
def url_encode_stream(obj, stream=None, charset='utf-8', encode_keys=False,
sort=False, key=None, separator=b'&'):
"""Like :meth:`url_encode` but writes the results to a stream
object. If the stream is `None` a generator over all encoded
pairs is returned.
.. versionadded:: 0.8
:param obj: the object to encode into a query string.
:param stream: a stream to write the encoded object into or `None` if
an iterator over the encoded pairs should be returned. In
that case the separator argument is ignored.
:param charset: the charset of the query string.
:param encode_keys: set to `True` if you have unicode keys. (Ignored on
Python 3.x)
:param sort: set to `True` if you want parameters to be sorted by `key`.
:param separator: the separator to be used for the pairs.
:param key: an optional function to be used for sorting. For more details
check out the :func:`sorted` documentation.
"""
separator = to_native(separator, 'ascii')
gen = _url_encode_impl(obj, charset, encode_keys, sort, key)
if stream is None:
return gen
for idx, chunk in enumerate(gen):
if idx:
stream.write(separator)
stream.write(chunk)
def url_join(base, url, allow_fragments=True):
"""Join a base URL and a possibly relative URL to form an absolute
interpretation of the latter.
:param base: the base URL for the join operation.
:param url: the URL to join.
:param allow_fragments: indicates whether fragments should be allowed.
"""
if isinstance(base, tuple):
base = url_unparse(base)
if isinstance(url, tuple):
url = url_unparse(url)
base, url = normalize_string_tuple((base, url))
s = make_literal_wrapper(base)
if not base:
return url
if not url:
return base
bscheme, bnetloc, bpath, bquery, bfragment = \
url_parse(base, allow_fragments=allow_fragments)
scheme, netloc, path, query, fragment = \
url_parse(url, bscheme, allow_fragments)
if scheme != bscheme:
return url
if netloc:
return url_unparse((scheme, netloc, path, query, fragment))
netloc = bnetloc
if path[:1] == s('/'):
segments = path.split(s('/'))
elif not path:
segments = bpath.split(s('/'))
if not query:
query = bquery
else:
segments = bpath.split(s('/'))[:-1] + path.split(s('/'))
# If the rightmost part is "./" we want to keep the slash but
# remove the dot.
if segments[-1] == s('.'):
segments[-1] = s('')
# Resolve ".." and "."
segments = [segment for segment in segments if segment != s('.')]
while 1:
i = 1
n = len(segments) - 1
while i < n:
if segments[i] == s('..') and \
segments[i - 1] not in (s(''), s('..')):
del segments[i - 1:i + 1]
break
i += 1
else:
break
# Remove trailing ".." if the URL is absolute
unwanted_marker = [s(''), s('..')]
while segments[:2] == unwanted_marker:
del segments[1]
path = s('/').join(segments)
return url_unparse((scheme, netloc, path, query, fragment))
class Href(object):
"""Implements a callable that constructs URLs with the given base. The
function can be called with any number of positional and keyword
arguments which than are used to assemble the URL. Works with URLs
and posix paths.
Positional arguments are appended as individual segments to
the path of the URL:
>>> href = Href('/foo')
>>> href('bar', 23)
'/foo/bar/23'
>>> href('foo', bar=23)
'/foo/foo?bar=23'
If any of the arguments (positional or keyword) evaluates to `None` it
will be skipped. If no keyword arguments are given the last argument
can be a :class:`dict` or :class:`MultiDict` (or any other dict subclass),
otherwise the keyword arguments are used for the query parameters, cutting
off the first trailing underscore of the parameter name:
>>> href(is_=42)
'/foo?is=42'
>>> href({'foo': 'bar'})
'/foo?foo=bar'
Combining of both methods is not allowed:
>>> href({'foo': 'bar'}, bar=42)
Traceback (most recent call last):
...
TypeError: keyword arguments and query-dicts can't be combined
Accessing attributes on the href object creates a new href object with
the attribute name as prefix:
>>> bar_href = href.bar
>>> bar_href("blub")
'/foo/bar/blub'
If `sort` is set to `True` the items are sorted by `key` or the default
sorting algorithm:
>>> href = Href("/", sort=True)
>>> href(a=1, b=2, c=3)
'/?a=1&b=2&c=3'
.. versionadded:: 0.5
`sort` and `key` were added.
"""
def __init__(self, base='./', charset='utf-8', sort=False, key=None):
if not base:
base = './'
self.base = base
self.charset = charset
self.sort = sort
self.key = key
def __getattr__(self, name):
if name[:2] == '__':
raise AttributeError(name)
base = self.base
if base[-1:] != '/':
base += '/'
return Href(url_join(base, name), self.charset, self.sort, self.key)
def __call__(self, *path, **query):
if path and isinstance(path[-1], dict):
if query:
raise TypeError('keyword arguments and query-dicts '
'can\'t be combined')
query, path = path[-1], path[:-1]
elif query:
query = dict([(k.endswith('_') and k[:-1] or k, v)
for k, v in query.items()])
path = '/'.join([to_unicode(url_quote(x, self.charset), 'ascii')
for x in path if x is not None]).lstrip('/')
rv = self.base
if path:
if not rv.endswith('/'):
rv += '/'
rv = url_join(rv, './' + path)
if query:
rv += '?' + to_unicode(url_encode(query, self.charset, sort=self.sort,
key=self.key), 'ascii')
return to_native(rv)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
3603,
272,
32202,
94,
339,
1124,
17719,
14,
3603,
1040,
1202,
370,
5647,
9978,
4975,
3423,
367,
2018,
499,
272,
7097,
12,
7447,
2446,
12016,
4898,
370,
1736,
6818,
314,
5953,
402,
314,
1611,
18,
272,
26678,
436,
2399,
29098,
402,
2649,
2291,
14,
22117,
642,
1990,
2575,
282,
30362,
272,
315,
388,
1856,
6792,
25781,
12,
652,
4788,
2755,
1655,
23515,
2952,
2018,
650,
1159,
272,
1124,
4078,
14,
1122,
1040,
5965,
1630,
2429,
2649,
7684,
14,
1010,
1163,
5932,
12,
272,
642,
859,
3955,
4816,
2877,
8363,
543,
14793,
3365,
5953,
14,
2002,
272,
3063,
642,
859,
3509,
282,
499,
13,
460,
13,
19,
13,
6490,
1771,
719,
402,
2018,
650,
1159,
272,
1124,
4078,
14,
1122,
4542,
1314,
365,
19762,
3261,
13,
6490,
14,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
747,
199,
646,
295,
199,
504,
10380,
423,
5819,
492,
1318,
63,
466,
12,
7843,
18,
12,
370,
63,
2975,
12,
971,
272,
370,
63,
6106,
12,
9031,
63,
475,
63,
875,
12,
862,
63,
14141,
63,
6106,
12,
971,
272,
7666,
63,
875,
63,
2960,
12,
1852,
63,
8939,
63,
5029,
12,
971,
272,
5325,
63,
2960,
63,
2722,
199,
504,
10380,
423,
4672,
492,
485,
2143,
63,
344,
3540,
12,
485,
2708,
63,
344,
3540,
199,
504,
10380,
14,
23004,
492,
29393,
12,
2740,
63,
3029,
63,
1744,
199,
504,
5055,
492,
12863,
421,
199,
3,
437,
5578,
3965,
367,
4052,
282,
1686,
4177,
10734,
2839,
199,
63,
5512,
63,
264,
275,
295,
14,
2014,
8,
82,
23811,
65,
13,
6353,
13,
58,
16,
13,
25,
16341,
32455,
9988,
199,
199,
3,
6659,
7421,
626,
787,
5048,
315,
1263,
1777,
402,
376,
2851,
14,
199,
63,
9223,
63,
3489,
275,
334,
66,
7,
23459,
7,
355,
330,
7,
28114,
11371,
3754,
6793,
358,
199,
199,
63,
4097,
7022,
275,
283,
11371,
18820,
10678,
7,
199,
63,
426,
400,
79,
4414,
275,
1211,
8,
272,
3666,
65,
435,
330,
680,
2143,
1062,
1109,
8,
65,
435,
330,
12,
3193,
430,
272,
367,
282,
315,
485,
4097,
7022,
367,
330,
315,
485,
4097,
7022,
199,
9,
421,
199,
63,
2632,
7075,
275,
5325,
63,
2960,
63,
2722,
8,
18921,
8,
272,
2513,
2632,
7075,
297,
272,
788,
5512,
297,
283,
12652,
297,
283,
515,
297,
283,
1131,
297,
283,
7677,
418,
199,
430,
421,
199,
533,
3523,
2632,
1547,
2632,
7075,
304,
339,
1449,
11823,
533,
402,
520,
647,
26,
533,
1705,
2632,
64,
436,
520,
647,
26,
533,
1705,
5571,
2632,
2313,
2344,
272,
636,
7257,
363,
275,
6248,
339,
347,
3350,
8,
277,
12,
1011,
958,
304,
267,
408,
1767,
376,
2851,
543,
314,
2011,
1338,
12,
871,
367,
5204,
2633,
267,
1627,
892,
1338,
701,
704,
73,
595,
422,
4252,
2368,
787,
2013,
1041,
267,
372,
291,
423,
1814,
3682,
958,
9,
339,
768,
1829,
272,
347,
1591,
8,
277,
304,
267,
408,
1918,
1591,
1777,
402,
314,
2851,
340,
2808,
12,
4257,
658,
403,
2313,
221,
710,
267,
1591,
365,
1902,
314,
6246,
503,
314,
3531,
2287,
26239,
315,
314,
267,
2851,
14,
221,
2779,
911,
440,
1395,
314,
1844,
14,
267,
408,
267,
372,
291,
423,
1294,
63,
1102,
3430,
16,
61,
339,
768,
1829,
272,
347,
13294,
63,
1102,
8,
277,
304,
267,
408,
25348,
8840,
2839,
520,
962,
1705,
1102,
64,
1325,
911,
372,
282,
754,
626,
267,
365,
15297,
370,
10485,
14,
221,
982,
652,
17651,
282,
10154,
626,
365,
440,
10485,
267,
652,
911,
7427,
370,
1305,
3540,
4849,
652,
14,
221,
961,
365,
2997,
367,
2838,
267,
5331,
1380,
314,
2851,
5594,
2387,
10757,
6279,
1759,
4110,
14,
267,
408,
267,
4336,
275,
291,
14,
1102,
267,
340,
4336,
365,
440,
488,
436,
1228,
8,
6310,
12,
1318,
63,
466,
304,
288,
862,
26,
355,
4336,
275,
485,
2143,
63,
344,
3540,
8,
6310,
9,
288,
871,
20872,
26,
355,
4336,
275,
4336,
14,
2143,
360,
4371,
297,
283,
4247,
358,
267,
372,
370,
63,
6106,
8,
6310,
12,
283,
4371,
297,
283,
4247,
358,
339,
768,
1829,
272,
347,
1844,
8,
277,
304,
267,
408,
1918,
1844,
315,
314,
2851,
465,
376,
3000,
340,
652,
1990,
3451,
12,
658,
403,
64,
267,
4257,
14,
221,
961,
1630,
440,
5554,
315,
849,
8873,
14,
267,
408,
267,
862,
26,
288,
4336,
275,
1109,
8,
475,
63,
6106,
8,
277,
423,
1294,
63,
1102,
3430,
17,
2459,
288,
340,
378,
2695,
4336,
2695,
18247,
26,
355,
372,
4336,
267,
871,
334,
3393,
12,
3146,
304,
288,
986,
339,
768,
1829,
272,
347,
1790,
8,
277,
304,
267,
408,
1918,
6299,
1777,
315,
314,
2851,
340,
2808,
12,
658,
403,
64,
267,
4257,
14,
267,
408,
267,
372,
291,
423,
1294,
63,
12652,
3430,
16,
61,
339,
768,
1829,
272,
347,
3434,
8,
277,
304,
267,
408,
1918,
3434,
340,
652,
1990,
1777,
402,
314,
2851,
12,
658,
403,
64,
4257,
14,
267,
961,
1334,
1939,
397,
2851,
15952,
436,
911,
3544,
506,
282,
2649,
1059,
14,
267,
408,
267,
4336,
275,
291,
423,
1294,
63,
1178,
3430,
16,
61,
267,
340,
4336,
365,
440,
488,
26,
288,
372,
485,
633,
63,
12240,
63,
10000,
8,
6310,
9,
339,
768,
1829,
272,
347,
3066,
63,
2473,
8,
277,
304,
267,
408,
1918,
3434,
340,
652,
1990,
1777,
402,
314,
2851,
12,
658,
403,
64,
4257,
14,
267,
25059,
520,
962,
1705,
2473,
64,
642,
1373,
365,
440,
3769,
11203,
14,
267,
408,
267,
372,
291,
423,
1294,
63,
1178,
3430,
16,
61,
339,
768,
1829,
272,
347,
2505,
8,
277,
304,
267,
408,
1918,
2505,
340,
652,
1990,
1777,
402,
314,
2851,
12,
658,
403,
64,
4257,
14,
267,
961,
1334,
1939,
397,
2851,
15952,
436,
911,
3544,
506,
282,
2649,
1059,
14,
267,
408,
267,
4336,
275,
291,
423,
1294,
63,
1178,
3430,
17,
61,
267,
340,
4336,
365,
440,
488,
26,
288,
372,
485,
633,
63,
12240,
63,
10000
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
3603,
272,
32202,
94,
339,
1124,
17719,
14,
3603,
1040,
1202,
370,
5647,
9978,
4975,
3423,
367,
2018,
499,
272,
7097,
12,
7447,
2446,
12016,
4898,
370,
1736,
6818,
314,
5953,
402,
314,
1611,
18,
272,
26678,
436,
2399,
29098,
402,
2649,
2291,
14,
22117,
642,
1990,
2575,
282,
30362,
272,
315,
388,
1856,
6792,
25781,
12,
652,
4788,
2755,
1655,
23515,
2952,
2018,
650,
1159,
272,
1124,
4078,
14,
1122,
1040,
5965,
1630,
2429,
2649,
7684,
14,
1010,
1163,
5932,
12,
272,
642,
859,
3955,
4816,
2877,
8363,
543,
14793,
3365,
5953,
14,
2002,
272,
3063,
642,
859,
3509,
282,
499,
13,
460,
13,
19,
13,
6490,
1771,
719,
402,
2018,
650,
1159,
272,
1124,
4078,
14,
1122,
4542,
1314,
365,
19762,
3261,
13,
6490,
14,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
747,
199,
646,
295,
199,
504,
10380,
423,
5819,
492,
1318,
63,
466,
12,
7843,
18,
12,
370,
63,
2975,
12,
971,
272,
370,
63,
6106,
12,
9031,
63,
475,
63,
875,
12,
862,
63,
14141,
63,
6106,
12,
971,
272,
7666,
63,
875,
63,
2960,
12,
1852,
63,
8939,
63,
5029,
12,
971,
272,
5325,
63,
2960,
63,
2722,
199,
504,
10380,
423,
4672,
492,
485,
2143,
63,
344,
3540,
12,
485,
2708,
63,
344,
3540,
199,
504,
10380,
14,
23004,
492,
29393,
12,
2740,
63,
3029,
63,
1744,
199,
504,
5055,
492,
12863,
421,
199,
3,
437,
5578,
3965,
367,
4052,
282,
1686,
4177,
10734,
2839,
199,
63,
5512,
63,
264,
275,
295,
14,
2014,
8,
82,
23811,
65,
13,
6353,
13,
58,
16,
13,
25,
16341,
32455,
9988,
199,
199,
3,
6659,
7421,
626,
787,
5048,
315,
1263,
1777,
402,
376,
2851,
14,
199,
63,
9223,
63,
3489,
275,
334,
66,
7,
23459,
7,
355,
330,
7,
28114,
11371,
3754,
6793,
358,
199,
199,
63,
4097,
7022,
275,
283,
11371,
18820,
10678,
7,
199,
63,
426,
400,
79,
4414,
275,
1211,
8,
272,
3666,
65,
435,
330,
680,
2143,
1062,
1109,
8,
65,
435,
330,
12,
3193,
430,
272,
367,
282,
315,
485,
4097,
7022,
367,
330,
315,
485,
4097,
7022,
199,
9,
421,
199,
63,
2632,
7075,
275,
5325,
63,
2960,
63,
2722,
8,
18921,
8,
272,
2513,
2632,
7075,
297,
272,
788,
5512,
297,
283,
12652,
297,
283,
515,
297,
283,
1131,
297,
283,
7677,
418,
199,
430,
421,
199,
533,
3523,
2632,
1547,
2632,
7075,
304,
339,
1449,
11823,
533,
402,
520,
647,
26,
533,
1705,
2632,
64,
436,
520,
647,
26,
533,
1705,
5571,
2632,
2313,
2344,
272,
636,
7257,
363,
275,
6248,
339,
347,
3350,
8,
277,
12,
1011,
958,
304,
267,
408,
1767,
376,
2851,
543,
314,
2011,
1338,
12,
871,
367,
5204,
2633,
267,
1627,
892,
1338,
701,
704,
73,
595,
422,
4252,
2368,
787,
2013,
1041,
267,
372,
291,
423,
1814,
3682,
958,
9,
339,
768,
1829,
272,
347,
1591,
8,
277,
304,
267,
408,
1918,
1591,
1777,
402,
314,
2851,
340,
2808,
12,
4257,
658,
403,
2313,
221,
710,
267,
1591,
365,
1902,
314,
6246,
503,
314,
3531,
2287,
26239,
315,
314,
267,
2851,
14,
221,
2779,
911,
440,
1395,
314,
1844,
14,
267,
408,
267,
372,
291,
423,
1294,
63,
1102,
3430,
16,
61,
339,
768,
1829,
272,
347,
13294,
63,
1102,
8,
277,
304,
267,
408,
25348,
8840,
2839,
520,
962,
1705,
1102,
64,
1325,
911,
372,
282,
754,
626,
267,
365,
15297,
370,
10485,
14,
221,
982,
652,
17651,
282,
10154,
626,
365,
440,
10485,
267,
652,
911,
7427,
370,
1305,
3540,
4849,
652,
14,
221,
961,
365,
2997,
367,
2838,
267,
5331,
1380,
314,
2851,
5594,
2387,
10757,
6279,
1759,
4110,
14,
267,
408,
267,
4336,
275,
291,
14,
1102,
267,
340,
4336,
365,
440,
488,
436,
1228,
8,
6310,
12,
1318,
63,
466,
304,
288,
862,
26,
355,
4336,
275,
485,
2143,
63,
344,
3540,
8,
6310,
9,
288,
871,
20872,
26,
355,
4336,
275,
4336,
14,
2143,
360,
4371,
297,
283,
4247,
358,
267,
372,
370,
63,
6106,
8,
6310,
12,
283,
4371,
297,
283,
4247,
358,
339,
768,
1829,
272,
347,
1844,
8,
277,
304,
267,
408,
1918,
1844,
315,
314,
2851,
465,
376,
3000,
340,
652,
1990,
3451,
12,
658,
403,
64,
267,
4257,
14,
221,
961,
1630,
440,
5554,
315,
849,
8873,
14,
267,
408,
267,
862,
26,
288,
4336,
275,
1109,
8,
475,
63,
6106,
8,
277,
423,
1294,
63,
1102,
3430,
17,
2459,
288,
340,
378,
2695,
4336,
2695,
18247,
26,
355,
372,
4336,
267,
871,
334,
3393,
12,
3146,
304,
288,
986,
339,
768,
1829,
272,
347,
1790,
8,
277,
304,
267,
408,
1918,
6299,
1777,
315,
314,
2851,
340,
2808,
12,
658,
403,
64,
267,
4257,
14,
267,
408,
267,
372,
291,
423,
1294,
63,
12652,
3430,
16,
61,
339,
768,
1829,
272,
347,
3434,
8,
277,
304,
267,
408,
1918,
3434,
340,
652,
1990,
1777,
402,
314,
2851,
12,
658,
403,
64,
4257,
14,
267,
961,
1334,
1939,
397,
2851,
15952,
436,
911,
3544,
506,
282,
2649,
1059,
14,
267,
408,
267,
4336,
275,
291,
423,
1294,
63,
1178,
3430,
16,
61,
267,
340,
4336,
365,
440,
488,
26,
288,
372,
485,
633,
63,
12240,
63,
10000,
8,
6310,
9,
339,
768,
1829,
272,
347,
3066,
63,
2473,
8,
277,
304,
267,
408,
1918,
3434,
340,
652,
1990,
1777,
402,
314,
2851,
12,
658,
403,
64,
4257,
14,
267,
25059,
520,
962,
1705,
2473,
64,
642,
1373,
365,
440,
3769,
11203,
14,
267,
408,
267,
372,
291,
423,
1294,
63,
1178,
3430,
16,
61,
339,
768,
1829,
272,
347,
2505,
8,
277,
304,
267,
408,
1918,
2505,
340,
652,
1990,
1777,
402,
314,
2851,
12,
658,
403,
64,
4257,
14,
267,
961,
1334,
1939,
397,
2851,
15952,
436,
911,
3544,
506,
282,
2649,
1059,
14,
267,
408,
267,
4336,
275,
291,
423,
1294,
63,
1178,
3430,
17,
61,
267,
340,
4336,
365,
440,
488,
26,
288,
372,
485,
633,
63,
12240,
63,
10000,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kevin-teddy/gajim
|
src/htmltextview.py
|
2
|
36141
|
# -*- coding:utf-8 -*-
## src/htmltextview.py
##
## Copyright (C) 2005 Gustavo J. A. M. Carneiro
## Copyright (C) 2006 Santiago Gala
## Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org>
## Copyright (C) 2006-2008 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2007 Nikos Kouremenos <kourem AT gmail.com>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
## Julien Pivotto <roidelapluie AT gmail.com>
## Stephan Erb <steve-e AT h3c.de>
##
## This file is part of Gajim.
##
## Gajim is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.
##
'''
A gtk.TextView-based renderer for XHTML-IM, as described in:
http://www.jabber.org/jeps/jep-0071.html
Starting with the version posted by Gustavo Carneiro,
I (Santiago Gala) am trying to make it more compatible
with the markup that docutils generate, and also more
modular.
'''
import gobject
import pango
import gtk
import xml.sax, xml.sax.handler
import re
import warnings
from cStringIO import StringIO
import socket
import time
import urllib2
import operator
if __name__ == '__main__':
from common import i18n
from common import gajim
import tooltips
__all__ = ['HtmlTextView']
whitespace_rx = re.compile('\\s+')
allwhitespace_rx = re.compile('^\\s*$')
# pixels = points * display_resolution
display_resolution = 0.3514598*(gtk.gdk.screen_height() /
float(gtk.gdk.screen_height_mm()))
# embryo of CSS classes
classes = {
#'system-message':';display: none',
'problematic':';color: red',
}
# styles for elements
element_styles = {
'u' : ';text-decoration: underline',
'em' : ';font-style: oblique',
'cite' : '; background-color:rgb(170,190,250); font-style: oblique',
'li' : '; margin-left: 1em; margin-right: 10%',
'strong' : ';font-weight: bold',
'pre' : '; background-color:rgb(190,190,190); font-family: monospace; white-space: pre; margin-left: 1em; margin-right: 10%',
'kbd' : ';background-color:rgb(210,210,210);font-family: monospace',
'blockquote': '; background-color:rgb(170,190,250); margin-left: 2em; margin-right: 10%',
'dt' : ';font-weight: bold; font-style: oblique',
'dd' : ';margin-left: 2em; font-style: oblique'
}
# no difference for the moment
element_styles['dfn'] = element_styles['em']
element_styles['var'] = element_styles['em']
# deprecated, legacy, presentational
element_styles['tt'] = element_styles['kbd']
element_styles['i'] = element_styles['em']
element_styles['b'] = element_styles['strong']
'''
==========
JEP-0071
==========
This Integration Set includes a subset of the modules defined for
XHTML 1.0 but does not redefine any existing modules, nor
does it define any new modules. Specifically, it includes the
following modules only:
- Structure
- Text
* Block
phrasal
addr, blockquote, pre
Struc
div,p
Heading
h1, h2, h3, h4, h5, h6
* Inline
phrasal
abbr, acronym, cite, code, dfn, em, kbd, q, samp, strong, var
structural
br, span
- Hypertext (a)
- List (ul, ol, dl)
- Image (img)
- Style Attribute
Therefore XHTML-IM uses the following content models:
Block.mix
Block-like elements, e.g., paragraphs
Flow.mix
Any block or inline elements
Inline.mix
Character-level elements
InlineNoAnchor.class
Anchor element
InlinePre.mix
Pre element
XHTML-IM also uses the following Attribute Groups:
Core.extra.attrib
TBD
I18n.extra.attrib
TBD
Common.extra
style
...
#block level:
#Heading h
# ( pres = h1 | h2 | h3 | h4 | h5 | h6 )
#Block ( phrasal = address | blockquote | pre )
#NOT ( presentational = hr )
# ( structural = div | p )
#other: section
#Inline ( phrasal = abbr | acronym | cite | code | dfn | em | kbd | q | samp | strong | var )
#NOT ( presentational = b | big | i | small | sub | sup | tt )
# ( structural = br | span )
#Param/Legacy param, font, basefont, center, s, strike, u, dir, menu, isindex
#
'''
BLOCK_HEAD = set(( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', ))
BLOCK_PHRASAL = set(( 'address', 'blockquote', 'pre', ))
BLOCK_PRES = set(( 'hr', )) #not in xhtml-im
BLOCK_STRUCT = set(( 'div', 'p', ))
BLOCK_HACKS = set(( 'table', 'tr' )) # at the very least, they will start line ;)
BLOCK = BLOCK_HEAD.union(BLOCK_PHRASAL).union(BLOCK_STRUCT).union(BLOCK_PRES).union(BLOCK_HACKS)
INLINE_PHRASAL = set('abbr, acronym, cite, code, dfn, em, kbd, q, samp, strong, var'.split(', '))
INLINE_PRES = set('b, i, u, tt'.split(', ')) #not in xhtml-im
INLINE_STRUCT = set('br, span'.split(', '))
INLINE = INLINE_PHRASAL.union(INLINE_PRES).union(INLINE_STRUCT)
LIST_ELEMS = set( 'dl, ol, ul'.split(', '))
for name in BLOCK_HEAD:
num = eval(name[1])
size = (num-1) // 2
weigth = (num - 1) % 2
element_styles[name] = '; font-size: %s; %s' % ( ('large', 'medium', 'small')[size],
('font-weight: bold', 'font-style: oblique')[weigth],
)
def build_patterns(view, config, interface):
# extra, rst does not mark _underline_ or /it/ up
# actually <b>, <i> or <u> are not in the JEP-0071, but are seen in the wild
basic_pattern = r'(?<!\w|\<|/|:)' r'/[^\s/]' r'([^/]*[^\s/])?' r'/(?!\w|/|:)|'\
r'(?<!\w)' r'_[^\s_]' r'([^_]*[^\s_])?' r'_(?!\w)'
view.basic_pattern_re = re.compile(basic_pattern)
# emoticons
emoticons_pattern = ''
try:
if config.get('emoticons_theme'):
# When an emoticon is bordered by an alpha-numeric character it is NOT
# expanded. e.g., foo:) NO, foo :) YES, (brb) NO, (:)) YES, etc.
# We still allow multiple emoticons side-by-side like :P:P:P
# sort keys by length so :qwe emot is checked before :q
keys = interface.emoticons.keys()
keys.sort(interface.on_emoticon_sort)
emoticons_pattern_prematch = ''
emoticons_pattern_postmatch = ''
emoticon_length = 0
for emoticon in keys: # travel thru emoticons list
emoticon_escaped = re.escape(emoticon) # espace regexp metachars
emoticons_pattern += emoticon_escaped + '|'# | means or in regexp
if (emoticon_length != len(emoticon)):
# Build up expressions to match emoticons next to other emoticons
emoticons_pattern_prematch = emoticons_pattern_prematch[:-1] + ')|(?<='
emoticons_pattern_postmatch = emoticons_pattern_postmatch[:-1] + ')|(?='
emoticon_length = len(emoticon)
emoticons_pattern_prematch += emoticon_escaped + '|'
emoticons_pattern_postmatch += emoticon_escaped + '|'
# We match from our list of emoticons, but they must either have
# whitespace, or another emoticon next to it to match successfully
# [\w.] alphanumeric and dot (for not matching 8) in (2.8))
emoticons_pattern = '|' + \
'(?:(?<![\w.]' + emoticons_pattern_prematch[:-1] + '))' + \
'(?:' + emoticons_pattern[:-1] + ')' + \
'(?:(?![\w.]' + emoticons_pattern_postmatch[:-1] + '))'
except Exception:
pass
view.emot_pattern_re = re.compile(emoticons_pattern, re.IGNORECASE)
# because emoticons match later (in the string) they need to be after
# basic matches that may occur earlier
emot_and_basic_pattern = basic_pattern + emoticons_pattern
view.emot_and_basic_re = re.compile(emot_and_basic_pattern, re.IGNORECASE)
def _parse_css_color(color):
'''_parse_css_color(css_color) -> gtk.gdk.Color'''
if color.startswith('rgb(') and color.endswith(')'):
r, g, b = [int(c)*257 for c in color[4:-1].split(',')]
return gtk.gdk.Color(r, g, b)
else:
return gtk.gdk.color_parse(color)
def style_iter(style):
return (map(lambda x:x.strip(),item.split(':', 1)) for item in style.split(';') if len(item.strip()))
class HtmlHandler(xml.sax.handler.ContentHandler):
"""A handler to display html to a gtk textview.
It keeps a stack of "style spans" (start/end element pairs)
and a stack of list counters, for nested lists.
"""
def __init__(self, textview, startiter):
xml.sax.handler.ContentHandler.__init__(self)
self.textbuf = textview.get_buffer()
self.textview = textview
self.iter = startiter
self.text = ''
self.starting=True
self.preserve = False
self.styles = [] # a gtk.TextTag or None, for each span level
self.list_counters = [] # stack (top at head) of list
# counters, or None for unordered list
def _parse_style_color(self, tag, value):
color = _parse_css_color(value)
tag.set_property('foreground-gdk', color)
def _parse_style_background_color(self, tag, value):
color = _parse_css_color(value)
tag.set_property('background-gdk', color)
tag.set_property('paragraph-background-gdk', color)
#FIXME: when we migrate to 2.10 rm this
if gtk.gtk_version >= (2, 8, 5) or gobject.pygtk_version >= (2, 8, 1):
def _get_current_attributes(self):
attrs = self.textview.get_default_attributes()
self.iter.backward_char()
self.iter.get_attributes(attrs)
self.iter.forward_char()
return attrs
else:
# Workaround http://bugzilla.gnome.org/show_bug.cgi?id=317455
def _get_current_style_attr(self, propname, comb_oper=None):
tags = [tag for tag in self.styles if tag is not None]
tags.reverse()
is_set_name = propname + '-set'
value = None
for tag in tags:
if tag.get_property(is_set_name):
if value is None:
value = tag.get_property(propname)
if comb_oper is None:
return value
else:
value = comb_oper(value, tag.get_property(propname))
return value
class _FakeAttrs(object):
__slots__ = ('font', 'font_scale')
def _get_current_attributes(self):
attrs = self._FakeAttrs()
attrs.font_scale = self._get_current_style_attr('scale',
operator.mul)
if attrs.font_scale is None:
attrs.font_scale = 1.0
attrs.font = self._get_current_style_attr('font-desc')
if attrs.font is None:
attrs.font = self.textview.style.font_desc
return attrs
def __parse_length_frac_size_allocate(self, textview, allocation,
frac, callback, args):
callback(allocation.width*frac, *args)
def _parse_length(self, value, font_relative, block_relative, minl, maxl, callback, *args):
'''Parse/calc length, converting to pixels, calls callback(length, *args)
when the length is first computed or changes'''
if value.endswith('%'):
val = float(value[:-1])
sign = cmp(val,0)
# limits: 1% to 500%
val = sign*max(1,min(abs(val),500))
frac = val/100
if font_relative:
attrs = self._get_current_attributes()
font_size = attrs.font.get_size() / pango.SCALE
callback(frac*display_resolution*font_size, *args)
elif block_relative:
# CSS says 'Percentage values: refer to width of the closest
# block-level ancestor'
# This is difficult/impossible to implement, so we use
# textview width instead; a reasonable approximation..
alloc = self.textview.get_allocation()
self.__parse_length_frac_size_allocate(self.textview, alloc,
frac, callback, args)
self.textview.connect('size-allocate',
self.__parse_length_frac_size_allocate,
frac, callback, args)
else:
callback(frac, *args)
return
val = float(value[:-2])
sign = cmp(val,0)
# validate length
val = sign*max(minl,min(abs(val*display_resolution),maxl))
if value.endswith('pt'): # points
callback(val*display_resolution, *args)
elif value.endswith('em'): # ems, the width of the element's font
attrs = self._get_current_attributes()
font_size = attrs.font.get_size() / pango.SCALE
callback(val*display_resolution*font_size, *args)
elif value.endswith('ex'): # x-height, ~ the height of the letter 'x'
# FIXME: figure out how to calculate this correctly
# for now 'em' size is used as approximation
attrs = self._get_current_attributes()
font_size = attrs.font.get_size() / pango.SCALE
callback(val*display_resolution*font_size, *args)
elif value.endswith('px'): # pixels
callback(val, *args)
else:
try:
# TODO: isn't "no units" interpreted as pixels?
val = int(value)
sign = cmp(val,0)
# validate length
val = sign*max(minl,min(abs(val),maxl))
callback(val, *args)
except Exception:
warnings.warn('Unable to parse length value "%s"' % value)
def __parse_font_size_cb(length, tag):
tag.set_property('size-points', length/display_resolution)
__parse_font_size_cb = staticmethod(__parse_font_size_cb)
def _parse_style_display(self, tag, value):
if value == 'none':
tag.set_property('invisible','true')
# FIXME: display: block, inline
def _parse_style_font_size(self, tag, value):
try:
scale = {
'xx-small': pango.SCALE_XX_SMALL,
'x-small': pango.SCALE_X_SMALL,
'small': pango.SCALE_SMALL,
'medium': pango.SCALE_MEDIUM,
'large': pango.SCALE_LARGE,
'x-large': pango.SCALE_X_LARGE,
'xx-large': pango.SCALE_XX_LARGE,
} [value]
except KeyError:
pass
else:
attrs = self._get_current_attributes()
tag.set_property('scale', scale / attrs.font_scale)
return
if value == 'smaller':
tag.set_property('scale', pango.SCALE_SMALL)
return
if value == 'larger':
tag.set_property('scale', pango.SCALE_LARGE)
return
# font relative (5 ~ 4pt, 110 ~ 72pt)
self._parse_length(value, True, False, 5, 110, self.__parse_font_size_cb, tag)
def _parse_style_font_style(self, tag, value):
try:
style = {
'normal': pango.STYLE_NORMAL,
'italic': pango.STYLE_ITALIC,
'oblique': pango.STYLE_OBLIQUE,
} [value]
except KeyError:
warnings.warn('unknown font-style %s' % value)
else:
tag.set_property('style', style)
def __frac_length_tag_cb(self,length, tag, propname):
styles = self._get_style_tags()
if styles:
length += styles[-1].get_property(propname)
tag.set_property(propname, length)
#__frac_length_tag_cb = staticmethod(__frac_length_tag_cb)
def _parse_style_margin_left(self, tag, value):
# block relative
self._parse_length(value, False, True, 1, 1000, self.__frac_length_tag_cb,
tag, 'left-margin')
def _parse_style_margin_right(self, tag, value):
# block relative
self._parse_length(value, False, True, 1, 1000, self.__frac_length_tag_cb,
tag, 'right-margin')
def _parse_style_font_weight(self, tag, value):
# TODO: missing 'bolder' and 'lighter'
try:
weight = {
'100': pango.WEIGHT_ULTRALIGHT,
'200': pango.WEIGHT_ULTRALIGHT,
'300': pango.WEIGHT_LIGHT,
'400': pango.WEIGHT_NORMAL,
'500': pango.WEIGHT_NORMAL,
'600': pango.WEIGHT_BOLD,
'700': pango.WEIGHT_BOLD,
'800': pango.WEIGHT_ULTRABOLD,
'900': pango.WEIGHT_HEAVY,
'normal': pango.WEIGHT_NORMAL,
'bold': pango.WEIGHT_BOLD,
} [value]
except KeyError:
warnings.warn('unknown font-style %s' % value)
else:
tag.set_property('weight', weight)
def _parse_style_font_family(self, tag, value):
tag.set_property('family', value)
def _parse_style_text_align(self, tag, value):
try:
align = {
'left': gtk.JUSTIFY_LEFT,
'right': gtk.JUSTIFY_RIGHT,
'center': gtk.JUSTIFY_CENTER,
'justify': gtk.JUSTIFY_FILL,
} [value]
except KeyError:
warnings.warn('Invalid text-align:%s requested' % value)
else:
tag.set_property('justification', align)
def _parse_style_text_decoration(self, tag, value):
values = value.split(' ')
if 'none' in values:
tag.set_property('underline', pango.UNDERLINE_NONE)
tag.set_property('strikethrough', False)
if 'underline' in values:
tag.set_property('underline', pango.UNDERLINE_SINGLE)
else:
tag.set_property('underline', pango.UNDERLINE_NONE)
if 'line-through' in values:
tag.set_property('strikethrough', True)
else:
tag.set_property('strikethrough', False)
if 'blink' in values:
warnings.warn('text-decoration:blink not implemented')
if 'overline' in values:
warnings.warn('text-decoration:overline not implemented')
def _parse_style_white_space(self, tag, value):
if value == 'pre':
tag.set_property('wrap_mode', gtk.WRAP_NONE)
elif value == 'normal':
tag.set_property('wrap_mode', gtk.WRAP_WORD)
elif value == 'nowrap':
tag.set_property('wrap_mode', gtk.WRAP_NONE)
def __length_tag_cb(self, value, tag, propname):
try:
tag.set_property(propname, value)
except Exception:
gajim.log.warn( "Error with prop: " + propname + " for tag: " + str(tag))
def _parse_style_width(self, tag, value):
if value == 'auto':
return
self._parse_length(value, False, False, 1, 1000, self.__length_tag_cb,
tag, "width")
def _parse_style_height(self, tag, value):
if value == 'auto':
return
self._parse_length(value, False, False, 1, 1000, self.__length_tag_cb,
tag, "height")
# build a dictionary mapping styles to methods, for greater speed
__style_methods = dict()
for style in ('background-color', 'color', 'font-family', 'font-size',
'font-style', 'font-weight', 'margin-left', 'margin-right',
'text-align', 'text-decoration', 'white-space', 'display',
'width', 'height' ):
try:
method = locals()['_parse_style_%s' % style.replace('-', '_')]
except KeyError:
warnings.warn('Style attribute "%s" not yet implemented' % style)
else:
__style_methods[style] = method
del style
# --
def _get_style_tags(self):
return [tag for tag in self.styles if tag is not None]
def _create_url(self, href, title, type_, id_):
'''Process a url tag.
'''
tag = self.textbuf.create_tag(id_)
if href and href[0] != '#':
tag.href = href
tag.type_ = type_ # to be used by the URL handler
tag.connect('event', self.textview.html_hyperlink_handler, 'url', href)
tag.set_property('foreground', '#0000ff')
tag.set_property('underline', pango.UNDERLINE_SINGLE)
tag.is_anchor = True
if title:
tag.title = title
return tag
def _process_img(self, attrs):
'''Process a img tag.
'''
try:
# Wait maximum 1s for connection
socket.setdefaulttimeout(1)
try:
f = urllib2.urlopen(attrs['src'])
except Exception, ex:
gajim.log.debug('Error loading image %s ' % attrs['src'] + str(ex))
pixbuf = None
alt = attrs.get('alt', 'Broken image')
else:
# Wait 0.1s between each byte
try:
f.fp._sock.fp._sock.settimeout(0.5)
except Exception:
pass
# Max image size = 2 MB (to try to prevent DoS)
mem = ''
deadline = time.time() + 3
while True:
if time.time() > deadline:
gajim.log.debug(str('Timeout loading image %s ' % \
attrs['src'] + ex))
mem = ''
alt = attrs.get('alt', '')
if alt:
alt += '\n'
alt += _('Timeout loading image')
break
try:
temp = f.read(100)
except socket.timeout, ex:
gajim.log.debug('Timeout loading image %s ' % attrs['src'] + \
str(ex))
mem = ''
alt = attrs.get('alt', '')
if alt:
alt += '\n'
alt += _('Timeout loading image')
break
if temp:
mem += temp
else:
break
if len(mem) > 2*1024*1024:
alt = attrs.get('alt', '')
if alt:
alt += '\n'
alt += _('Image is too big')
break
pixbuf = None
if mem:
# Caveat: GdkPixbuf is known not to be safe to load
# images from network... this program is now potentially
# hackable ;)
loader = gtk.gdk.PixbufLoader()
dims = [0,0]
def height_cb(length):
dims[1] = length
def width_cb(length):
dims[0] = length
# process width and height attributes
w = attrs.get('width')
h = attrs.get('height')
# override with width and height styles
for attr, val in style_iter(attrs.get('style', '')):
if attr == 'width':
w = val
elif attr == 'height':
h = val
if w:
self._parse_length(w, False, False, 1, 1000, width_cb)
if h:
self._parse_length(h, False, False, 1, 1000, height_cb)
def set_size(pixbuf, w, h, dims):
'''FIXME: floats should be relative to the whole
textview, and resize with it. This needs new
pifbufs for every resize, gtk.gdk.Pixbuf.scale_simple
or similar.
'''
if isinstance(dims[0], float):
dims[0] = int(dims[0]*w)
elif not dims[0]:
dims[0] = w
if isinstance(dims[1], float):
dims[1] = int(dims[1]*h)
if not dims[1]:
dims[1] = h
loader.set_size(*dims)
if w or h:
loader.connect('size-prepared', set_size, dims)
loader.write(mem)
loader.close()
pixbuf = loader.get_pixbuf()
alt = attrs.get('alt', '')
if pixbuf is not None:
tags = self._get_style_tags()
if tags:
tmpmark = self.textbuf.create_mark(None, self.iter, True)
self.textbuf.insert_pixbuf(self.iter, pixbuf)
self.starting = False
if tags:
start = self.textbuf.get_iter_at_mark(tmpmark)
for tag in tags:
self.textbuf.apply_tag(tag, start, self.iter)
self.textbuf.delete_mark(tmpmark)
else:
self._insert_text('[IMG: %s]' % alt)
except Exception, ex:
gajim.log.error('Error loading image ' + str(ex))
pixbuf = None
alt = attrs.get('alt', 'Broken image')
try:
loader.close()
except Exception:
pass
return pixbuf
def _begin_span(self, style, tag=None, id_=None):
if style is None:
self.styles.append(tag)
return None
if tag is None:
if id_:
tag = self.textbuf.create_tag(id_)
else:
tag = self.textbuf.create_tag() # we create anonymous tag
for attr, val in style_iter(style):
attr = attr.lower()
val = val
try:
method = self.__style_methods[attr]
except KeyError:
warnings.warn('Style attribute "%s" requested '
'but not yet implemented' % attr)
else:
method(self, tag, val)
self.styles.append(tag)
def _end_span(self):
self.styles.pop()
def _jump_line(self):
self.textbuf.insert_with_tags_by_name(self.iter, '\n', 'eol')
self.starting = True
def _insert_text(self, text):
if self.starting and text != '\n':
self.starting = (text[-1] == '\n')
tags = self._get_style_tags()
if tags:
self.textbuf.insert_with_tags(self.iter, text, *tags)
else:
self.textbuf.insert(self.iter, text)
def _starts_line(self):
return self.starting or self.iter.starts_line()
def _flush_text(self):
if not self.text: return
text, self.text = self.text, ''
if not self.preserve:
text = text.replace('\n', ' ')
self.handle_specials(whitespace_rx.sub(' ', text))
else:
self._insert_text(text.strip('\n'))
def _anchor_event(self, tag, textview, event, iter_, href, type_):
if event.type == gtk.gdk.BUTTON_PRESS:
self.textview.emit('url-clicked', href, type_)
return True
return False
def handle_specials(self, text):
index = 0
se = self.textview.config.get('show_ascii_formatting_chars')
af = gajim.config.get('ascii_formatting')
if self.textview.config.get('emoticons_theme'):
if af:
iterator = self.textview.emot_and_basic_re.finditer(text)
else:
iterator = self.textview.emot_pattern_re.finditer(text)
elif af:
iterator = self.textview.basic_pattern_re.finditer(text)
else:
iterator = []
for match in iterator:
start, end = match.span()
special_text = text[start:end]
if start != 0:
self._insert_text(text[index:start])
index = end # update index
#emoticons
possible_emot_ascii_caps = special_text.upper() # emoticons keys are CAPS
if self.textview.config.get('emoticons_theme') and \
possible_emot_ascii_caps in self.textview.interface.emoticons.keys():
#it's an emoticon
emot_ascii = possible_emot_ascii_caps
anchor = self.textbuf.create_child_anchor(self.iter)
img = gtk.Image()
img.set_from_file(self.textview.interface.emoticons[emot_ascii])
img.show()
# TODO: add alt/tooltip with the special_text (a11y)
self.textview.add_child_at_anchor(img, anchor)
elif af:
# now print it
if special_text.startswith('/'): # it's explicit italics
self.startElement('i', {})
elif special_text.startswith('_'): # it's explicit underline
self.startElement('u', {})
if se: self._insert_text(special_text[0])
self.handle_specials(special_text[1:-1])
if se: self._insert_text(special_text[0])
if special_text.startswith('_'): # it's explicit underline
self.endElement('u')
if special_text.startswith('/'): # it's explicit italics
self.endElement('i')
if index < len(text):
self._insert_text(text[index:])
def characters(self, content):
if self.preserve:
self.text += content
return
if allwhitespace_rx.match(content) is not None and self._starts_line():
self.text += ' '
return
self.text += content
self.starting = False
def startElement(self, name, attrs):
self._flush_text()
klass = [i for i in attrs.get('class',' ').split(' ') if i]
style = ''
#Add styles defined for classes
for k in klass:
if k in classes:
style += classes[k]
tag = None
#FIXME: if we want to use id, it needs to be unique across
# the whole textview, so we need to add something like the
# message-id to it.
#id_ = attrs.get('id',None)
id_ = None
if name == 'a':
#TODO: accesskey, charset, hreflang, rel, rev, tabindex, type
href = attrs.get('href', None)
if not href:
href = attrs.get('HREF', None)
# Gaim sends HREF instead of href
title = attrs.get('title', attrs.get('rel',href))
type_ = attrs.get('type', None)
tag = self._create_url(href, title, type_, id_)
elif name == 'blockquote':
cite = attrs.get('cite', None)
if cite:
tag = self.textbuf.create_tag(id_)
tag.title = title
tag.is_anchor = True
elif name in LIST_ELEMS:
style += ';margin-left: 2em'
elif name == 'img':
tag = self._process_img(attrs)
if name in element_styles:
style += element_styles[name]
# so that explicit styles override implicit ones,
# we add the attribute last
style += ";"+attrs.get('style','')
if style == '':
style = None
self._begin_span(style, tag, id_)
if name == 'br':
pass # handled in endElement
elif name == 'hr':
pass # handled in endElement
elif name in BLOCK:
if not self._starts_line():
self._jump_line()
if name == 'pre':
self.preserve = True
elif name == 'span':
pass
elif name in ('dl', 'ul'):
if not self._starts_line():
self._jump_line()
self.list_counters.append(None)
elif name == 'ol':
if not self._starts_line():
self._jump_line()
self.list_counters.append(0)
elif name == 'li':
if self.list_counters[-1] is None:
li_head = unichr(0x2022)
else:
self.list_counters[-1] += 1
li_head = '%i.' % self.list_counters[-1]
self.text = ' '*len(self.list_counters)*4 + li_head + ' '
self._flush_text()
self.starting = True
elif name == 'dd':
self._jump_line()
elif name == 'dt':
if not self.starting:
self._jump_line()
elif name in ('a', 'img', 'body', 'html'):
pass
elif name in INLINE:
pass
else:
warnings.warn('Unhandled element "%s"' % name)
def endElement(self, name):
endPreserving = False
newLine = False
if name == 'br':
newLine = True
elif name == 'hr':
#FIXME: plenty of unused attributes (width, height,...) :)
self._jump_line()
try:
self.textbuf.insert_pixbuf(self.iter, self.textview.focus_out_line_pixbuf)
#self._insert_text(u'\u2550'*40)
self._jump_line()
except Exception, e:
gajim.log.debug(str('Error in hr'+e))
elif name in LIST_ELEMS:
self.list_counters.pop()
elif name == 'li':
newLine = True
elif name == 'img':
pass
elif name == 'body' or name == 'html':
pass
elif name == 'a':
pass
elif name in INLINE:
pass
elif name in ('dd', 'dt', ):
pass
elif name in BLOCK:
if name == 'pre':
endPreserving = True
else:
warnings.warn("Unhandled element '%s'" % name)
self._flush_text()
if endPreserving:
self.preserve = False
if newLine:
self._jump_line()
self._end_span()
#if not self._starts_line():
# self.text = ' '
class HtmlTextView(gtk.TextView):
def __init__(self):
gobject.GObject.__init__(self)
self.set_wrap_mode(gtk.WRAP_CHAR)
self.set_editable(False)
self._changed_cursor = False
self.connect('destroy', self.__destroy_event)
self.connect('motion-notify-event', self.__motion_notify_event)
self.connect('leave-notify-event', self.__leave_event)
self.connect('enter-notify-event', self.__motion_notify_event)
self.get_buffer().create_tag('eol', scale = pango.SCALE_XX_SMALL)
self.tooltip = tooltips.BaseTooltip()
self.config = gajim.config
self.interface = gajim.interface
# end big hack
build_patterns(self,gajim.config,gajim.interface)
def __destroy_event(self, widget):
if self.tooltip.timeout != 0:
self.tooltip.hide_tooltip()
def __leave_event(self, widget, event):
if self._changed_cursor:
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.XTERM))
self._changed_cursor = False
def show_tooltip(self, tag):
if not self.tooltip.win:
# check if the current pointer is still over the line
x, y, _ = self.window.get_pointer()
x, y = self.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
tags = self.get_iter_at_location(x, y).get_tags()
is_over_anchor = False
for tag_ in tags:
if getattr(tag_, 'is_anchor', False):
is_over_anchor = True
break
if not is_over_anchor:
return
text = getattr(tag, 'title', False)
if text:
pointer = self.get_pointer()
position = self.window.get_origin()
self.tooltip.show_tooltip(text, 8, position[1] + pointer[1])
def __motion_notify_event(self, widget, event):
x, y, _ = widget.window.get_pointer()
x, y = widget.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
tags = widget.get_iter_at_location(x, y).get_tags()
is_over_anchor = False
for tag in tags:
if getattr(tag, 'is_anchor', False):
is_over_anchor = True
break
if self.tooltip.timeout != 0:
# Check if we should hide the line tooltip
if not is_over_anchor:
self.tooltip.hide_tooltip()
if not self._changed_cursor and is_over_anchor:
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
self._changed_cursor = True
self.tooltip.timeout = gobject.timeout_add(500, self.show_tooltip, tag)
elif self._changed_cursor and not is_over_anchor:
window = widget.get_window(gtk.TEXT_WINDOW_TEXT)
window.set_cursor(gtk.gdk.Cursor(gtk.gdk.XTERM))
self._changed_cursor = False
return False
def display_html(self, html):
buffer = self.get_buffer()
eob = buffer.get_end_iter()
## this works too if libxml2 is not available
# parser = xml.sax.make_parser(['drv_libxml2'])
# parser.setFeature(xml.sax.handler.feature_validation, True)
parser = xml.sax.make_parser()
parser.setContentHandler(HtmlHandler(self, eob))
parser.parse(StringIO(html))
# too much space after :)
#if not eob.starts_line():
# buffer.insert(eob, '\n')
change_cursor = None
if __name__ == '__main__':
import os
from common import gajim
class log(object):
def debug(self, text):
print "debug:", text
def warn(self, text):
print "warn;", text
def error(self,text):
print "error;", text
gajim.log=log()
if gajim.config.get('emoticons_theme'):
print "emoticons"
htmlview = HtmlTextView()
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png')
# use this for hr
htmlview.focus_out_line_pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_file)
tooltip = tooltips.BaseTooltip()
def on_textview_motion_notify_event(widget, event):
'''change the cursor to a hand when we are over a mail or an url'''
global change_cursor
pointer_x, pointer_y, spam = htmlview.window.get_pointer()
x, y = htmlview.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer_x,
pointer_y)
tags = htmlview.get_iter_at_location(x, y).get_tags()
if change_cursor:
htmlview.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
gtk.gdk.Cursor(gtk.gdk.XTERM))
change_cursor = None
tag_table = htmlview.get_buffer().get_tag_table()
over_line = False
for tag in tags:
try:
if tag.is_anchor:
htmlview.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
gtk.gdk.Cursor(gtk.gdk.HAND2))
change_cursor = tag
elif tag == tag_table.lookup('focus-out-line'):
over_line = True
except: pass
#if line_tooltip.timeout != 0:
# Check if we should hide the line tooltip
# if not over_line:
# line_tooltip.hide_tooltip()
#if over_line and not line_tooltip.win:
# line_tooltip.timeout = gobject.timeout_add(500,
# show_line_tooltip)
# htmlview.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
# gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
# change_cursor = tag
htmlview.connect('motion_notify_event', on_textview_motion_notify_event)
def handler(texttag, widget, event, iter_, kind, href):
if event.type == gtk.gdk.BUTTON_PRESS:
print href
htmlview.html_hyperlink_handler = handler
htmlview.display_html('<div><span style="color: red; text-decoration:underline">Hello</span><br/>\n'
' <img src="http://images.slashdot.org/topics/topicsoftware.gif"/><br/>\n'
' <span style="font-size: 500%; font-family: serif">World</span>\n'
'</div>\n')
htmlview.display_html('<hr />')
htmlview.display_html('''
<p style='font-size:large'>
<span style='font-style: italic'>O<span style='font-size:larger'>M</span>G</span>,
I'm <span style='color:green'>green</span>
with <span style='font-weight: bold'>envy</span>!
</p>
''')
htmlview.display_html('<hr />')
htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'>
<p>As Emerson said in his essay <span style='font-style: italic; background-color:cyan'>Self-Reliance</span>:</p>
<p style='margin-left: 5px; margin-right: 2%'>
"A foolish consistency is the hobgoblin of little minds."
</p>
</body>
''')
htmlview.display_html('<hr />')
htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'>
<p style='text-align:center'>Hey, are you licensed to <a href='http://www.jabber.org/'>Jabber</a>?</p>
<p style='text-align:right'><img src='http://www.jabber.org/images/psa-license.jpg'
alt='A License to Jabber'
width='50%' height='50%'
/></p>
</body>
''')
htmlview.display_html('<hr />')
htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'>
<ul style='background-color:rgb(120,140,100)'>
<li> One </li>
<li> Two </li>
<li> Three </li>
</ul><hr /><pre style="background-color:rgb(120,120,120)">def fac(n):
def faciter(n,acc):
if n==0: return acc
return faciter(n-1, acc*n)
if n<0: raise ValueError('Must be non-negative')
return faciter(n,1)</pre>
</body>
''')
htmlview.display_html('<hr />')
htmlview.display_html('''
<body xmlns='http://www.w3.org/1999/xhtml'>
<ol style='background-color:rgb(120,140,100)'>
<li> One </li>
<li> Two is nested: <ul style='background-color:rgb(200,200,100)'>
<li> One </li>
<li style='font-size:50%'> Two </li>
<li style='font-size:200%'> Three </li>
<li style='font-size:9999pt'> Four </li>
</ul></li>
<li> Three </li></ol>
</body>
''')
htmlview.show()
sw = gtk.ScrolledWindow()
sw.set_property('hscrollbar-policy', gtk.POLICY_AUTOMATIC)
sw.set_property('vscrollbar-policy', gtk.POLICY_AUTOMATIC)
sw.set_property('border-width', 0)
sw.add(htmlview)
sw.show()
frame = gtk.Frame()
frame.set_shadow_type(gtk.SHADOW_IN)
frame.show()
frame.add(sw)
w = gtk.Window()
w.add(frame)
w.set_default_size(400, 300)
w.show_all()
w.connect('destroy', lambda w: gtk.main_quit())
gtk.main()
# vim: se ts=3:
|
gpl-3.0
|
[
3,
1882,
2803,
26,
1624,
13,
24,
1882,
199,
309,
2928,
15,
1360,
505,
1345,
14,
647,
199,
309,
199,
309,
1898,
334,
35,
9,
11811,
598,
833,
1214,
79,
1603,
14,
437,
14,
603,
14,
14243,
685,
14352,
199,
309,
1898,
334,
35,
9,
8315,
428,
4466,
14315,
598,
14774,
199,
309,
1898,
334,
35,
9,
8315,
13,
9488,
1603,
69,
290,
13,
45,
759,
69,
12643,
19857,
1005,
665,
74,
1017,
15059,
1127,
7751,
14,
1308,
30,
199,
309,
1898,
334,
35,
9,
8315,
13,
9300,
1488,
1189,
7005,
656,
348,
12974,
665,
9209,
1904,
15059,
1127,
5294,
443,
14,
1308,
30,
199,
309,
1898,
334,
35,
9,
10219,
653,
3258,
736,
1804,
79,
608,
1410,
736,
665,
7697,
608,
77,
15059,
29712,
14,
957,
30,
199,
309,
1898,
334,
35,
9,
9079,
1603,
265,
1619,
290,
22985,
274,
692,
281,
665,
3596,
13,
5294,
74,
1017,
15059,
3330,
415,
6080,
14,
1308,
30,
199,
309,
8540,
1603,
13987,
287,
510,
13685,
475,
665,
293,
2655,
416,
1168,
85,
1873,
15059,
29712,
14,
957,
30,
199,
309,
8540,
17854,
16014,
221,
539,
66,
665,
1597,
432,
13,
69,
15059,
394,
19,
67,
14,
271,
30,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
598,
9091,
1017,
14,
199,
309,
199,
309,
598,
9091,
1017,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
199,
309,
701,
314,
2868,
2290,
2752,
27,
1015,
650,
1454,
14,
199,
309,
199,
309,
598,
9091,
1017,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
309,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
598,
9091,
1017,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
199,
2344,
199,
33,
8116,
14,
1872,
2768,
13,
6788,
11889,
367,
26223,
13,
1469,
12,
465,
11736,
315,
26,
523,
1455,
921,
1544,
14,
25075,
14,
1308,
15,
6532,
1190,
15,
74,
1545,
13,
383,
3172,
14,
1360,
199,
199,
14139,
543,
314,
1015,
22752,
701,
598,
833,
1214,
79,
14243,
685,
14352,
12,
199,
41,
334,
51,
4466,
14315,
598,
14774,
9,
8140,
9936,
370,
1852,
652,
1655,
9025,
199,
1045,
314,
9189,
626,
18382,
3550,
12,
436,
2597,
1655,
199,
1494,
2238,
14,
199,
199,
2344,
199,
199,
646,
25595,
199,
646,
299,
17771,
199,
646,
8116,
199,
646,
2748,
14,
14338,
12,
2748,
14,
14338,
14,
2232,
199,
646,
295,
199,
646,
3598,
199,
504,
15073,
492,
5228,
199,
646,
2838,
199,
646,
900,
199,
646,
4011,
18,
199,
646,
4182,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
504,
2863,
492,
284,
1085,
78,
199,
504,
2863,
492,
486,
9091,
1017,
199,
199,
646,
4744,
25842,
421,
199,
363,
452,
363,
275,
788,
12957,
1872,
2768,
418,
199,
199,
8506,
63,
6872,
275,
295,
14,
2014,
11671,
83,
13854,
199,
452,
8506,
63,
6872,
275,
295,
14,
2014,
9097,
1103,
83,
10,
9988,
199,
199,
3,
11094,
275,
4501,
627,
2929,
63,
12588,
199,
2918,
63,
12588,
275,
378,
14,
1276,
1079,
15897,
5830,
12275,
14,
24697,
14,
5410,
63,
3333,
342,
1182,
1871,
198,
1609,
8,
12275,
14,
24697,
14,
5410,
63,
3333,
63,
596,
4059,
199,
199,
3,
25316,
651,
79,
402,
15750,
3992,
199,
2888,
275,
469,
199,
198,
19367,
2253,
13,
1188,
5242,
27,
2918,
26,
7179,
297,
199,
198,
7,
496,
31197,
5242,
27,
2326,
26,
8992,
297,
199,
93,
199,
199,
3,
15725,
367,
4008,
199,
2108,
63,
12955,
275,
469,
507,
198,
7,
85,
7,
1057,
198,
26,
14289,
505,
13,
6518,
425,
26,
25735,
297,
507,
198,
7,
5633,
7,
198,
198,
26,
14289,
4246,
13,
2487,
26,
2607,
317,
544,
297,
507,
198,
7,
25171,
7,
198,
198,
26,
14289,
8020,
13,
2326,
26,
10090,
8,
11010,
12,
12205,
12,
7991,
2736,
5023,
13,
2487,
26,
2607,
317,
544,
297,
507,
198,
7,
317,
7,
198,
198,
26,
14289,
11042,
13,
3039,
26,
413,
5633,
27,
11042,
13,
1019,
26,
1616,
28575,
507,
198,
1159,
454,
951,
7,
198,
26,
14289,
4246,
13,
3463,
26,
17268,
297,
507,
198,
7,
657,
7,
198,
198,
26,
14289,
8020,
13,
2326,
26,
10090,
8,
12205,
12,
12205,
12,
12205,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
10424,
13,
2638,
26,
876,
27,
11042,
13,
3039,
26,
413,
5633,
27,
11042,
13,
1019,
26,
1616,
28575,
507,
198,
7,
75,
3691,
7,
198,
198,
26,
14289,
7451,
13,
2326,
26,
10090,
8,
12725,
12,
12725,
12,
12725,
2736,
4246,
13,
6606,
26,
3485,
17601,
297,
507,
198,
7,
28623,
356,
14289,
8020,
13,
2326,
26,
10090,
8,
11010,
12,
12205,
12,
7991,
2736,
11042,
13,
3039,
26,
499,
5633,
27,
11042,
13,
1019,
26,
1616,
28575,
507,
198,
5121,
84,
7,
198,
198,
26,
14289,
4246,
13,
3463,
26,
17268,
27,
5023,
13,
2487,
26,
2607,
317,
544,
297,
507,
198,
5121,
68,
7,
198,
198,
26,
14289,
9650,
13,
3039,
26,
499,
5633,
27,
5023,
13,
2487,
26,
2607,
317,
544,
7,
199,
93,
199,
3,
949,
8865,
367,
314,
12427,
199,
2108,
63,
12955,
459,
1587,
78,
418,
275,
1819,
63,
12955,
459,
5633,
418,
199,
2108,
63,
12955,
459,
1391,
418,
275,
1819,
63,
12955,
459,
5633,
418,
199,
3,
5906,
12,
12139,
12,
3451,
6279,
199,
2108,
63,
12955,
459,
6215,
418,
221,
275,
1819,
63,
12955,
459,
75,
3691,
418,
199,
2108,
63,
12955,
459,
73,
418,
257,
275,
1819,
63,
12955,
459,
5633,
418,
199,
2108,
63,
12955,
459,
66,
418,
257,
275,
1819,
63,
12955,
459,
9370,
418,
199,
199,
2344,
199,
17575,
523,
1603,
6102,
13,
383,
3172,
199,
17575,
199,
199,
2765,
27561,
2494,
6952,
282,
10026,
402,
314,
4621,
3247,
367,
221,
199,
56,
4943,
413,
14,
16
] |
[
1882,
2803,
26,
1624,
13,
24,
1882,
199,
309,
2928,
15,
1360,
505,
1345,
14,
647,
199,
309,
199,
309,
1898,
334,
35,
9,
11811,
598,
833,
1214,
79,
1603,
14,
437,
14,
603,
14,
14243,
685,
14352,
199,
309,
1898,
334,
35,
9,
8315,
428,
4466,
14315,
598,
14774,
199,
309,
1898,
334,
35,
9,
8315,
13,
9488,
1603,
69,
290,
13,
45,
759,
69,
12643,
19857,
1005,
665,
74,
1017,
15059,
1127,
7751,
14,
1308,
30,
199,
309,
1898,
334,
35,
9,
8315,
13,
9300,
1488,
1189,
7005,
656,
348,
12974,
665,
9209,
1904,
15059,
1127,
5294,
443,
14,
1308,
30,
199,
309,
1898,
334,
35,
9,
10219,
653,
3258,
736,
1804,
79,
608,
1410,
736,
665,
7697,
608,
77,
15059,
29712,
14,
957,
30,
199,
309,
1898,
334,
35,
9,
9079,
1603,
265,
1619,
290,
22985,
274,
692,
281,
665,
3596,
13,
5294,
74,
1017,
15059,
3330,
415,
6080,
14,
1308,
30,
199,
309,
8540,
1603,
13987,
287,
510,
13685,
475,
665,
293,
2655,
416,
1168,
85,
1873,
15059,
29712,
14,
957,
30,
199,
309,
8540,
17854,
16014,
221,
539,
66,
665,
1597,
432,
13,
69,
15059,
394,
19,
67,
14,
271,
30,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
598,
9091,
1017,
14,
199,
309,
199,
309,
598,
9091,
1017,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
199,
309,
701,
314,
2868,
2290,
2752,
27,
1015,
650,
1454,
14,
199,
309,
199,
309,
598,
9091,
1017,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
309,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
598,
9091,
1017,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
199,
2344,
199,
33,
8116,
14,
1872,
2768,
13,
6788,
11889,
367,
26223,
13,
1469,
12,
465,
11736,
315,
26,
523,
1455,
921,
1544,
14,
25075,
14,
1308,
15,
6532,
1190,
15,
74,
1545,
13,
383,
3172,
14,
1360,
199,
199,
14139,
543,
314,
1015,
22752,
701,
598,
833,
1214,
79,
14243,
685,
14352,
12,
199,
41,
334,
51,
4466,
14315,
598,
14774,
9,
8140,
9936,
370,
1852,
652,
1655,
9025,
199,
1045,
314,
9189,
626,
18382,
3550,
12,
436,
2597,
1655,
199,
1494,
2238,
14,
199,
199,
2344,
199,
199,
646,
25595,
199,
646,
299,
17771,
199,
646,
8116,
199,
646,
2748,
14,
14338,
12,
2748,
14,
14338,
14,
2232,
199,
646,
295,
199,
646,
3598,
199,
504,
15073,
492,
5228,
199,
646,
2838,
199,
646,
900,
199,
646,
4011,
18,
199,
646,
4182,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
504,
2863,
492,
284,
1085,
78,
199,
504,
2863,
492,
486,
9091,
1017,
199,
199,
646,
4744,
25842,
421,
199,
363,
452,
363,
275,
788,
12957,
1872,
2768,
418,
199,
199,
8506,
63,
6872,
275,
295,
14,
2014,
11671,
83,
13854,
199,
452,
8506,
63,
6872,
275,
295,
14,
2014,
9097,
1103,
83,
10,
9988,
199,
199,
3,
11094,
275,
4501,
627,
2929,
63,
12588,
199,
2918,
63,
12588,
275,
378,
14,
1276,
1079,
15897,
5830,
12275,
14,
24697,
14,
5410,
63,
3333,
342,
1182,
1871,
198,
1609,
8,
12275,
14,
24697,
14,
5410,
63,
3333,
63,
596,
4059,
199,
199,
3,
25316,
651,
79,
402,
15750,
3992,
199,
2888,
275,
469,
199,
198,
19367,
2253,
13,
1188,
5242,
27,
2918,
26,
7179,
297,
199,
198,
7,
496,
31197,
5242,
27,
2326,
26,
8992,
297,
199,
93,
199,
199,
3,
15725,
367,
4008,
199,
2108,
63,
12955,
275,
469,
507,
198,
7,
85,
7,
1057,
198,
26,
14289,
505,
13,
6518,
425,
26,
25735,
297,
507,
198,
7,
5633,
7,
198,
198,
26,
14289,
4246,
13,
2487,
26,
2607,
317,
544,
297,
507,
198,
7,
25171,
7,
198,
198,
26,
14289,
8020,
13,
2326,
26,
10090,
8,
11010,
12,
12205,
12,
7991,
2736,
5023,
13,
2487,
26,
2607,
317,
544,
297,
507,
198,
7,
317,
7,
198,
198,
26,
14289,
11042,
13,
3039,
26,
413,
5633,
27,
11042,
13,
1019,
26,
1616,
28575,
507,
198,
1159,
454,
951,
7,
198,
26,
14289,
4246,
13,
3463,
26,
17268,
297,
507,
198,
7,
657,
7,
198,
198,
26,
14289,
8020,
13,
2326,
26,
10090,
8,
12205,
12,
12205,
12,
12205,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
10424,
13,
2638,
26,
876,
27,
11042,
13,
3039,
26,
413,
5633,
27,
11042,
13,
1019,
26,
1616,
28575,
507,
198,
7,
75,
3691,
7,
198,
198,
26,
14289,
7451,
13,
2326,
26,
10090,
8,
12725,
12,
12725,
12,
12725,
2736,
4246,
13,
6606,
26,
3485,
17601,
297,
507,
198,
7,
28623,
356,
14289,
8020,
13,
2326,
26,
10090,
8,
11010,
12,
12205,
12,
7991,
2736,
11042,
13,
3039,
26,
499,
5633,
27,
11042,
13,
1019,
26,
1616,
28575,
507,
198,
5121,
84,
7,
198,
198,
26,
14289,
4246,
13,
3463,
26,
17268,
27,
5023,
13,
2487,
26,
2607,
317,
544,
297,
507,
198,
5121,
68,
7,
198,
198,
26,
14289,
9650,
13,
3039,
26,
499,
5633,
27,
5023,
13,
2487,
26,
2607,
317,
544,
7,
199,
93,
199,
3,
949,
8865,
367,
314,
12427,
199,
2108,
63,
12955,
459,
1587,
78,
418,
275,
1819,
63,
12955,
459,
5633,
418,
199,
2108,
63,
12955,
459,
1391,
418,
275,
1819,
63,
12955,
459,
5633,
418,
199,
3,
5906,
12,
12139,
12,
3451,
6279,
199,
2108,
63,
12955,
459,
6215,
418,
221,
275,
1819,
63,
12955,
459,
75,
3691,
418,
199,
2108,
63,
12955,
459,
73,
418,
257,
275,
1819,
63,
12955,
459,
5633,
418,
199,
2108,
63,
12955,
459,
66,
418,
257,
275,
1819,
63,
12955,
459,
9370,
418,
199,
199,
2344,
199,
17575,
523,
1603,
6102,
13,
383,
3172,
199,
17575,
199,
199,
2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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ravenac95/virtstrap
|
virtstrap-core/tests/test_hooks.py
|
1
|
1073
|
"""
Test Plugins
------------
"""
from nose.tools import raises
from virtstrap.hooks import Hook, create
def test_initialize_Hook():
hook = Hook()
@raises(NotImplementedError)
def test_run_hook():
hook = Hook()
options = None
hook.run('fake_event', options)
def test_fake_hook():
class FakeHook(Hook):
name = 'fake'
was_run = False
def run(self, event, options, **kwargs):
assert event == 'fake_event'
assert options == 'options'
self.was_run = True
hook = FakeHook()
hook.execute('fake_event', 'options')
assert hook.was_run, 'Hook did not make it to run'
def test_create_hook():
was_run = False
@create('command', ['event'])
def fake_hook(event, options, **kwargs):
assert event == 'event'
options['test'] = True
options = {'test': False}
assert fake_hook.name == 'fake_hook'
assert fake_hook.command == 'command'
fake_hook.execute('event', options)
assert options['test'], 'Hook did not make it to run the function'
|
mit
|
[
624,
199,
774,
30317,
199,
4559,
199,
199,
624,
199,
504,
11354,
14,
2537,
492,
6534,
199,
504,
12043,
7868,
14,
7922,
492,
24837,
12,
1218,
199,
199,
318,
511,
63,
8489,
63,
8481,
837,
272,
5759,
275,
24837,
342,
199,
199,
32,
3536,
8,
18097,
9,
199,
318,
511,
63,
1065,
63,
3664,
837,
272,
5759,
275,
24837,
342,
272,
1511,
275,
488,
272,
5759,
14,
1065,
360,
3183,
63,
1430,
297,
1511,
9,
199,
199,
318,
511,
63,
3183,
63,
3664,
837,
272,
1021,
7777,
8481,
8,
8481,
304,
267,
536,
275,
283,
3183,
7,
267,
1990,
63,
1065,
275,
756,
398,
347,
1255,
8,
277,
12,
1566,
12,
1511,
12,
1011,
958,
304,
288,
702,
1566,
508,
283,
3183,
63,
1430,
7,
288,
702,
1511,
508,
283,
1419,
7,
288,
291,
14,
10274,
63,
1065,
275,
715,
339,
5759,
275,
7777,
8481,
342,
272,
5759,
14,
2526,
360,
3183,
63,
1430,
297,
283,
1419,
358,
272,
702,
5759,
14,
10274,
63,
1065,
12,
283,
8481,
8103,
440,
1852,
652,
370,
1255,
7,
199,
199,
318,
511,
63,
981,
63,
3664,
837,
272,
1990,
63,
1065,
275,
756,
272,
768,
981,
360,
1531,
297,
788,
1430,
1105,
272,
347,
4026,
63,
3664,
8,
1430,
12,
1511,
12,
1011,
958,
304,
267,
702,
1566,
508,
283,
1430,
7,
267,
1511,
459,
396,
418,
275,
715,
339,
1511,
275,
791,
396,
356,
756,
93,
339,
702,
4026,
63,
3664,
14,
354,
508,
283,
3183,
63,
3664,
7,
272,
702,
4026,
63,
3664,
14,
1531,
508,
283,
1531,
7,
2286,
4026,
63,
3664,
14,
2526,
360,
1430,
297,
1511,
9,
272,
702,
1511,
459,
396,
995,
283,
8481,
8103,
440,
1852,
652,
370,
1255,
314,
805,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
774,
30317,
199,
4559,
199,
199,
624,
199,
504,
11354,
14,
2537,
492,
6534,
199,
504,
12043,
7868,
14,
7922,
492,
24837,
12,
1218,
199,
199,
318,
511,
63,
8489,
63,
8481,
837,
272,
5759,
275,
24837,
342,
199,
199,
32,
3536,
8,
18097,
9,
199,
318,
511,
63,
1065,
63,
3664,
837,
272,
5759,
275,
24837,
342,
272,
1511,
275,
488,
272,
5759,
14,
1065,
360,
3183,
63,
1430,
297,
1511,
9,
199,
199,
318,
511,
63,
3183,
63,
3664,
837,
272,
1021,
7777,
8481,
8,
8481,
304,
267,
536,
275,
283,
3183,
7,
267,
1990,
63,
1065,
275,
756,
398,
347,
1255,
8,
277,
12,
1566,
12,
1511,
12,
1011,
958,
304,
288,
702,
1566,
508,
283,
3183,
63,
1430,
7,
288,
702,
1511,
508,
283,
1419,
7,
288,
291,
14,
10274,
63,
1065,
275,
715,
339,
5759,
275,
7777,
8481,
342,
272,
5759,
14,
2526,
360,
3183,
63,
1430,
297,
283,
1419,
358,
272,
702,
5759,
14,
10274,
63,
1065,
12,
283,
8481,
8103,
440,
1852,
652,
370,
1255,
7,
199,
199,
318,
511,
63,
981,
63,
3664,
837,
272,
1990,
63,
1065,
275,
756,
272,
768,
981,
360,
1531,
297,
788,
1430,
1105,
272,
347,
4026,
63,
3664,
8,
1430,
12,
1511,
12,
1011,
958,
304,
267,
702,
1566,
508,
283,
1430,
7,
267,
1511,
459,
396,
418,
275,
715,
339,
1511,
275,
791,
396,
356,
756,
93,
339,
702,
4026,
63,
3664,
14,
354,
508,
283,
3183,
63,
3664,
7,
272,
702,
4026,
63,
3664,
14,
1531,
508,
283,
1531,
7,
2286,
4026,
63,
3664,
14,
2526,
360,
1430,
297,
1511,
9,
272,
702,
1511,
459,
396,
995,
283,
8481,
8103,
440,
1852,
652,
370,
1255,
314,
805,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
GheRivero/ansible
|
test/units/modules/system/test_pamd.py
|
19
|
17492
|
from __future__ import (absolute_import, division, print_function)
from ansible.compat.tests import unittest
from ansible.modules.system.pamd import PamdRule
from ansible.modules.system.pamd import PamdLine
from ansible.modules.system.pamd import PamdComment
from ansible.modules.system.pamd import PamdInclude
from ansible.modules.system.pamd import PamdService
class PamdLineTestCase(unittest.TestCase):
def setUp(self):
self.pamd_line = PamdLine("This is a test")
def test_line(self):
self.assertEqual("This is a test", str(self.pamd_line))
def test_matches(self):
self.assertFalse(self.pamd_line.matches("test", "matches", "foo", "bar"))
class PamdIncludeTestCase(unittest.TestCase):
def setUp(self):
self.good_include = PamdInclude("@include foobar")
self.bad_include = PamdInclude("include foobar")
def test_line(self):
self.assertEqual("@include foobar", str(self.good_include))
def test_matches(self):
self.assertFalse(self.good_include.matches("something", "something", "dark", "side"))
def test_valid(self):
self.assertTrue(self.good_include.is_valid)
self.assertFalse(self.bad_include.is_valid)
class PamdCommentTestCase(unittest.TestCase):
def setUp(self):
self.good_comment = PamdComment("# This is a test comment")
self.bad_comment = PamdComment("This is a bad test comment")
def test_line(self):
self.assertEqual("# This is a test comment", str(self.good_comment))
def test_matches(self):
self.assertFalse(self.good_comment.matches("test", "matches", "foo", "bar"))
def test_valid(self):
self.assertTrue(self.good_comment.is_valid)
self.assertFalse(self.bad_comment.is_valid)
class PamdRuleTestCase(unittest.TestCase):
def setUp(self):
self.rule = PamdRule('account', 'optional', 'pam_keyinit.so', 'revoke')
def test_type(self):
self.assertEqual(self.rule.rule_type, 'account')
def test_control(self):
self.assertEqual(self.rule.rule_control, 'optional')
self.assertEqual(self.rule._control, 'optional')
def test_path(self):
self.assertEqual(self.rule.rule_path, 'pam_keyinit.so')
def test_args(self):
self.assertEqual(self.rule.rule_args, ['revoke'])
def test_valid(self):
self.assertTrue(self.rule.validate()[0])
class PamdRuleBadValidationTestCase(unittest.TestCase):
def setUp(self):
self.bad_type = PamdRule('foobar', 'optional', 'pam_keyinit.so', 'revoke')
self.bad_control_simple = PamdRule('account', 'foobar', 'pam_keyinit.so', 'revoke')
self.bad_control_value = PamdRule('account', '[foobar=1 default=ignore]', 'pam_keyinit.so', 'revoke')
self.bad_control_action = PamdRule('account', '[success=1 default=foobar]', 'pam_keyinit.so', 'revoke')
def test_validate_bad_type(self):
self.assertFalse(self.bad_type.validate()[0])
def test_validate_bad_control_simple(self):
self.assertFalse(self.bad_control_simple.validate()[0])
def test_validate_bad_control_value(self):
self.assertFalse(self.bad_control_value.validate()[0])
def test_validate_bad_control_action(self):
self.assertFalse(self.bad_control_action.validate()[0])
class PamdServiceTestCase(unittest.TestCase):
def setUp(self):
self.system_auth_string = """#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
@include common-auth
@include common-account
@include common-session
auth required pam_env.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid
auth required pam_deny.so
# Test comment
auth sufficient pam_rootok.so
account required pam_unix.so
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid
account [success=1 default=ignore] \
pam_succeed_if.so user = vagrant use_uid quiet
account required pam_permit.so
account required pam_access.so listsep=,
session include system-auth
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session [success=1 test=me default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so"""
self.simple_system_auth_string = """#%PAM-1.0
auth required pam_env.so
"""
self.pamd = PamdService(self.system_auth_string)
def test_properly_parsed(self):
num_lines = len(self.system_auth_string.splitlines()) + 1
num_lines_processed = len(str(self.pamd).splitlines())
self.assertEqual(num_lines, num_lines_processed)
def test_has_rule(self):
self.assertTrue(self.pamd.has_rule('account', 'required', 'pam_permit.so'))
self.assertTrue(self.pamd.has_rule('account', '[success=1 default=ignore]', 'pam_succeed_if.so'))
def test_doesnt_have_rule(self):
self.assertFalse(self.pamd.has_rule('account', 'requisite', 'pam_permit.so'))
# Test Update
def test_update_rule_type(self):
self.assertTrue(self.pamd.update_rule('session', 'optional', 'pam_keyinit.so', new_type='account'))
self.assertTrue(self.pamd.has_rule('account', 'optional', 'pam_keyinit.so'))
test_rule = PamdRule('account', 'optional', 'pam_keyinit.so', 'revoke')
self.assertIn(str(test_rule), str(self.pamd))
def test_update_rule_that_doesnt_exist(self):
self.assertFalse(self.pamd.update_rule('blah', 'blah', 'blah', new_type='account'))
self.assertFalse(self.pamd.has_rule('blah', 'blah', 'blah'))
test_rule = PamdRule('blah', 'blah', 'blah', 'account')
self.assertNotIn(str(test_rule), str(self.pamd))
def test_update_rule_type_two(self):
self.assertTrue(self.pamd.update_rule('session', '[success=1 default=ignore]', 'pam_succeed_if.so', new_type='account'))
self.assertTrue(self.pamd.has_rule('account', '[success=1 default=ignore]', 'pam_succeed_if.so'))
test_rule = PamdRule('account', '[success=1 default=ignore]', 'pam_succeed_if.so')
self.assertIn(str(test_rule), str(self.pamd))
def test_update_rule_control_simple(self):
self.assertTrue(self.pamd.update_rule('session', 'optional', 'pam_keyinit.so', new_control='required'))
self.assertTrue(self.pamd.has_rule('session', 'required', 'pam_keyinit.so'))
test_rule = PamdRule('session', 'required', 'pam_keyinit.so')
self.assertIn(str(test_rule), str(self.pamd))
def test_update_rule_control_complex(self):
self.assertTrue(self.pamd.update_rule('session',
'[success=1 default=ignore]',
'pam_succeed_if.so',
new_control='[success=2 test=me default=ignore]'))
self.assertTrue(self.pamd.has_rule('session', '[success=2 test=me default=ignore]', 'pam_succeed_if.so'))
test_rule = PamdRule('session', '[success=2 test=me default=ignore]', 'pam_succeed_if.so')
self.assertIn(str(test_rule), str(self.pamd))
def test_update_rule_control_more_complex(self):
self.assertTrue(self.pamd.update_rule('session',
'[success=1 test=me default=ignore]',
'pam_succeed_if.so',
new_control='[success=2 test=me default=ignore]'))
self.assertTrue(self.pamd.has_rule('session', '[success=2 test=me default=ignore]', 'pam_succeed_if.so'))
test_rule = PamdRule('session', '[success=2 test=me default=ignore]', 'pam_succeed_if.so')
self.assertIn(str(test_rule), str(self.pamd))
def test_update_rule_module_path(self):
self.assertTrue(self.pamd.update_rule('auth', 'required', 'pam_env.so', new_path='pam_limits.so'))
self.assertTrue(self.pamd.has_rule('auth', 'required', 'pam_limits.so'))
def test_update_rule_module_path_slash(self):
self.assertTrue(self.pamd.update_rule('auth', 'required', 'pam_env.so', new_path='/lib64/security/pam_duo.so'))
self.assertTrue(self.pamd.has_rule('auth', 'required', '/lib64/security/pam_duo.so'))
def test_update_rule_module_args(self):
self.assertTrue(self.pamd.update_rule('auth', 'sufficient', 'pam_unix.so', new_args='uid uid'))
test_rule = PamdRule('auth', 'sufficient', 'pam_unix.so', 'uid uid')
self.assertIn(str(test_rule), str(self.pamd))
test_rule = PamdRule('auth', 'sufficient', 'pam_unix.so', 'nullok try_first_pass')
self.assertNotIn(str(test_rule), str(self.pamd))
def test_update_first_three(self):
self.assertTrue(self.pamd.update_rule('auth', 'required', 'pam_env.so',
new_type='one', new_control='two', new_path='three'))
self.assertTrue(self.pamd.has_rule('one', 'two', 'three'))
def test_update_first_three_with_module_args(self):
self.assertTrue(self.pamd.update_rule('auth', 'sufficient', 'pam_unix.so',
new_type='one', new_control='two', new_path='three'))
self.assertTrue(self.pamd.has_rule('one', 'two', 'three'))
test_rule = PamdRule('one', 'two', 'three')
self.assertIn(str(test_rule), str(self.pamd))
self.assertIn(str(test_rule), str(self.pamd))
def test_update_all_four(self):
self.assertTrue(self.pamd.update_rule('auth', 'sufficient', 'pam_unix.so',
new_type='one', new_control='two', new_path='three',
new_args='four five'))
test_rule = PamdRule('one', 'two', 'three', 'four five')
self.assertIn(str(test_rule), str(self.pamd))
test_rule = PamdRule('auth', 'sufficient', 'pam_unix.so', 'nullok try_first_pass')
self.assertNotIn(str(test_rule), str(self.pamd))
def test_update_rule_with_slash(self):
self.assertTrue(self.pamd.update_rule('account', '[success=1 default=ignore]', 'pam_succeed_if.so',
new_type='session', new_path='pam_access.so'))
test_rule = PamdRule('session', '[success=1 default=ignore]', 'pam_access.so')
self.assertIn(str(test_rule), str(self.pamd))
# Insert Before
def test_insert_before_rule(self):
count = self.pamd.insert_before('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_limits.so')
self.assertEqual(count, 1)
rules = self.pamd.get("account", "required", "pam_access.so")
for current_rule in rules:
self.assertTrue(current_rule.prev.matches("account", "required", "pam_limits.so"))
def test_insert_before_rule_where_rule_doesnt_exist(self):
count = self.pamd.insert_before('account', 'sufficient', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_limits.so')
self.assertFalse(count)
def test_insert_before_rule_with_args(self):
self.assertTrue(self.pamd.insert_before('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_limits.so',
new_args='uid'))
rules = self.pamd.get("account", "required", "pam_access.so")
for current_rule in rules:
self.assertTrue(current_rule.prev.matches("account", "required", "pam_limits.so", 'uid'))
def test_insert_before_rule_test_duplicates(self):
self.assertTrue(self.pamd.insert_before('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_limits.so'))
self.pamd.insert_before('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_limits.so')
rules = self.pamd.get("account", "required", "pam_access.so")
for current_rule in rules:
previous_rule = current_rule.prev
self.assertTrue(previous_rule.matches("account", "required", "pam_limits.so"))
self.assertFalse(previous_rule.prev.matches("account", "required", "pam_limits.so"))
def test_insert_before_first_rule(self):
self.assertTrue(self.pamd.insert_before('auth', 'required', 'pam_env.so',
new_type='account', new_control='required', new_path='pam_limits.so'))
def test_insert_before_first_rule_simple(self):
simple_service = PamdService(self.simple_system_auth_string)
self.assertTrue(simple_service.insert_before('auth', 'required', 'pam_env.so',
new_type='account', new_control='required', new_path='pam_limits.so'))
# Insert After
def test_insert_after_rule(self):
self.assertTrue(self.pamd.insert_after('account', 'required', 'pam_unix.so',
new_type='account', new_control='required', new_path='pam_permit.so'))
rules = self.pamd.get("account", "required", "pam_unix.so")
for current_rule in rules:
self.assertTrue(current_rule.next.matches("account", "required", "pam_permit.so"))
def test_insert_after_rule_with_args(self):
self.assertTrue(self.pamd.insert_after('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_permit.so',
new_args='uid'))
rules = self.pamd.get("account", "required", "pam_access.so")
for current_rule in rules:
self.assertTrue(current_rule.next.matches("account", "required", "pam_permit.so", "uid"))
def test_insert_after_test_duplicates(self):
self.assertTrue(self.pamd.insert_after('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_permit.so',
new_args='uid'))
self.assertFalse(self.pamd.insert_after('account', 'required', 'pam_access.so',
new_type='account', new_control='required', new_path='pam_permit.so',
new_args='uid'))
rules = self.pamd.get("account", "required", "pam_access.so")
for current_rule in rules:
self.assertTrue(current_rule.next.matches("account", "required", "pam_permit.so", "uid"))
self.assertFalse(current_rule.next.next.matches("account", "required", "pam_permit.so", "uid"))
def test_insert_after_rule_last_rule(self):
self.assertTrue(self.pamd.insert_after('session', 'required', 'pam_unix.so',
new_type='account', new_control='required', new_path='pam_permit.so',
new_args='uid'))
rules = self.pamd.get("session", "required", "pam_unix.so")
for current_rule in rules:
self.assertTrue(current_rule.next.matches("account", "required", "pam_permit.so", "uid"))
# Remove Module Arguments
def test_remove_module_arguments_one(self):
self.assertTrue(self.pamd.remove_module_arguments('auth', 'sufficient', 'pam_unix.so', 'nullok'))
def test_remove_module_arguments_one_list(self):
self.assertTrue(self.pamd.remove_module_arguments('auth', 'sufficient', 'pam_unix.so', ['nullok']))
def test_remove_module_arguments_two(self):
self.assertTrue(self.pamd.remove_module_arguments('session', '[success=1 default=ignore]', 'pam_succeed_if.so', 'service crond'))
def test_remove_module_arguments_two_list(self):
self.assertTrue(self.pamd.remove_module_arguments('session', '[success=1 default=ignore]', 'pam_succeed_if.so', ['service', 'crond']))
def test_remove_module_arguments_where_none_existed(self):
self.assertTrue(self.pamd.add_module_arguments('session', 'required', 'pam_limits.so', 'arg1 arg2= arg3=arg3'))
def test_add_module_arguments_where_none_existed(self):
self.assertTrue(self.pamd.add_module_arguments('account', 'required', 'pam_unix.so', 'arg1 arg2= arg3=arg3'))
def test_add_module_arguments_where_none_existed_list(self):
self.assertTrue(self.pamd.add_module_arguments('account', 'required', 'pam_unix.so', ['arg1', 'arg2=', 'arg3=arg3']))
def test_add_module_arguments_where_some_existed(self):
self.assertTrue(self.pamd.add_module_arguments('auth', 'sufficient', 'pam_unix.so', 'arg1 arg2= arg3=arg3'))
def test_remove_rule(self):
self.assertTrue(self.pamd.remove('account', 'required', 'pam_unix.so'))
test_rule = PamdRule('account', 'required', 'pam_unix.so')
self.assertNotIn(str(test_rule), str(self.pamd))
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
5065,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
3049,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
7488,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
7826,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
3167,
421,
199,
533,
510,
21778,
3049,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
387,
1064,
63,
604,
275,
510,
21778,
3049,
480,
2765,
365,
282,
511,
531,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
480,
2765,
365,
282,
511,
401,
620,
8,
277,
14,
387,
1064,
63,
604,
430,
339,
347,
511,
63,
6742,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
387,
1064,
63,
604,
14,
6742,
480,
396,
401,
298,
6742,
401,
298,
1421,
401,
298,
1700,
2237,
421,
199,
533,
510,
21778,
7826,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
8302,
63,
2613,
275,
510,
21778,
7826,
25915,
2613,
29245,
531,
267,
291,
14,
4087,
63,
2613,
275,
510,
21778,
7826,
480,
2613,
29245,
531,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
25915,
2613,
29245,
401,
620,
8,
277,
14,
8302,
63,
2613,
430,
339,
347,
511,
63,
6742,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
8302,
63,
2613,
14,
6742,
480,
10297,
401,
298,
10297,
401,
298,
13625,
401,
298,
2441,
2237,
339,
347,
511,
63,
1078,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8302,
63,
2613,
14,
374,
63,
1078,
9,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2613,
14,
374,
63,
1078,
9,
421,
199,
533,
510,
21778,
7488,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
8302,
63,
3349,
275,
510,
21778,
7488,
10064,
961,
365,
282,
511,
3721,
531,
267,
291,
14,
4087,
63,
3349,
275,
510,
21778,
7488,
480,
2765,
365,
282,
4875,
511,
3721,
531,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
10064,
961,
365,
282,
511,
3721,
401,
620,
8,
277,
14,
8302,
63,
3349,
430,
339,
347,
511,
63,
6742,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
8302,
63,
3349,
14,
6742,
480,
396,
401,
298,
6742,
401,
298,
1421,
401,
298,
1700,
2237,
339,
347,
511,
63,
1078,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8302,
63,
3349,
14,
374,
63,
1078,
9,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
3349,
14,
374,
63,
1078,
9,
421,
199,
533,
510,
21778,
5065,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
2200,
275,
510,
21778,
5065,
360,
2048,
297,
283,
4144,
297,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
339,
347,
511,
63,
466,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
466,
12,
283,
2048,
358,
339,
347,
511,
63,
2785,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
2785,
12,
283,
4144,
358,
267,
291,
14,
629,
8,
277,
14,
2200,
423,
2785,
12,
283,
4144,
358,
339,
347,
511,
63,
515,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
515,
12,
283,
28024,
63,
498,
826,
14,
1152,
358,
339,
347,
511,
63,
589,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
589,
12,
788,
24445,
1105,
339,
347,
511,
63,
1078,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2200,
14,
3502,
3430,
16,
566,
421,
199,
533,
510,
21778,
5065,
5725,
13816,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
4087,
63,
466,
275,
510,
21778,
5065,
360,
9664,
297,
283,
4144,
297,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
267,
291,
14,
4087,
63,
2785,
63,
4129,
275,
510,
21778,
5065,
360,
2048,
297,
283,
9664,
297,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
267,
291,
14,
4087,
63,
2785,
63,
585,
275,
510,
21778,
5065,
360,
2048,
297,
6730,
9664,
29,
17,
849,
29,
4247,
4300,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
267,
291,
14,
4087,
63,
2785,
63,
1287,
275,
510,
21778,
5065,
360,
2048,
297,
6730,
3742,
29,
17,
849,
29,
9664,
4300,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
339,
347,
511,
63,
3502,
63,
4087,
63,
466,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
466,
14,
3502,
3430,
16,
566,
339,
347,
511,
63,
3502,
63,
4087,
63,
2785,
63,
4129,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2785,
63,
4129,
14,
3502,
3430,
16,
566,
339,
347,
511,
63,
3502,
63,
4087,
63,
2785,
63,
585,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2785,
63,
585,
14,
3502,
3430,
16,
566,
339,
347,
511,
63,
3502,
63,
4087,
63,
2785,
63,
1287,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2785,
63,
1287,
14,
3502,
3430,
16,
566,
421,
199,
533,
510,
21778,
3167,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
2253,
63,
1178,
63,
875,
275,
408,
25745,
48,
1156,
13,
17,
14,
16,
199,
3,
961,
570,
365,
2599,
13,
10176,
14,
199,
3,
2876,
4493,
911,
506,
28924,
314,
2163,
900,
1790,
888,
365,
1255,
14,
199,
32,
2613,
257,
2863,
13,
1178,
199,
32,
2613,
257,
2863,
13,
2048,
199,
32,
2613,
257,
2863,
13,
1730,
199,
1178,
755,
1415,
299,
455,
63,
1813,
14,
1152,
199,
1178,
755,
19258,
299,
455,
63,
11864,
14,
1152
] |
[
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
5065,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
3049,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
7488,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
7826,
199,
504,
3242,
14,
3112,
14,
2253,
14,
387,
1064,
492,
510,
21778,
3167,
421,
199,
533,
510,
21778,
3049,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
387,
1064,
63,
604,
275,
510,
21778,
3049,
480,
2765,
365,
282,
511,
531,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
480,
2765,
365,
282,
511,
401,
620,
8,
277,
14,
387,
1064,
63,
604,
430,
339,
347,
511,
63,
6742,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
387,
1064,
63,
604,
14,
6742,
480,
396,
401,
298,
6742,
401,
298,
1421,
401,
298,
1700,
2237,
421,
199,
533,
510,
21778,
7826,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
8302,
63,
2613,
275,
510,
21778,
7826,
25915,
2613,
29245,
531,
267,
291,
14,
4087,
63,
2613,
275,
510,
21778,
7826,
480,
2613,
29245,
531,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
25915,
2613,
29245,
401,
620,
8,
277,
14,
8302,
63,
2613,
430,
339,
347,
511,
63,
6742,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
8302,
63,
2613,
14,
6742,
480,
10297,
401,
298,
10297,
401,
298,
13625,
401,
298,
2441,
2237,
339,
347,
511,
63,
1078,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8302,
63,
2613,
14,
374,
63,
1078,
9,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2613,
14,
374,
63,
1078,
9,
421,
199,
533,
510,
21778,
7488,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
8302,
63,
3349,
275,
510,
21778,
7488,
10064,
961,
365,
282,
511,
3721,
531,
267,
291,
14,
4087,
63,
3349,
275,
510,
21778,
7488,
480,
2765,
365,
282,
4875,
511,
3721,
531,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
10064,
961,
365,
282,
511,
3721,
401,
620,
8,
277,
14,
8302,
63,
3349,
430,
339,
347,
511,
63,
6742,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
8302,
63,
3349,
14,
6742,
480,
396,
401,
298,
6742,
401,
298,
1421,
401,
298,
1700,
2237,
339,
347,
511,
63,
1078,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8302,
63,
3349,
14,
374,
63,
1078,
9,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
3349,
14,
374,
63,
1078,
9,
421,
199,
533,
510,
21778,
5065,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
2200,
275,
510,
21778,
5065,
360,
2048,
297,
283,
4144,
297,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
339,
347,
511,
63,
466,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
466,
12,
283,
2048,
358,
339,
347,
511,
63,
2785,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
2785,
12,
283,
4144,
358,
267,
291,
14,
629,
8,
277,
14,
2200,
423,
2785,
12,
283,
4144,
358,
339,
347,
511,
63,
515,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
515,
12,
283,
28024,
63,
498,
826,
14,
1152,
358,
339,
347,
511,
63,
589,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2200,
14,
2200,
63,
589,
12,
788,
24445,
1105,
339,
347,
511,
63,
1078,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2200,
14,
3502,
3430,
16,
566,
421,
199,
533,
510,
21778,
5065,
5725,
13816,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
4087,
63,
466,
275,
510,
21778,
5065,
360,
9664,
297,
283,
4144,
297,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
267,
291,
14,
4087,
63,
2785,
63,
4129,
275,
510,
21778,
5065,
360,
2048,
297,
283,
9664,
297,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
267,
291,
14,
4087,
63,
2785,
63,
585,
275,
510,
21778,
5065,
360,
2048,
297,
6730,
9664,
29,
17,
849,
29,
4247,
4300,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
267,
291,
14,
4087,
63,
2785,
63,
1287,
275,
510,
21778,
5065,
360,
2048,
297,
6730,
3742,
29,
17,
849,
29,
9664,
4300,
283,
28024,
63,
498,
826,
14,
1152,
297,
283,
24445,
358,
339,
347,
511,
63,
3502,
63,
4087,
63,
466,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
466,
14,
3502,
3430,
16,
566,
339,
347,
511,
63,
3502,
63,
4087,
63,
2785,
63,
4129,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2785,
63,
4129,
14,
3502,
3430,
16,
566,
339,
347,
511,
63,
3502,
63,
4087,
63,
2785,
63,
585,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2785,
63,
585,
14,
3502,
3430,
16,
566,
339,
347,
511,
63,
3502,
63,
4087,
63,
2785,
63,
1287,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
4087,
63,
2785,
63,
1287,
14,
3502,
3430,
16,
566,
421,
199,
533,
510,
21778,
3167,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
2253,
63,
1178,
63,
875,
275,
408,
25745,
48,
1156,
13,
17,
14,
16,
199,
3,
961,
570,
365,
2599,
13,
10176,
14,
199,
3,
2876,
4493,
911,
506,
28924,
314,
2163,
900,
1790,
888,
365,
1255,
14,
199,
32,
2613,
257,
2863,
13,
1178,
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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
] |
vicky2135/lucious
|
oscar/lib/python2.7/site-packages/django/templatetags/i18n.py
|
115
|
19351
|
from __future__ import unicode_literals
import sys
from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError, Variable
from django.template.base import TOKEN_TEXT, TOKEN_VAR, render_value_in_context
from django.template.defaulttags import token_kwargs
from django.utils import six, translation
from django.utils.safestring import SafeData, mark_safe
register = Library()
class GetAvailableLanguagesNode(Node):
def __init__(self, variable):
self.variable = variable
def render(self, context):
context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES]
return ''
class GetLanguageInfoNode(Node):
def __init__(self, lang_code, variable):
self.lang_code = lang_code
self.variable = variable
def render(self, context):
lang_code = self.lang_code.resolve(context)
context[self.variable] = translation.get_language_info(lang_code)
return ''
class GetLanguageInfoListNode(Node):
def __init__(self, languages, variable):
self.languages = languages
self.variable = variable
def get_language_info(self, language):
# ``language`` is either a language code string or a sequence
# with the language code as its first item
if len(language[0]) > 1:
return translation.get_language_info(language[0])
else:
return translation.get_language_info(str(language))
def render(self, context):
langs = self.languages.resolve(context)
context[self.variable] = [self.get_language_info(lang) for lang in langs]
return ''
class GetCurrentLanguageNode(Node):
def __init__(self, variable):
self.variable = variable
def render(self, context):
context[self.variable] = translation.get_language()
return ''
class GetCurrentLanguageBidiNode(Node):
def __init__(self, variable):
self.variable = variable
def render(self, context):
context[self.variable] = translation.get_language_bidi()
return ''
class TranslateNode(Node):
def __init__(self, filter_expression, noop, asvar=None,
message_context=None):
self.noop = noop
self.asvar = asvar
self.message_context = message_context
self.filter_expression = filter_expression
if isinstance(self.filter_expression.var, six.string_types):
self.filter_expression.var = Variable("'%s'" %
self.filter_expression.var)
def render(self, context):
self.filter_expression.var.translate = not self.noop
if self.message_context:
self.filter_expression.var.message_context = (
self.message_context.resolve(context))
output = self.filter_expression.resolve(context)
value = render_value_in_context(output, context)
# Restore percent signs. Percent signs in template text are doubled
# so they are not interpreted as string format flags.
is_safe = isinstance(value, SafeData)
value = value.replace('%%', '%')
value = mark_safe(value) if is_safe else value
if self.asvar:
context[self.asvar] = value
return ''
else:
return value
class BlockTranslateNode(Node):
def __init__(self, extra_context, singular, plural=None, countervar=None,
counter=None, message_context=None, trimmed=False, asvar=None):
self.extra_context = extra_context
self.singular = singular
self.plural = plural
self.countervar = countervar
self.counter = counter
self.message_context = message_context
self.trimmed = trimmed
self.asvar = asvar
def render_token_list(self, tokens):
result = []
vars = []
for token in tokens:
if token.token_type == TOKEN_TEXT:
result.append(token.contents.replace('%', '%%'))
elif token.token_type == TOKEN_VAR:
result.append('%%(%s)s' % token.contents)
vars.append(token.contents)
msg = ''.join(result)
if self.trimmed:
msg = translation.trim_whitespace(msg)
return msg, vars
def render(self, context, nested=False):
if self.message_context:
message_context = self.message_context.resolve(context)
else:
message_context = None
tmp_context = {}
for var, val in self.extra_context.items():
tmp_context[var] = val.resolve(context)
# Update() works like a push(), so corresponding context.pop() is at
# the end of function
context.update(tmp_context)
singular, vars = self.render_token_list(self.singular)
if self.plural and self.countervar and self.counter:
count = self.counter.resolve(context)
context[self.countervar] = count
plural, plural_vars = self.render_token_list(self.plural)
if message_context:
result = translation.npgettext(message_context, singular,
plural, count)
else:
result = translation.ungettext(singular, plural, count)
vars.extend(plural_vars)
else:
if message_context:
result = translation.pgettext(message_context, singular)
else:
result = translation.ugettext(singular)
default_value = context.template.engine.string_if_invalid
def render_value(key):
if key in context:
val = context[key]
else:
val = default_value % key if '%s' in default_value else default_value
return render_value_in_context(val, context)
data = {v: render_value(v) for v in vars}
context.pop()
try:
result = result % data
except (KeyError, ValueError):
if nested:
# Either string is malformed, or it's a bug
raise TemplateSyntaxError(
"'blocktrans' is unable to format string returned by gettext: %r using %r"
% (result, data)
)
with translation.override(None):
result = self.render(context, nested=True)
if self.asvar:
context[self.asvar] = result
return ''
else:
return result
class LanguageNode(Node):
def __init__(self, nodelist, language):
self.nodelist = nodelist
self.language = language
def render(self, context):
with translation.override(self.language.resolve(context)):
output = self.nodelist.render(context)
return output
@register.tag("get_available_languages")
def do_get_available_languages(parser, token):
"""
This will store a list of available languages
in the context.
Usage::
{% get_available_languages as languages %}
{% for language in languages %}
...
{% endfor %}
This will just pull the LANGUAGES setting from
your setting file (or the default settings) and
put it into the named variable.
"""
# token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
args = token.contents.split()
if len(args) != 3 or args[1] != 'as':
raise TemplateSyntaxError("'get_available_languages' requires 'as variable' (got %r)" % args)
return GetAvailableLanguagesNode(args[2])
@register.tag("get_language_info")
def do_get_language_info(parser, token):
"""
This will store the language information dictionary for the given language
code in a context variable.
Usage::
{% get_language_info for LANGUAGE_CODE as l %}
{{ l.code }}
{{ l.name }}
{{ l.name_translated }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
"""
args = token.split_contents()
if len(args) != 5 or args[1] != 'for' or args[3] != 'as':
raise TemplateSyntaxError("'%s' requires 'for string as variable' (got %r)" % (args[0], args[1:]))
return GetLanguageInfoNode(parser.compile_filter(args[2]), args[4])
@register.tag("get_language_info_list")
def do_get_language_info_list(parser, token):
"""
This will store a list of language information dictionaries for the given
language codes in a context variable. The language codes can be specified
either as a list of strings or a settings.LANGUAGES style list (or any
sequence of sequences whose first items are language codes).
Usage::
{% get_language_info_list for LANGUAGES as langs %}
{% for l in langs %}
{{ l.code }}
{{ l.name }}
{{ l.name_translated }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
{% endfor %}
"""
args = token.split_contents()
if len(args) != 5 or args[1] != 'for' or args[3] != 'as':
raise TemplateSyntaxError("'%s' requires 'for sequence as variable' (got %r)" % (args[0], args[1:]))
return GetLanguageInfoListNode(parser.compile_filter(args[2]), args[4])
@register.filter
def language_name(lang_code):
return translation.get_language_info(lang_code)['name']
@register.filter
def language_name_translated(lang_code):
english_name = translation.get_language_info(lang_code)['name']
return translation.ugettext(english_name)
@register.filter
def language_name_local(lang_code):
return translation.get_language_info(lang_code)['name_local']
@register.filter
def language_bidi(lang_code):
return translation.get_language_info(lang_code)['bidi']
@register.tag("get_current_language")
def do_get_current_language(parser, token):
"""
This will store the current language in the context.
Usage::
{% get_current_language as language %}
This will fetch the currently active language and
put it's value into the ``language`` context
variable.
"""
# token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
args = token.contents.split()
if len(args) != 3 or args[1] != 'as':
raise TemplateSyntaxError("'get_current_language' requires 'as variable' (got %r)" % args)
return GetCurrentLanguageNode(args[2])
@register.tag("get_current_language_bidi")
def do_get_current_language_bidi(parser, token):
"""
This will store the current language layout in the context.
Usage::
{% get_current_language_bidi as bidi %}
This will fetch the currently active language's layout and
put it's value into the ``bidi`` context variable.
True indicates right-to-left layout, otherwise left-to-right
"""
# token.split_contents() isn't useful here because this tag doesn't accept variable as arguments
args = token.contents.split()
if len(args) != 3 or args[1] != 'as':
raise TemplateSyntaxError("'get_current_language_bidi' requires 'as variable' (got %r)" % args)
return GetCurrentLanguageBidiNode(args[2])
@register.tag("trans")
def do_translate(parser, token):
"""
This will mark a string for translation and will
translate the string for the current language.
Usage::
{% trans "this is a test" %}
This will mark the string for translation so it will
be pulled out by mark-messages.py into the .po files
and will run the string through the translation engine.
There is a second form::
{% trans "this is a test" noop %}
This will only mark for translation, but will return
the string unchanged. Use it when you need to store
values into forms that should be translated later on.
You can use variables instead of constant strings
to translate stuff you marked somewhere else::
{% trans variable %}
This will just try to translate the contents of
the variable ``variable``. Make sure that the string
in there is something that is in the .po file.
It is possible to store the translated string into a variable::
{% trans "this is a test" as var %}
{{ var }}
Contextual translations are also supported::
{% trans "this is a test" context "greeting" %}
This is equivalent to calling pgettext instead of (u)gettext.
"""
bits = token.split_contents()
if len(bits) < 2:
raise TemplateSyntaxError("'%s' takes at least one argument" % bits[0])
message_string = parser.compile_filter(bits[1])
remaining = bits[2:]
noop = False
asvar = None
message_context = None
seen = set()
invalid_context = {'as', 'noop'}
while remaining:
option = remaining.pop(0)
if option in seen:
raise TemplateSyntaxError(
"The '%s' option was specified more than once." % option,
)
elif option == 'noop':
noop = True
elif option == 'context':
try:
value = remaining.pop(0)
except IndexError:
msg = "No argument provided to the '%s' tag for the context option." % bits[0]
six.reraise(TemplateSyntaxError, TemplateSyntaxError(msg), sys.exc_info()[2])
if value in invalid_context:
raise TemplateSyntaxError(
"Invalid argument '%s' provided to the '%s' tag for the context option" % (value, bits[0]),
)
message_context = parser.compile_filter(value)
elif option == 'as':
try:
value = remaining.pop(0)
except IndexError:
msg = "No argument provided to the '%s' tag for the as option." % bits[0]
six.reraise(TemplateSyntaxError, TemplateSyntaxError(msg), sys.exc_info()[2])
asvar = value
else:
raise TemplateSyntaxError(
"Unknown argument for '%s' tag: '%s'. The only options "
"available are 'noop', 'context' \"xxx\", and 'as VAR'." % (
bits[0], option,
)
)
seen.add(option)
return TranslateNode(message_string, noop, asvar, message_context)
@register.tag("blocktrans")
def do_block_translate(parser, token):
"""
This will translate a block of text with parameters.
Usage::
{% blocktrans with bar=foo|filter boo=baz|filter %}
This is {{ bar }} and {{ boo }}.
{% endblocktrans %}
Additionally, this supports pluralization::
{% blocktrans count count=var|length %}
There is {{ count }} object.
{% plural %}
There are {{ count }} objects.
{% endblocktrans %}
This is much like ngettext, only in template syntax.
The "var as value" legacy format is still supported::
{% blocktrans with foo|filter as bar and baz|filter as boo %}
{% blocktrans count var|length as count %}
The translated string can be stored in a variable using `asvar`::
{% blocktrans with bar=foo|filter boo=baz|filter asvar var %}
This is {{ bar }} and {{ boo }}.
{% endblocktrans %}
{{ var }}
Contextual translations are supported::
{% blocktrans with bar=foo|filter context "greeting" %}
This is {{ bar }}.
{% endblocktrans %}
This is equivalent to calling pgettext/npgettext instead of
(u)gettext/(u)ngettext.
"""
bits = token.split_contents()
options = {}
remaining_bits = bits[1:]
asvar = None
while remaining_bits:
option = remaining_bits.pop(0)
if option in options:
raise TemplateSyntaxError('The %r option was specified more '
'than once.' % option)
if option == 'with':
value = token_kwargs(remaining_bits, parser, support_legacy=True)
if not value:
raise TemplateSyntaxError('"with" in %r tag needs at least '
'one keyword argument.' % bits[0])
elif option == 'count':
value = token_kwargs(remaining_bits, parser, support_legacy=True)
if len(value) != 1:
raise TemplateSyntaxError('"count" in %r tag expected exactly '
'one keyword argument.' % bits[0])
elif option == "context":
try:
value = remaining_bits.pop(0)
value = parser.compile_filter(value)
except Exception:
msg = (
'"context" in %r tag expected '
'exactly one argument.') % bits[0]
six.reraise(TemplateSyntaxError, TemplateSyntaxError(msg), sys.exc_info()[2])
elif option == "trimmed":
value = True
elif option == "asvar":
try:
value = remaining_bits.pop(0)
except IndexError:
msg = "No argument provided to the '%s' tag for the asvar option." % bits[0]
six.reraise(TemplateSyntaxError, TemplateSyntaxError(msg), sys.exc_info()[2])
asvar = value
else:
raise TemplateSyntaxError('Unknown argument for %r tag: %r.' %
(bits[0], option))
options[option] = value
if 'count' in options:
countervar, counter = list(options['count'].items())[0]
else:
countervar, counter = None, None
if 'context' in options:
message_context = options['context']
else:
message_context = None
extra_context = options.get('with', {})
trimmed = options.get("trimmed", False)
singular = []
plural = []
while parser.tokens:
token = parser.next_token()
if token.token_type in (TOKEN_VAR, TOKEN_TEXT):
singular.append(token)
else:
break
if countervar and counter:
if token.contents.strip() != 'plural':
raise TemplateSyntaxError("'blocktrans' doesn't allow other block tags inside it")
while parser.tokens:
token = parser.next_token()
if token.token_type in (TOKEN_VAR, TOKEN_TEXT):
plural.append(token)
else:
break
if token.contents.strip() != 'endblocktrans':
raise TemplateSyntaxError("'blocktrans' doesn't allow other block tags (seen %r) inside it" % token.contents)
return BlockTranslateNode(extra_context, singular, plural, countervar,
counter, message_context, trimmed=trimmed,
asvar=asvar)
@register.tag
def language(parser, token):
"""
This will enable the given language just for this block.
Usage::
{% language "de" %}
This is {{ bar }} and {{ boo }}.
{% endlanguage %}
"""
bits = token.split_contents()
if len(bits) != 2:
raise TemplateSyntaxError("'%s' takes one argument (language)" % bits[0])
language = parser.compile_filter(bits[1])
nodelist = parser.parse(('endlanguage',))
parser.delete_first_token()
return LanguageNode(nodelist, language)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1160,
492,
11243,
12,
5013,
12,
17762,
12,
4905,
199,
504,
1639,
14,
1160,
14,
1095,
492,
18243,
63,
3876,
12,
18243,
63,
5568,
12,
3795,
63,
585,
63,
262,
63,
1100,
199,
504,
1639,
14,
1160,
14,
885,
2969,
492,
1526,
63,
958,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7761,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
1451,
12,
2216,
63,
3489,
199,
199,
2683,
275,
11243,
342,
421,
199,
533,
2372,
11464,
8493,
83,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
1750,
304,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
1067,
59,
277,
14,
1975,
61,
275,
3842,
75,
12,
7761,
14,
23499,
8,
86,
430,
367,
1022,
12,
373,
315,
2202,
14,
26886,
61,
267,
372,
2125,
421,
199,
533,
2372,
8493,
2354,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
6339,
63,
600,
12,
1750,
304,
267,
291,
14,
4159,
63,
600,
275,
6339,
63,
600,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
6339,
63,
600,
275,
291,
14,
4159,
63,
600,
14,
6983,
8,
1100,
9,
267,
1067,
59,
277,
14,
1975,
61,
275,
7761,
14,
362,
63,
3671,
63,
815,
8,
4159,
63,
600,
9,
267,
372,
2125,
421,
199,
533,
2372,
8493,
2354,
1296,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
10815,
12,
1750,
304,
267,
291,
14,
13209,
275,
10815,
267,
291,
14,
1975,
275,
1750,
339,
347,
664,
63,
3671,
63,
815,
8,
277,
12,
2637,
304,
267,
327,
1124,
3671,
1040,
365,
1902,
282,
2637,
1233,
1059,
503,
282,
3414,
267,
327,
543,
314,
2637,
1233,
465,
2399,
1642,
1242,
267,
340,
822,
8,
3671,
59,
16,
566,
690,
413,
26,
288,
372,
7761,
14,
362,
63,
3671,
63,
815,
8,
3671,
59,
16,
566,
267,
587,
26,
288,
372,
7761,
14,
362,
63,
3671,
63,
815,
8,
495,
8,
3671,
430,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
31769,
275,
291,
14,
13209,
14,
6983,
8,
1100,
9,
267,
1067,
59,
277,
14,
1975,
61,
275,
359,
277,
14,
362,
63,
3671,
63,
815,
8,
4159,
9,
367,
6339,
315,
31769,
61,
267,
372,
2125,
421,
199,
533,
2372,
5639,
8493,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
1750,
304,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
1067,
59,
277,
14,
1975,
61,
275,
7761,
14,
362,
63,
3671,
342,
267,
372,
2125,
421,
199,
533,
2372,
5639,
8493,
34,
9897,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
1750,
304,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
1067,
59,
277,
14,
1975,
61,
275,
7761,
14,
362,
63,
3671,
63,
21555,
342,
267,
372,
2125,
421,
199,
533,
25540,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
2457,
63,
5599,
12,
29689,
12,
465,
1391,
29,
403,
12,
326,
1245,
63,
1100,
29,
403,
304,
267,
291,
14,
12921,
275,
29689,
267,
291,
14,
305,
1391,
275,
465,
1391,
267,
291,
14,
1188,
63,
1100,
275,
1245,
63,
1100,
267,
291,
14,
1541,
63,
5599,
275,
2457,
63,
5599,
267,
340,
1228,
8,
277,
14,
1541,
63,
5599,
14,
1391,
12,
3816,
14,
875,
63,
1313,
304,
288,
291,
14,
1541,
63,
5599,
14,
1391,
275,
4905,
21065,
83,
4065,
450,
8179,
291,
14,
1541,
63,
5599,
14,
1391,
9,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
291,
14,
1541,
63,
5599,
14,
1391,
14,
5275,
275,
440,
291,
14,
12921,
267,
340,
291,
14,
1188,
63,
1100,
26,
288,
291,
14,
1541,
63,
5599,
14,
1391,
14,
1188,
63,
1100,
275,
334,
355,
291,
14,
1188,
63,
1100,
14,
6983,
8,
1100,
430,
267,
1072,
275,
291,
14,
1541,
63,
5599,
14,
6983,
8,
1100,
9,
267,
574,
275,
3795,
63,
585,
63,
262,
63,
1100,
8,
1199,
12,
1067,
9,
267,
327,
22379,
8878,
27624,
14,
3492,
2946,
27624,
315,
1978,
1318,
787,
28584,
1146,
267,
327,
880,
2985,
787,
440,
11922,
465,
1059,
1475,
3285,
14,
267,
365,
63,
3489,
275,
1228,
8,
585,
12,
14969,
1451,
9,
267,
574,
275,
574,
14,
1814,
3508,
28575,
1543,
358,
267,
574,
275,
2216,
63,
3489,
8,
585,
9,
340,
365,
63,
3489,
587,
574,
267,
340,
291,
14,
305,
1391,
26,
288,
1067,
59,
277,
14,
305,
1391,
61,
275,
574,
288,
372,
2125,
267,
587,
26,
288,
372,
574,
421,
199,
533,
8651,
18355,
1716,
8,
1716,
304,
339,
347,
636,
826,
721,
277,
12,
2402,
63,
1100,
12,
15823,
12,
11718,
29,
403,
12,
7055,
1391,
29,
403,
12,
326,
7055,
29,
403,
12,
1245,
63,
1100,
29,
403,
12,
24196,
29,
797,
12,
465,
1391,
29,
403,
304,
267,
291,
14,
2911,
63,
1100,
275,
2402,
63,
1100,
267,
291,
14,
17045,
275,
15823,
267,
291,
14,
10019,
275,
11718,
267,
291,
14,
5337,
1391,
275,
7055,
1391,
267,
291,
14,
5337,
275,
7055,
267,
291,
14,
1188,
63,
1100,
275,
1245,
63,
1100,
267,
291,
14,
12263,
3594,
275,
24196,
267,
291,
14,
305,
1391,
275,
465,
1391,
339,
347,
3795,
63,
1418,
63,
513,
8,
277,
12,
4645,
304,
267,
754,
275,
942,
267,
6802,
275,
942,
267,
367,
1526,
315,
4645,
26,
288,
340,
1526,
14,
1418,
63,
466,
508,
18243,
63,
3876,
26,
355,
754,
14,
740,
8,
1418,
14,
4407,
14,
1814,
3508,
297,
23100,
1333,
288,
916,
1526,
14,
1418,
63,
466,
508,
18243,
63,
5568,
26,
355,
754,
14,
740,
3508,
28484,
83,
9,
83,
7,
450,
1526,
14,
4407,
9,
355,
6802,
14,
740,
8,
1418,
14,
4407,
9,
267,
1499,
275,
6522,
904,
8,
1099,
9,
267,
340,
291,
14,
12263,
3594,
26,
288,
1499,
275,
7761,
14,
12263,
63,
8506,
8,
1328,
9,
267,
372,
1499,
12,
6802,
339,
347,
3795,
8
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1160,
492,
11243,
12,
5013,
12,
17762,
12,
4905,
199,
504,
1639,
14,
1160,
14,
1095,
492,
18243,
63,
3876,
12,
18243,
63,
5568,
12,
3795,
63,
585,
63,
262,
63,
1100,
199,
504,
1639,
14,
1160,
14,
885,
2969,
492,
1526,
63,
958,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7761,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
1451,
12,
2216,
63,
3489,
199,
199,
2683,
275,
11243,
342,
421,
199,
533,
2372,
11464,
8493,
83,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
1750,
304,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
1067,
59,
277,
14,
1975,
61,
275,
3842,
75,
12,
7761,
14,
23499,
8,
86,
430,
367,
1022,
12,
373,
315,
2202,
14,
26886,
61,
267,
372,
2125,
421,
199,
533,
2372,
8493,
2354,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
6339,
63,
600,
12,
1750,
304,
267,
291,
14,
4159,
63,
600,
275,
6339,
63,
600,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
6339,
63,
600,
275,
291,
14,
4159,
63,
600,
14,
6983,
8,
1100,
9,
267,
1067,
59,
277,
14,
1975,
61,
275,
7761,
14,
362,
63,
3671,
63,
815,
8,
4159,
63,
600,
9,
267,
372,
2125,
421,
199,
533,
2372,
8493,
2354,
1296,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
10815,
12,
1750,
304,
267,
291,
14,
13209,
275,
10815,
267,
291,
14,
1975,
275,
1750,
339,
347,
664,
63,
3671,
63,
815,
8,
277,
12,
2637,
304,
267,
327,
1124,
3671,
1040,
365,
1902,
282,
2637,
1233,
1059,
503,
282,
3414,
267,
327,
543,
314,
2637,
1233,
465,
2399,
1642,
1242,
267,
340,
822,
8,
3671,
59,
16,
566,
690,
413,
26,
288,
372,
7761,
14,
362,
63,
3671,
63,
815,
8,
3671,
59,
16,
566,
267,
587,
26,
288,
372,
7761,
14,
362,
63,
3671,
63,
815,
8,
495,
8,
3671,
430,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
31769,
275,
291,
14,
13209,
14,
6983,
8,
1100,
9,
267,
1067,
59,
277,
14,
1975,
61,
275,
359,
277,
14,
362,
63,
3671,
63,
815,
8,
4159,
9,
367,
6339,
315,
31769,
61,
267,
372,
2125,
421,
199,
533,
2372,
5639,
8493,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
1750,
304,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
1067,
59,
277,
14,
1975,
61,
275,
7761,
14,
362,
63,
3671,
342,
267,
372,
2125,
421,
199,
533,
2372,
5639,
8493,
34,
9897,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
1750,
304,
267,
291,
14,
1975,
275,
1750,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
1067,
59,
277,
14,
1975,
61,
275,
7761,
14,
362,
63,
3671,
63,
21555,
342,
267,
372,
2125,
421,
199,
533,
25540,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
2457,
63,
5599,
12,
29689,
12,
465,
1391,
29,
403,
12,
326,
1245,
63,
1100,
29,
403,
304,
267,
291,
14,
12921,
275,
29689,
267,
291,
14,
305,
1391,
275,
465,
1391,
267,
291,
14,
1188,
63,
1100,
275,
1245,
63,
1100,
267,
291,
14,
1541,
63,
5599,
275,
2457,
63,
5599,
267,
340,
1228,
8,
277,
14,
1541,
63,
5599,
14,
1391,
12,
3816,
14,
875,
63,
1313,
304,
288,
291,
14,
1541,
63,
5599,
14,
1391,
275,
4905,
21065,
83,
4065,
450,
8179,
291,
14,
1541,
63,
5599,
14,
1391,
9,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
291,
14,
1541,
63,
5599,
14,
1391,
14,
5275,
275,
440,
291,
14,
12921,
267,
340,
291,
14,
1188,
63,
1100,
26,
288,
291,
14,
1541,
63,
5599,
14,
1391,
14,
1188,
63,
1100,
275,
334,
355,
291,
14,
1188,
63,
1100,
14,
6983,
8,
1100,
430,
267,
1072,
275,
291,
14,
1541,
63,
5599,
14,
6983,
8,
1100,
9,
267,
574,
275,
3795,
63,
585,
63,
262,
63,
1100,
8,
1199,
12,
1067,
9,
267,
327,
22379,
8878,
27624,
14,
3492,
2946,
27624,
315,
1978,
1318,
787,
28584,
1146,
267,
327,
880,
2985,
787,
440,
11922,
465,
1059,
1475,
3285,
14,
267,
365,
63,
3489,
275,
1228,
8,
585,
12,
14969,
1451,
9,
267,
574,
275,
574,
14,
1814,
3508,
28575,
1543,
358,
267,
574,
275,
2216,
63,
3489,
8,
585,
9,
340,
365,
63,
3489,
587,
574,
267,
340,
291,
14,
305,
1391,
26,
288,
1067,
59,
277,
14,
305,
1391,
61,
275,
574,
288,
372,
2125,
267,
587,
26,
288,
372,
574,
421,
199,
533,
8651,
18355,
1716,
8,
1716,
304,
339,
347,
636,
826,
721,
277,
12,
2402,
63,
1100,
12,
15823,
12,
11718,
29,
403,
12,
7055,
1391,
29,
403,
12,
326,
7055,
29,
403,
12,
1245,
63,
1100,
29,
403,
12,
24196,
29,
797,
12,
465,
1391,
29,
403,
304,
267,
291,
14,
2911,
63,
1100,
275,
2402,
63,
1100,
267,
291,
14,
17045,
275,
15823,
267,
291,
14,
10019,
275,
11718,
267,
291,
14,
5337,
1391,
275,
7055,
1391,
267,
291,
14,
5337,
275,
7055,
267,
291,
14,
1188,
63,
1100,
275,
1245,
63,
1100,
267,
291,
14,
12263,
3594,
275,
24196,
267,
291,
14,
305,
1391,
275,
465,
1391,
339,
347,
3795,
63,
1418,
63,
513,
8,
277,
12,
4645,
304,
267,
754,
275,
942,
267,
6802,
275,
942,
267,
367,
1526,
315,
4645,
26,
288,
340,
1526,
14,
1418,
63,
466,
508,
18243,
63,
3876,
26,
355,
754,
14,
740,
8,
1418,
14,
4407,
14,
1814,
3508,
297,
23100,
1333,
288,
916,
1526,
14,
1418,
63,
466,
508,
18243,
63,
5568,
26,
355,
754,
14,
740,
3508,
28484,
83,
9,
83,
7,
450,
1526,
14,
4407,
9,
355,
6802,
14,
740,
8,
1418,
14,
4407,
9,
267,
1499,
275,
6522,
904,
8,
1099,
9,
267,
340,
291,
14,
12263,
3594,
26,
288,
1499,
275,
7761,
14,
12263,
63,
8506,
8,
1328,
9,
267,
372,
1499,
12,
6802,
339,
347,
3795,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
tiagocoutinho/qarbon
|
qarbon/qt/gui/style/nebula.py
|
2
|
5273
|
# ----------------------------------------------------------------------------
# This file is part of qarbon (http://qarbon.rtfd.org/)
#
# Copyright (c) 2013 European Synchrotron Radiation Facility, Grenoble, France
#
# Distributed under the terms of the GNU Lesser General Public License,
# either version 3 of the License, or (at your option) any later version.
# See LICENSE.txt for more info.
# ----------------------------------------------------------------------------
"""Nebula style definition"""
from qarbon.qt.gui.style.templates import GROUPBOX_STYLESHEET_TEMPLATE
__BORDER_RADIUS = '4px'
TAB_STYLESHEET_TEMPLATE = """\
QToolTip {{
min-width: 280px;
}}
QTabWidget {{
}}
QTabWidget::tab-bar {{
left: 6px;
}}
QTabWidget::pane {{
border: 0px solid;
border-color: rgb(0, 65, 200);
border-top-left-radius: {border_radius};
border-top-right-radius: {border_radius};
border-bottom-left-radius: {border_radius};
border-bottom-right-radius: {border_radius};
background-color: {content_background_color};
}}
XulTabpanels {{
border: 1px solid;
border-color: rgb(0, 65, 200);
border-top-left-radius: 0px;
border-top-right-radius: {border_radius};
border-bottom-left-radius: {border_radius};
border-bottom-right-radius: {border_radius};
background-color: {content_background_color};
}}
QTabBar::tab {{
color:white;
background-color: {titlebar_background_color};
min-width: 8ex;
min-height: 22px;
padding: 2px;
}}
QTabBar::tab:top {{
border-top-left-radius: {border_radius};
border-top-right-radius: {border_radius};
}}
QTabBar::tab:bottom {{
border-bottom-left-radius: {border_radius};
border-bottom-right-radius: {border_radius};
}}
QTabBar::tab:selected {{
background-color: {selected_titlebar_background_color};
}}
"""
QGROUPBOX_STYLESHEET_TEMPLATE = """\
QGroupBox {{
border: 1px solid;
border-color: rgb(0, 65, 200);
border-radius: {border_radius};
margin-top: 1.5ex;
padding-top: 8px;
background-color: {content_background_color};
}}
QGroupBox::title {{
subcontrol-origin: margin;
subcontrol-position: top left;
padding-top: 1px;
padding-right: 3px;
padding-bottom: 2px;
padding-left: 3px;
border-width: 0px;
border-radius: {border_radius};
color:white;
background-color: {selected_titlebar_background_color};
left: 5px;
}}
QGroupBox::indicator {{
width: 15px;
height: 15px;
}}
"""
QDOCKWIDGET_STYLESHEET_TEMPLATE = """\
QDockWidget {{
color: {titlebar_color};
background-color: {content_background_color};
titlebar-close-icon: url(:/titlebar_close_black.png);
titlebar-normal-icon: url(:/titlebar_undock_black.png);
}}
QDockWidget::title {{
text-align: left;
padding-left: {border_radius};
border-top-left-radius: {border_radius};
border-top-right-radius: {border_radius};
border-bottom-left-radius: {border_radius};
border-bottom-right-radius: {border_radius};
background-color: {selected_titlebar_background_color};
}}
"""
QTOOLBOX_STYLESHEET_TEMPLATE = """\
QToolBox:tab {{
color: {titlebar_color};
border-width: 0px;
border-style: solid;
border-color: rgb(0, 65, 200);
border-top-left-radius: 0px;
border-top-right-radius: {border_radius};
border-bottom-left-radius: {border_radius};
border-bottom-right-radius: {border_radius};
background-color: {titlebar_background_color};
}}
QToolBox:tab:selected {{
background-color: {selected_titlebar_background_color};
}}
QToolBox:tab:first {{
border-top-left-radius: 0px;
border-top-right-radius: 0px;
}}
QToolBox:tab:last {{
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}}
QToolBox:tab:only-one {{
background-color: {single_titlebar_background_color};
}}
"""
GROUPBOX_NEBULA_STYLESHEET_MAP = {
'content_start_color': 'rgb(224, 224, 224)',
'content_stop_color': 'rgb(255, 255, 255)',
'content_border_radius': __BORDER_RADIUS,
'title_border_radius': __BORDER_RADIUS,
'title_start_color': 'rgb(60, 150, 255)',
'title_stop_color': 'rgb(0, 65, 200)',
'title_font_color': 'white',
}
GROUPBOX_NEBULA_STYLESHEET = \
GROUPBOX_STYLESHEET_TEMPLATE.format(**GROUPBOX_NEBULA_STYLESHEET_MAP)
NEBULA_STYLESHEET_MAP = {
'border_radius': __BORDER_RADIUS,
'titlebar_background_color': 'qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(200, 200, 200), stop: 1 rgb(150, 150, 150))',
'selected_titlebar_background_color': 'qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(60, 150, 255), stop: 1 rgb(0, 65, 200))',
'single_titlebar_background_color': 'qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(90, 180, 255), stop: 1 rgb(30, 95, 250))',
'titlebar_color': 'white',
'selected_titlebar_color': 'white',
'content_background_color': 'qlineargradient(x1: 0, y1: 0, x2: 1.0, y2: 1.0, stop: 0 rgb(224, 224, 224), stop: 1 rgb(255, 255, 255))'
}
STYLESHEET_TEMPLATE = TAB_STYLESHEET_TEMPLATE + \
QGROUPBOX_STYLESHEET_TEMPLATE + \
QDOCKWIDGET_STYLESHEET_TEMPLATE + \
QTOOLBOX_STYLESHEET_TEMPLATE
STYLESHEET = STYLESHEET_TEMPLATE.format(**NEBULA_STYLESHEET_MAP) + GROUPBOX_NEBULA_STYLESHEET
|
lgpl-3.0
|
[
3,
27103,
199,
3,
961,
570,
365,
1777,
402,
1894,
31585,
334,
1014,
921,
81,
31585,
14,
2591,
2592,
14,
1308,
24793,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
31615,
290,
428,
5654,
293,
454,
265,
3898,
328,
425,
10859,
12498,
12,
598,
828,
79,
830,
12,
481,
31331,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
12,
199,
3,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
1666,
5113,
14,
2424,
367,
1655,
2256,
14,
199,
3,
27103,
199,
199,
624,
46,
2871,
7586,
3449,
5492,
624,
199,
199,
504,
1894,
31585,
14,
8440,
14,
5885,
14,
2487,
14,
5876,
492,
15443,
15694,
63,
12307,
11344,
1645,
775,
63,
7433,
199,
199,
363,
30083,
63,
19662,
30373,
275,
283,
20,
5326,
7,
421,
199,
10129,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
199,
49,
21784,
8448,
272,
1748,
13,
2063,
26,
499,
1257,
5326,
27,
199,
4863,
199,
199,
49,
7690,
3339,
8448,
199,
4863,
199,
199,
49,
7690,
3339,
447,
2902,
13,
1700,
8448,
272,
3602,
26,
1227,
5326,
27,
199,
4863,
199,
199,
49,
7690,
3339,
447,
29092,
8448,
272,
9162,
26,
378,
5326,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
56,
348,
7690,
31929,
8448,
272,
9162,
26,
413,
5326,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
378,
5326,
27,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
8448,
272,
3164,
26,
7510,
27,
272,
8020,
13,
2326,
26,
469,
1213,
1700,
63,
7451,
63,
2326,
12084,
272,
1748,
13,
2063,
26,
1695,
476,
27,
272,
1748,
13,
3333,
26,
6928,
5326,
27,
272,
6273,
26,
499,
5326,
27,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
26,
2119,
8448,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
221,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
26,
8305,
8448,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
26,
5511,
8448,
272,
8020,
13,
2326,
26,
469,
5511,
63,
1213,
1700,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
624,
199,
199,
49,
7823,
15694,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
49,
2448,
3532,
8448,
272,
9162,
26,
413,
5326,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
11042,
13,
2119,
26,
413,
14,
21,
476,
27,
272,
6273,
13,
2119,
26,
1695,
5326,
27,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
199,
3586,
199,
199,
49,
2448,
3532,
447,
1213,
8448,
272,
1007,
2785,
13,
6493,
26,
11042,
27,
272,
1007,
2785,
13,
3124,
26,
2746,
3602,
27,
272,
6273,
13,
2119,
26,
413,
5326,
27,
272,
6273,
13,
1019,
26,
650,
5326,
27,
272,
6273,
13,
8305,
26,
499,
5326,
27,
272,
6273,
13,
3039,
26,
650,
5326,
27,
272,
9162,
13,
2063,
26,
378,
5326,
27,
272,
9162,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
3164,
26,
7510,
27,
272,
8020,
13,
2326,
26,
469,
5511,
63,
1213,
1700,
63,
7451,
63,
2326,
12084,
272,
3602,
26,
959,
5326,
27,
199,
4863,
421,
1413,
2448,
3532,
447,
15785,
8448,
272,
3462,
26,
4114,
5326,
27,
272,
4569,
26,
4114,
5326,
27,
199,
4863,
199,
199,
624,
199,
199,
49,
25190,
9845,
2970,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
49,
28804,
3339,
8448,
272,
3164,
26,
469,
1213,
1700,
63,
2326,
12084,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
272,
2538,
1700,
13,
1600,
13,
4677,
26,
1166,
8,
11254,
1213,
1700,
63,
1600,
63,
8399,
14,
4524,
2736,
272,
2538,
1700,
13,
3302,
13,
4677,
26,
1166,
8,
11254,
1213,
1700,
63,
725,
766,
63,
8399,
14,
4524,
2736,
199,
4863,
199,
199,
49,
28804,
3339,
447,
1213,
8448,
272,
1318,
13,
5743,
26,
3602,
27,
272,
6273,
13,
3039,
26,
469,
8665,
63,
8017,
12084,
339,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
339,
8020,
13,
2326,
26,
469,
5511,
63,
1213,
1700,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
624,
199,
199,
49,
9731,
15694,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
49,
5157,
3532,
26,
2902,
8448,
272,
3164,
26,
469,
1213,
1700,
63,
2326,
12084,
272,
9162,
13,
2063,
26,
378,
5326,
27,
272,
9162,
13,
2487,
26,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
378,
5326,
27,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469
] |
[
27103,
199,
3,
961,
570,
365,
1777,
402,
1894,
31585,
334,
1014,
921,
81,
31585,
14,
2591,
2592,
14,
1308,
24793,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
31615,
290,
428,
5654,
293,
454,
265,
3898,
328,
425,
10859,
12498,
12,
598,
828,
79,
830,
12,
481,
31331,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
12,
199,
3,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
1666,
5113,
14,
2424,
367,
1655,
2256,
14,
199,
3,
27103,
199,
199,
624,
46,
2871,
7586,
3449,
5492,
624,
199,
199,
504,
1894,
31585,
14,
8440,
14,
5885,
14,
2487,
14,
5876,
492,
15443,
15694,
63,
12307,
11344,
1645,
775,
63,
7433,
199,
199,
363,
30083,
63,
19662,
30373,
275,
283,
20,
5326,
7,
421,
199,
10129,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
199,
49,
21784,
8448,
272,
1748,
13,
2063,
26,
499,
1257,
5326,
27,
199,
4863,
199,
199,
49,
7690,
3339,
8448,
199,
4863,
199,
199,
49,
7690,
3339,
447,
2902,
13,
1700,
8448,
272,
3602,
26,
1227,
5326,
27,
199,
4863,
199,
199,
49,
7690,
3339,
447,
29092,
8448,
272,
9162,
26,
378,
5326,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
56,
348,
7690,
31929,
8448,
272,
9162,
26,
413,
5326,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
378,
5326,
27,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
8448,
272,
3164,
26,
7510,
27,
272,
8020,
13,
2326,
26,
469,
1213,
1700,
63,
7451,
63,
2326,
12084,
272,
1748,
13,
2063,
26,
1695,
476,
27,
272,
1748,
13,
3333,
26,
6928,
5326,
27,
272,
6273,
26,
499,
5326,
27,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
26,
2119,
8448,
272,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
221,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
26,
8305,
8448,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
199,
4863,
199,
199,
49,
7690,
5281,
447,
2902,
26,
5511,
8448,
272,
8020,
13,
2326,
26,
469,
5511,
63,
1213,
1700,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
624,
199,
199,
49,
7823,
15694,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
49,
2448,
3532,
8448,
272,
9162,
26,
413,
5326,
18609,
27,
272,
9162,
13,
2326,
26,
15180,
8,
16,
12,
11738,
12,
1926,
2736,
272,
9162,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
11042,
13,
2119,
26,
413,
14,
21,
476,
27,
272,
6273,
13,
2119,
26,
1695,
5326,
27,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
199,
3586,
199,
199,
49,
2448,
3532,
447,
1213,
8448,
272,
1007,
2785,
13,
6493,
26,
11042,
27,
272,
1007,
2785,
13,
3124,
26,
2746,
3602,
27,
272,
6273,
13,
2119,
26,
413,
5326,
27,
272,
6273,
13,
1019,
26,
650,
5326,
27,
272,
6273,
13,
8305,
26,
499,
5326,
27,
272,
6273,
13,
3039,
26,
650,
5326,
27,
272,
9162,
13,
2063,
26,
378,
5326,
27,
272,
9162,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
3164,
26,
7510,
27,
272,
8020,
13,
2326,
26,
469,
5511,
63,
1213,
1700,
63,
7451,
63,
2326,
12084,
272,
3602,
26,
959,
5326,
27,
199,
4863,
421,
1413,
2448,
3532,
447,
15785,
8448,
272,
3462,
26,
4114,
5326,
27,
272,
4569,
26,
4114,
5326,
27,
199,
4863,
199,
199,
624,
199,
199,
49,
25190,
9845,
2970,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
49,
28804,
3339,
8448,
272,
3164,
26,
469,
1213,
1700,
63,
2326,
12084,
272,
8020,
13,
2326,
26,
469,
1317,
63,
7451,
63,
2326,
12084,
272,
2538,
1700,
13,
1600,
13,
4677,
26,
1166,
8,
11254,
1213,
1700,
63,
1600,
63,
8399,
14,
4524,
2736,
272,
2538,
1700,
13,
3302,
13,
4677,
26,
1166,
8,
11254,
1213,
1700,
63,
725,
766,
63,
8399,
14,
4524,
2736,
199,
4863,
199,
199,
49,
28804,
3339,
447,
1213,
8448,
272,
1318,
13,
5743,
26,
3602,
27,
272,
6273,
13,
3039,
26,
469,
8665,
63,
8017,
12084,
339,
9162,
13,
2119,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
2119,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
3039,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
272,
9162,
13,
8305,
13,
1019,
13,
8017,
26,
469,
8665,
63,
8017,
12084,
339,
8020,
13,
2326,
26,
469,
5511,
63,
1213,
1700,
63,
7451,
63,
2326,
12084,
199,
4863,
199,
199,
624,
199,
199,
49,
9731,
15694,
63,
12307,
11344,
1645,
775,
63,
7433,
275,
9638,
199,
49,
5157,
3532,
26,
2902,
8448,
272,
3164,
26,
469,
1213,
1700,
63,
2326,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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
] |
pyqt/maya2012-qt4
|
PyQt4/uic/Compiler/qobjectcreator.py
|
1
|
5626
|
#############################################################################
##
## Copyright (C) 2011 Riverbank Computing Limited.
## Copyright (C) 2006 Thorsten Marek.
## All right reserved.
##
## This file is part of PyQt.
##
## You may use this file under the terms of the GPL v2 or the revised BSD
## license as follows:
##
## "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 Riverbank Computing Limited nor the names
## of its contributors may be used to endorse or promote products
## derived from this software without specific prior written
## permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
#############################################################################
import logging
try:
set()
except NameError:
from sets import Set as set
from PyQt4.uic.Compiler.indenter import write_code
from PyQt4.uic.Compiler.qtproxies import QtGui, Literal, strict_getattr
logger = logging.getLogger(__name__)
DEBUG = logger.debug
class _QtGuiWrapper(object):
def search(clsname):
try:
return strict_getattr(QtGui, clsname)
except AttributeError:
return None
search = staticmethod(search)
class _ModuleWrapper(object):
def __init__(self, name, classes):
if "." in name:
idx = name.rfind(".")
self._package = name[:idx]
self._module = name[idx + 1:]
else:
self._package = None
self._module = name
self._classes = set(classes)
self._used = False
def search(self, cls):
if cls in self._classes:
self._used = True
return type(cls, (QtGui.QWidget,), {"module": self._module})
else:
return None
def _writeImportCode(self):
if self._used:
if self._package is None:
write_code("import %s" % self._module)
else:
write_code("from %s import %s" % (self._package, self._module))
class _CustomWidgetLoader(object):
def __init__(self):
self._widgets = {}
self._usedWidgets = set()
def addCustomWidget(self, widgetClass, baseClass, module):
assert widgetClass not in self._widgets
self._widgets[widgetClass] = (baseClass, module)
def _resolveBaseclass(self, baseClass):
try:
for x in range(0, 10):
try: return strict_getattr(QtGui, baseClass)
except AttributeError: pass
baseClass = self._widgets[baseClass][0]
else:
raise ValueError("baseclass resolve took too long, check custom widgets")
except KeyError:
raise ValueError("unknown baseclass %s" % baseClass)
def search(self, cls):
try:
self._usedWidgets.add(cls)
baseClass = self._resolveBaseclass(self._widgets[cls][0])
DEBUG("resolved baseclass of %s: %s" % (cls, baseClass))
return type(cls, (baseClass,),
{"module" : ""})
except KeyError:
return None
def _writeImportCode(self):
imports = {}
for widget in self._usedWidgets:
_, module = self._widgets[widget]
imports.setdefault(module, []).append(widget)
for module, classes in imports.items():
write_code("from %s import %s" % (module, ", ".join(classes)))
class CompilerCreatorPolicy(object):
def __init__(self):
self._modules = []
def createQtGuiWrapper(self):
return _QtGuiWrapper
def createModuleWrapper(self, name, classes):
mw = _ModuleWrapper(name, classes)
self._modules.append(mw)
return mw
def createCustomWidgetLoader(self):
cw = _CustomWidgetLoader()
self._modules.append(cw)
return cw
def instantiate(self, clsObject, objectname, ctor_args, is_attribute=True, no_instantiation=False):
return clsObject(objectname, is_attribute, ctor_args, no_instantiation)
def invoke(self, rname, method, args):
return method(rname, *args)
def getSlot(self, object, slotname):
return Literal("%s.%s" % (object, slotname))
def _writeOutImports(self):
for module in self._modules:
module._writeImportCode()
|
gpl-3.0
|
[
31635,
199,
309,
199,
309,
1898,
334,
35,
9,
7760,
820,
4380,
9860,
27799,
23954,
14,
199,
309,
1898,
334,
35,
9,
8315,
3868,
1384,
724,
603,
1530,
75,
14,
199,
309,
2900,
2451,
4644,
14,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
14084,
14,
199,
309,
199,
309,
2047,
1443,
675,
642,
570,
1334,
314,
2895,
402,
314,
14629,
373,
18,
503,
314,
295,
17311,
6289,
199,
309,
4190,
465,
11924,
26,
199,
309,
199,
309,
298,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
309,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
309,
7647,
26,
199,
309,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
309,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
309,
258,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
309,
258,
4084,
14,
199,
309,
257,
627,
11443,
314,
536,
402,
314,
820,
4380,
9860,
27799,
23954,
6590,
314,
1561,
199,
309,
258,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
309,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
309,
258,
4983,
14,
199,
309,
199,
309,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
309,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
309,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
309,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
309,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
309,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
309,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
309,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
309,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
2122,
199,
309,
199,
31635,
421,
199,
646,
2050,
199,
199,
893,
26,
272,
663,
342,
199,
2590,
12746,
26,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
504,
14084,
20,
14,
85,
530,
14,
9131,
14,
262,
848,
351,
492,
2218,
63,
600,
199,
504,
14084,
20,
14,
85,
530,
14,
9131,
14,
8440,
17128,
492,
5928,
12,
18271,
12,
7478,
63,
5675,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
5287,
275,
2512,
14,
1757,
421,
199,
533,
485,
10604,
4590,
8,
785,
304,
272,
347,
2754,
8,
1886,
354,
304,
267,
862,
26,
288,
372,
7478,
63,
5675,
8,
10604,
12,
843,
354,
9,
267,
871,
4281,
26,
288,
372,
488,
339,
2754,
275,
12822,
8,
1733,
9,
421,
199,
533,
485,
2377,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
3992,
304,
267,
340,
14530,
315,
536,
26,
288,
4280,
275,
536,
14,
14542,
15857,
288,
291,
423,
2491,
275,
536,
1491,
2996,
61,
288,
291,
423,
578,
275,
536,
59,
2996,
435,
413,
2938,
267,
587,
26,
288,
291,
423,
2491,
275,
488,
288,
291,
423,
578,
275,
536,
10631,
291,
423,
2888,
275,
663,
8,
2888,
9,
267,
291,
423,
2972,
275,
756,
2286,
347,
2754,
8,
277,
12,
843,
304,
267,
340,
843,
315,
291,
423,
2888,
26,
288,
291,
423,
2972,
275,
715,
288,
372,
730,
8,
1886,
12,
334,
10604,
14,
23894,
4706,
2420,
578,
582,
291,
423,
578,
1552,
267,
587,
26,
288,
372,
488,
339,
347,
485,
952,
6295,
3034,
8,
277,
304,
267,
340,
291,
423,
2972,
26,
288,
340,
291,
423,
2491,
365,
488,
26,
355,
2218,
63,
600,
480,
646,
450,
83,
2,
450,
291,
423,
578,
9,
288,
587,
26,
355,
2218,
63,
600,
480,
504,
450,
83,
492,
450,
83,
2,
450,
334,
277,
423,
2491,
12,
291,
423,
578,
430,
421,
199,
533,
485,
7223,
3339,
5455,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
8583,
275,
1052,
267,
291,
423,
2972,
12462,
275,
663,
342,
5493,
347,
1050,
7223,
3339,
8,
277,
12,
3938,
2543,
12,
1300,
2543,
12,
859,
304,
267,
702,
3938,
2543,
440,
315,
291,
423,
8583,
4960,
291,
423,
8583,
59,
3440,
2543,
61,
275,
334,
1095,
2543,
12,
859,
9,
2378,
347,
485,
6983,
1563,
533,
8,
277,
12,
1300,
2543,
304,
267,
862,
26,
288,
367,
671,
315,
1425,
8,
16,
12,
1616,
304,
355,
862,
26,
372,
7478,
63,
5675,
8,
10604,
12,
1300,
2543,
9,
355,
871,
4281,
26,
986,
14977,
1300,
2543,
275,
291,
423,
8583,
59,
1095,
2543,
1527,
16,
61,
288,
587,
26,
355,
746,
1722,
480,
1095,
533,
7512,
27221,
4634,
1846,
12,
1104,
3537,
11114,
531,
398,
871,
4067,
26,
288,
746,
1722,
480,
5187,
1300,
533,
450,
83,
2,
450,
1300,
2543,
9,
268,
339,
347,
2754,
8,
277,
12,
843,
304,
267,
862,
26,
288,
291,
423,
2972,
12462,
14,
525,
8,
1886,
9,
288,
1300,
2543,
275,
291,
423,
6983,
1563,
533,
8,
277,
423,
8583,
59,
1886,
1527,
16,
566,
288,
10990,
480,
13697,
1300,
533,
402,
450,
83,
26,
450,
83,
2,
450,
334,
1886,
12,
1300,
2543,
430,
7846,
372,
730,
8,
1886,
12,
334,
1095,
2543,
4706,
717,
2420,
578,
2,
520,
3087,
1552,
2728,
871,
4067,
26,
288,
372,
488,
339,
347,
485,
952,
6295,
3034,
8,
277,
304,
267,
8925,
275,
1052,
267,
367,
3938,
315,
291,
423,
2972,
12462,
26,
288,
5501,
859,
275,
291,
423,
8583,
59,
3440,
61,
288,
8925,
14,
5486,
8,
578,
12,
15364,
740,
8,
3440,
9,
398,
367,
859,
12,
3992,
315,
8925,
14,
1744,
837,
288,
2218,
63,
600,
480,
504,
450,
83,
492,
450,
83,
2,
450,
334
] |
[
199,
309,
199,
309,
1898,
334,
35,
9,
7760,
820,
4380,
9860,
27799,
23954,
14,
199,
309,
1898,
334,
35,
9,
8315,
3868,
1384,
724,
603,
1530,
75,
14,
199,
309,
2900,
2451,
4644,
14,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
14084,
14,
199,
309,
199,
309,
2047,
1443,
675,
642,
570,
1334,
314,
2895,
402,
314,
14629,
373,
18,
503,
314,
295,
17311,
6289,
199,
309,
4190,
465,
11924,
26,
199,
309,
199,
309,
298,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
309,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
309,
7647,
26,
199,
309,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
309,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
309,
258,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
309,
258,
4084,
14,
199,
309,
257,
627,
11443,
314,
536,
402,
314,
820,
4380,
9860,
27799,
23954,
6590,
314,
1561,
199,
309,
258,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
309,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
309,
258,
4983,
14,
199,
309,
199,
309,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
309,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
309,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
309,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
309,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
309,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
309,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
309,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
309,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
2122,
199,
309,
199,
31635,
421,
199,
646,
2050,
199,
199,
893,
26,
272,
663,
342,
199,
2590,
12746,
26,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
504,
14084,
20,
14,
85,
530,
14,
9131,
14,
262,
848,
351,
492,
2218,
63,
600,
199,
504,
14084,
20,
14,
85,
530,
14,
9131,
14,
8440,
17128,
492,
5928,
12,
18271,
12,
7478,
63,
5675,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
5287,
275,
2512,
14,
1757,
421,
199,
533,
485,
10604,
4590,
8,
785,
304,
272,
347,
2754,
8,
1886,
354,
304,
267,
862,
26,
288,
372,
7478,
63,
5675,
8,
10604,
12,
843,
354,
9,
267,
871,
4281,
26,
288,
372,
488,
339,
2754,
275,
12822,
8,
1733,
9,
421,
199,
533,
485,
2377,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
3992,
304,
267,
340,
14530,
315,
536,
26,
288,
4280,
275,
536,
14,
14542,
15857,
288,
291,
423,
2491,
275,
536,
1491,
2996,
61,
288,
291,
423,
578,
275,
536,
59,
2996,
435,
413,
2938,
267,
587,
26,
288,
291,
423,
2491,
275,
488,
288,
291,
423,
578,
275,
536,
10631,
291,
423,
2888,
275,
663,
8,
2888,
9,
267,
291,
423,
2972,
275,
756,
2286,
347,
2754,
8,
277,
12,
843,
304,
267,
340,
843,
315,
291,
423,
2888,
26,
288,
291,
423,
2972,
275,
715,
288,
372,
730,
8,
1886,
12,
334,
10604,
14,
23894,
4706,
2420,
578,
582,
291,
423,
578,
1552,
267,
587,
26,
288,
372,
488,
339,
347,
485,
952,
6295,
3034,
8,
277,
304,
267,
340,
291,
423,
2972,
26,
288,
340,
291,
423,
2491,
365,
488,
26,
355,
2218,
63,
600,
480,
646,
450,
83,
2,
450,
291,
423,
578,
9,
288,
587,
26,
355,
2218,
63,
600,
480,
504,
450,
83,
492,
450,
83,
2,
450,
334,
277,
423,
2491,
12,
291,
423,
578,
430,
421,
199,
533,
485,
7223,
3339,
5455,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
8583,
275,
1052,
267,
291,
423,
2972,
12462,
275,
663,
342,
5493,
347,
1050,
7223,
3339,
8,
277,
12,
3938,
2543,
12,
1300,
2543,
12,
859,
304,
267,
702,
3938,
2543,
440,
315,
291,
423,
8583,
4960,
291,
423,
8583,
59,
3440,
2543,
61,
275,
334,
1095,
2543,
12,
859,
9,
2378,
347,
485,
6983,
1563,
533,
8,
277,
12,
1300,
2543,
304,
267,
862,
26,
288,
367,
671,
315,
1425,
8,
16,
12,
1616,
304,
355,
862,
26,
372,
7478,
63,
5675,
8,
10604,
12,
1300,
2543,
9,
355,
871,
4281,
26,
986,
14977,
1300,
2543,
275,
291,
423,
8583,
59,
1095,
2543,
1527,
16,
61,
288,
587,
26,
355,
746,
1722,
480,
1095,
533,
7512,
27221,
4634,
1846,
12,
1104,
3537,
11114,
531,
398,
871,
4067,
26,
288,
746,
1722,
480,
5187,
1300,
533,
450,
83,
2,
450,
1300,
2543,
9,
268,
339,
347,
2754,
8,
277,
12,
843,
304,
267,
862,
26,
288,
291,
423,
2972,
12462,
14,
525,
8,
1886,
9,
288,
1300,
2543,
275,
291,
423,
6983,
1563,
533,
8,
277,
423,
8583,
59,
1886,
1527,
16,
566,
288,
10990,
480,
13697,
1300,
533,
402,
450,
83,
26,
450,
83,
2,
450,
334,
1886,
12,
1300,
2543,
430,
7846,
372,
730,
8,
1886,
12,
334,
1095,
2543,
4706,
717,
2420,
578,
2,
520,
3087,
1552,
2728,
871,
4067,
26,
288,
372,
488,
339,
347,
485,
952,
6295,
3034,
8,
277,
304,
267,
8925,
275,
1052,
267,
367,
3938,
315,
291,
423,
2972,
12462,
26,
288,
5501,
859,
275,
291,
423,
8583,
59,
3440,
61,
288,
8925,
14,
5486,
8,
578,
12,
15364,
740,
8,
3440,
9,
398,
367,
859,
12,
3992,
315,
8925,
14,
1744,
837,
288,
2218,
63,
600,
480,
504,
450,
83,
492,
450,
83,
2,
450,
334,
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
1,
1
] |
sergecodd/FireFox-OS
|
B2G/gecko/testing/mozbase/mozrunner/mozrunner/runner.py
|
6
|
14272
|
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
__all__ = ['Runner', 'ThunderbirdRunner', 'FirefoxRunner', 'runners', 'CLI', 'cli', 'package_metadata']
import mozinfo
import optparse
import os
import platform
import subprocess
import sys
import ConfigParser
from utils import get_metadata_from_egg
from utils import findInPath
from mozprofile import *
from mozprocess.processhandler import ProcessHandler
if mozinfo.isMac:
from plistlib import readPlist
package_metadata = get_metadata_from_egg('mozrunner')
# Map of debugging programs to information about them
# from http://mxr.mozilla.org/mozilla-central/source/build/automationutils.py#59
debuggers = {'gdb': {'interactive': True,
'args': ['-q', '--args'],},
'valgrind': {'interactive': False,
'args': ['--leak-check=full']}
}
def debugger_arguments(debugger, arguments=None, interactive=None):
"""
finds debugger arguments from debugger given and defaults
* debugger : debugger name or path to debugger
* arguments : arguments to the debugger, or None to use defaults
* interactive : whether the debugger should be run in interactive mode, or None to use default
"""
# find debugger executable if not a file
executable = debugger
if not os.path.exists(executable):
executable = findInPath(debugger)
if executable is None:
raise Exception("Path to '%s' not found" % debugger)
# if debugger not in dictionary of knowns return defaults
dirname, debugger = os.path.split(debugger)
if debugger not in debuggers:
return ([executable] + (arguments or []), bool(interactive))
# otherwise use the dictionary values for arguments unless specified
if arguments is None:
arguments = debuggers[debugger].get('args', [])
if interactive is None:
interactive = debuggers[debugger].get('interactive', False)
return ([executable] + arguments, interactive)
class Runner(object):
"""Handles all running operations. Finds bins, runs and kills the process."""
profile_class = Profile # profile class to use by default
@classmethod
def create(cls, binary=None, cmdargs=None, env=None, kp_kwargs=None, profile_args=None,
clean_profile=True, process_class=ProcessHandler):
profile = cls.profile_class(**(profile_args or {}))
return cls(profile, binary=binary, cmdargs=cmdargs, env=env, kp_kwargs=kp_kwargs,
clean_profile=clean_profile, process_class=process_class)
def __init__(self, profile, binary, cmdargs=None, env=None,
kp_kwargs=None, clean_profile=True, process_class=ProcessHandler):
self.process_handler = None
self.process_class = process_class
self.profile = profile
self.clean_profile = clean_profile
# find the binary
self.binary = binary
if not self.binary:
raise Exception("Binary not specified")
if not os.path.exists(self.binary):
raise OSError("Binary path does not exist: %s" % self.binary)
# allow Mac binaries to be specified as an app bundle
plist = '%s/Contents/Info.plist' % self.binary
if mozinfo.isMac and os.path.exists(plist):
info = readPlist(plist)
self.binary = os.path.join(self.binary, "Contents/MacOS/",
info['CFBundleExecutable'])
self.cmdargs = cmdargs or []
_cmdargs = [i for i in self.cmdargs
if i != '-foreground']
if len(_cmdargs) != len(self.cmdargs):
# foreground should be last; see
# - https://bugzilla.mozilla.org/show_bug.cgi?id=625614
# - https://bugzilla.mozilla.org/show_bug.cgi?id=626826
self.cmdargs = _cmdargs
self.cmdargs.append('-foreground')
# process environment
if env is None:
self.env = os.environ.copy()
else:
self.env = env.copy()
# allows you to run an instance of Firefox separately from any other instances
self.env['MOZ_NO_REMOTE'] = '1'
# keeps Firefox attached to the terminal window after it starts
self.env['NO_EM_RESTART'] = '1'
# set the library path if needed on linux
if sys.platform == 'linux2' and self.binary.endswith('-bin'):
dirname = os.path.dirname(self.binary)
if os.environ.get('LD_LIBRARY_PATH', None):
self.env['LD_LIBRARY_PATH'] = '%s:%s' % (os.environ['LD_LIBRARY_PATH'], dirname)
else:
self.env['LD_LIBRARY_PATH'] = dirname
# arguments for ProfessHandler.Process
self.kp_kwargs = kp_kwargs or {}
@property
def command(self):
"""Returns the command list to run."""
return [self.binary, '-profile', self.profile.profile]
def get_repositoryInfo(self):
"""Read repository information from application.ini and platform.ini."""
config = ConfigParser.RawConfigParser()
dirname = os.path.dirname(self.binary)
repository = { }
for file, section in [('application', 'App'), ('platform', 'Build')]:
config.read(os.path.join(dirname, '%s.ini' % file))
for key, id in [('SourceRepository', 'repository'),
('SourceStamp', 'changeset')]:
try:
repository['%s_%s' % (file, id)] = config.get(section, key);
except:
repository['%s_%s' % (file, id)] = None
return repository
def is_running(self):
return self.process_handler is not None
def start(self, debug_args=None, interactive=False, timeout=None, outputTimeout=None):
"""
Run self.command in the proper environment.
- debug_args: arguments for the debugger
- interactive: uses subprocess.Popen directly
- read_output: sends program output to stdout [default=False]
- timeout: see process_handler.waitForFinish
- outputTimeout: see process_handler.waitForFinish
"""
# ensure you are stopped
self.stop()
# ensure the profile exists
if not self.profile.exists():
self.profile.reset()
assert self.profile.exists(), "%s : failure to reset profile" % self.__class__.__name__
cmd = self._wrap_command(self.command+self.cmdargs)
# attach a debugger, if specified
if debug_args:
cmd = list(debug_args) + cmd
if interactive:
self.process_handler = subprocess.Popen(cmd, env=self.env)
# TODO: other arguments
else:
# this run uses the managed processhandler
self.process_handler = self.process_class(cmd, env=self.env, **self.kp_kwargs)
self.process_handler.run(timeout, outputTimeout)
def wait(self, timeout=None):
"""
Wait for the app to exit.
If timeout is not None, will return after timeout seconds.
Use is_running() to determine whether or not a timeout occured.
Timeout is ignored if interactive was set to True.
"""
if self.process_handler is None:
return
if isinstance(self.process_handler, subprocess.Popen):
self.process_handler.wait()
else:
self.process_handler.wait(timeout)
if self.process_handler.proc.poll() is None:
# waitForFinish timed out
return
self.process_handler = None
def stop(self):
"""Kill the app"""
if self.process_handler is None:
return
self.process_handler.kill()
self.process_handler = None
def reset(self):
"""
reset the runner between runs
currently, only resets the profile, but probably should do more
"""
self.profile.reset()
def cleanup(self):
self.stop()
if self.clean_profile:
self.profile.cleanup()
def _wrap_command(self, cmd):
"""
If running on OS X 10.5 or older, wrap |cmd| so that it will
be executed as an i386 binary, in case it's a 32-bit/64-bit universal
binary.
"""
if mozinfo.isMac and hasattr(platform, 'mac_ver') and \
platform.mac_ver()[0][:4] < '10.6':
return ["arch", "-arch", "i386"] + cmd
return cmd
__del__ = cleanup
class FirefoxRunner(Runner):
"""Specialized Runner subclass for running Firefox."""
profile_class = FirefoxProfile
def __init__(self, profile, binary=None, **kwargs):
# take the binary from BROWSER_PATH environment variable
if (not binary) and 'BROWSER_PATH' in os.environ:
binary = os.environ['BROWSER_PATH']
Runner.__init__(self, profile, binary, **kwargs)
class ThunderbirdRunner(Runner):
"""Specialized Runner subclass for running Thunderbird"""
profile_class = ThunderbirdProfile
runners = {'firefox': FirefoxRunner,
'thunderbird': ThunderbirdRunner}
class CLI(MozProfileCLI):
"""Command line interface."""
module = "mozrunner"
def __init__(self, args=sys.argv[1:]):
"""
Setup command line parser and parse arguments
- args : command line arguments
"""
self.metadata = getattr(sys.modules[self.module],
'package_metadata',
{})
version = self.metadata.get('Version')
parser_args = {'description': self.metadata.get('Summary')}
if version:
parser_args['version'] = "%prog " + version
self.parser = optparse.OptionParser(**parser_args)
self.add_options(self.parser)
(self.options, self.args) = self.parser.parse_args(args)
if getattr(self.options, 'info', None):
self.print_metadata()
sys.exit(0)
# choose appropriate runner and profile classes
try:
self.runner_class = runners[self.options.app]
except KeyError:
self.parser.error('Application "%s" unknown (should be one of "firefox" or "thunderbird")' % self.options.app)
def add_options(self, parser):
"""add options to the parser"""
# add profile options
MozProfileCLI.add_options(self, parser)
# add runner options
parser.add_option('-b', "--binary",
dest="binary", help="Binary path.",
metavar=None, default=None)
parser.add_option('--app', dest='app', default='firefox',
help="Application to use [DEFAULT: %default]")
parser.add_option('--app-arg', dest='appArgs',
default=[], action='append',
help="provides an argument to the test application")
parser.add_option('--debugger', dest='debugger',
help="run under a debugger, e.g. gdb or valgrind")
parser.add_option('--debugger-args', dest='debugger_args',
action='append', default=None,
help="arguments to the debugger")
parser.add_option('--interactive', dest='interactive',
action='store_true',
help="run the program interactively")
if self.metadata:
parser.add_option("--info", dest="info", default=False,
action="store_true",
help="Print module information")
### methods for introspecting data
def get_metadata_from_egg(self):
import pkg_resources
ret = {}
dist = pkg_resources.get_distribution(self.module)
if dist.has_metadata("PKG-INFO"):
for line in dist.get_metadata_lines("PKG-INFO"):
key, value = line.split(':', 1)
ret[key] = value
if dist.has_metadata("requires.txt"):
ret["Dependencies"] = "\n" + dist.get_metadata("requires.txt")
return ret
def print_metadata(self, data=("Name", "Version", "Summary", "Home-page",
"Author", "Author-email", "License", "Platform", "Dependencies")):
for key in data:
if key in self.metadata:
print key + ": " + self.metadata[key]
### methods for running
def command_args(self):
"""additional arguments for the mozilla application"""
return self.options.appArgs
def runner_args(self):
"""arguments to instantiate the runner class"""
return dict(cmdargs=self.command_args(),
binary=self.options.binary,
profile_args=self.profile_args())
def create_runner(self):
return self.runner_class.create(**self.runner_args())
def run(self):
runner = self.create_runner()
self.start(runner)
runner.cleanup()
def debugger_arguments(self):
"""
returns a 2-tuple of debugger arguments:
(debugger_arguments, interactive)
"""
debug_args = self.options.debugger_args
interactive = self.options.interactive
if self.options.debugger:
debug_args, interactive = debugger_arguments(self.options.debugger)
return debug_args, interactive
def start(self, runner):
"""Starts the runner and waits for Firefox to exit or Keyboard Interrupt.
Shoule be overwritten to provide custom running of the runner instance."""
# attach a debugger if specified
debug_args, interactive = self.debugger_arguments()
runner.start(debug_args=debug_args, interactive=interactive)
print 'Starting:', ' '.join(runner.command)
try:
runner.wait()
except KeyboardInterrupt:
runner.stop()
def cli(args=sys.argv[1:]):
CLI(args).run()
if __name__ == '__main__':
cli()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
363,
452,
363,
275,
788,
7446,
297,
283,
2719,
7138,
22488,
7446,
297,
283,
27983,
7446,
297,
283,
32213,
297,
283,
7802,
297,
283,
2764,
297,
283,
2491,
63,
2343,
418,
199,
199,
646,
1303,
90,
815,
199,
646,
8691,
199,
646,
747,
199,
646,
4298,
199,
646,
3873,
199,
646,
984,
199,
646,
14196,
199,
199,
504,
3778,
492,
664,
63,
2343,
63,
504,
63,
5799,
199,
504,
3778,
492,
2342,
607,
2042,
199,
504,
1303,
90,
2913,
492,
627,
199,
504,
1303,
90,
1412,
14,
1412,
2232,
492,
7132,
2461,
199,
199,
692,
1303,
90,
815,
14,
374,
3399,
26,
272,
687,
14459,
773,
492,
1586,
21073,
199,
199,
2491,
63,
2343,
275,
664,
63,
2343,
63,
504,
63,
5799,
360,
23120,
5933,
358,
199,
199,
3,
9672,
402,
10201,
18572,
370,
2556,
3595,
3062,
199,
3,
687,
1455,
921,
9457,
82,
14,
12102,
14,
1308,
15,
12102,
13,
16067,
15,
1365,
15,
1506,
15,
23867,
1208,
14,
647,
3,
1427,
199,
17612,
83,
275,
791,
17119,
356,
791,
13543,
356,
715,
12,
2151,
283,
589,
356,
11573,
81,
297,
2850,
589,
995,
1386,
1467,
283,
637,
21510,
356,
791,
13543,
356,
756,
12,
2079,
283,
589,
356,
14574,
28212,
13,
1074,
29,
2861,
12074,
1467,
789,
199,
199,
318,
14958,
63,
4958,
8,
17612,
12,
2368,
29,
403,
12,
12777,
29,
403,
304,
272,
408,
272,
17651,
14958,
2368,
687,
14958,
1627,
436,
4243,
272,
627,
14958,
520,
14958,
536,
503,
931,
370,
14958,
272,
627,
2368,
520,
2368,
370,
314,
14958,
12,
503,
488,
370,
675,
4243,
272,
627,
12777,
520,
3775,
314,
14958,
1077,
506,
1255,
315,
12777,
818,
12,
503,
488,
370,
675,
849,
272,
408,
339,
327,
2342,
14958,
7286,
340,
440,
282,
570,
272,
7286,
275,
14958,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5904,
304,
267,
7286,
275,
2342,
607,
2042,
8,
17612,
9,
272,
340,
7286,
365,
488,
26,
267,
746,
2186,
480,
2042,
370,
1543,
83,
7,
440,
1911,
2,
450,
14958,
9,
339,
327,
340,
14958,
440,
315,
2600,
402,
5715,
561,
372,
4243,
272,
9017,
12,
14958,
275,
747,
14,
515,
14,
1294,
8,
17612,
9,
272,
340,
14958,
440,
315,
14958,
83,
26,
267,
372,
7287,
5904,
61,
435,
334,
4958,
503,
14431,
2155,
8,
13543,
430,
339,
327,
4257,
675,
314,
2600,
1338,
367,
2368,
7444,
2013,
272,
340,
2368,
365,
488,
26,
267,
2368,
275,
14958,
83,
59,
17612,
1055,
362,
360,
589,
297,
3073,
272,
340,
12777,
365,
488,
26,
267,
12777,
275,
14958,
83,
59,
17612,
1055,
362,
360,
13543,
297,
756,
9,
272,
372,
7287,
5904,
61,
435,
2368,
12,
12777,
9,
199,
199,
533,
3378,
1372,
8,
785,
304,
272,
408,
23555,
1006,
3879,
5331,
14,
31434,
13341,
12,
7858,
436,
1022,
15350,
314,
2112,
1041,
339,
4690,
63,
533,
275,
14386,
327,
4690,
1021,
370,
675,
701,
849,
339,
768,
3744,
272,
347,
1218,
8,
1886,
12,
3366,
29,
403,
12,
2088,
589,
29,
403,
12,
2589,
29,
403,
12,
1022,
80,
63,
958,
29,
403,
12,
4690,
63,
589,
29,
403,
12,
2049,
3633,
63,
2913,
29,
549,
12,
2112,
63,
533,
29,
3498,
2461,
304,
267,
4690,
275,
843,
14,
2913,
63,
533,
3682,
8,
2913,
63,
589,
503,
17003,
267,
372,
843,
8,
2913,
12,
3366,
29,
3008,
12,
2088,
589,
29,
1760,
589,
12,
2589,
29,
1813,
12,
1022,
80,
63,
958,
29,
25017,
63,
958,
12,
5644,
3633,
63,
2913,
29,
3118,
63,
2913,
12,
2112,
63,
533,
29,
1412,
63,
533,
9,
339,
347,
636,
826,
721,
277,
12,
4690,
12,
3366,
12,
2088,
589,
29,
403,
12,
2589,
29,
403,
12,
326,
1022,
80,
63,
958,
29,
403,
12,
3633,
63,
2913,
29,
549,
12,
2112,
63,
533,
29,
3498,
2461,
304,
267,
291,
14,
1412,
63,
2232,
275,
488,
267,
291,
14,
1412,
63,
533,
275,
2112,
63,
533,
267,
291,
14,
2913,
275,
4690,
267,
291,
14,
3118,
63,
2913,
275,
3633,
63,
2913,
398,
327,
2342,
314,
3366,
267,
291,
14,
3008,
275,
3366,
267,
340,
440,
291,
14,
3008,
26,
288,
746,
2186,
480,
6636,
440,
2013,
531,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
3008,
304,
288,
746,
6440,
480,
6636,
931,
1630,
440,
2187,
26,
450,
83,
2,
450,
291,
14,
3008,
9,
398,
327,
2040,
10444,
21984,
370,
506,
2013,
465,
376,
1145,
8844,
267,
14459,
275,
1543,
83,
15,
11383,
15,
2354,
14,
10265,
7,
450,
291,
14,
3008,
267,
340,
1303,
90,
815,
14,
374,
3399,
436,
747,
14,
515,
14,
2444,
8,
10265,
304,
288,
2256,
275,
1586,
21073,
8,
10265,
9,
288,
291,
14,
3008,
275,
747,
14,
515,
14,
904,
8,
277,
14,
3008,
12,
298,
11383,
15,
3399,
3100,
10665,
4318,
2256,
459,
5487,
12320,
18039,
1105,
398,
291,
14,
1760,
589,
275,
2088,
589,
503,
942,
267,
485,
1760,
589,
275,
359,
73,
367,
284,
315,
291,
14,
1760,
589,
490,
340,
284,
1137,
2475,
23801,
418,
267,
340,
822,
1547,
1760,
589,
9,
1137,
822,
8,
277,
14,
1760,
589,
304,
288,
327,
24470,
1077,
506,
2061,
27,
1937,
288,
327,
446,
4178,
921,
29220,
14,
12102,
14,
1308,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
22,
3912,
1079,
288,
327,
446,
4178,
921,
29220,
14,
12102,
14,
1308,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
22,
13731,
1479,
288,
291,
14,
1760,
589,
275,
485,
1760,
589,
288,
291,
14,
1760,
589,
14,
740,
3654,
23801,
358,
398,
327,
2112,
3734,
267,
340,
2589,
365,
488,
26,
288,
291,
14,
1813,
275,
747,
14,
2314,
14,
1574,
342,
267,
587,
26,
288,
291,
14,
1813,
275,
2589,
14,
1574,
342,
267,
327,
6127
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
363,
452,
363,
275,
788,
7446,
297,
283,
2719,
7138,
22488,
7446,
297,
283,
27983,
7446,
297,
283,
32213,
297,
283,
7802,
297,
283,
2764,
297,
283,
2491,
63,
2343,
418,
199,
199,
646,
1303,
90,
815,
199,
646,
8691,
199,
646,
747,
199,
646,
4298,
199,
646,
3873,
199,
646,
984,
199,
646,
14196,
199,
199,
504,
3778,
492,
664,
63,
2343,
63,
504,
63,
5799,
199,
504,
3778,
492,
2342,
607,
2042,
199,
504,
1303,
90,
2913,
492,
627,
199,
504,
1303,
90,
1412,
14,
1412,
2232,
492,
7132,
2461,
199,
199,
692,
1303,
90,
815,
14,
374,
3399,
26,
272,
687,
14459,
773,
492,
1586,
21073,
199,
199,
2491,
63,
2343,
275,
664,
63,
2343,
63,
504,
63,
5799,
360,
23120,
5933,
358,
199,
199,
3,
9672,
402,
10201,
18572,
370,
2556,
3595,
3062,
199,
3,
687,
1455,
921,
9457,
82,
14,
12102,
14,
1308,
15,
12102,
13,
16067,
15,
1365,
15,
1506,
15,
23867,
1208,
14,
647,
3,
1427,
199,
17612,
83,
275,
791,
17119,
356,
791,
13543,
356,
715,
12,
2151,
283,
589,
356,
11573,
81,
297,
2850,
589,
995,
1386,
1467,
283,
637,
21510,
356,
791,
13543,
356,
756,
12,
2079,
283,
589,
356,
14574,
28212,
13,
1074,
29,
2861,
12074,
1467,
789,
199,
199,
318,
14958,
63,
4958,
8,
17612,
12,
2368,
29,
403,
12,
12777,
29,
403,
304,
272,
408,
272,
17651,
14958,
2368,
687,
14958,
1627,
436,
4243,
272,
627,
14958,
520,
14958,
536,
503,
931,
370,
14958,
272,
627,
2368,
520,
2368,
370,
314,
14958,
12,
503,
488,
370,
675,
4243,
272,
627,
12777,
520,
3775,
314,
14958,
1077,
506,
1255,
315,
12777,
818,
12,
503,
488,
370,
675,
849,
272,
408,
339,
327,
2342,
14958,
7286,
340,
440,
282,
570,
272,
7286,
275,
14958,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5904,
304,
267,
7286,
275,
2342,
607,
2042,
8,
17612,
9,
272,
340,
7286,
365,
488,
26,
267,
746,
2186,
480,
2042,
370,
1543,
83,
7,
440,
1911,
2,
450,
14958,
9,
339,
327,
340,
14958,
440,
315,
2600,
402,
5715,
561,
372,
4243,
272,
9017,
12,
14958,
275,
747,
14,
515,
14,
1294,
8,
17612,
9,
272,
340,
14958,
440,
315,
14958,
83,
26,
267,
372,
7287,
5904,
61,
435,
334,
4958,
503,
14431,
2155,
8,
13543,
430,
339,
327,
4257,
675,
314,
2600,
1338,
367,
2368,
7444,
2013,
272,
340,
2368,
365,
488,
26,
267,
2368,
275,
14958,
83,
59,
17612,
1055,
362,
360,
589,
297,
3073,
272,
340,
12777,
365,
488,
26,
267,
12777,
275,
14958,
83,
59,
17612,
1055,
362,
360,
13543,
297,
756,
9,
272,
372,
7287,
5904,
61,
435,
2368,
12,
12777,
9,
199,
199,
533,
3378,
1372,
8,
785,
304,
272,
408,
23555,
1006,
3879,
5331,
14,
31434,
13341,
12,
7858,
436,
1022,
15350,
314,
2112,
1041,
339,
4690,
63,
533,
275,
14386,
327,
4690,
1021,
370,
675,
701,
849,
339,
768,
3744,
272,
347,
1218,
8,
1886,
12,
3366,
29,
403,
12,
2088,
589,
29,
403,
12,
2589,
29,
403,
12,
1022,
80,
63,
958,
29,
403,
12,
4690,
63,
589,
29,
403,
12,
2049,
3633,
63,
2913,
29,
549,
12,
2112,
63,
533,
29,
3498,
2461,
304,
267,
4690,
275,
843,
14,
2913,
63,
533,
3682,
8,
2913,
63,
589,
503,
17003,
267,
372,
843,
8,
2913,
12,
3366,
29,
3008,
12,
2088,
589,
29,
1760,
589,
12,
2589,
29,
1813,
12,
1022,
80,
63,
958,
29,
25017,
63,
958,
12,
5644,
3633,
63,
2913,
29,
3118,
63,
2913,
12,
2112,
63,
533,
29,
1412,
63,
533,
9,
339,
347,
636,
826,
721,
277,
12,
4690,
12,
3366,
12,
2088,
589,
29,
403,
12,
2589,
29,
403,
12,
326,
1022,
80,
63,
958,
29,
403,
12,
3633,
63,
2913,
29,
549,
12,
2112,
63,
533,
29,
3498,
2461,
304,
267,
291,
14,
1412,
63,
2232,
275,
488,
267,
291,
14,
1412,
63,
533,
275,
2112,
63,
533,
267,
291,
14,
2913,
275,
4690,
267,
291,
14,
3118,
63,
2913,
275,
3633,
63,
2913,
398,
327,
2342,
314,
3366,
267,
291,
14,
3008,
275,
3366,
267,
340,
440,
291,
14,
3008,
26,
288,
746,
2186,
480,
6636,
440,
2013,
531,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
3008,
304,
288,
746,
6440,
480,
6636,
931,
1630,
440,
2187,
26,
450,
83,
2,
450,
291,
14,
3008,
9,
398,
327,
2040,
10444,
21984,
370,
506,
2013,
465,
376,
1145,
8844,
267,
14459,
275,
1543,
83,
15,
11383,
15,
2354,
14,
10265,
7,
450,
291,
14,
3008,
267,
340,
1303,
90,
815,
14,
374,
3399,
436,
747,
14,
515,
14,
2444,
8,
10265,
304,
288,
2256,
275,
1586,
21073,
8,
10265,
9,
288,
291,
14,
3008,
275,
747,
14,
515,
14,
904,
8,
277,
14,
3008,
12,
298,
11383,
15,
3399,
3100,
10665,
4318,
2256,
459,
5487,
12320,
18039,
1105,
398,
291,
14,
1760,
589,
275,
2088,
589,
503,
942,
267,
485,
1760,
589,
275,
359,
73,
367,
284,
315,
291,
14,
1760,
589,
490,
340,
284,
1137,
2475,
23801,
418,
267,
340,
822,
1547,
1760,
589,
9,
1137,
822,
8,
277,
14,
1760,
589,
304,
288,
327,
24470,
1077,
506,
2061,
27,
1937,
288,
327,
446,
4178,
921,
29220,
14,
12102,
14,
1308,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
22,
3912,
1079,
288,
327,
446,
4178,
921,
29220,
14,
12102,
14,
1308,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
22,
13731,
1479,
288,
291,
14,
1760,
589,
275,
485,
1760,
589,
288,
291,
14,
1760,
589,
14,
740,
3654,
23801,
358,
398,
327,
2112,
3734,
267,
340,
2589,
365,
488,
26,
288,
291,
14,
1813,
275,
747,
14,
2314,
14,
1574,
342,
267,
587,
26,
288,
291,
14,
1813,
275,
2589,
14,
1574,
342,
267,
327,
6127,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wimnat/ansible-modules-extras
|
cloud/azure/azure_rm_deployment.py
|
9
|
27418
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
module: azure_rm_deployment
short_description: Create or destroy Azure Resource Manager template deployments
version_added: "2.1"
description:
- "Create or destroy Azure Resource Manager template deployments via the Azure SDK for Python.
You can find some quick start templates in GitHub here https://github.com/azure/azure-quickstart-templates.
For more information on Azue resource manager templates see https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-deploy/."
options:
resource_group_name:
description:
- The resource group name to use or create to host the deployed template
required: true
location:
description:
- The geo-locations in which the resource group will be located.
required: false
default: westus
deployment_mode:
description:
- In incremental mode, resources are deployed without deleting existing resources that are not included in the template.
In complete mode resources are deployed and existing resources in the resource group not included in the template are deleted.
required: false
default: incremental
choices:
- complete
- incremental
state:
description:
- If state is "present", template will be created. If state is "present" and if deployment exists, it will be
updated. If state is "absent", stack will be removed.
default: present
required: false
choices:
- present
- absent
template:
description:
- A hash containing the templates inline. This parameter is mutually exclusive with 'template_link'.
Either one of them is required if "state" parameter is "present".
required: false
default: null
template_link:
description:
- Uri of file containing the template body. This parameter is mutually exclusive with 'template'. Either one
of them is required if "state" parameter is "present".
required: false
default: null
parameters:
description:
- A hash of all the required template variables for the deployment template. This parameter is mutually exclusive
with 'parameters_link'. Either one of them is required if "state" parameter is "present".
required: false
default: null
parameters_link:
description:
- Uri of file containing the parameters body. This parameter is mutually exclusive with 'parameters'. Either
one of them is required if "state" parameter is "present".
required: false
default: null
deployment_name:
description:
- The name of the deployment to be tracked in the resource group deployment history. Re-using a deployment name
will overwrite the previous value in the resource group's deployment history.
default: ansible-arm
wait_for_deployment_completion:
description:
- Whether or not to block until the deployment has completed.
default: yes
choices: ['yes', 'no']
wait_for_deployment_polling_period:
description:
- Time (in seconds) to wait between polls when waiting for deployment completion.
default: 10
extends_documentation_fragment:
- azure
author:
- David Justice (@devigned)
- Laurent Mazuel (@lmazuel)
- Andre Price (@obsoleted)
'''
EXAMPLES = '''
# Destroy a template deployment
- name: Destroy Azure Deploy
azure_rm_deployment:
state: absent
subscription_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
resource_group_name: dev-ops-cle
# Create or update a template deployment based on uris using parameter and template links
- name: Create Azure Deploy
azure_rm_deployment:
state: present
resource_group_name: dev-ops-cle
template_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-linux/azuredeploy.json'
parameters_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-linux/azuredeploy.parameters.json'
# Create or update a template deployment based on a uri to the template and parameters specified inline.
# This deploys a VM with SSH support for a given public key, then stores the result in 'azure_vms'. The result is then
# used to create a new host group. This host group is then used to wait for each instance to respond to the public IP SSH.
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Destroy Azure Deploy
azure_rm_deployment:
state: absent
subscription_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
resource_group_name: dev-ops-cle
- name: Create Azure Deploy
azure_rm_deployment:
state: present
subscription_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
resource_group_name: dev-ops-cle
parameters:
newStorageAccountName:
value: devopsclestorage1
adminUsername:
value: devopscle
dnsNameForPublicIP:
value: devopscleazure
location:
value: West US
vmSize:
value: Standard_A2
vmName:
value: ansibleSshVm
sshKeyData:
value: YOUR_SSH_PUBLIC_KEY
template_link: 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-sshkey/azuredeploy.json'
register: azure
- name: Add new instance to host group
add_host: hostname={{ item['ips'][0].public_ip }} groupname=azure_vms
with_items: "{{ azure.deployment.instances }}"
- hosts: azure_vms
user: devopscle
tasks:
- name: Wait for SSH to come up
wait_for: port=22 timeout=2000 state=started
- name: echo the hostname of the vm
shell: hostname
# Deploy an Azure WebApp running a hello world'ish node app
- name: Create Azure WebApp Deployment at http://devopscleweb.azurewebsites.net/hello.js
azure_rm_deployment:
state: present
subscription_id: cbbdaed0-fea9-4693-bf0c-d446ac93c030
resource_group_name: dev-ops-cle-webapp
parameters:
repoURL:
value: 'https://github.com/devigned/az-roadshow-oss.git'
siteName:
value: devopscleweb
hostingPlanName:
value: someplan
siteLocation:
value: westus
sku:
value: Standard
template_link: 'https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-web-app-github-deploy/azuredeploy.json'
# Create or update a template deployment based on an inline template and parameters
- name: Create Azure Deploy
azure_rm_deployment:
state: present
subscription_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
resource_group_name: dev-ops-cle
template:
$schema: "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
contentVersion: "1.0.0.0"
parameters:
newStorageAccountName:
type: "string"
metadata:
description: "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed."
adminUsername:
type: "string"
metadata:
description: "User name for the Virtual Machine."
adminPassword:
type: "securestring"
metadata:
description: "Password for the Virtual Machine."
dnsNameForPublicIP:
type: "string"
metadata:
description: "Unique DNS Name for the Public IP used to access the Virtual Machine."
ubuntuOSVersion:
type: "string"
defaultValue: "14.04.2-LTS"
allowedValues:
- "12.04.5-LTS"
- "14.04.2-LTS"
- "15.04"
metadata:
description: "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version. Allowed values: 12.04.5-LTS, 14.04.2-LTS, 15.04."
variables:
location: "West US"
imagePublisher: "Canonical"
imageOffer: "UbuntuServer"
OSDiskName: "osdiskforlinuxsimple"
nicName: "myVMNic"
addressPrefix: "192.0.2.0/24"
subnetName: "Subnet"
subnetPrefix: "10.0.0.0/24"
storageAccountType: "Standard_LRS"
publicIPAddressName: "myPublicIP"
publicIPAddressType: "Dynamic"
vmStorageAccountContainerName: "vhds"
vmName: "MyUbuntuVM"
vmSize: "Standard_D1"
virtualNetworkName: "MyVNET"
vnetID: "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]"
subnetRef: "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]"
resources:
-
type: "Microsoft.Storage/storageAccounts"
name: "[parameters('newStorageAccountName')]"
apiVersion: "2015-05-01-preview"
location: "[variables('location')]"
properties:
accountType: "[variables('storageAccountType')]"
-
apiVersion: "2015-05-01-preview"
type: "Microsoft.Network/publicIPAddresses"
name: "[variables('publicIPAddressName')]"
location: "[variables('location')]"
properties:
publicIPAllocationMethod: "[variables('publicIPAddressType')]"
dnsSettings:
domainNameLabel: "[parameters('dnsNameForPublicIP')]"
-
type: "Microsoft.Network/virtualNetworks"
apiVersion: "2015-05-01-preview"
name: "[variables('virtualNetworkName')]"
location: "[variables('location')]"
properties:
addressSpace:
addressPrefixes:
- "[variables('addressPrefix')]"
subnets:
-
name: "[variables('subnetName')]"
properties:
addressPrefix: "[variables('subnetPrefix')]"
-
type: "Microsoft.Network/networkInterfaces"
apiVersion: "2015-05-01-preview"
name: "[variables('nicName')]"
location: "[variables('location')]"
dependsOn:
- "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
- "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
properties:
ipConfigurations:
-
name: "ipconfig1"
properties:
privateIPAllocationMethod: "Dynamic"
publicIPAddress:
id: "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
subnet:
id: "[variables('subnetRef')]"
-
type: "Microsoft.Compute/virtualMachines"
apiVersion: "2015-06-15"
name: "[variables('vmName')]"
location: "[variables('location')]"
dependsOn:
- "[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]"
- "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
properties:
hardwareProfile:
vmSize: "[variables('vmSize')]"
osProfile:
computername: "[variables('vmName')]"
adminUsername: "[parameters('adminUsername')]"
adminPassword: "[parameters('adminPassword')]"
storageProfile:
imageReference:
publisher: "[variables('imagePublisher')]"
offer: "[variables('imageOffer')]"
sku: "[parameters('ubuntuOSVersion')]"
version: "latest"
osDisk:
name: "osdisk"
vhd:
uri: "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
caching: "ReadWrite"
createOption: "FromImage"
networkProfile:
networkInterfaces:
-
id: "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
diagnosticsProfile:
bootDiagnostics:
enabled: "true"
storageUri: "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net')]"
parameters:
newStorageAccountName:
value: devopsclestorage
adminUsername:
value: devopscle
adminPassword:
value: Password1!
dnsNameForPublicIP:
value: devopscleazure
'''
RETURN = '''
deployment:
description: Deployment details
type: dict
returned: always
sample:
group_name:
description: Name of the resource group
type: string
returned: always
id:
description: The Azure ID of the deployment
type: string
returned: always
instances:
description: Provides the public IP addresses for each VM instance.
type: list
returned: always
name:
description: Name of the deployment
type: string
returned: always
outputs:
description: Dictionary of outputs received from the deployment
type: dict
returned: always
'''
PREREQ_IMPORT_ERROR = None
try:
import time
import yaml
except ImportError as exc:
IMPORT_ERROR = "Error importing module prerequisites: %s" % exc
from ansible.module_utils.azure_rm_common import *
try:
from itertools import chain
from azure.common.credentials import ServicePrincipalCredentials
from azure.common.exceptions import CloudError
from azure.mgmt.resource.resources.models import (DeploymentProperties,
ParametersLink,
TemplateLink,
Deployment,
ResourceGroup,
Dependency)
from azure.mgmt.resource.resources import ResourceManagementClient
from azure.mgmt.network import NetworkManagementClient
except ImportError:
# This is handled in azure_rm_common
pass
class AzureRMDeploymentManager(AzureRMModuleBase):
def __init__(self):
self.module_arg_spec = dict(
resource_group_name=dict(type='str', required=True, aliases=['resource_group']),
state=dict(type='str', default='present', choices=['present', 'absent']),
template=dict(type='dict', default=None),
parameters=dict(type='dict', default=None),
template_link=dict(type='str', default=None),
parameters_link=dict(type='str', default=None),
location=dict(type='str', default="westus"),
deployment_mode=dict(type='str', default='incremental', choices=['complete', 'incremental']),
deployment_name=dict(type='str', default="ansible-arm"),
wait_for_deployment_completion=dict(type='bool', default=True),
wait_for_deployment_polling_period=dict(type='int', default=10)
)
mutually_exclusive = [('template', 'template_link'),
('parameters', 'parameters_link')]
self.resource_group_name = None
self.state = None
self.template = None
self.parameters = None
self.template_link = None
self.parameters_link = None
self.location = None
self.deployment_mode = None
self.deployment_name = None
self.wait_for_deployment_completion = None
self.wait_for_deployment_polling_period = None
self.tags = None
self.results = dict(
deployment=dict(),
changed=False,
msg=""
)
super(AzureRMDeploymentManager, self).__init__(derived_arg_spec=self.module_arg_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=False)
def exec_module(self, **kwargs):
if PREREQ_IMPORT_ERROR:
self.fail(PREREQ_IMPORT_ERROR)
for key in self.module_arg_spec.keys() + ['tags']:
setattr(self, key, kwargs[key])
if self.state == 'present':
deployment = self.deploy_template()
self.results['deployment'] = dict(
name=deployment.name,
group_name=self.resource_group_name,
id=deployment.id,
outputs=deployment.properties.outputs,
instances=self._get_instances(deployment)
)
self.results['changed'] = True
self.results['msg'] = 'deployment succeeded'
else:
if self.resource_group_exists(self.resource_group_name):
self.destroy_resource_group()
self.results['changed'] = True
self.results['msg'] = "deployment deleted"
return self.results
def deploy_template(self):
"""
Deploy the targeted template and parameters
:param module: Ansible module containing the validated configuration for the deployment template
:param client: resource management client for azure
:param conn_info: connection info needed
:return:
"""
deploy_parameter = DeploymentProperties(self.deployment_mode)
if not self.parameters_link:
deploy_parameter.parameters = self.parameters
else:
deploy_parameter.parameters_link = ParametersLink(
uri=self.parameters_link
)
if not self.template_link:
deploy_parameter.template = self.template
else:
deploy_parameter.template_link = TemplateLink(
uri=self.template_link
)
params = ResourceGroup(location=self.location, tags=self.tags)
try:
self.rm_client.resource_groups.create_or_update(self.resource_group_name, params)
except CloudError as exc:
self.fail("Resource group create_or_update failed with status code: %s and message: %s" %
(exc.status_code, exc.message))
try:
result = self.rm_client.deployments.create_or_update(self.resource_group_name,
self.deployment_name,
deploy_parameter)
deployment_result = self.get_poller_result(result)
if self.wait_for_deployment_completion:
while deployment_result.properties is None or deployment_result.properties.provisioning_state not in ['Canceled', 'Failed', 'Deleted',
'Succeeded']:
time.sleep(self.wait_for_deployment_polling_period)
deployment_result = self.rm_client.deployments.get(self.resource_group_name, self.deployment_name)
except CloudError as exc:
failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name)
self.log("Deployment failed %s: %s" % (exc.status_code, exc.message))
self.fail("Deployment failed with status code: %s and message: %s" % (exc.status_code, exc.message),
failed_deployment_operations=failed_deployment_operations)
if self.wait_for_deployment_completion and deployment_result.properties.provisioning_state != 'Succeeded':
self.log("provisioning state: %s" % deployment_result.properties.provisioning_state)
failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name)
self.fail('Deployment failed. Deployment id: %s' % deployment_result.id,
failed_deployment_operations=failed_deployment_operations)
return deployment_result
def destroy_resource_group(self):
"""
Destroy the targeted resource group
"""
try:
result = self.rm_client.resource_groups.delete(self.resource_group_name)
result.wait() # Blocking wait till the delete is finished
except CloudError as e:
if e.status_code == 404 or e.status_code == 204:
return
else:
self.fail("Delete resource group and deploy failed with status code: %s and message: %s" %
(e.status_code, e.message))
def resource_group_exists(self, resource_group):
'''
Return True/False based on existence of requested resource group.
:param resource_group: string. Name of a resource group.
:return: boolean
'''
try:
self.rm_client.resource_groups.get(resource_group)
except CloudError:
return False
return True
def _get_failed_nested_operations(self, current_operations):
new_operations = []
for operation in current_operations:
if operation.properties.provisioning_state == 'Failed':
new_operations.append(operation)
if operation.properties.target_resource and \
'Microsoft.Resources/deployments' in operation.properties.target_resource.id:
nested_deployment = operation.properties.target_resource.resource_name
try:
nested_operations = self.rm_client.deployment_operations.list(self.resource_group_name,
nested_deployment)
except CloudError as exc:
self.fail("List nested deployment operations failed with status code: %s and message: %s" %
(e.status_code, e.message))
new_nested_operations = self._get_failed_nested_operations(nested_operations)
new_operations += new_nested_operations
return new_operations
def _get_failed_deployment_operations(self, deployment_name):
results = []
# time.sleep(15) # there is a race condition between when we ask for deployment status and when the
# # status is available.
try:
operations = self.rm_client.deployment_operations.list(self.resource_group_name, deployment_name)
except CloudError as exc:
self.fail("Get deployment failed with status code: %s and message: %s" %
(exc.status_code, exc.message))
try:
results = [
dict(
id=op.id,
operation_id=op.operation_id,
status_code=op.properties.status_code,
status_message=op.properties.status_message,
target_resource=dict(
id=op.properties.target_resource.id,
resource_name=op.properties.target_resource.resource_name,
resource_type=op.properties.target_resource.resource_type
) if op.properties.target_resource else None,
provisioning_state=op.properties.provisioning_state,
)
for op in self._get_failed_nested_operations(operations)
]
except:
# If we fail here, the original error gets lost and user receives wrong error message/stacktrace
pass
self.log(dict(failed_deployment_operations=results), pretty_print=True)
return results
def _get_instances(self, deployment):
dep_tree = self._build_hierarchy(deployment.properties.dependencies)
vms = self._get_dependencies(dep_tree, resource_type="Microsoft.Compute/virtualMachines")
vms_and_nics = [(vm, self._get_dependencies(vm['children'], "Microsoft.Network/networkInterfaces"))
for vm in vms]
vms_and_ips = [(vm['dep'], self._nic_to_public_ips_instance(nics))
for vm, nics in vms_and_nics]
return [dict(vm_name=vm.resource_name, ips=[self._get_ip_dict(ip)
for ip in ips]) for vm, ips in vms_and_ips if len(ips) > 0]
def _get_dependencies(self, dep_tree, resource_type):
matches = [value for value in dep_tree.values() if value['dep'].resource_type == resource_type]
for child_tree in [value['children'] for value in dep_tree.values()]:
matches += self._get_dependencies(child_tree, resource_type)
return matches
def _build_hierarchy(self, dependencies, tree=None):
tree = dict(top=True) if tree is None else tree
for dep in dependencies:
if dep.resource_name not in tree:
tree[dep.resource_name] = dict(dep=dep, children=dict())
if isinstance(dep, Dependency) and dep.depends_on is not None and len(dep.depends_on) > 0:
self._build_hierarchy(dep.depends_on, tree[dep.resource_name]['children'])
if 'top' in tree:
tree.pop('top', None)
keys = list(tree.keys())
for key1 in keys:
for key2 in keys:
if key2 in tree and key1 in tree[key2]['children'] and key1 in tree:
tree[key2]['children'][key1] = tree[key1]
tree.pop(key1)
return tree
def _get_ip_dict(self, ip):
ip_dict = dict(name=ip.name,
id=ip.id,
public_ip=ip.ip_address,
public_ip_allocation_method=str(ip.public_ip_allocation_method)
)
if ip.dns_settings:
ip_dict['dns_settings'] = {
'domain_name_label':ip.dns_settings.domain_name_label,
'fqdn':ip.dns_settings.fqdn
}
return ip_dict
def _nic_to_public_ips_instance(self, nics):
return [self.network_client.public_ip_addresses.get(public_ip_id.split('/')[4], public_ip_id.split('/')[-1])
for nic_obj in [self.network_client.network_interfaces.get(self.resource_group_name,
nic['dep'].resource_name) for nic in nics]
for public_ip_id in [ip_conf_instance.public_ip_address.id
for ip_conf_instance in nic_obj.ip_configurations
if ip_conf_instance.public_ip_address]]
def main():
AzureRMDeploymentManager()
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
13601,
63,
5682,
63,
13605,
199,
199,
3612,
63,
1802,
26,
2790,
503,
11972,
15474,
7337,
13537,
1978,
12287,
1470,
199,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
199,
1802,
26,
1362,
446,
298,
2499,
503,
11972,
15474,
7337,
13537,
1978,
12287,
1470,
4799,
314,
15474,
15610,
367,
2018,
14,
2126,
2047,
883,
2342,
2005,
12530,
1343,
7009,
315,
25141,
2348,
4178,
921,
5031,
14,
957,
15,
9078,
15,
9078,
13,
28957,
13,
5876,
14,
2126,
2104,
1655,
2556,
641,
437,
90,
310,
2073,
5256,
7009,
1937,
4178,
921,
9078,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
9970,
15,
19813,
15,
1927,
13,
923,
13,
1160,
13,
11060,
15,
2122,
199,
199,
1419,
26,
523,
2073,
63,
923,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
2073,
1572,
536,
370,
675,
503,
1218,
370,
1591,
314,
26181,
1978,
272,
1415,
26,
2549,
523,
2909,
26,
272,
1369,
26,
489,
446,
710,
8509,
13,
8022,
315,
1314,
314,
2073,
1572,
911,
506,
16180,
14,
272,
1415,
26,
3055,
272,
849,
26,
336,
597,
527,
523,
14295,
63,
632,
26,
272,
1369,
26,
489,
446,
1010,
16316,
818,
12,
5944,
787,
26181,
1928,
13794,
3411,
5944,
626,
787,
440,
5120,
315,
314,
1978,
14,
4960,
1010,
4890,
818,
5944,
787,
26181,
436,
3411,
5944,
315,
314,
2073,
1572,
440,
5120,
315,
314,
1978,
787,
5463,
14,
272,
1415,
26,
3055,
272,
849,
26,
16316,
272,
3415,
26,
267,
446,
4890,
267,
446,
16316,
523,
1174,
26,
272,
1369,
26,
489,
446,
982,
1174,
365,
298,
1881,
401,
1978,
911,
506,
2737,
14,
982,
1174,
365,
298,
1881,
2,
436,
340,
14295,
3495,
12,
652,
911,
506,
267,
4588,
14,
982,
1174,
365,
298,
5575,
401,
3464,
911,
506,
4829,
14,
272,
849,
26,
3451,
272,
1415,
26,
3055,
272,
3415,
26,
267,
446,
3451,
267,
446,
9552,
523,
1978,
26,
272,
1369,
26,
489,
446,
437,
2631,
3035,
314,
7009,
8308,
14,
961,
2725,
365,
16108,
13914,
543,
283,
1160,
63,
1073,
1370,
267,
13083,
1373,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1978,
63,
1073,
26,
272,
1369,
26,
489,
446,
738,
322,
402,
570,
3035,
314,
1978,
2396,
14,
961,
2725,
365,
16108,
13914,
543,
283,
1160,
1370,
13083,
1373,
267,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2633,
26,
272,
1369,
26,
489,
446,
437,
2631,
402,
1006,
314,
1415,
1978,
2860,
367,
314,
14295,
1978,
14,
961,
2725,
365,
16108,
13914,
267,
543,
283,
3214,
63,
1073,
1370,
13083,
1373,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2633,
63,
1073,
26,
272,
1369,
26,
489,
446,
738,
322,
402,
570,
3035,
314,
2633,
2396,
14,
961,
2725,
365,
16108,
13914,
543,
283,
3214,
1370,
13083,
267,
1373,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
14295,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
14295,
370,
506,
23268,
315,
314,
2073,
1572,
14295,
7994,
14,
799,
13,
4941,
282,
14295,
536,
267,
911,
8970,
314,
4136,
574,
315,
314,
2073,
1572,
1159,
14295,
7994,
14,
272,
849,
26,
3242,
13,
5362,
523,
3618,
63,
509,
63,
13605,
63,
13207,
26,
272,
1369,
26,
489,
446,
7480,
503,
440,
370,
1853,
5133,
314,
14295,
965,
9709,
14,
272,
849,
26,
9456,
272,
3415,
26,
788,
5066,
297,
283,
889,
418,
523,
3618,
63,
509,
63,
13605,
63,
17154,
63,
5191,
26,
272,
1369,
26,
489,
446,
4703,
334,
262,
4696,
9,
370,
3618,
3382,
3708,
478,
1380,
10923,
367,
14295,
13659,
14,
272,
849,
26,
1616,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
13601,
199,
199,
2502,
26,
272,
446,
20232,
13870,
1885,
8593,
271,
433,
784,
379,
9,
272,
446,
7964,
608,
343,
603,
4651,
13086,
8593,
76,
391,
90,
13086,
9,
272,
446,
6061,
264,
20276,
8593,
2873,
1152,
3496,
9,
199,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
20547,
4813,
282,
1978,
14295,
199,
13,
536,
26,
20547,
4813,
15474,
21588,
3374,
523,
13601,
63,
5682,
63,
13605,
26,
272,
1174,
26,
9552,
272,
9966,
63,
344,
26,
671,
5336,
10013,
13,
5336,
13,
5336,
13,
5336,
13,
9505,
5336,
272,
2073,
63,
923,
63,
354,
26,
4866,
13,
1483,
13,
2265,
199,
199,
3,
2790,
503,
1678,
282,
1978,
14295,
4079,
641,
7629,
374,
1808,
2725,
436,
1978,
6220,
199,
13,
536,
26,
2790,
15474,
21588,
3374,
523,
13601,
63,
5682,
63,
13605,
26,
272,
1174,
26,
3451,
272,
2073,
63,
923,
63,
354,
26,
4866,
13,
1483,
13,
2265,
272,
1978,
63,
1073,
26,
283,
2859,
921,
1773,
14,
5031,
751,
1317,
14,
957,
15,
22386,
15,
9078,
13,
28957,
13,
5876,
15,
4133,
15,
4893,
13,
2611,
13,
4129,
13,
5135,
15,
9078,
11060,
14,
1001,
7,
272,
2633
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
13601,
63,
5682,
63,
13605,
199,
199,
3612,
63,
1802,
26,
2790,
503,
11972,
15474,
7337,
13537,
1978,
12287,
1470,
199,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
199,
1802,
26,
1362,
446,
298,
2499,
503,
11972,
15474,
7337,
13537,
1978,
12287,
1470,
4799,
314,
15474,
15610,
367,
2018,
14,
2126,
2047,
883,
2342,
2005,
12530,
1343,
7009,
315,
25141,
2348,
4178,
921,
5031,
14,
957,
15,
9078,
15,
9078,
13,
28957,
13,
5876,
14,
2126,
2104,
1655,
2556,
641,
437,
90,
310,
2073,
5256,
7009,
1937,
4178,
921,
9078,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
9970,
15,
19813,
15,
1927,
13,
923,
13,
1160,
13,
11060,
15,
2122,
199,
199,
1419,
26,
523,
2073,
63,
923,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
2073,
1572,
536,
370,
675,
503,
1218,
370,
1591,
314,
26181,
1978,
272,
1415,
26,
2549,
523,
2909,
26,
272,
1369,
26,
489,
446,
710,
8509,
13,
8022,
315,
1314,
314,
2073,
1572,
911,
506,
16180,
14,
272,
1415,
26,
3055,
272,
849,
26,
336,
597,
527,
523,
14295,
63,
632,
26,
272,
1369,
26,
489,
446,
1010,
16316,
818,
12,
5944,
787,
26181,
1928,
13794,
3411,
5944,
626,
787,
440,
5120,
315,
314,
1978,
14,
4960,
1010,
4890,
818,
5944,
787,
26181,
436,
3411,
5944,
315,
314,
2073,
1572,
440,
5120,
315,
314,
1978,
787,
5463,
14,
272,
1415,
26,
3055,
272,
849,
26,
16316,
272,
3415,
26,
267,
446,
4890,
267,
446,
16316,
523,
1174,
26,
272,
1369,
26,
489,
446,
982,
1174,
365,
298,
1881,
401,
1978,
911,
506,
2737,
14,
982,
1174,
365,
298,
1881,
2,
436,
340,
14295,
3495,
12,
652,
911,
506,
267,
4588,
14,
982,
1174,
365,
298,
5575,
401,
3464,
911,
506,
4829,
14,
272,
849,
26,
3451,
272,
1415,
26,
3055,
272,
3415,
26,
267,
446,
3451,
267,
446,
9552,
523,
1978,
26,
272,
1369,
26,
489,
446,
437,
2631,
3035,
314,
7009,
8308,
14,
961,
2725,
365,
16108,
13914,
543,
283,
1160,
63,
1073,
1370,
267,
13083,
1373,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1978,
63,
1073,
26,
272,
1369,
26,
489,
446,
738,
322,
402,
570,
3035,
314,
1978,
2396,
14,
961,
2725,
365,
16108,
13914,
543,
283,
1160,
1370,
13083,
1373,
267,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2633,
26,
272,
1369,
26,
489,
446,
437,
2631,
402,
1006,
314,
1415,
1978,
2860,
367,
314,
14295,
1978,
14,
961,
2725,
365,
16108,
13914,
267,
543,
283,
3214,
63,
1073,
1370,
13083,
1373,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2633,
63,
1073,
26,
272,
1369,
26,
489,
446,
738,
322,
402,
570,
3035,
314,
2633,
2396,
14,
961,
2725,
365,
16108,
13914,
543,
283,
3214,
1370,
13083,
267,
1373,
402,
3062,
365,
1415,
340,
298,
929,
2,
2725,
365,
298,
1881,
1674,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
14295,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
14295,
370,
506,
23268,
315,
314,
2073,
1572,
14295,
7994,
14,
799,
13,
4941,
282,
14295,
536,
267,
911,
8970,
314,
4136,
574,
315,
314,
2073,
1572,
1159,
14295,
7994,
14,
272,
849,
26,
3242,
13,
5362,
523,
3618,
63,
509,
63,
13605,
63,
13207,
26,
272,
1369,
26,
489,
446,
7480,
503,
440,
370,
1853,
5133,
314,
14295,
965,
9709,
14,
272,
849,
26,
9456,
272,
3415,
26,
788,
5066,
297,
283,
889,
418,
523,
3618,
63,
509,
63,
13605,
63,
17154,
63,
5191,
26,
272,
1369,
26,
489,
446,
4703,
334,
262,
4696,
9,
370,
3618,
3382,
3708,
478,
1380,
10923,
367,
14295,
13659,
14,
272,
849,
26,
1616,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
13601,
199,
199,
2502,
26,
272,
446,
20232,
13870,
1885,
8593,
271,
433,
784,
379,
9,
272,
446,
7964,
608,
343,
603,
4651,
13086,
8593,
76,
391,
90,
13086,
9,
272,
446,
6061,
264,
20276,
8593,
2873,
1152,
3496,
9,
199,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
20547,
4813,
282,
1978,
14295,
199,
13,
536,
26,
20547,
4813,
15474,
21588,
3374,
523,
13601,
63,
5682,
63,
13605,
26,
272,
1174,
26,
9552,
272,
9966,
63,
344,
26,
671,
5336,
10013,
13,
5336,
13,
5336,
13,
5336,
13,
9505,
5336,
272,
2073,
63,
923,
63,
354,
26,
4866,
13,
1483,
13,
2265,
199,
199,
3,
2790,
503,
1678,
282,
1978,
14295,
4079,
641,
7629,
374,
1808,
2725,
436,
1978,
6220,
199,
13,
536,
26,
2790,
15474,
21588,
3374,
523,
13601,
63,
5682,
63,
13605,
26,
272,
1174,
26,
3451,
272,
2073,
63,
923,
63,
354,
26,
4866,
13,
1483,
13,
2265,
272,
1978,
63,
1073,
26,
283,
2859,
921,
1773,
14,
5031,
751,
1317,
14,
957,
15,
22386,
15,
9078,
13,
28957,
13,
5876,
15,
4133,
15,
4893,
13,
2611,
13,
4129,
13,
5135,
15,
9078,
11060,
14,
1001,
7,
272,
2633,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrcslws/nupic.research
|
nupic/research/frameworks/dynamic_sparse/networks/hebbian.py
|
3
|
9819
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2019, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
import torch
from torch import nn
from nupic.torch.modules import Flatten, KWinners, KWinners2d
from .layers import DSLinear, init_coactivation_tracking
__all__ = [
"DSLinearBlock",
"HebbianNetwork",
"MLPHeb",
"GSCHeb",
"gsc_heb_small",
]
# ------------------------------------------------------------------------------------
# DynamicSparse Linear Block
# ------------------------------------------------------------------------------------
class DSLinearBlock(nn.Sequential):
def __init__(
self,
in_features,
out_features,
bias=True,
batch_norm=None,
batch_norm_affine=True,
dropout=None,
activation_func=None,
config=None,
):
# Clarifications on batch norm position at the linear block:
# - bn before relu at original paper
# - bn after relu in recent work
# (see fchollet @ https://github.com/keras-team/keras/issues/1802)
# - however, if applied after RELU or kWinners, breaks sparsity
config = config or {}
layers = [DSLinear(in_features, out_features, bias=bias, config=config)]
if batch_norm:
layers.append(nn.BatchNorm1d(out_features, affine=batch_norm_affine))
if activation_func:
layers.append(activation_func)
if dropout:
layers.append(nn.Dropout(p=dropout))
super().__init__(*layers)
# Transfer forward hook.
dslayer = self[0]
forward_hook = dslayer.forward_hook
self.register_forward_hook(
lambda module, in_, out_: forward_hook(dslayer, in_, out_)
)
dslayer.forward_hook_handle.remove()
@property
def weight(self):
"""
Return weight of linear layer - needed for introspective networks.
"""
return self[0].weight
def forward(self, input_tensor):
output_tensor = super().forward(input_tensor)
return output_tensor
# ------------
# MLP Network
# ------------
class HebbianNetwork(nn.Module):
@property
def coactivations(self):
if self._track_coactivations:
return [m.coactivations.t() for m in self.dynamic_sparse_modules]
else:
return []
def forward(self, x):
if "features" in self._modules:
x = self.features(x)
x = self.classifier(x)
return x
def init_hebbian(self):
self._track_coactivations = True
self.apply(init_coactivation_tracking)
class MLPHeb(HebbianNetwork):
"""Simple 3 hidden layers + output MLP"""
def __init__(self, config=None):
super().__init__()
defaults = dict(
device="cpu",
input_size=784,
num_classes=10,
hidden_sizes=[100, 100, 100],
percent_on_k_winner=[1.0, 1.0, 1.0],
boost_strength=[1.4, 1.4, 1.4],
boost_strength_factor=[0.7, 0.7, 0.7],
batch_norm=False,
dropout=False,
bias=True,
k_inference_factor=1.0,
)
assert (
config is None or "use_kwinners" not in config
), "use_kwinners is deprecated"
defaults.update(config or {})
self.__dict__.update(defaults)
self.device = torch.device(self.device)
# decide which actiovation function to use
self.activation_funcs = []
for layer, hidden_size in enumerate(self.hidden_sizes):
if self.percent_on_k_winner[layer] < 0.5:
self.activation_funcs.append(
KWinners(
hidden_size,
percent_on=self.percent_on_k_winner[layer],
boost_strength=self.boost_strength[layer],
boost_strength_factor=self.boost_strength_factor[layer],
k_inference_factor=self.k_inference_factor,
)
)
else:
self.activation_funcs.append(nn.ReLU())
# Construct layers.
layers = []
kwargs = dict(bias=self.bias, batch_norm=self.batch_norm, dropout=self.dropout)
# Flatten image.
layers = [nn.Flatten()]
# Add the first layer
layers.append(
DSLinearBlock(
self.input_size,
self.hidden_sizes[0],
activation_func=self.activation_funcs[0],
config=config,
**kwargs,
)
)
# Add hidden layers.
for i in range(1, len(self.hidden_sizes)):
layers.append(
DSLinearBlock(
self.hidden_sizes[i - 1],
self.hidden_sizes[i],
activation_func=self.activation_funcs[i],
config=config,
**kwargs,
)
)
# Add last layer.
layers.append(
DSLinearBlock(
self.hidden_sizes[-1], self.num_classes, bias=self.bias, config=config
)
)
# Create the classifier.
self.dynamic_sparse_modules = [layer[0] for layer in layers[1:]]
self.classifier = nn.Sequential(*layers)
# Initialize attr to decide whether to update coactivations during learning.
self._track_coactivations = False # Off by default.
class GSCHeb(HebbianNetwork):
"""Simple 3 hidden layers + output MLP"""
def __init__(self, config=None):
super().__init__()
defaults = dict(
device="cpu",
input_size=1024,
num_classes=12,
boost_strength=[1.5, 1.5, 1.5],
boost_strength_factor=[0.9, 0.9, 0.9],
duty_cycle_period=1000,
k_inference_factor=1.5,
percent_on_k_winner=[0.095, 0.125, 0.1],
hidden_neurons_conv=[64, 64],
hidden_neurons_fc=1000,
batch_norm=True,
dropout=False,
bias=True,
)
defaults.update(config or {})
self.__dict__.update(defaults)
self.device = torch.device(self.device)
kwargs = dict(bias=self.bias, batch_norm=self.batch_norm, dropout=self.dropout)
# decide which actiovation function to use for conv
self.activation_funcs = []
for layer, hidden_size in enumerate(self.hidden_neurons_conv):
if self.percent_on_k_winner[layer] < 0.5:
self.activation_funcs.append(
KWinners2d(
hidden_size,
percent_on=self.percent_on_k_winner[layer],
boost_strength=self.boost_strength[layer],
boost_strength_factor=self.boost_strength_factor[layer],
k_inference_factor=self.k_inference_factor,
)
)
else:
self.activation_funcs.append(nn.ReLU())
# decide which activvation to use for linear
if self.percent_on_k_winner[-1] < 0.5:
linear_activation = KWinners(
self.hidden_neurons_fc,
percent_on=self.percent_on_k_winner[-1],
boost_strength=self.boost_strength[-1],
boost_strength_factor=self.boost_strength_factor[-1],
k_inference_factor=self.k_inference_factor,
)
else:
linear_activation = nn.ReLU()
# linear layers
conv_layers = [
# 28x28 -> 14x14
*self._conv_block(1, self.hidden_neurons_conv[0], self.activation_funcs[0]),
# 10x10 -> 5x5
*self._conv_block(
self.hidden_neurons_conv[0],
self.hidden_neurons_conv[1],
self.activation_funcs[1],
),
Flatten(),
]
linear_layers = [
DSLinearBlock(
self.hidden_neurons_conv[1] * 25,
self.hidden_neurons_fc,
activation_func=linear_activation,
batch_norm_affine=False,
config=config,
**kwargs,
),
DSLinearBlock(self.hidden_neurons_fc, self.num_classes, config=config),
]
self.features = nn.Sequential(*conv_layers)
self.classifier = nn.Sequential(*linear_layers)
def _conv_block(self, fin, fout, activation_func):
block = [
nn.Conv2d(fin, fout, kernel_size=5, stride=1, padding=0),
nn.BatchNorm2d(fout, affine=False),
nn.MaxPool2d(kernel_size=2, stride=2),
activation_func,
]
return block
def gsc_heb_small(config):
config["hidden_neurons_conv"] = [12, 12]
config["hidden_neurons_fc"] = 207
return GSCHeb(config)
|
agpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
20312,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
646,
21416,
199,
504,
21416,
492,
11542,
199,
199,
504,
26084,
14,
29676,
14,
3112,
492,
19005,
724,
12,
1804,
8886,
8715,
12,
1804,
8886,
8715,
18,
68,
199,
199,
504,
1275,
4359,
492,
577,
51,
10608,
12,
4205,
63,
331,
12312,
63,
14428,
199,
199,
363,
452,
363,
275,
359,
272,
298,
3177,
10608,
3142,
401,
272,
298,
1966,
2501,
5653,
4491,
401,
272,
298,
1698,
48,
1966,
66,
401,
272,
298,
8021,
1244,
2871,
401,
272,
298,
458,
67,
63,
9260,
63,
7241,
401,
199,
61,
421,
199,
3,
5620,
777,
375,
199,
3,
21907,
8629,
12489,
8651,
199,
3,
5620,
777,
375,
421,
199,
533,
577,
51,
10608,
3142,
8,
4411,
14,
18509,
304,
272,
347,
636,
826,
721,
267,
291,
12,
267,
315,
63,
3179,
12,
267,
734,
63,
3179,
12,
267,
10671,
29,
549,
12,
267,
3522,
63,
4791,
29,
403,
12,
267,
3522,
63,
4791,
63,
9181,
1132,
29,
549,
12,
267,
19795,
29,
403,
12,
267,
10361,
63,
1532,
29,
403,
12,
267,
1101,
29,
403,
12,
272,
3461,
398,
327,
8465,
759,
3477,
83,
641,
3522,
6316,
3421,
737,
314,
7798,
1853,
26,
267,
327,
446,
21847,
2544,
4668,
85,
737,
3379,
15220,
267,
327,
446,
21847,
2410,
4668,
85,
315,
8058,
1736,
267,
327,
334,
3239,
289,
27972,
2723,
768,
4178,
921,
5031,
14,
957,
15,
8811,
13,
5969,
15,
8811,
15,
10115,
15,
1085,
996,
9,
267,
327,
446,
13432,
12,
340,
6781,
2410,
820,
2901,
53,
503,
1022,
8886,
8715,
12,
18277,
28668,
3677,
267,
1101,
275,
1101,
503,
1052,
267,
9393,
275,
359,
3177,
10608,
8,
262,
63,
3179,
12,
734,
63,
3179,
12,
10671,
29,
8160,
12,
1101,
29,
888,
1874,
267,
340,
3522,
63,
4791,
26,
288,
9393,
14,
740,
8,
4411,
14,
32672,
17,
68,
8,
548,
63,
3179,
12,
31435,
29,
2912,
63,
4791,
63,
9181,
1132,
430,
267,
340,
10361,
63,
1532,
26,
288,
9393,
14,
740,
8,
12312,
63,
1532,
9,
267,
340,
19795,
26,
288,
9393,
14,
740,
8,
4411,
14,
30662,
8,
80,
29,
17953,
430,
267,
1613,
11027,
826,
9308,
4359,
9,
398,
327,
27507,
7568,
5759,
14,
267,
6364,
1897,
275,
291,
59,
16,
61,
267,
7568,
63,
3664,
275,
6364,
1897,
14,
6688,
63,
3664,
267,
291,
14,
2683,
63,
6688,
63,
3664,
8,
288,
2400,
859,
12,
315,
3131,
734,
10388,
7568,
63,
3664,
8,
795,
1897,
12,
315,
3131,
734,
4602,
267,
776,
267,
6364,
1897,
14,
6688,
63,
3664,
63,
2479,
14,
2168,
342,
339,
768,
1829,
272,
347,
5401,
8,
277,
304,
267,
408,
267,
1432,
5401,
402,
7798,
4045,
446,
4346,
367,
13318,
16657,
11759,
14,
267,
408,
267,
372,
291,
59,
16,
1055,
3463,
339,
347,
7568,
8,
277,
12,
1324,
63,
3128,
304,
267,
1072,
63,
3128,
275,
1613,
1252,
6688,
8,
1210,
63,
3128,
9,
267,
372,
1072,
63,
3128,
421,
199,
3,
3001,
375,
199,
3,
603,
9257,
7220,
199,
3,
3001,
375,
421,
199,
533,
5311,
2501,
5653,
4491,
8,
4411,
14,
2377,
304,
272,
768,
1829,
272,
347,
512,
31117,
8,
277,
304,
267,
340,
291,
423,
3885,
63,
331,
31117,
26,
288,
372,
359,
77,
14,
331,
31117,
14,
84,
342,
367,
333,
315,
291,
14,
7764,
63,
4421,
63,
3112,
61,
267,
587,
26,
288,
372,
942,
339,
347,
7568,
8,
277,
12,
671,
304,
267,
340,
298,
3179,
2,
315,
291,
423,
3112,
26,
288,
671,
275,
291,
14,
3179,
8,
88,
9,
267,
671,
275,
291,
14,
14720,
8,
88,
9,
267,
372,
671,
339,
347,
4205,
63,
426,
2501,
5653,
8,
277,
304,
267,
291,
423,
3885,
63,
331,
31117,
275,
715,
267,
291,
14,
4998,
8,
826,
63,
331,
12312,
63,
14428,
9,
421,
199,
533,
603,
9257,
1966,
66,
8,
1966,
2501,
5653,
4491,
304,
272,
408,
3184,
650,
8752,
9393,
435,
1072,
603,
9257,
624,
339,
347,
636,
826,
721,
277,
12,
1101,
29,
403,
304,
267,
1613,
11027,
826,
4533,
398,
4243,
275,
1211,
8,
288,
2243,
628,
3541,
401,
288,
1324,
63,
890,
29,
28394,
12,
288,
1967,
63,
2888,
29,
709,
12,
288,
8752,
63,
7723,
1524,
1960,
12,
2948,
12,
2948,
467,
288,
8878,
63,
265,
63,
75,
63,
2676,
1372,
1524,
17,
14,
16,
12,
413,
14,
16,
12,
413,
14,
16,
467,
288,
20198,
63,
21049,
1524,
17,
14,
20,
12,
413,
14,
20,
12,
413,
14,
20,
467,
288,
20198,
63,
21049,
63,
4778,
1524,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
467,
288,
3522,
63,
4791,
29,
797,
12,
288,
19795,
29,
797,
12,
288,
10671,
29,
549,
12,
288,
1022,
63,
20580,
63,
4778,
29,
17,
14,
16,
12,
267,
776,
267,
702,
334,
288,
1101,
365,
488,
503,
298,
1180,
63,
829,
262,
8715,
2,
440,
315,
1101,
267,
2318,
298,
1180,
63,
829,
262,
8715,
365,
5906,
2,
398,
4243
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
20312,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
646,
21416,
199,
504,
21416,
492,
11542,
199,
199,
504,
26084,
14,
29676,
14,
3112,
492,
19005,
724,
12,
1804,
8886,
8715,
12,
1804,
8886,
8715,
18,
68,
199,
199,
504,
1275,
4359,
492,
577,
51,
10608,
12,
4205,
63,
331,
12312,
63,
14428,
199,
199,
363,
452,
363,
275,
359,
272,
298,
3177,
10608,
3142,
401,
272,
298,
1966,
2501,
5653,
4491,
401,
272,
298,
1698,
48,
1966,
66,
401,
272,
298,
8021,
1244,
2871,
401,
272,
298,
458,
67,
63,
9260,
63,
7241,
401,
199,
61,
421,
199,
3,
5620,
777,
375,
199,
3,
21907,
8629,
12489,
8651,
199,
3,
5620,
777,
375,
421,
199,
533,
577,
51,
10608,
3142,
8,
4411,
14,
18509,
304,
272,
347,
636,
826,
721,
267,
291,
12,
267,
315,
63,
3179,
12,
267,
734,
63,
3179,
12,
267,
10671,
29,
549,
12,
267,
3522,
63,
4791,
29,
403,
12,
267,
3522,
63,
4791,
63,
9181,
1132,
29,
549,
12,
267,
19795,
29,
403,
12,
267,
10361,
63,
1532,
29,
403,
12,
267,
1101,
29,
403,
12,
272,
3461,
398,
327,
8465,
759,
3477,
83,
641,
3522,
6316,
3421,
737,
314,
7798,
1853,
26,
267,
327,
446,
21847,
2544,
4668,
85,
737,
3379,
15220,
267,
327,
446,
21847,
2410,
4668,
85,
315,
8058,
1736,
267,
327,
334,
3239,
289,
27972,
2723,
768,
4178,
921,
5031,
14,
957,
15,
8811,
13,
5969,
15,
8811,
15,
10115,
15,
1085,
996,
9,
267,
327,
446,
13432,
12,
340,
6781,
2410,
820,
2901,
53,
503,
1022,
8886,
8715,
12,
18277,
28668,
3677,
267,
1101,
275,
1101,
503,
1052,
267,
9393,
275,
359,
3177,
10608,
8,
262,
63,
3179,
12,
734,
63,
3179,
12,
10671,
29,
8160,
12,
1101,
29,
888,
1874,
267,
340,
3522,
63,
4791,
26,
288,
9393,
14,
740,
8,
4411,
14,
32672,
17,
68,
8,
548,
63,
3179,
12,
31435,
29,
2912,
63,
4791,
63,
9181,
1132,
430,
267,
340,
10361,
63,
1532,
26,
288,
9393,
14,
740,
8,
12312,
63,
1532,
9,
267,
340,
19795,
26,
288,
9393,
14,
740,
8,
4411,
14,
30662,
8,
80,
29,
17953,
430,
267,
1613,
11027,
826,
9308,
4359,
9,
398,
327,
27507,
7568,
5759,
14,
267,
6364,
1897,
275,
291,
59,
16,
61,
267,
7568,
63,
3664,
275,
6364,
1897,
14,
6688,
63,
3664,
267,
291,
14,
2683,
63,
6688,
63,
3664,
8,
288,
2400,
859,
12,
315,
3131,
734,
10388,
7568,
63,
3664,
8,
795,
1897,
12,
315,
3131,
734,
4602,
267,
776,
267,
6364,
1897,
14,
6688,
63,
3664,
63,
2479,
14,
2168,
342,
339,
768,
1829,
272,
347,
5401,
8,
277,
304,
267,
408,
267,
1432,
5401,
402,
7798,
4045,
446,
4346,
367,
13318,
16657,
11759,
14,
267,
408,
267,
372,
291,
59,
16,
1055,
3463,
339,
347,
7568,
8,
277,
12,
1324,
63,
3128,
304,
267,
1072,
63,
3128,
275,
1613,
1252,
6688,
8,
1210,
63,
3128,
9,
267,
372,
1072,
63,
3128,
421,
199,
3,
3001,
375,
199,
3,
603,
9257,
7220,
199,
3,
3001,
375,
421,
199,
533,
5311,
2501,
5653,
4491,
8,
4411,
14,
2377,
304,
272,
768,
1829,
272,
347,
512,
31117,
8,
277,
304,
267,
340,
291,
423,
3885,
63,
331,
31117,
26,
288,
372,
359,
77,
14,
331,
31117,
14,
84,
342,
367,
333,
315,
291,
14,
7764,
63,
4421,
63,
3112,
61,
267,
587,
26,
288,
372,
942,
339,
347,
7568,
8,
277,
12,
671,
304,
267,
340,
298,
3179,
2,
315,
291,
423,
3112,
26,
288,
671,
275,
291,
14,
3179,
8,
88,
9,
267,
671,
275,
291,
14,
14720,
8,
88,
9,
267,
372,
671,
339,
347,
4205,
63,
426,
2501,
5653,
8,
277,
304,
267,
291,
423,
3885,
63,
331,
31117,
275,
715,
267,
291,
14,
4998,
8,
826,
63,
331,
12312,
63,
14428,
9,
421,
199,
533,
603,
9257,
1966,
66,
8,
1966,
2501,
5653,
4491,
304,
272,
408,
3184,
650,
8752,
9393,
435,
1072,
603,
9257,
624,
339,
347,
636,
826,
721,
277,
12,
1101,
29,
403,
304,
267,
1613,
11027,
826,
4533,
398,
4243,
275,
1211,
8,
288,
2243,
628,
3541,
401,
288,
1324,
63,
890,
29,
28394,
12,
288,
1967,
63,
2888,
29,
709,
12,
288,
8752,
63,
7723,
1524,
1960,
12,
2948,
12,
2948,
467,
288,
8878,
63,
265,
63,
75,
63,
2676,
1372,
1524,
17,
14,
16,
12,
413,
14,
16,
12,
413,
14,
16,
467,
288,
20198,
63,
21049,
1524,
17,
14,
20,
12,
413,
14,
20,
12,
413,
14,
20,
467,
288,
20198,
63,
21049,
63,
4778,
1524,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
467,
288,
3522,
63,
4791,
29,
797,
12,
288,
19795,
29,
797,
12,
288,
10671,
29,
549,
12,
288,
1022,
63,
20580,
63,
4778,
29,
17,
14,
16,
12,
267,
776,
267,
702,
334,
288,
1101,
365,
488,
503,
298,
1180,
63,
829,
262,
8715,
2,
440,
315,
1101,
267,
2318,
298,
1180,
63,
829,
262,
8715,
365,
5906,
2,
398,
4243,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
markYoungH/chromium.src
|
tools/telemetry/telemetry/unittest_util/run_tests_unittest.py
|
21
|
3310
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
from telemetry.core import util
from telemetry.unittest_util import run_tests
class MockArgs(object):
def __init__(self):
self.positional_args = []
self.exact_test_filter = True
self.run_disabled_tests = False
class MockPossibleBrowser(object):
def __init__(self, browser_type, os_name, os_version_name,
supports_tab_control):
self.browser_type = browser_type
self.platform = MockPlatform(os_name, os_version_name)
self.supports_tab_control = supports_tab_control
class MockPlatform(object):
def __init__(self, os_name, os_version_name):
self.os_name = os_name
self.os_version_name = os_version_name
def GetOSName(self):
return self.os_name
def GetOSVersionName(self):
return self.os_version_name
class RunTestsUnitTest(unittest.TestCase):
def _GetEnabledTests(self, browser_type, os_name, os_version_name,
supports_tab_control):
runner = run_tests.typ.Runner()
host = runner.host
runner.top_level_dir = util.GetTelemetryDir()
runner.args.tests = [host.join(util.GetTelemetryDir(),
'telemetry', 'unittest_util', 'disabled_cases.py')]
possible_browser = MockPossibleBrowser(
browser_type, os_name, os_version_name, supports_tab_control)
runner.classifier = run_tests.GetClassifier(MockArgs(), possible_browser)
_, test_set = runner.find_tests(runner.args)
return set(test.name.split('.')[-1] for test in test_set.parallel_tests)
def testSystemMacMavericks(self):
self.assertEquals(
set(['testAllEnabled',
'testMacOnly',
'testMavericksOnly',
'testNoChromeOS',
'testNoWinLinux',
'testSystemOnly',
'testHasTabs']),
self._GetEnabledTests('system', 'mac', 'mavericks', True))
def testSystemMacLion(self):
self.assertEquals(
set(['testAllEnabled',
'testMacOnly',
'testNoChromeOS',
'testNoMavericks',
'testNoWinLinux',
'testSystemOnly',
'testHasTabs']),
self._GetEnabledTests('system', 'mac', 'lion', True))
def testCrosGuestChromeOS(self):
self.assertEquals(
set(['testAllEnabled',
'testChromeOSOnly',
'testNoMac',
'testNoMavericks',
'testNoSystem',
'testNoWinLinux',
'testHasTabs']),
self._GetEnabledTests('cros-guest', 'chromeos', '', True))
def testCanaryWindowsWin7(self):
self.assertEquals(
set(['testAllEnabled',
'testNoChromeOS',
'testNoMac',
'testNoMavericks',
'testNoSystem',
'testWinOrLinuxOnly',
'testHasTabs']),
self._GetEnabledTests('canary', 'win', 'win7', True))
def testDoesntHaveTabs(self):
self.assertEquals(
set(['testAllEnabled',
'testNoChromeOS',
'testNoMac',
'testNoMavericks',
'testNoSystem',
'testWinOrLinuxOnly']),
self._GetEnabledTests('canary', 'win', 'win7', False))
|
bsd-3-clause
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2882,
199,
199,
504,
17298,
14,
1018,
492,
4884,
199,
504,
17298,
14,
2796,
63,
1974,
492,
1255,
63,
2219,
421,
199,
533,
4420,
6213,
8,
785,
304,
523,
347,
636,
826,
721,
277,
304,
272,
291,
14,
17867,
63,
589,
275,
942,
272,
291,
14,
7327,
63,
396,
63,
1541,
275,
715,
272,
291,
14,
1065,
63,
7011,
63,
2219,
275,
756,
421,
199,
533,
4420,
28096,
11930,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
7042,
63,
466,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
12,
2049,
5171,
63,
2902,
63,
2785,
304,
272,
291,
14,
5750,
63,
466,
275,
7042,
63,
466,
272,
291,
14,
3246,
275,
4420,
10397,
8,
736,
63,
354,
12,
747,
63,
1023,
63,
354,
9,
272,
291,
14,
9823,
63,
2902,
63,
2785,
275,
5171,
63,
2902,
63,
2785,
421,
199,
533,
4420,
10397,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
304,
272,
291,
14,
736,
63,
354,
275,
747,
63,
354,
272,
291,
14,
736,
63,
1023,
63,
354,
275,
747,
63,
1023,
63,
354,
819,
347,
2372,
3100,
985,
8,
277,
304,
272,
372,
291,
14,
736,
63,
354,
819,
347,
2372,
3100,
3353,
985,
8,
277,
304,
272,
372,
291,
14,
736,
63,
1023,
63,
354,
421,
199,
533,
3378,
2925,
29037,
8,
2796,
14,
1746,
304,
819,
347,
485,
1002,
6589,
2925,
8,
277,
12,
7042,
63,
466,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
12,
2432,
5171,
63,
2902,
63,
2785,
304,
339,
7876,
275,
1255,
63,
2219,
14,
9749,
14,
7446,
342,
272,
1591,
275,
7876,
14,
1102,
272,
7876,
14,
2119,
63,
1896,
63,
694,
275,
4884,
14,
1002,
24944,
10987,
3567,
342,
272,
7876,
14,
589,
14,
2219,
275,
359,
1102,
14,
904,
8,
1974,
14,
1002,
24944,
10987,
3567,
1062,
267,
283,
15253,
10987,
297,
283,
2796,
63,
1974,
297,
283,
7011,
63,
9403,
14,
647,
5440,
272,
3962,
63,
5750,
275,
4420,
28096,
11930,
8,
267,
7042,
63,
466,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
12,
5171,
63,
2902,
63,
2785,
9,
272,
7876,
14,
14720,
275,
1255,
63,
2219,
14,
1002,
8508,
8,
3346,
6213,
1062,
3962,
63,
5750,
9,
272,
5501,
511,
63,
409,
275,
7876,
14,
1623,
63,
2219,
8,
5933,
14,
589,
9,
272,
372,
663,
8,
396,
14,
354,
14,
1294,
29084,
17,
61,
367,
511,
315,
511,
63,
409,
14,
11887,
63,
2219,
9,
819,
347,
511,
3989,
3399,
11903,
422,
2000,
83,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
3399,
5903,
297,
1467,
283,
396,
11903,
422,
2000,
83,
5903,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
8886,
14091,
297,
1467,
283,
396,
3989,
5903,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2253,
297,
283,
3088,
297,
283,
391,
422,
2000,
83,
297,
715,
430,
819,
347,
511,
3989,
3399,
44,
1636,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
3399,
5903,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
8886,
14091,
297,
1467,
283,
396,
3989,
5903,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2253,
297,
283,
3088,
297,
283,
29025,
297,
715,
430,
819,
347,
511,
35,
4796,
16022,
18083,
3100,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
18083,
3100,
5903,
297,
1467,
283,
396,
1944,
3399,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
3989,
297,
1467,
283,
396,
1944,
8886,
14091,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
20363,
13,
10409,
297,
283,
9887,
736,
297,
3260,
715,
430,
819,
347,
511,
6049,
695,
8647,
8886,
23,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
3399,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
3989,
297,
1467,
283,
396,
8886,
2844,
14091,
5903,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2425,
695,
297,
283,
2676,
297,
283,
2676,
23,
297,
715,
430,
819,
347,
511,
6586,
343,
40,
811,
23085,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
3399,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
3989,
297,
1467,
283,
396,
8886,
2844,
14091,
5903,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2425,
695,
297,
283,
2676,
297,
283,
2676,
23,
297,
756,
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
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2882,
199,
199,
504,
17298,
14,
1018,
492,
4884,
199,
504,
17298,
14,
2796,
63,
1974,
492,
1255,
63,
2219,
421,
199,
533,
4420,
6213,
8,
785,
304,
523,
347,
636,
826,
721,
277,
304,
272,
291,
14,
17867,
63,
589,
275,
942,
272,
291,
14,
7327,
63,
396,
63,
1541,
275,
715,
272,
291,
14,
1065,
63,
7011,
63,
2219,
275,
756,
421,
199,
533,
4420,
28096,
11930,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
7042,
63,
466,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
12,
2049,
5171,
63,
2902,
63,
2785,
304,
272,
291,
14,
5750,
63,
466,
275,
7042,
63,
466,
272,
291,
14,
3246,
275,
4420,
10397,
8,
736,
63,
354,
12,
747,
63,
1023,
63,
354,
9,
272,
291,
14,
9823,
63,
2902,
63,
2785,
275,
5171,
63,
2902,
63,
2785,
421,
199,
533,
4420,
10397,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
304,
272,
291,
14,
736,
63,
354,
275,
747,
63,
354,
272,
291,
14,
736,
63,
1023,
63,
354,
275,
747,
63,
1023,
63,
354,
819,
347,
2372,
3100,
985,
8,
277,
304,
272,
372,
291,
14,
736,
63,
354,
819,
347,
2372,
3100,
3353,
985,
8,
277,
304,
272,
372,
291,
14,
736,
63,
1023,
63,
354,
421,
199,
533,
3378,
2925,
29037,
8,
2796,
14,
1746,
304,
819,
347,
485,
1002,
6589,
2925,
8,
277,
12,
7042,
63,
466,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
12,
2432,
5171,
63,
2902,
63,
2785,
304,
339,
7876,
275,
1255,
63,
2219,
14,
9749,
14,
7446,
342,
272,
1591,
275,
7876,
14,
1102,
272,
7876,
14,
2119,
63,
1896,
63,
694,
275,
4884,
14,
1002,
24944,
10987,
3567,
342,
272,
7876,
14,
589,
14,
2219,
275,
359,
1102,
14,
904,
8,
1974,
14,
1002,
24944,
10987,
3567,
1062,
267,
283,
15253,
10987,
297,
283,
2796,
63,
1974,
297,
283,
7011,
63,
9403,
14,
647,
5440,
272,
3962,
63,
5750,
275,
4420,
28096,
11930,
8,
267,
7042,
63,
466,
12,
747,
63,
354,
12,
747,
63,
1023,
63,
354,
12,
5171,
63,
2902,
63,
2785,
9,
272,
7876,
14,
14720,
275,
1255,
63,
2219,
14,
1002,
8508,
8,
3346,
6213,
1062,
3962,
63,
5750,
9,
272,
5501,
511,
63,
409,
275,
7876,
14,
1623,
63,
2219,
8,
5933,
14,
589,
9,
272,
372,
663,
8,
396,
14,
354,
14,
1294,
29084,
17,
61,
367,
511,
315,
511,
63,
409,
14,
11887,
63,
2219,
9,
819,
347,
511,
3989,
3399,
11903,
422,
2000,
83,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
3399,
5903,
297,
1467,
283,
396,
11903,
422,
2000,
83,
5903,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
8886,
14091,
297,
1467,
283,
396,
3989,
5903,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2253,
297,
283,
3088,
297,
283,
391,
422,
2000,
83,
297,
715,
430,
819,
347,
511,
3989,
3399,
44,
1636,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
3399,
5903,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
8886,
14091,
297,
1467,
283,
396,
3989,
5903,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2253,
297,
283,
3088,
297,
283,
29025,
297,
715,
430,
819,
347,
511,
35,
4796,
16022,
18083,
3100,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
18083,
3100,
5903,
297,
1467,
283,
396,
1944,
3399,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
3989,
297,
1467,
283,
396,
1944,
8886,
14091,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
20363,
13,
10409,
297,
283,
9887,
736,
297,
3260,
715,
430,
819,
347,
511,
6049,
695,
8647,
8886,
23,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
3399,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
3989,
297,
1467,
283,
396,
8886,
2844,
14091,
5903,
297,
1467,
283,
396,
6362,
23085,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2425,
695,
297,
283,
2676,
297,
283,
2676,
23,
297,
715,
430,
819,
347,
511,
6586,
343,
40,
811,
23085,
8,
277,
304,
272,
291,
14,
2947,
8,
267,
663,
2941,
396,
2422,
6589,
297,
1467,
283,
396,
1944,
18083,
3100,
297,
1467,
283,
396,
1944,
3399,
297,
1467,
283,
396,
1944,
11903,
422,
2000,
83,
297,
1467,
283,
396,
1944,
3989,
297,
1467,
283,
396,
8886,
2844,
14091,
5903,
3815,
267,
291,
423,
1002,
6589,
2925,
360,
2425,
695,
297,
283,
2676,
297,
283,
2676,
23,
297,
756,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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py
|
14
|
2269
|
#!/usr/bin/env python
#
# Copyright (c) 2016 Intel Corporation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of works must retain the original copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the original 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 Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this work without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "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 INTEL CORPORATION 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:
# Lin, Wanming <wanming.lin@intel.com>
import unittest
import os
import sys
import commands
import comm
class TestWebAppRun(unittest.TestCase):
def test_run(self):
comm.setUp()
app_name = "helloworld"
pkg_name = "com.example." + app_name.lower()
content = "<a href='http://www.intel.com'>Intel</a>\n</body>"
key = "</body>"
replace_index_list = [key, content]
comm.create(
app_name,
pkg_name,
comm.MODE,
None,
replace_index_list,
self)
if comm.check_app_installed(pkg_name, self):
comm.app_uninstall(pkg_name, self)
comm.run(app_name, self)
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
20619,
11098,
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,
7647,
26,
199,
3,
199,
3,
627,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
199,
3,
257,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
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,
627,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
199,
3,
257,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
3,
9168,
12,
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,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
3,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
260,
29730,
12,
644,
290,
14566,
665,
20444,
14566,
14,
472,
32,
22264,
14,
957,
30,
199,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
3718,
199,
646,
1923,
421,
199,
533,
1379,
5926,
2640,
2540,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1065,
8,
277,
304,
267,
1923,
14,
5996,
342,
267,
1145,
63,
354,
275,
298,
5006,
7617,
2,
267,
5496,
63,
354,
275,
298,
957,
14,
2694,
2122,
435,
1145,
63,
354,
14,
2325,
342,
267,
1564,
275,
3886,
65,
4369,
534,
1014,
921,
1544,
14,
22264,
14,
957,
8423,
27528,
1108,
65,
3072,
78,
1108,
2030,
4335,
267,
790,
275,
15683,
2030,
4335,
267,
3350,
63,
1080,
63,
513,
275,
359,
498,
12,
1564,
61,
267,
1923,
14,
981,
8,
288,
1145,
63,
354,
12,
288,
5496,
63,
354,
12,
288,
1923,
14,
6963,
12,
288,
488,
12,
288,
3350,
63,
1080,
63,
513,
12,
288,
291,
9,
398,
340,
1923,
14,
1074,
63,
571,
63,
7657,
8,
4600,
63,
354,
12,
291,
304,
288,
1923,
14,
571,
63,
19502,
8,
4600,
63,
354,
12,
291,
9,
267,
1923,
14,
1065,
8,
571,
63,
354,
12,
291,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
20619,
11098,
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,
7647,
26,
199,
3,
199,
3,
627,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
199,
3,
257,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
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,
627,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
199,
3,
257,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
3,
9168,
12,
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,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
3,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
260,
29730,
12,
644,
290,
14566,
665,
20444,
14566,
14,
472,
32,
22264,
14,
957,
30,
199,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
3718,
199,
646,
1923,
421,
199,
533,
1379,
5926,
2640,
2540,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1065,
8,
277,
304,
267,
1923,
14,
5996,
342,
267,
1145,
63,
354,
275,
298,
5006,
7617,
2,
267,
5496,
63,
354,
275,
298,
957,
14,
2694,
2122,
435,
1145,
63,
354,
14,
2325,
342,
267,
1564,
275,
3886,
65,
4369,
534,
1014,
921,
1544,
14,
22264,
14,
957,
8423,
27528,
1108,
65,
3072,
78,
1108,
2030,
4335,
267,
790,
275,
15683,
2030,
4335,
267,
3350,
63,
1080,
63,
513,
275,
359,
498,
12,
1564,
61,
267,
1923,
14,
981,
8,
288,
1145,
63,
354,
12,
288,
5496,
63,
354,
12,
288,
1923,
14,
6963,
12,
288,
488,
12,
288,
3350,
63,
1080,
63,
513,
12,
288,
291,
9,
398,
340,
1923,
14,
1074,
63,
571,
63,
7657,
8,
4600,
63,
354,
12,
291,
304,
288,
1923,
14,
571,
63,
19502,
8,
4600,
63,
354,
12,
291,
9,
267,
1923,
14,
1065,
8,
571,
63,
354,
12,
291,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
FrankBie/django-openid-auth
|
django_openid_auth/admin.py
|
2
|
3685
|
# django-openid-auth - OpenID integration for django.contrib.auth
#
# Copyright (C) 2008-2010 Canonical Ltd.
# Copyright (C) 2010 Dave Walker
#
# 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.
#
# 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.
from django.conf import settings
from django.contrib import admin
from django_openid_auth import conf
from django_openid_auth.models import Nonce, Association, UserOpenID
from django_openid_auth.store import DjangoOpenIDStore
class NonceAdmin(admin.ModelAdmin):
list_display = ('server_url', 'timestamp')
actions = ['cleanup_nonces']
def cleanup_nonces(self, request, queryset):
store = DjangoOpenIDStore()
count = store.cleanupNonces()
self.message_user(request, "%d expired nonces removed" % count)
cleanup_nonces.short_description = "Clean up expired nonces"
admin.site.register(Nonce, NonceAdmin)
class AssociationAdmin(admin.ModelAdmin):
list_display = ('server_url', 'assoc_type')
list_filter = ('assoc_type',)
search_fields = ('server_url',)
actions = ['cleanup_associations']
def cleanup_associations(self, request, queryset):
store = DjangoOpenIDStore()
count = store.cleanupAssociations()
self.message_user(request, "%d expired associations removed" % count)
cleanup_associations.short_description = "Clean up expired associations"
admin.site.register(Association, AssociationAdmin)
class UserOpenIDAdmin(admin.ModelAdmin):
list_display = ('user', 'claimed_id')
search_fields = ('claimed_id',)
admin.site.register(UserOpenID, UserOpenIDAdmin)
# Support for allowing openid authentication for /admin (django.contrib.admin)
if conf.USE_AS_ADMIN_LOGIN:
from django.http import HttpResponseRedirect
from django_openid_auth import views
def _openid_login(self, request, error_message='', extra_context=None):
if request.user.is_authenticated():
if not request.user.is_staff:
return views.render_failure(
request, "User %s does not have admin access."
% request.user.username)
return views.render_failure(
request, "Unknown Error: %s" % error_message)
else:
# Redirect to openid login path,
return HttpResponseRedirect(
settings.LOGIN_URL + "?next=" + request.get_full_path())
# Overide the standard admin login form.
admin.sites.AdminSite.display_login_form = _openid_login
|
bsd-2-clause
|
[
3,
1639,
13,
15403,
13,
1178,
446,
221,
25463,
13150,
367,
1639,
14,
2828,
14,
1178,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
13,
6542,
6855,
7174,
12126,
14,
199,
3,
1898,
334,
35,
9,
7129,
577,
811,
644,
14976,
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,
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,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
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,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
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,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
492,
4628,
199,
199,
504,
1639,
63,
15403,
63,
1178,
492,
3743,
199,
504,
1639,
63,
15403,
63,
1178,
14,
992,
492,
653,
5089,
12,
24207,
425,
12,
2876,
30244,
199,
504,
1639,
63,
15403,
63,
1178,
14,
1617,
492,
5634,
30244,
5502,
421,
199,
533,
653,
5089,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
1000,
63,
633,
297,
283,
3954,
358,
272,
5445,
275,
788,
7661,
63,
2865,
823,
418,
339,
347,
9058,
63,
2865,
823,
8,
277,
12,
1056,
12,
7594,
304,
267,
3877,
275,
5634,
30244,
5502,
342,
267,
2338,
275,
3877,
14,
7661,
6932,
823,
342,
267,
291,
14,
1188,
63,
751,
8,
1069,
12,
2071,
68,
14721,
2222,
823,
4829,
2,
450,
2338,
9,
272,
9058,
63,
2865,
823,
14,
3612,
63,
1802,
275,
298,
6580,
1536,
14721,
2222,
823,
2,
199,
199,
2113,
14,
2124,
14,
2683,
8,
46,
5089,
12,
653,
5089,
4880,
9,
421,
199,
533,
24207,
425,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
1000,
63,
633,
297,
283,
16824,
63,
466,
358,
272,
769,
63,
1541,
275,
661,
16824,
63,
466,
9538,
272,
2754,
63,
955,
275,
661,
1000,
63,
633,
9538,
272,
5445,
275,
788,
7661,
63,
32600,
418,
339,
347,
9058,
63,
32600,
8,
277,
12,
1056,
12,
7594,
304,
267,
3877,
275,
5634,
30244,
5502,
342,
267,
2338,
275,
3877,
14,
7661,
14889,
1298,
342,
267,
291,
14,
1188,
63,
751,
8,
1069,
12,
2071,
68,
14721,
4035,
1298,
4829,
2,
450,
2338,
9,
272,
9058,
63,
32600,
14,
3612,
63,
1802,
275,
298,
6580,
1536,
14721,
4035,
1298,
2,
199,
199,
2113,
14,
2124,
14,
2683,
8,
18662,
12,
24207,
425,
4880,
9,
421,
199,
533,
2876,
30244,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
751,
297,
283,
31563,
63,
344,
358,
272,
2754,
63,
955,
275,
661,
31563,
63,
344,
9538,
199,
199,
2113,
14,
2124,
14,
2683,
8,
1899,
30244,
12,
2876,
30244,
4880,
9,
421,
199,
3,
12502,
367,
17266,
24494,
6299,
367,
1182,
2113,
334,
1176,
14,
2828,
14,
2113,
9,
199,
692,
3743,
14,
4701,
63,
1179,
63,
14288,
63,
17208,
26,
272,
687,
1639,
14,
1014,
492,
14935,
272,
687,
1639,
63,
15403,
63,
1178,
492,
6858,
339,
347,
485,
15403,
63,
2886,
8,
277,
12,
1056,
12,
1125,
63,
1188,
4581,
2402,
63,
1100,
29,
403,
304,
267,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
288,
340,
440,
1056,
14,
751,
14,
374,
63,
7018,
26,
355,
372,
6858,
14,
3352,
63,
5328,
8,
490,
1056,
12,
298,
1899,
450,
83,
1630,
440,
1172,
4628,
2879,
2122,
490,
450,
1056,
14,
751,
14,
2473,
9,
288,
372,
6858,
14,
3352,
63,
5328,
8,
355,
1056,
12,
298,
5912,
4520,
26,
450,
83,
2,
450,
1125,
63,
1188,
9,
267,
587,
26,
288,
327,
18532,
370,
24494,
4676,
931,
12,
288,
372,
14935,
8,
355,
2202,
14,
17208,
63,
2632,
435,
23665,
2184,
628,
435,
1056,
14,
362,
63,
2861,
63,
515,
1012,
339,
327,
7259,
2655,
314,
4465,
4628,
4676,
1824,
14,
272,
4628,
14,
8619,
14,
4880,
8972,
14,
2918,
63,
2886,
63,
964,
275,
485,
15403,
63,
2886,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
13,
15403,
13,
1178,
446,
221,
25463,
13150,
367,
1639,
14,
2828,
14,
1178,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
13,
6542,
6855,
7174,
12126,
14,
199,
3,
1898,
334,
35,
9,
7129,
577,
811,
644,
14976,
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,
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,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
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,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
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,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
492,
4628,
199,
199,
504,
1639,
63,
15403,
63,
1178,
492,
3743,
199,
504,
1639,
63,
15403,
63,
1178,
14,
992,
492,
653,
5089,
12,
24207,
425,
12,
2876,
30244,
199,
504,
1639,
63,
15403,
63,
1178,
14,
1617,
492,
5634,
30244,
5502,
421,
199,
533,
653,
5089,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
1000,
63,
633,
297,
283,
3954,
358,
272,
5445,
275,
788,
7661,
63,
2865,
823,
418,
339,
347,
9058,
63,
2865,
823,
8,
277,
12,
1056,
12,
7594,
304,
267,
3877,
275,
5634,
30244,
5502,
342,
267,
2338,
275,
3877,
14,
7661,
6932,
823,
342,
267,
291,
14,
1188,
63,
751,
8,
1069,
12,
2071,
68,
14721,
2222,
823,
4829,
2,
450,
2338,
9,
272,
9058,
63,
2865,
823,
14,
3612,
63,
1802,
275,
298,
6580,
1536,
14721,
2222,
823,
2,
199,
199,
2113,
14,
2124,
14,
2683,
8,
46,
5089,
12,
653,
5089,
4880,
9,
421,
199,
533,
24207,
425,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
1000,
63,
633,
297,
283,
16824,
63,
466,
358,
272,
769,
63,
1541,
275,
661,
16824,
63,
466,
9538,
272,
2754,
63,
955,
275,
661,
1000,
63,
633,
9538,
272,
5445,
275,
788,
7661,
63,
32600,
418,
339,
347,
9058,
63,
32600,
8,
277,
12,
1056,
12,
7594,
304,
267,
3877,
275,
5634,
30244,
5502,
342,
267,
2338,
275,
3877,
14,
7661,
14889,
1298,
342,
267,
291,
14,
1188,
63,
751,
8,
1069,
12,
2071,
68,
14721,
4035,
1298,
4829,
2,
450,
2338,
9,
272,
9058,
63,
32600,
14,
3612,
63,
1802,
275,
298,
6580,
1536,
14721,
4035,
1298,
2,
199,
199,
2113,
14,
2124,
14,
2683,
8,
18662,
12,
24207,
425,
4880,
9,
421,
199,
533,
2876,
30244,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
751,
297,
283,
31563,
63,
344,
358,
272,
2754,
63,
955,
275,
661,
31563,
63,
344,
9538,
199,
199,
2113,
14,
2124,
14,
2683,
8,
1899,
30244,
12,
2876,
30244,
4880,
9,
421,
199,
3,
12502,
367,
17266,
24494,
6299,
367,
1182,
2113,
334,
1176,
14,
2828,
14,
2113,
9,
199,
692,
3743,
14,
4701,
63,
1179,
63,
14288,
63,
17208,
26,
272,
687,
1639,
14,
1014,
492,
14935,
272,
687,
1639,
63,
15403,
63,
1178,
492,
6858,
339,
347,
485,
15403,
63,
2886,
8,
277,
12,
1056,
12,
1125,
63,
1188,
4581,
2402,
63,
1100,
29,
403,
304,
267,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
288,
340,
440,
1056,
14,
751,
14,
374,
63,
7018,
26,
355,
372,
6858,
14,
3352,
63,
5328,
8,
490,
1056,
12,
298,
1899,
450,
83,
1630,
440,
1172,
4628,
2879,
2122,
490,
450,
1056,
14,
751,
14,
2473,
9,
288,
372,
6858,
14,
3352,
63,
5328,
8,
355,
1056,
12,
298,
5912,
4520,
26,
450,
83,
2,
450,
1125,
63,
1188,
9,
267,
587,
26,
288,
327,
18532,
370,
24494,
4676,
931,
12,
288,
372,
14935,
8,
355,
2202,
14,
17208,
63,
2632,
435,
23665,
2184,
628,
435,
1056,
14,
362,
63,
2861,
63,
515,
1012,
339,
327,
7259,
2655,
314,
4465,
4628,
4676,
1824,
14,
272,
4628,
14,
8619,
14,
4880,
8972,
14,
2918,
63,
2886,
63,
964,
275,
485,
15403,
63,
2886,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
slowfranklin/samba
|
python/samba/netcmd/dns.py
|
25
|
48747
|
# DNS management tool
#
# Copyright (C) Amitay Isaacs 2011-2012
#
# 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 samba.getopt as options
from struct import pack
from socket import inet_ntoa
from socket import inet_ntop
from socket import AF_INET
from socket import AF_INET6
import shlex
from samba.netcmd import (
Command,
CommandError,
Option,
SuperCommand,
)
from samba.dcerpc import dnsp, dnsserver
def dns_connect(server, lp, creds):
if server.lower() == 'localhost':
server = '127.0.0.1'
binding_str = "ncacn_ip_tcp:%s[sign]" % server
dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
return dns_conn
def bool_string(flag):
if flag == 0:
ret = 'FALSE'
elif flag == 1:
ret = 'TRUE'
else:
ret = 'UNKNOWN (0x%x)' % flag
return ret
def enum_string(module, enum_defs, value):
ret = None
for e in enum_defs:
if value == getattr(module, e):
ret = e
break
if not ret:
ret = 'UNKNOWN (0x%x)' % value
return ret
def bitmap_string(module, bitmap_defs, value):
ret = ''
for b in bitmap_defs:
if value & getattr(module, b):
ret += '%s ' % b
if not ret:
ret = 'NONE'
return ret
def boot_method_string(boot_method):
enum_defs = [ 'DNS_BOOT_METHOD_UNINITIALIZED', 'DNS_BOOT_METHOD_FILE',
'DNS_BOOT_METHOD_REGISTRY', 'DNS_BOOT_METHOD_DIRECTORY' ]
return enum_string(dnsserver, enum_defs, boot_method)
def name_check_flag_string(check_flag):
enum_defs = [ 'DNS_ALLOW_RFC_NAMES_ONLY', 'DNS_ALLOW_NONRFC_NAMES',
'DNS_ALLOW_MULTIBYTE_NAMES', 'DNS_ALLOW_ALL_NAMES' ]
return enum_string(dnsserver, enum_defs, check_flag)
def zone_type_string(zone_type):
enum_defs = [ 'DNS_ZONE_TYPE_CACHE', 'DNS_ZONE_TYPE_PRIMARY',
'DNS_ZONE_TYPE_SECONDARY', 'DNS_ZONE_TYPE_STUB',
'DNS_ZONE_TYPE_FORWARDER', 'DNS_ZONE_TYPE_SECONDARY_CACHE' ]
return enum_string(dnsp, enum_defs, zone_type)
def zone_update_string(zone_update):
enum_defs = [ 'DNS_ZONE_UPDATE_OFF', 'DNS_ZONE_UPDATE_UNSECURE',
'DNS_ZONE_UPDATE_SECURE' ]
return enum_string(dnsp, enum_defs, zone_update)
def zone_secondary_security_string(security):
enum_defs = [ 'DNS_ZONE_SECSECURE_NO_SECURITY', 'DNS_ZONE_SECSECURE_NS_ONLY',
'DNS_ZONE_SECSECURE_LIST_ONLY', 'DNS_ZONE_SECSECURE_NO_XFER' ]
return enum_string(dnsserver, enum_defs, security)
def zone_notify_level_string(notify_level):
enum_defs = [ 'DNS_ZONE_NOTIFY_OFF', 'DNS_ZONE_NOTIFY_ALL_SECONDARIES',
'DNS_ZONE_NOTIFY_LIST_ONLY' ]
return enum_string(dnsserver, enum_defs, notify_level)
def dp_flags_string(dp_flags):
bitmap_defs = [ 'DNS_DP_AUTOCREATED', 'DNS_DP_LEGACY', 'DNS_DP_DOMAIN_DEFAULT',
'DNS_DP_FOREST_DEFAULT', 'DNS_DP_ENLISTED', 'DNS_DP_DELETED' ]
return bitmap_string(dnsserver, bitmap_defs, dp_flags)
def zone_flags_string(flags):
bitmap_defs = [ 'DNS_RPC_ZONE_PAUSED', 'DNS_RPC_ZONE_SHUTDOWN',
'DNS_RPC_ZONE_REVERSE', 'DNS_RPC_ZONE_AUTOCREATED',
'DNS_RPC_ZONE_DSINTEGRATED', 'DNS_RPC_ZONE_AGING',
'DNS_RPC_ZONE_UPDATE_UNSECURE', 'DNS_RPC_ZONE_UPDATE_SECURE',
'DNS_RPC_ZONE_READONLY']
return bitmap_string(dnsserver, bitmap_defs, flags)
def ip4_array_string(array):
ret = []
if not array:
return ret
for i in xrange(array.AddrCount):
addr = inet_ntop(AF_INET, pack('I', array.AddrArray[i]))
ret.append(addr)
return ret
def dns_addr_array_string(array):
ret = []
if not array:
return ret
for i in xrange(array.AddrCount):
if array.AddrArray[i].MaxSa[0] == 0x02:
x = "".join([chr(b) for b in array.AddrArray[i].MaxSa])[4:8]
addr = inet_ntop(AF_INET, x)
elif array.AddrArray[i].MaxSa[0] == 0x17:
x = "".join([chr(b) for b in array.AddrArray[i].MaxSa])[8:24]
addr = inet_ntop(AF_INET6, x)
else:
addr = 'UNKNOWN'
ret.append(addr)
return ret
def dns_type_flag(rec_type):
rtype = rec_type.upper()
if rtype == 'A':
record_type = dnsp.DNS_TYPE_A
elif rtype == 'AAAA':
record_type = dnsp.DNS_TYPE_AAAA
elif rtype == 'PTR':
record_type = dnsp.DNS_TYPE_PTR
elif rtype == 'NS':
record_type = dnsp.DNS_TYPE_NS
elif rtype == 'CNAME':
record_type = dnsp.DNS_TYPE_CNAME
elif rtype == 'SOA':
record_type = dnsp.DNS_TYPE_SOA
elif rtype == 'MX':
record_type = dnsp.DNS_TYPE_MX
elif rtype == 'SRV':
record_type = dnsp.DNS_TYPE_SRV
elif rtype == 'TXT':
record_type = dnsp.DNS_TYPE_TXT
elif rtype == 'ALL':
record_type = dnsp.DNS_TYPE_ALL
else:
raise CommandError('Unknown type of DNS record %s' % rec_type)
return record_type
def dns_client_version(cli_version):
version = cli_version.upper()
if version == 'W2K':
client_version = dnsserver.DNS_CLIENT_VERSION_W2K
elif version == 'DOTNET':
client_version = dnsserver.DNS_CLIENT_VERSION_DOTNET
elif version == 'LONGHORN':
client_version = dnsserver.DNS_CLIENT_VERSION_LONGHORN
else:
raise CommandError('Unknown client version %s' % cli_version)
return client_version
def print_serverinfo(outf, typeid, serverinfo):
outf.write(' dwVersion : 0x%x\n' % serverinfo.dwVersion)
outf.write(' fBootMethod : %s\n' % boot_method_string(serverinfo.fBootMethod))
outf.write(' fAdminConfigured : %s\n' % bool_string(serverinfo.fAdminConfigured))
outf.write(' fAllowUpdate : %s\n' % bool_string(serverinfo.fAllowUpdate))
outf.write(' fDsAvailable : %s\n' % bool_string(serverinfo.fDsAvailable))
outf.write(' pszServerName : %s\n' % serverinfo.pszServerName)
outf.write(' pszDsContainer : %s\n' % serverinfo.pszDsContainer)
if typeid != dnsserver.DNSSRV_TYPEID_SERVER_INFO:
outf.write(' aipServerAddrs : %s\n' %
ip4_array_string(serverinfo.aipServerAddrs))
outf.write(' aipListenAddrs : %s\n' %
ip4_array_string(serverinfo.aipListenAddrs))
outf.write(' aipForwarders : %s\n' %
ip4_array_string(serverinfo.aipForwarders))
else:
outf.write(' aipServerAddrs : %s\n' %
dns_addr_array_string(serverinfo.aipServerAddrs))
outf.write(' aipListenAddrs : %s\n' %
dns_addr_array_string(serverinfo.aipListenAddrs))
outf.write(' aipForwarders : %s\n' %
dns_addr_array_string(serverinfo.aipForwarders))
outf.write(' dwLogLevel : %d\n' % serverinfo.dwLogLevel)
outf.write(' dwDebugLevel : %d\n' % serverinfo.dwDebugLevel)
outf.write(' dwForwardTimeout : %d\n' % serverinfo.dwForwardTimeout)
outf.write(' dwRpcPrototol : 0x%x\n' % serverinfo.dwRpcProtocol)
outf.write(' dwNameCheckFlag : %s\n' % name_check_flag_string(serverinfo.dwNameCheckFlag))
outf.write(' cAddressAnswerLimit : %d\n' % serverinfo.cAddressAnswerLimit)
outf.write(' dwRecursionRetry : %d\n' % serverinfo.dwRecursionRetry)
outf.write(' dwRecursionTimeout : %d\n' % serverinfo.dwRecursionTimeout)
outf.write(' dwMaxCacheTtl : %d\n' % serverinfo.dwMaxCacheTtl)
outf.write(' dwDsPollingInterval : %d\n' % serverinfo.dwDsPollingInterval)
outf.write(' dwScavengingInterval : %d\n' % serverinfo.dwScavengingInterval)
outf.write(' dwDefaultRefreshInterval : %d\n' % serverinfo.dwDefaultRefreshInterval)
outf.write(' dwDefaultNoRefreshInterval : %d\n' % serverinfo.dwDefaultNoRefreshInterval)
outf.write(' fAutoReverseZones : %s\n' % bool_string(serverinfo.fAutoReverseZones))
outf.write(' fAutoCacheUpdate : %s\n' % bool_string(serverinfo.fAutoCacheUpdate))
outf.write(' fRecurseAfterForwarding : %s\n' % bool_string(serverinfo.fRecurseAfterForwarding))
outf.write(' fForwardDelegations : %s\n' % bool_string(serverinfo.fForwardDelegations))
outf.write(' fNoRecursion : %s\n' % bool_string(serverinfo.fNoRecursion))
outf.write(' fSecureResponses : %s\n' % bool_string(serverinfo.fSecureResponses))
outf.write(' fRoundRobin : %s\n' % bool_string(serverinfo.fRoundRobin))
outf.write(' fLocalNetPriority : %s\n' % bool_string(serverinfo.fLocalNetPriority))
outf.write(' fBindSecondaries : %s\n' % bool_string(serverinfo.fBindSecondaries))
outf.write(' fWriteAuthorityNs : %s\n' % bool_string(serverinfo.fWriteAuthorityNs))
outf.write(' fStrictFileParsing : %s\n' % bool_string(serverinfo.fStrictFileParsing))
outf.write(' fLooseWildcarding : %s\n' % bool_string(serverinfo.fLooseWildcarding))
outf.write(' fDefaultAgingState : %s\n' % bool_string(serverinfo.fDefaultAgingState))
if typeid != dnsserver.DNSSRV_TYPEID_SERVER_INFO_W2K:
outf.write(' dwRpcStructureVersion : 0x%x\n' % serverinfo.dwRpcStructureVersion)
outf.write(' aipLogFilter : %s\n' % dns_addr_array_string(serverinfo.aipLogFilter))
outf.write(' pwszLogFilePath : %s\n' % serverinfo.pwszLogFilePath)
outf.write(' pszDomainName : %s\n' % serverinfo.pszDomainName)
outf.write(' pszForestName : %s\n' % serverinfo.pszForestName)
outf.write(' pszDomainDirectoryPartition : %s\n' % serverinfo.pszDomainDirectoryPartition)
outf.write(' pszForestDirectoryPartition : %s\n' % serverinfo.pszForestDirectoryPartition)
outf.write(' dwLocalNetPriorityNetMask : 0x%x\n' % serverinfo.dwLocalNetPriorityNetMask)
outf.write(' dwLastScavengeTime : %d\n' % serverinfo.dwLastScavengeTime)
outf.write(' dwEventLogLevel : %d\n' % serverinfo.dwEventLogLevel)
outf.write(' dwLogFileMaxSize : %d\n' % serverinfo.dwLogFileMaxSize)
outf.write(' dwDsForestVersion : %d\n' % serverinfo.dwDsForestVersion)
outf.write(' dwDsDomainVersion : %d\n' % serverinfo.dwDsDomainVersion)
outf.write(' dwDsDsaVersion : %d\n' % serverinfo.dwDsDsaVersion)
if typeid == dnsserver.DNSSRV_TYPEID_SERVER_INFO:
outf.write(' fReadOnlyDC : %s\n' % bool_string(serverinfo.fReadOnlyDC))
def print_zoneinfo(outf, typeid, zoneinfo):
outf.write(' pszZoneName : %s\n' % zoneinfo.pszZoneName)
outf.write(' dwZoneType : %s\n' % zone_type_string(zoneinfo.dwZoneType))
outf.write(' fReverse : %s\n' % bool_string(zoneinfo.fReverse))
outf.write(' fAllowUpdate : %s\n' % zone_update_string(zoneinfo.fAllowUpdate))
outf.write(' fPaused : %s\n' % bool_string(zoneinfo.fPaused))
outf.write(' fShutdown : %s\n' % bool_string(zoneinfo.fShutdown))
outf.write(' fAutoCreated : %s\n' % bool_string(zoneinfo.fAutoCreated))
outf.write(' fUseDatabase : %s\n' % bool_string(zoneinfo.fUseDatabase))
outf.write(' pszDataFile : %s\n' % zoneinfo.pszDataFile)
if typeid != dnsserver.DNSSRV_TYPEID_ZONE_INFO:
outf.write(' aipMasters : %s\n' %
ip4_array_string(zoneinfo.aipMasters))
else:
outf.write(' aipMasters : %s\n' %
dns_addr_array_string(zoneinfo.aipMasters))
outf.write(' fSecureSecondaries : %s\n' % zone_secondary_security_string(zoneinfo.fSecureSecondaries))
outf.write(' fNotifyLevel : %s\n' % zone_notify_level_string(zoneinfo.fNotifyLevel))
if typeid != dnsserver.DNSSRV_TYPEID_ZONE_INFO:
outf.write(' aipSecondaries : %s\n' %
ip4_array_string(zoneinfo.aipSecondaries))
outf.write(' aipNotify : %s\n' %
ip4_array_string(zoneinfo.aipNotify))
else:
outf.write(' aipSecondaries : %s\n' %
dns_addr_array_string(zoneinfo.aipSecondaries))
outf.write(' aipNotify : %s\n' %
dns_addr_array_string(zoneinfo.aipNotify))
outf.write(' fUseWins : %s\n' % bool_string(zoneinfo.fUseWins))
outf.write(' fUseNbstat : %s\n' % bool_string(zoneinfo.fUseNbstat))
outf.write(' fAging : %s\n' % bool_string(zoneinfo.fAging))
outf.write(' dwNoRefreshInterval : %d\n' % zoneinfo.dwNoRefreshInterval)
outf.write(' dwRefreshInterval : %d\n' % zoneinfo.dwRefreshInterval)
outf.write(' dwAvailForScavengeTime : %d\n' % zoneinfo.dwAvailForScavengeTime)
if typeid != dnsserver.DNSSRV_TYPEID_ZONE_INFO:
outf.write(' aipScavengeServers : %s\n' %
ip4_array_string(zoneinfo.aipScavengeServers))
else:
outf.write(' aipScavengeServers : %s\n' %
dns_addr_array_string(zoneinfo.aipScavengeServers))
if typeid != dnsserver.DNSSRV_TYPEID_ZONE_INFO_W2K:
outf.write(' dwRpcStructureVersion : 0x%x\n' % zoneinfo.dwRpcStructureVersion)
outf.write(' dwForwarderTimeout : %d\n' % zoneinfo.dwForwarderTimeout)
outf.write(' fForwarderSlave : %d\n' % zoneinfo.fForwarderSlave)
if typeid != dnsserver.DNSSRV_TYPEID_ZONE_INFO:
outf.write(' aipLocalMasters : %s\n' %
ip4_array_string(zoneinfo.aipLocalMasters))
else:
outf.write(' aipLocalMasters : %s\n' %
dns_addr_array_string(zoneinfo.aipLocalMasters))
outf.write(' dwDpFlags : %s\n' % dp_flags_string(zoneinfo.dwDpFlags))
outf.write(' pszDpFqdn : %s\n' % zoneinfo.pszDpFqdn)
outf.write(' pwszZoneDn : %s\n' % zoneinfo.pwszZoneDn)
outf.write(' dwLastSuccessfulSoaCheck : %d\n' % zoneinfo.dwLastSuccessfulSoaCheck)
outf.write(' dwLastSuccessfulXfr : %d\n' % zoneinfo.dwLastSuccessfulXfr)
if typeid == dnsserver.DNSSRV_TYPEID_ZONE_INFO:
outf.write(' fQueuedForBackgroundLoad : %s\n' % bool_string(zoneinfo.fQueuedForBackgroundLoad))
outf.write(' fBackgroundLoadInProgress : %s\n' % bool_string(zoneinfo.fBackgroundLoadInProgress))
outf.write(' fReadOnlyZone : %s\n' % bool_string(zoneinfo.fReadOnlyZone))
outf.write(' dwLastXfrAttempt : %d\n' % zoneinfo.dwLastXfrAttempt)
outf.write(' dwLastXfrResult : %d\n' % zoneinfo.dwLastXfrResult)
def print_zone(outf, typeid, zone):
outf.write(' pszZoneName : %s\n' % zone.pszZoneName)
outf.write(' Flags : %s\n' % zone_flags_string(zone.Flags))
outf.write(' ZoneType : %s\n' % zone_type_string(zone.ZoneType))
outf.write(' Version : %s\n' % zone.Version)
if typeid != dnsserver.DNSSRV_TYPEID_ZONE_W2K:
outf.write(' dwDpFlags : %s\n' % dp_flags_string(zone.dwDpFlags))
outf.write(' pszDpFqdn : %s\n' % zone.pszDpFqdn)
def print_enumzones(outf, typeid, zones):
outf.write(' %d zone(s) found\n' % zones.dwZoneCount)
for zone in zones.ZoneArray:
outf.write('\n')
print_zone(outf, typeid, zone)
def print_dns_record(outf, rec):
if rec.wType == dnsp.DNS_TYPE_A:
mesg = 'A: %s' % (rec.data)
elif rec.wType == dnsp.DNS_TYPE_AAAA:
mesg = 'AAAA: %s' % (rec.data)
elif rec.wType == dnsp.DNS_TYPE_PTR:
mesg = 'PTR: %s' % (rec.data.str)
elif rec.wType == dnsp.DNS_TYPE_NS:
mesg = 'NS: %s' % (rec.data.str)
elif rec.wType == dnsp.DNS_TYPE_CNAME:
mesg = 'CNAME: %s' % (rec.data.str)
elif rec.wType == dnsp.DNS_TYPE_SOA:
mesg = 'SOA: serial=%d, refresh=%d, retry=%d, expire=%d, minttl=%d, ns=%s, email=%s' % (
rec.data.dwSerialNo,
rec.data.dwRefresh,
rec.data.dwRetry,
rec.data.dwExpire,
rec.data.dwMinimumTtl,
rec.data.NamePrimaryServer.str,
rec.data.ZoneAdministratorEmail.str)
elif rec.wType == dnsp.DNS_TYPE_MX:
mesg = 'MX: %s (%d)' % (rec.data.nameExchange.str, rec.data.wPreference)
elif rec.wType == dnsp.DNS_TYPE_SRV:
mesg = 'SRV: %s (%d, %d, %d)' % (rec.data.nameTarget.str, rec.data.wPort,
rec.data.wPriority, rec.data.wWeight)
elif rec.wType == dnsp.DNS_TYPE_TXT:
slist = ['"%s"' % name.str for name in rec.data.str]
mesg = 'TXT: %s' % ','.join(slist)
else:
mesg = 'Unknown: '
outf.write(' %s (flags=%x, serial=%d, ttl=%d)\n' % (
mesg, rec.dwFlags, rec.dwSerial, rec.dwTtlSeconds))
def print_dnsrecords(outf, records):
for rec in records.rec:
outf.write(' Name=%s, Records=%d, Children=%d\n' % (
rec.dnsNodeName.str,
rec.wRecordCount,
rec.dwChildCount))
for dns_rec in rec.records:
print_dns_record(outf, dns_rec)
#
# Always create a copy of strings when creating DNS_RPC_RECORDs
# to overcome the bug in pidl generated python bindings.
#
class ARecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, ip_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(ARecord, self).__init__()
self.wType = dnsp.DNS_TYPE_A
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._ip_addr = ip_addr[:]
self.data = self._ip_addr
class AAAARecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, ip6_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(AAAARecord, self).__init__()
self.wType = dnsp.DNS_TYPE_AAAA
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._ip6_addr = ip6_addr[:]
self.data = self._ip6_addr
class PTRRecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, ptr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(PTRRecord, self).__init__()
self.wType = dnsp.DNS_TYPE_PTR
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._ptr = ptr[:]
ptr_name = dnsserver.DNS_RPC_NAME()
ptr_name.str = self._ptr
ptr_name.len = len(ptr)
self.data = ptr_name
class CNameRecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, cname, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(CNameRecord, self).__init__()
self.wType = dnsp.DNS_TYPE_CNAME
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._cname = cname[:]
cname_name = dnsserver.DNS_RPC_NAME()
cname_name.str = self._cname
cname_name.len = len(cname)
self.data = cname_name
class NSRecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, dns_server, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(NSRecord, self).__init__()
self.wType = dnsp.DNS_TYPE_NS
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._dns_server = dns_server[:]
ns = dnsserver.DNS_RPC_NAME()
ns.str = self._dns_server
ns.len = len(dns_server)
self.data = ns
class MXRecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, mail_server, preference, serial=1, ttl=900,
rank=dnsp.DNS_RANK_ZONE, node_flag=0):
super(MXRecord, self).__init__()
self.wType = dnsp.DNS_TYPE_MX
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._mail_server = mail_server[:]
mx = dnsserver.DNS_RPC_RECORD_NAME_PREFERENCE()
mx.wPreference = preference
mx.nameExchange.str = self._mail_server
mx.nameExchange.len = len(mail_server)
self.data = mx
class SOARecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, mname, rname, serial=1, refresh=900, retry=600,
expire=86400, minimum=3600, ttl=3600, rank=dnsp.DNS_RANK_ZONE,
node_flag=dnsp.DNS_RPC_FLAG_AUTH_ZONE_ROOT):
super(SOARecord, self).__init__()
self.wType = dnsp.DNS_TYPE_SOA
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._mname = mname[:]
self._rname = rname[:]
soa = dnsserver.DNS_RPC_RECORD_SOA()
soa.dwSerialNo = serial
soa.dwRefresh = refresh
soa.dwRetry = retry
soa.dwExpire = expire
soa.dwMinimumTtl = minimum
soa.NamePrimaryServer.str = self._mname
soa.NamePrimaryServer.len = len(mname)
soa.ZoneAdministratorEmail.str = self._rname
soa.ZoneAdministratorEmail.len = len(rname)
self.data = soa
class SRVRecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, target, port, priority=0, weight=100, serial=1, ttl=900,
rank=dnsp.DNS_RANK_ZONE, node_flag=0):
super(SRVRecord, self).__init__()
self.wType = dnsp.DNS_TYPE_SRV
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._target = target[:]
srv = dnsserver.DNS_RPC_RECORD_SRV()
srv.wPriority = priority
srv.wWeight = weight
srv.wPort = port
srv.nameTarget.str = self._target
srv.nameTarget.len = len(target)
self.data = srv
class TXTRecord(dnsserver.DNS_RPC_RECORD):
def __init__(self, slist, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(TXTRecord, self).__init__()
self.wType = dnsp.DNS_TYPE_TXT
self.dwFlags = rank | node_flag
self.dwSerial = serial
self.dwTtlSeconds = ttl
self._slist = []
for s in slist:
self._slist.append(s[:])
names = []
for s in self._slist:
name = dnsserver.DNS_RPC_NAME()
name.str = s
name.len = len(s)
names.append(name)
txt = dnsserver.DNS_RPC_RECORD_STRING()
txt.count = len(slist)
txt.str = names
self.data = txt
# Convert data into a dns record
def data_to_dns_record(record_type, data):
if record_type == dnsp.DNS_TYPE_A:
rec = ARecord(data)
elif record_type == dnsp.DNS_TYPE_AAAA:
rec = AAAARecord(data)
elif record_type == dnsp.DNS_TYPE_PTR:
rec = PTRRecord(data)
elif record_type == dnsp.DNS_TYPE_CNAME:
rec = CNameRecord(data)
elif record_type == dnsp.DNS_TYPE_NS:
rec = NSRecord(data)
elif record_type == dnsp.DNS_TYPE_MX:
tmp = data.split(' ')
if len(tmp) != 2:
raise CommandError('Data requires 2 elements - mail_server, preference')
mail_server = tmp[0]
preference = int(tmp[1])
rec = MXRecord(mail_server, preference)
elif record_type == dnsp.DNS_TYPE_SRV:
tmp = data.split(' ')
if len(tmp) != 4:
raise CommandError('Data requires 4 elements - server, port, priority, weight')
server = tmp[0]
port = int(tmp[1])
priority = int(tmp[2])
weight = int(tmp[3])
rec = SRVRecord(server, port, priority=priority, weight=weight)
elif record_type == dnsp.DNS_TYPE_SOA:
tmp = data.split(' ')
if len(tmp) != 7:
raise CommandError('Data requires 7 elements - nameserver, email, serial, '
'refresh, retry, expire, minimumttl')
nameserver = tmp[0]
email = tmp[1]
serial = int(tmp[2])
refresh = int(tmp[3])
retry = int(tmp[4])
expire = int(tmp[5])
minimum = int(tmp[6])
rec = SOARecord(nameserver, email, serial=serial, refresh=refresh,
retry=retry, expire=expire, minimum=minimum)
elif record_type == dnsp.DNS_TYPE_TXT:
slist = shlex.split(data)
rec = TXTRecord(slist)
else:
raise CommandError('Unsupported record type')
return rec
# Match dns name (of type DNS_RPC_NAME)
def dns_name_equal(n1, n2):
return n1.str.rstrip('.').lower() == n2.str.rstrip('.').lower()
# Match a dns record with specified data
def dns_record_match(dns_conn, server, zone, name, record_type, data):
urec = data_to_dns_record(record_type, data)
select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA
try:
buflen, res = dns_conn.DnssrvEnumRecords2(
dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name, None,
record_type, select_flags, None, None)
except RuntimeError, e:
return None
if not res or res.count == 0:
return None
rec_match = None
for rec in res.rec[0].records:
if rec.wType != record_type:
continue
found = False
if record_type == dnsp.DNS_TYPE_A:
if rec.data == urec.data:
found = True
elif record_type == dnsp.DNS_TYPE_AAAA:
if rec.data == urec.data:
found = True
elif record_type == dnsp.DNS_TYPE_PTR:
if dns_name_equal(rec.data, urec.data):
found = True
elif record_type == dnsp.DNS_TYPE_CNAME:
if dns_name_equal(rec.data, urec.data):
found = True
elif record_type == dnsp.DNS_TYPE_NS:
if dns_name_equal(rec.data, urec.data):
found = True
elif record_type == dnsp.DNS_TYPE_MX:
if dns_name_equal(rec.data.nameExchange, urec.data.nameExchange) and \
rec.data.wPreference == urec.data.wPreference:
found = True
elif record_type == dnsp.DNS_TYPE_SRV:
if rec.data.wPriority == urec.data.wPriority and \
rec.data.wWeight == urec.data.wWeight and \
rec.data.wPort == urec.data.wPort and \
dns_name_equal(rec.data.nameTarget, urec.data.nameTarget):
found = True
elif record_type == dnsp.DNS_TYPE_SOA:
if rec.data.dwSerialNo == urec.data.dwSerialNo and \
rec.data.dwRefresh == urec.data.dwRefresh and \
rec.data.dwRetry == urec.data.dwRetry and \
rec.data.dwExpire == urec.data.dwExpire and \
rec.data.dwMinimumTtl == urec.data.dwMinimumTtl and \
dns_name_equal(rec.data.NamePrimaryServer,
urec.data.NamePrimaryServer) and \
dns_name_equal(rec.data.ZoneAdministratorEmail,
urec.data.ZoneAdministratorEmail):
found = True
elif record_type == dnsp.DNS_TYPE_TXT:
if rec.data.count == urec.data.count:
found = True
for i in xrange(rec.data.count):
found = found and \
(rec.data.str[i].str == urec.data.str[i].str)
if found:
rec_match = rec
break
return rec_match
class cmd_serverinfo(Command):
"""Query for Server information."""
synopsis = '%prog <server> [options]'
takes_args = [ 'server' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option('--client-version', help='Client Version',
default='longhorn', metavar='w2k|dotnet|longhorn',
choices=['w2k','dotnet','longhorn'], dest='cli_ver'),
]
def run(self, server, cli_ver, sambaopts=None, credopts=None,
versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
client_version = dns_client_version(cli_ver)
typeid, res = dns_conn.DnssrvQuery2(client_version, 0, server,
None, 'ServerInfo')
print_serverinfo(self.outf, typeid, res)
class cmd_zoneinfo(Command):
"""Query for zone information."""
synopsis = '%prog <server> <zone> [options]'
takes_args = [ 'server', 'zone' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option('--client-version', help='Client Version',
default='longhorn', metavar='w2k|dotnet|longhorn',
choices=['w2k','dotnet','longhorn'], dest='cli_ver'),
]
def run(self, server, zone, cli_ver, sambaopts=None, credopts=None,
versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
client_version = dns_client_version(cli_ver)
typeid, res = dns_conn.DnssrvQuery2(client_version, 0, server, zone,
'ZoneInfo')
print_zoneinfo(self.outf, typeid, res)
class cmd_zonelist(Command):
"""Query for zones."""
synopsis = '%prog <server> [options]'
takes_args = [ 'server' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option('--client-version', help='Client Version',
default='longhorn', metavar='w2k|dotnet|longhorn',
choices=['w2k','dotnet','longhorn'], dest='cli_ver'),
Option('--primary', help='List primary zones (default)',
action='store_true', dest='primary'),
Option('--secondary', help='List secondary zones',
action='store_true', dest='secondary'),
Option('--cache', help='List cached zones',
action='store_true', dest='cache'),
Option('--auto', help='List automatically created zones',
action='store_true', dest='auto'),
Option('--forward', help='List forward zones',
action='store_true', dest='forward'),
Option('--reverse', help='List reverse zones',
action='store_true', dest='reverse'),
Option('--ds', help='List directory integrated zones',
action='store_true', dest='ds'),
Option('--non-ds', help='List non-directory zones',
action='store_true', dest='nonds')
]
def run(self, server, cli_ver, primary=False, secondary=False, cache=False,
auto=False, forward=False, reverse=False, ds=False, nonds=False,
sambaopts=None, credopts=None, versionopts=None):
request_filter = 0
if primary:
request_filter |= dnsserver.DNS_ZONE_REQUEST_PRIMARY
if secondary:
request_filter |= dnsserver.DNS_ZONE_REQUEST_SECONDARY
if cache:
request_filter |= dnsserver.DNS_ZONE_REQUEST_CACHE
if auto:
request_filter |= dnsserver.DNS_ZONE_REQUEST_AUTO
if forward:
request_filter |= dnsserver.DNS_ZONE_REQUEST_FORWARD
if reverse:
request_filter |= dnsserver.DNS_ZONE_REQUEST_REVERSE
if ds:
request_filter |= dnsserver.DNS_ZONE_REQUEST_DS
if nonds:
request_filter |= dnsserver.DNS_ZONE_REQUEST_NON_DS
if request_filter == 0:
request_filter = dnsserver.DNS_ZONE_REQUEST_PRIMARY
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
client_version = dns_client_version(cli_ver)
typeid, res = dns_conn.DnssrvComplexOperation2(client_version,
0, server, None,
'EnumZones',
dnsserver.DNSSRV_TYPEID_DWORD,
request_filter)
if client_version == dnsserver.DNS_CLIENT_VERSION_W2K:
typeid = dnsserver.DNSSRV_TYPEID_ZONE_W2K
else:
typeid = dnsserver.DNSSRV_TYPEID_ZONE
print_enumzones(self.outf, typeid, res)
class cmd_zonecreate(Command):
"""Create a zone."""
synopsis = '%prog <server> <zone> [options]'
takes_args = [ 'server', 'zone' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option('--client-version', help='Client Version',
default='longhorn', metavar='w2k|dotnet|longhorn',
choices=['w2k','dotnet','longhorn'], dest='cli_ver')
]
def run(self, server, zone, cli_ver, sambaopts=None, credopts=None,
versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
zone = zone.lower()
client_version = dns_client_version(cli_ver)
if client_version == dnsserver.DNS_CLIENT_VERSION_W2K:
typeid = dnsserver.DNSSRV_TYPEID_ZONE_CREATE_W2K
zone_create_info = dnsserver.DNS_RPC_ZONE_CREATE_INFO_W2K()
zone_create_info.pszZoneName = zone
zone_create_info.dwZoneType = dnsp.DNS_ZONE_TYPE_PRIMARY
zone_create_info.fAging = 0
zone_create_info.fDsIntegrated = 1
zone_create_info.fLoadExisting = 1
elif client_version == dnsserver.DNS_CLIENT_VERSION_DOTNET:
typeid = dnsserver.DNSSRV_TYPEID_ZONE_CREATE_DOTNET
zone_create_info = dnsserver.DNS_RPC_ZONE_CREATE_INFO_DOTNET()
zone_create_info.pszZoneName = zone
zone_create_info.dwZoneType = dnsp.DNS_ZONE_TYPE_PRIMARY
zone_create_info.fAging = 0
zone_create_info.fDsIntegrated = 1
zone_create_info.fLoadExisting = 1
zone_create_info.dwDpFlags = dnsserver.DNS_DP_DOMAIN_DEFAULT
else:
typeid = dnsserver.DNSSRV_TYPEID_ZONE_CREATE
zone_create_info = dnsserver.DNS_RPC_ZONE_CREATE_INFO_LONGHORN()
zone_create_info.pszZoneName = zone
zone_create_info.dwZoneType = dnsp.DNS_ZONE_TYPE_PRIMARY
zone_create_info.fAging = 0
zone_create_info.fDsIntegrated = 1
zone_create_info.fLoadExisting = 1
zone_create_info.dwDpFlags = dnsserver.DNS_DP_DOMAIN_DEFAULT
res = dns_conn.DnssrvOperation2(client_version, 0, server, None,
0, 'ZoneCreate', typeid,
zone_create_info)
typeid = dnsserver.DNSSRV_TYPEID_NAME_AND_PARAM
name_and_param = dnsserver.DNS_RPC_NAME_AND_PARAM()
name_and_param.pszNodeName = 'AllowUpdate'
name_and_param.dwParam = dnsp.DNS_ZONE_UPDATE_SECURE
res = dns_conn.DnssrvOperation2(client_version, 0, server, zone,
0, 'ResetDwordProperty', typeid,
name_and_param)
self.outf.write('Zone %s created successfully\n' % zone)
class cmd_zonedelete(Command):
"""Delete a zone."""
synopsis = '%prog <server> <zone> [options]'
takes_args = [ 'server', 'zone' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
def run(self, server, zone, sambaopts=None, credopts=None,
versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
zone = zone.lower()
res = dns_conn.DnssrvOperation2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
0, server, zone, 0, 'DeleteZoneFromDs',
dnsserver.DNSSRV_TYPEID_NULL,
None)
self.outf.write('Zone %s delete successfully\n' % zone)
class cmd_query(Command):
"""Query a name."""
synopsis = '%prog <server> <zone> <name> <A|AAAA|CNAME|MX|NS|SOA|SRV|TXT|ALL> [options]'
takes_args = [ 'server', 'zone', 'name', 'rtype' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option('--authority', help='Search authoritative records (default)',
action='store_true', dest='authority'),
Option('--cache', help='Search cached records',
action='store_true', dest='cache'),
Option('--glue', help='Search glue records',
action='store_true', dest='glue'),
Option('--root', help='Search root hints',
action='store_true', dest='root'),
Option('--additional', help='List additional records',
action='store_true', dest='additional'),
Option('--no-children', help='Do not list children',
action='store_true', dest='no_children'),
Option('--only-children', help='List only children',
action='store_true', dest='only_children')
]
def run(self, server, zone, name, rtype, authority=False, cache=False,
glue=False, root=False, additional=False, no_children=False,
only_children=False, sambaopts=None, credopts=None,
versionopts=None):
record_type = dns_type_flag(rtype)
if name.find('*') != -1:
raise CommandError('Wildcard searches not supported. To dump entire zone use "@"')
select_flags = 0
if authority:
select_flags |= dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA
if cache:
select_flags |= dnsserver.DNS_RPC_VIEW_CACHE_DATA
if glue:
select_flags |= dnsserver.DNS_RPC_VIEW_GLUE_DATA
if root:
select_flags |= dnsserver.DNS_RPC_VIEW_ROOT_HINT_DATA
if additional:
select_flags |= dnsserver.DNS_RPC_VIEW_ADDITIONAL_DATA
if no_children:
select_flags |= dnsserver.DNS_RPC_VIEW_NO_CHILDREN
if only_children:
select_flags |= dnsserver.DNS_RPC_VIEW_ONLY_CHILDREN
if select_flags == 0:
select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA
if select_flags == dnsserver.DNS_RPC_VIEW_ADDITIONAL_DATA:
self.outf.write('Specify either --authority or --root along with --additional.\n')
self.outf.write('Assuming --authority.\n')
select_flags |= dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
buflen, res = dns_conn.DnssrvEnumRecords2(
dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name,
None, record_type, select_flags, None, None)
print_dnsrecords(self.outf, res)
class cmd_roothints(Command):
"""Query root hints."""
synopsis = '%prog <server> [<name>] [options]'
takes_args = [ 'server', 'name?' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
def run(self, server, name='.', sambaopts=None, credopts=None,
versionopts=None):
record_type = dnsp.DNS_TYPE_NS
select_flags = (dnsserver.DNS_RPC_VIEW_ROOT_HINT_DATA |
dnsserver.DNS_RPC_VIEW_ADDITIONAL_DATA)
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
buflen, res = dns_conn.DnssrvEnumRecords2(
dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, '..RootHints',
name, None, record_type, select_flags, None, None)
print_dnsrecords(self.outf, res)
class cmd_add_record(Command):
"""Add a DNS record
For each type data contents are as follows:
A ipv4_address_string
AAAA ipv6_address_string
PTR fqdn_string
CNAME fqdn_string
NS fqdn_string
MX "fqdn_string preference"
SRV "fqdn_string port priority weight"
TXT "'string1' 'string2' ..."
"""
synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS|MX|SRV|TXT> <data>'
takes_args = [ 'server', 'zone', 'name', 'rtype', 'data' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
def run(self, server, zone, name, rtype, data, sambaopts=None,
credopts=None, versionopts=None):
if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SRV','TXT'):
raise CommandError('Adding record of type %s is not supported' % rtype)
record_type = dns_type_flag(rtype)
rec = data_to_dns_record(record_type, data)
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
rec_match = dns_record_match(dns_conn, server, zone, name, record_type,
data)
if rec_match is not None:
raise CommandError('Record already exists')
add_rec_buf = dnsserver.DNS_RPC_RECORD_BUF()
add_rec_buf.rec = rec
dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
0, server, zone, name, add_rec_buf, None)
self.outf.write('Record added successfully\n')
class cmd_update_record(Command):
"""Update a DNS record
For each type data contents are as follows:
A ipv4_address_string
AAAA ipv6_address_string
PTR fqdn_string
CNAME fqdn_string
NS fqdn_string
MX "fqdn_string preference"
SOA "fqdn_dns fqdn_email serial refresh retry expire minimumttl"
SRV "fqdn_string port priority weight"
TXT "'string1' 'string2' ..."
"""
synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS|MX|SOA|SRV|TXT> <olddata> <newdata>'
takes_args = [ 'server', 'zone', 'name', 'rtype', 'olddata', 'newdata' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
def run(self, server, zone, name, rtype, olddata, newdata,
sambaopts=None, credopts=None, versionopts=None):
if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SOA','SRV','TXT'):
raise CommandError('Updating record of type %s is not supported' % rtype)
record_type = dns_type_flag(rtype)
rec = data_to_dns_record(record_type, newdata)
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
rec_match = dns_record_match(dns_conn, server, zone, name, record_type,
olddata)
if not rec_match:
raise CommandError('Record does not exist')
# Copy properties from existing record to new record
rec.dwFlags = rec_match.dwFlags
rec.dwSerial = rec_match.dwSerial
rec.dwTtlSeconds = rec_match.dwTtlSeconds
rec.dwTimeStamp = rec_match.dwTimeStamp
add_rec_buf = dnsserver.DNS_RPC_RECORD_BUF()
add_rec_buf.rec = rec
del_rec_buf = dnsserver.DNS_RPC_RECORD_BUF()
del_rec_buf.rec = rec_match
dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
0,
server,
zone,
name,
add_rec_buf,
del_rec_buf)
self.outf.write('Record updated successfully\n')
class cmd_delete_record(Command):
"""Delete a DNS record
For each type data contents are as follows:
A ipv4_address_string
AAAA ipv6_address_string
PTR fqdn_string
CNAME fqdn_string
NS fqdn_string
MX "fqdn_string preference"
SRV "fqdn_string port priority weight"
TXT "'string1' 'string2' ..."
"""
synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS|MX|SRV|TXT> <data>'
takes_args = [ 'server', 'zone', 'name', 'rtype', 'data' ]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
def run(self, server, zone, name, rtype, data, sambaopts=None, credopts=None, versionopts=None):
if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SRV','TXT'):
raise CommandError('Deleting record of type %s is not supported' % rtype)
record_type = dns_type_flag(rtype)
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
rec_match = dns_record_match(dns_conn, server, zone, name, record_type, data)
if not rec_match:
raise CommandError('Record does not exist')
del_rec_buf = dnsserver.DNS_RPC_RECORD_BUF()
del_rec_buf.rec = rec_match
dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
0,
server,
zone,
name,
None,
del_rec_buf)
self.outf.write('Record deleted successfully\n')
class cmd_dns(SuperCommand):
"""Domain Name Service (DNS) management."""
subcommands = {}
subcommands['serverinfo'] = cmd_serverinfo()
subcommands['zoneinfo'] = cmd_zoneinfo()
subcommands['zonelist'] = cmd_zonelist()
subcommands['zonecreate'] = cmd_zonecreate()
subcommands['zonedelete'] = cmd_zonedelete()
subcommands['query'] = cmd_query()
subcommands['roothints'] = cmd_roothints()
subcommands['add'] = cmd_add_record()
subcommands['update'] = cmd_update_record()
subcommands['delete'] = cmd_delete_record()
|
gpl-3.0
|
[
3,
10237,
10041,
4744,
199,
3,
199,
3,
1898,
334,
35,
9,
437,
1147,
1187,
473,
2231,
645,
83,
7760,
13,
7409,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
31710,
14,
18907,
465,
1511,
199,
504,
2702,
492,
1706,
199,
504,
2838,
492,
17260,
63,
343,
20047,
199,
504,
2838,
492,
17260,
63,
343,
411,
199,
504,
2838,
492,
20089,
63,
11367,
199,
504,
2838,
492,
20089,
63,
11367,
22,
199,
646,
16701,
199,
199,
504,
31710,
14,
846,
1760,
492,
334,
272,
5817,
12,
272,
14393,
12,
272,
3207,
12,
272,
17897,
3110,
12,
272,
776,
199,
504,
31710,
14,
68,
2247,
2352,
492,
6715,
80,
12,
6715,
1000,
421,
199,
318,
6715,
63,
2242,
8,
1000,
12,
13204,
12,
20023,
304,
272,
340,
1654,
14,
2325,
342,
508,
283,
5967,
356,
267,
1654,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
272,
11696,
63,
495,
275,
298,
7966,
645,
78,
63,
711,
63,
8815,
2689,
83,
59,
1037,
8480,
450,
1654,
272,
6715,
63,
1631,
275,
6715,
1000,
14,
5797,
1000,
8,
9140,
63,
495,
12,
13204,
12,
20023,
9,
272,
372,
6715,
63,
1631,
421,
199,
318,
2155,
63,
875,
8,
4173,
304,
272,
340,
3305,
508,
378,
26,
267,
2203,
275,
283,
19823,
7,
272,
916,
3305,
508,
413,
26,
267,
2203,
275,
283,
15064,
7,
272,
587,
26,
267,
2203,
275,
283,
11588,
334,
16,
88,
5,
88,
3171,
450,
3305,
272,
372,
2203,
421,
199,
318,
4952,
63,
875,
8,
578,
12,
4952,
63,
8710,
12,
574,
304,
272,
2203,
275,
488,
272,
367,
325,
315,
4952,
63,
8710,
26,
267,
340,
574,
508,
2519,
8,
578,
12,
325,
304,
288,
2203,
275,
325,
288,
2059,
272,
340,
440,
2203,
26,
267,
2203,
275,
283,
11588,
334,
16,
88,
5,
88,
3171,
450,
574,
272,
372,
2203,
421,
199,
318,
20810,
63,
875,
8,
578,
12,
20810,
63,
8710,
12,
574,
304,
272,
2203,
275,
2125,
272,
367,
330,
315,
20810,
63,
8710,
26,
267,
340,
574,
1253,
2519,
8,
578,
12,
330,
304,
288,
2203,
847,
1543,
83,
283,
450,
330,
272,
340,
440,
2203,
26,
267,
2203,
275,
283,
9185,
7,
272,
372,
2203,
421,
199,
318,
8498,
63,
765,
63,
875,
8,
4930,
63,
765,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
22679,
63,
9977,
63,
1734,
13768,
18732,
297,
283,
12323,
63,
22679,
63,
9977,
63,
3817,
297,
490,
283,
12323,
63,
22679,
63,
9977,
63,
25304,
57,
297,
283,
12323,
63,
22679,
63,
9977,
63,
16436,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
8498,
63,
765,
9,
421,
199,
318,
536,
63,
1074,
63,
4173,
63,
875,
8,
1074,
63,
4173,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
12231,
63,
14468,
63,
14546,
63,
10452,
297,
283,
12323,
63,
12231,
63,
13887,
14468,
63,
14546,
297,
490,
283,
12323,
63,
12231,
63,
8203,
2100,
57,
3727,
63,
14546,
297,
283,
12323,
63,
12231,
63,
1761,
63,
14546,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
1104,
63,
4173,
9,
421,
199,
318,
5718,
63,
466,
63,
875,
8,
2619,
63,
466,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
2711,
63,
8677,
297,
283,
12323,
63,
15353,
63,
2711,
63,
31035,
297,
490,
283,
12323,
63,
15353,
63,
2711,
63,
24236,
4392,
297,
283,
12323,
63,
15353,
63,
2711,
63,
840,
2533,
297,
490,
283,
12323,
63,
15353,
63,
2711,
63,
22371,
11733,
297,
283,
12323,
63,
15353,
63,
2711,
63,
24236,
4392,
63,
8677,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
80,
12,
4952,
63,
8710,
12,
5718,
63,
466,
9,
421,
199,
318,
5718,
63,
873,
63,
875,
8,
2619,
63,
873,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
10383,
63,
7517,
297,
283,
12323,
63,
15353,
63,
10383,
63,
1734,
20696,
297,
490,
283,
12323,
63,
15353,
63,
10383,
63,
20696,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
80,
12,
4952,
63,
8710,
12,
5718,
63,
873,
9,
421,
199,
318,
5718,
63,
12371,
63,
4416,
63,
875,
8,
4416,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
2826,
63,
13554,
297,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
2709,
63,
10452,
297,
490,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
4924,
63,
10452,
297,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
2826,
63,
56,
15849,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
6391,
9,
421,
199,
318,
5718,
63,
6814,
63,
1896,
63,
875,
8,
6814,
63,
1896,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
24972,
63,
7517,
297,
283,
12323,
63,
15353,
63,
24972,
63,
1761,
63,
24236,
25244,
297,
490,
283,
12323,
63,
15353,
63,
24972,
63,
4924,
63,
10452,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
11705,
63,
1896,
9,
421,
199,
318,
12392,
63,
2469,
63,
875,
8,
5780,
63,
2469,
304,
272,
20810,
63,
8710,
275,
359,
283,
12323,
63,
11741,
63,
13883,
26561,
297,
283,
12323,
63
] |
[
10237,
10041,
4744,
199,
3,
199,
3,
1898,
334,
35,
9,
437,
1147,
1187,
473,
2231,
645,
83,
7760,
13,
7409,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
31710,
14,
18907,
465,
1511,
199,
504,
2702,
492,
1706,
199,
504,
2838,
492,
17260,
63,
343,
20047,
199,
504,
2838,
492,
17260,
63,
343,
411,
199,
504,
2838,
492,
20089,
63,
11367,
199,
504,
2838,
492,
20089,
63,
11367,
22,
199,
646,
16701,
199,
199,
504,
31710,
14,
846,
1760,
492,
334,
272,
5817,
12,
272,
14393,
12,
272,
3207,
12,
272,
17897,
3110,
12,
272,
776,
199,
504,
31710,
14,
68,
2247,
2352,
492,
6715,
80,
12,
6715,
1000,
421,
199,
318,
6715,
63,
2242,
8,
1000,
12,
13204,
12,
20023,
304,
272,
340,
1654,
14,
2325,
342,
508,
283,
5967,
356,
267,
1654,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
272,
11696,
63,
495,
275,
298,
7966,
645,
78,
63,
711,
63,
8815,
2689,
83,
59,
1037,
8480,
450,
1654,
272,
6715,
63,
1631,
275,
6715,
1000,
14,
5797,
1000,
8,
9140,
63,
495,
12,
13204,
12,
20023,
9,
272,
372,
6715,
63,
1631,
421,
199,
318,
2155,
63,
875,
8,
4173,
304,
272,
340,
3305,
508,
378,
26,
267,
2203,
275,
283,
19823,
7,
272,
916,
3305,
508,
413,
26,
267,
2203,
275,
283,
15064,
7,
272,
587,
26,
267,
2203,
275,
283,
11588,
334,
16,
88,
5,
88,
3171,
450,
3305,
272,
372,
2203,
421,
199,
318,
4952,
63,
875,
8,
578,
12,
4952,
63,
8710,
12,
574,
304,
272,
2203,
275,
488,
272,
367,
325,
315,
4952,
63,
8710,
26,
267,
340,
574,
508,
2519,
8,
578,
12,
325,
304,
288,
2203,
275,
325,
288,
2059,
272,
340,
440,
2203,
26,
267,
2203,
275,
283,
11588,
334,
16,
88,
5,
88,
3171,
450,
574,
272,
372,
2203,
421,
199,
318,
20810,
63,
875,
8,
578,
12,
20810,
63,
8710,
12,
574,
304,
272,
2203,
275,
2125,
272,
367,
330,
315,
20810,
63,
8710,
26,
267,
340,
574,
1253,
2519,
8,
578,
12,
330,
304,
288,
2203,
847,
1543,
83,
283,
450,
330,
272,
340,
440,
2203,
26,
267,
2203,
275,
283,
9185,
7,
272,
372,
2203,
421,
199,
318,
8498,
63,
765,
63,
875,
8,
4930,
63,
765,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
22679,
63,
9977,
63,
1734,
13768,
18732,
297,
283,
12323,
63,
22679,
63,
9977,
63,
3817,
297,
490,
283,
12323,
63,
22679,
63,
9977,
63,
25304,
57,
297,
283,
12323,
63,
22679,
63,
9977,
63,
16436,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
8498,
63,
765,
9,
421,
199,
318,
536,
63,
1074,
63,
4173,
63,
875,
8,
1074,
63,
4173,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
12231,
63,
14468,
63,
14546,
63,
10452,
297,
283,
12323,
63,
12231,
63,
13887,
14468,
63,
14546,
297,
490,
283,
12323,
63,
12231,
63,
8203,
2100,
57,
3727,
63,
14546,
297,
283,
12323,
63,
12231,
63,
1761,
63,
14546,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
1104,
63,
4173,
9,
421,
199,
318,
5718,
63,
466,
63,
875,
8,
2619,
63,
466,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
2711,
63,
8677,
297,
283,
12323,
63,
15353,
63,
2711,
63,
31035,
297,
490,
283,
12323,
63,
15353,
63,
2711,
63,
24236,
4392,
297,
283,
12323,
63,
15353,
63,
2711,
63,
840,
2533,
297,
490,
283,
12323,
63,
15353,
63,
2711,
63,
22371,
11733,
297,
283,
12323,
63,
15353,
63,
2711,
63,
24236,
4392,
63,
8677,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
80,
12,
4952,
63,
8710,
12,
5718,
63,
466,
9,
421,
199,
318,
5718,
63,
873,
63,
875,
8,
2619,
63,
873,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
10383,
63,
7517,
297,
283,
12323,
63,
15353,
63,
10383,
63,
1734,
20696,
297,
490,
283,
12323,
63,
15353,
63,
10383,
63,
20696,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
80,
12,
4952,
63,
8710,
12,
5718,
63,
873,
9,
421,
199,
318,
5718,
63,
12371,
63,
4416,
63,
875,
8,
4416,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
2826,
63,
13554,
297,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
2709,
63,
10452,
297,
490,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
4924,
63,
10452,
297,
283,
12323,
63,
15353,
63,
15048,
20696,
63,
2826,
63,
56,
15849,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
6391,
9,
421,
199,
318,
5718,
63,
6814,
63,
1896,
63,
875,
8,
6814,
63,
1896,
304,
272,
4952,
63,
8710,
275,
359,
283,
12323,
63,
15353,
63,
24972,
63,
7517,
297,
283,
12323,
63,
15353,
63,
24972,
63,
1761,
63,
24236,
25244,
297,
490,
283,
12323,
63,
15353,
63,
24972,
63,
4924,
63,
10452,
7,
1622,
272,
372,
4952,
63,
875,
8,
5797,
1000,
12,
4952,
63,
8710,
12,
11705,
63,
1896,
9,
421,
199,
318,
12392,
63,
2469,
63,
875,
8,
5780,
63,
2469,
304,
272,
20810,
63,
8710,
275,
359,
283,
12323,
63,
11741,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
openhealthcare/gloss
|
sites/uch/mock_api.py
|
1
|
4898
|
import random
from gloss import models
from gloss.translators.hl7 import coded_values
from datetime import datetime, date, timedelta
from gloss.external_api import save_message
first_names = [
"Jane", "James", "Chandeep", "Samantha", "Oliver", "Charlie",
"Sophie", "Emily", "Lily", "Olivia", "Amelia", "Isabella"
]
last_names = [
"Smith", "Jones", "Williams", "Taylor", "Brown", "Davies", "Wilson",
"Brooke", "King", "Patel", "Jameson", "Davidson", "Williams"
]
adjectives = [
"orange", "red", "blue", "green", "pink", "purple", "gold", "silver",
"bronze", "ruby", "azure", "copper", "forest", "silent", "loud", "dry",
"angry"
]
nouns = [
"cat", "dog", "eagle", "penguin", "lion", "tiger", "cheetah", "antelope",
"chimpanzee", "gorilla", "spider", "frog", "toad", "bat", "owl", "elvis"
]
NULL_PROBABILITY = 2 # out of 10
def date_generator(*args, **kwargs):
start_date = kwargs.get("start_date")
end_date = kwargs.get("end_date")
if not end_date:
end_date = date.today()
if not start_date:
today = date.today()
# multiple of 4 in case we're in a leap year
back = 92
start_date = date(today.year - back, today.month, today.day)
year_diff = end_date.year - start_date.year
if year_diff == 0:
year = end_date.year
else:
year = end_date.year - random.randint(1, year_diff)
if year == start_date.year:
first_month = start_date.month
else:
first_month = 1
if year == end_date.year:
last_month = end_date.month
else:
last_month = 12
month = random.randint(first_month, last_month)
if month == end_date.month and year == end_date.year:
last_day = end_date.day
else:
last_day = 28
if month == start_date.month and year == start_date.year:
first_day = start_date.day
else:
first_day = 1
day = random.randint(first_day, last_day)
return date(year, month, day)
def date_time_generator(*args, **kwargs):
d = date_generator(*args, **kwargs)
hours = random.randint(0, 23)
minutes = random.randint(0, 59)
return datetime(d.year, d.month, d.day, hours, minutes)
def get_birth_date():
eighteen_years_ago = date.today() - timedelta(days=18*365)
return date_generator(start_date=date(1920, 1, 1), end_date=eighteen_years_ago)
def get_first_name():
return random.choice(first_names)
def get_last_name():
return random.choice(last_names)
def get_sex():
return random.choice(coded_values.SEX_MAPPING.values())
def get_religion():
return random.choice(coded_values.RELIGION_MAPPINGS.values())
def get_ethnicity():
return random.choice(coded_values.ETHNICITY_MAPPING.values())
def get_marital_status():
return random.choice(coded_values.MARITAL_STATUSES_MAPPING.values())
def get_title():
possible = ("Mr", "Mrs", "Ms", "Dr", "Rev")
return random.choice(possible)
def nullable(some_func):
if random.randint(0, 10) < NULL_PROBABILITY:
return None
else:
return some_func()
def get_fake_patient():
get_post_code = lambda: "SW12 0BJ"
get_gp_practice_code = lambda: "GPZ XY10"
return dict(
surname=get_last_name(),
first_name=get_first_name(),
middle_name=nullable(get_first_name),
title=nullable(get_title),
date_of_birth=get_birth_date(),
sex=nullable(get_sex),
marital_status=nullable(get_marital_status),
religion=nullable(get_religion),
date_of_death=None,
post_code=nullable(get_post_code),
gp_practice_code=nullable(get_gp_practice_code),
ethnicity=nullable(get_ethnicity)
)
@models.atomic_method
def save_mock_patients(some_identifier, session):
if some_identifier.startswith("xxx"):
pass
else:
patient = save_message(
models.Patient.message_type(**get_fake_patient()), some_identifier,
session=session
)
if some_identifier.startswith("mmm"):
create_merge(patient, some_identifier, session=session)
@models.atomic_method
def create_merge(patient, some_identifier, session):
new_identifier = "{0}{1}".format(random.randint(100, 999), some_identifier)
other_patient = save_message(
models.Patient.message_type(**get_fake_patient()), new_identifier,
session=session
)
merge = models.Merge(
gloss_reference=patient.gloss_reference,
new_reference=other_patient.gloss_reference
)
session.add(merge)
def get_mock_data(cls, some_identifier, some_issuing_source, session):
if cls == models.Patient:
if some_identifier.startswith("xxx"):
return []
else:
return [cls.message_type(**get_fake_patient())]
else:
return cls._to_messages(some_identifier, some_issuing_source, session)
|
gpl-3.0
|
[
646,
2196,
199,
504,
486,
4358,
492,
1709,
199,
504,
486,
4358,
14,
1515,
20830,
14,
15544,
23,
492,
1233,
68,
63,
1459,
199,
504,
2197,
492,
2197,
12,
1434,
12,
6871,
199,
504,
486,
4358,
14,
5159,
63,
1246,
492,
3354,
63,
1188,
421,
199,
2246,
63,
1247,
275,
359,
272,
298,
42,
5865,
401,
298,
42,
14015,
401,
298,
27039,
16131,
401,
298,
51,
455,
290,
273,
65,
401,
298,
47,
317,
422,
401,
298,
1610,
21530,
401,
272,
298,
51,
24316,
1873,
401,
298,
37,
77,
3444,
401,
298,
44,
3444,
401,
298,
47,
317,
12897,
401,
298,
33,
278,
21796,
401,
298,
1831,
902,
416,
2,
199,
61,
199,
199,
2019,
63,
1247,
275,
359,
272,
298,
16782,
448,
401,
298,
42,
4548,
401,
298,
55,
8148,
19470,
401,
298,
52,
1187,
25339,
401,
298,
34,
18406,
401,
298,
36,
7194,
397,
401,
298,
55,
382,
834,
401,
272,
298,
34,
293,
79,
415,
401,
298,
43,
316,
401,
298,
48,
21163,
401,
298,
42,
313,
834,
401,
298,
36,
17204,
834,
401,
298,
55,
8148,
19470,
2,
199,
61,
199,
199,
12551,
825,
7301,
275,
359,
272,
298,
22683,
401,
298,
581,
401,
298,
6304,
401,
298,
7731,
401,
298,
26591,
401,
298,
6653,
11045,
401,
298,
23628,
401,
298,
20329,
422,
401,
272,
298,
66,
2641,
806,
401,
298,
21952,
401,
298,
9078,
401,
298,
26950,
529,
401,
298,
25736,
401,
298,
14434,
401,
298,
320,
1181,
401,
298,
10481,
401,
272,
298,
621,
651,
2,
199,
61,
199,
199,
889,
324,
83,
275,
359,
272,
298,
3385,
401,
298,
13889,
401,
298,
69,
643,
274,
401,
298,
897,
6051,
262,
401,
298,
29025,
401,
298,
280,
836,
401,
298,
595,
1841,
72,
401,
298,
8949,
14363,
401,
272,
298,
335,
3236,
290,
806,
69,
401,
298,
2904,
6165,
401,
298,
12856,
401,
298,
70,
19029,
401,
298,
475,
350,
401,
298,
13475,
401,
298,
583,
76,
401,
298,
352,
5068,
2,
199,
61,
421,
199,
8084,
63,
30533,
2477,
275,
499,
327,
734,
402,
1616,
421,
199,
318,
1434,
63,
4679,
2031,
589,
12,
1011,
958,
304,
272,
1343,
63,
602,
275,
2074,
14,
362,
480,
928,
63,
602,
531,
272,
1284,
63,
602,
275,
2074,
14,
362,
480,
500,
63,
602,
531,
272,
340,
440,
1284,
63,
602,
26,
267,
1284,
63,
602,
275,
1434,
14,
8136,
342,
272,
340,
440,
1343,
63,
602,
26,
267,
11168,
275,
1434,
14,
8136,
342,
267,
327,
3663,
402,
841,
315,
1930,
781,
3984,
315,
282,
29487,
5361,
267,
1771,
275,
20140,
267,
1343,
63,
602,
275,
1434,
8,
8136,
14,
3403,
446,
1771,
12,
11168,
14,
4482,
12,
11168,
14,
2977,
9,
339,
5361,
63,
3028,
275,
1284,
63,
602,
14,
3403,
446,
1343,
63,
602,
14,
3403,
272,
340,
5361,
63,
3028,
508,
378,
26,
267,
5361,
275,
1284,
63,
602,
14,
3403,
272,
587,
26,
267,
5361,
275,
1284,
63,
602,
14,
3403,
446,
2196,
14,
8393,
8,
17,
12,
5361,
63,
3028,
9,
339,
340,
5361,
508,
1343,
63,
602,
14,
3403,
26,
267,
1642,
63,
4482,
275,
1343,
63,
602,
14,
4482,
272,
587,
26,
267,
1642,
63,
4482,
275,
413,
339,
340,
5361,
508,
1284,
63,
602,
14,
3403,
26,
267,
2061,
63,
4482,
275,
1284,
63,
602,
14,
4482,
272,
587,
26,
267,
2061,
63,
4482,
275,
3144,
339,
5794,
275,
2196,
14,
8393,
8,
2246,
63,
4482,
12,
2061,
63,
4482,
9,
339,
340,
5794,
508,
1284,
63,
602,
14,
4482,
436,
5361,
508,
1284,
63,
602,
14,
3403,
26,
267,
2061,
63,
2977,
275,
1284,
63,
602,
14,
2977,
272,
587,
26,
267,
2061,
63,
2977,
275,
7294,
339,
340,
5794,
508,
1343,
63,
602,
14,
4482,
436,
5361,
508,
1343,
63,
602,
14,
3403,
26,
267,
1642,
63,
2977,
275,
1343,
63,
602,
14,
2977,
272,
587,
26,
267,
1642,
63,
2977,
275,
413,
272,
5382,
275,
2196,
14,
8393,
8,
2246,
63,
2977,
12,
2061,
63,
2977,
9,
272,
372,
1434,
8,
3403,
12,
5794,
12,
5382,
9,
421,
199,
318,
1434,
63,
521,
63,
4679,
2031,
589,
12,
1011,
958,
304,
272,
366,
275,
1434,
63,
4679,
2031,
589,
12,
1011,
958,
9,
272,
10857,
275,
2196,
14,
8393,
8,
16,
12,
6546,
9,
272,
9395,
275,
2196,
14,
8393,
8,
16,
12,
8155,
9,
272,
372,
2197,
8,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
12,
10857,
12,
9395,
9,
421,
199,
318,
664,
63,
10907,
63,
602,
837,
272,
325,
2056,
25076,
63,
18431,
63,
14315,
275,
1434,
14,
8136,
342,
446,
6871,
8,
4899,
29,
1085,
10,
12664,
9,
272,
372,
1434,
63,
4679,
8,
928,
63,
602,
29,
602,
8,
1167,
1165,
12,
413,
12,
413,
395,
1284,
63,
602,
29,
69,
2056,
25076,
63,
18431,
63,
14315,
9,
421,
199,
318,
664,
63,
2246,
63,
354,
837,
272,
372,
2196,
14,
5095,
8,
2246,
63,
1247,
9,
421,
199,
318,
664,
63,
2019,
63,
354,
837,
272,
372,
2196,
14,
5095,
8,
2019,
63,
1247,
9,
421,
199,
318,
664,
63,
20160,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
899,
56,
63,
20351,
14,
1459,
1012,
421,
199,
318,
664,
63,
264,
17506,
1636,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
13604,
1277,
1075,
63,
32362,
14,
1459,
1012,
421,
199,
318,
664,
63,
12391,
12165,
1209,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
21265,
30374,
1922,
63,
20351,
14,
1459,
1012,
421,
199,
318,
664,
63,
4584,
6910,
63,
1205,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
45,
689,
649,
748,
63,
6305,
654,
63,
20351,
14,
1459,
1012,
421,
199,
318,
664,
63,
1213,
837,
272,
3962,
275,
1689,
45,
82,
401,
298,
45,
2393,
401,
298,
13586,
401,
298,
21733,
401,
298,
26176,
531,
272,
372,
2196,
14,
5095,
8,
13893,
9,
421,
199,
318,
7854,
8,
3972,
63,
1532,
304,
272,
340,
2196,
14,
8393,
8,
16,
12,
1616,
9,
665,
5962,
63,
30533,
2477,
26,
267,
372,
488,
272,
587,
26,
267,
372,
2005,
63,
1532,
342
] |
[
2196,
199,
504,
486,
4358,
492,
1709,
199,
504,
486,
4358,
14,
1515,
20830,
14,
15544,
23,
492,
1233,
68,
63,
1459,
199,
504,
2197,
492,
2197,
12,
1434,
12,
6871,
199,
504,
486,
4358,
14,
5159,
63,
1246,
492,
3354,
63,
1188,
421,
199,
2246,
63,
1247,
275,
359,
272,
298,
42,
5865,
401,
298,
42,
14015,
401,
298,
27039,
16131,
401,
298,
51,
455,
290,
273,
65,
401,
298,
47,
317,
422,
401,
298,
1610,
21530,
401,
272,
298,
51,
24316,
1873,
401,
298,
37,
77,
3444,
401,
298,
44,
3444,
401,
298,
47,
317,
12897,
401,
298,
33,
278,
21796,
401,
298,
1831,
902,
416,
2,
199,
61,
199,
199,
2019,
63,
1247,
275,
359,
272,
298,
16782,
448,
401,
298,
42,
4548,
401,
298,
55,
8148,
19470,
401,
298,
52,
1187,
25339,
401,
298,
34,
18406,
401,
298,
36,
7194,
397,
401,
298,
55,
382,
834,
401,
272,
298,
34,
293,
79,
415,
401,
298,
43,
316,
401,
298,
48,
21163,
401,
298,
42,
313,
834,
401,
298,
36,
17204,
834,
401,
298,
55,
8148,
19470,
2,
199,
61,
199,
199,
12551,
825,
7301,
275,
359,
272,
298,
22683,
401,
298,
581,
401,
298,
6304,
401,
298,
7731,
401,
298,
26591,
401,
298,
6653,
11045,
401,
298,
23628,
401,
298,
20329,
422,
401,
272,
298,
66,
2641,
806,
401,
298,
21952,
401,
298,
9078,
401,
298,
26950,
529,
401,
298,
25736,
401,
298,
14434,
401,
298,
320,
1181,
401,
298,
10481,
401,
272,
298,
621,
651,
2,
199,
61,
199,
199,
889,
324,
83,
275,
359,
272,
298,
3385,
401,
298,
13889,
401,
298,
69,
643,
274,
401,
298,
897,
6051,
262,
401,
298,
29025,
401,
298,
280,
836,
401,
298,
595,
1841,
72,
401,
298,
8949,
14363,
401,
272,
298,
335,
3236,
290,
806,
69,
401,
298,
2904,
6165,
401,
298,
12856,
401,
298,
70,
19029,
401,
298,
475,
350,
401,
298,
13475,
401,
298,
583,
76,
401,
298,
352,
5068,
2,
199,
61,
421,
199,
8084,
63,
30533,
2477,
275,
499,
327,
734,
402,
1616,
421,
199,
318,
1434,
63,
4679,
2031,
589,
12,
1011,
958,
304,
272,
1343,
63,
602,
275,
2074,
14,
362,
480,
928,
63,
602,
531,
272,
1284,
63,
602,
275,
2074,
14,
362,
480,
500,
63,
602,
531,
272,
340,
440,
1284,
63,
602,
26,
267,
1284,
63,
602,
275,
1434,
14,
8136,
342,
272,
340,
440,
1343,
63,
602,
26,
267,
11168,
275,
1434,
14,
8136,
342,
267,
327,
3663,
402,
841,
315,
1930,
781,
3984,
315,
282,
29487,
5361,
267,
1771,
275,
20140,
267,
1343,
63,
602,
275,
1434,
8,
8136,
14,
3403,
446,
1771,
12,
11168,
14,
4482,
12,
11168,
14,
2977,
9,
339,
5361,
63,
3028,
275,
1284,
63,
602,
14,
3403,
446,
1343,
63,
602,
14,
3403,
272,
340,
5361,
63,
3028,
508,
378,
26,
267,
5361,
275,
1284,
63,
602,
14,
3403,
272,
587,
26,
267,
5361,
275,
1284,
63,
602,
14,
3403,
446,
2196,
14,
8393,
8,
17,
12,
5361,
63,
3028,
9,
339,
340,
5361,
508,
1343,
63,
602,
14,
3403,
26,
267,
1642,
63,
4482,
275,
1343,
63,
602,
14,
4482,
272,
587,
26,
267,
1642,
63,
4482,
275,
413,
339,
340,
5361,
508,
1284,
63,
602,
14,
3403,
26,
267,
2061,
63,
4482,
275,
1284,
63,
602,
14,
4482,
272,
587,
26,
267,
2061,
63,
4482,
275,
3144,
339,
5794,
275,
2196,
14,
8393,
8,
2246,
63,
4482,
12,
2061,
63,
4482,
9,
339,
340,
5794,
508,
1284,
63,
602,
14,
4482,
436,
5361,
508,
1284,
63,
602,
14,
3403,
26,
267,
2061,
63,
2977,
275,
1284,
63,
602,
14,
2977,
272,
587,
26,
267,
2061,
63,
2977,
275,
7294,
339,
340,
5794,
508,
1343,
63,
602,
14,
4482,
436,
5361,
508,
1343,
63,
602,
14,
3403,
26,
267,
1642,
63,
2977,
275,
1343,
63,
602,
14,
2977,
272,
587,
26,
267,
1642,
63,
2977,
275,
413,
272,
5382,
275,
2196,
14,
8393,
8,
2246,
63,
2977,
12,
2061,
63,
2977,
9,
272,
372,
1434,
8,
3403,
12,
5794,
12,
5382,
9,
421,
199,
318,
1434,
63,
521,
63,
4679,
2031,
589,
12,
1011,
958,
304,
272,
366,
275,
1434,
63,
4679,
2031,
589,
12,
1011,
958,
9,
272,
10857,
275,
2196,
14,
8393,
8,
16,
12,
6546,
9,
272,
9395,
275,
2196,
14,
8393,
8,
16,
12,
8155,
9,
272,
372,
2197,
8,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
12,
10857,
12,
9395,
9,
421,
199,
318,
664,
63,
10907,
63,
602,
837,
272,
325,
2056,
25076,
63,
18431,
63,
14315,
275,
1434,
14,
8136,
342,
446,
6871,
8,
4899,
29,
1085,
10,
12664,
9,
272,
372,
1434,
63,
4679,
8,
928,
63,
602,
29,
602,
8,
1167,
1165,
12,
413,
12,
413,
395,
1284,
63,
602,
29,
69,
2056,
25076,
63,
18431,
63,
14315,
9,
421,
199,
318,
664,
63,
2246,
63,
354,
837,
272,
372,
2196,
14,
5095,
8,
2246,
63,
1247,
9,
421,
199,
318,
664,
63,
2019,
63,
354,
837,
272,
372,
2196,
14,
5095,
8,
2019,
63,
1247,
9,
421,
199,
318,
664,
63,
20160,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
899,
56,
63,
20351,
14,
1459,
1012,
421,
199,
318,
664,
63,
264,
17506,
1636,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
13604,
1277,
1075,
63,
32362,
14,
1459,
1012,
421,
199,
318,
664,
63,
12391,
12165,
1209,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
21265,
30374,
1922,
63,
20351,
14,
1459,
1012,
421,
199,
318,
664,
63,
4584,
6910,
63,
1205,
837,
272,
372,
2196,
14,
5095,
8,
15282,
63,
1459,
14,
45,
689,
649,
748,
63,
6305,
654,
63,
20351,
14,
1459,
1012,
421,
199,
318,
664,
63,
1213,
837,
272,
3962,
275,
1689,
45,
82,
401,
298,
45,
2393,
401,
298,
13586,
401,
298,
21733,
401,
298,
26176,
531,
272,
372,
2196,
14,
5095,
8,
13893,
9,
421,
199,
318,
7854,
8,
3972,
63,
1532,
304,
272,
340,
2196,
14,
8393,
8,
16,
12,
1616,
9,
665,
5962,
63,
30533,
2477,
26,
267,
372,
488,
272,
587,
26,
267,
372,
2005,
63,
1532,
342,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
martydill/url_shortener
|
code/venv/lib/python2.7/site-packages/IPython/terminal/embed.py
|
4
|
10491
|
# encoding: utf-8
"""
An embedded IPython shell.
"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from __future__ import with_statement
from __future__ import print_function
import sys
import warnings
from IPython.core import ultratb, compilerop
from IPython.core.magic import Magics, magics_class, line_magic
from IPython.core.interactiveshell import DummyMod
from IPython.core.interactiveshell import InteractiveShell
from IPython.terminal.interactiveshell import TerminalInteractiveShell
from IPython.terminal.ipapp import load_default_config
from IPython.utils.traitlets import Bool, CBool, Unicode
from IPython.utils.io import ask_yes_no
# This is an additional magic that is exposed in embedded shells.
@magics_class
class EmbeddedMagics(Magics):
@line_magic
def kill_embedded(self, parameter_s=''):
"""%kill_embedded : deactivate for good the current embedded IPython.
This function (after asking for confirmation) sets an internal flag so
that an embedded IPython will never activate again. This is useful to
permanently disable a shell that is being called inside a loop: once
you've figured out what you needed from it, you may then kill it and
the program will then continue to run without the interactive shell
interfering again.
"""
kill = ask_yes_no("Are you sure you want to kill this embedded instance "
"(y/n)? [y/N] ",'n')
if kill:
self.shell.embedded_active = False
print ("This embedded IPython will not reactivate anymore "
"once you exit.")
class InteractiveShellEmbed(TerminalInteractiveShell):
dummy_mode = Bool(False)
exit_msg = Unicode('')
embedded = CBool(True)
embedded_active = CBool(True)
# Like the base class display_banner is not configurable, but here it
# is True by default.
display_banner = CBool(True)
exit_msg = Unicode()
def __init__(self, **kw):
if kw.get('user_global_ns', None) is not None:
warnings.warn("user_global_ns has been replaced by user_module. The\
parameter will be ignored.", DeprecationWarning)
super(InteractiveShellEmbed,self).__init__(**kw)
# don't use the ipython crash handler so that user exceptions aren't
# trapped
sys.excepthook = ultratb.FormattedTB(color_scheme=self.colors,
mode=self.xmode,
call_pdb=self.pdb)
def init_sys_modules(self):
pass
def init_magics(self):
super(InteractiveShellEmbed, self).init_magics()
self.register_magics(EmbeddedMagics)
def __call__(self, header='', local_ns=None, module=None, dummy=None,
stack_depth=1, global_ns=None, compile_flags=None):
"""Activate the interactive interpreter.
__call__(self,header='',local_ns=None,module=None,dummy=None) -> Start
the interpreter shell with the given local and global namespaces, and
optionally print a header string at startup.
The shell can be globally activated/deactivated using the
dummy_mode attribute. This allows you to turn off a shell used
for debugging globally.
However, *each* time you call the shell you can override the current
state of dummy_mode with the optional keyword parameter 'dummy'. For
example, if you set dummy mode on with IPShell.dummy_mode = True, you
can still have a specific call work by making it as IPShell(dummy=False).
"""
# If the user has turned it off, go away
if not self.embedded_active:
return
# Normal exits from interactive mode set this flag, so the shell can't
# re-enter (it checks this variable at the start of interactive mode).
self.exit_now = False
# Allow the dummy parameter to override the global __dummy_mode
if dummy or (dummy != 0 and self.dummy_mode):
return
if self.has_readline:
self.set_readline_completer()
# self.banner is auto computed
if header:
self.old_banner2 = self.banner2
self.banner2 = self.banner2 + '\n' + header + '\n'
else:
self.old_banner2 = ''
# Call the embedding code with a stack depth of 1 so it can skip over
# our call and get the original caller's namespaces.
self.mainloop(local_ns, module, stack_depth=stack_depth,
global_ns=global_ns, compile_flags=compile_flags)
self.banner2 = self.old_banner2
if self.exit_msg is not None:
print(self.exit_msg)
def mainloop(self, local_ns=None, module=None, stack_depth=0,
display_banner=None, global_ns=None, compile_flags=None):
"""Embeds IPython into a running python program.
Parameters
----------
local_ns, module
Working local namespace (a dict) and module (a module or similar
object). If given as None, they are automatically taken from the scope
where the shell was called, so that program variables become visible.
stack_depth : int
How many levels in the stack to go to looking for namespaces (when
local_ns or module is None). This allows an intermediate caller to
make sure that this function gets the namespace from the intended
level in the stack. By default (0) it will get its locals and globals
from the immediate caller.
compile_flags
A bit field identifying the __future__ features
that are enabled, as passed to the builtin :func:`compile` function.
If given as None, they are automatically taken from the scope where
the shell was called.
"""
if (global_ns is not None) and (module is None):
warnings.warn("global_ns is deprecated, use module instead.", DeprecationWarning)
module = DummyMod()
module.__dict__ = global_ns
# Get locals and globals from caller
if ((local_ns is None or module is None or compile_flags is None)
and self.default_user_namespaces):
call_frame = sys._getframe(stack_depth).f_back
if local_ns is None:
local_ns = call_frame.f_locals
if module is None:
global_ns = call_frame.f_globals
module = sys.modules[global_ns['__name__']]
if compile_flags is None:
compile_flags = (call_frame.f_code.co_flags &
compilerop.PyCF_MASK)
# Save original namespace and module so we can restore them after
# embedding; otherwise the shell doesn't shut down correctly.
orig_user_module = self.user_module
orig_user_ns = self.user_ns
orig_compile_flags = self.compile.flags
# Update namespaces and fire up interpreter
# The global one is easy, we can just throw it in
if module is not None:
self.user_module = module
# But the user/local one is tricky: ipython needs it to store internal
# data, but we also need the locals. We'll throw our hidden variables
# like _ih and get_ipython() into the local namespace, but delete them
# later.
if local_ns is not None:
reentrant_local_ns = {k: v for (k, v) in local_ns.items() if k not in self.user_ns_hidden.keys()}
self.user_ns = reentrant_local_ns
self.init_user_ns()
# Compiler flags
if compile_flags is not None:
self.compile.flags = compile_flags
# make sure the tab-completer has the correct frame information, so it
# actually completes using the frame's locals/globals
self.set_completer_frame()
with self.builtin_trap, self.display_trap:
self.interact(display_banner=display_banner)
# now, purge out the local namespace of IPython's hidden variables.
if local_ns is not None:
local_ns.update({k: v for (k, v) in self.user_ns.items() if k not in self.user_ns_hidden.keys()})
# Restore original namespace so shell can shut down when we exit.
self.user_module = orig_user_module
self.user_ns = orig_user_ns
self.compile.flags = orig_compile_flags
def embed(**kwargs):
"""Call this to embed IPython at the current point in your program.
The first invocation of this will create an :class:`InteractiveShellEmbed`
instance and then call it. Consecutive calls just call the already
created instance.
If you don't want the kernel to initialize the namespace
from the scope of the surrounding function,
and/or you want to load full IPython configuration,
you probably want `IPython.start_ipython()` instead.
Here is a simple example::
from IPython import embed
a = 10
b = 20
embed(header='First time')
c = 30
d = 40
embed()
Full customization can be done by passing a :class:`Config` in as the
config argument.
"""
config = kwargs.get('config')
header = kwargs.pop('header', u'')
compile_flags = kwargs.pop('compile_flags', None)
if config is None:
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs['config'] = config
#save ps1/ps2 if defined
ps1 = None
ps2 = None
try:
ps1 = sys.ps1
ps2 = sys.ps2
except AttributeError:
pass
#save previous instance
saved_shell_instance = InteractiveShell._instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
shell = InteractiveShellEmbed.instance(**kwargs)
shell(header=header, stack_depth=2, compile_flags=compile_flags)
InteractiveShellEmbed.clear_instance()
#restore previous instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
for subclass in cls._walk_mro():
subclass._instance = saved_shell_instance
if ps1 is not None:
sys.ps1 = ps1
sys.ps2 = ps2
|
mit
|
[
3,
2644,
26,
2774,
13,
24,
199,
624,
199,
2493,
12169,
16243,
5218,
14,
199,
624,
199,
3,
1898,
334,
67,
9,
16243,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
984,
199,
646,
3598,
199,
199,
504,
16243,
14,
1018,
492,
221,
427,
17565,
66,
12,
6555,
2675,
199,
504,
16243,
14,
1018,
14,
11523,
492,
603,
643,
2932,
12,
8127,
2932,
63,
533,
12,
1004,
63,
11523,
199,
504,
16243,
14,
1018,
14,
262,
2967,
67,
7301,
72,
1697,
492,
9762,
9871,
199,
504,
16243,
14,
1018,
14,
262,
2967,
67,
7301,
72,
1697,
492,
1010,
7502,
8529,
199,
504,
16243,
14,
12010,
14,
262,
2967,
67,
7301,
72,
1697,
492,
20429,
279,
23879,
8529,
199,
504,
16243,
14,
12010,
14,
20014,
802,
492,
2248,
63,
885,
63,
888,
199,
199,
504,
16243,
14,
1208,
14,
1239,
5776,
1086,
492,
19287,
12,
445,
10349,
12,
6140,
199,
504,
16243,
14,
1208,
14,
2308,
492,
7198,
63,
5066,
63,
889,
421,
199,
3,
961,
365,
376,
4722,
10628,
626,
365,
19282,
315,
12169,
1033,
6840,
14,
199,
32,
5615,
2932,
63,
533,
199,
533,
24297,
770,
22745,
2932,
8,
22745,
2932,
304,
339,
768,
604,
63,
11523,
272,
347,
14561,
63,
18757,
8,
277,
12,
2725,
63,
83,
9280,
267,
408,
5,
8997,
63,
18757,
520,
25560,
367,
6954,
314,
1453,
12169,
16243,
14,
398,
961,
805,
334,
4399,
7198,
316,
367,
18791,
9,
5951,
376,
5007,
3305,
880,
267,
626,
376,
12169,
16243,
911,
7078,
15422,
4020,
14,
221,
961,
365,
2997,
370,
267,
19860,
590,
3507,
282,
5218,
626,
365,
3769,
2797,
6272,
282,
4438,
26,
5403,
267,
1265,
9064,
6085,
3297,
734,
4052,
1265,
4346,
687,
652,
12,
1265,
1443,
2066,
14561,
652,
436,
267,
314,
2240,
911,
2066,
1980,
370,
1255,
1928,
314,
12777,
5218,
267,
1640,
2412,
316,
4020,
14,
267,
408,
398,
14561,
275,
7198,
63,
5066,
63,
889,
480,
17683,
1265,
3238,
1265,
2934,
370,
14561,
642,
12169,
1256,
298,
586,
7340,
89,
15,
78,
5547,
359,
89,
15,
46,
61,
298,
2584,
78,
358,
267,
340,
14561,
26,
288,
291,
14,
5641,
14,
18757,
63,
2682,
275,
756,
288,
870,
1689,
2765,
12169,
16243,
911,
440,
295,
8222,
20827,
298,
673,
298,
5089,
1265,
4458,
2685,
421,
199,
533,
1010,
7502,
8529,
13200,
8,
22015,
23879,
8529,
304,
339,
7283,
63,
632,
275,
19287,
8,
797,
9,
272,
4458,
63,
1328,
275,
6140,
8355,
272,
12169,
275,
445,
10349,
8,
549,
9,
272,
12169,
63,
2682,
275,
445,
10349,
8,
549,
9,
272,
327,
16485,
314,
1300,
1021,
2929,
63,
13066,
365,
440,
30241,
12,
1325,
2348,
652,
272,
327,
365,
715,
701,
849,
14,
272,
2929,
63,
13066,
275,
445,
10349,
8,
549,
9,
272,
4458,
63,
1328,
275,
6140,
342,
1362,
339,
347,
636,
826,
721,
277,
12,
1011,
829,
304,
268,
13857,
340,
4775,
14,
362,
360,
751,
63,
2966,
63,
561,
297,
488,
9,
365,
440,
488,
26,
288,
3598,
14,
4050,
480,
751,
63,
2966,
63,
561,
965,
2757,
8717,
701,
922,
63,
578,
14,
710,
60,
2574,
2725,
911,
506,
5525,
4765,
13413,
9,
398,
1613,
8,
23879,
8529,
13200,
12,
277,
2843,
826,
14155,
829,
9,
398,
327,
2793,
1133,
675,
314,
284,
1548,
12420,
3016,
880,
626,
922,
4967,
10621,
1133,
267,
327,
22514,
1915,
267,
984,
14,
476,
301,
13316,
6992,
275,
221,
427,
17565,
66,
14,
31602,
20098,
8,
2326,
63,
5512,
29,
277,
14,
7120,
12,
6163,
818,
29,
277,
14,
88,
632,
12,
6163,
1240,
63,
10511,
29,
277,
14,
10511,
9,
339,
347,
4205,
63,
1274,
63,
3112,
8,
277,
304,
267,
986,
339,
347,
4205,
63,
5615,
2932,
8,
277,
304,
267,
1613,
8,
23879,
8529,
13200,
12,
291,
680,
826,
63,
5615,
2932,
342,
267,
291,
14,
2683,
63,
5615,
2932,
8,
27395,
22745,
2932,
9,
339,
347,
636,
1250,
721,
277,
12,
1406,
4581,
2257,
63,
561,
29,
403,
12,
859,
29,
403,
12,
7283,
29,
403,
12,
326,
3464,
63,
4631,
29,
17,
12,
2288,
63,
561,
29,
403,
12,
6555,
63,
2469,
29,
403,
304,
267,
408,
30120,
314,
12777,
12693,
14,
398,
636,
1250,
721,
277,
12,
1291,
4581,
1832,
63,
561,
29,
403,
12,
578,
29,
403,
12,
5869,
29,
403,
9,
1035,
7707,
267,
314,
12693,
5218,
543,
314,
1627,
2257,
436,
2288,
10747,
12,
436,
267,
14190,
870,
282,
1406,
1059,
737,
14210,
14,
398,
710,
5218,
883,
506,
26662,
22225,
15,
271,
18218,
1808,
314,
267,
7283,
63,
632,
2225,
14,
961,
6127,
1265,
370,
7485,
2331,
282,
5218,
1202,
267,
367,
10201,
26662,
14,
398,
9738,
12,
627,
10885,
10,
900,
1265,
1240,
314,
5218,
1265,
883,
4278,
314,
1453,
267,
1174,
402,
7283,
63,
632,
543,
314,
2716,
4252,
2725,
283,
5869,
1370,
2104,
267,
2893,
12,
340,
1265,
663,
7283,
818,
641,
543,
3531,
8529,
14,
5869,
63,
632,
275,
715,
12,
1265,
267,
883,
5139,
1172,
282,
2488,
1240,
1736,
701,
10663,
652,
465,
3531,
8529,
8,
5869,
29,
797,
680,
267,
408,
398,
327,
982,
314,
922,
965,
19136,
652,
2331,
12,
2621,
13437,
267,
340,
440,
291,
14,
18757,
63,
2682,
26,
288,
372,
398,
327,
11514,
20100,
687,
12777,
818,
663,
642,
3305,
12,
880,
314,
5218,
883,
1133,
267,
327,
295,
13,
4200,
334,
390,
5920,
642,
1750,
737,
314,
1343,
402,
12777,
818,
680,
267,
291,
14,
2224,
63,
2131,
275,
756,
398,
327,
9812,
314,
7283,
2725,
370,
4278,
314,
2288,
636,
5869,
63,
632,
267,
340,
7283,
503,
334,
5869,
1137,
378,
436,
291,
14,
5869,
63,
632,
304,
288,
372,
398,
340,
291,
14,
1989,
63,
6407,
26,
288,
291,
14,
409,
63,
6407,
63,
18452,
342,
398,
327,
291,
14,
13066,
365,
2599,
9235,
267,
340,
1406,
26,
288,
291,
14,
1753,
63,
13066,
18,
275,
291,
14,
13066,
18,
288,
291,
14,
13066,
18,
275,
291,
14,
13066,
18,
435,
1557,
78,
7,
435,
1406,
435,
1557,
78,
7
] |
[
2644,
26,
2774,
13,
24,
199,
624,
199,
2493,
12169,
16243,
5218,
14,
199,
624,
199,
3,
1898,
334,
67,
9,
16243,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
984,
199,
646,
3598,
199,
199,
504,
16243,
14,
1018,
492,
221,
427,
17565,
66,
12,
6555,
2675,
199,
504,
16243,
14,
1018,
14,
11523,
492,
603,
643,
2932,
12,
8127,
2932,
63,
533,
12,
1004,
63,
11523,
199,
504,
16243,
14,
1018,
14,
262,
2967,
67,
7301,
72,
1697,
492,
9762,
9871,
199,
504,
16243,
14,
1018,
14,
262,
2967,
67,
7301,
72,
1697,
492,
1010,
7502,
8529,
199,
504,
16243,
14,
12010,
14,
262,
2967,
67,
7301,
72,
1697,
492,
20429,
279,
23879,
8529,
199,
504,
16243,
14,
12010,
14,
20014,
802,
492,
2248,
63,
885,
63,
888,
199,
199,
504,
16243,
14,
1208,
14,
1239,
5776,
1086,
492,
19287,
12,
445,
10349,
12,
6140,
199,
504,
16243,
14,
1208,
14,
2308,
492,
7198,
63,
5066,
63,
889,
421,
199,
3,
961,
365,
376,
4722,
10628,
626,
365,
19282,
315,
12169,
1033,
6840,
14,
199,
32,
5615,
2932,
63,
533,
199,
533,
24297,
770,
22745,
2932,
8,
22745,
2932,
304,
339,
768,
604,
63,
11523,
272,
347,
14561,
63,
18757,
8,
277,
12,
2725,
63,
83,
9280,
267,
408,
5,
8997,
63,
18757,
520,
25560,
367,
6954,
314,
1453,
12169,
16243,
14,
398,
961,
805,
334,
4399,
7198,
316,
367,
18791,
9,
5951,
376,
5007,
3305,
880,
267,
626,
376,
12169,
16243,
911,
7078,
15422,
4020,
14,
221,
961,
365,
2997,
370,
267,
19860,
590,
3507,
282,
5218,
626,
365,
3769,
2797,
6272,
282,
4438,
26,
5403,
267,
1265,
9064,
6085,
3297,
734,
4052,
1265,
4346,
687,
652,
12,
1265,
1443,
2066,
14561,
652,
436,
267,
314,
2240,
911,
2066,
1980,
370,
1255,
1928,
314,
12777,
5218,
267,
1640,
2412,
316,
4020,
14,
267,
408,
398,
14561,
275,
7198,
63,
5066,
63,
889,
480,
17683,
1265,
3238,
1265,
2934,
370,
14561,
642,
12169,
1256,
298,
586,
7340,
89,
15,
78,
5547,
359,
89,
15,
46,
61,
298,
2584,
78,
358,
267,
340,
14561,
26,
288,
291,
14,
5641,
14,
18757,
63,
2682,
275,
756,
288,
870,
1689,
2765,
12169,
16243,
911,
440,
295,
8222,
20827,
298,
673,
298,
5089,
1265,
4458,
2685,
421,
199,
533,
1010,
7502,
8529,
13200,
8,
22015,
23879,
8529,
304,
339,
7283,
63,
632,
275,
19287,
8,
797,
9,
272,
4458,
63,
1328,
275,
6140,
8355,
272,
12169,
275,
445,
10349,
8,
549,
9,
272,
12169,
63,
2682,
275,
445,
10349,
8,
549,
9,
272,
327,
16485,
314,
1300,
1021,
2929,
63,
13066,
365,
440,
30241,
12,
1325,
2348,
652,
272,
327,
365,
715,
701,
849,
14,
272,
2929,
63,
13066,
275,
445,
10349,
8,
549,
9,
272,
4458,
63,
1328,
275,
6140,
342,
1362,
339,
347,
636,
826,
721,
277,
12,
1011,
829,
304,
268,
13857,
340,
4775,
14,
362,
360,
751,
63,
2966,
63,
561,
297,
488,
9,
365,
440,
488,
26,
288,
3598,
14,
4050,
480,
751,
63,
2966,
63,
561,
965,
2757,
8717,
701,
922,
63,
578,
14,
710,
60,
2574,
2725,
911,
506,
5525,
4765,
13413,
9,
398,
1613,
8,
23879,
8529,
13200,
12,
277,
2843,
826,
14155,
829,
9,
398,
327,
2793,
1133,
675,
314,
284,
1548,
12420,
3016,
880,
626,
922,
4967,
10621,
1133,
267,
327,
22514,
1915,
267,
984,
14,
476,
301,
13316,
6992,
275,
221,
427,
17565,
66,
14,
31602,
20098,
8,
2326,
63,
5512,
29,
277,
14,
7120,
12,
6163,
818,
29,
277,
14,
88,
632,
12,
6163,
1240,
63,
10511,
29,
277,
14,
10511,
9,
339,
347,
4205,
63,
1274,
63,
3112,
8,
277,
304,
267,
986,
339,
347,
4205,
63,
5615,
2932,
8,
277,
304,
267,
1613,
8,
23879,
8529,
13200,
12,
291,
680,
826,
63,
5615,
2932,
342,
267,
291,
14,
2683,
63,
5615,
2932,
8,
27395,
22745,
2932,
9,
339,
347,
636,
1250,
721,
277,
12,
1406,
4581,
2257,
63,
561,
29,
403,
12,
859,
29,
403,
12,
7283,
29,
403,
12,
326,
3464,
63,
4631,
29,
17,
12,
2288,
63,
561,
29,
403,
12,
6555,
63,
2469,
29,
403,
304,
267,
408,
30120,
314,
12777,
12693,
14,
398,
636,
1250,
721,
277,
12,
1291,
4581,
1832,
63,
561,
29,
403,
12,
578,
29,
403,
12,
5869,
29,
403,
9,
1035,
7707,
267,
314,
12693,
5218,
543,
314,
1627,
2257,
436,
2288,
10747,
12,
436,
267,
14190,
870,
282,
1406,
1059,
737,
14210,
14,
398,
710,
5218,
883,
506,
26662,
22225,
15,
271,
18218,
1808,
314,
267,
7283,
63,
632,
2225,
14,
961,
6127,
1265,
370,
7485,
2331,
282,
5218,
1202,
267,
367,
10201,
26662,
14,
398,
9738,
12,
627,
10885,
10,
900,
1265,
1240,
314,
5218,
1265,
883,
4278,
314,
1453,
267,
1174,
402,
7283,
63,
632,
543,
314,
2716,
4252,
2725,
283,
5869,
1370,
2104,
267,
2893,
12,
340,
1265,
663,
7283,
818,
641,
543,
3531,
8529,
14,
5869,
63,
632,
275,
715,
12,
1265,
267,
883,
5139,
1172,
282,
2488,
1240,
1736,
701,
10663,
652,
465,
3531,
8529,
8,
5869,
29,
797,
680,
267,
408,
398,
327,
982,
314,
922,
965,
19136,
652,
2331,
12,
2621,
13437,
267,
340,
440,
291,
14,
18757,
63,
2682,
26,
288,
372,
398,
327,
11514,
20100,
687,
12777,
818,
663,
642,
3305,
12,
880,
314,
5218,
883,
1133,
267,
327,
295,
13,
4200,
334,
390,
5920,
642,
1750,
737,
314,
1343,
402,
12777,
818,
680,
267,
291,
14,
2224,
63,
2131,
275,
756,
398,
327,
9812,
314,
7283,
2725,
370,
4278,
314,
2288,
636,
5869,
63,
632,
267,
340,
7283,
503,
334,
5869,
1137,
378,
436,
291,
14,
5869,
63,
632,
304,
288,
372,
398,
340,
291,
14,
1989,
63,
6407,
26,
288,
291,
14,
409,
63,
6407,
63,
18452,
342,
398,
327,
291,
14,
13066,
365,
2599,
9235,
267,
340,
1406,
26,
288,
291,
14,
1753,
63,
13066,
18,
275,
291,
14,
13066,
18,
288,
291,
14,
13066,
18,
275,
291,
14,
13066,
18,
435,
1557,
78,
7,
435,
1406,
435,
1557,
78,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
xyzoer/pyspider
|
pyspider/webui/result.py
|
32
|
1787
|
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Binux<i@binux.me>
# http://binux.me
# Created on 2014-10-19 16:23:55
from __future__ import unicode_literals
from flask import render_template, request, json
from flask import Response
from .app import app
from pyspider.libs import result_dump
@app.route('/results')
def result():
resultdb = app.config['resultdb']
project = request.args.get('project')
offset = int(request.args.get('offset', 0))
limit = int(request.args.get('limit', 20))
count = resultdb.count(project)
results = list(resultdb.select(project, offset=offset, limit=limit))
return render_template(
"result.html", count=count, results=results,
result_formater=result_dump.result_formater,
project=project, offset=offset, limit=limit, json=json
)
@app.route('/results/dump/<project>.<_format>')
def dump_result(project, _format):
resultdb = app.config['resultdb']
# force update project list
resultdb.get(project, 'any')
if project not in resultdb.projects:
return "no such project.", 404
offset = int(request.args.get('offset', 0))
limit = int(request.args.get('limit', 0))
results = resultdb.select(project, offset=offset, limit=limit)
if _format == 'json':
valid = request.args.get('style', 'rows') == 'full'
return Response(result_dump.dump_as_json(results, valid),
mimetype='application/json')
elif _format == 'txt':
return Response(result_dump.dump_as_txt(results),
mimetype='text/plain')
elif _format == 'csv':
return Response(result_dump.dump_as_csv(results),
mimetype='text/csv')
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
6695,
26,
663,
10844,
5584,
29,
20,
6714,
29,
20,
23014,
29,
20,
16328,
29,
11864,
289,
10945,
29,
1624,
24,
26,
199,
3,
6529,
26,
699,
7226,
28,
73,
32,
1393,
2521,
14,
278,
30,
199,
3,
260,
1455,
921,
1393,
2521,
14,
278,
199,
3,
18208,
641,
6927,
13,
709,
13,
1167,
3193,
26,
1789,
26,
1229,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
7209,
492,
3795,
63,
1160,
12,
1056,
12,
2022,
199,
504,
7209,
492,
7232,
199,
504,
1275,
571,
492,
1145,
199,
504,
10382,
12508,
14,
8450,
492,
754,
63,
2724,
421,
199,
32,
571,
14,
4449,
2336,
2604,
358,
199,
318,
754,
837,
272,
754,
697,
275,
1145,
14,
888,
459,
1099,
697,
418,
272,
2199,
275,
1056,
14,
589,
14,
362,
360,
1715,
358,
272,
3268,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
2743,
297,
378,
430,
272,
2304,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
3097,
297,
3388,
430,
339,
2338,
275,
754,
697,
14,
835,
8,
1715,
9,
272,
2058,
275,
769,
8,
1099,
697,
14,
2416,
8,
1715,
12,
3268,
29,
2743,
12,
2304,
29,
3097,
430,
339,
372,
3795,
63,
1160,
8,
267,
298,
1099,
14,
1360,
401,
2338,
29,
835,
12,
2058,
29,
2604,
12,
267,
754,
63,
964,
6618,
29,
1099,
63,
2724,
14,
1099,
63,
964,
6618,
12,
267,
2199,
29,
1715,
12,
3268,
29,
2743,
12,
2304,
29,
3097,
12,
2022,
29,
1001,
272,
776,
421,
199,
32,
571,
14,
4449,
2336,
2604,
15,
2724,
8316,
1715,
10827,
28,
63,
908,
5971,
199,
318,
5461,
63,
1099,
8,
1715,
12,
485,
908,
304,
272,
754,
697,
275,
1145,
14,
888,
459,
1099,
697,
418,
272,
327,
3542,
1678,
2199,
769,
272,
754,
697,
14,
362,
8,
1715,
12,
283,
1629,
358,
272,
340,
2199,
440,
315,
754,
697,
14,
6776,
26,
267,
372,
298,
889,
4066,
2199,
4765,
7901,
339,
3268,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
2743,
297,
378,
430,
272,
2304,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
3097,
297,
378,
430,
272,
2058,
275,
754,
697,
14,
2416,
8,
1715,
12,
3268,
29,
2743,
12,
2304,
29,
3097,
9,
339,
340,
485,
908,
508,
283,
1001,
356,
267,
1686,
275,
1056,
14,
589,
14,
362,
360,
2487,
297,
283,
3838,
358,
508,
283,
2861,
7,
267,
372,
7232,
8,
1099,
63,
2724,
14,
2724,
63,
305,
63,
1001,
8,
2604,
12,
1686,
395,
717,
12200,
534,
3578,
15,
1001,
358,
272,
916,
485,
908,
508,
283,
2424,
356,
267,
372,
7232,
8,
1099,
63,
2724,
14,
2724,
63,
305,
63,
2424,
8,
2604,
395,
717,
12200,
534,
505,
15,
6104,
358,
272,
916,
485,
908,
508,
283,
4737,
356,
267,
372,
7232,
8,
1099,
63,
2724,
14,
2724,
63,
305,
63,
4737,
8,
2604,
395,
717,
12200,
534,
505,
15,
4737,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
6695,
26,
663,
10844,
5584,
29,
20,
6714,
29,
20,
23014,
29,
20,
16328,
29,
11864,
289,
10945,
29,
1624,
24,
26,
199,
3,
6529,
26,
699,
7226,
28,
73,
32,
1393,
2521,
14,
278,
30,
199,
3,
260,
1455,
921,
1393,
2521,
14,
278,
199,
3,
18208,
641,
6927,
13,
709,
13,
1167,
3193,
26,
1789,
26,
1229,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
7209,
492,
3795,
63,
1160,
12,
1056,
12,
2022,
199,
504,
7209,
492,
7232,
199,
504,
1275,
571,
492,
1145,
199,
504,
10382,
12508,
14,
8450,
492,
754,
63,
2724,
421,
199,
32,
571,
14,
4449,
2336,
2604,
358,
199,
318,
754,
837,
272,
754,
697,
275,
1145,
14,
888,
459,
1099,
697,
418,
272,
2199,
275,
1056,
14,
589,
14,
362,
360,
1715,
358,
272,
3268,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
2743,
297,
378,
430,
272,
2304,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
3097,
297,
3388,
430,
339,
2338,
275,
754,
697,
14,
835,
8,
1715,
9,
272,
2058,
275,
769,
8,
1099,
697,
14,
2416,
8,
1715,
12,
3268,
29,
2743,
12,
2304,
29,
3097,
430,
339,
372,
3795,
63,
1160,
8,
267,
298,
1099,
14,
1360,
401,
2338,
29,
835,
12,
2058,
29,
2604,
12,
267,
754,
63,
964,
6618,
29,
1099,
63,
2724,
14,
1099,
63,
964,
6618,
12,
267,
2199,
29,
1715,
12,
3268,
29,
2743,
12,
2304,
29,
3097,
12,
2022,
29,
1001,
272,
776,
421,
199,
32,
571,
14,
4449,
2336,
2604,
15,
2724,
8316,
1715,
10827,
28,
63,
908,
5971,
199,
318,
5461,
63,
1099,
8,
1715,
12,
485,
908,
304,
272,
754,
697,
275,
1145,
14,
888,
459,
1099,
697,
418,
272,
327,
3542,
1678,
2199,
769,
272,
754,
697,
14,
362,
8,
1715,
12,
283,
1629,
358,
272,
340,
2199,
440,
315,
754,
697,
14,
6776,
26,
267,
372,
298,
889,
4066,
2199,
4765,
7901,
339,
3268,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
2743,
297,
378,
430,
272,
2304,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
3097,
297,
378,
430,
272,
2058,
275,
754,
697,
14,
2416,
8,
1715,
12,
3268,
29,
2743,
12,
2304,
29,
3097,
9,
339,
340,
485,
908,
508,
283,
1001,
356,
267,
1686,
275,
1056,
14,
589,
14,
362,
360,
2487,
297,
283,
3838,
358,
508,
283,
2861,
7,
267,
372,
7232,
8,
1099,
63,
2724,
14,
2724,
63,
305,
63,
1001,
8,
2604,
12,
1686,
395,
717,
12200,
534,
3578,
15,
1001,
358,
272,
916,
485,
908,
508,
283,
2424,
356,
267,
372,
7232,
8,
1099,
63,
2724,
14,
2724,
63,
305,
63,
2424,
8,
2604,
395,
717,
12200,
534,
505,
15,
6104,
358,
272,
916,
485,
908,
508,
283,
4737,
356,
267,
372,
7232,
8,
1099,
63,
2724,
14,
2724,
63,
305,
63,
4737,
8,
2604,
395,
717,
12200,
534,
505,
15,
4737,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pillip8282/TizenRT
|
external/protobuf/conformance/update_failure_list.py
|
41
|
2898
|
#!/usr/bin/env python
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
# https://developers.google.com/protocol-buffers/
#
# 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.
"""Script to update a failure list file to add/remove failures.
This is sort of like comm(1), except it recognizes comments and ignores them.
"""
import argparse
parser = argparse.ArgumentParser(
description='Adds/removes failures from the failure list.')
parser.add_argument('filename', type=str, help='failure list file to update')
parser.add_argument('--add', dest='add_list', action='append')
parser.add_argument('--remove', dest='remove_list', action='append')
args = parser.parse_args()
add_set = set()
remove_set = set()
for add_file in (args.add_list or []):
with open(add_file) as f:
for line in f:
add_set.add(line)
for remove_file in (args.remove_list or []):
with open(remove_file) as f:
for line in f:
if line in add_set:
raise Exception("Asked to both add and remove test: " + line)
remove_set.add(line.strip())
add_list = sorted(add_set, reverse=True)
with open(args.filename) as in_file:
existing_list = in_file.read()
with open(args.filename, "w") as f:
for line in existing_list.splitlines(True):
test = line.split("#")[0].strip()
while len(add_list) > 0 and test > add_list[-1]:
f.write(add_list.pop())
if test not in remove_set:
f.write(line)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
4178,
921,
23826,
14,
3098,
14,
957,
15,
3922,
13,
17389,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
5229,
370,
1678,
282,
5988,
769,
570,
370,
1050,
15,
2168,
9081,
14,
199,
199,
2765,
365,
4069,
402,
2839,
1923,
8,
17,
395,
871,
652,
17319,
6491,
6786,
436,
24010,
3062,
14,
199,
624,
199,
199,
646,
7534,
199,
199,
2087,
275,
7534,
14,
10730,
8,
272,
1369,
534,
14995,
15,
264,
4912,
9081,
687,
314,
5988,
769,
2659,
199,
2087,
14,
525,
63,
2094,
360,
1501,
297,
730,
29,
495,
12,
1720,
534,
5328,
769,
570,
370,
1678,
358,
199,
2087,
14,
525,
63,
2094,
4517,
525,
297,
2053,
534,
525,
63,
513,
297,
1595,
534,
740,
358,
199,
2087,
14,
525,
63,
2094,
4517,
2168,
297,
2053,
534,
2168,
63,
513,
297,
1595,
534,
740,
358,
199,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
525,
63,
409,
275,
663,
342,
199,
2168,
63,
409,
275,
663,
342,
199,
199,
509,
1050,
63,
493,
315,
334,
589,
14,
525,
63,
513,
503,
12319,
523,
543,
1551,
8,
525,
63,
493,
9,
465,
289,
26,
272,
367,
1004,
315,
289,
26,
489,
1050,
63,
409,
14,
525,
8,
604,
9,
199,
199,
509,
2813,
63,
493,
315,
334,
589,
14,
2168,
63,
513,
503,
12319,
523,
543,
1551,
8,
2168,
63,
493,
9,
465,
289,
26,
272,
367,
1004,
315,
289,
26,
489,
340,
1004,
315,
1050,
63,
409,
26,
267,
746,
2186,
480,
25525,
379,
370,
3865,
1050,
436,
2813,
511,
26,
298,
435,
1004,
9,
489,
2813,
63,
409,
14,
525,
8,
604,
14,
1913,
1012,
199,
199,
525,
63,
513,
275,
3355,
8,
525,
63,
409,
12,
3837,
29,
549,
9,
199,
199,
1045,
1551,
8,
589,
14,
1501,
9,
465,
315,
63,
493,
26,
272,
3411,
63,
513,
275,
315,
63,
493,
14,
739,
342,
199,
199,
1045,
1551,
8,
589,
14,
1501,
12,
298,
87,
531,
465,
289,
26,
523,
367,
1004,
315,
3411,
63,
513,
14,
7644,
8,
549,
304,
272,
511,
275,
1004,
14,
1294,
10064,
9981,
16,
1055,
1913,
342,
272,
1830,
822,
8,
525,
63,
513,
9,
690,
378,
436,
511,
690,
1050,
63,
513,
1988,
17,
2189,
489,
289,
14,
952,
8,
525,
63,
513,
14,
1935,
1012,
272,
340,
511,
440,
315,
2813,
63,
409,
26,
489,
289,
14,
952,
8,
604,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
4178,
921,
23826,
14,
3098,
14,
957,
15,
3922,
13,
17389,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
5229,
370,
1678,
282,
5988,
769,
570,
370,
1050,
15,
2168,
9081,
14,
199,
199,
2765,
365,
4069,
402,
2839,
1923,
8,
17,
395,
871,
652,
17319,
6491,
6786,
436,
24010,
3062,
14,
199,
624,
199,
199,
646,
7534,
199,
199,
2087,
275,
7534,
14,
10730,
8,
272,
1369,
534,
14995,
15,
264,
4912,
9081,
687,
314,
5988,
769,
2659,
199,
2087,
14,
525,
63,
2094,
360,
1501,
297,
730,
29,
495,
12,
1720,
534,
5328,
769,
570,
370,
1678,
358,
199,
2087,
14,
525,
63,
2094,
4517,
525,
297,
2053,
534,
525,
63,
513,
297,
1595,
534,
740,
358,
199,
2087,
14,
525,
63,
2094,
4517,
2168,
297,
2053,
534,
2168,
63,
513,
297,
1595,
534,
740,
358,
199,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
525,
63,
409,
275,
663,
342,
199,
2168,
63,
409,
275,
663,
342,
199,
199,
509,
1050,
63,
493,
315,
334,
589,
14,
525,
63,
513,
503,
12319,
523,
543,
1551,
8,
525,
63,
493,
9,
465,
289,
26,
272,
367,
1004,
315,
289,
26,
489,
1050,
63,
409,
14,
525,
8,
604,
9,
199,
199,
509,
2813,
63,
493,
315,
334,
589,
14,
2168,
63,
513,
503,
12319,
523,
543,
1551,
8,
2168,
63,
493,
9,
465,
289,
26,
272,
367,
1004,
315,
289,
26,
489,
340,
1004,
315,
1050,
63,
409,
26,
267,
746,
2186,
480,
25525,
379,
370,
3865,
1050,
436,
2813,
511,
26,
298,
435,
1004,
9,
489,
2813,
63,
409,
14,
525,
8,
604,
14,
1913,
1012,
199,
199,
525,
63,
513,
275,
3355,
8,
525,
63,
409,
12,
3837,
29,
549,
9,
199,
199,
1045,
1551,
8,
589,
14,
1501,
9,
465,
315,
63,
493,
26,
272,
3411,
63,
513,
275,
315,
63,
493,
14,
739,
342,
199,
199,
1045,
1551,
8,
589,
14,
1501,
12,
298,
87,
531,
465,
289,
26,
523,
367,
1004,
315,
3411,
63,
513,
14,
7644,
8,
549,
304,
272,
511,
275,
1004,
14,
1294,
10064,
9981,
16,
1055,
1913,
342,
272,
1830,
822,
8,
525,
63,
513,
9,
690,
378,
436,
511,
690,
1050,
63,
513,
1988,
17,
2189,
489,
289,
14,
952,
8,
525,
63,
513,
14,
1935,
1012,
272,
340,
511,
440,
315,
2813,
63,
409,
26,
489,
289,
14,
952,
8,
604,
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,
0
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,
0
] |
EvanK/ansible
|
lib/ansible/modules/cloud/openstack/os_subnets_facts.py
|
31
|
4515
|
#!/usr/bin/python
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: os_subnets_facts
short_description: Retrieve facts about one or more OpenStack subnets.
version_added: "2.0"
author: "Davide Agnello (@dagnello)"
description:
- Retrieve facts about one or more subnets from OpenStack.
requirements:
- "python >= 2.7"
- "openstacksdk"
options:
name:
description:
- Name or ID of the subnet.
- Alias 'subnet' added in version 2.8.
required: false
aliases: ['subnet']
filters:
description:
- A dictionary of meta data to use for further filtering. Elements of
this dictionary may be additional dictionaries.
required: false
availability_zone:
description:
- Ignored. Present for backwards compatibility
required: false
extends_documentation_fragment: openstack
'''
EXAMPLES = '''
- name: Gather facts about previously created subnets
os_subnets_facts:
auth:
auth_url: https://identity.example.com
username: user
password: password
project_name: someproject
- name: Show openstack subnets
debug:
var: openstack_subnets
- name: Gather facts about a previously created subnet by name
os_subnets_facts:
auth:
auth_url: https://identity.example.com
username: user
password: password
project_name: someproject
name: subnet1
- name: Show openstack subnets
debug:
var: openstack_subnets
- name: Gather facts about a previously created subnet with filter
# Note: name and filters parameters are not mutually exclusive
os_subnets_facts:
auth:
auth_url: https://identity.example.com
username: user
password: password
project_name: someproject
filters:
tenant_id: 55e2ce24b2a245b09f181bf025724cbe
- name: Show openstack subnets
debug:
var: openstack_subnets
'''
RETURN = '''
openstack_subnets:
description: has all the openstack facts about the subnets
returned: always, but can be null
type: complex
contains:
id:
description: Unique UUID.
returned: success
type: str
name:
description: Name given to the subnet.
returned: success
type: str
network_id:
description: Network ID this subnet belongs in.
returned: success
type: str
cidr:
description: Subnet's CIDR.
returned: success
type: str
gateway_ip:
description: Subnet's gateway ip.
returned: success
type: str
enable_dhcp:
description: DHCP enable flag for this subnet.
returned: success
type: bool
ip_version:
description: IP version for this subnet.
returned: success
type: int
tenant_id:
description: Tenant id associated with this subnet.
returned: success
type: str
dns_nameservers:
description: DNS name servers for this subnet.
returned: success
type: list of strings
allocation_pools:
description: Allocation pools associated with this subnet.
returned: success
type: list of dicts
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_cloud_from_module
def main():
argument_spec = openstack_full_argument_spec(
name=dict(required=False, default=None, aliases=['subnet']),
filters=dict(required=False, type='dict', default=None)
)
module = AnsibleModule(argument_spec)
sdk, cloud = openstack_cloud_from_module(module)
try:
subnets = cloud.search_subnets(module.params['name'],
module.params['filters'])
module.exit_json(changed=False, ansible_facts=dict(
openstack_subnets=subnets))
except sdk.exceptions.OpenStackCloudException as e:
module.fail_json(msg=str(e))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
14967,
63,
5047,
199,
3612,
63,
1802,
26,
13939,
9036,
3595,
1373,
503,
1655,
14260,
18709,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
298,
25014,
5624,
437,
784,
3312,
8593,
7406,
2715,
320,
2924,
199,
1802,
26,
272,
446,
13939,
9036,
3595,
1373,
503,
1655,
18709,
687,
14260,
14,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
23,
2,
272,
446,
298,
8512,
9277,
2,
199,
1419,
26,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
503,
2870,
402,
314,
6303,
14,
267,
446,
24777,
283,
5327,
7,
3483,
315,
1015,
499,
14,
24,
14,
1362,
1415,
26,
3055,
1362,
5481,
26,
788,
5327,
418,
2043,
4766,
26,
1362,
1369,
26,
267,
446,
437,
2600,
402,
3404,
666,
370,
675,
367,
9848,
14545,
14,
221,
6566,
83,
402,
881,
642,
2600,
1443,
506,
4722,
11196,
14,
1362,
1415,
26,
3055,
2043,
14962,
63,
2619,
26,
1362,
1369,
26,
2126,
446,
27662,
14,
5543,
1150,
367,
8552,
7163,
1362,
1415,
26,
3055,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
19634,
9036,
3595,
10889,
2737,
18709,
523,
747,
63,
14967,
63,
5047,
26,
272,
1790,
26,
489,
1790,
63,
633,
26,
4178,
921,
5582,
14,
2694,
14,
957,
489,
3434,
26,
922,
489,
2505,
26,
2505,
489,
2199,
63,
354,
26,
2005,
1715,
199,
199,
13,
536,
26,
12968,
13869,
18709,
523,
3105,
26,
272,
2729,
26,
13869,
63,
14967,
199,
199,
13,
536,
26,
19634,
9036,
3595,
282,
10889,
2737,
6303,
701,
536,
523,
747,
63,
14967,
63,
5047,
26,
272,
1790,
26,
489,
1790,
63,
633,
26,
4178,
921,
5582,
14,
2694,
14,
957,
489,
3434,
26,
922,
489,
2505,
26,
2505,
489,
2199,
63,
354,
26,
2005,
1715,
272,
536,
26,
6303,
17,
199,
199,
13,
536,
26,
12968,
13869,
18709,
523,
3105,
26,
272,
2729,
26,
13869,
63,
14967,
199,
199,
13,
536,
26,
19634,
9036,
3595,
282,
10889,
2737,
6303,
543,
2457,
523,
327,
3390,
26,
536,
436,
4766,
2633,
787,
440,
16108,
13914,
523,
747,
63,
14967,
63,
5047,
26,
272,
1790,
26,
489,
1790,
63,
633,
26,
4178,
921,
5582,
14,
2694,
14,
957,
489,
3434,
26,
922,
489,
2505,
26,
2505,
489,
2199,
63,
354,
26,
2005,
1715,
272,
4766,
26,
489,
8261,
63,
344,
26,
12766,
69,
18,
301,
1194,
66,
18,
65,
11677,
66,
1643,
70,
12851,
4361,
16,
11551,
1194,
67,
1235,
199,
199,
13,
536,
26,
12968,
13869,
18709,
523,
3105,
26,
272,
2729,
26,
13869,
63,
14967,
199,
2344,
199,
199,
9677,
275,
1449,
199,
8512,
63,
14967,
26,
272,
1369,
26,
965,
1006,
314,
13869,
9036,
3595,
314,
18709,
272,
2138,
26,
3544,
12,
1325,
883,
506,
2973,
272,
730,
26,
6114,
272,
3509,
26,
267,
1305,
26,
288,
1369,
26,
18276,
11134,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
536,
26,
288,
1369,
26,
2812,
1627,
370,
314,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
2784,
63,
344,
26,
288,
1369,
26,
7220,
2870,
642,
6303,
15006,
315,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
16770,
26,
288,
1369,
26,
4804,
846,
1159,
29215,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
10391,
63,
711,
26,
288,
1369,
26,
4804,
846,
1159,
10391,
3384,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
4756,
63,
10801,
26,
288,
1369,
26,
26821,
4756,
3305,
367,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
2155,
267,
3384,
63,
1023,
26,
288,
1369,
26,
3531,
1015,
367,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
1109,
267,
8261,
63,
344,
26,
288,
1369,
26,
377,
287,
867,
1305,
4568,
543,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
6715,
63,
28620,
26,
288,
1369,
26,
10237,
536,
8037,
367,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
769,
402,
3326,
267,
18723,
63,
12406,
26,
288,
1369,
26,
4580,
1985,
20092,
4568,
543,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
769,
402,
10809,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
8512,
492,
13869,
63,
2861,
63,
2094,
63,
1650,
12,
13869,
63,
4091,
63,
504,
63,
578,
421,
199,
318,
2446,
837,
339,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
536,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
12,
5481,
2968,
5327,
3815,
267,
4766,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
807,
297,
849,
29,
403,
9,
272,
776,
272,
859,
275,
6953,
8,
2094,
63,
1650,
9,
339,
13628,
12,
8002,
275,
13869,
63,
4091,
63,
504,
63,
578,
8,
578,
9,
272,
862,
26,
267,
18709,
275,
8002,
14,
1733,
63,
14967,
8,
578,
14,
1162,
459,
354,
995,
4318,
859,
14,
1162,
459,
4273,
1105,
267,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
12,
3242,
63,
5047,
29,
807,
8,
288,
13869,
63,
14967,
29,
14967,
430,
339,
871,
13628,
14,
3924,
14,
26208,
9089,
1726,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
14967,
63,
5047,
199,
3612,
63,
1802,
26,
13939,
9036,
3595,
1373,
503,
1655,
14260,
18709,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
298,
25014,
5624,
437,
784,
3312,
8593,
7406,
2715,
320,
2924,
199,
1802,
26,
272,
446,
13939,
9036,
3595,
1373,
503,
1655,
18709,
687,
14260,
14,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
23,
2,
272,
446,
298,
8512,
9277,
2,
199,
1419,
26,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
503,
2870,
402,
314,
6303,
14,
267,
446,
24777,
283,
5327,
7,
3483,
315,
1015,
499,
14,
24,
14,
1362,
1415,
26,
3055,
1362,
5481,
26,
788,
5327,
418,
2043,
4766,
26,
1362,
1369,
26,
267,
446,
437,
2600,
402,
3404,
666,
370,
675,
367,
9848,
14545,
14,
221,
6566,
83,
402,
881,
642,
2600,
1443,
506,
4722,
11196,
14,
1362,
1415,
26,
3055,
2043,
14962,
63,
2619,
26,
1362,
1369,
26,
2126,
446,
27662,
14,
5543,
1150,
367,
8552,
7163,
1362,
1415,
26,
3055,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
19634,
9036,
3595,
10889,
2737,
18709,
523,
747,
63,
14967,
63,
5047,
26,
272,
1790,
26,
489,
1790,
63,
633,
26,
4178,
921,
5582,
14,
2694,
14,
957,
489,
3434,
26,
922,
489,
2505,
26,
2505,
489,
2199,
63,
354,
26,
2005,
1715,
199,
199,
13,
536,
26,
12968,
13869,
18709,
523,
3105,
26,
272,
2729,
26,
13869,
63,
14967,
199,
199,
13,
536,
26,
19634,
9036,
3595,
282,
10889,
2737,
6303,
701,
536,
523,
747,
63,
14967,
63,
5047,
26,
272,
1790,
26,
489,
1790,
63,
633,
26,
4178,
921,
5582,
14,
2694,
14,
957,
489,
3434,
26,
922,
489,
2505,
26,
2505,
489,
2199,
63,
354,
26,
2005,
1715,
272,
536,
26,
6303,
17,
199,
199,
13,
536,
26,
12968,
13869,
18709,
523,
3105,
26,
272,
2729,
26,
13869,
63,
14967,
199,
199,
13,
536,
26,
19634,
9036,
3595,
282,
10889,
2737,
6303,
543,
2457,
523,
327,
3390,
26,
536,
436,
4766,
2633,
787,
440,
16108,
13914,
523,
747,
63,
14967,
63,
5047,
26,
272,
1790,
26,
489,
1790,
63,
633,
26,
4178,
921,
5582,
14,
2694,
14,
957,
489,
3434,
26,
922,
489,
2505,
26,
2505,
489,
2199,
63,
354,
26,
2005,
1715,
272,
4766,
26,
489,
8261,
63,
344,
26,
12766,
69,
18,
301,
1194,
66,
18,
65,
11677,
66,
1643,
70,
12851,
4361,
16,
11551,
1194,
67,
1235,
199,
199,
13,
536,
26,
12968,
13869,
18709,
523,
3105,
26,
272,
2729,
26,
13869,
63,
14967,
199,
2344,
199,
199,
9677,
275,
1449,
199,
8512,
63,
14967,
26,
272,
1369,
26,
965,
1006,
314,
13869,
9036,
3595,
314,
18709,
272,
2138,
26,
3544,
12,
1325,
883,
506,
2973,
272,
730,
26,
6114,
272,
3509,
26,
267,
1305,
26,
288,
1369,
26,
18276,
11134,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
536,
26,
288,
1369,
26,
2812,
1627,
370,
314,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
2784,
63,
344,
26,
288,
1369,
26,
7220,
2870,
642,
6303,
15006,
315,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
16770,
26,
288,
1369,
26,
4804,
846,
1159,
29215,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
10391,
63,
711,
26,
288,
1369,
26,
4804,
846,
1159,
10391,
3384,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
4756,
63,
10801,
26,
288,
1369,
26,
26821,
4756,
3305,
367,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
2155,
267,
3384,
63,
1023,
26,
288,
1369,
26,
3531,
1015,
367,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
1109,
267,
8261,
63,
344,
26,
288,
1369,
26,
377,
287,
867,
1305,
4568,
543,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
620,
267,
6715,
63,
28620,
26,
288,
1369,
26,
10237,
536,
8037,
367,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
769,
402,
3326,
267,
18723,
63,
12406,
26,
288,
1369,
26,
4580,
1985,
20092,
4568,
543,
642,
6303,
14,
288,
2138,
26,
3182,
288,
730,
26,
769,
402,
10809,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
8512,
492,
13869,
63,
2861,
63,
2094,
63,
1650,
12,
13869,
63,
4091,
63,
504,
63,
578,
421,
199,
318,
2446,
837,
339,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
536,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
12,
5481,
2968,
5327,
3815,
267,
4766,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
807,
297,
849,
29,
403,
9,
272,
776,
272,
859,
275,
6953,
8,
2094,
63,
1650,
9,
339,
13628,
12,
8002,
275,
13869,
63,
4091,
63,
504,
63,
578,
8,
578,
9,
272,
862,
26,
267,
18709,
275,
8002,
14,
1733,
63,
14967,
8,
578,
14,
1162,
459,
354,
995,
4318,
859,
14,
1162,
459,
4273,
1105,
267,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
12,
3242,
63,
5047,
29,
807,
8,
288,
13869,
63,
14967,
29,
14967,
430,
339,
871,
13628,
14,
3924,
14,
26208,
9089,
1726,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
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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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,
0,
0,
0,
0,
0
] |
chidea/GoPythonDLLWrapper
|
bin/lib/site-packages/pkg_resources/_vendor/packaging/_structures.py
|
906
|
1809
|
# Copyright 2014 Donald Stufft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function
class Infinity(object):
def __repr__(self):
return "Infinity"
def __hash__(self):
return hash(repr(self))
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __eq__(self, other):
return isinstance(other, self.__class__)
def __ne__(self, other):
return not isinstance(other, self.__class__)
def __gt__(self, other):
return True
def __ge__(self, other):
return True
def __neg__(self):
return NegativeInfinity
Infinity = Infinity()
class NegativeInfinity(object):
def __repr__(self):
return "-Infinity"
def __hash__(self):
return hash(repr(self))
def __lt__(self, other):
return True
def __le__(self, other):
return True
def __eq__(self, other):
return isinstance(other, self.__class__)
def __ne__(self, other):
return not isinstance(other, self.__class__)
def __gt__(self, other):
return False
def __ge__(self, other):
return False
def __neg__(self):
return Infinity
NegativeInfinity = NegativeInfinity()
|
mit
|
[
3,
1898,
6927,
7529,
27075,
1933,
3043,
84,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
421,
199,
533,
1010,
9693,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
32548,
14660,
199,
199,
14660,
275,
1010,
9693,
342,
421,
199,
533,
32548,
14660,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3905,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
1010,
9693,
199,
199,
15562,
14660,
275,
32548,
14660,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6927,
7529,
27075,
1933,
3043,
84,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
421,
199,
533,
1010,
9693,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
32548,
14660,
199,
199,
14660,
275,
1010,
9693,
342,
421,
199,
533,
32548,
14660,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3905,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
1010,
9693,
199,
199,
15562,
14660,
275,
32548,
14660,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jtoppins/beaker
|
IntegrationTests/src/bkr/inttest/client/test_workflow.py
|
1
|
4319
|
# 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.
import unittest2 as unittest
import re
from bkr.client import BeakerWorkflow, BeakerRecipe
class WorkflowTest(unittest.TestCase):
def setUp(self):
self.command = BeakerWorkflow(None)
def test_processPartitions(self):
recipe = BeakerRecipe()
recipe.addPartition(name='/mnt/block1',type='part', fs='ext3', size=1024)
xml = recipe.toxml()
self.assertEquals(xml, '<recipe whiteboard="">'
'<distroRequires>'
'<and/>'
'</distroRequires>'
'<hostRequires/>'
'<repos/>'
'<partitions>'
'<partition fs="ext3" name="/mnt/block1" size="1024" type="part"/>'
'</partitions>'
'</recipe>')
def test_processTemplate_minimal_recipe(self):
recipeTemplate = BeakerRecipe()
recipe = self.command.processTemplate(recipeTemplate,
[{'name': '/example', 'arches': []}])
xml = recipe.toxml()
self.assertEquals(xml, '<recipe whiteboard="">'
'<distroRequires>'
'<and/>'
'</distroRequires>'
'<hostRequires/>'
'<repos/>'
'<partitions/>'
'<task name="/distribution/install" role="STANDALONE">'
'<params/>'
'</task>'
'<task name="/example" role="STANDALONE">'
'<params/>'
'</task>'
'</recipe>')
# https://bugzilla.redhat.com/show_bug.cgi?id=723789
def test_processTemplate_does_not_produce_duplicates(self):
recipeTemplate = BeakerRecipe()
# with passed-in distroRequires XML
recipe = self.command.processTemplate(recipeTemplate,
requestedTasks=[{'name': '/example', 'arches': []}],
distroRequires='<distroRequires><distro_name op="=" value="RHEL99-U1" /></distroRequires>')
xml = recipe.toxml(prettyxml=True)
self.assertEquals(len(re.findall('<distro_name', xml)), 1, xml)
# with passed-in hostRequires XML
recipe = self.command.processTemplate(recipeTemplate,
requestedTasks=[{'name': '/example', 'arches': []}],
hostRequires='<hostRequires><hostname op="=" value="lolcat.example.invalid" /></hostRequires>')
xml = recipe.toxml(prettyxml=True)
self.assertEquals(len(re.findall('<hostname', xml)), 1, xml)
# with distroRequires and hostRequires in the template
recipeTemplate.addBaseRequires(distro='RHEL99-U1', machine='lolcat.example.invalid')
recipe = self.command.processTemplate(recipeTemplate,
requestedTasks=[{'name': '/example', 'arches': []}])
xml = recipe.toxml(prettyxml=True)
self.assertEquals(len(re.findall('<distro_name', xml)), 1, xml)
self.assertEquals(len(re.findall('<hostname', xml)), 1, xml)
# https://bugzilla.redhat.com/show_bug.cgi?id=1200427
def test_distro_wildcard(self):
recipeTemplate = BeakerRecipe()
recipeTemplate.addBaseRequires(distro='RHEL-7.1%')
recipe = self.command.processTemplate(recipeTemplate,
requestedTasks=[{'name': '/example', 'arches': []}])
xml = recipe.toxml(prettyxml=True)
self.assertIn('<distro_name op="like" value="RHEL-7.1%"/>', xml)
# https://bugzilla.redhat.com/show_bug.cgi?id=1010355
def test_hostrequire_accepts_like_operator(self):
recipeTemplate = BeakerRecipe()
recipeTemplate.addBaseRequires(hostrequire=['hostname like %.khw.%'])
recipe = self.command.processTemplate(recipeTemplate,
requestedTasks=[{'name': '/example', 'arches': []}])
xml = recipe.toxml()
self.assertIn('<hostname op="like" value="%.khw.%"/>', xml)
|
gpl-2.0
|
[
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
646,
2882,
18,
465,
2882,
199,
646,
295,
199,
504,
330,
16779,
14,
1258,
492,
6423,
12630,
17527,
12,
6423,
12630,
25879,
199,
199,
533,
27282,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1531,
275,
6423,
12630,
17527,
8,
403,
9,
339,
347,
511,
63,
1412,
23921,
8,
277,
304,
267,
17121,
275,
6423,
12630,
25879,
342,
267,
17121,
14,
525,
13068,
8,
354,
8805,
20481,
15,
1457,
17,
297,
466,
534,
2064,
297,
7449,
534,
832,
19,
297,
1568,
29,
7727,
9,
267,
2748,
275,
17121,
14,
475,
1652,
342,
267,
291,
14,
2947,
8,
1652,
12,
2650,
13191,
10424,
3576,
9287,
3524,
2079,
2650,
18371,
18153,
3524,
2079,
2650,
460,
3133,
7,
2079,
11936,
18371,
18153,
3524,
2079,
2650,
1102,
18153,
3133,
7,
2079,
2650,
11857,
3133,
7,
2079,
2650,
12553,
3524,
2079,
2650,
5312,
7449,
628,
832,
19,
2,
536,
9555,
20481,
15,
1457,
17,
2,
1568,
628,
7727,
2,
730,
628,
2064,
7897,
7,
2079,
11936,
12553,
3524,
2079,
11936,
13191,
5971,
339,
347,
511,
63,
1412,
4231,
63,
21508,
63,
13191,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
9016,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
342,
267,
291,
14,
2947,
8,
1652,
12,
2650,
13191,
10424,
3576,
9287,
3524,
2079,
2650,
18371,
18153,
3524,
2079,
2650,
460,
3133,
7,
2079,
11936,
18371,
18153,
3524,
2079,
2650,
1102,
18153,
3133,
7,
2079,
2650,
11857,
3133,
7,
2079,
2650,
12553,
3133,
7,
2079,
2650,
1765,
536,
9555,
4972,
15,
3174,
2,
4719,
628,
840,
3649,
748,
4817,
15603,
2079,
2650,
1162,
3133,
7,
2079,
11936,
1765,
3524,
2079,
2650,
1765,
536,
9555,
2694,
2,
4719,
628,
840,
3649,
748,
4817,
15603,
2079,
2650,
1162,
3133,
7,
2079,
11936,
1765,
3524,
2079,
11936,
13191,
5971,
339,
327,
4178,
921,
29220,
14,
17164,
14,
957,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
2819,
1401,
1407,
272,
347,
511,
63,
1412,
4231,
63,
9105,
63,
1397,
63,
7832,
63,
18563,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
398,
327,
543,
3032,
13,
262,
20499,
18153,
4692,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
942,
22140,
355,
20499,
18153,
15829,
18371,
18153,
2535,
18371,
63,
354,
1687,
628,
628,
574,
628,
50,
24771,
1020,
13,
53,
17,
2,
9109,
18371,
18153,
5971,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
18371,
63,
354,
297,
2748,
1826,
413,
12,
2748,
9,
398,
327,
543,
3032,
13,
262,
1591,
18153,
4692,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
942,
22140,
355,
1591,
18153,
15829,
1102,
18153,
2535,
4269,
1687,
628,
628,
574,
628,
320,
76,
3385,
14,
2694,
14,
3197,
2,
9109,
1102,
18153,
5971,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
4269,
297,
2748,
1826,
413,
12,
2748,
9,
398,
327,
543,
20499,
18153,
436,
1591,
18153,
315,
314,
1978,
267,
17121,
4231,
14,
525,
1563,
18153,
8,
18371,
534,
50,
24771,
1020,
13,
53,
17,
297,
6844,
534,
320,
76,
3385,
14,
2694,
14,
3197,
358,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
18371,
63,
354,
297,
2748,
1826,
413,
12,
2748,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
4269,
297,
2748,
1826,
413,
12,
2748,
9,
339,
327,
4178,
921,
29220,
14,
17164,
14,
957,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
713,
7979,
1465,
272,
347,
511,
63,
18371,
63,
16692,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
267,
17121,
4231,
14,
525,
1563,
18153,
8,
18371,
534,
50,
24771,
13,
23,
14,
17,
5,
358,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
4080,
4827,
18371,
63,
354,
1687,
628,
2930,
2,
574,
628,
50,
24771,
13,
23,
14,
17,
5,
7897,
297,
2748,
9,
339,
327,
4178,
921,
29220,
14,
17164,
14,
957,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
4893,
1644,
1229,
272,
347,
511,
63,
1102,
4365,
63,
27692,
63,
2930,
63,
3856,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
267,
17121,
4231,
14,
525,
1563,
18153,
8,
1102,
4365,
2968,
4269,
2839,
10536,
75,
8090,
4111,
1105,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
342,
267,
291,
14,
4080,
4827,
4269,
1687,
628,
2930,
2,
574,
5961,
14,
75,
8090,
4111,
7897,
297,
2748,
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
] |
[
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
646,
2882,
18,
465,
2882,
199,
646,
295,
199,
504,
330,
16779,
14,
1258,
492,
6423,
12630,
17527,
12,
6423,
12630,
25879,
199,
199,
533,
27282,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1531,
275,
6423,
12630,
17527,
8,
403,
9,
339,
347,
511,
63,
1412,
23921,
8,
277,
304,
267,
17121,
275,
6423,
12630,
25879,
342,
267,
17121,
14,
525,
13068,
8,
354,
8805,
20481,
15,
1457,
17,
297,
466,
534,
2064,
297,
7449,
534,
832,
19,
297,
1568,
29,
7727,
9,
267,
2748,
275,
17121,
14,
475,
1652,
342,
267,
291,
14,
2947,
8,
1652,
12,
2650,
13191,
10424,
3576,
9287,
3524,
2079,
2650,
18371,
18153,
3524,
2079,
2650,
460,
3133,
7,
2079,
11936,
18371,
18153,
3524,
2079,
2650,
1102,
18153,
3133,
7,
2079,
2650,
11857,
3133,
7,
2079,
2650,
12553,
3524,
2079,
2650,
5312,
7449,
628,
832,
19,
2,
536,
9555,
20481,
15,
1457,
17,
2,
1568,
628,
7727,
2,
730,
628,
2064,
7897,
7,
2079,
11936,
12553,
3524,
2079,
11936,
13191,
5971,
339,
347,
511,
63,
1412,
4231,
63,
21508,
63,
13191,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
9016,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
342,
267,
291,
14,
2947,
8,
1652,
12,
2650,
13191,
10424,
3576,
9287,
3524,
2079,
2650,
18371,
18153,
3524,
2079,
2650,
460,
3133,
7,
2079,
11936,
18371,
18153,
3524,
2079,
2650,
1102,
18153,
3133,
7,
2079,
2650,
11857,
3133,
7,
2079,
2650,
12553,
3133,
7,
2079,
2650,
1765,
536,
9555,
4972,
15,
3174,
2,
4719,
628,
840,
3649,
748,
4817,
15603,
2079,
2650,
1162,
3133,
7,
2079,
11936,
1765,
3524,
2079,
2650,
1765,
536,
9555,
2694,
2,
4719,
628,
840,
3649,
748,
4817,
15603,
2079,
2650,
1162,
3133,
7,
2079,
11936,
1765,
3524,
2079,
11936,
13191,
5971,
339,
327,
4178,
921,
29220,
14,
17164,
14,
957,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
2819,
1401,
1407,
272,
347,
511,
63,
1412,
4231,
63,
9105,
63,
1397,
63,
7832,
63,
18563,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
398,
327,
543,
3032,
13,
262,
20499,
18153,
4692,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
942,
22140,
355,
20499,
18153,
15829,
18371,
18153,
2535,
18371,
63,
354,
1687,
628,
628,
574,
628,
50,
24771,
1020,
13,
53,
17,
2,
9109,
18371,
18153,
5971,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
18371,
63,
354,
297,
2748,
1826,
413,
12,
2748,
9,
398,
327,
543,
3032,
13,
262,
1591,
18153,
4692,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
942,
22140,
355,
1591,
18153,
15829,
1102,
18153,
2535,
4269,
1687,
628,
628,
574,
628,
320,
76,
3385,
14,
2694,
14,
3197,
2,
9109,
1102,
18153,
5971,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
4269,
297,
2748,
1826,
413,
12,
2748,
9,
398,
327,
543,
20499,
18153,
436,
1591,
18153,
315,
314,
1978,
267,
17121,
4231,
14,
525,
1563,
18153,
8,
18371,
534,
50,
24771,
1020,
13,
53,
17,
297,
6844,
534,
320,
76,
3385,
14,
2694,
14,
3197,
358,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
18371,
63,
354,
297,
2748,
1826,
413,
12,
2748,
9,
267,
291,
14,
2947,
8,
552,
8,
264,
14,
6452,
4827,
4269,
297,
2748,
1826,
413,
12,
2748,
9,
339,
327,
4178,
921,
29220,
14,
17164,
14,
957,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
713,
7979,
1465,
272,
347,
511,
63,
18371,
63,
16692,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
267,
17121,
4231,
14,
525,
1563,
18153,
8,
18371,
534,
50,
24771,
13,
23,
14,
17,
5,
358,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
8,
9118,
1652,
29,
549,
9,
267,
291,
14,
4080,
4827,
18371,
63,
354,
1687,
628,
2930,
2,
574,
628,
50,
24771,
13,
23,
14,
17,
5,
7897,
297,
2748,
9,
339,
327,
4178,
921,
29220,
14,
17164,
14,
957,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
4893,
1644,
1229,
272,
347,
511,
63,
1102,
4365,
63,
27692,
63,
2930,
63,
3856,
8,
277,
304,
267,
17121,
4231,
275,
6423,
12630,
25879,
342,
267,
17121,
4231,
14,
525,
1563,
18153,
8,
1102,
4365,
2968,
4269,
2839,
10536,
75,
8090,
4111,
1105,
267,
17121,
275,
291,
14,
1531,
14,
1412,
4231,
8,
13191,
4231,
12,
355,
5839,
19295,
1524,
1445,
354,
356,
1994,
2694,
297,
283,
1047,
397,
356,
23455,
566,
267,
2748,
275,
17121,
14,
475,
1652,
342,
267,
291,
14,
4080,
4827,
4269,
1687,
628,
2930,
2,
574,
5961,
14,
75,
8090,
4111,
7897,
297,
2748,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
adamnew123456/myweb
|
myweb/backend/db.py
|
1
|
8614
|
"""
An interface on top of a database, which stores articles along with associated
metadata.
"""
from collections import namedtuple
import os
import os.path
import sqlite3
import sys
import zlib
import myweb.backend.query as query
import myweb.backend.utils as utils
# The connected database - there's meant to be only one, which is why this is a
# module and not a class
DB = None
CURSOR = None
# The default database path, which can be passed to `load_database'
if 'HOME' in os.environ: # Unix-likes
DEFAULT_DB = os.path.join(os.environ['HOME'], '.myweb')
elif 'AppData' in os.environ: # Windows
DEFAULT_DB = os.path.join(os.environ['AppData'], 'myweb.sqlite')
else:
print('Cannot find suitable location for database - set either $HOME or %APPDATA%')
sys.exit(1)
# How much to compress the article data by
COMPRESS = 6
# How to package results returned by 'get_article'
Article = namedtuple('Article',
['url', 'content', 'links', 'backlinks', 'tags'])
class Queries:
"Longer queries are stored here, rather than inline, for readability"
create_article_table = '''
CREATE TABLE IF NOT EXISTS ARTICLES(Url STRING PRIMARY KEY,
Article BLOB,
Domain STRING)'''
create_links_table = '''
CREATE TABLE IF NOT EXISTS LINKS(Url STRING, Linked STRING,
PRIMARY KEY (Url, Linked))'''
create_tags_table = '''
CREATE TABLE IF NOT EXISTS TAGS(Url STRING, Tag STRING,
PRIMARY KEY (Url, Tag))'''
search_base_query = '''
SELECT ARTICLES.Url FROM ARTICLES
WHERE '''
count_matching_urls = '''
SELECT COUNT(Articles.Url) FROM ARTICLES WHERE Url = ?'''
check_tag = '''
EXISTS (SELECT 1 FROM TAGS WHERE Tag = ? AND Url = ARTICLES.Url)'''
check_domain = '''
ARTICLES.Domain = ?'''
check_links = '''
EXISTS (SELECT 1 FROM LINKS WHERE Linked = ? AND Url = ARTICLES.Url)'''
check_linked = '''
EXISTS (SELECT 1 FROM LINKS WHERE Url = ? AND Linked = ARTICLES.Url)'''
check_url = '''
ARTICLES.Url = ?'''
def load_database(path):
"""
Loads the database from a file, which is then used for the whole module.
@note The globals `DB` and `CURSOR` are configured here.
"""
global DB
DB = sqlite3.connect(path)
global CURSOR
CURSOR = DB.cursor()
# Create the requisite tables - the tables are documented in schema.markdown
# for the relationships and meaning between these tables.
CURSOR.execute(Queries.create_article_table)
CURSOR.execute(Queries.create_links_table)
CURSOR.execute(Queries.create_tags_table)
def sql_from_query(query_node):
"""
Outputs templated SQL, as well as the list of templates to fill them.
The return value is a tuple:
- The raw SQL to insert
- The variables to add to the query formatter
"""
simple_types = {
query.Tag: (Queries.check_tag, 'tag'),
query.Domain: (Queries.check_domain, 'domain'),
query.Links: (Queries.check_links, 'url'),
query.LinkedBy: (Queries.check_linked, 'url'),
query.Url: (Queries.check_url, 'url')
}
if isinstance(query_node, tuple(simple_types)):
query_template, attr_name = simple_types[type(query_node)]
attr_value = getattr(query_node, attr_name)
return (query_template, (attr_value,))
elif isinstance(query_node, query.And):
sql_1, variables_1 = sql_from_query(query_node.oper_1)
sql_2, variables_2 = sql_from_query(query_node.oper_2)
return ('({query1}) AND ({query2})'.format(
query1=sql_1, query2=sql_2),
variables_1 + variables_2)
elif isinstance(query_node, query.Or):
sql_1, variables_1 = sql_from_query(query_node.oper_1)
sql_2, variables_2 = sql_from_query(query_node.oper_2)
return ('({query1}) OR ({query2})'.format(
query1=sql_1, query2=sql_2),
variables_1 + variables_2)
elif isinstance(query_node, query.Not):
sql, variables = sql_from_query(query_node.expr)
return ('NOT (' + sql + ')', variables)
def execute_query(query_tree):
"""
Processes a query tree, returning a list of eligible URIs.
"""
# Introduce the proper tables into the query before passing it off to
# the query->sql converter
base_query = Queries.search_base_query
sql, variables = sql_from_query(query_tree)
results = set(row[0] for row in DB.execute(base_query + sql, variables))
return results
def create_article(url, content, links, tags):
"""
Inserts a new article in the database.
@raise KeyError If the article exists already.
"""
url = utils.normalize_url(url)
# First, ensure that no article by the given URI exists in the database
# already
count_set = set(row[0] for row in
CURSOR.execute(Queries.count_matching_urls, (url,)))
if count_set.pop() > 0:
raise KeyError('Already have article about ' + url)
content_bytes = bytes(content, 'utf-8')
CURSOR.execute('INSERT INTO ARTICLES VALUES (?, ?, ?)',
(url, zlib.compress(content_bytes, COMPRESS), utils.get_domain(url)))
for link in links:
CURSOR.execute('INSERT INTO LINKS VALUES (?, ?)', (url, link))
for tag in tags:
CURSOR.execute('INSERT INTO TAGS VALUES (?, ?)', (url, tag))
DB.commit()
def update_multimap_table(url, table, column, values):
"""
Updates a one-to-many table, by setting a list of values to a URI.
This routine is meant to do this intelligently, by calculating the
difference between the existing values and the new set of values, and
adding/deleting as little as possible.
"""
# First, figure out what rows are already in the DB
existing_values = set(row[0] for row in
CURSOR.execute('SELECT {} FROM {} WHERE Url = ?'.format(column, table),
(url,)))
# Then, get the difference between existing values and what should/should
# not be in the table
to_add = values - existing_values
to_remove = existing_values - values
# Finally, do the insertions/removals
for val in to_add:
CURSOR.execute('INSERT INTO {} VALUES (?, ?)'.format(table, column),
(url, val))
for val in to_remove:
CURSOR.execute(
'DELETE FROM {} WHERE Url = ? AND {} = ?'.format(table, column),
(url, val))
def update_article(url, content, links, tags):
"""
Updates an existing article in the database.
@note Both links and tags must each be a set()
@raise KeyError If the article doesn't yet exist.
"""
url = utils.normalize_url(url)
# First, ensure that 1 article by the given URI exists in the database
# already
count_set = set(row[0] for row in
CURSOR.execute(Queries.count_matching_urls, (url,)))
if count_set.pop() != 1:
raise KeyError('Database has no article about ' + url)
content_bytes = bytes(content, 'utf-8')
CURSOR.execute('UPDATE ARTICLES SET Article = ? WHERE Url = ?',
(zlib.compress(content_bytes, COMPRESS), url))
# Update the tag/links tables
update_multimap_table(url, 'TAGS', 'Tag', tags)
update_multimap_table(url, 'LINKS', 'Linked', links)
DB.commit()
def get_article(url):
"""
Gets the content of an article, as an Article object.
@raise KeyError If the article doesn't exist.
"""
url = utils.normalize_url(url)
# Get the content, and convert it from zlib compressed bytes to UTF-8
try:
article_row = next(
CURSOR.execute('SELECT Article FROM ARTICLES WHERE Url = ?',
(url,)))
zlib_content_bytes = article_row[0]
except StopIteration:
raise KeyError('Database has no article about ' + url)
content_bytes = zlib.decompress(zlib_content_bytes)
content = content_bytes.decode('utf-8')
# Get all the tags and links for the article
tags = set(row[0] for row in
CURSOR.execute('SELECT Tag FROM TAGS WHERE Url = ?', (url,)))
links = set(row[0] for row in
CURSOR.execute('SELECT Linked FROM LINKS WHERE Url = ?', (url,)))
backlinks = set(row[0] for row in
CURSOR.execute('SELECT Url FROM LINKS WHERE Linked = ?', (url,)))
return Article(url, content, links, backlinks, tags)
def delete_article(url):
"""
Deletes the article, along with its tags and links.
"""
url = utils.normalize_url(url)
CURSOR.execute('DELETE FROM ARTICLES WHERE Url = ?', (url,))
CURSOR.execute('DELETE FROM TAGS WHERE Url = ?', (url,))
CURSOR.execute('DELETE FROM LINKS WHERE Url = ?', (url,))
DB.commit()
|
bsd-2-clause
|
[
624,
199,
2493,
3217,
641,
2746,
402,
282,
3050,
12,
1314,
14086,
23242,
3180,
543,
4568,
199,
2343,
14,
199,
624,
199,
199,
504,
5055,
492,
12863,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
11723,
19,
199,
646,
984,
199,
646,
12472,
199,
199,
646,
3002,
2520,
14,
4620,
14,
1131,
465,
1827,
199,
646,
3002,
2520,
14,
4620,
14,
1208,
465,
3778,
199,
199,
3,
710,
8539,
3050,
446,
2337,
1159,
18329,
370,
506,
1454,
1373,
12,
1314,
365,
10842,
642,
365,
282,
199,
3,
859,
436,
440,
282,
1021,
199,
2846,
275,
488,
199,
31321,
275,
488,
199,
199,
3,
710,
849,
3050,
931,
12,
1314,
883,
506,
3032,
370,
658,
912,
63,
4659,
7,
199,
692,
283,
9524,
7,
315,
747,
14,
2314,
26,
327,
13074,
13,
29572,
272,
6186,
63,
2846,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
9524,
995,
1987,
1662,
2520,
358,
199,
4164,
283,
2640,
1451,
7,
315,
747,
14,
2314,
26,
327,
5417,
272,
6186,
63,
2846,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
2640,
1451,
995,
283,
1662,
2520,
14,
10659,
358,
199,
2836,
26,
272,
870,
360,
6612,
2342,
11233,
2909,
367,
3050,
446,
663,
1902,
2672,
9524,
503,
450,
28057,
5,
358,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
7494,
8298,
370,
11029,
314,
9772,
666,
701,
199,
22827,
1608,
275,
1227,
199,
199,
3,
7494,
370,
2559,
2058,
2138,
701,
283,
362,
63,
6934,
7,
199,
7221,
275,
12863,
360,
7221,
297,
267,
788,
633,
297,
283,
1317,
297,
283,
4614,
297,
283,
894,
4614,
297,
283,
2969,
1105,
199,
199,
533,
5843,
5460,
26,
272,
298,
31253,
836,
9212,
787,
5489,
2348,
12,
7830,
2419,
8308,
12,
367,
1586,
3616,
2,
272,
1218,
63,
6934,
63,
1224,
275,
1449,
199,
8366,
9934,
8036,
2845,
23875,
4160,
52,
948,
11344,
8,
6417,
18661,
19770,
9301,
12,
4960,
8281,
699,
9376,
12,
4960,
14061,
18661,
9,
2344,
272,
1218,
63,
4614,
63,
1224,
275,
1449,
199,
8366,
9934,
8036,
2845,
23875,
19774,
51,
8,
6417,
18661,
12,
10967,
379,
18661,
12,
4960,
19770,
9301,
334,
6417,
12,
10967,
379,
430,
2344,
272,
1218,
63,
2969,
63,
1224,
275,
1449,
199,
8366,
9934,
8036,
2845,
23875,
18395,
51,
8,
6417,
18661,
12,
8053,
18661,
12,
4960,
19770,
9301,
334,
6417,
12,
8053,
430,
2344,
272,
2754,
63,
1095,
63,
1131,
275,
1449,
199,
4859,
4160,
52,
948,
11344,
14,
6417,
4442,
4160,
52,
948,
11344,
221,
199,
17688,
1449,
272,
2338,
63,
9467,
63,
3603,
275,
1449,
199,
4859,
24903,
8,
7221,
83,
14,
6417,
9,
4442,
4160,
52,
948,
11344,
6038,
20503,
275,
5805,
2344,
272,
1104,
63,
1450,
275,
1449,
199,
23558,
334,
4859,
413,
4442,
18395,
51,
6038,
8053,
275,
5805,
2401,
20503,
275,
4160,
52,
948,
11344,
14,
6417,
9,
2344,
272,
1104,
63,
2261,
275,
1449,
199,
2294,
948,
11344,
14,
7705,
275,
5805,
2344,
272,
1104,
63,
4614,
275,
1449,
199,
23558,
334,
4859,
413,
4442,
19774,
51,
6038,
10967,
379,
275,
5805,
2401,
20503,
275,
4160,
52,
948,
11344,
14,
6417,
9,
2344,
272,
1104,
63,
12751,
275,
1449,
199,
23558,
334,
4859,
413,
4442,
19774,
51,
6038,
20503,
275,
5805,
2401,
10967,
379,
275,
4160,
52,
948,
11344,
14,
6417,
9,
2344,
272,
1104,
63,
633,
275,
1449,
199,
2294,
948,
11344,
14,
6417,
275,
5805,
2344,
199,
199,
318,
2248,
63,
4659,
8,
515,
304,
272,
408,
272,
30367,
314,
3050,
687,
282,
570,
12,
1314,
365,
2066,
1202,
367,
314,
8852,
859,
14,
272,
768,
4610,
710,
7992,
658,
2846,
64,
436,
658,
31321,
64,
787,
7526,
2348,
14,
272,
408,
272,
2288,
6249,
272,
6249,
275,
11723,
19,
14,
2242,
8,
515,
9,
339,
2288,
18715,
26508,
272,
18715,
26508,
275,
6249,
14,
3937,
342,
339,
327,
2790,
314,
295,
783,
2124,
6716,
446,
314,
6716,
787,
22751,
315,
4177,
14,
15653,
272,
327,
367,
314,
20045,
436,
11150,
3382,
3520,
6716,
14,
272,
18715,
26508,
14,
2526,
8,
13611,
14,
981,
63,
6934,
63,
1224,
9,
272,
18715,
26508,
14,
2526,
8,
13611,
14,
981,
63,
4614,
63,
1224,
9,
272,
18715,
26508,
14,
2526,
8,
13611,
14,
981,
63,
2969,
63,
1224,
9,
199,
199,
318,
3875,
63,
504,
63,
1131,
8,
1131,
63,
932,
304,
272,
408,
272,
29206,
27960,
5385,
12,
465,
5521,
465,
314,
769,
402,
7009,
370,
5554,
3062,
14,
272,
710,
372,
574,
365,
282,
2008,
26,
1362,
446,
710,
3066,
5385,
370,
5518,
1362,
446,
710,
2860,
370,
1050,
370,
314,
1827,
9698,
272,
408,
272,
3486,
63,
1313,
275,
469,
267,
1827,
14,
1931,
26,
334,
13611,
14,
1074,
63,
1450,
12,
283,
1450,
659,
267,
1827,
14,
7705,
26,
334,
13611,
14,
1074,
63,
2261,
12,
283,
2261,
659,
267,
1827,
14,
16974,
26,
334,
13611,
14,
1074,
63,
4614,
12,
283,
633,
659,
267,
1827,
14,
26748,
2175,
26,
334,
13611,
14,
1074,
63,
12751,
12,
283,
633,
659,
267,
1827,
14,
6417,
26,
334,
13611,
14,
1074,
63,
633,
12,
283,
633,
358,
272,
789,
339,
340,
1228,
8,
1131,
63,
932,
12,
2008,
8,
4129,
63,
1313,
2298,
267,
1827,
63,
1160,
12,
1921,
63,
354,
275,
3486,
63,
1313,
59,
466,
8,
1131,
63,
932,
1874,
267,
1921,
63,
585,
275,
2519,
8,
1131,
63,
932,
12,
1921,
63,
354,
9,
267,
372,
334,
1131,
63,
1160,
12,
334,
962,
63,
585,
4641,
272,
916,
1228,
8,
1131,
63,
932,
12,
1827,
14,
3325,
304,
267,
3875,
63,
17,
12,
2860,
63,
17,
275,
3875,
63,
504,
63,
1131,
8,
1131,
63,
932,
14,
2262,
63,
17,
9,
267,
3875,
63,
18,
12,
2860,
63,
18,
275,
3875,
63,
504,
63,
1131,
8,
1131,
63,
932,
14,
2262,
63,
18,
9,
267,
372,
661,
2561,
1131,
17,
1552,
2401,
11459,
1131,
18,
25885,
908,
8,
490,
1827,
17,
29,
3009,
63,
17,
12,
1827,
18,
29,
3009,
63,
18,
395,
355,
2860,
63,
17,
435,
2860,
63,
18,
9,
272,
916,
1228,
8,
1131,
63,
932,
12,
1827,
14,
2844,
304,
267,
3875,
63,
17
] |
[
199,
2493,
3217,
641,
2746,
402,
282,
3050,
12,
1314,
14086,
23242,
3180,
543,
4568,
199,
2343,
14,
199,
624,
199,
199,
504,
5055,
492,
12863,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
11723,
19,
199,
646,
984,
199,
646,
12472,
199,
199,
646,
3002,
2520,
14,
4620,
14,
1131,
465,
1827,
199,
646,
3002,
2520,
14,
4620,
14,
1208,
465,
3778,
199,
199,
3,
710,
8539,
3050,
446,
2337,
1159,
18329,
370,
506,
1454,
1373,
12,
1314,
365,
10842,
642,
365,
282,
199,
3,
859,
436,
440,
282,
1021,
199,
2846,
275,
488,
199,
31321,
275,
488,
199,
199,
3,
710,
849,
3050,
931,
12,
1314,
883,
506,
3032,
370,
658,
912,
63,
4659,
7,
199,
692,
283,
9524,
7,
315,
747,
14,
2314,
26,
327,
13074,
13,
29572,
272,
6186,
63,
2846,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
9524,
995,
1987,
1662,
2520,
358,
199,
4164,
283,
2640,
1451,
7,
315,
747,
14,
2314,
26,
327,
5417,
272,
6186,
63,
2846,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
2640,
1451,
995,
283,
1662,
2520,
14,
10659,
358,
199,
2836,
26,
272,
870,
360,
6612,
2342,
11233,
2909,
367,
3050,
446,
663,
1902,
2672,
9524,
503,
450,
28057,
5,
358,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
7494,
8298,
370,
11029,
314,
9772,
666,
701,
199,
22827,
1608,
275,
1227,
199,
199,
3,
7494,
370,
2559,
2058,
2138,
701,
283,
362,
63,
6934,
7,
199,
7221,
275,
12863,
360,
7221,
297,
267,
788,
633,
297,
283,
1317,
297,
283,
4614,
297,
283,
894,
4614,
297,
283,
2969,
1105,
199,
199,
533,
5843,
5460,
26,
272,
298,
31253,
836,
9212,
787,
5489,
2348,
12,
7830,
2419,
8308,
12,
367,
1586,
3616,
2,
272,
1218,
63,
6934,
63,
1224,
275,
1449,
199,
8366,
9934,
8036,
2845,
23875,
4160,
52,
948,
11344,
8,
6417,
18661,
19770,
9301,
12,
4960,
8281,
699,
9376,
12,
4960,
14061,
18661,
9,
2344,
272,
1218,
63,
4614,
63,
1224,
275,
1449,
199,
8366,
9934,
8036,
2845,
23875,
19774,
51,
8,
6417,
18661,
12,
10967,
379,
18661,
12,
4960,
19770,
9301,
334,
6417,
12,
10967,
379,
430,
2344,
272,
1218,
63,
2969,
63,
1224,
275,
1449,
199,
8366,
9934,
8036,
2845,
23875,
18395,
51,
8,
6417,
18661,
12,
8053,
18661,
12,
4960,
19770,
9301,
334,
6417,
12,
8053,
430,
2344,
272,
2754,
63,
1095,
63,
1131,
275,
1449,
199,
4859,
4160,
52,
948,
11344,
14,
6417,
4442,
4160,
52,
948,
11344,
221,
199,
17688,
1449,
272,
2338,
63,
9467,
63,
3603,
275,
1449,
199,
4859,
24903,
8,
7221,
83,
14,
6417,
9,
4442,
4160,
52,
948,
11344,
6038,
20503,
275,
5805,
2344,
272,
1104,
63,
1450,
275,
1449,
199,
23558,
334,
4859,
413,
4442,
18395,
51,
6038,
8053,
275,
5805,
2401,
20503,
275,
4160,
52,
948,
11344,
14,
6417,
9,
2344,
272,
1104,
63,
2261,
275,
1449,
199,
2294,
948,
11344,
14,
7705,
275,
5805,
2344,
272,
1104,
63,
4614,
275,
1449,
199,
23558,
334,
4859,
413,
4442,
19774,
51,
6038,
10967,
379,
275,
5805,
2401,
20503,
275,
4160,
52,
948,
11344,
14,
6417,
9,
2344,
272,
1104,
63,
12751,
275,
1449,
199,
23558,
334,
4859,
413,
4442,
19774,
51,
6038,
20503,
275,
5805,
2401,
10967,
379,
275,
4160,
52,
948,
11344,
14,
6417,
9,
2344,
272,
1104,
63,
633,
275,
1449,
199,
2294,
948,
11344,
14,
6417,
275,
5805,
2344,
199,
199,
318,
2248,
63,
4659,
8,
515,
304,
272,
408,
272,
30367,
314,
3050,
687,
282,
570,
12,
1314,
365,
2066,
1202,
367,
314,
8852,
859,
14,
272,
768,
4610,
710,
7992,
658,
2846,
64,
436,
658,
31321,
64,
787,
7526,
2348,
14,
272,
408,
272,
2288,
6249,
272,
6249,
275,
11723,
19,
14,
2242,
8,
515,
9,
339,
2288,
18715,
26508,
272,
18715,
26508,
275,
6249,
14,
3937,
342,
339,
327,
2790,
314,
295,
783,
2124,
6716,
446,
314,
6716,
787,
22751,
315,
4177,
14,
15653,
272,
327,
367,
314,
20045,
436,
11150,
3382,
3520,
6716,
14,
272,
18715,
26508,
14,
2526,
8,
13611,
14,
981,
63,
6934,
63,
1224,
9,
272,
18715,
26508,
14,
2526,
8,
13611,
14,
981,
63,
4614,
63,
1224,
9,
272,
18715,
26508,
14,
2526,
8,
13611,
14,
981,
63,
2969,
63,
1224,
9,
199,
199,
318,
3875,
63,
504,
63,
1131,
8,
1131,
63,
932,
304,
272,
408,
272,
29206,
27960,
5385,
12,
465,
5521,
465,
314,
769,
402,
7009,
370,
5554,
3062,
14,
272,
710,
372,
574,
365,
282,
2008,
26,
1362,
446,
710,
3066,
5385,
370,
5518,
1362,
446,
710,
2860,
370,
1050,
370,
314,
1827,
9698,
272,
408,
272,
3486,
63,
1313,
275,
469,
267,
1827,
14,
1931,
26,
334,
13611,
14,
1074,
63,
1450,
12,
283,
1450,
659,
267,
1827,
14,
7705,
26,
334,
13611,
14,
1074,
63,
2261,
12,
283,
2261,
659,
267,
1827,
14,
16974,
26,
334,
13611,
14,
1074,
63,
4614,
12,
283,
633,
659,
267,
1827,
14,
26748,
2175,
26,
334,
13611,
14,
1074,
63,
12751,
12,
283,
633,
659,
267,
1827,
14,
6417,
26,
334,
13611,
14,
1074,
63,
633,
12,
283,
633,
358,
272,
789,
339,
340,
1228,
8,
1131,
63,
932,
12,
2008,
8,
4129,
63,
1313,
2298,
267,
1827,
63,
1160,
12,
1921,
63,
354,
275,
3486,
63,
1313,
59,
466,
8,
1131,
63,
932,
1874,
267,
1921,
63,
585,
275,
2519,
8,
1131,
63,
932,
12,
1921,
63,
354,
9,
267,
372,
334,
1131,
63,
1160,
12,
334,
962,
63,
585,
4641,
272,
916,
1228,
8,
1131,
63,
932,
12,
1827,
14,
3325,
304,
267,
3875,
63,
17,
12,
2860,
63,
17,
275,
3875,
63,
504,
63,
1131,
8,
1131,
63,
932,
14,
2262,
63,
17,
9,
267,
3875,
63,
18,
12,
2860,
63,
18,
275,
3875,
63,
504,
63,
1131,
8,
1131,
63,
932,
14,
2262,
63,
18,
9,
267,
372,
661,
2561,
1131,
17,
1552,
2401,
11459,
1131,
18,
25885,
908,
8,
490,
1827,
17,
29,
3009,
63,
17,
12,
1827,
18,
29,
3009,
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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
] |
wfxiang08/ansible
|
lib/ansible/playbook/handler.py
|
237
|
1957
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.errors import AnsibleError
#from ansible.inventory.host import Host
from ansible.playbook.task import Task
class Handler(Task):
def __init__(self, block=None, role=None, task_include=None):
self._flagged_hosts = []
super(Handler, self).__init__(block=block, role=role, task_include=task_include)
def __repr__(self):
''' returns a human readable representation of the handler '''
return "HANDLER: %s" % self.get_name()
@staticmethod
def load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None):
t = Handler(block=block, role=role, task_include=task_include)
return t.load_data(data, variable_manager=variable_manager, loader=loader)
def flag_for_host(self, host):
#assert instanceof(host, Host)
if host not in self._flagged_hosts:
self._flagged_hosts.append(host)
def has_triggered(self, host):
return host in self._flagged_hosts
def serialize(self):
result = super(Handler, self).serialize()
result['is_handler'] = True
return result
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
3,
504,
3242,
14,
7212,
14,
1102,
492,
10891,
199,
504,
3242,
14,
14205,
14,
1765,
492,
8495,
199,
199,
533,
18599,
8,
4476,
304,
339,
347,
636,
826,
721,
277,
12,
1853,
29,
403,
12,
4719,
29,
403,
12,
2120,
63,
2613,
29,
403,
304,
267,
291,
423,
4173,
3046,
63,
5146,
275,
942,
398,
1613,
8,
2461,
12,
291,
2843,
826,
721,
1457,
29,
1457,
12,
4719,
29,
3756,
12,
2120,
63,
2613,
29,
1765,
63,
2613,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
1449,
2529,
282,
11779,
12701,
6025,
402,
314,
3016,
1449,
267,
372,
298,
30872,
26,
450,
83,
2,
450,
291,
14,
362,
63,
354,
342,
339,
768,
4639,
272,
347,
2248,
8,
576,
12,
1853,
29,
403,
12,
4719,
29,
403,
12,
2120,
63,
2613,
29,
403,
12,
1750,
63,
2609,
29,
403,
12,
5077,
29,
403,
304,
267,
307,
275,
18599,
8,
1457,
29,
1457,
12,
4719,
29,
3756,
12,
2120,
63,
2613,
29,
1765,
63,
2613,
9,
267,
372,
307,
14,
912,
63,
576,
8,
576,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
12,
5077,
29,
3422,
9,
339,
347,
3305,
63,
509,
63,
1102,
8,
277,
12,
1591,
304,
267,
327,
479,
1256,
1618,
8,
1102,
12,
10891,
9,
267,
340,
1591,
440,
315,
291,
423,
4173,
3046,
63,
5146,
26,
288,
291,
423,
4173,
3046,
63,
5146,
14,
740,
8,
1102,
9,
339,
347,
965,
63,
21142,
8,
277,
12,
1591,
304,
267,
372,
1591,
315,
291,
423,
4173,
3046,
63,
5146,
339,
347,
8437,
8,
277,
304,
267,
754,
275,
1613,
8,
2461,
12,
291,
680,
3549,
342,
267,
754,
459,
374,
63,
2232,
418,
275,
715,
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
] |
[
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
3,
504,
3242,
14,
7212,
14,
1102,
492,
10891,
199,
504,
3242,
14,
14205,
14,
1765,
492,
8495,
199,
199,
533,
18599,
8,
4476,
304,
339,
347,
636,
826,
721,
277,
12,
1853,
29,
403,
12,
4719,
29,
403,
12,
2120,
63,
2613,
29,
403,
304,
267,
291,
423,
4173,
3046,
63,
5146,
275,
942,
398,
1613,
8,
2461,
12,
291,
2843,
826,
721,
1457,
29,
1457,
12,
4719,
29,
3756,
12,
2120,
63,
2613,
29,
1765,
63,
2613,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
1449,
2529,
282,
11779,
12701,
6025,
402,
314,
3016,
1449,
267,
372,
298,
30872,
26,
450,
83,
2,
450,
291,
14,
362,
63,
354,
342,
339,
768,
4639,
272,
347,
2248,
8,
576,
12,
1853,
29,
403,
12,
4719,
29,
403,
12,
2120,
63,
2613,
29,
403,
12,
1750,
63,
2609,
29,
403,
12,
5077,
29,
403,
304,
267,
307,
275,
18599,
8,
1457,
29,
1457,
12,
4719,
29,
3756,
12,
2120,
63,
2613,
29,
1765,
63,
2613,
9,
267,
372,
307,
14,
912,
63,
576,
8,
576,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
12,
5077,
29,
3422,
9,
339,
347,
3305,
63,
509,
63,
1102,
8,
277,
12,
1591,
304,
267,
327,
479,
1256,
1618,
8,
1102,
12,
10891,
9,
267,
340,
1591,
440,
315,
291,
423,
4173,
3046,
63,
5146,
26,
288,
291,
423,
4173,
3046,
63,
5146,
14,
740,
8,
1102,
9,
339,
347,
965,
63,
21142,
8,
277,
12,
1591,
304,
267,
372,
1591,
315,
291,
423,
4173,
3046,
63,
5146,
339,
347,
8437,
8,
277,
304,
267,
754,
275,
1613,
8,
2461,
12,
291,
680,
3549,
342,
267,
754,
459,
374,
63,
2232,
418,
275,
715,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mcrowson/django
|
tests/auth_tests/test_handlers.py
|
328
|
2868
|
from __future__ import unicode_literals
from django.contrib.auth.handlers.modwsgi import (
check_password, groups_for_user,
)
from django.contrib.auth.models import Group, User
from django.contrib.auth.tests.custom_user import CustomUser
from django.test import TransactionTestCase, override_settings
# This must be a TransactionTestCase because the WSGI auth handler performs
# its own transaction management.
class ModWsgiHandlerTestCase(TransactionTestCase):
"""
Tests for the mod_wsgi authentication handler
"""
available_apps = [
'django.contrib.auth',
'django.contrib.contenttypes',
]
def test_check_password(self):
"""
Verify that check_password returns the correct values as per
http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider
"""
User.objects.create_user('test', 'test@example.com', 'test')
# User not in database
self.assertIsNone(check_password({}, 'unknown', ''))
# Valid user with correct password
self.assertTrue(check_password({}, 'test', 'test'))
# correct password, but user is inactive
User.objects.filter(username='test').update(is_active=False)
self.assertFalse(check_password({}, 'test', 'test'))
# Valid user with incorrect password
self.assertFalse(check_password({}, 'test', 'incorrect'))
@override_settings(AUTH_USER_MODEL='auth.CustomUser')
def test_check_password_custom_user(self):
"""
Verify that check_password returns the correct values as per
http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider
with custom user installed
"""
CustomUser._default_manager.create_user('test@example.com', '1990-01-01', 'test')
# User not in database
self.assertIsNone(check_password({}, 'unknown', ''))
# Valid user with correct password'
self.assertTrue(check_password({}, 'test@example.com', 'test'))
# Valid user with incorrect password
self.assertFalse(check_password({}, 'test@example.com', 'incorrect'))
def test_groups_for_user(self):
"""
Check that groups_for_user returns correct values as per
http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Group_Authorisation
"""
user1 = User.objects.create_user('test', 'test@example.com', 'test')
User.objects.create_user('test1', 'test1@example.com', 'test1')
group = Group.objects.create(name='test_group')
user1.groups.add(group)
# User not in database
self.assertEqual(groups_for_user({}, 'unknown'), [])
self.assertEqual(groups_for_user({}, 'test'), [b'test_group'])
self.assertEqual(groups_for_user({}, 'test1'), [])
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
5586,
14,
1494,
6508,
492,
334,
272,
1104,
63,
2060,
12,
4652,
63,
509,
63,
751,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
5611,
12,
2876,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
4229,
63,
751,
492,
8388,
1899,
199,
504,
1639,
14,
396,
492,
18244,
1746,
12,
4278,
63,
1751,
421,
199,
3,
961,
1471,
506,
282,
18244,
1746,
2952,
314,
9279,
1790,
3016,
18628,
199,
3,
2399,
5705,
6008,
10041,
14,
199,
533,
22035,
55,
5395,
2461,
1746,
8,
10161,
1746,
304,
272,
408,
272,
6496,
367,
314,
3413,
63,
6508,
6299,
3016,
272,
408,
339,
2808,
63,
5181,
275,
359,
267,
283,
1176,
14,
2828,
14,
1178,
297,
267,
283,
1176,
14,
2828,
14,
10778,
297,
272,
1622,
339,
347,
511,
63,
1074,
63,
2060,
8,
277,
304,
267,
408,
267,
7635,
626,
1104,
63,
2060,
2529,
314,
3211,
1338,
465,
1126,
267,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
1494,
6508,
15,
6797,
15,
3946,
3717,
1352,
10832,
706,
3,
28993,
63,
10348,
63,
6663,
267,
408,
267,
2876,
14,
1462,
14,
981,
63,
751,
360,
396,
297,
283,
396,
32,
2694,
14,
957,
297,
283,
396,
358,
398,
327,
2876,
440,
315,
3050,
267,
291,
14,
7702,
8,
1074,
63,
2060,
16037,
283,
5187,
297,
12381,
398,
327,
4821,
922,
543,
3211,
2505,
267,
291,
14,
1815,
8,
1074,
63,
2060,
16037,
283,
396,
297,
283,
396,
1333,
398,
327,
3211,
2505,
12,
1325,
922,
365,
21325,
267,
2876,
14,
1462,
14,
1541,
8,
2473,
534,
396,
1959,
873,
8,
374,
63,
2682,
29,
797,
9,
267,
291,
14,
3334,
8,
1074,
63,
2060,
16037,
283,
396,
297,
283,
396,
1333,
398,
327,
4821,
922,
543,
8927,
2505,
267,
291,
14,
3334,
8,
1074,
63,
2060,
16037,
283,
396,
297,
283,
15448,
1333,
339,
768,
4415,
63,
1751,
8,
5580,
63,
3791,
63,
11429,
534,
1178,
14,
31482,
358,
272,
347,
511,
63,
1074,
63,
2060,
63,
4229,
63,
751,
8,
277,
304,
267,
408,
267,
7635,
626,
1104,
63,
2060,
2529,
314,
3211,
1338,
465,
1126,
267,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
1494,
6508,
15,
6797,
15,
3946,
3717,
1352,
10832,
706,
3,
28993,
63,
10348,
63,
6663,
398,
543,
3537,
922,
4903,
267,
408,
398,
8388,
1899,
423,
885,
63,
2609,
14,
981,
63,
751,
360,
396,
32,
2694,
14,
957,
297,
283,
7155,
16,
13,
614,
13,
614,
297,
283,
396,
358,
398,
327,
2876,
440,
315,
3050,
267,
291,
14,
7702,
8,
1074,
63,
2060,
16037,
283,
5187,
297,
12381,
398,
327,
4821,
922,
543,
3211,
2505,
7,
267,
291,
14,
1815,
8,
1074,
63,
2060,
16037,
283,
396,
32,
2694,
14,
957,
297,
283,
396,
1333,
398,
327,
4821,
922,
543,
8927,
2505,
267,
291,
14,
3334,
8,
1074,
63,
2060,
16037,
283,
396,
32,
2694,
14,
957,
297,
283,
15448,
1333,
339,
347,
511,
63,
2634,
63,
509,
63,
751,
8,
277,
304,
267,
408,
267,
2670,
626,
4652,
63,
509,
63,
751,
2529,
3211,
1338,
465,
1126,
267,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
1494,
6508,
15,
6797,
15,
3946,
3717,
1352,
10832,
706,
3,
28993,
63,
2448,
63,
5949,
19914,
267,
408,
267,
922,
17,
275,
2876,
14,
1462,
14,
981,
63,
751,
360,
396,
297,
283,
396,
32,
2694,
14,
957,
297,
283,
396,
358,
267,
2876,
14,
1462,
14,
981,
63,
751,
360,
396,
17,
297,
283,
396,
17,
32,
2694,
14,
957,
297,
283,
396,
17,
358,
267,
1572,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
396,
63,
923,
358,
267,
922,
17,
14,
2634,
14,
525,
8,
923,
9,
398,
327,
2876,
440,
315,
3050,
267,
291,
14,
629,
8,
2634,
63,
509,
63,
751,
16037,
283,
5187,
659,
3073,
398,
291,
14,
629,
8,
2634,
63,
509,
63,
751,
16037,
283,
396,
659,
359,
66,
1133,
597,
63,
923,
1105,
267,
291,
14,
629,
8,
2634,
63,
509,
63,
751,
16037,
283,
396,
17,
659,
3073,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
5586,
14,
1494,
6508,
492,
334,
272,
1104,
63,
2060,
12,
4652,
63,
509,
63,
751,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
5611,
12,
2876,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
4229,
63,
751,
492,
8388,
1899,
199,
504,
1639,
14,
396,
492,
18244,
1746,
12,
4278,
63,
1751,
421,
199,
3,
961,
1471,
506,
282,
18244,
1746,
2952,
314,
9279,
1790,
3016,
18628,
199,
3,
2399,
5705,
6008,
10041,
14,
199,
533,
22035,
55,
5395,
2461,
1746,
8,
10161,
1746,
304,
272,
408,
272,
6496,
367,
314,
3413,
63,
6508,
6299,
3016,
272,
408,
339,
2808,
63,
5181,
275,
359,
267,
283,
1176,
14,
2828,
14,
1178,
297,
267,
283,
1176,
14,
2828,
14,
10778,
297,
272,
1622,
339,
347,
511,
63,
1074,
63,
2060,
8,
277,
304,
267,
408,
267,
7635,
626,
1104,
63,
2060,
2529,
314,
3211,
1338,
465,
1126,
267,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
1494,
6508,
15,
6797,
15,
3946,
3717,
1352,
10832,
706,
3,
28993,
63,
10348,
63,
6663,
267,
408,
267,
2876,
14,
1462,
14,
981,
63,
751,
360,
396,
297,
283,
396,
32,
2694,
14,
957,
297,
283,
396,
358,
398,
327,
2876,
440,
315,
3050,
267,
291,
14,
7702,
8,
1074,
63,
2060,
16037,
283,
5187,
297,
12381,
398,
327,
4821,
922,
543,
3211,
2505,
267,
291,
14,
1815,
8,
1074,
63,
2060,
16037,
283,
396,
297,
283,
396,
1333,
398,
327,
3211,
2505,
12,
1325,
922,
365,
21325,
267,
2876,
14,
1462,
14,
1541,
8,
2473,
534,
396,
1959,
873,
8,
374,
63,
2682,
29,
797,
9,
267,
291,
14,
3334,
8,
1074,
63,
2060,
16037,
283,
396,
297,
283,
396,
1333,
398,
327,
4821,
922,
543,
8927,
2505,
267,
291,
14,
3334,
8,
1074,
63,
2060,
16037,
283,
396,
297,
283,
15448,
1333,
339,
768,
4415,
63,
1751,
8,
5580,
63,
3791,
63,
11429,
534,
1178,
14,
31482,
358,
272,
347,
511,
63,
1074,
63,
2060,
63,
4229,
63,
751,
8,
277,
304,
267,
408,
267,
7635,
626,
1104,
63,
2060,
2529,
314,
3211,
1338,
465,
1126,
267,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
1494,
6508,
15,
6797,
15,
3946,
3717,
1352,
10832,
706,
3,
28993,
63,
10348,
63,
6663,
398,
543,
3537,
922,
4903,
267,
408,
398,
8388,
1899,
423,
885,
63,
2609,
14,
981,
63,
751,
360,
396,
32,
2694,
14,
957,
297,
283,
7155,
16,
13,
614,
13,
614,
297,
283,
396,
358,
398,
327,
2876,
440,
315,
3050,
267,
291,
14,
7702,
8,
1074,
63,
2060,
16037,
283,
5187,
297,
12381,
398,
327,
4821,
922,
543,
3211,
2505,
7,
267,
291,
14,
1815,
8,
1074,
63,
2060,
16037,
283,
396,
32,
2694,
14,
957,
297,
283,
396,
1333,
398,
327,
4821,
922,
543,
8927,
2505,
267,
291,
14,
3334,
8,
1074,
63,
2060,
16037,
283,
396,
32,
2694,
14,
957,
297,
283,
15448,
1333,
339,
347,
511,
63,
2634,
63,
509,
63,
751,
8,
277,
304,
267,
408,
267,
2670,
626,
4652,
63,
509,
63,
751,
2529,
3211,
1338,
465,
1126,
267,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
1494,
6508,
15,
6797,
15,
3946,
3717,
1352,
10832,
706,
3,
28993,
63,
2448,
63,
5949,
19914,
267,
408,
267,
922,
17,
275,
2876,
14,
1462,
14,
981,
63,
751,
360,
396,
297,
283,
396,
32,
2694,
14,
957,
297,
283,
396,
358,
267,
2876,
14,
1462,
14,
981,
63,
751,
360,
396,
17,
297,
283,
396,
17,
32,
2694,
14,
957,
297,
283,
396,
17,
358,
267,
1572,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
396,
63,
923,
358,
267,
922,
17,
14,
2634,
14,
525,
8,
923,
9,
398,
327,
2876,
440,
315,
3050,
267,
291,
14,
629,
8,
2634,
63,
509,
63,
751,
16037,
283,
5187,
659,
3073,
398,
291,
14,
629,
8,
2634,
63,
509,
63,
751,
16037,
283,
396,
659,
359,
66,
1133,
597,
63,
923,
1105,
267,
291,
14,
629,
8,
2634,
63,
509,
63,
751,
16037,
283,
396,
17,
659,
3073,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
NewpTone/stacklab-cinder
|
cinder/tests/test_nfs.py
|
2
|
20277
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2012 NetApp, 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.
"""Unit tests for the NFS driver module"""
import os
import errno
import __builtin__
import mox as mox_lib
from mox import IsA
from mox import IgnoreArg
from mox import stubout
from cinder import context
from cinder import exception
from cinder import test
from cinder.exception import ProcessExecutionError
from cinder.volume import nfs
class DumbVolume(object):
fields = {}
def __setitem__(self, key, value):
self.fields[key] = value
def __getitem__(self, item):
return self.fields[item]
class NfsDriverTestCase(test.TestCase):
"""Test case for NFS driver"""
TEST_NFS_EXPORT1 = 'nfs-host1:/export'
TEST_NFS_EXPORT2 = 'nfs-host2:/export'
TEST_SIZE_IN_GB = 1
TEST_MNT_POINT = '/mnt/nfs'
TEST_MNT_POINT_BASE = '/mnt/test'
TEST_LOCAL_PATH = '/mnt/nfs/volume-123'
TEST_FILE_NAME = 'test.txt'
TEST_SHARES_CONFIG_FILE = '/etc/cinder/test-shares.conf'
ONE_GB_IN_BYTES = 1024 * 1024 * 1024
def setUp(self):
self._driver = nfs.NfsDriver()
self._mox = mox_lib.Mox()
self.stubs = stubout.StubOutForTesting()
def tearDown(self):
self._mox.UnsetStubs()
self.stubs.UnsetAll()
def stub_out_not_replaying(self, obj, attr_name):
attr_to_replace = getattr(obj, attr_name)
stub = mox_lib.MockObject(attr_to_replace)
self.stubs.Set(obj, attr_name, stub)
def test_path_exists_should_return_true(self):
"""_path_exists should return True if stat returns 0"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_execute')
drv._execute('stat', self.TEST_FILE_NAME, run_as_root=True)
mox.ReplayAll()
self.assertTrue(drv._path_exists(self.TEST_FILE_NAME))
mox.VerifyAll()
def test_path_exists_should_return_false(self):
"""_path_exists should return True if stat doesn't return 0"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_execute')
drv._execute('stat', self.TEST_FILE_NAME, run_as_root=True).\
AndRaise(ProcessExecutionError(
stderr="stat: cannot stat `test.txt': No such file or directory"))
mox.ReplayAll()
self.assertFalse(drv._path_exists(self.TEST_FILE_NAME))
mox.VerifyAll()
def test_local_path(self):
"""local_path common use case"""
nfs.FLAGS.nfs_mount_point_base = self.TEST_MNT_POINT_BASE
drv = self._driver
volume = DumbVolume()
volume['provider_location'] = self.TEST_NFS_EXPORT1
volume['name'] = 'volume-123'
self.assertEqual(
'/mnt/test/2f4f60214cf43c595666dd815f0360a4/volume-123',
drv.local_path(volume))
def test_mount_nfs_should_mount_correctly(self):
"""_mount_nfs common case usage"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_MNT_POINT).AndReturn(True)
mox.StubOutWithMock(drv, '_execute')
drv._execute('mount', '-t', 'nfs', self.TEST_NFS_EXPORT1,
self.TEST_MNT_POINT, run_as_root=True)
mox.ReplayAll()
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT)
mox.VerifyAll()
def test_mount_nfs_should_suppress_already_mounted_error(self):
"""_mount_nfs should suppress already mounted error if ensure=True
"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_MNT_POINT).AndReturn(True)
mox.StubOutWithMock(drv, '_execute')
drv._execute('mount', '-t', 'nfs', self.TEST_NFS_EXPORT1,
self.TEST_MNT_POINT, run_as_root=True).\
AndRaise(ProcessExecutionError(
stderr='is busy or already mounted'))
mox.ReplayAll()
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT, ensure=True)
mox.VerifyAll()
def test_mount_nfs_should_reraise_already_mounted_error(self):
"""_mount_nfs should not suppress already mounted error if ensure=False
"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_MNT_POINT).AndReturn(True)
mox.StubOutWithMock(drv, '_execute')
drv._execute('mount', '-t', 'nfs', self.TEST_NFS_EXPORT1,
self.TEST_MNT_POINT, run_as_root=True).\
AndRaise(ProcessExecutionError(stderr='is busy or already mounted'))
mox.ReplayAll()
self.assertRaises(ProcessExecutionError, drv._mount_nfs,
self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT,
ensure=False)
mox.VerifyAll()
def test_mount_nfs_should_create_mountpoint_if_not_yet(self):
"""_mount_nfs should create mountpoint if it doesn't exist"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_MNT_POINT).AndReturn(False)
mox.StubOutWithMock(drv, '_execute')
drv._execute('mkdir', '-p', self.TEST_MNT_POINT)
drv._execute(*([IgnoreArg()] * 5), run_as_root=IgnoreArg())
mox.ReplayAll()
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT)
mox.VerifyAll()
def test_mount_nfs_should_not_create_mountpoint_if_already(self):
"""_mount_nfs should not create mountpoint if it already exists"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_MNT_POINT).AndReturn(True)
mox.StubOutWithMock(drv, '_execute')
drv._execute(*([IgnoreArg()] * 5), run_as_root=IgnoreArg())
mox.ReplayAll()
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT)
mox.VerifyAll()
def test_get_hash_str(self):
"""_get_hash_str should calculation correct value"""
drv = self._driver
self.assertEqual('2f4f60214cf43c595666dd815f0360a4',
drv._get_hash_str(self.TEST_NFS_EXPORT1))
def test_get_mount_point_for_share(self):
"""_get_mount_point_for_share should calculate correct value"""
drv = self._driver
nfs.FLAGS.nfs_mount_point_base = self.TEST_MNT_POINT_BASE
self.assertEqual('/mnt/test/2f4f60214cf43c595666dd815f0360a4',
drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1))
def test_get_available_capacity_with_df(self):
"""_get_available_capacity should calculate correct value"""
mox = self._mox
drv = self._driver
df_avail = 1490560
df_head = 'Filesystem 1K-blocks Used Available Use% Mounted on\n'
df_data = 'nfs-host:/export 2620544 996864 %d 41%% /mnt' % df_avail
df_output = df_head + df_data
setattr(nfs.FLAGS, 'nfs_disk_util', 'df')
mox.StubOutWithMock(drv, '_get_mount_point_for_share')
drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1).\
AndReturn(self.TEST_MNT_POINT)
mox.StubOutWithMock(drv, '_execute')
drv._execute('df', '-P', '-B', '1', self.TEST_MNT_POINT,
run_as_root=True).AndReturn((df_output, None))
mox.ReplayAll()
self.assertEquals(df_avail,
drv._get_available_capacity(self.TEST_NFS_EXPORT1))
mox.VerifyAll()
delattr(nfs.FLAGS, 'nfs_disk_util')
def test_get_available_capacity_with_du(self):
"""_get_available_capacity should calculate correct value"""
mox = self._mox
drv = self._driver
setattr(nfs.FLAGS, 'nfs_disk_util', 'du')
df_total_size = 2620544
df_used_size = 996864
df_avail_size = 1490560
df_title = 'Filesystem 1-blocks Used Available Use% Mounted on\n'
df_mnt_data = 'nfs-host:/export %d %d %d 41%% /mnt' % (df_total_size,
df_used_size,
df_avail_size)
df_output = df_title + df_mnt_data
du_used = 490560
du_output = '%d /mnt' % du_used
mox.StubOutWithMock(drv, '_get_mount_point_for_share')
drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1).\
AndReturn(self.TEST_MNT_POINT)
mox.StubOutWithMock(drv, '_execute')
drv._execute('df', '-P', '-B', '1', self.TEST_MNT_POINT,
run_as_root=True).\
AndReturn((df_output, None))
drv._execute('du', '-sb', '--apparent-size',
'--exclude', '*snapshot*',
self.TEST_MNT_POINT,
run_as_root=True).AndReturn((du_output, None))
mox.ReplayAll()
self.assertEquals(df_total_size - du_used,
drv._get_available_capacity(self.TEST_NFS_EXPORT1))
mox.VerifyAll()
delattr(nfs.FLAGS, 'nfs_disk_util')
def test_load_shares_config(self):
mox = self._mox
drv = self._driver
nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE
mox.StubOutWithMock(__builtin__, 'open')
config_data = []
config_data.append(self.TEST_NFS_EXPORT1)
config_data.append('#' + self.TEST_NFS_EXPORT2)
config_data.append('')
__builtin__.open(self.TEST_SHARES_CONFIG_FILE).AndReturn(config_data)
mox.ReplayAll()
shares = drv._load_shares_config()
self.assertEqual([self.TEST_NFS_EXPORT1], shares)
mox.VerifyAll()
def test_ensure_share_mounted(self):
"""_ensure_share_mounted simple use case"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_get_mount_point_for_share')
drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1).\
AndReturn(self.TEST_MNT_POINT)
mox.StubOutWithMock(drv, '_mount_nfs')
drv._mount_nfs(self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT, ensure=True)
mox.ReplayAll()
drv._ensure_share_mounted(self.TEST_NFS_EXPORT1)
mox.VerifyAll()
def test_ensure_shares_mounted_should_save_mounting_successfully(self):
"""_ensure_shares_mounted should save share if mounted with success"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_load_shares_config')
drv._load_shares_config().AndReturn([self.TEST_NFS_EXPORT1])
mox.StubOutWithMock(drv, '_ensure_share_mounted')
drv._ensure_share_mounted(self.TEST_NFS_EXPORT1)
mox.ReplayAll()
drv._ensure_shares_mounted()
self.assertEqual(1, len(drv._mounted_shares))
self.assertEqual(self.TEST_NFS_EXPORT1, drv._mounted_shares[0])
mox.VerifyAll()
def test_ensure_shares_mounted_should_not_save_mounting_with_error(self):
"""_ensure_shares_mounted should not save share if failed to mount"""
mox = self._mox
drv = self._driver
mox.StubOutWithMock(drv, '_load_shares_config')
drv._load_shares_config().AndReturn([self.TEST_NFS_EXPORT1])
mox.StubOutWithMock(drv, '_ensure_share_mounted')
drv._ensure_share_mounted(self.TEST_NFS_EXPORT1).AndRaise(Exception())
mox.ReplayAll()
drv._ensure_shares_mounted()
self.assertEqual(0, len(drv._mounted_shares))
mox.VerifyAll()
def test_setup_should_throw_error_if_shares_config_not_configured(self):
"""do_setup should throw error if shares config is not configured """
drv = self._driver
nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE
self.assertRaises(exception.NfsException,
drv.do_setup, IsA(context.RequestContext))
def test_setup_should_throw_exception_if_nfs_client_is_not_installed(self):
"""do_setup should throw error if nfs client is not installed """
mox = self._mox
drv = self._driver
nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE
mox.StubOutWithMock(os.path, 'exists')
os.path.exists(self.TEST_SHARES_CONFIG_FILE).AndReturn(True)
mox.StubOutWithMock(drv, '_execute')
drv._execute('mount.nfs', check_exit_code=False).\
AndRaise(OSError(errno.ENOENT, 'No such file or directory'))
mox.ReplayAll()
self.assertRaises(exception.NfsException,
drv.do_setup, IsA(context.RequestContext))
mox.VerifyAll()
def test_find_share_should_throw_error_if_there_is_no_mounted_shares(self):
"""_find_share should throw error if there is no mounted shares"""
drv = self._driver
drv._mounted_shares = []
self.assertRaises(exception.NotFound, drv._find_share,
self.TEST_SIZE_IN_GB)
def test_find_share(self):
"""_find_share simple use case"""
mox = self._mox
drv = self._driver
drv._mounted_shares = [self.TEST_NFS_EXPORT1, self.TEST_NFS_EXPORT2]
mox.StubOutWithMock(drv, '_get_available_capacity')
drv._get_available_capacity(self.TEST_NFS_EXPORT1).\
AndReturn(2 * self.ONE_GB_IN_BYTES)
drv._get_available_capacity(self.TEST_NFS_EXPORT2).\
AndReturn(3 * self.ONE_GB_IN_BYTES)
mox.ReplayAll()
self.assertEqual(self.TEST_NFS_EXPORT2,
drv._find_share(self.TEST_SIZE_IN_GB))
mox.VerifyAll()
def test_find_share_should_throw_error_if_there_is_no_enough_place(self):
"""_find_share should throw error if there is no share to host vol"""
mox = self._mox
drv = self._driver
drv._mounted_shares = [self.TEST_NFS_EXPORT1, self.TEST_NFS_EXPORT2]
mox.StubOutWithMock(drv, '_get_available_capacity')
drv._get_available_capacity(self.TEST_NFS_EXPORT1).\
AndReturn(0)
drv._get_available_capacity(self.TEST_NFS_EXPORT2).\
AndReturn(0)
mox.ReplayAll()
self.assertRaises(exception.NfsNoSuitableShareFound, drv._find_share,
self.TEST_SIZE_IN_GB)
mox.VerifyAll()
def _simple_volume(self):
volume = DumbVolume()
volume['provider_location'] = '127.0.0.1:/mnt'
volume['name'] = 'volume_name'
volume['size'] = 10
return volume
def test_create_sparsed_volume(self):
mox = self._mox
drv = self._driver
volume = self._simple_volume()
setattr(nfs.FLAGS, 'nfs_sparsed_volumes', True)
mox.StubOutWithMock(drv, '_create_sparsed_file')
mox.StubOutWithMock(drv, '_set_rw_permissions_for_all')
drv._create_sparsed_file(IgnoreArg(), IgnoreArg())
drv._set_rw_permissions_for_all(IgnoreArg())
mox.ReplayAll()
drv._do_create_volume(volume)
mox.VerifyAll()
delattr(nfs.FLAGS, 'nfs_sparsed_volumes')
def test_create_nonsparsed_volume(self):
mox = self._mox
drv = self._driver
volume = self._simple_volume()
setattr(nfs.FLAGS, 'nfs_sparsed_volumes', False)
mox.StubOutWithMock(drv, '_create_regular_file')
mox.StubOutWithMock(drv, '_set_rw_permissions_for_all')
drv._create_regular_file(IgnoreArg(), IgnoreArg())
drv._set_rw_permissions_for_all(IgnoreArg())
mox.ReplayAll()
drv._do_create_volume(volume)
mox.VerifyAll()
delattr(nfs.FLAGS, 'nfs_sparsed_volumes')
def test_create_volume_should_ensure_nfs_mounted(self):
"""create_volume should ensure shares provided in config are mounted"""
mox = self._mox
drv = self._driver
self.stub_out_not_replaying(nfs, 'LOG')
self.stub_out_not_replaying(drv, '_find_share')
self.stub_out_not_replaying(drv, '_do_create_volume')
mox.StubOutWithMock(drv, '_ensure_shares_mounted')
drv._ensure_shares_mounted()
mox.ReplayAll()
volume = DumbVolume()
volume['size'] = self.TEST_SIZE_IN_GB
drv.create_volume(volume)
mox.VerifyAll()
def test_create_volume_should_return_provider_location(self):
"""create_volume should return provider_location with found share """
mox = self._mox
drv = self._driver
self.stub_out_not_replaying(nfs, 'LOG')
self.stub_out_not_replaying(drv, '_ensure_shares_mounted')
self.stub_out_not_replaying(drv, '_do_create_volume')
mox.StubOutWithMock(drv, '_find_share')
drv._find_share(self.TEST_SIZE_IN_GB).AndReturn(self.TEST_NFS_EXPORT1)
mox.ReplayAll()
volume = DumbVolume()
volume['size'] = self.TEST_SIZE_IN_GB
result = drv.create_volume(volume)
self.assertEqual(self.TEST_NFS_EXPORT1, result['provider_location'])
mox.VerifyAll()
def test_delete_volume(self):
"""delete_volume simple test case"""
mox = self._mox
drv = self._driver
self.stub_out_not_replaying(drv, '_ensure_share_mounted')
volume = DumbVolume()
volume['name'] = 'volume-123'
volume['provider_location'] = self.TEST_NFS_EXPORT1
mox.StubOutWithMock(drv, 'local_path')
drv.local_path(volume).AndReturn(self.TEST_LOCAL_PATH)
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_LOCAL_PATH).AndReturn(True)
mox.StubOutWithMock(drv, '_execute')
drv._execute('rm', '-f', self.TEST_LOCAL_PATH, run_as_root=True)
mox.ReplayAll()
drv.delete_volume(volume)
mox.VerifyAll()
def test_delete_should_ensure_share_mounted(self):
"""delete_volume should ensure that corresponding share is mounted"""
mox = self._mox
drv = self._driver
self.stub_out_not_replaying(drv, '_execute')
volume = DumbVolume()
volume['name'] = 'volume-123'
volume['provider_location'] = self.TEST_NFS_EXPORT1
mox.StubOutWithMock(drv, '_ensure_share_mounted')
drv._ensure_share_mounted(self.TEST_NFS_EXPORT1)
mox.ReplayAll()
drv.delete_volume(volume)
mox.VerifyAll()
def test_delete_should_not_delete_if_provider_location_not_provided(self):
"""delete_volume shouldn't try to delete if provider_location missed"""
mox = self._mox
drv = self._driver
self.stub_out_not_replaying(drv, '_ensure_share_mounted')
volume = DumbVolume()
volume['name'] = 'volume-123'
volume['provider_location'] = None
mox.StubOutWithMock(drv, '_execute')
mox.ReplayAll()
drv.delete_volume(volume)
mox.VerifyAll()
def test_delete_should_not_delete_if_there_is_no_file(self):
"""delete_volume should not try to delete if file missed"""
mox = self._mox
drv = self._driver
self.stub_out_not_replaying(drv, '_ensure_share_mounted')
volume = DumbVolume()
volume['name'] = 'volume-123'
volume['provider_location'] = self.TEST_NFS_EXPORT1
mox.StubOutWithMock(drv, 'local_path')
drv.local_path(volume).AndReturn(self.TEST_LOCAL_PATH)
mox.StubOutWithMock(drv, '_path_exists')
drv._path_exists(self.TEST_LOCAL_PATH).AndReturn(False)
mox.StubOutWithMock(drv, '_execute')
mox.ReplayAll()
drv.delete_volume(volume)
mox.VerifyAll()
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
334,
67,
9,
6029,
28076,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
624,
5072,
2295,
367,
314,
653,
7079,
5253,
859,
624,
199,
199,
646,
747,
199,
646,
7554,
199,
646,
636,
5351,
363,
199,
199,
646,
18610,
465,
18610,
63,
773,
199,
504,
18610,
492,
29719,
199,
504,
18610,
492,
14092,
6373,
199,
504,
18610,
492,
10098,
548,
199,
199,
504,
13069,
492,
1067,
199,
504,
13069,
492,
1919,
199,
504,
13069,
492,
511,
199,
504,
13069,
14,
1971,
492,
7132,
32165,
199,
199,
504,
13069,
14,
2405,
492,
31307,
421,
199,
533,
577,
4295,
6464,
8,
785,
304,
272,
1504,
275,
1052,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
291,
14,
955,
59,
498,
61,
275,
574,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
14,
955,
59,
1053,
61,
421,
199,
533,
653,
2319,
6158,
1746,
8,
396,
14,
1746,
304,
272,
408,
774,
1930,
367,
653,
7079,
5253,
624,
339,
7393,
63,
46,
7079,
63,
18341,
17,
275,
283,
19591,
13,
1102,
17,
11254,
3790,
7,
272,
7393,
63,
46,
7079,
63,
18341,
18,
275,
283,
19591,
13,
1102,
18,
11254,
3790,
7,
272,
7393,
63,
4305,
63,
568,
63,
6487,
275,
413,
272,
7393,
63,
45,
12460,
63,
7217,
275,
1994,
20481,
15,
19591,
7,
272,
7393,
63,
45,
12460,
63,
7217,
63,
5825,
275,
1994,
20481,
15,
396,
7,
272,
7393,
63,
7486,
63,
3243,
275,
1994,
20481,
15,
19591,
15,
2405,
13,
4288,
7,
272,
7393,
63,
3817,
63,
2339,
275,
283,
396,
14,
2424,
7,
272,
7393,
63,
11152,
654,
63,
5569,
63,
3817,
275,
1994,
6839,
15,
12372,
15,
396,
13,
18318,
14,
2190,
7,
272,
13051,
63,
6487,
63,
568,
63,
20352,
275,
6619,
627,
6619,
627,
6619,
339,
347,
3613,
8,
277,
304,
267,
291,
423,
3090,
275,
31307,
14,
46,
2319,
6158,
342,
267,
291,
423,
6625,
275,
18610,
63,
773,
14,
3716,
88,
342,
267,
291,
14,
8957,
275,
10098,
548,
14,
11975,
1858,
9029,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
423,
6625,
14,
1358,
409,
8067,
83,
342,
267,
291,
14,
8957,
14,
1358,
409,
2422,
342,
339,
347,
10098,
63,
548,
63,
1397,
63,
19540,
316,
8,
277,
12,
1559,
12,
1921,
63,
354,
304,
267,
1921,
63,
475,
63,
1814,
275,
2519,
8,
1113,
12,
1921,
63,
354,
9,
267,
10098,
275,
18610,
63,
773,
14,
3346,
1692,
8,
962,
63,
475,
63,
1814,
9,
267,
291,
14,
8957,
14,
1084,
8,
1113,
12,
1921,
63,
354,
12,
10098,
9,
339,
347,
511,
63,
515,
63,
2444,
63,
5626,
63,
1107,
63,
2052,
8,
277,
304,
267,
408,
63,
515,
63,
2444,
1077,
372,
715,
340,
5672,
2529,
378,
624,
267,
18610,
275,
291,
423,
6625,
267,
18754,
275,
291,
423,
3090,
398,
18610,
14,
12088,
8,
24066,
12,
2513,
2526,
358,
267,
18754,
423,
2526,
360,
3736,
297,
291,
14,
2864,
63,
3817,
63,
2339,
12,
1255,
63,
305,
63,
1231,
29,
549,
9,
398,
18610,
14,
12982,
342,
398,
291,
14,
1815,
8,
24066,
423,
515,
63,
2444,
8,
277,
14,
2864,
63,
3817,
63,
2339,
430,
398,
18610,
14,
31912,
342,
339,
347,
511,
63,
515,
63,
2444,
63,
5626,
63,
1107,
63,
3910,
8,
277,
304,
267,
408,
63,
515,
63,
2444,
1077,
372,
715,
340,
5672,
3181,
1133,
372,
378,
624,
267,
18610,
275,
291,
423,
6625,
267,
18754,
275,
291,
423,
3090,
398,
18610,
14,
12088,
8,
24066,
12,
2513,
2526,
358,
267,
18754,
423,
2526,
360,
3736,
297,
291,
14,
2864,
63,
3817,
63,
2339,
12,
1255,
63,
305,
63,
1231,
29,
549,
12013,
288,
6061,
18111,
8,
3498,
32165,
8,
288,
4635,
628,
3736,
26,
3913,
5672,
658,
396,
14,
2424,
356,
3091,
4066,
570,
503,
2082,
2237,
398,
18610,
14,
12982,
342,
398,
291,
14,
3334,
8,
24066,
423,
515,
63,
2444,
8,
277,
14,
2864,
63,
3817,
63,
2339,
430,
398,
18610,
14,
31912,
342,
339,
347,
511,
63,
1832,
63,
515,
8,
277,
304,
267,
408,
1832,
63,
515,
2863,
675,
1930,
624,
267,
31307,
14,
4831,
14,
19591,
63,
3956,
63,
1403,
63,
1095,
275,
291,
14,
2864,
63,
45,
12460,
63,
7217,
63,
5825,
267,
18754,
275,
291,
423,
3090,
398,
3301,
275,
577,
4295,
6464,
342,
267,
3301,
459,
3780,
63,
1985,
418,
275,
291,
14,
2864,
63,
46,
7079,
63,
18341,
17,
267,
3301,
459,
354,
418,
275,
283,
2405,
13,
4288,
7,
398,
291,
14,
629,
8,
288,
1994,
20481,
15,
396,
15,
18,
70,
20,
70,
28384,
1079,
2177,
2824,
67,
16447,
11829,
617,
28250,
70,
16,
11197,
65,
20,
15,
2405,
13,
4288,
297,
288,
18754,
14,
1832,
63,
515,
8,
2405,
430,
339,
347,
511,
63,
3956,
63,
19591,
63,
5626,
63,
3956,
63,
4525,
590,
8,
277,
304,
267,
408,
63,
3956,
63,
19591,
2863,
1930,
4503,
624,
267,
18610,
275,
291,
423,
6625,
267,
18754,
275,
291,
423,
3090,
398,
18610,
14,
12088,
8,
24066,
12,
2513,
515,
63,
2444,
358,
267,
18754,
423,
515,
63,
2444,
8,
277,
14,
2864,
63,
45,
12460,
63,
7217,
680,
8572,
8,
549,
9,
398,
18610,
14,
12088,
8,
24066
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
334,
67,
9,
6029,
28076,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
624,
5072,
2295,
367,
314,
653,
7079,
5253,
859,
624,
199,
199,
646,
747,
199,
646,
7554,
199,
646,
636,
5351,
363,
199,
199,
646,
18610,
465,
18610,
63,
773,
199,
504,
18610,
492,
29719,
199,
504,
18610,
492,
14092,
6373,
199,
504,
18610,
492,
10098,
548,
199,
199,
504,
13069,
492,
1067,
199,
504,
13069,
492,
1919,
199,
504,
13069,
492,
511,
199,
504,
13069,
14,
1971,
492,
7132,
32165,
199,
199,
504,
13069,
14,
2405,
492,
31307,
421,
199,
533,
577,
4295,
6464,
8,
785,
304,
272,
1504,
275,
1052,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
291,
14,
955,
59,
498,
61,
275,
574,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
14,
955,
59,
1053,
61,
421,
199,
533,
653,
2319,
6158,
1746,
8,
396,
14,
1746,
304,
272,
408,
774,
1930,
367,
653,
7079,
5253,
624,
339,
7393,
63,
46,
7079,
63,
18341,
17,
275,
283,
19591,
13,
1102,
17,
11254,
3790,
7,
272,
7393,
63,
46,
7079,
63,
18341,
18,
275,
283,
19591,
13,
1102,
18,
11254,
3790,
7,
272,
7393,
63,
4305,
63,
568,
63,
6487,
275,
413,
272,
7393,
63,
45,
12460,
63,
7217,
275,
1994,
20481,
15,
19591,
7,
272,
7393,
63,
45,
12460,
63,
7217,
63,
5825,
275,
1994,
20481,
15,
396,
7,
272,
7393,
63,
7486,
63,
3243,
275,
1994,
20481,
15,
19591,
15,
2405,
13,
4288,
7,
272,
7393,
63,
3817,
63,
2339,
275,
283,
396,
14,
2424,
7,
272,
7393,
63,
11152,
654,
63,
5569,
63,
3817,
275,
1994,
6839,
15,
12372,
15,
396,
13,
18318,
14,
2190,
7,
272,
13051,
63,
6487,
63,
568,
63,
20352,
275,
6619,
627,
6619,
627,
6619,
339,
347,
3613,
8,
277,
304,
267,
291,
423,
3090,
275,
31307,
14,
46,
2319,
6158,
342,
267,
291,
423,
6625,
275,
18610,
63,
773,
14,
3716,
88,
342,
267,
291,
14,
8957,
275,
10098,
548,
14,
11975,
1858,
9029,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
423,
6625,
14,
1358,
409,
8067,
83,
342,
267,
291,
14,
8957,
14,
1358,
409,
2422,
342,
339,
347,
10098,
63,
548,
63,
1397,
63,
19540,
316,
8,
277,
12,
1559,
12,
1921,
63,
354,
304,
267,
1921,
63,
475,
63,
1814,
275,
2519,
8,
1113,
12,
1921,
63,
354,
9,
267,
10098,
275,
18610,
63,
773,
14,
3346,
1692,
8,
962,
63,
475,
63,
1814,
9,
267,
291,
14,
8957,
14,
1084,
8,
1113,
12,
1921,
63,
354,
12,
10098,
9,
339,
347,
511,
63,
515,
63,
2444,
63,
5626,
63,
1107,
63,
2052,
8,
277,
304,
267,
408,
63,
515,
63,
2444,
1077,
372,
715,
340,
5672,
2529,
378,
624,
267,
18610,
275,
291,
423,
6625,
267,
18754,
275,
291,
423,
3090,
398,
18610,
14,
12088,
8,
24066,
12,
2513,
2526,
358,
267,
18754,
423,
2526,
360,
3736,
297,
291,
14,
2864,
63,
3817,
63,
2339,
12,
1255,
63,
305,
63,
1231,
29,
549,
9,
398,
18610,
14,
12982,
342,
398,
291,
14,
1815,
8,
24066,
423,
515,
63,
2444,
8,
277,
14,
2864,
63,
3817,
63,
2339,
430,
398,
18610,
14,
31912,
342,
339,
347,
511,
63,
515,
63,
2444,
63,
5626,
63,
1107,
63,
3910,
8,
277,
304,
267,
408,
63,
515,
63,
2444,
1077,
372,
715,
340,
5672,
3181,
1133,
372,
378,
624,
267,
18610,
275,
291,
423,
6625,
267,
18754,
275,
291,
423,
3090,
398,
18610,
14,
12088,
8,
24066,
12,
2513,
2526,
358,
267,
18754,
423,
2526,
360,
3736,
297,
291,
14,
2864,
63,
3817,
63,
2339,
12,
1255,
63,
305,
63,
1231,
29,
549,
12013,
288,
6061,
18111,
8,
3498,
32165,
8,
288,
4635,
628,
3736,
26,
3913,
5672,
658,
396,
14,
2424,
356,
3091,
4066,
570,
503,
2082,
2237,
398,
18610,
14,
12982,
342,
398,
291,
14,
3334,
8,
24066,
423,
515,
63,
2444,
8,
277,
14,
2864,
63,
3817,
63,
2339,
430,
398,
18610,
14,
31912,
342,
339,
347,
511,
63,
1832,
63,
515,
8,
277,
304,
267,
408,
1832,
63,
515,
2863,
675,
1930,
624,
267,
31307,
14,
4831,
14,
19591,
63,
3956,
63,
1403,
63,
1095,
275,
291,
14,
2864,
63,
45,
12460,
63,
7217,
63,
5825,
267,
18754,
275,
291,
423,
3090,
398,
3301,
275,
577,
4295,
6464,
342,
267,
3301,
459,
3780,
63,
1985,
418,
275,
291,
14,
2864,
63,
46,
7079,
63,
18341,
17,
267,
3301,
459,
354,
418,
275,
283,
2405,
13,
4288,
7,
398,
291,
14,
629,
8,
288,
1994,
20481,
15,
396,
15,
18,
70,
20,
70,
28384,
1079,
2177,
2824,
67,
16447,
11829,
617,
28250,
70,
16,
11197,
65,
20,
15,
2405,
13,
4288,
297,
288,
18754,
14,
1832,
63,
515,
8,
2405,
430,
339,
347,
511,
63,
3956,
63,
19591,
63,
5626,
63,
3956,
63,
4525,
590,
8,
277,
304,
267,
408,
63,
3956,
63,
19591,
2863,
1930,
4503,
624,
267,
18610,
275,
291,
423,
6625,
267,
18754,
275,
291,
423,
3090,
398,
18610,
14,
12088,
8,
24066,
12,
2513,
515,
63,
2444,
358,
267,
18754,
423,
515,
63,
2444,
8,
277,
14,
2864,
63,
45,
12460,
63,
7217,
680,
8572,
8,
549,
9,
398,
18610,
14,
12088,
8,
24066,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hexxcointakeover/hexxcoin
|
qa/rpc-tests/disablewallet.py
|
102
|
1820
|
#!/usr/bin/env python3
# Copyright (c) 2015-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Exercise API with -disablewallet.
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
class DisableWalletTest (BitcoinTestFramework):
def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False):
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [['-disablewallet']])
self.is_network_split = False
self.sync_all()
def run_test (self):
# Check regression: https://github.com/bitcoin/bitcoin/issues/6963#issuecomment-154548880
x = self.nodes[0].validateaddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
assert(x['isvalid'] == False)
x = self.nodes[0].validateaddress('mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
assert(x['isvalid'] == True)
# Checking mining to an address without a wallet
try:
self.nodes[0].generatetoaddress(1, 'mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
except JSONRPCException as e:
assert("Invalid address" not in e.error['message'])
assert("ProcessNewBlock, block not accepted" not in e.error['message'])
assert("Couldn't create new block" not in e.error['message'])
try:
self.nodes[0].generatetoaddress(1, '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
raise AssertionError("Must not mine to invalid address!")
except JSONRPCException as e:
assert("Invalid address" in e.error['message'])
if __name__ == '__main__':
DisableWalletTest ().main ()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6900,
13,
9261,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
199,
3,
199,
3,
1316,
20616,
3261,
543,
446,
5993,
13892,
14,
199,
3,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
627,
421,
199,
533,
17534,
55,
9478,
774,
334,
4734,
9061,
26203,
304,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
715,
267,
291,
14,
1507,
63,
2415,
275,
413,
339,
347,
3272,
63,
1200,
8,
277,
12,
3715,
29,
797,
304,
267,
291,
14,
2415,
275,
1343,
63,
2415,
8,
277,
14,
1507,
63,
2415,
12,
291,
14,
1419,
14,
8616,
12,
11194,
13,
5993,
13892,
12121,
267,
291,
14,
374,
63,
1200,
63,
1294,
275,
756,
267,
291,
14,
5186,
63,
452,
342,
339,
347,
1255,
63,
396,
334,
277,
304,
267,
327,
2670,
10864,
26,
4178,
921,
5031,
14,
957,
15,
22816,
15,
22816,
15,
10115,
15,
1876,
2766,
3,
5237,
3349,
13,
10478,
1477,
1299,
1257,
267,
671,
275,
291,
14,
2415,
59,
16,
1055,
3502,
1562,
360,
19,
42,
2905,
84,
17,
55,
80,
37,
58,
2898,
12874,
77,
49,
433,
825,
82,
9745,
73,
55,
11641,
81,
50,
72,
3705,
27480,
358,
267,
702,
8,
88,
459,
374,
1078,
418,
508,
756,
9,
267,
671,
275,
291,
14,
2415,
59,
16,
1055,
3502,
1562,
360,
22599,
57,
53,
77,
55,
57,
83,
3210,
23,
10562,
18934,
1230,
8163,
73,
19,
1254,
15775,
33,
81,
58,
88,
44,
71,
48,
58,
358,
267,
702,
8,
88,
459,
374,
1078,
418,
508,
715,
9,
398,
327,
25109,
1748,
316,
370,
376,
2287,
1928,
282,
20534,
267,
862,
26,
288,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
17,
12,
283,
22599,
57,
53,
77,
55,
57,
83,
3210,
23,
10562,
18934,
1230,
8163,
73,
19,
1254,
15775,
33,
81,
58,
88,
44,
71,
48,
58,
358,
267,
871,
4840,
8171,
1726,
465,
325,
26,
288,
702,
480,
3364,
2287,
2,
440,
315,
325,
14,
705,
459,
1188,
1105,
288,
702,
480,
3498,
4665,
3142,
12,
1853,
440,
10226,
2,
440,
315,
325,
14,
705,
459,
1188,
1105,
288,
702,
480,
20485,
1133,
1218,
892,
1853,
2,
440,
315,
325,
14,
705,
459,
1188,
1105,
398,
862,
26,
288,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
17,
12,
283,
19,
42,
2905,
84,
17,
55,
80,
37,
58,
2898,
12874,
77,
49,
433,
825,
82,
9745,
73,
55,
11641,
81,
50,
72,
3705,
27480,
358,
288,
746,
9070,
480,
13757,
440,
30820,
370,
3866,
2287,
9124,
267,
871,
4840,
8171,
1726,
465,
325,
26,
288,
702,
480,
3364,
2287,
2,
315,
325,
14,
705,
459,
1188,
1105,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
17534,
55,
9478,
774,
334,
680,
973,
6248,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6900,
13,
9261,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
199,
3,
199,
3,
1316,
20616,
3261,
543,
446,
5993,
13892,
14,
199,
3,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
627,
421,
199,
533,
17534,
55,
9478,
774,
334,
4734,
9061,
26203,
304,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
715,
267,
291,
14,
1507,
63,
2415,
275,
413,
339,
347,
3272,
63,
1200,
8,
277,
12,
3715,
29,
797,
304,
267,
291,
14,
2415,
275,
1343,
63,
2415,
8,
277,
14,
1507,
63,
2415,
12,
291,
14,
1419,
14,
8616,
12,
11194,
13,
5993,
13892,
12121,
267,
291,
14,
374,
63,
1200,
63,
1294,
275,
756,
267,
291,
14,
5186,
63,
452,
342,
339,
347,
1255,
63,
396,
334,
277,
304,
267,
327,
2670,
10864,
26,
4178,
921,
5031,
14,
957,
15,
22816,
15,
22816,
15,
10115,
15,
1876,
2766,
3,
5237,
3349,
13,
10478,
1477,
1299,
1257,
267,
671,
275,
291,
14,
2415,
59,
16,
1055,
3502,
1562,
360,
19,
42,
2905,
84,
17,
55,
80,
37,
58,
2898,
12874,
77,
49,
433,
825,
82,
9745,
73,
55,
11641,
81,
50,
72,
3705,
27480,
358,
267,
702,
8,
88,
459,
374,
1078,
418,
508,
756,
9,
267,
671,
275,
291,
14,
2415,
59,
16,
1055,
3502,
1562,
360,
22599,
57,
53,
77,
55,
57,
83,
3210,
23,
10562,
18934,
1230,
8163,
73,
19,
1254,
15775,
33,
81,
58,
88,
44,
71,
48,
58,
358,
267,
702,
8,
88,
459,
374,
1078,
418,
508,
715,
9,
398,
327,
25109,
1748,
316,
370,
376,
2287,
1928,
282,
20534,
267,
862,
26,
288,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
17,
12,
283,
22599,
57,
53,
77,
55,
57,
83,
3210,
23,
10562,
18934,
1230,
8163,
73,
19,
1254,
15775,
33,
81,
58,
88,
44,
71,
48,
58,
358,
267,
871,
4840,
8171,
1726,
465,
325,
26,
288,
702,
480,
3364,
2287,
2,
440,
315,
325,
14,
705,
459,
1188,
1105,
288,
702,
480,
3498,
4665,
3142,
12,
1853,
440,
10226,
2,
440,
315,
325,
14,
705,
459,
1188,
1105,
288,
702,
480,
20485,
1133,
1218,
892,
1853,
2,
440,
315,
325,
14,
705,
459,
1188,
1105,
398,
862,
26,
288,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
17,
12,
283,
19,
42,
2905,
84,
17,
55,
80,
37,
58,
2898,
12874,
77,
49,
433,
825,
82,
9745,
73,
55,
11641,
81,
50,
72,
3705,
27480,
358,
288,
746,
9070,
480,
13757,
440,
30820,
370,
3866,
2287,
9124,
267,
871,
4840,
8171,
1726,
465,
325,
26,
288,
702,
480,
3364,
2287,
2,
315,
325,
14,
705,
459,
1188,
1105,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
17534,
55,
9478,
774,
334,
680,
973,
6248,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
nzavagli/UnrealPy
|
UnrealPyEmbed/Development/Python/2015.08.07-Python2710-x64-Source-vs2015/Python27/Source/boto-2.38.0/boto/dynamodb2/items.py
|
103
|
14658
|
from copy import deepcopy
class NEWVALUE(object):
# A marker for new data added.
pass
class Item(object):
"""
An object representing the item data within a DynamoDB table.
An item is largely schema-free, meaning it can contain any data. The only
limitation is that it must have data for the fields in the ``Table``'s
schema.
This object presents a dictionary-like interface for accessing/storing
data. It also tries to intelligently track how data has changed throughout
the life of the instance, to be as efficient as possible about updates.
Empty items, or items that have no data, are considered falsey.
"""
def __init__(self, table, data=None, loaded=False):
"""
Constructs an (unsaved) ``Item`` instance.
To persist the data in DynamoDB, you'll need to call the ``Item.save``
(or ``Item.partial_save``) on the instance.
Requires a ``table`` parameter, which should be a ``Table`` instance.
This is required, as DynamoDB's API is focus around all operations
being table-level. It's also for persisting schema around many objects.
Optionally accepts a ``data`` parameter, which should be a dictionary
of the fields & values of the item. Alternatively, an ``Item`` instance
may be provided from which to extract the data.
Optionally accepts a ``loaded`` parameter, which should be a boolean.
``True`` if it was preexisting data loaded from DynamoDB, ``False`` if
it's new data from the user. Default is ``False``.
Example::
>>> users = Table('users')
>>> user = Item(users, data={
... 'username': 'johndoe',
... 'first_name': 'John',
... 'date_joined': 1248o61592,
... })
# Change existing data.
>>> user['first_name'] = 'Johann'
# Add more data.
>>> user['last_name'] = 'Doe'
# Delete data.
>>> del user['date_joined']
# Iterate over all the data.
>>> for field, val in user.items():
... print "%s: %s" % (field, val)
username: johndoe
first_name: John
date_joined: 1248o61592
"""
self.table = table
self._loaded = loaded
self._orig_data = {}
self._data = data
self._dynamizer = table._dynamizer
if isinstance(self._data, Item):
self._data = self._data._data
if self._data is None:
self._data = {}
if self._loaded:
self._orig_data = deepcopy(self._data)
def __getitem__(self, key):
return self._data.get(key, None)
def __setitem__(self, key, value):
self._data[key] = value
def __delitem__(self, key):
if not key in self._data:
return
del self._data[key]
def keys(self):
return self._data.keys()
def values(self):
return self._data.values()
def items(self):
return self._data.items()
def get(self, key, default=None):
return self._data.get(key, default)
def __iter__(self):
for key in self._data:
yield self._data[key]
def __contains__(self, key):
return key in self._data
def __bool__(self):
return bool(self._data)
__nonzero__ = __bool__
def _determine_alterations(self):
"""
Checks the ``-orig_data`` against the ``_data`` to determine what
changes to the data are present.
Returns a dictionary containing the keys ``adds``, ``changes`` &
``deletes``, containing the updated data.
"""
alterations = {
'adds': {},
'changes': {},
'deletes': [],
}
orig_keys = set(self._orig_data.keys())
data_keys = set(self._data.keys())
# Run through keys we know are in both for changes.
for key in orig_keys.intersection(data_keys):
if self._data[key] != self._orig_data[key]:
if self._is_storable(self._data[key]):
alterations['changes'][key] = self._data[key]
else:
alterations['deletes'].append(key)
# Run through additions.
for key in data_keys.difference(orig_keys):
if self._is_storable(self._data[key]):
alterations['adds'][key] = self._data[key]
# Run through deletions.
for key in orig_keys.difference(data_keys):
alterations['deletes'].append(key)
return alterations
def needs_save(self, data=None):
"""
Returns whether or not the data has changed on the ``Item``.
Optionally accepts a ``data`` argument, which accepts the output from
``self._determine_alterations()`` if you've already called it. Typically
unnecessary to do. Default is ``None``.
Example:
>>> user.needs_save()
False
>>> user['first_name'] = 'Johann'
>>> user.needs_save()
True
"""
if data is None:
data = self._determine_alterations()
needs_save = False
for kind in ['adds', 'changes', 'deletes']:
if len(data[kind]):
needs_save = True
break
return needs_save
def mark_clean(self):
"""
Marks an ``Item`` instance as no longer needing to be saved.
Example:
>>> user.needs_save()
False
>>> user['first_name'] = 'Johann'
>>> user.needs_save()
True
>>> user.mark_clean()
>>> user.needs_save()
False
"""
self._orig_data = deepcopy(self._data)
def mark_dirty(self):
"""
DEPRECATED: Marks an ``Item`` instance as needing to be saved.
This method is no longer necessary, as the state tracking on ``Item``
has been improved to automatically detect proper state.
"""
return
def load(self, data):
"""
This is only useful when being handed raw data from DynamoDB directly.
If you have a Python datastructure already, use the ``__init__`` or
manually set the data instead.
Largely internal, unless you know what you're doing or are trying to
mix the low-level & high-level APIs.
"""
self._data = {}
for field_name, field_value in data.get('Item', {}).items():
self[field_name] = self._dynamizer.decode(field_value)
self._loaded = True
self._orig_data = deepcopy(self._data)
def get_keys(self):
"""
Returns a Python-style dict of the keys/values.
Largely internal.
"""
key_fields = self.table.get_key_fields()
key_data = {}
for key in key_fields:
key_data[key] = self[key]
return key_data
def get_raw_keys(self):
"""
Returns a DynamoDB-style dict of the keys/values.
Largely internal.
"""
raw_key_data = {}
for key, value in self.get_keys().items():
raw_key_data[key] = self._dynamizer.encode(value)
return raw_key_data
def build_expects(self, fields=None):
"""
Builds up a list of expecations to hand off to DynamoDB on save.
Largely internal.
"""
expects = {}
if fields is None:
fields = list(self._data.keys()) + list(self._orig_data.keys())
# Only uniques.
fields = set(fields)
for key in fields:
expects[key] = {
'Exists': True,
}
value = None
# Check for invalid keys.
if not key in self._orig_data and not key in self._data:
raise ValueError("Unknown key %s provided." % key)
# States:
# * New field (only in _data)
# * Unchanged field (in both _data & _orig_data, same data)
# * Modified field (in both _data & _orig_data, different data)
# * Deleted field (only in _orig_data)
orig_value = self._orig_data.get(key, NEWVALUE)
current_value = self._data.get(key, NEWVALUE)
if orig_value == current_value:
# Existing field unchanged.
value = current_value
else:
if key in self._data:
if not key in self._orig_data:
# New field.
expects[key]['Exists'] = False
else:
# Existing field modified.
value = orig_value
else:
# Existing field deleted.
value = orig_value
if value is not None:
expects[key]['Value'] = self._dynamizer.encode(value)
return expects
def _is_storable(self, value):
# We need to prevent ``None``, empty string & empty set from
# heading to DDB, but allow false-y values like 0 & False make it.
if not value:
if not value in (0, 0.0, False):
return False
return True
def prepare_full(self):
"""
Runs through all fields & encodes them to be handed off to DynamoDB
as part of an ``save`` (``put_item``) call.
Largely internal.
"""
# This doesn't save on it's own. Rather, we prepare the datastructure
# and hand-off to the table to handle creation/update.
final_data = {}
for key, value in self._data.items():
if not self._is_storable(value):
continue
final_data[key] = self._dynamizer.encode(value)
return final_data
def prepare_partial(self):
"""
Runs through **ONLY** the changed/deleted fields & encodes them to be
handed off to DynamoDB as part of an ``partial_save`` (``update_item``)
call.
Largely internal.
"""
# This doesn't save on it's own. Rather, we prepare the datastructure
# and hand-off to the table to handle creation/update.
final_data = {}
fields = set()
alterations = self._determine_alterations()
for key, value in alterations['adds'].items():
final_data[key] = {
'Action': 'PUT',
'Value': self._dynamizer.encode(self._data[key])
}
fields.add(key)
for key, value in alterations['changes'].items():
final_data[key] = {
'Action': 'PUT',
'Value': self._dynamizer.encode(self._data[key])
}
fields.add(key)
for key in alterations['deletes']:
final_data[key] = {
'Action': 'DELETE',
}
fields.add(key)
return final_data, fields
def partial_save(self):
"""
Saves only the changed data to DynamoDB.
Extremely useful for high-volume/high-write data sets, this allows
you to update only a handful of fields rather than having to push
entire items. This prevents many accidental overwrite situations as
well as saves on the amount of data to transfer over the wire.
Returns ``True`` on success, ``False`` if no save was performed or
the write failed.
Example::
>>> user['last_name'] = 'Doh!'
# Only the last name field will be sent to DynamoDB.
>>> user.partial_save()
"""
key = self.get_keys()
# Build a new dict of only the data we're changing.
final_data, fields = self.prepare_partial()
if not final_data:
return False
# Remove the key(s) from the ``final_data`` if present.
# They should only be present if this is a new item, in which
# case we shouldn't be sending as part of the data to update.
for fieldname, value in key.items():
if fieldname in final_data:
del final_data[fieldname]
try:
# It's likely also in ``fields``, so remove it there too.
fields.remove(fieldname)
except KeyError:
pass
# Build expectations of only the fields we're planning to update.
expects = self.build_expects(fields=fields)
returned = self.table._update_item(key, final_data, expects=expects)
# Mark the object as clean.
self.mark_clean()
return returned
def save(self, overwrite=False):
"""
Saves all data to DynamoDB.
By default, this attempts to ensure that none of the underlying
data has changed. If any fields have changed in between when the
``Item`` was constructed & when it is saved, this call will fail so
as not to cause any data loss.
If you're sure possibly overwriting data is acceptable, you can pass
an ``overwrite=True``. If that's not acceptable, you may be able to use
``Item.partial_save`` to only write the changed field data.
Optionally accepts an ``overwrite`` parameter, which should be a
boolean. If you provide ``True``, the item will be forcibly overwritten
within DynamoDB, even if another process changed the data in the
meantime. (Default: ``False``)
Returns ``True`` on success, ``False`` if no save was performed.
Example::
>>> user['last_name'] = 'Doh!'
# All data on the Item is sent to DynamoDB.
>>> user.save()
# If it fails, you can overwrite.
>>> user.save(overwrite=True)
"""
if not self.needs_save() and not overwrite:
return False
final_data = self.prepare_full()
expects = None
if overwrite is False:
# Build expectations about *all* of the data.
expects = self.build_expects()
returned = self.table._put_item(final_data, expects=expects)
# Mark the object as clean.
self.mark_clean()
return returned
def delete(self):
"""
Deletes the item's data to DynamoDB.
Returns ``True`` on success.
Example::
# Buh-bye now.
>>> user.delete()
"""
key_data = self.get_keys()
return self.table.delete_item(**key_data)
|
mit
|
[
504,
1331,
492,
14800,
421,
199,
533,
18689,
7041,
8,
785,
304,
272,
327,
437,
3608,
367,
892,
666,
3483,
14,
272,
986,
421,
199,
533,
7020,
8,
785,
304,
272,
408,
272,
1626,
909,
6144,
314,
1242,
666,
4453,
282,
31856,
1817,
14,
339,
1626,
1242,
365,
7031,
590,
4177,
13,
4624,
12,
11150,
652,
883,
1395,
1263,
666,
14,
710,
1454,
272,
12305,
365,
626,
652,
1471,
1172,
666,
367,
314,
1504,
315,
314,
1124,
3186,
1040,
7,
83,
272,
4177,
14,
339,
961,
909,
3451,
83,
282,
2600,
13,
2930,
3217,
367,
18549,
15,
270,
6854,
272,
666,
14,
2779,
2597,
11275,
370,
4661,
24024,
590,
4426,
4212,
666,
965,
2896,
23088,
272,
314,
15451,
402,
314,
1256,
12,
370,
506,
465,
13402,
465,
3962,
3595,
7029,
14,
339,
9630,
2974,
12,
503,
2974,
626,
1172,
949,
666,
12,
787,
8652,
3055,
89,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
1817,
12,
666,
29,
403,
12,
6511,
29,
797,
304,
267,
408,
267,
9215,
83,
376,
334,
324,
8420,
9,
1124,
2081,
1040,
1256,
14,
398,
4005,
22400,
314,
666,
315,
31856,
12,
1265,
7171,
1929,
370,
1240,
314,
1124,
2081,
14,
2117,
1040,
267,
334,
269,
1124,
2081,
14,
6672,
63,
2117,
16580,
641,
314,
1256,
14,
398,
15127,
282,
1124,
1224,
1040,
2725,
12,
1314,
1077,
506,
282,
1124,
3186,
1040,
1256,
14,
267,
961,
365,
1415,
12,
465,
31856,
1159,
3261,
365,
16470,
6818,
1006,
5331,
267,
3769,
1817,
13,
1896,
14,
2779,
1159,
2597,
367,
22400,
316,
4177,
6818,
5002,
2251,
14,
398,
22383,
11479,
282,
1124,
576,
1040,
2725,
12,
1314,
1077,
506,
282,
2600,
267,
402,
314,
1504,
1253,
1338,
402,
314,
1242,
14,
26776,
12,
376,
1124,
2081,
1040,
1256,
267,
1443,
506,
2741,
687,
1314,
370,
5536,
314,
666,
14,
398,
22383,
11479,
282,
1124,
4591,
1040,
2725,
12,
1314,
1077,
506,
282,
5046,
14,
267,
1124,
549,
1040,
340,
652,
1990,
876,
5952,
666,
6511,
687,
31856,
12,
1124,
797,
1040,
340,
267,
652,
1159,
892,
666,
687,
314,
922,
14,
3758,
365,
1124,
797,
4345,
398,
5679,
447,
953,
1306,
4390,
275,
6957,
360,
3707,
358,
288,
1306,
922,
275,
7020,
8,
3707,
12,
666,
3126,
288,
2263,
258,
283,
2473,
356,
283,
31073,
977,
13361,
297,
288,
2263,
258,
283,
2246,
63,
354,
356,
283,
12923,
297,
288,
2263,
258,
283,
602,
63,
11806,
356,
413,
11242,
79,
28249,
2942,
12,
288,
2263,
3828,
953,
327,
7743,
3411,
666,
14,
288,
1306,
922,
459,
2246,
63,
354,
418,
275,
283,
5691,
72,
1189,
7,
288,
327,
2654,
1655,
666,
14,
288,
1306,
922,
459,
2019,
63,
354,
418,
275,
283,
2585,
69,
7,
288,
327,
8496,
666,
14,
288,
1306,
2150,
922,
459,
602,
63,
11806,
418,
953,
327,
23989,
1806,
1006,
314,
666,
14,
288,
1306,
367,
901,
12,
1139,
315,
922,
14,
1744,
837,
288,
2263,
258,
870,
2071,
83,
26,
450,
83,
2,
450,
334,
698,
12,
1139,
9,
288,
3434,
26,
5225,
72,
977,
13361,
288,
1642,
63,
354,
26,
17815,
288,
1434,
63,
11806,
26,
413,
11242,
79,
28249,
2942,
398,
408,
267,
291,
14,
1224,
275,
1817,
267,
291,
423,
4591,
275,
6511,
267,
291,
423,
2981,
63,
576,
275,
1052,
267,
291,
423,
576,
275,
666,
267,
291,
423,
20353,
1793,
275,
1817,
423,
20353,
1793,
398,
340,
1228,
8,
277,
423,
576,
12,
7020,
304,
288,
291,
423,
576,
275,
291,
423,
576,
423,
576,
267,
340,
291,
423,
576,
365,
488,
26,
288,
291,
423,
576,
275,
1052,
398,
340,
291,
423,
4591,
26,
288,
291,
423,
2981,
63,
576,
275,
14800,
8,
277,
423,
576,
9,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
423,
576,
14,
362,
8,
498,
12,
488,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
291,
423,
576,
59,
498,
61,
275,
574,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
340,
440,
790,
315,
291,
423,
576,
26,
288,
372,
398,
2150,
291,
423,
576,
59,
498,
61,
339,
347,
2883,
8,
277,
304,
267,
372,
291,
423,
576,
14,
1612,
342,
339,
347,
1338,
8,
277,
304,
267,
372,
291,
423,
576,
14,
1459,
342,
339,
347,
2974,
8,
277,
304,
267,
372,
291,
423,
576,
14,
1744,
342,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
372,
291,
423,
576,
14,
362,
8,
498,
12,
849,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
367,
790,
315,
291,
423,
576,
26,
288,
1995,
291,
423,
576,
59,
498,
61,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
372,
790,
315,
291,
423,
576,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
2155,
8,
277,
423,
576,
9,
339,
636,
10262,
363,
275,
636,
2245,
363,
339,
347,
485,
22189,
63,
279,
23029,
8,
277,
304,
267,
408,
267,
13813,
314,
27810,
2981,
63,
576,
1040,
6169,
314,
24507,
576,
1040,
370,
6705,
4052,
267,
4493,
370,
314,
666,
787,
3451,
14,
398,
1803,
282,
2600,
3035,
314,
2883,
1124,
525,
83,
4542,
1124,
6627,
1040,
1253,
267,
1124,
26289,
4542,
3035,
314,
4588,
666,
14,
267,
408,
267,
741,
23029,
275,
469,
288,
283,
525,
83,
356,
5479,
288,
283,
6627,
356,
5479,
288,
283,
26289,
356,
990,
267,
789,
398,
2306,
63,
1612,
275,
663,
8,
277,
423,
2981,
63,
576,
14,
1612,
1012,
267,
666,
63,
1612,
275,
663,
8,
277,
423,
576,
14,
1612,
1012,
398,
327,
3378,
4012,
2883,
781,
5715,
787,
315,
3865,
367,
4493,
14,
267,
367,
790,
315,
2306,
63,
1612,
14,
12569,
8,
576,
63,
1612,
304,
288,
340,
291,
423,
576,
59,
498,
61,
1137,
291,
423,
2981,
63,
576,
59,
498,
2189,
355,
340,
291,
423,
374,
63,
8041,
461,
8,
277,
423,
576,
59,
498,
4682,
490,
741,
23029,
459,
6627,
3488,
498,
61,
275,
291,
423,
576,
59,
498,
61,
355,
587,
26,
490,
741,
23029,
459,
26289,
2278,
740,
8,
498,
9,
398,
327,
3378,
4012,
32113,
14,
267,
367,
790,
315,
666,
63,
1612,
14
] |
[
1331,
492,
14800,
421,
199,
533,
18689,
7041,
8,
785,
304,
272,
327,
437,
3608,
367,
892,
666,
3483,
14,
272,
986,
421,
199,
533,
7020,
8,
785,
304,
272,
408,
272,
1626,
909,
6144,
314,
1242,
666,
4453,
282,
31856,
1817,
14,
339,
1626,
1242,
365,
7031,
590,
4177,
13,
4624,
12,
11150,
652,
883,
1395,
1263,
666,
14,
710,
1454,
272,
12305,
365,
626,
652,
1471,
1172,
666,
367,
314,
1504,
315,
314,
1124,
3186,
1040,
7,
83,
272,
4177,
14,
339,
961,
909,
3451,
83,
282,
2600,
13,
2930,
3217,
367,
18549,
15,
270,
6854,
272,
666,
14,
2779,
2597,
11275,
370,
4661,
24024,
590,
4426,
4212,
666,
965,
2896,
23088,
272,
314,
15451,
402,
314,
1256,
12,
370,
506,
465,
13402,
465,
3962,
3595,
7029,
14,
339,
9630,
2974,
12,
503,
2974,
626,
1172,
949,
666,
12,
787,
8652,
3055,
89,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
1817,
12,
666,
29,
403,
12,
6511,
29,
797,
304,
267,
408,
267,
9215,
83,
376,
334,
324,
8420,
9,
1124,
2081,
1040,
1256,
14,
398,
4005,
22400,
314,
666,
315,
31856,
12,
1265,
7171,
1929,
370,
1240,
314,
1124,
2081,
14,
2117,
1040,
267,
334,
269,
1124,
2081,
14,
6672,
63,
2117,
16580,
641,
314,
1256,
14,
398,
15127,
282,
1124,
1224,
1040,
2725,
12,
1314,
1077,
506,
282,
1124,
3186,
1040,
1256,
14,
267,
961,
365,
1415,
12,
465,
31856,
1159,
3261,
365,
16470,
6818,
1006,
5331,
267,
3769,
1817,
13,
1896,
14,
2779,
1159,
2597,
367,
22400,
316,
4177,
6818,
5002,
2251,
14,
398,
22383,
11479,
282,
1124,
576,
1040,
2725,
12,
1314,
1077,
506,
282,
2600,
267,
402,
314,
1504,
1253,
1338,
402,
314,
1242,
14,
26776,
12,
376,
1124,
2081,
1040,
1256,
267,
1443,
506,
2741,
687,
1314,
370,
5536,
314,
666,
14,
398,
22383,
11479,
282,
1124,
4591,
1040,
2725,
12,
1314,
1077,
506,
282,
5046,
14,
267,
1124,
549,
1040,
340,
652,
1990,
876,
5952,
666,
6511,
687,
31856,
12,
1124,
797,
1040,
340,
267,
652,
1159,
892,
666,
687,
314,
922,
14,
3758,
365,
1124,
797,
4345,
398,
5679,
447,
953,
1306,
4390,
275,
6957,
360,
3707,
358,
288,
1306,
922,
275,
7020,
8,
3707,
12,
666,
3126,
288,
2263,
258,
283,
2473,
356,
283,
31073,
977,
13361,
297,
288,
2263,
258,
283,
2246,
63,
354,
356,
283,
12923,
297,
288,
2263,
258,
283,
602,
63,
11806,
356,
413,
11242,
79,
28249,
2942,
12,
288,
2263,
3828,
953,
327,
7743,
3411,
666,
14,
288,
1306,
922,
459,
2246,
63,
354,
418,
275,
283,
5691,
72,
1189,
7,
288,
327,
2654,
1655,
666,
14,
288,
1306,
922,
459,
2019,
63,
354,
418,
275,
283,
2585,
69,
7,
288,
327,
8496,
666,
14,
288,
1306,
2150,
922,
459,
602,
63,
11806,
418,
953,
327,
23989,
1806,
1006,
314,
666,
14,
288,
1306,
367,
901,
12,
1139,
315,
922,
14,
1744,
837,
288,
2263,
258,
870,
2071,
83,
26,
450,
83,
2,
450,
334,
698,
12,
1139,
9,
288,
3434,
26,
5225,
72,
977,
13361,
288,
1642,
63,
354,
26,
17815,
288,
1434,
63,
11806,
26,
413,
11242,
79,
28249,
2942,
398,
408,
267,
291,
14,
1224,
275,
1817,
267,
291,
423,
4591,
275,
6511,
267,
291,
423,
2981,
63,
576,
275,
1052,
267,
291,
423,
576,
275,
666,
267,
291,
423,
20353,
1793,
275,
1817,
423,
20353,
1793,
398,
340,
1228,
8,
277,
423,
576,
12,
7020,
304,
288,
291,
423,
576,
275,
291,
423,
576,
423,
576,
267,
340,
291,
423,
576,
365,
488,
26,
288,
291,
423,
576,
275,
1052,
398,
340,
291,
423,
4591,
26,
288,
291,
423,
2981,
63,
576,
275,
14800,
8,
277,
423,
576,
9,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
423,
576,
14,
362,
8,
498,
12,
488,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
291,
423,
576,
59,
498,
61,
275,
574,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
340,
440,
790,
315,
291,
423,
576,
26,
288,
372,
398,
2150,
291,
423,
576,
59,
498,
61,
339,
347,
2883,
8,
277,
304,
267,
372,
291,
423,
576,
14,
1612,
342,
339,
347,
1338,
8,
277,
304,
267,
372,
291,
423,
576,
14,
1459,
342,
339,
347,
2974,
8,
277,
304,
267,
372,
291,
423,
576,
14,
1744,
342,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
372,
291,
423,
576,
14,
362,
8,
498,
12,
849,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
367,
790,
315,
291,
423,
576,
26,
288,
1995,
291,
423,
576,
59,
498,
61,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
372,
790,
315,
291,
423,
576,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
2155,
8,
277,
423,
576,
9,
339,
636,
10262,
363,
275,
636,
2245,
363,
339,
347,
485,
22189,
63,
279,
23029,
8,
277,
304,
267,
408,
267,
13813,
314,
27810,
2981,
63,
576,
1040,
6169,
314,
24507,
576,
1040,
370,
6705,
4052,
267,
4493,
370,
314,
666,
787,
3451,
14,
398,
1803,
282,
2600,
3035,
314,
2883,
1124,
525,
83,
4542,
1124,
6627,
1040,
1253,
267,
1124,
26289,
4542,
3035,
314,
4588,
666,
14,
267,
408,
267,
741,
23029,
275,
469,
288,
283,
525,
83,
356,
5479,
288,
283,
6627,
356,
5479,
288,
283,
26289,
356,
990,
267,
789,
398,
2306,
63,
1612,
275,
663,
8,
277,
423,
2981,
63,
576,
14,
1612,
1012,
267,
666,
63,
1612,
275,
663,
8,
277,
423,
576,
14,
1612,
1012,
398,
327,
3378,
4012,
2883,
781,
5715,
787,
315,
3865,
367,
4493,
14,
267,
367,
790,
315,
2306,
63,
1612,
14,
12569,
8,
576,
63,
1612,
304,
288,
340,
291,
423,
576,
59,
498,
61,
1137,
291,
423,
2981,
63,
576,
59,
498,
2189,
355,
340,
291,
423,
374,
63,
8041,
461,
8,
277,
423,
576,
59,
498,
4682,
490,
741,
23029,
459,
6627,
3488,
498,
61,
275,
291,
423,
576,
59,
498,
61,
355,
587,
26,
490,
741,
23029,
459,
26289,
2278,
740,
8,
498,
9,
398,
327,
3378,
4012,
32113,
14,
267,
367,
790,
315,
666,
63,
1612,
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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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
] |
fossoult/odoo
|
addons/lunch/report/__init__.py
|
441
|
1087
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import order
import report_lunch_order
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
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,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
1865,
199,
646,
3622,
63,
76,
4689,
63,
1648,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
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,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
1865,
199,
646,
3622,
63,
76,
4689,
63,
1648,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
mmazanec22/too-windy
|
env/lib/python3.5/site-packages/dateutil/tz/_common.py
|
46
|
11744
|
from six import PY3
from six.moves import _thread
from datetime import datetime, timedelta, tzinfo
import copy
ZERO = timedelta(0)
__all__ = ['tzname_in_python2', 'enfold']
def tzname_in_python2(namefunc):
"""Change unicode output into bytestrings in Python 2
tzname() API changed in Python 3. It used to return bytes, but was changed
to unicode strings
"""
def adjust_encoding(*args, **kwargs):
name = namefunc(*args, **kwargs)
if name is not None and not PY3:
name = name.encode()
return name
return adjust_encoding
# The following is adapted from Alexander Belopolsky's tz library
# https://github.com/abalkin/tz
if hasattr(datetime, 'fold'):
# This is the pre-python 3.6 fold situation
def enfold(dt, fold=1):
"""
Provides a unified interface for assigning the ``fold`` attribute to
datetimes both before and after the implementation of PEP-495.
:param fold:
The value for the ``fold`` attribute in the returned datetime. This
should be either 0 or 1.
:return:
Returns an object for which ``getattr(dt, 'fold', 0)`` returns
``fold`` for all versions of Python. In versions prior to
Python 3.6, this is a ``_DatetimeWithFold`` object, which is a
subclass of :py:class:`datetime.datetime` with the ``fold``
attribute added, if ``fold`` is 1.
..versionadded:: 2.6.0
"""
return dt.replace(fold=fold)
else:
class _DatetimeWithFold(datetime):
"""
This is a class designed to provide a PEP 495-compliant interface for
Python versions before 3.6. It is used only for dates in a fold, so
the ``fold`` attribute is fixed at ``1``.
..versionadded:: 2.6.0
"""
__slots__ = ()
@property
def fold(self):
return 1
def enfold(dt, fold=1):
"""
Provides a unified interface for assigning the ``fold`` attribute to
datetimes both before and after the implementation of PEP-495.
:param fold:
The value for the ``fold`` attribute in the returned datetime. This
should be either 0 or 1.
:return:
Returns an object for which ``getattr(dt, 'fold', 0)`` returns
``fold`` for all versions of Python. In versions prior to
Python 3.6, this is a ``_DatetimeWithFold`` object, which is a
subclass of :py:class:`datetime.datetime` with the ``fold``
attribute added, if ``fold`` is 1.
..versionadded:: 2.6.0
"""
if getattr(dt, 'fold', 0) == fold:
return dt
args = dt.timetuple()[:6]
args += (dt.microsecond, dt.tzinfo)
if fold:
return _DatetimeWithFold(*args)
else:
return datetime(*args)
class _tzinfo(tzinfo):
"""
Base class for all ``dateutil`` ``tzinfo`` objects.
"""
def is_ambiguous(self, dt):
"""
Whether or not the "wall time" of a given datetime is ambiguous in this
zone.
:param dt:
A :py:class:`datetime.datetime`, naive or time zone aware.
:return:
Returns ``True`` if ambiguous, ``False`` otherwise.
..versionadded:: 2.6.0
"""
dt = dt.replace(tzinfo=self)
wall_0 = enfold(dt, fold=0)
wall_1 = enfold(dt, fold=1)
same_offset = wall_0.utcoffset() == wall_1.utcoffset()
same_dt = wall_0.replace(tzinfo=None) == wall_1.replace(tzinfo=None)
return same_dt and not same_offset
def _fold_status(self, dt_utc, dt_wall):
"""
Determine the fold status of a "wall" datetime, given a representation
of the same datetime as a (naive) UTC datetime. This is calculated based
on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all
datetimes, and that this offset is the actual number of hours separating
``dt_utc`` and ``dt_wall``.
:param dt_utc:
Representation of the datetime as UTC
:param dt_wall:
Representation of the datetime as "wall time". This parameter must
either have a `fold` attribute or have a fold-naive
:class:`datetime.tzinfo` attached, otherwise the calculation may
fail.
"""
if self.is_ambiguous(dt_wall):
delta_wall = dt_wall - dt_utc
_fold = int(delta_wall == (dt_utc.utcoffset() - dt_utc.dst()))
else:
_fold = 0
return _fold
def _fold(self, dt):
return getattr(dt, 'fold', 0)
def _fromutc(self, dt):
"""
Given a timezone-aware datetime in a given timezone, calculates a
timezone-aware datetime in a new timezone.
Since this is the one time that we *know* we have an unambiguous
datetime object, we take this opportunity to determine whether the
datetime is ambiguous and in a "fold" state (e.g. if it's the first
occurence, chronologically, of the ambiguous datetime).
:param dt:
A timezone-aware :class:`datetime.dateime` object.
"""
# Re-implement the algorithm from Python's datetime.py
if not isinstance(dt, datetime):
raise TypeError("fromutc() requires a datetime argument")
if dt.tzinfo is not self:
raise ValueError("dt.tzinfo is not self")
dtoff = dt.utcoffset()
if dtoff is None:
raise ValueError("fromutc() requires a non-None utcoffset() "
"result")
# The original datetime.py code assumes that `dst()` defaults to
# zero during ambiguous times. PEP 495 inverts this presumption, so
# for pre-PEP 495 versions of python, we need to tweak the algorithm.
dtdst = dt.dst()
if dtdst is None:
raise ValueError("fromutc() requires a non-None dst() result")
delta = dtoff - dtdst
if delta:
dt += delta
# Set fold=1 so we can default to being in the fold for
# ambiguous dates.
dtdst = enfold(dt, fold=1).dst()
if dtdst is None:
raise ValueError("fromutc(): dt.dst gave inconsistent "
"results; cannot convert")
return dt + dtdst
def fromutc(self, dt):
"""
Given a timezone-aware datetime in a given timezone, calculates a
timezone-aware datetime in a new timezone.
Since this is the one time that we *know* we have an unambiguous
datetime object, we take this opportunity to determine whether the
datetime is ambiguous and in a "fold" state (e.g. if it's the first
occurance, chronologically, of the ambiguous datetime).
:param dt:
A timezone-aware :class:`datetime.dateime` object.
"""
dt_wall = self._fromutc(dt)
# Calculate the fold status given the two datetimes.
_fold = self._fold_status(dt, dt_wall)
# Set the default fold value for ambiguous dates
return enfold(dt_wall, fold=_fold)
class tzrangebase(_tzinfo):
"""
This is an abstract base class for time zones represented by an annual
transition into and out of DST. Child classes should implement the following
methods:
* ``__init__(self, *args, **kwargs)``
* ``transitions(self, year)`` - this is expected to return a tuple of
datetimes representing the DST on and off transitions in standard
time.
A fully initialized ``tzrangebase`` subclass should also provide the
following attributes:
* ``hasdst``: Boolean whether or not the zone uses DST.
* ``_dst_offset`` / ``_std_offset``: :class:`datetime.timedelta` objects
representing the respective UTC offsets.
* ``_dst_abbr`` / ``_std_abbr``: Strings representing the timezone short
abbreviations in DST and STD, respectively.
* ``_hasdst``: Whether or not the zone has DST.
..versionadded:: 2.6.0
"""
def __init__(self):
raise NotImplementedError('tzrangebase is an abstract base class')
def utcoffset(self, dt):
isdst = self._isdst(dt)
if isdst is None:
return None
elif isdst:
return self._dst_offset
else:
return self._std_offset
def dst(self, dt):
isdst = self._isdst(dt)
if isdst is None:
return None
elif isdst:
return self._dst_base_offset
else:
return ZERO
@tzname_in_python2
def tzname(self, dt):
if self._isdst(dt):
return self._dst_abbr
else:
return self._std_abbr
def fromutc(self, dt):
""" Given a datetime in UTC, return local time """
if not isinstance(dt, datetime):
raise TypeError("fromutc() requires a datetime argument")
if dt.tzinfo is not self:
raise ValueError("dt.tzinfo is not self")
# Get transitions - if there are none, fixed offset
transitions = self.transitions(dt.year)
if transitions is None:
return dt + self.utcoffset(dt)
# Get the transition times in UTC
dston, dstoff = transitions
dston -= self._std_offset
dstoff -= self._std_offset
utc_transitions = (dston, dstoff)
dt_utc = dt.replace(tzinfo=None)
isdst = self._naive_isdst(dt_utc, utc_transitions)
if isdst:
dt_wall = dt + self._dst_offset
else:
dt_wall = dt + self._std_offset
_fold = int(not isdst and self.is_ambiguous(dt_wall))
return enfold(dt_wall, fold=_fold)
def is_ambiguous(self, dt):
"""
Whether or not the "wall time" of a given datetime is ambiguous in this
zone.
:param dt:
A :py:class:`datetime.datetime`, naive or time zone aware.
:return:
Returns ``True`` if ambiguous, ``False`` otherwise.
.. versionadded:: 2.6.0
"""
if not self.hasdst:
return False
start, end = self.transitions(dt.year)
dt = dt.replace(tzinfo=None)
return (end <= dt < end + self._dst_base_offset)
def _isdst(self, dt):
if not self.hasdst:
return False
elif dt is None:
return None
transitions = self.transitions(dt.year)
if transitions is None:
return False
dt = dt.replace(tzinfo=None)
isdst = self._naive_isdst(dt, transitions)
# Handle ambiguous dates
if not isdst and self.is_ambiguous(dt):
return not self._fold(dt)
else:
return isdst
def _naive_isdst(self, dt, transitions):
dston, dstoff = transitions
dt = dt.replace(tzinfo=None)
if dston < dstoff:
isdst = dston <= dt < dstoff
else:
isdst = not dstoff <= dt < dston
return isdst
@property
def _dst_base_offset(self):
return self._dst_offset - self._std_offset
__hash__ = None
def __ne__(self, other):
return not (self == other)
def __repr__(self):
return "%s(...)" % self.__class__.__name__
__reduce__ = object.__reduce__
def _total_seconds(td):
# Python 2.6 doesn't have a total_seconds() method on timedelta objects
return ((td.seconds + td.days * 86400) * 1000000 +
td.microseconds) // 1000000
_total_seconds = getattr(timedelta, 'total_seconds', _total_seconds)
|
gpl-3.0
|
[
504,
3816,
492,
7843,
19,
199,
504,
3816,
14,
4912,
492,
485,
2671,
199,
199,
504,
2197,
492,
2197,
12,
6871,
12,
10313,
199,
646,
1331,
199,
199,
24655,
275,
6871,
8,
16,
9,
199,
199,
363,
452,
363,
275,
788,
20027,
63,
262,
63,
1548,
18,
297,
283,
287,
14011,
418,
421,
199,
318,
28054,
63,
262,
63,
1548,
18,
8,
354,
1532,
304,
272,
408,
4001,
2649,
1072,
1901,
18792,
25182,
315,
2018,
499,
339,
28054,
342,
3261,
2896,
315,
2018,
650,
14,
2779,
1202,
370,
372,
2783,
12,
1325,
1990,
2896,
272,
370,
2649,
3326,
272,
408,
272,
347,
11311,
63,
2991,
2031,
589,
12,
1011,
958,
304,
267,
536,
275,
536,
1532,
2031,
589,
12,
1011,
958,
9,
267,
340,
536,
365,
440,
488,
436,
440,
7843,
19,
26,
288,
536,
275,
536,
14,
2143,
342,
398,
372,
536,
339,
372,
11311,
63,
2991,
421,
199,
3,
710,
2569,
365,
26266,
687,
22986,
11438,
6423,
320,
2515,
12267,
1159,
5823,
3555,
199,
3,
4178,
921,
5031,
14,
957,
15,
371,
4878,
262,
15,
3903,
199,
692,
2688,
8,
2083,
12,
283,
14011,
735,
272,
327,
961,
365,
314,
876,
13,
1548,
650,
14,
22,
20675,
25781,
272,
347,
655,
14011,
8,
3583,
12,
20675,
29,
17,
304,
267,
408,
267,
21552,
282,
25344,
3217,
367,
26694,
314,
1124,
14011,
1040,
2225,
370,
267,
29297,
3865,
2544,
436,
2410,
314,
4514,
402,
13663,
13,
20384,
14,
398,
520,
635,
20675,
26,
288,
710,
574,
367,
314,
1124,
14011,
1040,
2225,
315,
314,
2138,
2197,
14,
961,
288,
1077,
506,
1902,
378,
503,
413,
14,
398,
520,
1107,
26,
288,
1803,
376,
909,
367,
1314,
1124,
5675,
8,
3583,
12,
283,
14011,
297,
378,
9719,
2529,
288,
1124,
14011,
1040,
367,
1006,
5459,
402,
2018,
14,
1010,
5459,
6791,
370,
288,
2018,
650,
14,
22,
12,
642,
365,
282,
24507,
19636,
3007,
27985,
1040,
909,
12,
1314,
365,
282,
288,
5516,
402,
520,
647,
26,
533,
1705,
2083,
14,
2083,
64,
543,
314,
1124,
14011,
1040,
288,
2225,
3483,
12,
340,
1124,
14011,
1040,
365,
413,
14,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
267,
372,
4487,
14,
1814,
8,
14011,
29,
14011,
9,
199,
199,
2836,
26,
272,
1021,
485,
19636,
3007,
27985,
8,
2083,
304,
267,
408,
267,
961,
365,
282,
1021,
19829,
370,
5647,
282,
13663,
841,
2720,
13,
863,
22676,
3217,
367,
267,
2018,
5459,
2544,
650,
14,
22,
14,
2779,
365,
1202,
1454,
367,
10831,
315,
282,
20675,
12,
880,
267,
314,
1124,
14011,
1040,
2225,
365,
6317,
737,
1124,
17,
4345,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
267,
636,
7257,
363,
275,
6248,
398,
768,
1829,
267,
347,
20675,
8,
277,
304,
288,
372,
413,
339,
347,
655,
14011,
8,
3583,
12,
20675,
29,
17,
304,
267,
408,
267,
21552,
282,
25344,
3217,
367,
26694,
314,
1124,
14011,
1040,
2225,
370,
267,
29297,
3865,
2544,
436,
2410,
314,
4514,
402,
13663,
13,
20384,
14,
398,
520,
635,
20675,
26,
288,
710,
574,
367,
314,
1124,
14011,
1040,
2225,
315,
314,
2138,
2197,
14,
961,
288,
1077,
506,
1902,
378,
503,
413,
14,
398,
520,
1107,
26,
288,
1803,
376,
909,
367,
1314,
1124,
5675,
8,
3583,
12,
283,
14011,
297,
378,
9719,
2529,
288,
1124,
14011,
1040,
367,
1006,
5459,
402,
2018,
14,
1010,
5459,
6791,
370,
288,
2018,
650,
14,
22,
12,
642,
365,
282,
24507,
19636,
3007,
27985,
1040,
909,
12,
1314,
365,
282,
288,
5516,
402,
520,
647,
26,
533,
1705,
2083,
14,
2083,
64,
543,
314,
1124,
14011,
1040,
288,
2225,
3483,
12,
340,
1124,
14011,
1040,
365,
413,
14,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
267,
340,
2519,
8,
3583,
12,
283,
14011,
297,
378,
9,
508,
20675,
26,
288,
372,
4487,
398,
1249,
275,
4487,
14,
22309,
20523,
22,
61,
267,
1249,
847,
334,
3583,
14,
16627,
12,
4487,
14,
9374,
9,
398,
340,
20675,
26,
288,
372,
485,
19636,
3007,
27985,
2031,
589,
9,
267,
587,
26,
288,
372,
2197,
2031,
589,
9,
421,
199,
533,
485,
9374,
8,
9374,
304,
272,
408,
272,
3523,
1021,
367,
1006,
1124,
602,
1974,
1040,
1124,
9374,
1040,
2251,
14,
272,
408,
339,
347,
365,
63,
26465,
8,
277,
12,
4487,
304,
267,
408,
267,
7480,
503,
440,
314,
298,
7567,
900,
2,
402,
282,
1627,
2197,
365,
26711,
315,
642,
267,
5718,
14,
398,
520,
635,
4487,
26,
288,
437,
520,
647,
26,
533,
1705,
2083,
14,
2083,
3559,
19995,
503,
900,
5718,
20381,
14,
7318,
520,
1107,
26,
288,
1803,
1124,
549,
1040,
340,
26711,
12,
1124,
797,
1040,
4257,
14,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
398,
4487,
275,
4487,
14,
1814,
8,
9374,
29,
277,
9,
398,
19882,
63,
16,
275,
655,
14011,
8,
3583,
12,
20675,
29,
16,
9,
267,
19882,
63,
17,
275,
655,
14011,
8,
3583,
12,
20675,
29,
17,
9,
398,
2011,
63,
2743,
275,
19882,
63,
16,
14,
24036,
342,
508,
19882,
63,
17,
14,
24036,
342,
267,
2011,
63,
3583,
275,
19882,
63,
16,
14,
1814,
8,
9374,
29,
403,
9,
508,
19882,
63,
17,
14,
1814,
8,
9374,
29,
403,
9,
2728,
372,
2011,
63,
3583,
436,
440,
2011,
63,
2743,
339,
347,
485,
14011,
63,
1205,
8,
277,
12,
4487,
63,
5834,
12,
4487,
63,
7567,
304,
267,
408,
267,
14703,
314,
20675,
2004,
402,
282,
298,
7567,
2,
2197,
12,
1627,
282,
6025,
267,
402,
314,
2011,
2197,
465,
282,
334,
21578,
9,
12174,
2197,
14,
961,
365,
12950,
4079,
267,
641,
314,
30075,
626,
1124,
3583,
14,
24036,
342,
446,
4487,
14,
5119,
8497,
365,
4413,
367,
1006,
267,
29297,
12,
436,
626,
642,
3268,
365,
314,
3503,
1329,
402,
10857,
4216,
1958,
267,
1124,
3583,
63,
5834,
1040,
436,
1124,
3583,
63,
7567,
4345,
398,
520,
635,
4487,
63,
5834,
26,
288,
17634,
425,
402,
314,
2197,
465,
12174,
398,
520,
635,
4487,
63,
7567,
26,
288,
17634,
425,
402,
314,
2197,
465,
298,
7567,
900,
1674,
961,
2725,
1471,
288,
1902,
1172,
282
] |
[
3816,
492,
7843,
19,
199,
504,
3816,
14,
4912,
492,
485,
2671,
199,
199,
504,
2197,
492,
2197,
12,
6871,
12,
10313,
199,
646,
1331,
199,
199,
24655,
275,
6871,
8,
16,
9,
199,
199,
363,
452,
363,
275,
788,
20027,
63,
262,
63,
1548,
18,
297,
283,
287,
14011,
418,
421,
199,
318,
28054,
63,
262,
63,
1548,
18,
8,
354,
1532,
304,
272,
408,
4001,
2649,
1072,
1901,
18792,
25182,
315,
2018,
499,
339,
28054,
342,
3261,
2896,
315,
2018,
650,
14,
2779,
1202,
370,
372,
2783,
12,
1325,
1990,
2896,
272,
370,
2649,
3326,
272,
408,
272,
347,
11311,
63,
2991,
2031,
589,
12,
1011,
958,
304,
267,
536,
275,
536,
1532,
2031,
589,
12,
1011,
958,
9,
267,
340,
536,
365,
440,
488,
436,
440,
7843,
19,
26,
288,
536,
275,
536,
14,
2143,
342,
398,
372,
536,
339,
372,
11311,
63,
2991,
421,
199,
3,
710,
2569,
365,
26266,
687,
22986,
11438,
6423,
320,
2515,
12267,
1159,
5823,
3555,
199,
3,
4178,
921,
5031,
14,
957,
15,
371,
4878,
262,
15,
3903,
199,
692,
2688,
8,
2083,
12,
283,
14011,
735,
272,
327,
961,
365,
314,
876,
13,
1548,
650,
14,
22,
20675,
25781,
272,
347,
655,
14011,
8,
3583,
12,
20675,
29,
17,
304,
267,
408,
267,
21552,
282,
25344,
3217,
367,
26694,
314,
1124,
14011,
1040,
2225,
370,
267,
29297,
3865,
2544,
436,
2410,
314,
4514,
402,
13663,
13,
20384,
14,
398,
520,
635,
20675,
26,
288,
710,
574,
367,
314,
1124,
14011,
1040,
2225,
315,
314,
2138,
2197,
14,
961,
288,
1077,
506,
1902,
378,
503,
413,
14,
398,
520,
1107,
26,
288,
1803,
376,
909,
367,
1314,
1124,
5675,
8,
3583,
12,
283,
14011,
297,
378,
9719,
2529,
288,
1124,
14011,
1040,
367,
1006,
5459,
402,
2018,
14,
1010,
5459,
6791,
370,
288,
2018,
650,
14,
22,
12,
642,
365,
282,
24507,
19636,
3007,
27985,
1040,
909,
12,
1314,
365,
282,
288,
5516,
402,
520,
647,
26,
533,
1705,
2083,
14,
2083,
64,
543,
314,
1124,
14011,
1040,
288,
2225,
3483,
12,
340,
1124,
14011,
1040,
365,
413,
14,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
267,
372,
4487,
14,
1814,
8,
14011,
29,
14011,
9,
199,
199,
2836,
26,
272,
1021,
485,
19636,
3007,
27985,
8,
2083,
304,
267,
408,
267,
961,
365,
282,
1021,
19829,
370,
5647,
282,
13663,
841,
2720,
13,
863,
22676,
3217,
367,
267,
2018,
5459,
2544,
650,
14,
22,
14,
2779,
365,
1202,
1454,
367,
10831,
315,
282,
20675,
12,
880,
267,
314,
1124,
14011,
1040,
2225,
365,
6317,
737,
1124,
17,
4345,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
267,
636,
7257,
363,
275,
6248,
398,
768,
1829,
267,
347,
20675,
8,
277,
304,
288,
372,
413,
339,
347,
655,
14011,
8,
3583,
12,
20675,
29,
17,
304,
267,
408,
267,
21552,
282,
25344,
3217,
367,
26694,
314,
1124,
14011,
1040,
2225,
370,
267,
29297,
3865,
2544,
436,
2410,
314,
4514,
402,
13663,
13,
20384,
14,
398,
520,
635,
20675,
26,
288,
710,
574,
367,
314,
1124,
14011,
1040,
2225,
315,
314,
2138,
2197,
14,
961,
288,
1077,
506,
1902,
378,
503,
413,
14,
398,
520,
1107,
26,
288,
1803,
376,
909,
367,
1314,
1124,
5675,
8,
3583,
12,
283,
14011,
297,
378,
9719,
2529,
288,
1124,
14011,
1040,
367,
1006,
5459,
402,
2018,
14,
1010,
5459,
6791,
370,
288,
2018,
650,
14,
22,
12,
642,
365,
282,
24507,
19636,
3007,
27985,
1040,
909,
12,
1314,
365,
282,
288,
5516,
402,
520,
647,
26,
533,
1705,
2083,
14,
2083,
64,
543,
314,
1124,
14011,
1040,
288,
2225,
3483,
12,
340,
1124,
14011,
1040,
365,
413,
14,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
267,
340,
2519,
8,
3583,
12,
283,
14011,
297,
378,
9,
508,
20675,
26,
288,
372,
4487,
398,
1249,
275,
4487,
14,
22309,
20523,
22,
61,
267,
1249,
847,
334,
3583,
14,
16627,
12,
4487,
14,
9374,
9,
398,
340,
20675,
26,
288,
372,
485,
19636,
3007,
27985,
2031,
589,
9,
267,
587,
26,
288,
372,
2197,
2031,
589,
9,
421,
199,
533,
485,
9374,
8,
9374,
304,
272,
408,
272,
3523,
1021,
367,
1006,
1124,
602,
1974,
1040,
1124,
9374,
1040,
2251,
14,
272,
408,
339,
347,
365,
63,
26465,
8,
277,
12,
4487,
304,
267,
408,
267,
7480,
503,
440,
314,
298,
7567,
900,
2,
402,
282,
1627,
2197,
365,
26711,
315,
642,
267,
5718,
14,
398,
520,
635,
4487,
26,
288,
437,
520,
647,
26,
533,
1705,
2083,
14,
2083,
3559,
19995,
503,
900,
5718,
20381,
14,
7318,
520,
1107,
26,
288,
1803,
1124,
549,
1040,
340,
26711,
12,
1124,
797,
1040,
4257,
14,
398,
2508,
1023,
3270,
447,
499,
14,
22,
14,
16,
267,
408,
398,
4487,
275,
4487,
14,
1814,
8,
9374,
29,
277,
9,
398,
19882,
63,
16,
275,
655,
14011,
8,
3583,
12,
20675,
29,
16,
9,
267,
19882,
63,
17,
275,
655,
14011,
8,
3583,
12,
20675,
29,
17,
9,
398,
2011,
63,
2743,
275,
19882,
63,
16,
14,
24036,
342,
508,
19882,
63,
17,
14,
24036,
342,
267,
2011,
63,
3583,
275,
19882,
63,
16,
14,
1814,
8,
9374,
29,
403,
9,
508,
19882,
63,
17,
14,
1814,
8,
9374,
29,
403,
9,
2728,
372,
2011,
63,
3583,
436,
440,
2011,
63,
2743,
339,
347,
485,
14011,
63,
1205,
8,
277,
12,
4487,
63,
5834,
12,
4487,
63,
7567,
304,
267,
408,
267,
14703,
314,
20675,
2004,
402,
282,
298,
7567,
2,
2197,
12,
1627,
282,
6025,
267,
402,
314,
2011,
2197,
465,
282,
334,
21578,
9,
12174,
2197,
14,
961,
365,
12950,
4079,
267,
641,
314,
30075,
626,
1124,
3583,
14,
24036,
342,
446,
4487,
14,
5119,
8497,
365,
4413,
367,
1006,
267,
29297,
12,
436,
626,
642,
3268,
365,
314,
3503,
1329,
402,
10857,
4216,
1958,
267,
1124,
3583,
63,
5834,
1040,
436,
1124,
3583,
63,
7567,
4345,
398,
520,
635,
4487,
63,
5834,
26,
288,
17634,
425,
402,
314,
2197,
465,
12174,
398,
520,
635,
4487,
63,
7567,
26,
288,
17634,
425,
402,
314,
2197,
465,
298,
7567,
900,
1674,
961,
2725,
1471,
288,
1902,
1172,
282,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
krikru/tensorflow-opencl
|
tensorflow/contrib/tfprof/python/tools/tfprof/model_analyzer.py
|
62
|
6724
|
# 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.
# ==============================================================================
"""Model Analyzer.
Analyze model, including shape, params, time, memory, structure, etc.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.tfprof.python.tools.tfprof import pywrap_tensorflow_print_model_analysis_lib as print_mdl
from tensorflow.contrib.tfprof.python.tools.tfprof import tfprof_logger
from tensorflow.tools.tfprof import tfprof_options_pb2
from tensorflow.tools.tfprof import tfprof_output_pb2
# pylint: disable=bad-whitespace
# pylint: disable=bad-continuation
# 2 example tfprof_options for print_model_analysis API.
#
# Show the parameter statistics of trainable variables.
TRAINABLE_VARS_PARAMS_STAT_OPTIONS = {
'max_depth': 10000,
'min_bytes': 0,
'min_micros': 0,
'min_params': 0,
'min_float_ops': 0,
'device_regexes': ['.*'],
'order_by': 'name',
'account_type_regexes': [tfprof_logger.TRAINABLE_VARIABLES],
'start_name_regexes': ['.*'],
'trim_name_regexes': [],
'show_name_regexes': ['.*'],
'hide_name_regexes': [],
'account_displayed_op_only': True,
'select': ['params'],
'viz': False,
'dump_to_file': ''
}
# Show the number float operations.
FLOAT_OPS_OPTIONS = {
'max_depth': 10000,
'min_bytes': 0,
'min_micros': 0,
'min_params': 0,
'min_float_ops': 1,
'device_regexes': ['.*'],
'order_by': 'float_ops',
'account_type_regexes': ['.*'],
'start_name_regexes': ['.*'],
'trim_name_regexes': [],
'show_name_regexes': ['.*'],
'hide_name_regexes': [],
'account_displayed_op_only': True,
'select': ['float_ops'],
'viz': False,
'dump_to_file': ''
}
# Show number of parameters on parameter server 0.
# It is recommended to provide`run_meta` argument
# to have complete device placement info.
PRINT_PARAMS_ON_DEVICE = {
'max_depth': 1,
'min_bytes': 0,
'min_micros': 0,
'min_params': 0,
'min_float_ops': 0,
'device_regexes': ['.*'],
'order_by': 'name',
'account_type_regexes': ['.*ps.*task:0.*'],
'start_name_regexes': ['.*'],
'trim_name_regexes': [],
'show_name_regexes': ['.*'],
'hide_name_regexes': [],
'account_displayed_op_only': False,
'select': ['device', 'params'],
'viz': False,
'dump_to_file': ''
}
# Show the timing stats and memory demands.
PRINT_ALL_TIMING_MEMORY = {
'max_depth': 10000,
'min_bytes': 1, # Only >=1
'min_micros': 1, # Only >=1
'min_params': 0,
'min_float_ops': 0,
'device_regexes': ['.*'],
'order_by': 'name',
'account_type_regexes': ['.*'],
'start_name_regexes': ['.*'],
'trim_name_regexes': [],
'show_name_regexes': ['.*'],
'hide_name_regexes': [],
'account_displayed_op_only': True,
'select': ['micros', 'bytes'],
'viz': False,
'dump_to_file': ''
}
# pylint: enable=bad-whitespace
# pylint: enable=bad-continuation
def print_model_analysis(graph,
run_meta=None,
op_log=None,
tfprof_cmd='scope',
tfprof_options=TRAINABLE_VARS_PARAMS_STAT_OPTIONS):
"""Print model statistics.
Prints the model statistics to stdout. Also returns the results
in a TFProfNode proto. See go/tfprof or run tfprof tool:
'bazel run third_party/tensorflow/tools/tfprof help'
Examples:
Show the parameter/shape statistics of tf.trainable_variables().
print_model_analysis(sess.graph).
Show number of float ops. Only ops with RegisterStatistics defined
are counted.
show_float_op_opts = model_analyzer.FLOAT_OPS_OPTIONS
print_model_analysis(sess.graph, tfprof_options=show_float_op_opts)
Args:
graph: tf.Graph.
run_meta: tensorflow::RunMetadata proto. When provided, also shows valid
timing and memory information when 'select' option contains
'micros' and 'bytes'.
op_log: tensorflow::tfprof::OpLog proto. users can use this proto to
group together ops and use a op_type to select the group.
tfprof_cmd: string. Either 'scope' or 'graph'. 'scope' view organize
ops using their name scopes. 'graph' view organize ops using
their graph inputs.
tfprof_options: See 'tfprof help' for details.
Returns:
TFProfNode proto. Side effect: a formatted output to stdout.
"""
# pylint: disable=protected-access
op_log = tfprof_logger._merge_default_with_oplog(graph, op_log, run_meta)
# pylint: enable=protected-access
opts = tfprof_options_pb2.OptionsProto()
opts.max_depth = tfprof_options['max_depth']
opts.min_bytes = tfprof_options['min_bytes']
opts.min_micros = tfprof_options['min_micros']
opts.min_params = tfprof_options['min_params']
opts.min_float_ops = tfprof_options['min_float_ops']
for p in tfprof_options['device_regexes']:
opts.device_regexes.append(p)
opts.order_by = tfprof_options['order_by']
for p in tfprof_options['account_type_regexes']:
opts.account_type_regexes.append(p)
for p in tfprof_options['start_name_regexes']:
opts.start_name_regexes.append(p)
for p in tfprof_options['trim_name_regexes']:
opts.trim_name_regexes.append(p)
for p in tfprof_options['show_name_regexes']:
opts.show_name_regexes.append(p)
for p in tfprof_options['hide_name_regexes']:
opts.hide_name_regexes.append(p)
opts.account_displayed_op_only = tfprof_options['account_displayed_op_only']
for p in tfprof_options['select']:
opts.select.append(p)
opts.viz = tfprof_options['viz']
opts.dump_to_file = tfprof_options['dump_to_file']
run_meta_str = run_meta.SerializeToString() if run_meta else b''
op_log_str = op_log.SerializeToString() if op_log else b''
tfprof_node = tfprof_output_pb2.TFProfNode()
tfprof_node.ParseFromString(
print_mdl.PrintModelAnalysis(
graph.as_graph_def().SerializeToString(), run_meta_str, op_log_str,
tfprof_cmd.encode('utf-8'), opts.SerializeToString()))
return tfprof_node
|
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,
1685,
14279,
2282,
14,
199,
199,
8014,
806,
1402,
12,
5893,
2215,
12,
1862,
12,
900,
12,
4402,
12,
5523,
12,
5423,
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,
504,
3228,
14,
2828,
14,
3249,
14979,
14,
1548,
14,
2537,
14,
3249,
14979,
492,
1134,
3823,
63,
16008,
63,
1361,
63,
1238,
63,
10466,
63,
773,
465,
870,
63,
1064,
76,
199,
504,
3228,
14,
2828,
14,
3249,
14979,
14,
1548,
14,
2537,
14,
3249,
14979,
492,
2833,
14979,
63,
2921,
199,
504,
3228,
14,
2537,
14,
3249,
14979,
492,
2833,
14979,
63,
1419,
63,
3317,
18,
199,
504,
3228,
14,
2537,
14,
3249,
14979,
492,
2833,
14979,
63,
1199,
63,
3317,
18,
199,
199,
3,
4287,
26,
3507,
29,
4087,
13,
8506,
199,
3,
4287,
26,
3507,
29,
4087,
13,
20305,
199,
3,
499,
2893,
2833,
14979,
63,
1419,
367,
870,
63,
1238,
63,
10466,
3261,
14,
199,
3,
199,
3,
12968,
314,
2725,
11076,
402,
17029,
2860,
14,
199,
18473,
2617,
63,
21367,
63,
17978,
63,
4315,
63,
8808,
275,
469,
272,
283,
988,
63,
4631,
356,
11630,
12,
272,
283,
827,
63,
2394,
356,
378,
12,
272,
283,
827,
63,
6453,
83,
356,
378,
12,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
378,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
354,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
359,
3249,
14979,
63,
2921,
14,
18473,
2617,
63,
21161,
467,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
715,
12,
272,
283,
2416,
356,
788,
1162,
995,
272,
283,
17249,
356,
756,
12,
272,
283,
2724,
63,
475,
63,
493,
356,
2125,
199,
93,
199,
199,
3,
12968,
314,
1329,
2069,
5331,
14,
199,
11783,
63,
21665,
63,
8808,
275,
469,
272,
283,
988,
63,
4631,
356,
11630,
12,
272,
283,
827,
63,
2394,
356,
378,
12,
272,
283,
827,
63,
6453,
83,
356,
378,
12,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
413,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
1609,
63,
1483,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
788,
2795,
995,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
715,
12,
272,
283,
2416,
356,
788,
1609,
63,
1483,
995,
272,
283,
17249,
356,
756,
12,
272,
283,
2724,
63,
475,
63,
493,
356,
2125,
199,
93,
199,
199,
3,
12968,
1329,
402,
2633,
641,
2725,
1654,
378,
14,
199,
3,
2779,
365,
14318,
370,
5647,
64,
1065,
63,
2024,
64,
1423,
199,
3,
370,
1172,
4890,
2243,
22286,
2256,
14,
199,
21754,
63,
17978,
63,
615,
63,
10555,
275,
469,
272,
283,
988,
63,
4631,
356,
413,
12,
272,
283,
827,
63,
2394,
356,
378,
12,
272,
283,
827,
63,
6453,
83,
356,
378,
12,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
378,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
354,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
788,
2795,
1190,
2795,
1765,
26,
16,
2795,
995,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
756,
12,
272,
283,
2416,
356,
788,
1782,
297,
283,
1162,
995,
272,
283,
17249,
356,
756,
12,
272,
283,
2724,
63,
475,
63,
493,
356,
2125,
199,
93,
199,
199,
3,
12968,
314,
20542,
5020,
436,
4402,
28548,
5915,
14,
199,
21754,
63,
1761,
63,
11342,
1206,
63,
19495,
275,
469,
272,
283,
988,
63,
4631,
356,
11630,
12,
272,
283,
827,
63,
2394,
356,
413,
12,
221,
327,
5972,
2356,
17,
272,
283,
827,
63,
6453,
83,
356,
413,
12,
221,
327,
5972,
2356,
17,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
378,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
354,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
788,
2795,
995,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356
] |
[
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,
1685,
14279,
2282,
14,
199,
199,
8014,
806,
1402,
12,
5893,
2215,
12,
1862,
12,
900,
12,
4402,
12,
5523,
12,
5423,
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,
504,
3228,
14,
2828,
14,
3249,
14979,
14,
1548,
14,
2537,
14,
3249,
14979,
492,
1134,
3823,
63,
16008,
63,
1361,
63,
1238,
63,
10466,
63,
773,
465,
870,
63,
1064,
76,
199,
504,
3228,
14,
2828,
14,
3249,
14979,
14,
1548,
14,
2537,
14,
3249,
14979,
492,
2833,
14979,
63,
2921,
199,
504,
3228,
14,
2537,
14,
3249,
14979,
492,
2833,
14979,
63,
1419,
63,
3317,
18,
199,
504,
3228,
14,
2537,
14,
3249,
14979,
492,
2833,
14979,
63,
1199,
63,
3317,
18,
199,
199,
3,
4287,
26,
3507,
29,
4087,
13,
8506,
199,
3,
4287,
26,
3507,
29,
4087,
13,
20305,
199,
3,
499,
2893,
2833,
14979,
63,
1419,
367,
870,
63,
1238,
63,
10466,
3261,
14,
199,
3,
199,
3,
12968,
314,
2725,
11076,
402,
17029,
2860,
14,
199,
18473,
2617,
63,
21367,
63,
17978,
63,
4315,
63,
8808,
275,
469,
272,
283,
988,
63,
4631,
356,
11630,
12,
272,
283,
827,
63,
2394,
356,
378,
12,
272,
283,
827,
63,
6453,
83,
356,
378,
12,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
378,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
354,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
359,
3249,
14979,
63,
2921,
14,
18473,
2617,
63,
21161,
467,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
715,
12,
272,
283,
2416,
356,
788,
1162,
995,
272,
283,
17249,
356,
756,
12,
272,
283,
2724,
63,
475,
63,
493,
356,
2125,
199,
93,
199,
199,
3,
12968,
314,
1329,
2069,
5331,
14,
199,
11783,
63,
21665,
63,
8808,
275,
469,
272,
283,
988,
63,
4631,
356,
11630,
12,
272,
283,
827,
63,
2394,
356,
378,
12,
272,
283,
827,
63,
6453,
83,
356,
378,
12,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
413,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
1609,
63,
1483,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
788,
2795,
995,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
715,
12,
272,
283,
2416,
356,
788,
1609,
63,
1483,
995,
272,
283,
17249,
356,
756,
12,
272,
283,
2724,
63,
475,
63,
493,
356,
2125,
199,
93,
199,
199,
3,
12968,
1329,
402,
2633,
641,
2725,
1654,
378,
14,
199,
3,
2779,
365,
14318,
370,
5647,
64,
1065,
63,
2024,
64,
1423,
199,
3,
370,
1172,
4890,
2243,
22286,
2256,
14,
199,
21754,
63,
17978,
63,
615,
63,
10555,
275,
469,
272,
283,
988,
63,
4631,
356,
413,
12,
272,
283,
827,
63,
2394,
356,
378,
12,
272,
283,
827,
63,
6453,
83,
356,
378,
12,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
378,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
354,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
788,
2795,
1190,
2795,
1765,
26,
16,
2795,
995,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
756,
12,
272,
283,
2416,
356,
788,
1782,
297,
283,
1162,
995,
272,
283,
17249,
356,
756,
12,
272,
283,
2724,
63,
475,
63,
493,
356,
2125,
199,
93,
199,
199,
3,
12968,
314,
20542,
5020,
436,
4402,
28548,
5915,
14,
199,
21754,
63,
1761,
63,
11342,
1206,
63,
19495,
275,
469,
272,
283,
988,
63,
4631,
356,
11630,
12,
272,
283,
827,
63,
2394,
356,
413,
12,
221,
327,
5972,
2356,
17,
272,
283,
827,
63,
6453,
83,
356,
413,
12,
221,
327,
5972,
2356,
17,
272,
283,
827,
63,
1162,
356,
378,
12,
272,
283,
827,
63,
1609,
63,
1483,
356,
378,
12,
272,
283,
1782,
63,
29283,
356,
788,
2795,
995,
272,
283,
1648,
63,
991,
356,
283,
354,
297,
272,
283,
2048,
63,
466,
63,
29283,
356,
788,
2795,
995,
272,
283,
928,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
12263,
63,
354,
63,
29283,
356,
990,
272,
283,
2384,
63,
354,
63,
29283,
356,
788,
2795,
995,
272,
283,
8191,
63,
354,
63,
29283,
356,
990,
272,
283,
2048,
63,
22283,
63,
411,
63,
2118,
356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
Salat-Cx65/python-for-android
|
python3-alpha/python3-src/Lib/test/test_osx_env.py
|
59
|
1341
|
"""
Test suite for OS X interpreter environment variables.
"""
from test.support import EnvironmentVarGuard, run_unittest
import subprocess
import sys
import unittest
class OSXEnvironmentVariableTestCase(unittest.TestCase):
def _check_sys(self, ev, cond, sv, val = sys.executable + 'dummy'):
with EnvironmentVarGuard() as evg:
subpc = [str(sys.executable), '-c',
'import sys; sys.exit(2 if "%s" %s %s else 3)' % (val, cond, sv)]
# ensure environment variable does not exist
evg.unset(ev)
# test that test on sys.xxx normally fails
rc = subprocess.call(subpc)
self.assertEqual(rc, 3, "expected %s not %s %s" % (ev, cond, sv))
# set environ variable
evg.set(ev, val)
# test that sys.xxx has been influenced by the environ value
rc = subprocess.call(subpc)
self.assertEqual(rc, 2, "expected %s %s %s" % (ev, cond, sv))
def test_pythonexecutable_sets_sys_executable(self):
self._check_sys('PYTHONEXECUTABLE', '==', 'sys.executable')
def test_main():
from distutils import sysconfig
if sys.platform == 'darwin' and sysconfig.get_config_var('WITH_NEXT_FRAMEWORK'):
run_unittest(OSXEnvironmentVariableTestCase)
if __name__ == "__main__":
test_main()
|
apache-2.0
|
[
624,
199,
774,
5241,
367,
4403,
1323,
12693,
3734,
2860,
14,
199,
624,
199,
199,
504,
511,
14,
4058,
492,
9711,
5894,
18183,
12,
1255,
63,
2796,
199,
646,
3873,
199,
646,
984,
199,
646,
2882,
199,
199,
533,
32144,
8263,
2773,
1746,
8,
2796,
14,
1746,
304,
272,
347,
485,
1074,
63,
1274,
8,
277,
12,
8145,
12,
9288,
12,
19291,
12,
1139,
275,
984,
14,
5904,
435,
283,
5869,
735,
267,
543,
9711,
5894,
18183,
342,
465,
8145,
71,
26,
288,
1007,
2352,
275,
359,
495,
8,
1274,
14,
5904,
395,
2475,
67,
297,
355,
283,
646,
984,
27,
984,
14,
2224,
8,
18,
340,
2071,
83,
2,
450,
83,
450,
83,
587,
650,
3171,
450,
334,
637,
12,
9288,
12,
19291,
1874,
288,
327,
4868,
3734,
1750,
1630,
440,
2187,
288,
8145,
71,
14,
16787,
8,
6857,
9,
288,
327,
511,
626,
511,
641,
984,
14,
10013,
12252,
6918,
288,
4819,
275,
3873,
14,
1250,
8,
954,
2352,
9,
288,
291,
14,
629,
8,
1195,
12,
650,
12,
298,
2062,
450,
83,
440,
450,
83,
450,
83,
2,
450,
334,
6857,
12,
9288,
12,
19291,
430,
288,
327,
663,
6160,
1750,
288,
8145,
71,
14,
409,
8,
6857,
12,
1139,
9,
288,
327,
511,
626,
984,
14,
10013,
965,
2757,
315,
24585,
68,
701,
314,
6160,
574,
288,
4819,
275,
3873,
14,
1250,
8,
954,
2352,
9,
288,
291,
14,
629,
8,
1195,
12,
499,
12,
298,
2062,
450,
83,
450,
83,
450,
83,
2,
450,
334,
6857,
12,
9288,
12,
19291,
430,
339,
347,
511,
63,
647,
273,
368,
9542,
2964,
63,
2193,
63,
1274,
63,
5904,
8,
277,
304,
267,
291,
423,
1074,
63,
1274,
360,
11720,
21623,
297,
283,
389,
297,
283,
1274,
14,
5904,
358,
199,
199,
318,
511,
63,
973,
837,
272,
687,
7065,
492,
22381,
339,
340,
984,
14,
3246,
508,
283,
13245,
7,
436,
22381,
14,
362,
63,
888,
63,
1391,
360,
9139,
63,
21917,
63,
12683,
8406,
735,
267,
1255,
63,
2796,
8,
25160,
8263,
2773,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
511,
63,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
774,
5241,
367,
4403,
1323,
12693,
3734,
2860,
14,
199,
624,
199,
199,
504,
511,
14,
4058,
492,
9711,
5894,
18183,
12,
1255,
63,
2796,
199,
646,
3873,
199,
646,
984,
199,
646,
2882,
199,
199,
533,
32144,
8263,
2773,
1746,
8,
2796,
14,
1746,
304,
272,
347,
485,
1074,
63,
1274,
8,
277,
12,
8145,
12,
9288,
12,
19291,
12,
1139,
275,
984,
14,
5904,
435,
283,
5869,
735,
267,
543,
9711,
5894,
18183,
342,
465,
8145,
71,
26,
288,
1007,
2352,
275,
359,
495,
8,
1274,
14,
5904,
395,
2475,
67,
297,
355,
283,
646,
984,
27,
984,
14,
2224,
8,
18,
340,
2071,
83,
2,
450,
83,
450,
83,
587,
650,
3171,
450,
334,
637,
12,
9288,
12,
19291,
1874,
288,
327,
4868,
3734,
1750,
1630,
440,
2187,
288,
8145,
71,
14,
16787,
8,
6857,
9,
288,
327,
511,
626,
511,
641,
984,
14,
10013,
12252,
6918,
288,
4819,
275,
3873,
14,
1250,
8,
954,
2352,
9,
288,
291,
14,
629,
8,
1195,
12,
650,
12,
298,
2062,
450,
83,
440,
450,
83,
450,
83,
2,
450,
334,
6857,
12,
9288,
12,
19291,
430,
288,
327,
663,
6160,
1750,
288,
8145,
71,
14,
409,
8,
6857,
12,
1139,
9,
288,
327,
511,
626,
984,
14,
10013,
965,
2757,
315,
24585,
68,
701,
314,
6160,
574,
288,
4819,
275,
3873,
14,
1250,
8,
954,
2352,
9,
288,
291,
14,
629,
8,
1195,
12,
499,
12,
298,
2062,
450,
83,
450,
83,
450,
83,
2,
450,
334,
6857,
12,
9288,
12,
19291,
430,
339,
347,
511,
63,
647,
273,
368,
9542,
2964,
63,
2193,
63,
1274,
63,
5904,
8,
277,
304,
267,
291,
423,
1074,
63,
1274,
360,
11720,
21623,
297,
283,
389,
297,
283,
1274,
14,
5904,
358,
199,
199,
318,
511,
63,
973,
837,
272,
687,
7065,
492,
22381,
339,
340,
984,
14,
3246,
508,
283,
13245,
7,
436,
22381,
14,
362,
63,
888,
63,
1391,
360,
9139,
63,
21917,
63,
12683,
8406,
735,
267,
1255,
63,
2796,
8,
25160,
8263,
2773,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
511,
63,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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cs.py
|
1
|
1676
|
"""This demo illustrates how to set boundary conditions for meshes
that include boundary indicators. The mesh used in this demo was
generated with VMTK (http://www.vmtk.org/)."""
# Copyright (C) 2008-2012 Anders Logg
#
# This file is part of DOLFIN.
#
# DOLFIN 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.
#
# DOLFIN 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 DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Martin Alnaes 2012
#
# First added: 2008-05-23
# Last changed: 2012-10-16
from dolfin import *
# Create mesh and define function space
mesh = Mesh("../../../../data/meshes/aneurysm.xml.gz")
V = FunctionSpace(mesh, "CG", 1)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx
# Define boundary condition values
u0 = Constant(0.0)
u1 = Constant(1.0)
u2 = Constant(2.0)
u3 = Constant(3.0)
# Define boundary conditions
bc0 = DirichletBC(V, u0, 0)
bc1 = DirichletBC(V, u1, 1)
bc2 = DirichletBC(V, u2, 2)
bc3 = DirichletBC(V, u3, 3)
# Compute solution
u = Function(V)
solve(a == L, u, [bc0, bc1, bc2, bc3])
# Write solution to file
File("u.pvd") << u
# Plot solution
plot(u, interactive=True)
|
gpl-3.0
|
[
624,
2765,
14779,
22907,
11409,
2335,
4212,
370,
663,
8424,
3704,
367,
9364,
397,
199,
9099,
2387,
8424,
7262,
2750,
14,
710,
9364,
1202,
315,
642,
14779,
1990,
199,
10176,
543,
812,
5747,
43,
334,
1014,
921,
1544,
14,
86,
2037,
75,
14,
1308,
15,
10477,
199,
199,
3,
1898,
334,
35,
9,
9079,
13,
7409,
1626,
7735,
5297,
71,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28701,
17383,
14,
199,
3,
199,
3,
28701,
17383,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
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,
28701,
17383,
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,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
28701,
17383,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
22016,
701,
603,
26788,
4580,
3540,
397,
6029,
199,
3,
199,
3,
7758,
3483,
26,
221,
9079,
13,
1717,
13,
1789,
199,
3,
15237,
2896,
26,
6029,
13,
709,
13,
975,
199,
199,
504,
886,
276,
262,
492,
627,
199,
199,
3,
2790,
9364,
436,
5627,
805,
4601,
199,
6480,
275,
603,
10613,
480,
9707,
9707,
576,
15,
6480,
397,
15,
5865,
300,
588,
77,
14,
1652,
14,
6838,
531,
199,
54,
275,
6801,
7643,
8,
6480,
12,
298,
4064,
401,
413,
9,
199,
199,
3,
13930,
4172,
6279,
5160,
199,
85,
275,
377,
1383,
3481,
8,
54,
9,
199,
86,
275,
1379,
3481,
8,
54,
9,
199,
70,
275,
19991,
8,
16,
14,
16,
9,
199,
65,
275,
6308,
8,
6017,
8,
85,
395,
7659,
8,
86,
19198,
8373,
199,
44,
275,
289,
10,
86,
10,
8373,
199,
199,
3,
13930,
8424,
5558,
1338,
199,
85,
16,
275,
19991,
8,
16,
14,
16,
9,
199,
85,
17,
275,
19991,
8,
17,
14,
16,
9,
199,
85,
18,
275,
19991,
8,
18,
14,
16,
9,
199,
85,
19,
275,
19991,
8,
19,
14,
16,
9,
199,
199,
3,
13930,
8424,
3704,
199,
3776,
16,
275,
3757,
19683,
6265,
8,
54,
12,
399,
16,
12,
378,
9,
199,
3776,
17,
275,
3757,
19683,
6265,
8,
54,
12,
399,
17,
12,
413,
9,
199,
3776,
18,
275,
3757,
19683,
6265,
8,
54,
12,
399,
18,
12,
499,
9,
199,
3776,
19,
275,
3757,
19683,
6265,
8,
54,
12,
399,
19,
12,
650,
9,
199,
199,
3,
8354,
8744,
199,
85,
275,
6801,
8,
54,
9,
199,
11356,
8,
65,
508,
491,
12,
399,
12,
359,
3776,
16,
12,
16604,
17,
12,
16604,
18,
12,
16604,
19,
566,
199,
199,
3,
6990,
8744,
370,
570,
199,
1173,
480,
85,
14,
1381,
68,
531,
5213,
399,
199,
199,
3,
14794,
8744,
199,
2798,
8,
85,
12,
12777,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2765,
14779,
22907,
11409,
2335,
4212,
370,
663,
8424,
3704,
367,
9364,
397,
199,
9099,
2387,
8424,
7262,
2750,
14,
710,
9364,
1202,
315,
642,
14779,
1990,
199,
10176,
543,
812,
5747,
43,
334,
1014,
921,
1544,
14,
86,
2037,
75,
14,
1308,
15,
10477,
199,
199,
3,
1898,
334,
35,
9,
9079,
13,
7409,
1626,
7735,
5297,
71,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28701,
17383,
14,
199,
3,
199,
3,
28701,
17383,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
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,
28701,
17383,
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,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
28701,
17383,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
22016,
701,
603,
26788,
4580,
3540,
397,
6029,
199,
3,
199,
3,
7758,
3483,
26,
221,
9079,
13,
1717,
13,
1789,
199,
3,
15237,
2896,
26,
6029,
13,
709,
13,
975,
199,
199,
504,
886,
276,
262,
492,
627,
199,
199,
3,
2790,
9364,
436,
5627,
805,
4601,
199,
6480,
275,
603,
10613,
480,
9707,
9707,
576,
15,
6480,
397,
15,
5865,
300,
588,
77,
14,
1652,
14,
6838,
531,
199,
54,
275,
6801,
7643,
8,
6480,
12,
298,
4064,
401,
413,
9,
199,
199,
3,
13930,
4172,
6279,
5160,
199,
85,
275,
377,
1383,
3481,
8,
54,
9,
199,
86,
275,
1379,
3481,
8,
54,
9,
199,
70,
275,
19991,
8,
16,
14,
16,
9,
199,
65,
275,
6308,
8,
6017,
8,
85,
395,
7659,
8,
86,
19198,
8373,
199,
44,
275,
289,
10,
86,
10,
8373,
199,
199,
3,
13930,
8424,
5558,
1338,
199,
85,
16,
275,
19991,
8,
16,
14,
16,
9,
199,
85,
17,
275,
19991,
8,
17,
14,
16,
9,
199,
85,
18,
275,
19991,
8,
18,
14,
16,
9,
199,
85,
19,
275,
19991,
8,
19,
14,
16,
9,
199,
199,
3,
13930,
8424,
3704,
199,
3776,
16,
275,
3757,
19683,
6265,
8,
54,
12,
399,
16,
12,
378,
9,
199,
3776,
17,
275,
3757,
19683,
6265,
8,
54,
12,
399,
17,
12,
413,
9,
199,
3776,
18,
275,
3757,
19683,
6265,
8,
54,
12,
399,
18,
12,
499,
9,
199,
3776,
19,
275,
3757,
19683,
6265,
8,
54,
12,
399,
19,
12,
650,
9,
199,
199,
3,
8354,
8744,
199,
85,
275,
6801,
8,
54,
9,
199,
11356,
8,
65,
508,
491,
12,
399,
12,
359,
3776,
16,
12,
16604,
17,
12,
16604,
18,
12,
16604,
19,
566,
199,
199,
3,
6990,
8744,
370,
570,
199,
1173,
480,
85,
14,
1381,
68,
531,
5213,
399,
199,
199,
3,
14794,
8744,
199,
2798,
8,
85,
12,
12777,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
HBehrens/feedsanitizer
|
django/contrib/gis/gdal/datasource.py
|
321
|
4734
|
"""
DataSource is a wrapper for the OGR Data Source object, which provides
an interface for reading vector geometry data from many different file
formats (including ESRI shapefiles).
When instantiating a DataSource object, use the filename of a
GDAL-supported data source. For example, a SHP file or a
TIGER/Line file from the government.
The ds_driver keyword is used internally when a ctypes pointer
is passed in directly.
Example:
ds = DataSource('/home/foo/bar.shp')
for layer in ds:
for feature in layer:
# Getting the geometry for the feature.
g = feature.geom
# Getting the 'description' field for the feature.
desc = feature['description']
# We can also increment through all of the fields
# attached to this feature.
for field in feature:
# Get the name of the field (e.g. 'description')
nm = field.name
# Get the type (integer) of the field, e.g. 0 => OFTInteger
t = field.type
# Returns the value the field; OFTIntegers return ints,
# OFTReal returns floats, all else returns string.
val = field.value
"""
# ctypes prerequisites.
from ctypes import byref, c_void_p
# The GDAL C library, OGR exceptions, and the Layer object.
from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.driver import Driver
from django.contrib.gis.gdal.error import OGRException, OGRIndexError
from django.contrib.gis.gdal.layer import Layer
# Getting the ctypes prototypes for the DataSource.
from django.contrib.gis.gdal.prototypes import ds as capi
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
# The OGR_DS_* routines are relevant here.
class DataSource(GDALBase):
"Wraps an OGR Data Source object."
#### Python 'magic' routines ####
def __init__(self, ds_input, ds_driver=False, write=False):
# The write flag.
if write:
self._write = 1
else:
self._write = 0
# Registering all the drivers, this needs to be done
# _before_ we try to open up a data source.
if not capi.get_driver_count():
capi.register_all()
if isinstance(ds_input, basestring):
# The data source driver is a void pointer.
ds_driver = Driver.ptr_type()
try:
# OGROpen will auto-detect the data source type.
ds = capi.open_ds(ds_input, self._write, byref(ds_driver))
except OGRException:
# Making the error message more clear rather than something
# like "Invalid pointer returned from OGROpen".
raise OGRException('Could not open the datasource at "%s"' % ds_input)
elif isinstance(ds_input, self.ptr_type) and isinstance(ds_driver, Driver.ptr_type):
ds = ds_input
else:
raise OGRException('Invalid data source input type: %s' % type(ds_input))
if bool(ds):
self.ptr = ds
self.driver = Driver(ds_driver)
else:
# Raise an exception if the returned pointer is NULL
raise OGRException('Invalid data source file "%s"' % ds_input)
def __del__(self):
"Destroys this DataStructure object."
if self._ptr: capi.destroy_ds(self._ptr)
def __iter__(self):
"Allows for iteration over the layers in a data source."
for i in xrange(self.layer_count):
yield self[i]
def __getitem__(self, index):
"Allows use of the index [] operator to get a layer at the index."
if isinstance(index, basestring):
l = capi.get_layer_by_name(self.ptr, index)
if not l: raise OGRIndexError('invalid OGR Layer name given: "%s"' % index)
elif isinstance(index, int):
if index < 0 or index >= self.layer_count:
raise OGRIndexError('index out of range')
l = capi.get_layer(self._ptr, index)
else:
raise TypeError('Invalid index type: %s' % type(index))
return Layer(l, self)
def __len__(self):
"Returns the number of layers within the data source."
return self.layer_count
def __str__(self):
"Returns OGR GetName and Driver for the Data Source."
return '%s (%s)' % (self.name, str(self.driver))
@property
def layer_count(self):
"Returns the number of layers in the data source."
return capi.get_layer_count(self._ptr)
@property
def name(self):
"Returns the name of the data source."
return capi.get_ds_name(self._ptr)
|
mit
|
[
624,
199,
24300,
365,
282,
4975,
367,
314,
10904,
3918,
5800,
909,
12,
1314,
6571,
199,
376,
3217,
367,
7664,
5477,
3400,
666,
687,
5002,
3365,
570,
199,
6752,
334,
15768,
10427,
6129,
2215,
1725,
680,
421,
3979,
9034,
1958,
282,
24300,
909,
12,
675,
314,
1788,
402,
282,
199,
15801,
13,
4946,
666,
1350,
14,
221,
2104,
2893,
12,
282,
4410,
48,
570,
503,
282,
199,
377,
1277,
540,
15,
3049,
570,
687,
314,
3681,
25490,
14,
421,
710,
6364,
63,
3090,
4252,
365,
1202,
14448,
1380,
282,
5577,
7849,
199,
365,
3032,
315,
5370,
14,
421,
5679,
26,
523,
6364,
275,
24300,
2336,
4219,
15,
1421,
15,
1700,
14,
17299,
358,
523,
367,
4045,
315,
6364,
26,
489,
367,
3878,
315,
4045,
26,
881,
327,
20703,
314,
3400,
367,
314,
3878,
14,
881,
486,
275,
3878,
14,
6481,
8592,
327,
20703,
314,
283,
1802,
7,
901,
367,
314,
3878,
14,
881,
4328,
275,
3878,
459,
1802,
418,
8592,
327,
2136,
883,
2597,
11609,
4012,
1006,
402,
314,
1504,
881,
327,
221,
10102,
370,
642,
3878,
14,
881,
367,
901,
315,
3878,
26,
1598,
327,
2372,
314,
536,
402,
314,
901,
334,
69,
14,
71,
14,
283,
1802,
358,
1598,
16751,
275,
901,
14,
354,
25841,
327,
2372,
314,
730,
334,
4115,
9,
402,
314,
901,
12,
325,
14,
71,
14,
378,
9265,
20025,
2674,
1598,
307,
275,
901,
14,
466,
25841,
327,
1803,
314,
574,
314,
901,
27,
20025,
2674,
83,
372,
14526,
12,
1598,
327,
221,
20025,
10099,
2529,
15657,
12,
1006,
587,
2529,
1059,
14,
1598,
1139,
275,
901,
14,
585,
199,
624,
199,
3,
5577,
876,
30140,
14,
199,
504,
5577,
492,
15968,
12,
286,
63,
1647,
63,
80,
199,
199,
3,
710,
15801,
445,
3555,
12,
10904,
4967,
12,
436,
314,
11915,
909,
14,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1095,
492,
15801,
1563,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
3090,
492,
19447,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
12,
10904,
12129,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1897,
492,
11915,
199,
199,
3,
20703,
314,
5577,
19393,
83,
367,
314,
24300,
14,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
16141,
83,
492,
6364,
465,
13648,
199,
199,
3,
2104,
1655,
2556,
12,
1937,
314,
10904,
445,
3261,
1350,
1233,
26,
199,
3,
221,
1455,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
15,
14945,
363,
1246,
63,
24,
72,
14,
1360,
199,
3,
199,
3,
710,
10904,
63,
3177,
15192,
14975,
787,
12082,
2348,
14,
199,
533,
24300,
8,
17835,
1563,
304,
272,
298,
55,
8146,
376,
10904,
3918,
5800,
909,
2122,
339,
14055,
2018,
283,
11523,
7,
14975,
14055,
272,
347,
636,
826,
721,
277,
12,
6364,
63,
1210,
12,
6364,
63,
3090,
29,
797,
12,
2218,
29,
797,
304,
267,
327,
710,
2218,
3305,
14,
267,
340,
2218,
26,
288,
291,
423,
952,
275,
413,
267,
587,
26,
288,
291,
423,
952,
275,
378,
398,
327,
11828,
316,
1006,
314,
19016,
12,
642,
4839,
370,
506,
4224,
267,
327,
221,
485,
5182,
63,
781,
862,
370,
1551,
1536,
282,
666,
1350,
14,
267,
340,
440,
13648,
14,
362,
63,
3090,
63,
835,
837,
288,
13648,
14,
2683,
63,
452,
342,
398,
340,
1228,
8,
795,
63,
1210,
12,
7116,
304,
288,
327,
710,
666,
1350,
5253,
365,
282,
2309,
7849,
14,
288,
6364,
63,
3090,
275,
19447,
14,
4695,
63,
466,
342,
288,
862,
26,
355,
327,
19746,
1092,
897,
911,
2599,
13,
13552,
314,
666,
1350,
730,
14,
355,
6364,
275,
13648,
14,
1490,
63,
795,
8,
795,
63,
1210,
12,
291,
423,
952,
12,
15968,
8,
795,
63,
3090,
430,
288,
871,
19746,
907,
16010,
26,
355,
327,
32269,
314,
1125,
1245,
1655,
5436,
7830,
2419,
6020,
355,
327,
2839,
298,
3364,
7849,
2138,
687,
19746,
1092,
897,
1674,
355,
746,
19746,
907,
16010,
360,
6531,
440,
1551,
314,
29289,
737,
2071,
83,
4507,
450,
6364,
63,
1210,
9,
267,
916,
1228,
8,
795,
63,
1210,
12,
291,
14,
4695,
63,
466,
9,
436,
1228,
8,
795,
63,
3090,
12,
19447,
14,
4695,
63,
466,
304,
288,
6364,
275,
6364,
63,
1210,
267,
587,
26,
288,
746,
19746,
907,
16010,
360,
3364,
666,
1350,
1324,
730,
26,
450,
83,
7,
450,
730,
8,
795,
63,
1210,
430,
398,
340,
2155,
8,
795,
304,
288,
291,
14,
4695,
275,
6364,
288,
291,
14,
3090,
275,
19447,
8,
795,
63,
3090,
9,
267,
587,
26,
288,
327,
14771,
376,
1919,
340,
314,
2138,
7849,
365,
5962,
7205,
746,
19746,
907,
16010,
360,
3364,
666,
1350,
570,
2071,
83,
4507,
450,
6364,
63,
1210,
9,
339,
347,
636,
2264,
721,
277,
304,
267,
298,
8004,
293,
588,
642,
3918,
10766,
909,
2122,
267,
340,
291,
423,
4695,
26,
13648,
14,
7237,
63,
795,
8,
277,
423,
4695,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
298,
19780,
367,
8494,
1806,
314,
9393,
315,
282,
666,
1350,
2122,
267,
367,
284,
315,
4945,
8,
277,
14,
1897,
63,
835,
304,
288,
1995,
291,
59,
73,
61,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
298,
19780,
675,
402,
314,
1478,
942,
4182,
370,
664,
282,
4045,
737,
314,
1478,
2122,
267,
340,
1228,
8,
1080,
12,
7116,
304,
288,
634,
275,
13648,
14,
362,
63,
1897,
63,
991,
63,
354,
8,
277,
14,
4695,
12,
1478,
9,
288,
340,
440,
634,
26,
746,
10904,
12129,
360,
3197,
10904,
11915,
536,
1627,
26,
2071,
83,
4507,
450,
1478,
9,
267,
916,
1228,
8,
1080,
12,
1109,
304,
288,
340,
1478,
665,
378,
503,
1478,
2356,
291,
14,
1897,
63,
835,
26,
355,
746,
10904,
12129,
360,
1080,
734,
402,
1425,
358,
288,
634,
275,
13648,
14,
362,
63,
1897,
8,
277,
423,
4695,
12,
1478,
9,
267,
587,
26,
288,
746,
3146,
360,
3364,
1478,
730,
26,
450,
83,
7,
450,
730,
8,
1080,
430,
267,
372,
11915,
8,
76,
12,
291,
9,
5493,
347,
636,
552,
721,
277,
304,
267,
298,
3407,
314,
1329,
402,
9393,
4453,
314,
666,
1350
] |
[
199,
24300,
365,
282,
4975,
367,
314,
10904,
3918,
5800,
909,
12,
1314,
6571,
199,
376,
3217,
367,
7664,
5477,
3400,
666,
687,
5002,
3365,
570,
199,
6752,
334,
15768,
10427,
6129,
2215,
1725,
680,
421,
3979,
9034,
1958,
282,
24300,
909,
12,
675,
314,
1788,
402,
282,
199,
15801,
13,
4946,
666,
1350,
14,
221,
2104,
2893,
12,
282,
4410,
48,
570,
503,
282,
199,
377,
1277,
540,
15,
3049,
570,
687,
314,
3681,
25490,
14,
421,
710,
6364,
63,
3090,
4252,
365,
1202,
14448,
1380,
282,
5577,
7849,
199,
365,
3032,
315,
5370,
14,
421,
5679,
26,
523,
6364,
275,
24300,
2336,
4219,
15,
1421,
15,
1700,
14,
17299,
358,
523,
367,
4045,
315,
6364,
26,
489,
367,
3878,
315,
4045,
26,
881,
327,
20703,
314,
3400,
367,
314,
3878,
14,
881,
486,
275,
3878,
14,
6481,
8592,
327,
20703,
314,
283,
1802,
7,
901,
367,
314,
3878,
14,
881,
4328,
275,
3878,
459,
1802,
418,
8592,
327,
2136,
883,
2597,
11609,
4012,
1006,
402,
314,
1504,
881,
327,
221,
10102,
370,
642,
3878,
14,
881,
367,
901,
315,
3878,
26,
1598,
327,
2372,
314,
536,
402,
314,
901,
334,
69,
14,
71,
14,
283,
1802,
358,
1598,
16751,
275,
901,
14,
354,
25841,
327,
2372,
314,
730,
334,
4115,
9,
402,
314,
901,
12,
325,
14,
71,
14,
378,
9265,
20025,
2674,
1598,
307,
275,
901,
14,
466,
25841,
327,
1803,
314,
574,
314,
901,
27,
20025,
2674,
83,
372,
14526,
12,
1598,
327,
221,
20025,
10099,
2529,
15657,
12,
1006,
587,
2529,
1059,
14,
1598,
1139,
275,
901,
14,
585,
199,
624,
199,
3,
5577,
876,
30140,
14,
199,
504,
5577,
492,
15968,
12,
286,
63,
1647,
63,
80,
199,
199,
3,
710,
15801,
445,
3555,
12,
10904,
4967,
12,
436,
314,
11915,
909,
14,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1095,
492,
15801,
1563,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
3090,
492,
19447,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
12,
10904,
12129,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1897,
492,
11915,
199,
199,
3,
20703,
314,
5577,
19393,
83,
367,
314,
24300,
14,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
16141,
83,
492,
6364,
465,
13648,
199,
199,
3,
2104,
1655,
2556,
12,
1937,
314,
10904,
445,
3261,
1350,
1233,
26,
199,
3,
221,
1455,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
15,
14945,
363,
1246,
63,
24,
72,
14,
1360,
199,
3,
199,
3,
710,
10904,
63,
3177,
15192,
14975,
787,
12082,
2348,
14,
199,
533,
24300,
8,
17835,
1563,
304,
272,
298,
55,
8146,
376,
10904,
3918,
5800,
909,
2122,
339,
14055,
2018,
283,
11523,
7,
14975,
14055,
272,
347,
636,
826,
721,
277,
12,
6364,
63,
1210,
12,
6364,
63,
3090,
29,
797,
12,
2218,
29,
797,
304,
267,
327,
710,
2218,
3305,
14,
267,
340,
2218,
26,
288,
291,
423,
952,
275,
413,
267,
587,
26,
288,
291,
423,
952,
275,
378,
398,
327,
11828,
316,
1006,
314,
19016,
12,
642,
4839,
370,
506,
4224,
267,
327,
221,
485,
5182,
63,
781,
862,
370,
1551,
1536,
282,
666,
1350,
14,
267,
340,
440,
13648,
14,
362,
63,
3090,
63,
835,
837,
288,
13648,
14,
2683,
63,
452,
342,
398,
340,
1228,
8,
795,
63,
1210,
12,
7116,
304,
288,
327,
710,
666,
1350,
5253,
365,
282,
2309,
7849,
14,
288,
6364,
63,
3090,
275,
19447,
14,
4695,
63,
466,
342,
288,
862,
26,
355,
327,
19746,
1092,
897,
911,
2599,
13,
13552,
314,
666,
1350,
730,
14,
355,
6364,
275,
13648,
14,
1490,
63,
795,
8,
795,
63,
1210,
12,
291,
423,
952,
12,
15968,
8,
795,
63,
3090,
430,
288,
871,
19746,
907,
16010,
26,
355,
327,
32269,
314,
1125,
1245,
1655,
5436,
7830,
2419,
6020,
355,
327,
2839,
298,
3364,
7849,
2138,
687,
19746,
1092,
897,
1674,
355,
746,
19746,
907,
16010,
360,
6531,
440,
1551,
314,
29289,
737,
2071,
83,
4507,
450,
6364,
63,
1210,
9,
267,
916,
1228,
8,
795,
63,
1210,
12,
291,
14,
4695,
63,
466,
9,
436,
1228,
8,
795,
63,
3090,
12,
19447,
14,
4695,
63,
466,
304,
288,
6364,
275,
6364,
63,
1210,
267,
587,
26,
288,
746,
19746,
907,
16010,
360,
3364,
666,
1350,
1324,
730,
26,
450,
83,
7,
450,
730,
8,
795,
63,
1210,
430,
398,
340,
2155,
8,
795,
304,
288,
291,
14,
4695,
275,
6364,
288,
291,
14,
3090,
275,
19447,
8,
795,
63,
3090,
9,
267,
587,
26,
288,
327,
14771,
376,
1919,
340,
314,
2138,
7849,
365,
5962,
7205,
746,
19746,
907,
16010,
360,
3364,
666,
1350,
570,
2071,
83,
4507,
450,
6364,
63,
1210,
9,
339,
347,
636,
2264,
721,
277,
304,
267,
298,
8004,
293,
588,
642,
3918,
10766,
909,
2122,
267,
340,
291,
423,
4695,
26,
13648,
14,
7237,
63,
795,
8,
277,
423,
4695,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
298,
19780,
367,
8494,
1806,
314,
9393,
315,
282,
666,
1350,
2122,
267,
367,
284,
315,
4945,
8,
277,
14,
1897,
63,
835,
304,
288,
1995,
291,
59,
73,
61,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
298,
19780,
675,
402,
314,
1478,
942,
4182,
370,
664,
282,
4045,
737,
314,
1478,
2122,
267,
340,
1228,
8,
1080,
12,
7116,
304,
288,
634,
275,
13648,
14,
362,
63,
1897,
63,
991,
63,
354,
8,
277,
14,
4695,
12,
1478,
9,
288,
340,
440,
634,
26,
746,
10904,
12129,
360,
3197,
10904,
11915,
536,
1627,
26,
2071,
83,
4507,
450,
1478,
9,
267,
916,
1228,
8,
1080,
12,
1109,
304,
288,
340,
1478,
665,
378,
503,
1478,
2356,
291,
14,
1897,
63,
835,
26,
355,
746,
10904,
12129,
360,
1080,
734,
402,
1425,
358,
288,
634,
275,
13648,
14,
362,
63,
1897,
8,
277,
423,
4695,
12,
1478,
9,
267,
587,
26,
288,
746,
3146,
360,
3364,
1478,
730,
26,
450,
83,
7,
450,
730,
8,
1080,
430,
267,
372,
11915,
8,
76,
12,
291,
9,
5493,
347,
636,
552,
721,
277,
304,
267,
298,
3407,
314,
1329,
402,
9393,
4453,
314,
666,
1350,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JioCloud/contrail-generateDS
|
tests/recursive_simpletype2_sub.py
|
10
|
4772
|
#!/usr/bin/env python
#
# Generated by generateDS.py.
#
import sys
import recursive_simpletype2_sup as supermod
etree_ = None
Verbose_import_ = False
( XMLParser_import_none, XMLParser_import_lxml,
XMLParser_import_elementtree
) = range(3)
XMLParser_import_library = None
try:
# lxml
from lxml import etree as etree_
XMLParser_import_library = XMLParser_import_lxml
if Verbose_import_:
print("running with lxml.etree")
except ImportError:
try:
# cElementTree from Python 2.5+
import xml.etree.cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# ElementTree from Python 2.5+
import xml.etree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree")
except ImportError:
raise ImportError("Failed to import ElementTree from any known place")
def parsexml_(*args, **kwargs):
if (XMLParser_import_library == XMLParser_import_lxml and
'parser' not in kwargs):
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
kwargs['parser'] = etree_.ETCompatXMLParser()
doc = etree_.parse(*args, **kwargs)
return doc
#
# Globals
#
ExternalEncoding = 'ascii'
#
# Data representation classes
#
class PersonTypeSub(supermod.PersonType):
def __init__(self, personId=None, fname=None, lname=None):
super(PersonTypeSub, self).__init__(personId, fname, lname, )
supermod.PersonType.subclass = PersonTypeSub
# end class PersonTypeSub
def get_root_tag(node):
tag = supermod.Tag_pattern_.match(node.tag).groups()[-1]
rootClass = None
if hasattr(supermod, tag):
rootClass = getattr(supermod, tag)
return tag, rootClass
def parse(inFilename):
doc = parsexml_(inFilename)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'person'
rootClass = supermod.PersonType
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
## sys.stdout.write('<?xml version="1.0" ?>\n')
## rootObj.export(sys.stdout, 0, name_=rootTag,
## namespacedef_='',
## pretty_print=True)
doc = None
return rootObj
def parseString(inString):
from StringIO import StringIO
doc = parsexml_(StringIO(inString))
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'person'
rootClass = supermod.PersonType
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
## sys.stdout.write('<?xml version="1.0" ?>\n')
## rootObj.export(sys.stdout, 0, name_=rootTag,
## namespacedef_='')
return rootObj
def parseLiteral(inFilename):
doc = parsexml_(inFilename)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'person'
rootClass = supermod.PersonType
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
## sys.stdout.write('#from recursive_simpletype2_sup import *\n\n')
## sys.stdout.write('import recursive_simpletype2_sup as model_\n\n')
## sys.stdout.write('rootObj = model_.person(\n')
## rootObj.exportLiteral(sys.stdout, 0, name_="person")
## sys.stdout.write(')\n')
return rootObj
USAGE_TEXT = """
Usage: python ???.py <infilename>
"""
def usage():
print USAGE_TEXT
sys.exit(1)
def main():
args = sys.argv[1:]
if len(args) != 1:
usage()
infilename = args[0]
root = parse(infilename)
if __name__ == '__main__':
#import pdb; pdb.set_trace()
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
199,
3,
17065,
221,
701,
3550,
3177,
14,
647,
14,
199,
3,
199,
199,
646,
984,
199,
199,
646,
9133,
63,
4129,
466,
18,
63,
1961,
465,
1613,
1494,
199,
199,
9464,
63,
275,
488,
199,
21879,
63,
646,
63,
275,
756,
199,
8,
257,
4692,
2842,
63,
646,
63,
3592,
12,
4692,
2842,
63,
646,
63,
22899,
12,
272,
4692,
2842,
63,
646,
63,
2108,
2350,
272,
776,
275,
1425,
8,
19,
9,
199,
4317,
2842,
63,
646,
63,
4342,
275,
488,
199,
893,
26,
272,
327,
14490,
272,
687,
14490,
492,
7559,
465,
7559,
63,
272,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
22899,
272,
340,
5444,
2220,
63,
646,
10388,
267,
870,
480,
5720,
543,
14490,
14,
9464,
531,
199,
2590,
3545,
26,
272,
862,
26,
267,
327,
286,
15325,
687,
2018,
499,
14,
21,
11,
267,
492,
2748,
14,
9464,
14,
67,
15325,
465,
7559,
63,
267,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
267,
340,
5444,
2220,
63,
646,
10388,
288,
870,
480,
5720,
543,
286,
15325,
641,
2018,
499,
14,
21,
21425,
272,
871,
3545,
26,
267,
862,
26,
288,
327,
13139,
687,
2018,
499,
14,
21,
11,
288,
492,
2748,
14,
9464,
14,
15325,
465,
7559,
63,
288,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
288,
340,
5444,
2220,
63,
646,
10388,
355,
870,
480,
5720,
543,
13139,
641,
2018,
499,
14,
21,
21425,
267,
871,
3545,
26,
288,
862,
26,
355,
327,
3293,
286,
15325,
3907,
355,
492,
286,
15325,
465,
7559,
63,
355,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
355,
340,
5444,
2220,
63,
646,
10388,
490,
870,
480,
5720,
543,
286,
15325,
531,
288,
871,
3545,
26,
355,
862,
26,
490,
327,
3293,
13139,
3907,
490,
492,
1819,
2350,
14,
15325,
465,
7559,
63,
490,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
490,
340,
5444,
2220,
63,
646,
10388,
717,
870,
480,
5720,
543,
13139,
531,
355,
871,
3545,
26,
490,
746,
3545,
480,
4276,
370,
492,
13139,
687,
1263,
6040,
4192,
531,
199,
199,
318,
2198,
1652,
63,
2031,
589,
12,
1011,
958,
304,
272,
340,
334,
4317,
2842,
63,
646,
63,
4342,
508,
4692,
2842,
63,
646,
63,
22899,
436,
267,
283,
2087,
7,
440,
315,
2074,
304,
267,
327,
3645,
314,
14490,
13139,
9025,
1798,
880,
626,
12,
325,
14,
71,
2020,
267,
327,
257,
781,
3686,
6786,
14,
267,
2074,
459,
2087,
418,
275,
7559,
3754,
775,
2404,
292,
4317,
2842,
342,
272,
1382,
275,
7559,
3754,
1122,
2031,
589,
12,
1011,
958,
9,
272,
372,
1382,
199,
199,
3,
199,
3,
13641,
83,
199,
3,
199,
199,
25199,
275,
283,
4371,
7,
199,
199,
3,
199,
3,
3918,
6025,
3992,
199,
3,
199,
199,
533,
8028,
804,
2610,
8,
4792,
1494,
14,
7344,
804,
304,
272,
347,
636,
826,
721,
277,
12,
4954,
1304,
29,
403,
12,
6748,
29,
403,
12,
634,
354,
29,
403,
304,
267,
1613,
8,
7344,
804,
2610,
12,
291,
2843,
826,
721,
5484,
1304,
12,
6748,
12,
634,
354,
12,
776,
199,
4792,
1494,
14,
7344,
804,
14,
6083,
275,
8028,
804,
2610,
199,
3,
1284,
1021,
8028,
804,
2610,
4388,
199,
318,
664,
63,
1231,
63,
1450,
8,
932,
304,
272,
1947,
275,
1613,
1494,
14,
1931,
63,
3401,
3754,
1431,
8,
932,
14,
1450,
680,
2634,
19105,
17,
61,
272,
1738,
2543,
275,
488,
272,
340,
2688,
8,
4792,
1494,
12,
1947,
304,
267,
1738,
2543,
275,
2519,
8,
4792,
1494,
12,
1947,
9,
272,
372,
1947,
12,
1738,
2543,
421,
199,
318,
2198,
8,
262,
8117,
304,
272,
1382,
275,
2198,
1652,
2531,
262,
8117,
9,
272,
1738,
1716,
275,
1382,
14,
24544,
342,
272,
1738,
1931,
12,
1738,
2543,
275,
664,
63,
1231,
63,
1450,
8,
1231,
1716,
9,
272,
340,
1738,
2543,
365,
488,
26,
267,
1738,
1931,
275,
283,
5484,
7,
267,
1738,
2543,
275,
1613,
1494,
14,
7344,
804,
272,
1738,
5665,
275,
1738,
2543,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8,
1231,
1716,
9,
272,
327,
12030,
2018,
370,
8775,
314,
4601,
1202,
701,
314,
14316,
14,
272,
1382,
275,
488,
199,
309,
258,
984,
14,
2703,
14,
952,
4827,
31,
1652,
1015,
628,
17,
14,
16,
2,
5805,
3072,
78,
358,
199,
309,
258,
1738,
5665,
14,
3790,
8,
1274,
14,
2703,
12,
378,
12,
536,
10683,
1231,
1931,
12,
199,
309,
260,
18143,
15080,
199,
309,
260,
7268,
63,
1361,
29,
549,
9,
272,
1382,
275,
488,
272,
372,
1738,
5665,
421,
199,
318,
2198,
1558,
8,
262,
1558,
304,
272,
687,
5228,
492,
5228,
272,
1382,
275,
2198,
1652,
2531,
6424,
8,
262,
1558,
430,
272,
1738,
1716,
275,
1382,
14,
24544,
342,
272,
1738,
1931,
12,
1738,
2543,
275,
664,
63,
1231,
63,
1450,
8,
1231,
1716,
9,
272,
340,
1738,
2543,
365,
488,
26,
267,
1738,
1931,
275,
283,
5484,
7,
267,
1738,
2543,
275,
1613,
1494,
14,
7344,
804,
272,
1738,
5665,
275,
1738,
2543,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8,
1231,
1716,
9,
272,
327,
12030,
2018,
370,
8775,
314,
4601,
1202,
701,
314,
14316,
14,
272,
1382,
275,
488,
199,
309,
258,
984,
14,
2703,
14,
952,
4827,
31,
1652,
1015,
628,
17,
14,
16,
2,
5805,
3072,
78,
358,
199,
309,
258,
1738,
5665,
14,
3790,
8,
1274,
14,
2703,
12,
378,
12,
536,
10683,
1231,
1931,
12,
199,
309,
260,
18143,
7993,
358,
272,
372,
1738,
5665,
421,
199,
318,
2198,
7621,
8,
262,
8117,
304,
272,
1382,
275,
2198,
1652,
2531,
262,
8117,
9,
272,
1738,
1716,
275,
1382,
14,
24544,
342,
272,
1738,
1931,
12,
1738,
2543,
275,
664,
63,
1231,
63,
1450,
8,
1231,
1716,
9,
272,
340,
1738,
2543,
365,
488,
26,
267,
1738,
1931,
275,
283,
5484,
7,
267,
1738,
2543,
275,
1613,
1494,
14,
7344,
804,
272,
1738,
5665,
275,
1738,
2543,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
199,
3,
17065,
221,
701,
3550,
3177,
14,
647,
14,
199,
3,
199,
199,
646,
984,
199,
199,
646,
9133,
63,
4129,
466,
18,
63,
1961,
465,
1613,
1494,
199,
199,
9464,
63,
275,
488,
199,
21879,
63,
646,
63,
275,
756,
199,
8,
257,
4692,
2842,
63,
646,
63,
3592,
12,
4692,
2842,
63,
646,
63,
22899,
12,
272,
4692,
2842,
63,
646,
63,
2108,
2350,
272,
776,
275,
1425,
8,
19,
9,
199,
4317,
2842,
63,
646,
63,
4342,
275,
488,
199,
893,
26,
272,
327,
14490,
272,
687,
14490,
492,
7559,
465,
7559,
63,
272,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
22899,
272,
340,
5444,
2220,
63,
646,
10388,
267,
870,
480,
5720,
543,
14490,
14,
9464,
531,
199,
2590,
3545,
26,
272,
862,
26,
267,
327,
286,
15325,
687,
2018,
499,
14,
21,
11,
267,
492,
2748,
14,
9464,
14,
67,
15325,
465,
7559,
63,
267,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
267,
340,
5444,
2220,
63,
646,
10388,
288,
870,
480,
5720,
543,
286,
15325,
641,
2018,
499,
14,
21,
21425,
272,
871,
3545,
26,
267,
862,
26,
288,
327,
13139,
687,
2018,
499,
14,
21,
11,
288,
492,
2748,
14,
9464,
14,
15325,
465,
7559,
63,
288,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
288,
340,
5444,
2220,
63,
646,
10388,
355,
870,
480,
5720,
543,
13139,
641,
2018,
499,
14,
21,
21425,
267,
871,
3545,
26,
288,
862,
26,
355,
327,
3293,
286,
15325,
3907,
355,
492,
286,
15325,
465,
7559,
63,
355,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
355,
340,
5444,
2220,
63,
646,
10388,
490,
870,
480,
5720,
543,
286,
15325,
531,
288,
871,
3545,
26,
355,
862,
26,
490,
327,
3293,
13139,
3907,
490,
492,
1819,
2350,
14,
15325,
465,
7559,
63,
490,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
490,
340,
5444,
2220,
63,
646,
10388,
717,
870,
480,
5720,
543,
13139,
531,
355,
871,
3545,
26,
490,
746,
3545,
480,
4276,
370,
492,
13139,
687,
1263,
6040,
4192,
531,
199,
199,
318,
2198,
1652,
63,
2031,
589,
12,
1011,
958,
304,
272,
340,
334,
4317,
2842,
63,
646,
63,
4342,
508,
4692,
2842,
63,
646,
63,
22899,
436,
267,
283,
2087,
7,
440,
315,
2074,
304,
267,
327,
3645,
314,
14490,
13139,
9025,
1798,
880,
626,
12,
325,
14,
71,
2020,
267,
327,
257,
781,
3686,
6786,
14,
267,
2074,
459,
2087,
418,
275,
7559,
3754,
775,
2404,
292,
4317,
2842,
342,
272,
1382,
275,
7559,
3754,
1122,
2031,
589,
12,
1011,
958,
9,
272,
372,
1382,
199,
199,
3,
199,
3,
13641,
83,
199,
3,
199,
199,
25199,
275,
283,
4371,
7,
199,
199,
3,
199,
3,
3918,
6025,
3992,
199,
3,
199,
199,
533,
8028,
804,
2610,
8,
4792,
1494,
14,
7344,
804,
304,
272,
347,
636,
826,
721,
277,
12,
4954,
1304,
29,
403,
12,
6748,
29,
403,
12,
634,
354,
29,
403,
304,
267,
1613,
8,
7344,
804,
2610,
12,
291,
2843,
826,
721,
5484,
1304,
12,
6748,
12,
634,
354,
12,
776,
199,
4792,
1494,
14,
7344,
804,
14,
6083,
275,
8028,
804,
2610,
199,
3,
1284,
1021,
8028,
804,
2610,
4388,
199,
318,
664,
63,
1231,
63,
1450,
8,
932,
304,
272,
1947,
275,
1613,
1494,
14,
1931,
63,
3401,
3754,
1431,
8,
932,
14,
1450,
680,
2634,
19105,
17,
61,
272,
1738,
2543,
275,
488,
272,
340,
2688,
8,
4792,
1494,
12,
1947,
304,
267,
1738,
2543,
275,
2519,
8,
4792,
1494,
12,
1947,
9,
272,
372,
1947,
12,
1738,
2543,
421,
199,
318,
2198,
8,
262,
8117,
304,
272,
1382,
275,
2198,
1652,
2531,
262,
8117,
9,
272,
1738,
1716,
275,
1382,
14,
24544,
342,
272,
1738,
1931,
12,
1738,
2543,
275,
664,
63,
1231,
63,
1450,
8,
1231,
1716,
9,
272,
340,
1738,
2543,
365,
488,
26,
267,
1738,
1931,
275,
283,
5484,
7,
267,
1738,
2543,
275,
1613,
1494,
14,
7344,
804,
272,
1738,
5665,
275,
1738,
2543,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8,
1231,
1716,
9,
272,
327,
12030,
2018,
370,
8775,
314,
4601,
1202,
701,
314,
14316,
14,
272,
1382,
275,
488,
199,
309,
258,
984,
14,
2703,
14,
952,
4827,
31,
1652,
1015,
628,
17,
14,
16,
2,
5805,
3072,
78,
358,
199,
309,
258,
1738,
5665,
14,
3790,
8,
1274,
14,
2703,
12,
378,
12,
536,
10683,
1231,
1931,
12,
199,
309,
260,
18143,
15080,
199,
309,
260,
7268,
63,
1361,
29,
549,
9,
272,
1382,
275,
488,
272,
372,
1738,
5665,
421,
199,
318,
2198,
1558,
8,
262,
1558,
304,
272,
687,
5228,
492,
5228,
272,
1382,
275,
2198,
1652,
2531,
6424,
8,
262,
1558,
430,
272,
1738,
1716,
275,
1382,
14,
24544,
342,
272,
1738,
1931,
12,
1738,
2543,
275,
664,
63,
1231,
63,
1450,
8,
1231,
1716,
9,
272,
340,
1738,
2543,
365,
488,
26,
267,
1738,
1931,
275,
283,
5484,
7,
267,
1738,
2543,
275,
1613,
1494,
14,
7344,
804,
272,
1738,
5665,
275,
1738,
2543,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8,
1231,
1716,
9,
272,
327,
12030,
2018,
370,
8775,
314,
4601,
1202,
701,
314,
14316,
14,
272,
1382,
275,
488,
199,
309,
258,
984,
14,
2703,
14,
952,
4827,
31,
1652,
1015,
628,
17,
14,
16,
2,
5805,
3072,
78,
358,
199,
309,
258,
1738,
5665,
14,
3790,
8,
1274,
14,
2703,
12,
378,
12,
536,
10683,
1231,
1931,
12,
199,
309,
260,
18143,
7993,
358,
272,
372,
1738,
5665,
421,
199,
318,
2198,
7621,
8,
262,
8117,
304,
272,
1382,
275,
2198,
1652,
2531,
262,
8117,
9,
272,
1738,
1716,
275,
1382,
14,
24544,
342,
272,
1738,
1931,
12,
1738,
2543,
275,
664,
63,
1231,
63,
1450,
8,
1231,
1716,
9,
272,
340,
1738,
2543,
365,
488,
26,
267,
1738,
1931,
275,
283,
5484,
7,
267,
1738,
2543,
275,
1613,
1494,
14,
7344,
804,
272,
1738,
5665,
275,
1738,
2543,
14,
3702,
342,
272,
1738,
5665,
14,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1,
1,
1,
1,
1
] |
muffl0n/ansible-cmdb
|
lib/mako/ast.py
|
60
|
6702
|
# mako/ast.py
# Copyright (C) 2006-2015 the Mako authors and contributors <see AUTHORS file>
#
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""utilities for analyzing expressions and blocks of Python
code, as well as generating Python from AST nodes"""
from mako import exceptions, pyparser, compat
import re
class PythonCode(object):
"""represents information about a string containing Python code"""
def __init__(self, code, **exception_kwargs):
self.code = code
# represents all identifiers which are assigned to at some point in
# the code
self.declared_identifiers = set()
# represents all identifiers which are referenced before their
# assignment, if any
self.undeclared_identifiers = set()
# note that an identifier can be in both the undeclared and declared
# lists.
# using AST to parse instead of using code.co_varnames,
# code.co_names has several advantages:
# - we can locate an identifier as "undeclared" even if
# its declared later in the same block of code
# - AST is less likely to break with version changes
# (for example, the behavior of co_names changed a little bit
# in python version 2.5)
if isinstance(code, compat.string_types):
expr = pyparser.parse(code.lstrip(), "exec", **exception_kwargs)
else:
expr = code
f = pyparser.FindIdentifiers(self, **exception_kwargs)
f.visit(expr)
class ArgumentList(object):
"""parses a fragment of code as a comma-separated list of expressions"""
def __init__(self, code, **exception_kwargs):
self.codeargs = []
self.args = []
self.declared_identifiers = set()
self.undeclared_identifiers = set()
if isinstance(code, compat.string_types):
if re.match(r"\S", code) and not re.match(r",\s*$", code):
# if theres text and no trailing comma, insure its parsed
# as a tuple by adding a trailing comma
code += ","
expr = pyparser.parse(code, "exec", **exception_kwargs)
else:
expr = code
f = pyparser.FindTuple(self, PythonCode, **exception_kwargs)
f.visit(expr)
class PythonFragment(PythonCode):
"""extends PythonCode to provide identifier lookups in partial control
statements
e.g.
for x in 5:
elif y==9:
except (MyException, e):
etc.
"""
def __init__(self, code, **exception_kwargs):
m = re.match(r'^(\w+)(?:\s+(.*?))?:\s*(#|$)', code.strip(), re.S)
if not m:
raise exceptions.CompileException(
"Fragment '%s' is not a partial control statement" %
code, **exception_kwargs)
if m.group(3):
code = code[:m.start(3)]
(keyword, expr) = m.group(1,2)
if keyword in ['for','if', 'while']:
code = code + "pass"
elif keyword == 'try':
code = code + "pass\nexcept:pass"
elif keyword == 'elif' or keyword == 'else':
code = "if False:pass\n" + code + "pass"
elif keyword == 'except':
code = "try:pass\n" + code + "pass"
elif keyword == 'with':
code = code + "pass"
else:
raise exceptions.CompileException(
"Unsupported control keyword: '%s'" %
keyword, **exception_kwargs)
super(PythonFragment, self).__init__(code, **exception_kwargs)
class FunctionDecl(object):
"""function declaration"""
def __init__(self, code, allow_kwargs=True, **exception_kwargs):
self.code = code
expr = pyparser.parse(code, "exec", **exception_kwargs)
f = pyparser.ParseFunc(self, **exception_kwargs)
f.visit(expr)
if not hasattr(self, 'funcname'):
raise exceptions.CompileException(
"Code '%s' is not a function declaration" % code,
**exception_kwargs)
if not allow_kwargs and self.kwargs:
raise exceptions.CompileException(
"'**%s' keyword argument not allowed here" %
self.kwargnames[-1], **exception_kwargs)
def get_argument_expressions(self, as_call=False):
"""Return the argument declarations of this FunctionDecl as a printable
list.
By default the return value is appropriate for writing in a ``def``;
set `as_call` to true to build arguments to be passed to the function
instead (assuming locals with the same names as the arguments exist).
"""
namedecls = []
# Build in reverse order, since defaults and slurpy args come last
argnames = self.argnames[::-1]
kwargnames = self.kwargnames[::-1]
defaults = self.defaults[::-1]
kwdefaults = self.kwdefaults[::-1]
# Named arguments
if self.kwargs:
namedecls.append("**" + kwargnames.pop(0))
for name in kwargnames:
# Keyword-only arguments must always be used by name, so even if
# this is a call, print out `foo=foo`
if as_call:
namedecls.append("%s=%s" % (name, name))
elif kwdefaults:
default = kwdefaults.pop(0)
if default is None:
# The AST always gives kwargs a default, since you can do
# `def foo(*, a=1, b, c=3)`
namedecls.append(name)
else:
namedecls.append("%s=%s" % (
name, pyparser.ExpressionGenerator(default).value()))
else:
namedecls.append(name)
# Positional arguments
if self.varargs:
namedecls.append("*" + argnames.pop(0))
for name in argnames:
if as_call or not defaults:
namedecls.append(name)
else:
default = defaults.pop(0)
namedecls.append("%s=%s" % (
name, pyparser.ExpressionGenerator(default).value()))
namedecls.reverse()
return namedecls
@property
def allargnames(self):
return tuple(self.argnames) + tuple(self.kwargnames)
class FunctionArgs(FunctionDecl):
"""the argument portion of a function declaration"""
def __init__(self, code, **kwargs):
super(FunctionArgs, self).__init__("def ANON(%s):pass" % code,
**kwargs)
|
mit
|
[
3,
26834,
15,
1810,
14,
647,
199,
3,
1898,
334,
35,
9,
8315,
13,
7806,
314,
603,
23564,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
603,
23564,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
16355,
367,
5909,
20135,
8455,
436,
5664,
402,
2018,
199,
600,
12,
465,
5521,
465,
12999,
2018,
687,
20788,
3380,
624,
199,
199,
504,
26834,
492,
4967,
12,
1134,
2087,
12,
8434,
199,
646,
295,
199,
199,
533,
2018,
3034,
8,
785,
304,
272,
408,
13063,
83,
2556,
3595,
282,
1059,
3035,
2018,
1233,
624,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
1011,
1971,
63,
958,
304,
267,
291,
14,
600,
275,
1233,
398,
327,
8469,
1006,
14154,
1314,
787,
7943,
370,
737,
2005,
2376,
315,
267,
327,
314,
1233,
267,
291,
14,
13545,
63,
14227,
275,
663,
342,
398,
327,
8469,
1006,
14154,
1314,
787,
11812,
2544,
3932,
267,
327,
9801,
12,
340,
1263,
267,
291,
14,
31531,
63,
14227,
275,
663,
342,
398,
327,
5317,
626,
376,
5148,
883,
506,
315,
3865,
314,
625,
13545,
436,
14290,
267,
327,
5548,
14,
398,
327,
1808,
20788,
370,
2198,
3140,
402,
1808,
1233,
14,
331,
63,
1391,
1247,
12,
267,
327,
1233,
14,
331,
63,
1247,
965,
9978,
19396,
867,
7441,
26,
267,
327,
446,
781,
883,
16592,
376,
5148,
465,
298,
31531,
2,
2755,
340,
267,
327,
2399,
14290,
2945,
315,
314,
2011,
1853,
402,
1233,
267,
327,
446,
20788,
365,
6656,
12060,
370,
2059,
543,
1015,
4493,
267,
327,
334,
509,
2893,
12,
314,
5953,
402,
512,
63,
1247,
2896,
282,
12050,
4546,
267,
327,
315,
2366,
1015,
499,
14,
21,
9,
267,
340,
1228,
8,
600,
12,
8434,
14,
875,
63,
1313,
304,
288,
5348,
275,
1134,
2087,
14,
1122,
8,
600,
14,
10124,
1062,
298,
1628,
401,
1011,
1971,
63,
958,
9,
267,
587,
26,
288,
5348,
275,
1233,
398,
289,
275,
1134,
2087,
14,
6591,
41,
8577,
8,
277,
12,
1011,
1971,
63,
958,
9,
267,
289,
14,
5427,
8,
3684,
9,
199,
199,
533,
5886,
1296,
8,
785,
304,
272,
408,
462,
874,
282,
7956,
402,
1233,
465,
282,
10029,
13,
12794,
769,
402,
8455,
624,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
1011,
1971,
63,
958,
304,
267,
291,
14,
600,
589,
275,
942,
267,
291,
14,
589,
275,
942,
267,
291,
14,
13545,
63,
14227,
275,
663,
342,
267,
291,
14,
31531,
63,
14227,
275,
663,
342,
267,
340,
1228,
8,
600,
12,
8434,
14,
875,
63,
1313,
304,
288,
340,
295,
14,
1431,
8,
82,
3212,
51,
401,
1233,
9,
436,
440,
295,
14,
1431,
8,
82,
22260,
83,
10,
11918,
1233,
304,
355,
327,
340,
314,
470,
1318,
436,
949,
8520,
10029,
12,
315,
3253,
2399,
4565,
355,
327,
465,
282,
2008,
701,
7791,
282,
8520,
10029,
355,
1233,
221,
847,
21147,
288,
5348,
275,
1134,
2087,
14,
1122,
8,
600,
12,
298,
1628,
401,
1011,
1971,
63,
958,
9,
267,
587,
26,
288,
5348,
275,
1233,
398,
289,
275,
1134,
2087,
14,
6591,
7075,
8,
277,
12,
2018,
3034,
12,
1011,
1971,
63,
958,
9,
267,
289,
14,
5427,
8,
3684,
9,
199,
199,
533,
2018,
11080,
8,
4718,
3034,
304,
272,
408,
11036,
2018,
3034,
370,
5647,
5148,
16807,
315,
7417,
3304,
272,
9834,
339,
325,
14,
71,
14,
267,
367,
671,
315,
959,
26,
267,
916,
612,
389,
25,
26,
267,
871,
334,
5713,
1726,
12,
325,
304,
272,
5423,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
1011,
1971,
63,
958,
304,
267,
333,
275,
295,
14,
1431,
8,
82,
31344,
87,
8771,
15840,
83,
15622,
6697,
22119,
3427,
83,
5830,
3,
92,
4,
3196,
1233,
14,
1913,
1062,
295,
14,
51,
9,
267,
340,
440,
333,
26,
288,
746,
4967,
14,
12626,
1726,
8,
2079,
298,
11080,
1543,
83,
7,
365,
440,
282,
7417,
3304,
5164,
2,
450,
2079,
1233,
12,
1011,
1971,
63,
958,
9,
267,
340,
333,
14,
923,
8,
19,
304,
288,
1233,
275,
1233,
1491,
77,
14,
928,
8,
19,
1874,
267,
334,
6691,
12,
5348,
9,
275,
333,
14,
923,
8,
17,
12,
18,
9,
267,
340,
4252,
315,
788,
509,
1673,
692,
297,
283,
6710,
2565,
288,
1233,
275,
1233,
435,
298,
1529,
2,
267,
916,
4252,
508,
283,
893,
356,
288,
1233,
275,
1233,
435,
298,
1529,
60,
78,
2590,
26,
1529,
2,
267,
916,
4252,
508,
283,
4164,
7,
503,
4252,
508,
283,
2836,
356,
288,
1233,
275,
298,
692,
756,
26,
1529,
60,
78,
2,
435,
1233,
435,
298,
1529,
2,
267,
916,
4252,
508,
283,
2590,
356,
288,
1233,
275,
298,
893,
26,
1529,
60,
78,
2,
435,
1233,
435,
298,
1529,
2,
267,
916,
4252,
508,
283,
1045,
356,
288,
1233,
275,
1233,
435,
298,
1529,
2,
267,
587,
26,
288,
746,
4967,
14,
12626,
1726,
8,
1816,
298,
12647,
3304,
4252,
26,
1543,
83,
4065,
450,
1816,
4252,
12,
1011,
1971,
63,
958,
9,
267,
1613,
8,
4718,
11080,
12,
291,
2843,
826,
721,
600,
12,
1011,
1971,
63,
958,
9,
421,
199,
533,
6801,
20856,
8,
785,
304,
272,
408,
1593,
12560,
624,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
2040,
63,
958,
29,
549,
12,
1011,
1971,
63,
958,
304,
267,
291,
14,
600,
275,
1233,
267,
5348,
275,
1134,
2087,
14,
1122,
8,
600,
12,
298,
1628,
401,
1011,
1971,
63,
958,
9,
398,
289,
275,
1134,
2087,
14,
4003,
7465,
8,
277,
12,
1011,
1971,
63,
958,
9,
267,
289,
14,
5427,
8,
3684,
9,
267,
340,
440,
2688,
8,
277,
12,
283,
29577,
735,
288,
746,
4967,
14,
12626,
1726,
8,
1169,
298,
3034,
1543,
83,
7,
365,
440,
282,
805,
12560,
2,
450,
1233,
12,
1169,
1011,
1971,
63,
958,
9,
267,
340,
440,
2040,
63,
958,
436,
291,
14,
958,
26,
288,
746,
4967,
14,
12626,
1726,
8,
1816,
3546,
538,
5,
83,
7,
4252,
1423,
440,
4370,
2348,
2,
450,
1816,
291,
14,
12745
] |
[
26834,
15,
1810,
14,
647,
199,
3,
1898,
334,
35,
9,
8315,
13,
7806,
314,
603,
23564,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
603,
23564,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
16355,
367,
5909,
20135,
8455,
436,
5664,
402,
2018,
199,
600,
12,
465,
5521,
465,
12999,
2018,
687,
20788,
3380,
624,
199,
199,
504,
26834,
492,
4967,
12,
1134,
2087,
12,
8434,
199,
646,
295,
199,
199,
533,
2018,
3034,
8,
785,
304,
272,
408,
13063,
83,
2556,
3595,
282,
1059,
3035,
2018,
1233,
624,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
1011,
1971,
63,
958,
304,
267,
291,
14,
600,
275,
1233,
398,
327,
8469,
1006,
14154,
1314,
787,
7943,
370,
737,
2005,
2376,
315,
267,
327,
314,
1233,
267,
291,
14,
13545,
63,
14227,
275,
663,
342,
398,
327,
8469,
1006,
14154,
1314,
787,
11812,
2544,
3932,
267,
327,
9801,
12,
340,
1263,
267,
291,
14,
31531,
63,
14227,
275,
663,
342,
398,
327,
5317,
626,
376,
5148,
883,
506,
315,
3865,
314,
625,
13545,
436,
14290,
267,
327,
5548,
14,
398,
327,
1808,
20788,
370,
2198,
3140,
402,
1808,
1233,
14,
331,
63,
1391,
1247,
12,
267,
327,
1233,
14,
331,
63,
1247,
965,
9978,
19396,
867,
7441,
26,
267,
327,
446,
781,
883,
16592,
376,
5148,
465,
298,
31531,
2,
2755,
340,
267,
327,
2399,
14290,
2945,
315,
314,
2011,
1853,
402,
1233,
267,
327,
446,
20788,
365,
6656,
12060,
370,
2059,
543,
1015,
4493,
267,
327,
334,
509,
2893,
12,
314,
5953,
402,
512,
63,
1247,
2896,
282,
12050,
4546,
267,
327,
315,
2366,
1015,
499,
14,
21,
9,
267,
340,
1228,
8,
600,
12,
8434,
14,
875,
63,
1313,
304,
288,
5348,
275,
1134,
2087,
14,
1122,
8,
600,
14,
10124,
1062,
298,
1628,
401,
1011,
1971,
63,
958,
9,
267,
587,
26,
288,
5348,
275,
1233,
398,
289,
275,
1134,
2087,
14,
6591,
41,
8577,
8,
277,
12,
1011,
1971,
63,
958,
9,
267,
289,
14,
5427,
8,
3684,
9,
199,
199,
533,
5886,
1296,
8,
785,
304,
272,
408,
462,
874,
282,
7956,
402,
1233,
465,
282,
10029,
13,
12794,
769,
402,
8455,
624,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
1011,
1971,
63,
958,
304,
267,
291,
14,
600,
589,
275,
942,
267,
291,
14,
589,
275,
942,
267,
291,
14,
13545,
63,
14227,
275,
663,
342,
267,
291,
14,
31531,
63,
14227,
275,
663,
342,
267,
340,
1228,
8,
600,
12,
8434,
14,
875,
63,
1313,
304,
288,
340,
295,
14,
1431,
8,
82,
3212,
51,
401,
1233,
9,
436,
440,
295,
14,
1431,
8,
82,
22260,
83,
10,
11918,
1233,
304,
355,
327,
340,
314,
470,
1318,
436,
949,
8520,
10029,
12,
315,
3253,
2399,
4565,
355,
327,
465,
282,
2008,
701,
7791,
282,
8520,
10029,
355,
1233,
221,
847,
21147,
288,
5348,
275,
1134,
2087,
14,
1122,
8,
600,
12,
298,
1628,
401,
1011,
1971,
63,
958,
9,
267,
587,
26,
288,
5348,
275,
1233,
398,
289,
275,
1134,
2087,
14,
6591,
7075,
8,
277,
12,
2018,
3034,
12,
1011,
1971,
63,
958,
9,
267,
289,
14,
5427,
8,
3684,
9,
199,
199,
533,
2018,
11080,
8,
4718,
3034,
304,
272,
408,
11036,
2018,
3034,
370,
5647,
5148,
16807,
315,
7417,
3304,
272,
9834,
339,
325,
14,
71,
14,
267,
367,
671,
315,
959,
26,
267,
916,
612,
389,
25,
26,
267,
871,
334,
5713,
1726,
12,
325,
304,
272,
5423,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
1011,
1971,
63,
958,
304,
267,
333,
275,
295,
14,
1431,
8,
82,
31344,
87,
8771,
15840,
83,
15622,
6697,
22119,
3427,
83,
5830,
3,
92,
4,
3196,
1233,
14,
1913,
1062,
295,
14,
51,
9,
267,
340,
440,
333,
26,
288,
746,
4967,
14,
12626,
1726,
8,
2079,
298,
11080,
1543,
83,
7,
365,
440,
282,
7417,
3304,
5164,
2,
450,
2079,
1233,
12,
1011,
1971,
63,
958,
9,
267,
340,
333,
14,
923,
8,
19,
304,
288,
1233,
275,
1233,
1491,
77,
14,
928,
8,
19,
1874,
267,
334,
6691,
12,
5348,
9,
275,
333,
14,
923,
8,
17,
12,
18,
9,
267,
340,
4252,
315,
788,
509,
1673,
692,
297,
283,
6710,
2565,
288,
1233,
275,
1233,
435,
298,
1529,
2,
267,
916,
4252,
508,
283,
893,
356,
288,
1233,
275,
1233,
435,
298,
1529,
60,
78,
2590,
26,
1529,
2,
267,
916,
4252,
508,
283,
4164,
7,
503,
4252,
508,
283,
2836,
356,
288,
1233,
275,
298,
692,
756,
26,
1529,
60,
78,
2,
435,
1233,
435,
298,
1529,
2,
267,
916,
4252,
508,
283,
2590,
356,
288,
1233,
275,
298,
893,
26,
1529,
60,
78,
2,
435,
1233,
435,
298,
1529,
2,
267,
916,
4252,
508,
283,
1045,
356,
288,
1233,
275,
1233,
435,
298,
1529,
2,
267,
587,
26,
288,
746,
4967,
14,
12626,
1726,
8,
1816,
298,
12647,
3304,
4252,
26,
1543,
83,
4065,
450,
1816,
4252,
12,
1011,
1971,
63,
958,
9,
267,
1613,
8,
4718,
11080,
12,
291,
2843,
826,
721,
600,
12,
1011,
1971,
63,
958,
9,
421,
199,
533,
6801,
20856,
8,
785,
304,
272,
408,
1593,
12560,
624,
272,
347,
636,
826,
721,
277,
12,
1233,
12,
2040,
63,
958,
29,
549,
12,
1011,
1971,
63,
958,
304,
267,
291,
14,
600,
275,
1233,
267,
5348,
275,
1134,
2087,
14,
1122,
8,
600,
12,
298,
1628,
401,
1011,
1971,
63,
958,
9,
398,
289,
275,
1134,
2087,
14,
4003,
7465,
8,
277,
12,
1011,
1971,
63,
958,
9,
267,
289,
14,
5427,
8,
3684,
9,
267,
340,
440,
2688,
8,
277,
12,
283,
29577,
735,
288,
746,
4967,
14,
12626,
1726,
8,
1169,
298,
3034,
1543,
83,
7,
365,
440,
282,
805,
12560,
2,
450,
1233,
12,
1169,
1011,
1971,
63,
958,
9,
267,
340,
440,
2040,
63,
958,
436,
291,
14,
958,
26,
288,
746,
4967,
14,
12626,
1726,
8,
1816,
3546,
538,
5,
83,
7,
4252,
1423,
440,
4370,
2348,
2,
450,
1816,
291,
14,
12745,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PopCap/GameIdea
|
Engine/Source/ThirdParty/HTML5/emsdk/Win64/python/2.7.5.3_64bit/Lib/site-packages/pip/vendor/html5lib/html5parser.py
|
79
|
117499
|
from __future__ import absolute_import, division, unicode_literals
from pip.vendor.six import with_metaclass
import types
from . import inputstream
from . import tokenizer
from . import treebuilders
from .treebuilders._base import Marker
from . import utils
from . import constants
from .constants import spaceCharacters, asciiUpper2Lower
from .constants import specialElements
from .constants import headingElements
from .constants import cdataElements, rcdataElements
from .constants import tokenTypes, ReparseException, namespaces
from .constants import htmlIntegrationPointElements, mathmlTextIntegrationPointElements
def parse(doc, treebuilder="etree", encoding=None,
namespaceHTMLElements=True):
"""Parse a string or file-like object into a tree"""
tb = treebuilders.getTreeBuilder(treebuilder)
p = HTMLParser(tb, namespaceHTMLElements=namespaceHTMLElements)
return p.parse(doc, encoding=encoding)
def parseFragment(doc, container="div", treebuilder="etree", encoding=None,
namespaceHTMLElements=True):
tb = treebuilders.getTreeBuilder(treebuilder)
p = HTMLParser(tb, namespaceHTMLElements=namespaceHTMLElements)
return p.parseFragment(doc, container=container, encoding=encoding)
def method_decorator_metaclass(function):
class Decorated(type):
def __new__(meta, classname, bases, classDict):
for attributeName, attribute in classDict.items():
if isinstance(attribute, types.FunctionType):
attribute = function(attribute)
classDict[attributeName] = attribute
return type.__new__(meta, classname, bases, classDict)
return Decorated
class HTMLParser(object):
"""HTML parser. Generates a tree structure from a stream of (possibly
malformed) HTML"""
def __init__(self, tree=None, tokenizer=tokenizer.HTMLTokenizer,
strict=False, namespaceHTMLElements=True, debug=False):
"""
strict - raise an exception when a parse error is encountered
tree - a treebuilder class controlling the type of tree that will be
returned. Built in treebuilders can be accessed through
html5lib.treebuilders.getTreeBuilder(treeType)
tokenizer - a class that provides a stream of tokens to the treebuilder.
This may be replaced for e.g. a sanitizer which converts some tags to
text
"""
# Raise an exception on the first error encountered
self.strict = strict
if tree is None:
tree = treebuilders.getTreeBuilder("etree")
self.tree = tree(namespaceHTMLElements)
self.tokenizer_class = tokenizer
self.errors = []
self.phases = dict([(name, cls(self, self.tree)) for name, cls in
getPhases(debug).items()])
def _parse(self, stream, innerHTML=False, container="div",
encoding=None, parseMeta=True, useChardet=True, **kwargs):
self.innerHTMLMode = innerHTML
self.container = container
self.tokenizer = self.tokenizer_class(stream, encoding=encoding,
parseMeta=parseMeta,
useChardet=useChardet,
parser=self, **kwargs)
self.reset()
while True:
try:
self.mainLoop()
break
except ReparseException:
self.reset()
def reset(self):
self.tree.reset()
self.firstStartTag = False
self.errors = []
self.log = [] # only used with debug mode
# "quirks" / "limited quirks" / "no quirks"
self.compatMode = "no quirks"
if self.innerHTMLMode:
self.innerHTML = self.container.lower()
if self.innerHTML in cdataElements:
self.tokenizer.state = self.tokenizer.rcdataState
elif self.innerHTML in rcdataElements:
self.tokenizer.state = self.tokenizer.rawtextState
elif self.innerHTML == 'plaintext':
self.tokenizer.state = self.tokenizer.plaintextState
else:
# state already is data state
# self.tokenizer.state = self.tokenizer.dataState
pass
self.phase = self.phases["beforeHtml"]
self.phase.insertHtmlElement()
self.resetInsertionMode()
else:
self.innerHTML = False
self.phase = self.phases["initial"]
self.lastPhase = None
self.beforeRCDataPhase = None
self.framesetOK = True
def isHTMLIntegrationPoint(self, element):
if (element.name == "annotation-xml" and
element.namespace == namespaces["mathml"]):
return ("encoding" in element.attributes and
element.attributes["encoding"].translate(
asciiUpper2Lower) in
("text/html", "application/xhtml+xml"))
else:
return (element.namespace, element.name) in htmlIntegrationPointElements
def isMathMLTextIntegrationPoint(self, element):
return (element.namespace, element.name) in mathmlTextIntegrationPointElements
def mainLoop(self):
CharactersToken = tokenTypes["Characters"]
SpaceCharactersToken = tokenTypes["SpaceCharacters"]
StartTagToken = tokenTypes["StartTag"]
EndTagToken = tokenTypes["EndTag"]
CommentToken = tokenTypes["Comment"]
DoctypeToken = tokenTypes["Doctype"]
ParseErrorToken = tokenTypes["ParseError"]
for token in self.normalizedTokens():
new_token = token
while new_token is not None:
currentNode = self.tree.openElements[-1] if self.tree.openElements else None
currentNodeNamespace = currentNode.namespace if currentNode else None
currentNodeName = currentNode.name if currentNode else None
type = new_token["type"]
if type == ParseErrorToken:
self.parseError(new_token["data"], new_token.get("datavars", {}))
new_token = None
else:
if (len(self.tree.openElements) == 0 or
currentNodeNamespace == self.tree.defaultNamespace or
(self.isMathMLTextIntegrationPoint(currentNode) and
((type == StartTagToken and
token["name"] not in frozenset(["mglyph", "malignmark"])) or
type in (CharactersToken, SpaceCharactersToken))) or
(currentNodeNamespace == namespaces["mathml"] and
currentNodeName == "annotation-xml" and
token["name"] == "svg") or
(self.isHTMLIntegrationPoint(currentNode) and
type in (StartTagToken, CharactersToken, SpaceCharactersToken))):
phase = self.phase
else:
phase = self.phases["inForeignContent"]
if type == CharactersToken:
new_token = phase.processCharacters(new_token)
elif type == SpaceCharactersToken:
new_token = phase.processSpaceCharacters(new_token)
elif type == StartTagToken:
new_token = phase.processStartTag(new_token)
elif type == EndTagToken:
new_token = phase.processEndTag(new_token)
elif type == CommentToken:
new_token = phase.processComment(new_token)
elif type == DoctypeToken:
new_token = phase.processDoctype(new_token)
if (type == StartTagToken and token["selfClosing"]
and not token["selfClosingAcknowledged"]):
self.parseError("non-void-element-with-trailing-solidus",
{"name": token["name"]})
# When the loop finishes it's EOF
reprocess = True
phases = []
while reprocess:
phases.append(self.phase)
reprocess = self.phase.processEOF()
if reprocess:
assert self.phase not in phases
def normalizedTokens(self):
for token in self.tokenizer:
yield self.normalizeToken(token)
def parse(self, stream, encoding=None, parseMeta=True, useChardet=True):
"""Parse a HTML document into a well-formed tree
stream - a filelike object or string containing the HTML to be parsed
The optional encoding parameter must be a string that indicates
the encoding. If specified, that encoding will be used,
regardless of any BOM or later declaration (such as in a meta
element)
"""
self._parse(stream, innerHTML=False, encoding=encoding,
parseMeta=parseMeta, useChardet=useChardet)
return self.tree.getDocument()
def parseFragment(self, stream, container="div", encoding=None,
parseMeta=False, useChardet=True):
"""Parse a HTML fragment into a well-formed tree fragment
container - name of the element we're setting the innerHTML property
if set to None, default to 'div'
stream - a filelike object or string containing the HTML to be parsed
The optional encoding parameter must be a string that indicates
the encoding. If specified, that encoding will be used,
regardless of any BOM or later declaration (such as in a meta
element)
"""
self._parse(stream, True, container=container, encoding=encoding)
return self.tree.getFragment()
def parseError(self, errorcode="XXX-undefined-error", datavars={}):
# XXX The idea is to make errorcode mandatory.
self.errors.append((self.tokenizer.stream.position(), errorcode, datavars))
if self.strict:
raise ParseError
def normalizeToken(self, token):
""" HTML5 specific normalizations to the token stream """
if token["type"] == tokenTypes["StartTag"]:
token["data"] = dict(token["data"][::-1])
return token
def adjustMathMLAttributes(self, token):
replacements = {"definitionurl": "definitionURL"}
for k, v in replacements.items():
if k in token["data"]:
token["data"][v] = token["data"][k]
del token["data"][k]
def adjustSVGAttributes(self, token):
replacements = {
"attributename": "attributeName",
"attributetype": "attributeType",
"basefrequency": "baseFrequency",
"baseprofile": "baseProfile",
"calcmode": "calcMode",
"clippathunits": "clipPathUnits",
"contentscripttype": "contentScriptType",
"contentstyletype": "contentStyleType",
"diffuseconstant": "diffuseConstant",
"edgemode": "edgeMode",
"externalresourcesrequired": "externalResourcesRequired",
"filterres": "filterRes",
"filterunits": "filterUnits",
"glyphref": "glyphRef",
"gradienttransform": "gradientTransform",
"gradientunits": "gradientUnits",
"kernelmatrix": "kernelMatrix",
"kernelunitlength": "kernelUnitLength",
"keypoints": "keyPoints",
"keysplines": "keySplines",
"keytimes": "keyTimes",
"lengthadjust": "lengthAdjust",
"limitingconeangle": "limitingConeAngle",
"markerheight": "markerHeight",
"markerunits": "markerUnits",
"markerwidth": "markerWidth",
"maskcontentunits": "maskContentUnits",
"maskunits": "maskUnits",
"numoctaves": "numOctaves",
"pathlength": "pathLength",
"patterncontentunits": "patternContentUnits",
"patterntransform": "patternTransform",
"patternunits": "patternUnits",
"pointsatx": "pointsAtX",
"pointsaty": "pointsAtY",
"pointsatz": "pointsAtZ",
"preservealpha": "preserveAlpha",
"preserveaspectratio": "preserveAspectRatio",
"primitiveunits": "primitiveUnits",
"refx": "refX",
"refy": "refY",
"repeatcount": "repeatCount",
"repeatdur": "repeatDur",
"requiredextensions": "requiredExtensions",
"requiredfeatures": "requiredFeatures",
"specularconstant": "specularConstant",
"specularexponent": "specularExponent",
"spreadmethod": "spreadMethod",
"startoffset": "startOffset",
"stddeviation": "stdDeviation",
"stitchtiles": "stitchTiles",
"surfacescale": "surfaceScale",
"systemlanguage": "systemLanguage",
"tablevalues": "tableValues",
"targetx": "targetX",
"targety": "targetY",
"textlength": "textLength",
"viewbox": "viewBox",
"viewtarget": "viewTarget",
"xchannelselector": "xChannelSelector",
"ychannelselector": "yChannelSelector",
"zoomandpan": "zoomAndPan"
}
for originalName in list(token["data"].keys()):
if originalName in replacements:
svgName = replacements[originalName]
token["data"][svgName] = token["data"][originalName]
del token["data"][originalName]
def adjustForeignAttributes(self, token):
replacements = {
"xlink:actuate": ("xlink", "actuate", namespaces["xlink"]),
"xlink:arcrole": ("xlink", "arcrole", namespaces["xlink"]),
"xlink:href": ("xlink", "href", namespaces["xlink"]),
"xlink:role": ("xlink", "role", namespaces["xlink"]),
"xlink:show": ("xlink", "show", namespaces["xlink"]),
"xlink:title": ("xlink", "title", namespaces["xlink"]),
"xlink:type": ("xlink", "type", namespaces["xlink"]),
"xml:base": ("xml", "base", namespaces["xml"]),
"xml:lang": ("xml", "lang", namespaces["xml"]),
"xml:space": ("xml", "space", namespaces["xml"]),
"xmlns": (None, "xmlns", namespaces["xmlns"]),
"xmlns:xlink": ("xmlns", "xlink", namespaces["xmlns"])
}
for originalName in token["data"].keys():
if originalName in replacements:
foreignName = replacements[originalName]
token["data"][foreignName] = token["data"][originalName]
del token["data"][originalName]
def reparseTokenNormal(self, token):
self.parser.phase()
def resetInsertionMode(self):
# The name of this method is mostly historical. (It's also used in the
# specification.)
last = False
newModes = {
"select": "inSelect",
"td": "inCell",
"th": "inCell",
"tr": "inRow",
"tbody": "inTableBody",
"thead": "inTableBody",
"tfoot": "inTableBody",
"caption": "inCaption",
"colgroup": "inColumnGroup",
"table": "inTable",
"head": "inBody",
"body": "inBody",
"frameset": "inFrameset",
"html": "beforeHead"
}
for node in self.tree.openElements[::-1]:
nodeName = node.name
new_phase = None
if node == self.tree.openElements[0]:
assert self.innerHTML
last = True
nodeName = self.innerHTML
# Check for conditions that should only happen in the innerHTML
# case
if nodeName in ("select", "colgroup", "head", "html"):
assert self.innerHTML
if not last and node.namespace != self.tree.defaultNamespace:
continue
if nodeName in newModes:
new_phase = self.phases[newModes[nodeName]]
break
elif last:
new_phase = self.phases["inBody"]
break
self.phase = new_phase
def parseRCDataRawtext(self, token, contentType):
"""Generic RCDATA/RAWTEXT Parsing algorithm
contentType - RCDATA or RAWTEXT
"""
assert contentType in ("RAWTEXT", "RCDATA")
self.tree.insertElement(token)
if contentType == "RAWTEXT":
self.tokenizer.state = self.tokenizer.rawtextState
else:
self.tokenizer.state = self.tokenizer.rcdataState
self.originalPhase = self.phase
self.phase = self.phases["text"]
def getPhases(debug):
def log(function):
"""Logger that records which phase processes each token"""
type_names = dict((value, key) for key, value in
constants.tokenTypes.items())
def wrapped(self, *args, **kwargs):
if function.__name__.startswith("process") and len(args) > 0:
token = args[0]
try:
info = {"type": type_names[token['type']]}
except:
raise
if token['type'] in constants.tagTokenTypes:
info["name"] = token['name']
self.parser.log.append((self.parser.tokenizer.state.__name__,
self.parser.phase.__class__.__name__,
self.__class__.__name__,
function.__name__,
info))
return function(self, *args, **kwargs)
else:
return function(self, *args, **kwargs)
return wrapped
def getMetaclass(use_metaclass, metaclass_func):
if use_metaclass:
return method_decorator_metaclass(metaclass_func)
else:
return type
class Phase(with_metaclass(getMetaclass(debug, log))):
"""Base class for helper object that implements each phase of processing
"""
def __init__(self, parser, tree):
self.parser = parser
self.tree = tree
def processEOF(self):
raise NotImplementedError
def processComment(self, token):
# For most phases the following is correct. Where it's not it will be
# overridden.
self.tree.insertComment(token, self.tree.openElements[-1])
def processDoctype(self, token):
self.parser.parseError("unexpected-doctype")
def processCharacters(self, token):
self.tree.insertText(token["data"])
def processSpaceCharacters(self, token):
self.tree.insertText(token["data"])
def processStartTag(self, token):
return self.startTagHandler[token["name"]](token)
def startTagHtml(self, token):
if not self.parser.firstStartTag and token["name"] == "html":
self.parser.parseError("non-html-root")
# XXX Need a check here to see if the first start tag token emitted is
# this token... If it's not, invoke self.parser.parseError().
for attr, value in token["data"].items():
if attr not in self.tree.openElements[0].attributes:
self.tree.openElements[0].attributes[attr] = value
self.parser.firstStartTag = False
def processEndTag(self, token):
return self.endTagHandler[token["name"]](token)
class InitialPhase(Phase):
def processSpaceCharacters(self, token):
pass
def processComment(self, token):
self.tree.insertComment(token, self.tree.document)
def processDoctype(self, token):
name = token["name"]
publicId = token["publicId"]
systemId = token["systemId"]
correct = token["correct"]
if (name != "html" or publicId is not None or
systemId is not None and systemId != "about:legacy-compat"):
self.parser.parseError("unknown-doctype")
if publicId is None:
publicId = ""
self.tree.insertDoctype(token)
if publicId != "":
publicId = publicId.translate(asciiUpper2Lower)
if (not correct or token["name"] != "html"
or publicId.startswith(
("+//silmaril//dtd html pro v0r11 19970101//",
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
"-//as//dtd html 3.0 aswedit + extensions//",
"-//ietf//dtd html 2.0 level 1//",
"-//ietf//dtd html 2.0 level 2//",
"-//ietf//dtd html 2.0 strict level 1//",
"-//ietf//dtd html 2.0 strict level 2//",
"-//ietf//dtd html 2.0 strict//",
"-//ietf//dtd html 2.0//",
"-//ietf//dtd html 2.1e//",
"-//ietf//dtd html 3.0//",
"-//ietf//dtd html 3.2 final//",
"-//ietf//dtd html 3.2//",
"-//ietf//dtd html 3//",
"-//ietf//dtd html level 0//",
"-//ietf//dtd html level 1//",
"-//ietf//dtd html level 2//",
"-//ietf//dtd html level 3//",
"-//ietf//dtd html strict level 0//",
"-//ietf//dtd html strict level 1//",
"-//ietf//dtd html strict level 2//",
"-//ietf//dtd html strict level 3//",
"-//ietf//dtd html strict//",
"-//ietf//dtd html//",
"-//metrius//dtd metrius presentational//",
"-//microsoft//dtd internet explorer 2.0 html strict//",
"-//microsoft//dtd internet explorer 2.0 html//",
"-//microsoft//dtd internet explorer 2.0 tables//",
"-//microsoft//dtd internet explorer 3.0 html strict//",
"-//microsoft//dtd internet explorer 3.0 html//",
"-//microsoft//dtd internet explorer 3.0 tables//",
"-//netscape comm. corp.//dtd html//",
"-//netscape comm. corp.//dtd strict html//",
"-//o'reilly and associates//dtd html 2.0//",
"-//o'reilly and associates//dtd html extended 1.0//",
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//",
"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//",
"-//spyglass//dtd html 2.0 extended//",
"-//sq//dtd html 2.0 hotmetal + extensions//",
"-//sun microsystems corp.//dtd hotjava html//",
"-//sun microsystems corp.//dtd hotjava strict html//",
"-//w3c//dtd html 3 1995-03-24//",
"-//w3c//dtd html 3.2 draft//",
"-//w3c//dtd html 3.2 final//",
"-//w3c//dtd html 3.2//",
"-//w3c//dtd html 3.2s draft//",
"-//w3c//dtd html 4.0 frameset//",
"-//w3c//dtd html 4.0 transitional//",
"-//w3c//dtd html experimental 19960712//",
"-//w3c//dtd html experimental 970421//",
"-//w3c//dtd w3 html//",
"-//w3o//dtd w3 html 3.0//",
"-//webtechs//dtd mozilla html 2.0//",
"-//webtechs//dtd mozilla html//"))
or publicId in
("-//w3o//dtd w3 html strict 3.0//en//",
"-/w3c/dtd html 4.0 transitional/en",
"html")
or publicId.startswith(
("-//w3c//dtd html 4.01 frameset//",
"-//w3c//dtd html 4.01 transitional//")) and
systemId is None
or systemId and systemId.lower() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
self.parser.compatMode = "quirks"
elif (publicId.startswith(
("-//w3c//dtd xhtml 1.0 frameset//",
"-//w3c//dtd xhtml 1.0 transitional//"))
or publicId.startswith(
("-//w3c//dtd html 4.01 frameset//",
"-//w3c//dtd html 4.01 transitional//")) and
systemId is not None):
self.parser.compatMode = "limited quirks"
self.parser.phase = self.parser.phases["beforeHtml"]
def anythingElse(self):
self.parser.compatMode = "quirks"
self.parser.phase = self.parser.phases["beforeHtml"]
def processCharacters(self, token):
self.parser.parseError("expected-doctype-but-got-chars")
self.anythingElse()
return token
def processStartTag(self, token):
self.parser.parseError("expected-doctype-but-got-start-tag",
{"name": token["name"]})
self.anythingElse()
return token
def processEndTag(self, token):
self.parser.parseError("expected-doctype-but-got-end-tag",
{"name": token["name"]})
self.anythingElse()
return token
def processEOF(self):
self.parser.parseError("expected-doctype-but-got-eof")
self.anythingElse()
return True
class BeforeHtmlPhase(Phase):
# helper methods
def insertHtmlElement(self):
self.tree.insertRoot(impliedTagToken("html", "StartTag"))
self.parser.phase = self.parser.phases["beforeHead"]
# other
def processEOF(self):
self.insertHtmlElement()
return True
def processComment(self, token):
self.tree.insertComment(token, self.tree.document)
def processSpaceCharacters(self, token):
pass
def processCharacters(self, token):
self.insertHtmlElement()
return token
def processStartTag(self, token):
if token["name"] == "html":
self.parser.firstStartTag = True
self.insertHtmlElement()
return token
def processEndTag(self, token):
if token["name"] not in ("head", "body", "html", "br"):
self.parser.parseError("unexpected-end-tag-before-html",
{"name": token["name"]})
else:
self.insertHtmlElement()
return token
class BeforeHeadPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("head", self.startTagHead)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
(("head", "body", "html", "br"), self.endTagImplyHead)
])
self.endTagHandler.default = self.endTagOther
def processEOF(self):
self.startTagHead(impliedTagToken("head", "StartTag"))
return True
def processSpaceCharacters(self, token):
pass
def processCharacters(self, token):
self.startTagHead(impliedTagToken("head", "StartTag"))
return token
def startTagHtml(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagHead(self, token):
self.tree.insertElement(token)
self.tree.headPointer = self.tree.openElements[-1]
self.parser.phase = self.parser.phases["inHead"]
def startTagOther(self, token):
self.startTagHead(impliedTagToken("head", "StartTag"))
return token
def endTagImplyHead(self, token):
self.startTagHead(impliedTagToken("head", "StartTag"))
return token
def endTagOther(self, token):
self.parser.parseError("end-tag-after-implied-root",
{"name": token["name"]})
class InHeadPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("title", self.startTagTitle),
(("noscript", "noframes", "style"), self.startTagNoScriptNoFramesStyle),
("script", self.startTagScript),
(("base", "basefont", "bgsound", "command", "link"),
self.startTagBaseLinkCommand),
("meta", self.startTagMeta),
("head", self.startTagHead)
])
self.startTagHandler.default = self.startTagOther
self. endTagHandler = utils.MethodDispatcher([
("head", self.endTagHead),
(("br", "html", "body"), self.endTagHtmlBodyBr)
])
self.endTagHandler.default = self.endTagOther
# the real thing
def processEOF(self):
self.anythingElse()
return True
def processCharacters(self, token):
self.anythingElse()
return token
def startTagHtml(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagHead(self, token):
self.parser.parseError("two-heads-are-not-better-than-one")
def startTagBaseLinkCommand(self, token):
self.tree.insertElement(token)
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
def startTagMeta(self, token):
self.tree.insertElement(token)
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
attributes = token["data"]
if self.parser.tokenizer.stream.charEncoding[1] == "tentative":
if "charset" in attributes:
self.parser.tokenizer.stream.changeEncoding(attributes["charset"])
elif ("content" in attributes and
"http-equiv" in attributes and
attributes["http-equiv"].lower() == "content-type"):
# Encoding it as UTF-8 here is a hack, as really we should pass
# the abstract Unicode string, and just use the
# ContentAttrParser on that, but using UTF-8 allows all chars
# to be encoded and as a ASCII-superset works.
data = inputstream.EncodingBytes(attributes["content"].encode("utf-8"))
parser = inputstream.ContentAttrParser(data)
codec = parser.parse()
self.parser.tokenizer.stream.changeEncoding(codec)
def startTagTitle(self, token):
self.parser.parseRCDataRawtext(token, "RCDATA")
def startTagNoScriptNoFramesStyle(self, token):
# Need to decide whether to implement the scripting-disabled case
self.parser.parseRCDataRawtext(token, "RAWTEXT")
def startTagScript(self, token):
self.tree.insertElement(token)
self.parser.tokenizer.state = self.parser.tokenizer.scriptDataState
self.parser.originalPhase = self.parser.phase
self.parser.phase = self.parser.phases["text"]
def startTagOther(self, token):
self.anythingElse()
return token
def endTagHead(self, token):
node = self.parser.tree.openElements.pop()
assert node.name == "head", "Expected head got %s" % node.name
self.parser.phase = self.parser.phases["afterHead"]
def endTagHtmlBodyBr(self, token):
self.anythingElse()
return token
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
def anythingElse(self):
self.endTagHead(impliedTagToken("head"))
# XXX If we implement a parser for which scripting is disabled we need to
# implement this phase.
#
# class InHeadNoScriptPhase(Phase):
class AfterHeadPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("body", self.startTagBody),
("frameset", self.startTagFrameset),
(("base", "basefont", "bgsound", "link", "meta", "noframes", "script",
"style", "title"),
self.startTagFromHead),
("head", self.startTagHead)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([(("body", "html", "br"),
self.endTagHtmlBodyBr)])
self.endTagHandler.default = self.endTagOther
def processEOF(self):
self.anythingElse()
return True
def processCharacters(self, token):
self.anythingElse()
return token
def startTagHtml(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagBody(self, token):
self.parser.framesetOK = False
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inBody"]
def startTagFrameset(self, token):
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inFrameset"]
def startTagFromHead(self, token):
self.parser.parseError("unexpected-start-tag-out-of-my-head",
{"name": token["name"]})
self.tree.openElements.append(self.tree.headPointer)
self.parser.phases["inHead"].processStartTag(token)
for node in self.tree.openElements[::-1]:
if node.name == "head":
self.tree.openElements.remove(node)
break
def startTagHead(self, token):
self.parser.parseError("unexpected-start-tag", {"name": token["name"]})
def startTagOther(self, token):
self.anythingElse()
return token
def endTagHtmlBodyBr(self, token):
self.anythingElse()
return token
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
def anythingElse(self):
self.tree.insertElement(impliedTagToken("body", "StartTag"))
self.parser.phase = self.parser.phases["inBody"]
self.parser.framesetOK = True
class InBodyPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#parsing-main-inbody
# the really-really-really-very crazy mode
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
# Keep a ref to this for special handling of whitespace in <pre>
self.processSpaceCharactersNonPre = self.processSpaceCharacters
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
(("base", "basefont", "bgsound", "command", "link", "meta",
"noframes", "script", "style", "title"),
self.startTagProcessInHead),
("body", self.startTagBody),
("frameset", self.startTagFrameset),
(("address", "article", "aside", "blockquote", "center", "details",
"details", "dir", "div", "dl", "fieldset", "figcaption", "figure",
"footer", "header", "hgroup", "main", "menu", "nav", "ol", "p",
"section", "summary", "ul"),
self.startTagCloseP),
(headingElements, self.startTagHeading),
(("pre", "listing"), self.startTagPreListing),
("form", self.startTagForm),
(("li", "dd", "dt"), self.startTagListItem),
("plaintext", self.startTagPlaintext),
("a", self.startTagA),
(("b", "big", "code", "em", "font", "i", "s", "small", "strike",
"strong", "tt", "u"), self.startTagFormatting),
("nobr", self.startTagNobr),
("button", self.startTagButton),
(("applet", "marquee", "object"), self.startTagAppletMarqueeObject),
("xmp", self.startTagXmp),
("table", self.startTagTable),
(("area", "br", "embed", "img", "keygen", "wbr"),
self.startTagVoidFormatting),
(("param", "source", "track"), self.startTagParamSource),
("input", self.startTagInput),
("hr", self.startTagHr),
("image", self.startTagImage),
("isindex", self.startTagIsIndex),
("textarea", self.startTagTextarea),
("iframe", self.startTagIFrame),
(("noembed", "noframes", "noscript"), self.startTagRawtext),
("select", self.startTagSelect),
(("rp", "rt"), self.startTagRpRt),
(("option", "optgroup"), self.startTagOpt),
(("math"), self.startTagMath),
(("svg"), self.startTagSvg),
(("caption", "col", "colgroup", "frame", "head",
"tbody", "td", "tfoot", "th", "thead",
"tr"), self.startTagMisplaced)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("body", self.endTagBody),
("html", self.endTagHtml),
(("address", "article", "aside", "blockquote", "button", "center",
"details", "dialog", "dir", "div", "dl", "fieldset", "figcaption", "figure",
"footer", "header", "hgroup", "listing", "main", "menu", "nav", "ol", "pre",
"section", "summary", "ul"), self.endTagBlock),
("form", self.endTagForm),
("p", self.endTagP),
(("dd", "dt", "li"), self.endTagListItem),
(headingElements, self.endTagHeading),
(("a", "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
"strike", "strong", "tt", "u"), self.endTagFormatting),
(("applet", "marquee", "object"), self.endTagAppletMarqueeObject),
("br", self.endTagBr),
])
self.endTagHandler.default = self.endTagOther
def isMatchingFormattingElement(self, node1, node2):
if node1.name != node2.name or node1.namespace != node2.namespace:
return False
elif len(node1.attributes) != len(node2.attributes):
return False
else:
attributes1 = sorted(node1.attributes.items())
attributes2 = sorted(node2.attributes.items())
for attr1, attr2 in zip(attributes1, attributes2):
if attr1 != attr2:
return False
return True
# helper
def addFormattingElement(self, token):
self.tree.insertElement(token)
element = self.tree.openElements[-1]
matchingElements = []
for node in self.tree.activeFormattingElements[::-1]:
if node is Marker:
break
elif self.isMatchingFormattingElement(node, element):
matchingElements.append(node)
assert len(matchingElements) <= 3
if len(matchingElements) == 3:
self.tree.activeFormattingElements.remove(matchingElements[-1])
self.tree.activeFormattingElements.append(element)
# the real deal
def processEOF(self):
allowed_elements = frozenset(("dd", "dt", "li", "p", "tbody", "td",
"tfoot", "th", "thead", "tr", "body",
"html"))
for node in self.tree.openElements[::-1]:
if node.name not in allowed_elements:
self.parser.parseError("expected-closing-tag-but-got-eof")
break
# Stop parsing
def processSpaceCharactersDropNewline(self, token):
# Sometimes (start of <pre>, <listing>, and <textarea> blocks) we
# want to drop leading newlines
data = token["data"]
self.processSpaceCharacters = self.processSpaceCharactersNonPre
if (data.startswith("\n") and
self.tree.openElements[-1].name in ("pre", "listing", "textarea")
and not self.tree.openElements[-1].hasContent()):
data = data[1:]
if data:
self.tree.reconstructActiveFormattingElements()
self.tree.insertText(data)
def processCharacters(self, token):
if token["data"] == "\u0000":
# The tokenizer should always emit null on its own
return
self.tree.reconstructActiveFormattingElements()
self.tree.insertText(token["data"])
# This must be bad for performance
if (self.parser.framesetOK and
any([char not in spaceCharacters
for char in token["data"]])):
self.parser.framesetOK = False
def processSpaceCharacters(self, token):
self.tree.reconstructActiveFormattingElements()
self.tree.insertText(token["data"])
def startTagProcessInHead(self, token):
return self.parser.phases["inHead"].processStartTag(token)
def startTagBody(self, token):
self.parser.parseError("unexpected-start-tag", {"name": "body"})
if (len(self.tree.openElements) == 1
or self.tree.openElements[1].name != "body"):
assert self.parser.innerHTML
else:
self.parser.framesetOK = False
for attr, value in token["data"].items():
if attr not in self.tree.openElements[1].attributes:
self.tree.openElements[1].attributes[attr] = value
def startTagFrameset(self, token):
self.parser.parseError("unexpected-start-tag", {"name": "frameset"})
if (len(self.tree.openElements) == 1 or self.tree.openElements[1].name != "body"):
assert self.parser.innerHTML
elif not self.parser.framesetOK:
pass
else:
if self.tree.openElements[1].parent:
self.tree.openElements[1].parent.removeChild(self.tree.openElements[1])
while self.tree.openElements[-1].name != "html":
self.tree.openElements.pop()
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inFrameset"]
def startTagCloseP(self, token):
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
self.tree.insertElement(token)
def startTagPreListing(self, token):
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
self.tree.insertElement(token)
self.parser.framesetOK = False
self.processSpaceCharacters = self.processSpaceCharactersDropNewline
def startTagForm(self, token):
if self.tree.formPointer:
self.parser.parseError("unexpected-start-tag", {"name": "form"})
else:
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
self.tree.insertElement(token)
self.tree.formPointer = self.tree.openElements[-1]
def startTagListItem(self, token):
self.parser.framesetOK = False
stopNamesMap = {"li": ["li"],
"dt": ["dt", "dd"],
"dd": ["dt", "dd"]}
stopNames = stopNamesMap[token["name"]]
for node in reversed(self.tree.openElements):
if node.name in stopNames:
self.parser.phase.processEndTag(
impliedTagToken(node.name, "EndTag"))
break
if (node.nameTuple in specialElements and
node.name not in ("address", "div", "p")):
break
if self.tree.elementInScope("p", variant="button"):
self.parser.phase.processEndTag(
impliedTagToken("p", "EndTag"))
self.tree.insertElement(token)
def startTagPlaintext(self, token):
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
self.tree.insertElement(token)
self.parser.tokenizer.state = self.parser.tokenizer.plaintextState
def startTagHeading(self, token):
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
if self.tree.openElements[-1].name in headingElements:
self.parser.parseError("unexpected-start-tag", {"name": token["name"]})
self.tree.openElements.pop()
self.tree.insertElement(token)
def startTagA(self, token):
afeAElement = self.tree.elementInActiveFormattingElements("a")
if afeAElement:
self.parser.parseError("unexpected-start-tag-implies-end-tag",
{"startName": "a", "endName": "a"})
self.endTagFormatting(impliedTagToken("a"))
if afeAElement in self.tree.openElements:
self.tree.openElements.remove(afeAElement)
if afeAElement in self.tree.activeFormattingElements:
self.tree.activeFormattingElements.remove(afeAElement)
self.tree.reconstructActiveFormattingElements()
self.addFormattingElement(token)
def startTagFormatting(self, token):
self.tree.reconstructActiveFormattingElements()
self.addFormattingElement(token)
def startTagNobr(self, token):
self.tree.reconstructActiveFormattingElements()
if self.tree.elementInScope("nobr"):
self.parser.parseError("unexpected-start-tag-implies-end-tag",
{"startName": "nobr", "endName": "nobr"})
self.processEndTag(impliedTagToken("nobr"))
# XXX Need tests that trigger the following
self.tree.reconstructActiveFormattingElements()
self.addFormattingElement(token)
def startTagButton(self, token):
if self.tree.elementInScope("button"):
self.parser.parseError("unexpected-start-tag-implies-end-tag",
{"startName": "button", "endName": "button"})
self.processEndTag(impliedTagToken("button"))
return token
else:
self.tree.reconstructActiveFormattingElements()
self.tree.insertElement(token)
self.parser.framesetOK = False
def startTagAppletMarqueeObject(self, token):
self.tree.reconstructActiveFormattingElements()
self.tree.insertElement(token)
self.tree.activeFormattingElements.append(Marker)
self.parser.framesetOK = False
def startTagXmp(self, token):
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
self.tree.reconstructActiveFormattingElements()
self.parser.framesetOK = False
self.parser.parseRCDataRawtext(token, "RAWTEXT")
def startTagTable(self, token):
if self.parser.compatMode != "quirks":
if self.tree.elementInScope("p", variant="button"):
self.processEndTag(impliedTagToken("p"))
self.tree.insertElement(token)
self.parser.framesetOK = False
self.parser.phase = self.parser.phases["inTable"]
def startTagVoidFormatting(self, token):
self.tree.reconstructActiveFormattingElements()
self.tree.insertElement(token)
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
self.parser.framesetOK = False
def startTagInput(self, token):
framesetOK = self.parser.framesetOK
self.startTagVoidFormatting(token)
if ("type" in token["data"] and
token["data"]["type"].translate(asciiUpper2Lower) == "hidden"):
# input type=hidden doesn't change framesetOK
self.parser.framesetOK = framesetOK
def startTagParamSource(self, token):
self.tree.insertElement(token)
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
def startTagHr(self, token):
if self.tree.elementInScope("p", variant="button"):
self.endTagP(impliedTagToken("p"))
self.tree.insertElement(token)
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
self.parser.framesetOK = False
def startTagImage(self, token):
# No really...
self.parser.parseError("unexpected-start-tag-treated-as",
{"originalName": "image", "newName": "img"})
self.processStartTag(impliedTagToken("img", "StartTag",
attributes=token["data"],
selfClosing=token["selfClosing"]))
def startTagIsIndex(self, token):
self.parser.parseError("deprecated-tag", {"name": "isindex"})
if self.tree.formPointer:
return
form_attrs = {}
if "action" in token["data"]:
form_attrs["action"] = token["data"]["action"]
self.processStartTag(impliedTagToken("form", "StartTag",
attributes=form_attrs))
self.processStartTag(impliedTagToken("hr", "StartTag"))
self.processStartTag(impliedTagToken("label", "StartTag"))
# XXX Localization ...
if "prompt" in token["data"]:
prompt = token["data"]["prompt"]
else:
prompt = "This is a searchable index. Enter search keywords: "
self.processCharacters(
{"type": tokenTypes["Characters"], "data": prompt})
attributes = token["data"].copy()
if "action" in attributes:
del attributes["action"]
if "prompt" in attributes:
del attributes["prompt"]
attributes["name"] = "isindex"
self.processStartTag(impliedTagToken("input", "StartTag",
attributes=attributes,
selfClosing=
token["selfClosing"]))
self.processEndTag(impliedTagToken("label"))
self.processStartTag(impliedTagToken("hr", "StartTag"))
self.processEndTag(impliedTagToken("form"))
def startTagTextarea(self, token):
self.tree.insertElement(token)
self.parser.tokenizer.state = self.parser.tokenizer.rcdataState
self.processSpaceCharacters = self.processSpaceCharactersDropNewline
self.parser.framesetOK = False
def startTagIFrame(self, token):
self.parser.framesetOK = False
self.startTagRawtext(token)
def startTagRawtext(self, token):
"""iframe, noembed noframes, noscript(if scripting enabled)"""
self.parser.parseRCDataRawtext(token, "RAWTEXT")
def startTagOpt(self, token):
if self.tree.openElements[-1].name == "option":
self.parser.phase.processEndTag(impliedTagToken("option"))
self.tree.reconstructActiveFormattingElements()
self.parser.tree.insertElement(token)
def startTagSelect(self, token):
self.tree.reconstructActiveFormattingElements()
self.tree.insertElement(token)
self.parser.framesetOK = False
if self.parser.phase in (self.parser.phases["inTable"],
self.parser.phases["inCaption"],
self.parser.phases["inColumnGroup"],
self.parser.phases["inTableBody"],
self.parser.phases["inRow"],
self.parser.phases["inCell"]):
self.parser.phase = self.parser.phases["inSelectInTable"]
else:
self.parser.phase = self.parser.phases["inSelect"]
def startTagRpRt(self, token):
if self.tree.elementInScope("ruby"):
self.tree.generateImpliedEndTags()
if self.tree.openElements[-1].name != "ruby":
self.parser.parseError()
self.tree.insertElement(token)
def startTagMath(self, token):
self.tree.reconstructActiveFormattingElements()
self.parser.adjustMathMLAttributes(token)
self.parser.adjustForeignAttributes(token)
token["namespace"] = namespaces["mathml"]
self.tree.insertElement(token)
# Need to get the parse error right for the case where the token
# has a namespace not equal to the xmlns attribute
if token["selfClosing"]:
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
def startTagSvg(self, token):
self.tree.reconstructActiveFormattingElements()
self.parser.adjustSVGAttributes(token)
self.parser.adjustForeignAttributes(token)
token["namespace"] = namespaces["svg"]
self.tree.insertElement(token)
# Need to get the parse error right for the case where the token
# has a namespace not equal to the xmlns attribute
if token["selfClosing"]:
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
def startTagMisplaced(self, token):
""" Elements that should be children of other elements that have a
different insertion mode; here they are ignored
"caption", "col", "colgroup", "frame", "frameset", "head",
"option", "optgroup", "tbody", "td", "tfoot", "th", "thead",
"tr", "noscript"
"""
self.parser.parseError("unexpected-start-tag-ignored", {"name": token["name"]})
def startTagOther(self, token):
self.tree.reconstructActiveFormattingElements()
self.tree.insertElement(token)
def endTagP(self, token):
if not self.tree.elementInScope("p", variant="button"):
self.startTagCloseP(impliedTagToken("p", "StartTag"))
self.parser.parseError("unexpected-end-tag", {"name": "p"})
self.endTagP(impliedTagToken("p", "EndTag"))
else:
self.tree.generateImpliedEndTags("p")
if self.tree.openElements[-1].name != "p":
self.parser.parseError("unexpected-end-tag", {"name": "p"})
node = self.tree.openElements.pop()
while node.name != "p":
node = self.tree.openElements.pop()
def endTagBody(self, token):
if not self.tree.elementInScope("body"):
self.parser.parseError()
return
elif self.tree.openElements[-1].name != "body":
for node in self.tree.openElements[2:]:
if node.name not in frozenset(("dd", "dt", "li", "optgroup",
"option", "p", "rp", "rt",
"tbody", "td", "tfoot",
"th", "thead", "tr", "body",
"html")):
# Not sure this is the correct name for the parse error
self.parser.parseError(
"expected-one-end-tag-but-got-another",
{"expectedName": "body", "gotName": node.name})
break
self.parser.phase = self.parser.phases["afterBody"]
def endTagHtml(self, token):
# We repeat the test for the body end tag token being ignored here
if self.tree.elementInScope("body"):
self.endTagBody(impliedTagToken("body"))
return token
def endTagBlock(self, token):
# Put us back in the right whitespace handling mode
if token["name"] == "pre":
self.processSpaceCharacters = self.processSpaceCharactersNonPre
inScope = self.tree.elementInScope(token["name"])
if inScope:
self.tree.generateImpliedEndTags()
if self.tree.openElements[-1].name != token["name"]:
self.parser.parseError("end-tag-too-early", {"name": token["name"]})
if inScope:
node = self.tree.openElements.pop()
while node.name != token["name"]:
node = self.tree.openElements.pop()
def endTagForm(self, token):
node = self.tree.formPointer
self.tree.formPointer = None
if node is None or not self.tree.elementInScope(node):
self.parser.parseError("unexpected-end-tag",
{"name": "form"})
else:
self.tree.generateImpliedEndTags()
if self.tree.openElements[-1] != node:
self.parser.parseError("end-tag-too-early-ignored",
{"name": "form"})
self.tree.openElements.remove(node)
def endTagListItem(self, token):
if token["name"] == "li":
variant = "list"
else:
variant = None
if not self.tree.elementInScope(token["name"], variant=variant):
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
else:
self.tree.generateImpliedEndTags(exclude=token["name"])
if self.tree.openElements[-1].name != token["name"]:
self.parser.parseError(
"end-tag-too-early",
{"name": token["name"]})
node = self.tree.openElements.pop()
while node.name != token["name"]:
node = self.tree.openElements.pop()
def endTagHeading(self, token):
for item in headingElements:
if self.tree.elementInScope(item):
self.tree.generateImpliedEndTags()
break
if self.tree.openElements[-1].name != token["name"]:
self.parser.parseError("end-tag-too-early", {"name": token["name"]})
for item in headingElements:
if self.tree.elementInScope(item):
item = self.tree.openElements.pop()
while item.name not in headingElements:
item = self.tree.openElements.pop()
break
def endTagFormatting(self, token):
"""The much-feared adoption agency algorithm"""
# http://svn.whatwg.org/webapps/complete.html#adoptionAgency revision 7867
# XXX Better parseError messages appreciated.
# Step 1
outerLoopCounter = 0
# Step 2
while outerLoopCounter < 8:
# Step 3
outerLoopCounter += 1
# Step 4:
# Let the formatting element be the last element in
# the list of active formatting elements that:
# - is between the end of the list and the last scope
# marker in the list, if any, or the start of the list
# otherwise, and
# - has the same tag name as the token.
formattingElement = self.tree.elementInActiveFormattingElements(
token["name"])
if (not formattingElement or
(formattingElement in self.tree.openElements and
not self.tree.elementInScope(formattingElement.name))):
# If there is no such node, then abort these steps
# and instead act as described in the "any other
# end tag" entry below.
self.endTagOther(token)
return
# Otherwise, if there is such a node, but that node is
# not in the stack of open elements, then this is a
# parse error; remove the element from the list, and
# abort these steps.
elif formattingElement not in self.tree.openElements:
self.parser.parseError("adoption-agency-1.2", {"name": token["name"]})
self.tree.activeFormattingElements.remove(formattingElement)
return
# Otherwise, if there is such a node, and that node is
# also in the stack of open elements, but the element
# is not in scope, then this is a parse error; ignore
# the token, and abort these steps.
elif not self.tree.elementInScope(formattingElement.name):
self.parser.parseError("adoption-agency-4.4", {"name": token["name"]})
return
# Otherwise, there is a formatting element and that
# element is in the stack and is in scope. If the
# element is not the current node, this is a parse
# error. In any case, proceed with the algorithm as
# written in the following steps.
else:
if formattingElement != self.tree.openElements[-1]:
self.parser.parseError("adoption-agency-1.3", {"name": token["name"]})
# Step 5:
# Let the furthest block be the topmost node in the
# stack of open elements that is lower in the stack
# than the formatting element, and is an element in
# the special category. There might not be one.
afeIndex = self.tree.openElements.index(formattingElement)
furthestBlock = None
for element in self.tree.openElements[afeIndex:]:
if element.nameTuple in specialElements:
furthestBlock = element
break
# Step 6:
# If there is no furthest block, then the UA must
# first pop all the nodes from the bottom of the stack
# of open elements, from the current node up to and
# including the formatting element, then remove the
# formatting element from the list of active
# formatting elements, and finally abort these steps.
if furthestBlock is None:
element = self.tree.openElements.pop()
while element != formattingElement:
element = self.tree.openElements.pop()
self.tree.activeFormattingElements.remove(element)
return
# Step 7
commonAncestor = self.tree.openElements[afeIndex - 1]
# Step 8:
# The bookmark is supposed to help us identify where to reinsert
# nodes in step 15. We have to ensure that we reinsert nodes after
# the node before the active formatting element. Note the bookmark
# can move in step 9.7
bookmark = self.tree.activeFormattingElements.index(formattingElement)
# Step 9
lastNode = node = furthestBlock
innerLoopCounter = 0
index = self.tree.openElements.index(node)
while innerLoopCounter < 3:
innerLoopCounter += 1
# Node is element before node in open elements
index -= 1
node = self.tree.openElements[index]
if node not in self.tree.activeFormattingElements:
self.tree.openElements.remove(node)
continue
# Step 9.6
if node == formattingElement:
break
# Step 9.7
if lastNode == furthestBlock:
bookmark = self.tree.activeFormattingElements.index(node) + 1
# Step 9.8
clone = node.cloneNode()
# Replace node with clone
self.tree.activeFormattingElements[
self.tree.activeFormattingElements.index(node)] = clone
self.tree.openElements[
self.tree.openElements.index(node)] = clone
node = clone
# Step 9.9
# Remove lastNode from its parents, if any
if lastNode.parent:
lastNode.parent.removeChild(lastNode)
node.appendChild(lastNode)
# Step 9.10
lastNode = node
# Step 10
# Foster parent lastNode if commonAncestor is a
# table, tbody, tfoot, thead, or tr we need to foster
# parent the lastNode
if lastNode.parent:
lastNode.parent.removeChild(lastNode)
if commonAncestor.name in frozenset(("table", "tbody", "tfoot", "thead", "tr")):
parent, insertBefore = self.tree.getTableMisnestedNodePosition()
parent.insertBefore(lastNode, insertBefore)
else:
commonAncestor.appendChild(lastNode)
# Step 11
clone = formattingElement.cloneNode()
# Step 12
furthestBlock.reparentChildren(clone)
# Step 13
furthestBlock.appendChild(clone)
# Step 14
self.tree.activeFormattingElements.remove(formattingElement)
self.tree.activeFormattingElements.insert(bookmark, clone)
# Step 15
self.tree.openElements.remove(formattingElement)
self.tree.openElements.insert(
self.tree.openElements.index(furthestBlock) + 1, clone)
def endTagAppletMarqueeObject(self, token):
if self.tree.elementInScope(token["name"]):
self.tree.generateImpliedEndTags()
if self.tree.openElements[-1].name != token["name"]:
self.parser.parseError("end-tag-too-early", {"name": token["name"]})
if self.tree.elementInScope(token["name"]):
element = self.tree.openElements.pop()
while element.name != token["name"]:
element = self.tree.openElements.pop()
self.tree.clearActiveFormattingElements()
def endTagBr(self, token):
self.parser.parseError("unexpected-end-tag-treated-as",
{"originalName": "br", "newName": "br element"})
self.tree.reconstructActiveFormattingElements()
self.tree.insertElement(impliedTagToken("br", "StartTag"))
self.tree.openElements.pop()
def endTagOther(self, token):
for node in self.tree.openElements[::-1]:
if node.name == token["name"]:
self.tree.generateImpliedEndTags(exclude=token["name"])
if self.tree.openElements[-1].name != token["name"]:
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
while self.tree.openElements.pop() != node:
pass
break
else:
if node.nameTuple in specialElements:
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
break
class TextPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("script", self.endTagScript)])
self.endTagHandler.default = self.endTagOther
def processCharacters(self, token):
self.tree.insertText(token["data"])
def processEOF(self):
self.parser.parseError("expected-named-closing-tag-but-got-eof",
{"name": self.tree.openElements[-1].name})
self.tree.openElements.pop()
self.parser.phase = self.parser.originalPhase
return True
def startTagOther(self, token):
assert False, "Tried to process start tag %s in RCDATA/RAWTEXT mode" % token['name']
def endTagScript(self, token):
node = self.tree.openElements.pop()
assert node.name == "script"
self.parser.phase = self.parser.originalPhase
# The rest of this method is all stuff that only happens if
# document.write works
def endTagOther(self, token):
self.tree.openElements.pop()
self.parser.phase = self.parser.originalPhase
class InTablePhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-table
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("caption", self.startTagCaption),
("colgroup", self.startTagColgroup),
("col", self.startTagCol),
(("tbody", "tfoot", "thead"), self.startTagRowGroup),
(("td", "th", "tr"), self.startTagImplyTbody),
("table", self.startTagTable),
(("style", "script"), self.startTagStyleScript),
("input", self.startTagInput),
("form", self.startTagForm)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("table", self.endTagTable),
(("body", "caption", "col", "colgroup", "html", "tbody", "td",
"tfoot", "th", "thead", "tr"), self.endTagIgnore)
])
self.endTagHandler.default = self.endTagOther
# helper methods
def clearStackToTableContext(self):
# "clear the stack back to a table context"
while self.tree.openElements[-1].name not in ("table", "html"):
# self.parser.parseError("unexpected-implied-end-tag-in-table",
# {"name": self.tree.openElements[-1].name})
self.tree.openElements.pop()
# When the current node is <html> it's an innerHTML case
# processing methods
def processEOF(self):
if self.tree.openElements[-1].name != "html":
self.parser.parseError("eof-in-table")
else:
assert self.parser.innerHTML
# Stop parsing
def processSpaceCharacters(self, token):
originalPhase = self.parser.phase
self.parser.phase = self.parser.phases["inTableText"]
self.parser.phase.originalPhase = originalPhase
self.parser.phase.processSpaceCharacters(token)
def processCharacters(self, token):
originalPhase = self.parser.phase
self.parser.phase = self.parser.phases["inTableText"]
self.parser.phase.originalPhase = originalPhase
self.parser.phase.processCharacters(token)
def insertText(self, token):
# If we get here there must be at least one non-whitespace character
# Do the table magic!
self.tree.insertFromTable = True
self.parser.phases["inBody"].processCharacters(token)
self.tree.insertFromTable = False
def startTagCaption(self, token):
self.clearStackToTableContext()
self.tree.activeFormattingElements.append(Marker)
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inCaption"]
def startTagColgroup(self, token):
self.clearStackToTableContext()
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inColumnGroup"]
def startTagCol(self, token):
self.startTagColgroup(impliedTagToken("colgroup", "StartTag"))
return token
def startTagRowGroup(self, token):
self.clearStackToTableContext()
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inTableBody"]
def startTagImplyTbody(self, token):
self.startTagRowGroup(impliedTagToken("tbody", "StartTag"))
return token
def startTagTable(self, token):
self.parser.parseError("unexpected-start-tag-implies-end-tag",
{"startName": "table", "endName": "table"})
self.parser.phase.processEndTag(impliedTagToken("table"))
if not self.parser.innerHTML:
return token
def startTagStyleScript(self, token):
return self.parser.phases["inHead"].processStartTag(token)
def startTagInput(self, token):
if ("type" in token["data"] and
token["data"]["type"].translate(asciiUpper2Lower) == "hidden"):
self.parser.parseError("unexpected-hidden-input-in-table")
self.tree.insertElement(token)
# XXX associate with form
self.tree.openElements.pop()
else:
self.startTagOther(token)
def startTagForm(self, token):
self.parser.parseError("unexpected-form-in-table")
if self.tree.formPointer is None:
self.tree.insertElement(token)
self.tree.formPointer = self.tree.openElements[-1]
self.tree.openElements.pop()
def startTagOther(self, token):
self.parser.parseError("unexpected-start-tag-implies-table-voodoo", {"name": token["name"]})
# Do the table magic!
self.tree.insertFromTable = True
self.parser.phases["inBody"].processStartTag(token)
self.tree.insertFromTable = False
def endTagTable(self, token):
if self.tree.elementInScope("table", variant="table"):
self.tree.generateImpliedEndTags()
if self.tree.openElements[-1].name != "table":
self.parser.parseError("end-tag-too-early-named",
{"gotName": "table",
"expectedName": self.tree.openElements[-1].name})
while self.tree.openElements[-1].name != "table":
self.tree.openElements.pop()
self.tree.openElements.pop()
self.parser.resetInsertionMode()
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def endTagIgnore(self, token):
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag-implies-table-voodoo", {"name": token["name"]})
# Do the table magic!
self.tree.insertFromTable = True
self.parser.phases["inBody"].processEndTag(token)
self.tree.insertFromTable = False
class InTableTextPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.originalPhase = None
self.characterTokens = []
def flushCharacters(self):
data = "".join([item["data"] for item in self.characterTokens])
if any([item not in spaceCharacters for item in data]):
token = {"type": tokenTypes["Characters"], "data": data}
self.parser.phases["inTable"].insertText(token)
elif data:
self.tree.insertText(data)
self.characterTokens = []
def processComment(self, token):
self.flushCharacters()
self.parser.phase = self.originalPhase
return token
def processEOF(self):
self.flushCharacters()
self.parser.phase = self.originalPhase
return True
def processCharacters(self, token):
if token["data"] == "\u0000":
return
self.characterTokens.append(token)
def processSpaceCharacters(self, token):
# pretty sure we should never reach here
self.characterTokens.append(token)
# assert False
def processStartTag(self, token):
self.flushCharacters()
self.parser.phase = self.originalPhase
return token
def processEndTag(self, token):
self.flushCharacters()
self.parser.phase = self.originalPhase
return token
class InCaptionPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-caption
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
(("caption", "col", "colgroup", "tbody", "td", "tfoot", "th",
"thead", "tr"), self.startTagTableElement)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("caption", self.endTagCaption),
("table", self.endTagTable),
(("body", "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
"thead", "tr"), self.endTagIgnore)
])
self.endTagHandler.default = self.endTagOther
def ignoreEndTagCaption(self):
return not self.tree.elementInScope("caption", variant="table")
def processEOF(self):
self.parser.phases["inBody"].processEOF()
def processCharacters(self, token):
return self.parser.phases["inBody"].processCharacters(token)
def startTagTableElement(self, token):
self.parser.parseError()
# XXX Have to duplicate logic here to find out if the tag is ignored
ignoreEndTag = self.ignoreEndTagCaption()
self.parser.phase.processEndTag(impliedTagToken("caption"))
if not ignoreEndTag:
return token
def startTagOther(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def endTagCaption(self, token):
if not self.ignoreEndTagCaption():
# AT this code is quite similar to endTagTable in "InTable"
self.tree.generateImpliedEndTags()
if self.tree.openElements[-1].name != "caption":
self.parser.parseError("expected-one-end-tag-but-got-another",
{"gotName": "caption",
"expectedName": self.tree.openElements[-1].name})
while self.tree.openElements[-1].name != "caption":
self.tree.openElements.pop()
self.tree.openElements.pop()
self.tree.clearActiveFormattingElements()
self.parser.phase = self.parser.phases["inTable"]
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def endTagTable(self, token):
self.parser.parseError()
ignoreEndTag = self.ignoreEndTagCaption()
self.parser.phase.processEndTag(impliedTagToken("caption"))
if not ignoreEndTag:
return token
def endTagIgnore(self, token):
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
def endTagOther(self, token):
return self.parser.phases["inBody"].processEndTag(token)
class InColumnGroupPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-column
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("col", self.startTagCol)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("colgroup", self.endTagColgroup),
("col", self.endTagCol)
])
self.endTagHandler.default = self.endTagOther
def ignoreEndTagColgroup(self):
return self.tree.openElements[-1].name == "html"
def processEOF(self):
if self.tree.openElements[-1].name == "html":
assert self.parser.innerHTML
return
else:
ignoreEndTag = self.ignoreEndTagColgroup()
self.endTagColgroup(impliedTagToken("colgroup"))
if not ignoreEndTag:
return True
def processCharacters(self, token):
ignoreEndTag = self.ignoreEndTagColgroup()
self.endTagColgroup(impliedTagToken("colgroup"))
if not ignoreEndTag:
return token
def startTagCol(self, token):
self.tree.insertElement(token)
self.tree.openElements.pop()
def startTagOther(self, token):
ignoreEndTag = self.ignoreEndTagColgroup()
self.endTagColgroup(impliedTagToken("colgroup"))
if not ignoreEndTag:
return token
def endTagColgroup(self, token):
if self.ignoreEndTagColgroup():
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
else:
self.tree.openElements.pop()
self.parser.phase = self.parser.phases["inTable"]
def endTagCol(self, token):
self.parser.parseError("no-end-tag", {"name": "col"})
def endTagOther(self, token):
ignoreEndTag = self.ignoreEndTagColgroup()
self.endTagColgroup(impliedTagToken("colgroup"))
if not ignoreEndTag:
return token
class InTableBodyPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-table0
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("tr", self.startTagTr),
(("td", "th"), self.startTagTableCell),
(("caption", "col", "colgroup", "tbody", "tfoot", "thead"),
self.startTagTableOther)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
(("tbody", "tfoot", "thead"), self.endTagTableRowGroup),
("table", self.endTagTable),
(("body", "caption", "col", "colgroup", "html", "td", "th",
"tr"), self.endTagIgnore)
])
self.endTagHandler.default = self.endTagOther
# helper methods
def clearStackToTableBodyContext(self):
while self.tree.openElements[-1].name not in ("tbody", "tfoot",
"thead", "html"):
# self.parser.parseError("unexpected-implied-end-tag-in-table",
# {"name": self.tree.openElements[-1].name})
self.tree.openElements.pop()
if self.tree.openElements[-1].name == "html":
assert self.parser.innerHTML
# the rest
def processEOF(self):
self.parser.phases["inTable"].processEOF()
def processSpaceCharacters(self, token):
return self.parser.phases["inTable"].processSpaceCharacters(token)
def processCharacters(self, token):
return self.parser.phases["inTable"].processCharacters(token)
def startTagTr(self, token):
self.clearStackToTableBodyContext()
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inRow"]
def startTagTableCell(self, token):
self.parser.parseError("unexpected-cell-in-table-body",
{"name": token["name"]})
self.startTagTr(impliedTagToken("tr", "StartTag"))
return token
def startTagTableOther(self, token):
# XXX AT Any ideas on how to share this with endTagTable?
if (self.tree.elementInScope("tbody", variant="table") or
self.tree.elementInScope("thead", variant="table") or
self.tree.elementInScope("tfoot", variant="table")):
self.clearStackToTableBodyContext()
self.endTagTableRowGroup(
impliedTagToken(self.tree.openElements[-1].name))
return token
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def startTagOther(self, token):
return self.parser.phases["inTable"].processStartTag(token)
def endTagTableRowGroup(self, token):
if self.tree.elementInScope(token["name"], variant="table"):
self.clearStackToTableBodyContext()
self.tree.openElements.pop()
self.parser.phase = self.parser.phases["inTable"]
else:
self.parser.parseError("unexpected-end-tag-in-table-body",
{"name": token["name"]})
def endTagTable(self, token):
if (self.tree.elementInScope("tbody", variant="table") or
self.tree.elementInScope("thead", variant="table") or
self.tree.elementInScope("tfoot", variant="table")):
self.clearStackToTableBodyContext()
self.endTagTableRowGroup(
impliedTagToken(self.tree.openElements[-1].name))
return token
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def endTagIgnore(self, token):
self.parser.parseError("unexpected-end-tag-in-table-body",
{"name": token["name"]})
def endTagOther(self, token):
return self.parser.phases["inTable"].processEndTag(token)
class InRowPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-row
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
(("td", "th"), self.startTagTableCell),
(("caption", "col", "colgroup", "tbody", "tfoot", "thead",
"tr"), self.startTagTableOther)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("tr", self.endTagTr),
("table", self.endTagTable),
(("tbody", "tfoot", "thead"), self.endTagTableRowGroup),
(("body", "caption", "col", "colgroup", "html", "td", "th"),
self.endTagIgnore)
])
self.endTagHandler.default = self.endTagOther
# helper methods (XXX unify this with other table helper methods)
def clearStackToTableRowContext(self):
while self.tree.openElements[-1].name not in ("tr", "html"):
self.parser.parseError("unexpected-implied-end-tag-in-table-row",
{"name": self.tree.openElements[-1].name})
self.tree.openElements.pop()
def ignoreEndTagTr(self):
return not self.tree.elementInScope("tr", variant="table")
# the rest
def processEOF(self):
self.parser.phases["inTable"].processEOF()
def processSpaceCharacters(self, token):
return self.parser.phases["inTable"].processSpaceCharacters(token)
def processCharacters(self, token):
return self.parser.phases["inTable"].processCharacters(token)
def startTagTableCell(self, token):
self.clearStackToTableRowContext()
self.tree.insertElement(token)
self.parser.phase = self.parser.phases["inCell"]
self.tree.activeFormattingElements.append(Marker)
def startTagTableOther(self, token):
ignoreEndTag = self.ignoreEndTagTr()
self.endTagTr(impliedTagToken("tr"))
# XXX how are we sure it's always ignored in the innerHTML case?
if not ignoreEndTag:
return token
def startTagOther(self, token):
return self.parser.phases["inTable"].processStartTag(token)
def endTagTr(self, token):
if not self.ignoreEndTagTr():
self.clearStackToTableRowContext()
self.tree.openElements.pop()
self.parser.phase = self.parser.phases["inTableBody"]
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def endTagTable(self, token):
ignoreEndTag = self.ignoreEndTagTr()
self.endTagTr(impliedTagToken("tr"))
# Reprocess the current tag if the tr end tag was not ignored
# XXX how are we sure it's always ignored in the innerHTML case?
if not ignoreEndTag:
return token
def endTagTableRowGroup(self, token):
if self.tree.elementInScope(token["name"], variant="table"):
self.endTagTr(impliedTagToken("tr"))
return token
else:
self.parser.parseError()
def endTagIgnore(self, token):
self.parser.parseError("unexpected-end-tag-in-table-row",
{"name": token["name"]})
def endTagOther(self, token):
return self.parser.phases["inTable"].processEndTag(token)
class InCellPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-cell
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
(("caption", "col", "colgroup", "tbody", "td", "tfoot", "th",
"thead", "tr"), self.startTagTableOther)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
(("td", "th"), self.endTagTableCell),
(("body", "caption", "col", "colgroup", "html"), self.endTagIgnore),
(("table", "tbody", "tfoot", "thead", "tr"), self.endTagImply)
])
self.endTagHandler.default = self.endTagOther
# helper
def closeCell(self):
if self.tree.elementInScope("td", variant="table"):
self.endTagTableCell(impliedTagToken("td"))
elif self.tree.elementInScope("th", variant="table"):
self.endTagTableCell(impliedTagToken("th"))
# the rest
def processEOF(self):
self.parser.phases["inBody"].processEOF()
def processCharacters(self, token):
return self.parser.phases["inBody"].processCharacters(token)
def startTagTableOther(self, token):
if (self.tree.elementInScope("td", variant="table") or
self.tree.elementInScope("th", variant="table")):
self.closeCell()
return token
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def startTagOther(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def endTagTableCell(self, token):
if self.tree.elementInScope(token["name"], variant="table"):
self.tree.generateImpliedEndTags(token["name"])
if self.tree.openElements[-1].name != token["name"]:
self.parser.parseError("unexpected-cell-end-tag",
{"name": token["name"]})
while True:
node = self.tree.openElements.pop()
if node.name == token["name"]:
break
else:
self.tree.openElements.pop()
self.tree.clearActiveFormattingElements()
self.parser.phase = self.parser.phases["inRow"]
else:
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
def endTagIgnore(self, token):
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
def endTagImply(self, token):
if self.tree.elementInScope(token["name"], variant="table"):
self.closeCell()
return token
else:
# sometimes innerHTML case
self.parser.parseError()
def endTagOther(self, token):
return self.parser.phases["inBody"].processEndTag(token)
class InSelectPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("option", self.startTagOption),
("optgroup", self.startTagOptgroup),
("select", self.startTagSelect),
(("input", "keygen", "textarea"), self.startTagInput),
("script", self.startTagScript)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("option", self.endTagOption),
("optgroup", self.endTagOptgroup),
("select", self.endTagSelect)
])
self.endTagHandler.default = self.endTagOther
# http://www.whatwg.org/specs/web-apps/current-work/#in-select
def processEOF(self):
if self.tree.openElements[-1].name != "html":
self.parser.parseError("eof-in-select")
else:
assert self.parser.innerHTML
def processCharacters(self, token):
if token["data"] == "\u0000":
return
self.tree.insertText(token["data"])
def startTagOption(self, token):
# We need to imply </option> if <option> is the current node.
if self.tree.openElements[-1].name == "option":
self.tree.openElements.pop()
self.tree.insertElement(token)
def startTagOptgroup(self, token):
if self.tree.openElements[-1].name == "option":
self.tree.openElements.pop()
if self.tree.openElements[-1].name == "optgroup":
self.tree.openElements.pop()
self.tree.insertElement(token)
def startTagSelect(self, token):
self.parser.parseError("unexpected-select-in-select")
self.endTagSelect(impliedTagToken("select"))
def startTagInput(self, token):
self.parser.parseError("unexpected-input-in-select")
if self.tree.elementInScope("select", variant="select"):
self.endTagSelect(impliedTagToken("select"))
return token
else:
assert self.parser.innerHTML
def startTagScript(self, token):
return self.parser.phases["inHead"].processStartTag(token)
def startTagOther(self, token):
self.parser.parseError("unexpected-start-tag-in-select",
{"name": token["name"]})
def endTagOption(self, token):
if self.tree.openElements[-1].name == "option":
self.tree.openElements.pop()
else:
self.parser.parseError("unexpected-end-tag-in-select",
{"name": "option"})
def endTagOptgroup(self, token):
# </optgroup> implicitly closes <option>
if (self.tree.openElements[-1].name == "option" and
self.tree.openElements[-2].name == "optgroup"):
self.tree.openElements.pop()
# It also closes </optgroup>
if self.tree.openElements[-1].name == "optgroup":
self.tree.openElements.pop()
# But nothing else
else:
self.parser.parseError("unexpected-end-tag-in-select",
{"name": "optgroup"})
def endTagSelect(self, token):
if self.tree.elementInScope("select", variant="select"):
node = self.tree.openElements.pop()
while node.name != "select":
node = self.tree.openElements.pop()
self.parser.resetInsertionMode()
else:
# innerHTML case
assert self.parser.innerHTML
self.parser.parseError()
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag-in-select",
{"name": token["name"]})
class InSelectInTablePhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
(("caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"),
self.startTagTable)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
(("caption", "table", "tbody", "tfoot", "thead", "tr", "td", "th"),
self.endTagTable)
])
self.endTagHandler.default = self.endTagOther
def processEOF(self):
self.parser.phases["inSelect"].processEOF()
def processCharacters(self, token):
return self.parser.phases["inSelect"].processCharacters(token)
def startTagTable(self, token):
self.parser.parseError("unexpected-table-element-start-tag-in-select-in-table", {"name": token["name"]})
self.endTagOther(impliedTagToken("select"))
return token
def startTagOther(self, token):
return self.parser.phases["inSelect"].processStartTag(token)
def endTagTable(self, token):
self.parser.parseError("unexpected-table-element-end-tag-in-select-in-table", {"name": token["name"]})
if self.tree.elementInScope(token["name"], variant="table"):
self.endTagOther(impliedTagToken("select"))
return token
def endTagOther(self, token):
return self.parser.phases["inSelect"].processEndTag(token)
class InForeignContentPhase(Phase):
breakoutElements = frozenset(["b", "big", "blockquote", "body", "br",
"center", "code", "dd", "div", "dl", "dt",
"em", "embed", "h1", "h2", "h3",
"h4", "h5", "h6", "head", "hr", "i", "img",
"li", "listing", "menu", "meta", "nobr",
"ol", "p", "pre", "ruby", "s", "small",
"span", "strong", "strike", "sub", "sup",
"table", "tt", "u", "ul", "var"])
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
def adjustSVGTagNames(self, token):
replacements = {"altglyph": "altGlyph",
"altglyphdef": "altGlyphDef",
"altglyphitem": "altGlyphItem",
"animatecolor": "animateColor",
"animatemotion": "animateMotion",
"animatetransform": "animateTransform",
"clippath": "clipPath",
"feblend": "feBlend",
"fecolormatrix": "feColorMatrix",
"fecomponenttransfer": "feComponentTransfer",
"fecomposite": "feComposite",
"feconvolvematrix": "feConvolveMatrix",
"fediffuselighting": "feDiffuseLighting",
"fedisplacementmap": "feDisplacementMap",
"fedistantlight": "feDistantLight",
"feflood": "feFlood",
"fefunca": "feFuncA",
"fefuncb": "feFuncB",
"fefuncg": "feFuncG",
"fefuncr": "feFuncR",
"fegaussianblur": "feGaussianBlur",
"feimage": "feImage",
"femerge": "feMerge",
"femergenode": "feMergeNode",
"femorphology": "feMorphology",
"feoffset": "feOffset",
"fepointlight": "fePointLight",
"fespecularlighting": "feSpecularLighting",
"fespotlight": "feSpotLight",
"fetile": "feTile",
"feturbulence": "feTurbulence",
"foreignobject": "foreignObject",
"glyphref": "glyphRef",
"lineargradient": "linearGradient",
"radialgradient": "radialGradient",
"textpath": "textPath"}
if token["name"] in replacements:
token["name"] = replacements[token["name"]]
def processCharacters(self, token):
if token["data"] == "\u0000":
token["data"] = "\uFFFD"
elif (self.parser.framesetOK and
any(char not in spaceCharacters for char in token["data"])):
self.parser.framesetOK = False
Phase.processCharacters(self, token)
def processStartTag(self, token):
currentNode = self.tree.openElements[-1]
if (token["name"] in self.breakoutElements or
(token["name"] == "font" and
set(token["data"].keys()) & set(["color", "face", "size"]))):
self.parser.parseError("unexpected-html-element-in-foreign-content",
{"name": token["name"]})
while (self.tree.openElements[-1].namespace !=
self.tree.defaultNamespace and
not self.parser.isHTMLIntegrationPoint(self.tree.openElements[-1]) and
not self.parser.isMathMLTextIntegrationPoint(self.tree.openElements[-1])):
self.tree.openElements.pop()
return token
else:
if currentNode.namespace == namespaces["mathml"]:
self.parser.adjustMathMLAttributes(token)
elif currentNode.namespace == namespaces["svg"]:
self.adjustSVGTagNames(token)
self.parser.adjustSVGAttributes(token)
self.parser.adjustForeignAttributes(token)
token["namespace"] = currentNode.namespace
self.tree.insertElement(token)
if token["selfClosing"]:
self.tree.openElements.pop()
token["selfClosingAcknowledged"] = True
def processEndTag(self, token):
nodeIndex = len(self.tree.openElements) - 1
node = self.tree.openElements[-1]
if node.name != token["name"]:
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
while True:
if node.name.translate(asciiUpper2Lower) == token["name"]:
# XXX this isn't in the spec but it seems necessary
if self.parser.phase == self.parser.phases["inTableText"]:
self.parser.phase.flushCharacters()
self.parser.phase = self.parser.phase.originalPhase
while self.tree.openElements.pop() != node:
assert self.tree.openElements
new_token = None
break
nodeIndex -= 1
node = self.tree.openElements[nodeIndex]
if node.namespace != self.tree.defaultNamespace:
continue
else:
new_token = self.parser.phase.processEndTag(token)
break
return new_token
class AfterBodyPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([("html", self.endTagHtml)])
self.endTagHandler.default = self.endTagOther
def processEOF(self):
# Stop parsing
pass
def processComment(self, token):
# This is needed because data is to be appended to the <html> element
# here and not to whatever is currently open.
self.tree.insertComment(token, self.tree.openElements[0])
def processCharacters(self, token):
self.parser.parseError("unexpected-char-after-body")
self.parser.phase = self.parser.phases["inBody"]
return token
def startTagHtml(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagOther(self, token):
self.parser.parseError("unexpected-start-tag-after-body",
{"name": token["name"]})
self.parser.phase = self.parser.phases["inBody"]
return token
def endTagHtml(self, name):
if self.parser.innerHTML:
self.parser.parseError("unexpected-end-tag-after-body-innerhtml")
else:
self.parser.phase = self.parser.phases["afterAfterBody"]
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag-after-body",
{"name": token["name"]})
self.parser.phase = self.parser.phases["inBody"]
return token
class InFramesetPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#in-frameset
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("frameset", self.startTagFrameset),
("frame", self.startTagFrame),
("noframes", self.startTagNoframes)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("frameset", self.endTagFrameset)
])
self.endTagHandler.default = self.endTagOther
def processEOF(self):
if self.tree.openElements[-1].name != "html":
self.parser.parseError("eof-in-frameset")
else:
assert self.parser.innerHTML
def processCharacters(self, token):
self.parser.parseError("unexpected-char-in-frameset")
def startTagFrameset(self, token):
self.tree.insertElement(token)
def startTagFrame(self, token):
self.tree.insertElement(token)
self.tree.openElements.pop()
def startTagNoframes(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagOther(self, token):
self.parser.parseError("unexpected-start-tag-in-frameset",
{"name": token["name"]})
def endTagFrameset(self, token):
if self.tree.openElements[-1].name == "html":
# innerHTML case
self.parser.parseError("unexpected-frameset-in-frameset-innerhtml")
else:
self.tree.openElements.pop()
if (not self.parser.innerHTML and
self.tree.openElements[-1].name != "frameset"):
# If we're not in innerHTML mode and the the current node is not a
# "frameset" element (anymore) then switch.
self.parser.phase = self.parser.phases["afterFrameset"]
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag-in-frameset",
{"name": token["name"]})
class AfterFramesetPhase(Phase):
# http://www.whatwg.org/specs/web-apps/current-work/#after3
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("noframes", self.startTagNoframes)
])
self.startTagHandler.default = self.startTagOther
self.endTagHandler = utils.MethodDispatcher([
("html", self.endTagHtml)
])
self.endTagHandler.default = self.endTagOther
def processEOF(self):
# Stop parsing
pass
def processCharacters(self, token):
self.parser.parseError("unexpected-char-after-frameset")
def startTagNoframes(self, token):
return self.parser.phases["inHead"].processStartTag(token)
def startTagOther(self, token):
self.parser.parseError("unexpected-start-tag-after-frameset",
{"name": token["name"]})
def endTagHtml(self, token):
self.parser.phase = self.parser.phases["afterAfterFrameset"]
def endTagOther(self, token):
self.parser.parseError("unexpected-end-tag-after-frameset",
{"name": token["name"]})
class AfterAfterBodyPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml)
])
self.startTagHandler.default = self.startTagOther
def processEOF(self):
pass
def processComment(self, token):
self.tree.insertComment(token, self.tree.document)
def processSpaceCharacters(self, token):
return self.parser.phases["inBody"].processSpaceCharacters(token)
def processCharacters(self, token):
self.parser.parseError("expected-eof-but-got-char")
self.parser.phase = self.parser.phases["inBody"]
return token
def startTagHtml(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagOther(self, token):
self.parser.parseError("expected-eof-but-got-start-tag",
{"name": token["name"]})
self.parser.phase = self.parser.phases["inBody"]
return token
def processEndTag(self, token):
self.parser.parseError("expected-eof-but-got-end-tag",
{"name": token["name"]})
self.parser.phase = self.parser.phases["inBody"]
return token
class AfterAfterFramesetPhase(Phase):
def __init__(self, parser, tree):
Phase.__init__(self, parser, tree)
self.startTagHandler = utils.MethodDispatcher([
("html", self.startTagHtml),
("noframes", self.startTagNoFrames)
])
self.startTagHandler.default = self.startTagOther
def processEOF(self):
pass
def processComment(self, token):
self.tree.insertComment(token, self.tree.document)
def processSpaceCharacters(self, token):
return self.parser.phases["inBody"].processSpaceCharacters(token)
def processCharacters(self, token):
self.parser.parseError("expected-eof-but-got-char")
def startTagHtml(self, token):
return self.parser.phases["inBody"].processStartTag(token)
def startTagNoFrames(self, token):
return self.parser.phases["inHead"].processStartTag(token)
def startTagOther(self, token):
self.parser.parseError("expected-eof-but-got-start-tag",
{"name": token["name"]})
def processEndTag(self, token):
self.parser.parseError("expected-eof-but-got-end-tag",
{"name": token["name"]})
return {
"initial": InitialPhase,
"beforeHtml": BeforeHtmlPhase,
"beforeHead": BeforeHeadPhase,
"inHead": InHeadPhase,
# XXX "inHeadNoscript": InHeadNoScriptPhase,
"afterHead": AfterHeadPhase,
"inBody": InBodyPhase,
"text": TextPhase,
"inTable": InTablePhase,
"inTableText": InTableTextPhase,
"inCaption": InCaptionPhase,
"inColumnGroup": InColumnGroupPhase,
"inTableBody": InTableBodyPhase,
"inRow": InRowPhase,
"inCell": InCellPhase,
"inSelect": InSelectPhase,
"inSelectInTable": InSelectInTablePhase,
"inForeignContent": InForeignContentPhase,
"afterBody": AfterBodyPhase,
"inFrameset": InFramesetPhase,
"afterFrameset": AfterFramesetPhase,
"afterAfterBody": AfterAfterBodyPhase,
"afterAfterFrameset": AfterAfterFramesetPhase,
# XXX after after frameset
}
def impliedTagToken(name, type="EndTag", attributes=None,
selfClosing=False):
if attributes is None:
attributes = {}
return {"type": tokenTypes[type], "name": name, "data": attributes,
"selfClosing": selfClosing}
class ParseError(Exception):
"""Error in parsed document"""
pass
|
bsd-2-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
504,
7305,
14,
9884,
14,
4174,
492,
543,
63,
6577,
199,
199,
646,
2943,
199,
199,
504,
1275,
492,
1324,
1745,
199,
504,
1275,
492,
14803,
199,
199,
504,
1275,
492,
3123,
20968,
199,
504,
1275,
2350,
20968,
423,
1095,
492,
26903,
199,
199,
504,
1275,
492,
3778,
199,
504,
1275,
492,
5262,
199,
504,
1275,
5559,
492,
25431,
12,
13294,
19316,
18,
17846,
199,
504,
1275,
5559,
492,
4539,
6255,
199,
504,
1275,
5559,
492,
16631,
6255,
199,
504,
1275,
5559,
492,
286,
576,
6255,
12,
4819,
576,
6255,
199,
504,
1275,
5559,
492,
10042,
12,
799,
1122,
1726,
12,
10747,
199,
504,
1275,
5559,
492,
3517,
20405,
3428,
6255,
12,
3473,
757,
1872,
20405,
3428,
6255,
421,
199,
318,
2198,
8,
1301,
12,
3123,
5649,
628,
9464,
401,
2644,
29,
403,
12,
881,
3231,
31428,
20446,
29,
549,
304,
272,
408,
4003,
282,
1059,
503,
570,
13,
2930,
909,
1901,
282,
3123,
624,
272,
7070,
275,
3123,
20968,
14,
362,
20437,
8,
2350,
5649,
9,
272,
299,
275,
24581,
8,
5842,
12,
3231,
31428,
20446,
29,
3251,
31428,
20446,
9,
272,
372,
299,
14,
1122,
8,
1301,
12,
2644,
29,
2991,
9,
421,
199,
318,
2198,
11080,
8,
1301,
12,
3970,
628,
3015,
401,
3123,
5649,
628,
9464,
401,
2644,
29,
403,
12,
2116,
3231,
31428,
20446,
29,
549,
304,
272,
7070,
275,
3123,
20968,
14,
362,
20437,
8,
2350,
5649,
9,
272,
299,
275,
24581,
8,
5842,
12,
3231,
31428,
20446,
29,
3251,
31428,
20446,
9,
272,
372,
299,
14,
1122,
11080,
8,
1301,
12,
3970,
29,
3600,
12,
2644,
29,
2991,
9,
421,
199,
318,
1083,
63,
11547,
63,
6577,
8,
1593,
304,
272,
1021,
13966,
269,
972,
8,
466,
304,
267,
347,
636,
1222,
721,
2024,
12,
15876,
12,
9768,
12,
1021,
2141,
304,
288,
367,
2225,
985,
12,
2225,
315,
1021,
2141,
14,
1744,
837,
355,
340,
1228,
8,
3215,
12,
2943,
14,
26371,
304,
490,
2225,
275,
805,
8,
3215,
9,
2234,
1021,
2141,
59,
3215,
985,
61,
275,
2225,
288,
372,
730,
855,
1222,
721,
2024,
12,
15876,
12,
9768,
12,
1021,
2141,
9,
272,
372,
13966,
269,
972,
421,
199,
533,
24581,
8,
785,
304,
272,
408,
4943,
1798,
14,
21687,
282,
3123,
5523,
687,
282,
2547,
402,
334,
19614,
267,
24159,
9,
4163,
624,
339,
347,
636,
826,
721,
277,
12,
3123,
29,
403,
12,
14803,
29,
13771,
14,
4943,
21782,
12,
326,
7478,
29,
797,
12,
3231,
31428,
20446,
29,
549,
12,
3105,
29,
797,
304,
267,
408,
267,
7478,
446,
746,
376,
1919,
1380,
282,
2198,
1125,
365,
14556,
398,
3123,
446,
282,
3123,
5649,
1021,
30350,
314,
730,
402,
3123,
626,
911,
506,
267,
2138,
14,
4779,
4803,
315,
3123,
20968,
883,
506,
13810,
4012,
267,
3517,
21,
773,
14,
2350,
20968,
14,
362,
20437,
8,
2350,
804,
9,
398,
14803,
446,
282,
1021,
626,
6571,
282,
2547,
402,
4645,
370,
314,
3123,
5649,
14,
267,
961,
1443,
506,
8717,
367,
325,
14,
71,
14,
282,
25092,
2282,
1314,
15373,
2005,
3762,
370,
267,
1318,
267,
408,
398,
327,
14771,
376,
1919,
641,
314,
1642,
1125,
14556,
267,
291,
14,
4768,
275,
7478,
398,
340,
3123,
365,
488,
26,
288,
3123,
275,
3123,
20968,
14,
362,
20437,
480,
9464,
531,
267,
291,
14,
2350,
275,
3123,
8,
3251,
31428,
20446,
9,
267,
291,
14,
13771,
63,
533,
275,
14803,
267,
291,
14,
2550,
275,
942,
398,
291,
14,
14236,
275,
1211,
7694,
354,
12,
843,
8,
277,
12,
291,
14,
2350,
430,
367,
536,
12,
843,
315,
1169,
664,
30996,
8,
1757,
680,
1744,
9383,
339,
347,
485,
1122,
8,
277,
12,
2547,
12,
6506,
4943,
29,
797,
12,
3970,
628,
3015,
401,
2049,
2644,
29,
403,
12,
2198,
3396,
29,
549,
12,
675,
1610,
9886,
29,
549,
12,
1011,
958,
304,
398,
291,
14,
26502,
1385,
275,
6506,
4943,
267,
291,
14,
3600,
275,
3970,
267,
291,
14,
13771,
275,
291,
14,
13771,
63,
533,
8,
1745,
12,
2644,
29,
2991,
12,
6343,
2198,
3396,
29,
1122,
3396,
12,
6343,
675,
1610,
9886,
29,
1180,
1610,
9886,
12,
6343,
1798,
29,
277,
12,
1011,
958,
9,
267,
291,
14,
3958,
342,
398,
1830,
715,
26,
288,
862,
26,
355,
291,
14,
973,
7382,
342,
355,
2059,
288,
871,
799,
1122,
1726,
26,
355,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
2350,
14,
3958,
342,
267,
291,
14,
2246,
17697,
275,
756,
267,
291,
14,
2550,
275,
942,
267,
291,
14,
793,
275,
942,
221,
327,
1454,
1202,
543,
3105,
818,
267,
327,
298,
392,
723,
6080,
2,
1182,
298,
14136,
2173,
723,
6080,
2,
1182,
298,
889,
2173,
723,
6080,
2,
267,
291,
14,
5819,
1385,
275,
298,
889,
2173,
723,
6080,
2,
398,
340,
291,
14,
26502,
1385,
26,
288,
291,
14,
26502,
275,
291,
14,
3600,
14,
2325,
342,
953,
340,
291,
14,
26502,
315,
286,
576,
6255,
26,
355,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
1195,
18694,
288,
916,
291,
14,
26502,
315,
4819,
576,
6255,
26,
355,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
1773,
505,
2223,
288,
916,
291,
14,
26502,
508,
283,
17426,
356,
355,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
17426,
2223,
288,
587,
26,
355,
327,
1174,
2575,
365,
666,
1174,
355,
327,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
18694,
355,
986,
288,
291,
14,
6971,
275,
291,
14,
14236,
905,
5182,
12957,
937,
288,
291,
14,
6971,
14,
3176,
12957,
2162,
342,
288,
291,
14,
3958,
607,
4535,
1385,
342,
267,
587,
26,
288,
291,
14,
26502,
275,
756,
288,
291,
14,
6971,
275,
291,
14,
14236,
905,
2747,
937,
398,
291,
14,
2019,
10521,
275,
488,
398,
291,
14,
5182,
8205,
1451,
10521,
275,
488,
398,
291,
14,
27462,
3593,
275,
715,
339,
347,
365,
4943,
20405,
3428,
8,
277,
12,
1819,
304,
267,
340,
334,
2108,
14,
354,
508,
298,
9340,
13,
1652,
2,
436,
355,
1819,
14,
3251,
508,
10747,
905,
27595
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
504,
7305,
14,
9884,
14,
4174,
492,
543,
63,
6577,
199,
199,
646,
2943,
199,
199,
504,
1275,
492,
1324,
1745,
199,
504,
1275,
492,
14803,
199,
199,
504,
1275,
492,
3123,
20968,
199,
504,
1275,
2350,
20968,
423,
1095,
492,
26903,
199,
199,
504,
1275,
492,
3778,
199,
504,
1275,
492,
5262,
199,
504,
1275,
5559,
492,
25431,
12,
13294,
19316,
18,
17846,
199,
504,
1275,
5559,
492,
4539,
6255,
199,
504,
1275,
5559,
492,
16631,
6255,
199,
504,
1275,
5559,
492,
286,
576,
6255,
12,
4819,
576,
6255,
199,
504,
1275,
5559,
492,
10042,
12,
799,
1122,
1726,
12,
10747,
199,
504,
1275,
5559,
492,
3517,
20405,
3428,
6255,
12,
3473,
757,
1872,
20405,
3428,
6255,
421,
199,
318,
2198,
8,
1301,
12,
3123,
5649,
628,
9464,
401,
2644,
29,
403,
12,
881,
3231,
31428,
20446,
29,
549,
304,
272,
408,
4003,
282,
1059,
503,
570,
13,
2930,
909,
1901,
282,
3123,
624,
272,
7070,
275,
3123,
20968,
14,
362,
20437,
8,
2350,
5649,
9,
272,
299,
275,
24581,
8,
5842,
12,
3231,
31428,
20446,
29,
3251,
31428,
20446,
9,
272,
372,
299,
14,
1122,
8,
1301,
12,
2644,
29,
2991,
9,
421,
199,
318,
2198,
11080,
8,
1301,
12,
3970,
628,
3015,
401,
3123,
5649,
628,
9464,
401,
2644,
29,
403,
12,
2116,
3231,
31428,
20446,
29,
549,
304,
272,
7070,
275,
3123,
20968,
14,
362,
20437,
8,
2350,
5649,
9,
272,
299,
275,
24581,
8,
5842,
12,
3231,
31428,
20446,
29,
3251,
31428,
20446,
9,
272,
372,
299,
14,
1122,
11080,
8,
1301,
12,
3970,
29,
3600,
12,
2644,
29,
2991,
9,
421,
199,
318,
1083,
63,
11547,
63,
6577,
8,
1593,
304,
272,
1021,
13966,
269,
972,
8,
466,
304,
267,
347,
636,
1222,
721,
2024,
12,
15876,
12,
9768,
12,
1021,
2141,
304,
288,
367,
2225,
985,
12,
2225,
315,
1021,
2141,
14,
1744,
837,
355,
340,
1228,
8,
3215,
12,
2943,
14,
26371,
304,
490,
2225,
275,
805,
8,
3215,
9,
2234,
1021,
2141,
59,
3215,
985,
61,
275,
2225,
288,
372,
730,
855,
1222,
721,
2024,
12,
15876,
12,
9768,
12,
1021,
2141,
9,
272,
372,
13966,
269,
972,
421,
199,
533,
24581,
8,
785,
304,
272,
408,
4943,
1798,
14,
21687,
282,
3123,
5523,
687,
282,
2547,
402,
334,
19614,
267,
24159,
9,
4163,
624,
339,
347,
636,
826,
721,
277,
12,
3123,
29,
403,
12,
14803,
29,
13771,
14,
4943,
21782,
12,
326,
7478,
29,
797,
12,
3231,
31428,
20446,
29,
549,
12,
3105,
29,
797,
304,
267,
408,
267,
7478,
446,
746,
376,
1919,
1380,
282,
2198,
1125,
365,
14556,
398,
3123,
446,
282,
3123,
5649,
1021,
30350,
314,
730,
402,
3123,
626,
911,
506,
267,
2138,
14,
4779,
4803,
315,
3123,
20968,
883,
506,
13810,
4012,
267,
3517,
21,
773,
14,
2350,
20968,
14,
362,
20437,
8,
2350,
804,
9,
398,
14803,
446,
282,
1021,
626,
6571,
282,
2547,
402,
4645,
370,
314,
3123,
5649,
14,
267,
961,
1443,
506,
8717,
367,
325,
14,
71,
14,
282,
25092,
2282,
1314,
15373,
2005,
3762,
370,
267,
1318,
267,
408,
398,
327,
14771,
376,
1919,
641,
314,
1642,
1125,
14556,
267,
291,
14,
4768,
275,
7478,
398,
340,
3123,
365,
488,
26,
288,
3123,
275,
3123,
20968,
14,
362,
20437,
480,
9464,
531,
267,
291,
14,
2350,
275,
3123,
8,
3251,
31428,
20446,
9,
267,
291,
14,
13771,
63,
533,
275,
14803,
267,
291,
14,
2550,
275,
942,
398,
291,
14,
14236,
275,
1211,
7694,
354,
12,
843,
8,
277,
12,
291,
14,
2350,
430,
367,
536,
12,
843,
315,
1169,
664,
30996,
8,
1757,
680,
1744,
9383,
339,
347,
485,
1122,
8,
277,
12,
2547,
12,
6506,
4943,
29,
797,
12,
3970,
628,
3015,
401,
2049,
2644,
29,
403,
12,
2198,
3396,
29,
549,
12,
675,
1610,
9886,
29,
549,
12,
1011,
958,
304,
398,
291,
14,
26502,
1385,
275,
6506,
4943,
267,
291,
14,
3600,
275,
3970,
267,
291,
14,
13771,
275,
291,
14,
13771,
63,
533,
8,
1745,
12,
2644,
29,
2991,
12,
6343,
2198,
3396,
29,
1122,
3396,
12,
6343,
675,
1610,
9886,
29,
1180,
1610,
9886,
12,
6343,
1798,
29,
277,
12,
1011,
958,
9,
267,
291,
14,
3958,
342,
398,
1830,
715,
26,
288,
862,
26,
355,
291,
14,
973,
7382,
342,
355,
2059,
288,
871,
799,
1122,
1726,
26,
355,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
2350,
14,
3958,
342,
267,
291,
14,
2246,
17697,
275,
756,
267,
291,
14,
2550,
275,
942,
267,
291,
14,
793,
275,
942,
221,
327,
1454,
1202,
543,
3105,
818,
267,
327,
298,
392,
723,
6080,
2,
1182,
298,
14136,
2173,
723,
6080,
2,
1182,
298,
889,
2173,
723,
6080,
2,
267,
291,
14,
5819,
1385,
275,
298,
889,
2173,
723,
6080,
2,
398,
340,
291,
14,
26502,
1385,
26,
288,
291,
14,
26502,
275,
291,
14,
3600,
14,
2325,
342,
953,
340,
291,
14,
26502,
315,
286,
576,
6255,
26,
355,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
1195,
18694,
288,
916,
291,
14,
26502,
315,
4819,
576,
6255,
26,
355,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
1773,
505,
2223,
288,
916,
291,
14,
26502,
508,
283,
17426,
356,
355,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
17426,
2223,
288,
587,
26,
355,
327,
1174,
2575,
365,
666,
1174,
355,
327,
291,
14,
13771,
14,
929,
275,
291,
14,
13771,
14,
18694,
355,
986,
288,
291,
14,
6971,
275,
291,
14,
14236,
905,
5182,
12957,
937,
288,
291,
14,
6971,
14,
3176,
12957,
2162,
342,
288,
291,
14,
3958,
607,
4535,
1385,
342,
267,
587,
26,
288,
291,
14,
26502,
275,
756,
288,
291,
14,
6971,
275,
291,
14,
14236,
905,
2747,
937,
398,
291,
14,
2019,
10521,
275,
488,
398,
291,
14,
5182,
8205,
1451,
10521,
275,
488,
398,
291,
14,
27462,
3593,
275,
715,
339,
347,
365,
4943,
20405,
3428,
8,
277,
12,
1819,
304,
267,
340,
334,
2108,
14,
354,
508,
298,
9340,
13,
1652,
2,
436,
355,
1819,
14,
3251,
508,
10747,
905,
27595,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
labordoc/labordoc-next
|
modules/bibsword/lib/bibsword_client_http.py
|
25
|
6651
|
## This file is part of Invenio.
## Copyright (C) 2010, 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
'''
BibSWORD Client Http Queries
'''
import urllib2
from tempfile import NamedTemporaryFile
from invenio.config import CFG_TMPDIR
from invenio.urlutils import make_user_agent_string
class RemoteSwordServer:
'''This class gives every tools to communicate with the SWORD/APP deposit
of ArXiv.
'''
# static variable used to properly perform http request
agent = make_user_agent_string("BibSWORD")
def __init__(self, authentication_infos):
'''
This method the constructor of the class, it initialise the
connection using a passord. That allows users to connect with
auto-authentication.
@param self: reference to the current instance of the class
@param authentication_infos: dictionary with authentication infos containing
keys:
- realm: realm of the server
- hostname: hostname of the server
- username: name of an arxiv known user
- password: password of the known user
'''
#password manager with default realm to avoid looking for it
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(authentication_infos['realm'],
authentication_infos['hostname'],
authentication_infos['username'],
authentication_infos['password'])
#create an authentificaiton handler
authhandler = urllib2.HTTPBasicAuthHandler(passman)
http_handler = urllib2.HTTPHandler(debuglevel=0)
opener = urllib2.build_opener(authhandler, http_handler)
# insalling : every call to opener will user the same user/pass
urllib2.install_opener(opener)
def get_remote_collection(self, url):
'''
This method sent a request to the servicedocument to know the
collections offer by arxives.
@param self: reference to the current instance of the class
@param url: the url where the request is made
@return: (xml file) collection of arxiv allowed for the user
'''
#format the request
request = urllib2.Request(url)
#launch request
#try:
response = urllib2.urlopen(request)
#except urllib2.HTTPError:
# return ''
#except urllib2.URLError:
# return ''
return response.read()
def deposit_media(self, media, collection, onbehalf):
'''
This method allow the deposit of any type of media on a given arxiv
collection.
@param self: reference to the current instanc off the class
@param media: dict of file info {'type', 'size', 'file'}
@param collection: abreviation of the collection where to deposit
@param onbehalf: user that make the deposition
@return: (xml file) contains error ot the url of the temp file
'''
#format the final deposit URL
deposit_url = collection
#prepare the header
headers = {}
headers['Content-Type'] = media['type']
headers['Content-Length'] = media['size']
#if on behalf, add to the header
if onbehalf != '':
headers['X-On-Behalf-Of'] = onbehalf
headers['X-No-Op'] = 'True'
headers['X-Verbose'] = 'True'
headers['User-Agent'] = self.agent
#format the request
result = urllib2.Request(deposit_url, media['file'], headers)
#launch request
try:
return urllib2.urlopen(result).read()
except urllib2.HTTPError:
return ''
def metadata_submission(self, deposit_url, metadata, onbehalf):
'''
This method send the metadata to ArXiv, then return the answere
@param metadata: xml file to submit to ArXiv
@param onbehalf: specify the persone (and email) to informe of the
publication
'''
#prepare the header of the request
headers = {}
headers['Host'] = 'arxiv.org'
headers['User-Agent'] = self.agent
headers['Content-Type'] = 'application/atom+xml;type=entry'
#if on behalf, add to the header
if onbehalf != '':
headers['X-On-Behalf-Of'] = onbehalf
headers['X-No-Op'] = 'True'
headers['X-verbose'] = 'True'
#format the request
result = urllib2.Request(deposit_url, metadata, headers)
#launch request
try:
response = urllib2.urlopen(result).read()
except urllib2.HTTPError, e:
tmpfd = NamedTemporaryFile(mode='w', suffix='.xml', prefix='bibsword_error_',
dir=CFG_TMPDIR, delete=False)
tmpfd.write(e.read())
tmpfd.close()
return ''
except urllib2.URLError:
return ''
return response
def get_submission_status(self, status_url) :
'''
This method get the xml file from the given URL and return it
@param status_url: url where to get the status
@return: xml atom entry containing the status
'''
#format the http request
request = urllib2.Request(status_url)
request.add_header('Host', 'arxiv.org')
request.add_header('User-Agent', self.agent)
#launch request
try:
response = urllib2.urlopen(request).read()
except urllib2.HTTPError:
return 'HTTPError (Might be an authentication issue)'
except urllib2.URLError:
return 'Wrong url'
return response
|
gpl-2.0
|
[
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
2344,
199,
25217,
51,
5172,
6810,
4760,
5843,
5460,
199,
2344,
199,
199,
646,
4011,
18,
199,
504,
5549,
492,
31825,
199,
504,
13640,
14,
888,
492,
10974,
63,
17983,
3022,
199,
504,
13640,
14,
633,
1208,
492,
1852,
63,
751,
63,
4054,
63,
875,
199,
199,
533,
17283,
51,
1027,
3120,
26,
272,
1449,
2765,
1021,
10557,
4036,
7249,
370,
26808,
543,
314,
428,
5172,
15,
7121,
477,
21759,
267,
402,
1952,
56,
1003,
14,
272,
1449,
339,
327,
2955,
1750,
1202,
370,
7684,
5147,
1455,
1056,
272,
6631,
275,
1852,
63,
751,
63,
4054,
63,
875,
480,
25217,
51,
5172,
531,
2378,
347,
636,
826,
721,
277,
12,
6299,
63,
14195,
304,
398,
1449,
288,
961,
1083,
314,
3787,
402,
314,
1021,
12,
652,
2536,
572,
314,
288,
1950,
1808,
282,
986,
2181,
14,
10314,
6127,
4390,
370,
4907,
543,
288,
2599,
13,
11725,
14,
288,
768,
635,
291,
26,
3659,
370,
314,
1453,
1256,
402,
314,
1021,
288,
768,
635,
6299,
63,
14195,
26,
2600,
543,
6299,
24485,
3035,
1460,
2883,
26,
4490,
446,
10482,
26,
10482,
402,
314,
1654,
4490,
446,
6246,
26,
6246,
402,
314,
1654,
4490,
446,
3434,
26,
536,
402,
376,
601,
25034,
6040,
922,
4490,
446,
2505,
26,
2505,
402,
314,
6040,
922,
267,
1449,
398,
327,
2060,
5256,
543,
849,
10482,
370,
5126,
10023,
367,
652,
267,
986,
1237,
275,
4011,
18,
14,
2856,
6139,
20752,
3007,
2698,
27422,
342,
398,
986,
1237,
14,
525,
63,
2060,
8,
11725,
63,
14195,
459,
7728,
995,
2490,
6299,
63,
14195,
459,
4269,
995,
2490,
6299,
63,
14195,
459,
2473,
995,
2490,
6299,
63,
14195,
459,
2060,
1105,
398,
327,
981,
376,
1790,
287,
1428,
696,
390,
265,
3016,
267,
1790,
2232,
275,
4011,
18,
14,
2856,
6845,
21547,
8,
1529,
1237,
9,
398,
1455,
63,
2232,
275,
4011,
18,
14,
2856,
2461,
8,
1757,
1896,
29,
16,
9,
398,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
8,
1178,
2232,
12,
1455,
63,
2232,
9,
267,
327,
5261,
26039,
520,
4036,
1240,
370,
16088,
911,
922,
314,
2011,
922,
15,
1529,
267,
4011,
18,
14,
3174,
63,
11637,
8,
11637,
9,
2378,
347,
664,
63,
3846,
63,
3627,
8,
277,
12,
1166,
304,
267,
1449,
288,
961,
1083,
4847,
282,
1056,
370,
314,
2435,
3554,
370,
5715,
314,
288,
5055,
19793,
701,
601,
88,
7602,
14,
288,
768,
635,
291,
26,
3659,
370,
314,
1453,
1256,
402,
314,
1021,
288,
768,
635,
1166,
26,
314,
1166,
2382,
314,
1056,
365,
6326,
288,
768,
1107,
26,
334,
1652,
570,
9,
3245,
402,
601,
25034,
4370,
367,
314,
922,
267,
1449,
398,
327,
908,
314,
1056,
267,
1056,
275,
4011,
18,
14,
2017,
8,
633,
9,
398,
327,
9850,
1056,
267,
327,
893,
26,
267,
1177,
275,
4011,
18,
14,
10890,
8,
1069,
9,
267,
327,
2590,
4011,
18,
14,
12815,
26,
267,
327,
259,
372,
2125,
267,
327,
2590,
4011,
18,
14,
31475,
26,
267,
327,
259,
372,
2125,
398,
372,
1177,
14,
739,
342,
2378,
347,
477,
21759,
63,
4603,
8,
277,
12,
5898,
12,
3245,
12,
641,
1235,
10220,
304,
267,
1449,
288,
961,
1083,
2040,
314,
477,
21759,
402,
1263,
730,
402,
5898,
641,
282,
1627,
601,
25034,
288,
3245,
14,
288,
768,
635,
291,
26,
3659,
370,
314,
1453,
2727,
18595,
2331,
314,
1021,
288,
768,
635,
5898,
26,
1211,
402,
570,
2256,
791,
466,
297,
283,
890,
297,
283,
493,
936,
288,
768,
635,
3245,
26,
2236,
264,
12337,
402,
314,
3245,
2382,
370,
477,
21759,
288,
768,
635,
641,
1235,
10220,
26,
922,
626,
1852,
314,
477,
3124,
288,
768,
1107,
26,
334,
1652,
570,
9,
3509,
1125,
312,
84,
314,
1166,
402,
314,
2388,
570,
267,
1449,
398,
327,
908,
314,
4242,
477,
21759,
2851,
267,
477,
21759,
63,
633,
275,
3245,
398,
327,
6726,
314,
1406,
267,
2323,
275,
1052,
267,
2323,
459,
2714,
13,
804,
418,
275,
5898,
459,
466,
418,
267,
2323,
459,
2714,
13,
4625,
418,
275,
5898,
459,
890,
418,
267,
327,
692,
641,
506,
10220,
12,
1050,
370,
314,
1406,
267,
340,
641,
1235,
10220,
1137,
8061,
288,
2323,
459,
56,
13,
3314,
13,
3655,
10220,
13,
3466,
418,
275,
641,
1235,
10220,
398,
2323,
459,
56,
13,
1944,
13,
4619,
418,
275,
283,
549,
7,
267,
2323,
459,
56,
13,
21879,
418,
275,
283,
549,
7,
267,
2323,
459,
1899,
13,
7788,
418,
275,
291,
14,
4054,
398,
327,
908,
314,
1056,
267,
754,
275,
4011,
18,
14,
2017,
8,
271,
21759,
63,
633,
12,
5898,
459,
493,
995,
2323,
9,
398,
327,
9850,
1056,
267,
862,
26,
288,
372,
4011,
18,
14,
10890,
8,
1099,
680,
739,
342,
267,
871,
4011,
18,
14,
12815,
26,
288,
372,
2125,
2378,
347,
3341,
63,
12542,
8,
277,
12,
477,
21759,
63,
633,
12,
3341,
12,
641,
1235,
10220,
304,
267,
1449,
288,
961,
1083,
3222,
314,
3341,
370,
1952,
56,
1003,
12,
2066,
372,
314,
4987,
1129,
264,
288,
768,
635,
3341,
26,
2748,
570,
370,
11482,
370,
1952,
56,
1003,
288
] |
[
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
2344,
199,
25217,
51,
5172,
6810,
4760,
5843,
5460,
199,
2344,
199,
199,
646,
4011,
18,
199,
504,
5549,
492,
31825,
199,
504,
13640,
14,
888,
492,
10974,
63,
17983,
3022,
199,
504,
13640,
14,
633,
1208,
492,
1852,
63,
751,
63,
4054,
63,
875,
199,
199,
533,
17283,
51,
1027,
3120,
26,
272,
1449,
2765,
1021,
10557,
4036,
7249,
370,
26808,
543,
314,
428,
5172,
15,
7121,
477,
21759,
267,
402,
1952,
56,
1003,
14,
272,
1449,
339,
327,
2955,
1750,
1202,
370,
7684,
5147,
1455,
1056,
272,
6631,
275,
1852,
63,
751,
63,
4054,
63,
875,
480,
25217,
51,
5172,
531,
2378,
347,
636,
826,
721,
277,
12,
6299,
63,
14195,
304,
398,
1449,
288,
961,
1083,
314,
3787,
402,
314,
1021,
12,
652,
2536,
572,
314,
288,
1950,
1808,
282,
986,
2181,
14,
10314,
6127,
4390,
370,
4907,
543,
288,
2599,
13,
11725,
14,
288,
768,
635,
291,
26,
3659,
370,
314,
1453,
1256,
402,
314,
1021,
288,
768,
635,
6299,
63,
14195,
26,
2600,
543,
6299,
24485,
3035,
1460,
2883,
26,
4490,
446,
10482,
26,
10482,
402,
314,
1654,
4490,
446,
6246,
26,
6246,
402,
314,
1654,
4490,
446,
3434,
26,
536,
402,
376,
601,
25034,
6040,
922,
4490,
446,
2505,
26,
2505,
402,
314,
6040,
922,
267,
1449,
398,
327,
2060,
5256,
543,
849,
10482,
370,
5126,
10023,
367,
652,
267,
986,
1237,
275,
4011,
18,
14,
2856,
6139,
20752,
3007,
2698,
27422,
342,
398,
986,
1237,
14,
525,
63,
2060,
8,
11725,
63,
14195,
459,
7728,
995,
2490,
6299,
63,
14195,
459,
4269,
995,
2490,
6299,
63,
14195,
459,
2473,
995,
2490,
6299,
63,
14195,
459,
2060,
1105,
398,
327,
981,
376,
1790,
287,
1428,
696,
390,
265,
3016,
267,
1790,
2232,
275,
4011,
18,
14,
2856,
6845,
21547,
8,
1529,
1237,
9,
398,
1455,
63,
2232,
275,
4011,
18,
14,
2856,
2461,
8,
1757,
1896,
29,
16,
9,
398,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
8,
1178,
2232,
12,
1455,
63,
2232,
9,
267,
327,
5261,
26039,
520,
4036,
1240,
370,
16088,
911,
922,
314,
2011,
922,
15,
1529,
267,
4011,
18,
14,
3174,
63,
11637,
8,
11637,
9,
2378,
347,
664,
63,
3846,
63,
3627,
8,
277,
12,
1166,
304,
267,
1449,
288,
961,
1083,
4847,
282,
1056,
370,
314,
2435,
3554,
370,
5715,
314,
288,
5055,
19793,
701,
601,
88,
7602,
14,
288,
768,
635,
291,
26,
3659,
370,
314,
1453,
1256,
402,
314,
1021,
288,
768,
635,
1166,
26,
314,
1166,
2382,
314,
1056,
365,
6326,
288,
768,
1107,
26,
334,
1652,
570,
9,
3245,
402,
601,
25034,
4370,
367,
314,
922,
267,
1449,
398,
327,
908,
314,
1056,
267,
1056,
275,
4011,
18,
14,
2017,
8,
633,
9,
398,
327,
9850,
1056,
267,
327,
893,
26,
267,
1177,
275,
4011,
18,
14,
10890,
8,
1069,
9,
267,
327,
2590,
4011,
18,
14,
12815,
26,
267,
327,
259,
372,
2125,
267,
327,
2590,
4011,
18,
14,
31475,
26,
267,
327,
259,
372,
2125,
398,
372,
1177,
14,
739,
342,
2378,
347,
477,
21759,
63,
4603,
8,
277,
12,
5898,
12,
3245,
12,
641,
1235,
10220,
304,
267,
1449,
288,
961,
1083,
2040,
314,
477,
21759,
402,
1263,
730,
402,
5898,
641,
282,
1627,
601,
25034,
288,
3245,
14,
288,
768,
635,
291,
26,
3659,
370,
314,
1453,
2727,
18595,
2331,
314,
1021,
288,
768,
635,
5898,
26,
1211,
402,
570,
2256,
791,
466,
297,
283,
890,
297,
283,
493,
936,
288,
768,
635,
3245,
26,
2236,
264,
12337,
402,
314,
3245,
2382,
370,
477,
21759,
288,
768,
635,
641,
1235,
10220,
26,
922,
626,
1852,
314,
477,
3124,
288,
768,
1107,
26,
334,
1652,
570,
9,
3509,
1125,
312,
84,
314,
1166,
402,
314,
2388,
570,
267,
1449,
398,
327,
908,
314,
4242,
477,
21759,
2851,
267,
477,
21759,
63,
633,
275,
3245,
398,
327,
6726,
314,
1406,
267,
2323,
275,
1052,
267,
2323,
459,
2714,
13,
804,
418,
275,
5898,
459,
466,
418,
267,
2323,
459,
2714,
13,
4625,
418,
275,
5898,
459,
890,
418,
267,
327,
692,
641,
506,
10220,
12,
1050,
370,
314,
1406,
267,
340,
641,
1235,
10220,
1137,
8061,
288,
2323,
459,
56,
13,
3314,
13,
3655,
10220,
13,
3466,
418,
275,
641,
1235,
10220,
398,
2323,
459,
56,
13,
1944,
13,
4619,
418,
275,
283,
549,
7,
267,
2323,
459,
56,
13,
21879,
418,
275,
283,
549,
7,
267,
2323,
459,
1899,
13,
7788,
418,
275,
291,
14,
4054,
398,
327,
908,
314,
1056,
267,
754,
275,
4011,
18,
14,
2017,
8,
271,
21759,
63,
633,
12,
5898,
459,
493,
995,
2323,
9,
398,
327,
9850,
1056,
267,
862,
26,
288,
372,
4011,
18,
14,
10890,
8,
1099,
680,
739,
342,
267,
871,
4011,
18,
14,
12815,
26,
288,
372,
2125,
2378,
347,
3341,
63,
12542,
8,
277,
12,
477,
21759,
63,
633,
12,
3341,
12,
641,
1235,
10220,
304,
267,
1449,
288,
961,
1083,
3222,
314,
3341,
370,
1952,
56,
1003,
12,
2066,
372,
314,
4987,
1129,
264,
288,
768,
635,
3341,
26,
2748,
570,
370,
11482,
370,
1952,
56,
1003,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
madan96/sympy
|
sympy/polys/rootisolation.py
|
78
|
55536
|
"""Real and complex root isolation and refinement algorithms. """
from __future__ import print_function, division
from sympy.polys.densebasic import (
dup_LC, dup_TC, dup_degree,
dup_strip, dup_reverse,
dup_convert,
dup_terms_gcd)
from sympy.polys.densearith import (
dup_neg, dup_rshift, dup_rem)
from sympy.polys.densetools import (
dup_clear_denoms,
dup_mirror, dup_scale, dup_shift,
dup_transform,
dup_diff,
dup_eval, dmp_eval_in,
dup_sign_variations,
dup_real_imag)
from sympy.polys.sqfreetools import (
dup_sqf_part, dup_sqf_list)
from sympy.polys.factortools import (
dup_factor_list)
from sympy.polys.polyerrors import (
RefinementFailed,
DomainError)
from sympy.core.compatibility import range
def dup_sturm(f, K):
"""
Computes the Sturm sequence of ``f`` in ``F[x]``.
Given a univariate, square-free polynomial ``f(x)`` returns the
associated Sturm sequence ``f_0(x), ..., f_n(x)`` defined by::
f_0(x), f_1(x) = f(x), f'(x)
f_n = -rem(f_{n-2}(x), f_{n-1}(x))
Examples
========
>>> from sympy.polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> R.dup_sturm(x**3 - 2*x**2 + x - 3)
[x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2/9*x + 25/9, -2079/4]
References
==========
1. [Davenport88]_
"""
if not K.has_Field:
raise DomainError("can't compute Sturm sequence over %s" % K)
f = dup_sqf_part(f, K)
sturm = [f, dup_diff(f, 1, K)]
while sturm[-1]:
s = dup_rem(sturm[-2], sturm[-1], K)
sturm.append(dup_neg(s, K))
return sturm[:-1]
def dup_root_upper_bound(f, K):
"""Compute the LMQ upper bound for the positive roots of `f`;
LMQ (Local Max Quadratic) was developed by Akritas-Strzebonski-Vigklas.
Reference:
==========
Alkiviadis G. Akritas: "Linear and Quadratic Complexity Bounds on the
Values of the Positive Roots of Polynomials"
Journal of Universal Computer Science, Vol. 15, No. 3, 523-537, 2009.
"""
n, P = len(f), []
t = n * [K.one]
if dup_LC(f, K) < 0:
f = dup_neg(f, K)
f = list(reversed(f))
for i in range(0, n):
if f[i] >= 0:
continue
a, QL = K.log(-f[i], 2), []
for j in range(i + 1, n):
if f[j] <= 0:
continue
q = t[j] + a - K.log(f[j], 2)
QL.append([q // (j - i) , j])
if not QL:
continue
q = min(QL)
t[q[1]] = t[q[1]] + 1
P.append(q[0])
if not P:
return None
else:
return K.get_field()(2)**(max(P) + 1)
def dup_root_lower_bound(f, K):
"""Compute the LMQ lower bound for the positive roots of `f`;
LMQ (Local Max Quadratic) was developed by Akritas-Strzebonski-Vigklas.
Reference:
==========
Alkiviadis G. Akritas: "Linear and Quadratic Complexity Bounds on the
Values of the Positive Roots of Polynomials"
Journal of Universal Computer Science, Vol. 15, No. 3, 523-537, 2009.
"""
bound = dup_root_upper_bound(dup_reverse(f), K)
if bound is not None:
return 1/bound
else:
return None
def _mobius_from_interval(I, field):
"""Convert an open interval to a Mobius transform. """
s, t = I
a, c = field.numer(s), field.denom(s)
b, d = field.numer(t), field.denom(t)
return a, b, c, d
def _mobius_to_interval(M, field):
"""Convert a Mobius transform to an open interval. """
a, b, c, d = M
s, t = field(a, c), field(b, d)
if s <= t:
return (s, t)
else:
return (t, s)
def dup_step_refine_real_root(f, M, K, fast=False):
"""One step of positive real root refinement algorithm. """
a, b, c, d = M
if a == b and c == d:
return f, (a, b, c, d)
A = dup_root_lower_bound(f, K)
if A is not None:
A = K(int(A))
else:
A = K.zero
if fast and A > 16:
f = dup_scale(f, A, K)
a, c, A = A*a, A*c, K.one
if A >= K.one:
f = dup_shift(f, A, K)
b, d = A*a + b, A*c + d
if not dup_eval(f, K.zero, K):
return f, (b, b, d, d)
f, g = dup_shift(f, K.one, K), f
a1, b1, c1, d1 = a, a + b, c, c + d
if not dup_eval(f, K.zero, K):
return f, (b1, b1, d1, d1)
k = dup_sign_variations(f, K)
if k == 1:
a, b, c, d = a1, b1, c1, d1
else:
f = dup_shift(dup_reverse(g), K.one, K)
if not dup_eval(f, K.zero, K):
f = dup_rshift(f, 1, K)
a, b, c, d = b, a + b, d, c + d
return f, (a, b, c, d)
def dup_inner_refine_real_root(f, M, K, eps=None, steps=None, disjoint=None, fast=False, mobius=False):
"""Refine a positive root of `f` given a Mobius transform or an interval. """
F = K.get_field()
if len(M) == 2:
a, b, c, d = _mobius_from_interval(M, F)
else:
a, b, c, d = M
while not c:
f, (a, b, c, d) = dup_step_refine_real_root(f, (a, b, c,
d), K, fast=fast)
if eps is not None and steps is not None:
for i in range(0, steps):
if abs(F(a, c) - F(b, d)) >= eps:
f, (a, b, c, d) = dup_step_refine_real_root(f, (a, b, c, d), K, fast=fast)
else:
break
else:
if eps is not None:
while abs(F(a, c) - F(b, d)) >= eps:
f, (a, b, c, d) = dup_step_refine_real_root(f, (a, b, c, d), K, fast=fast)
if steps is not None:
for i in range(0, steps):
f, (a, b, c, d) = dup_step_refine_real_root(f, (a, b, c, d), K, fast=fast)
if disjoint is not None:
while True:
u, v = _mobius_to_interval((a, b, c, d), F)
if v <= disjoint or disjoint <= u:
break
else:
f, (a, b, c, d) = dup_step_refine_real_root(f, (a, b, c, d), K, fast=fast)
if not mobius:
return _mobius_to_interval((a, b, c, d), F)
else:
return f, (a, b, c, d)
def dup_outer_refine_real_root(f, s, t, K, eps=None, steps=None, disjoint=None, fast=False):
"""Refine a positive root of `f` given an interval `(s, t)`. """
a, b, c, d = _mobius_from_interval((s, t), K.get_field())
f = dup_transform(f, dup_strip([a, b]),
dup_strip([c, d]), K)
if dup_sign_variations(f, K) != 1:
raise RefinementFailed("there should be exactly one root in (%s, %s) interval" % (s, t))
return dup_inner_refine_real_root(f, (a, b, c, d), K, eps=eps, steps=steps, disjoint=disjoint, fast=fast)
def dup_refine_real_root(f, s, t, K, eps=None, steps=None, disjoint=None, fast=False):
"""Refine real root's approximating interval to the given precision. """
if K.is_QQ:
(_, f), K = dup_clear_denoms(f, K, convert=True), K.get_ring()
elif not K.is_ZZ:
raise DomainError("real root refinement not supported over %s" % K)
if s == t:
return (s, t)
if s > t:
s, t = t, s
negative = False
if s < 0:
if t <= 0:
f, s, t, negative = dup_mirror(f, K), -t, -s, True
else:
raise ValueError("can't refine a real root in (%s, %s)" % (s, t))
if negative and disjoint is not None:
if disjoint < 0:
disjoint = -disjoint
else:
disjoint = None
s, t = dup_outer_refine_real_root(
f, s, t, K, eps=eps, steps=steps, disjoint=disjoint, fast=fast)
if negative:
return (-t, -s)
else:
return ( s, t)
def dup_inner_isolate_real_roots(f, K, eps=None, fast=False):
"""Internal function for isolation positive roots up to given precision.
References:
===========
1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root
Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the
Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear
Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.
"""
a, b, c, d = K.one, K.zero, K.zero, K.one
k = dup_sign_variations(f, K)
if k == 0:
return []
if k == 1:
roots = [dup_inner_refine_real_root(
f, (a, b, c, d), K, eps=eps, fast=fast, mobius=True)]
else:
roots, stack = [], [(a, b, c, d, f, k)]
while stack:
a, b, c, d, f, k = stack.pop()
A = dup_root_lower_bound(f, K)
if A is not None:
A = K(int(A))
else:
A = K.zero
if fast and A > 16:
f = dup_scale(f, A, K)
a, c, A = A*a, A*c, K.one
if A >= K.one:
f = dup_shift(f, A, K)
b, d = A*a + b, A*c + d
if not dup_TC(f, K):
roots.append((f, (b, b, d, d)))
f = dup_rshift(f, 1, K)
k = dup_sign_variations(f, K)
if k == 0:
continue
if k == 1:
roots.append(dup_inner_refine_real_root(
f, (a, b, c, d), K, eps=eps, fast=fast, mobius=True))
continue
f1 = dup_shift(f, K.one, K)
a1, b1, c1, d1, r = a, a + b, c, c + d, 0
if not dup_TC(f1, K):
roots.append((f1, (b1, b1, d1, d1)))
f1, r = dup_rshift(f1, 1, K), 1
k1 = dup_sign_variations(f1, K)
k2 = k - k1 - r
a2, b2, c2, d2 = b, a + b, d, c + d
if k2 > 1:
f2 = dup_shift(dup_reverse(f), K.one, K)
if not dup_TC(f2, K):
f2 = dup_rshift(f2, 1, K)
k2 = dup_sign_variations(f2, K)
else:
f2 = None
if k1 < k2:
a1, a2, b1, b2 = a2, a1, b2, b1
c1, c2, d1, d2 = c2, c1, d2, d1
f1, f2, k1, k2 = f2, f1, k2, k1
if not k1:
continue
if f1 is None:
f1 = dup_shift(dup_reverse(f), K.one, K)
if not dup_TC(f1, K):
f1 = dup_rshift(f1, 1, K)
if k1 == 1:
roots.append(dup_inner_refine_real_root(
f1, (a1, b1, c1, d1), K, eps=eps, fast=fast, mobius=True))
else:
stack.append((a1, b1, c1, d1, f1, k1))
if not k2:
continue
if f2 is None:
f2 = dup_shift(dup_reverse(f), K.one, K)
if not dup_TC(f2, K):
f2 = dup_rshift(f2, 1, K)
if k2 == 1:
roots.append(dup_inner_refine_real_root(
f2, (a2, b2, c2, d2), K, eps=eps, fast=fast, mobius=True))
else:
stack.append((a2, b2, c2, d2, f2, k2))
return roots
def _discard_if_outside_interval(f, M, inf, sup, K, negative, fast, mobius):
"""Discard an isolating interval if outside ``(inf, sup)``. """
F = K.get_field()
while True:
u, v = _mobius_to_interval(M, F)
if negative:
u, v = -v, -u
if (inf is None or u >= inf) and (sup is None or v <= sup):
if not mobius:
return u, v
else:
return f, M
elif (sup is not None and u > sup) or (inf is not None and v < inf):
return None
else:
f, M = dup_step_refine_real_root(f, M, K, fast=fast)
def dup_inner_isolate_positive_roots(f, K, eps=None, inf=None, sup=None, fast=False, mobius=False):
"""Iteratively compute disjoint positive root isolation intervals. """
if sup is not None and sup < 0:
return []
roots = dup_inner_isolate_real_roots(f, K, eps=eps, fast=fast)
F, results = K.get_field(), []
if inf is not None or sup is not None:
for f, M in roots:
result = _discard_if_outside_interval(f, M, inf, sup, K, False, fast, mobius)
if result is not None:
results.append(result)
elif not mobius:
for f, M in roots:
u, v = _mobius_to_interval(M, F)
results.append((u, v))
else:
results = roots
return results
def dup_inner_isolate_negative_roots(f, K, inf=None, sup=None, eps=None, fast=False, mobius=False):
"""Iteratively compute disjoint negative root isolation intervals. """
if inf is not None and inf >= 0:
return []
roots = dup_inner_isolate_real_roots(dup_mirror(f, K), K, eps=eps, fast=fast)
F, results = K.get_field(), []
if inf is not None or sup is not None:
for f, M in roots:
result = _discard_if_outside_interval(f, M, inf, sup, K, True, fast, mobius)
if result is not None:
results.append(result)
elif not mobius:
for f, M in roots:
u, v = _mobius_to_interval(M, F)
results.append((-v, -u))
else:
results = roots
return results
def _isolate_zero(f, K, inf, sup, basis=False, sqf=False):
"""Handle special case of CF algorithm when ``f`` is homogeneous. """
j, f = dup_terms_gcd(f, K)
if j > 0:
F = K.get_field()
if (inf is None or inf <= 0) and (sup is None or 0 <= sup):
if not sqf:
if not basis:
return [((F.zero, F.zero), j)], f
else:
return [((F.zero, F.zero), j, [K.one, K.zero])], f
else:
return [(F.zero, F.zero)], f
return [], f
def dup_isolate_real_roots_sqf(f, K, eps=None, inf=None, sup=None, fast=False, blackbox=False):
"""Isolate real roots of a square-free polynomial using the Vincent-Akritas-Strzebonski (VAS) CF approach.
References:
===========
1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods.
Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance
of the Continued Fractions Method Using New Bounds of Positive Roots.
Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.
"""
if K.is_QQ:
(_, f), K = dup_clear_denoms(f, K, convert=True), K.get_ring()
elif not K.is_ZZ:
raise DomainError("isolation of real roots not supported over %s" % K)
if dup_degree(f) <= 0:
return []
I_zero, f = _isolate_zero(f, K, inf, sup, basis=False, sqf=True)
I_neg = dup_inner_isolate_negative_roots(f, K, eps=eps, inf=inf, sup=sup, fast=fast)
I_pos = dup_inner_isolate_positive_roots(f, K, eps=eps, inf=inf, sup=sup, fast=fast)
roots = sorted(I_neg + I_zero + I_pos)
if not blackbox:
return roots
else:
return [ RealInterval((a, b), f, K) for (a, b) in roots ]
def dup_isolate_real_roots(f, K, eps=None, inf=None, sup=None, basis=False, fast=False):
"""Isolate real roots using Vincent-Akritas-Strzebonski (VAS) continued fractions approach.
References:
===========
1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods.
Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance
of the Continued Fractions Method Using New Bounds of Positive Roots.
Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.
"""
if K.is_QQ:
(_, f), K = dup_clear_denoms(f, K, convert=True), K.get_ring()
elif not K.is_ZZ:
raise DomainError("isolation of real roots not supported over %s" % K)
if dup_degree(f) <= 0:
return []
I_zero, f = _isolate_zero(f, K, inf, sup, basis=basis, sqf=False)
_, factors = dup_sqf_list(f, K)
if len(factors) == 1:
((f, k),) = factors
I_neg = dup_inner_isolate_negative_roots(f, K, eps=eps, inf=inf, sup=sup, fast=fast)
I_pos = dup_inner_isolate_positive_roots(f, K, eps=eps, inf=inf, sup=sup, fast=fast)
I_neg = [ ((u, v), k) for u, v in I_neg ]
I_pos = [ ((u, v), k) for u, v in I_pos ]
else:
I_neg, I_pos = _real_isolate_and_disjoin(factors, K,
eps=eps, inf=inf, sup=sup, basis=basis, fast=fast)
return sorted(I_neg + I_zero + I_pos)
def dup_isolate_real_roots_list(polys, K, eps=None, inf=None, sup=None, strict=False, basis=False, fast=False):
"""Isolate real roots of a list of square-free polynomial using Vincent-Akritas-Strzebonski (VAS) CF approach.
References:
===========
1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods.
Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.
2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance
of the Continued Fractions Method Using New Bounds of Positive Roots.
Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.
"""
if K.is_QQ:
K, F, polys = K.get_ring(), K, polys[:]
for i, p in enumerate(polys):
polys[i] = dup_clear_denoms(p, F, K, convert=True)[1]
elif not K.is_ZZ:
raise DomainError("isolation of real roots not supported over %s" % K)
zeros, factors_dict = False, {}
if (inf is None or inf <= 0) and (sup is None or 0 <= sup):
zeros, zero_indices = True, {}
for i, p in enumerate(polys):
j, p = dup_terms_gcd(p, K)
if zeros and j > 0:
zero_indices[i] = j
for f, k in dup_factor_list(p, K)[1]:
f = tuple(f)
if f not in factors_dict:
factors_dict[f] = {i: k}
else:
factors_dict[f][i] = k
factors_list = []
for f, indices in factors_dict.items():
factors_list.append((list(f), indices))
I_neg, I_pos = _real_isolate_and_disjoin(factors_list, K, eps=eps,
inf=inf, sup=sup, strict=strict, basis=basis, fast=fast)
F = K.get_field()
if not zeros or not zero_indices:
I_zero = []
else:
if not basis:
I_zero = [((F.zero, F.zero), zero_indices)]
else:
I_zero = [((F.zero, F.zero), zero_indices, [K.one, K.zero])]
return sorted(I_neg + I_zero + I_pos)
def _disjoint_p(M, N, strict=False):
"""Check if Mobius transforms define disjoint intervals. """
a1, b1, c1, d1 = M
a2, b2, c2, d2 = N
a1d1, b1c1 = a1*d1, b1*c1
a2d2, b2c2 = a2*d2, b2*c2
if a1d1 == b1c1 and a2d2 == b2c2:
return True
if a1d1 > b1c1:
a1, c1, b1, d1 = b1, d1, a1, c1
if a2d2 > b2c2:
a2, c2, b2, d2 = b2, d2, a2, c2
if not strict:
return a2*d1 >= c2*b1 or b2*c1 <= d2*a1
else:
return a2*d1 > c2*b1 or b2*c1 < d2*a1
def _real_isolate_and_disjoin(factors, K, eps=None, inf=None, sup=None, strict=False, basis=False, fast=False):
"""Isolate real roots of a list of polynomials and disjoin intervals. """
I_pos, I_neg = [], []
for i, (f, k) in enumerate(factors):
for F, M in dup_inner_isolate_positive_roots(f, K, eps=eps, inf=inf, sup=sup, fast=fast, mobius=True):
I_pos.append((F, M, k, f))
for G, N in dup_inner_isolate_negative_roots(f, K, eps=eps, inf=inf, sup=sup, fast=fast, mobius=True):
I_neg.append((G, N, k, f))
for i, (f, M, k, F) in enumerate(I_pos):
for j, (g, N, m, G) in enumerate(I_pos[i + 1:]):
while not _disjoint_p(M, N, strict=strict):
f, M = dup_inner_refine_real_root(f, M, K, steps=1, fast=fast, mobius=True)
g, N = dup_inner_refine_real_root(g, N, K, steps=1, fast=fast, mobius=True)
I_pos[i + j + 1] = (g, N, m, G)
I_pos[i] = (f, M, k, F)
for i, (f, M, k, F) in enumerate(I_neg):
for j, (g, N, m, G) in enumerate(I_neg[i + 1:]):
while not _disjoint_p(M, N, strict=strict):
f, M = dup_inner_refine_real_root(f, M, K, steps=1, fast=fast, mobius=True)
g, N = dup_inner_refine_real_root(g, N, K, steps=1, fast=fast, mobius=True)
I_neg[i + j + 1] = (g, N, m, G)
I_neg[i] = (f, M, k, F)
if strict:
for i, (f, M, k, F) in enumerate(I_neg):
if not M[0]:
while not M[0]:
f, M = dup_inner_refine_real_root(f, M, K, steps=1, fast=fast, mobius=True)
I_neg[i] = (f, M, k, F)
break
for j, (g, N, m, G) in enumerate(I_pos):
if not N[0]:
while not N[0]:
g, N = dup_inner_refine_real_root(g, N, K, steps=1, fast=fast, mobius=True)
I_pos[j] = (g, N, m, G)
break
field = K.get_field()
I_neg = [ (_mobius_to_interval(M, field), k, f) for (_, M, k, f) in I_neg ]
I_pos = [ (_mobius_to_interval(M, field), k, f) for (_, M, k, f) in I_pos ]
if not basis:
I_neg = [ ((-v, -u), k) for ((u, v), k, _) in I_neg ]
I_pos = [ (( u, v), k) for ((u, v), k, _) in I_pos ]
else:
I_neg = [ ((-v, -u), k, f) for ((u, v), k, f) in I_neg ]
I_pos = [ (( u, v), k, f) for ((u, v), k, f) in I_pos ]
return I_neg, I_pos
def dup_count_real_roots(f, K, inf=None, sup=None):
"""Returns the number of distinct real roots of ``f`` in ``[inf, sup]``. """
if dup_degree(f) <= 0:
return 0
if not K.has_Field:
R, K = K, K.get_field()
f = dup_convert(f, R, K)
sturm = dup_sturm(f, K)
if inf is None:
signs_inf = dup_sign_variations([ dup_LC(s, K)*(-1)**dup_degree(s) for s in sturm ], K)
else:
signs_inf = dup_sign_variations([ dup_eval(s, inf, K) for s in sturm ], K)
if sup is None:
signs_sup = dup_sign_variations([ dup_LC(s, K) for s in sturm ], K)
else:
signs_sup = dup_sign_variations([ dup_eval(s, sup, K) for s in sturm ], K)
count = abs(signs_inf - signs_sup)
if inf is not None and not dup_eval(f, inf, K):
count += 1
return count
OO = 'OO' # Origin of (re, im) coordinate system
Q1 = 'Q1' # Quadrant #1 (++): re > 0 and im > 0
Q2 = 'Q2' # Quadrant #2 (-+): re < 0 and im > 0
Q3 = 'Q3' # Quadrant #3 (--): re < 0 and im < 0
Q4 = 'Q4' # Quadrant #4 (+-): re > 0 and im < 0
A1 = 'A1' # Axis #1 (+0): re > 0 and im = 0
A2 = 'A2' # Axis #2 (0+): re = 0 and im > 0
A3 = 'A3' # Axis #3 (-0): re < 0 and im = 0
A4 = 'A4' # Axis #4 (0-): re = 0 and im < 0
_rules_simple = {
# Q --> Q (same) => no change
(Q1, Q1): 0,
(Q2, Q2): 0,
(Q3, Q3): 0,
(Q4, Q4): 0,
# A -- CCW --> Q => +1/4 (CCW)
(A1, Q1): 1,
(A2, Q2): 1,
(A3, Q3): 1,
(A4, Q4): 1,
# A -- CW --> Q => -1/4 (CCW)
(A1, Q4): 2,
(A2, Q1): 2,
(A3, Q2): 2,
(A4, Q3): 2,
# Q -- CCW --> A => +1/4 (CCW)
(Q1, A2): 3,
(Q2, A3): 3,
(Q3, A4): 3,
(Q4, A1): 3,
# Q -- CW --> A => -1/4 (CCW)
(Q1, A1): 4,
(Q2, A2): 4,
(Q3, A3): 4,
(Q4, A4): 4,
# Q -- CCW --> Q => +1/2 (CCW)
(Q1, Q2): +5,
(Q2, Q3): +5,
(Q3, Q4): +5,
(Q4, Q1): +5,
# Q -- CW --> Q => -1/2 (CW)
(Q1, Q4): -5,
(Q2, Q1): -5,
(Q3, Q2): -5,
(Q4, Q3): -5,
}
_rules_ambiguous = {
# A -- CCW --> Q => { +1/4 (CCW), -9/4 (CW) }
(A1, OO, Q1): -1,
(A2, OO, Q2): -1,
(A3, OO, Q3): -1,
(A4, OO, Q4): -1,
# A -- CW --> Q => { -1/4 (CCW), +7/4 (CW) }
(A1, OO, Q4): -2,
(A2, OO, Q1): -2,
(A3, OO, Q2): -2,
(A4, OO, Q3): -2,
# Q -- CCW --> A => { +1/4 (CCW), -9/4 (CW) }
(Q1, OO, A2): -3,
(Q2, OO, A3): -3,
(Q3, OO, A4): -3,
(Q4, OO, A1): -3,
# Q -- CW --> A => { -1/4 (CCW), +7/4 (CW) }
(Q1, OO, A1): -4,
(Q2, OO, A2): -4,
(Q3, OO, A3): -4,
(Q4, OO, A4): -4,
# A -- OO --> A => { +1 (CCW), -1 (CW) }
(A1, A3): 7,
(A2, A4): 7,
(A3, A1): 7,
(A4, A2): 7,
(A1, OO, A3): 7,
(A2, OO, A4): 7,
(A3, OO, A1): 7,
(A4, OO, A2): 7,
# Q -- DIA --> Q => { +1 (CCW), -1 (CW) }
(Q1, Q3): 8,
(Q2, Q4): 8,
(Q3, Q1): 8,
(Q4, Q2): 8,
(Q1, OO, Q3): 8,
(Q2, OO, Q4): 8,
(Q3, OO, Q1): 8,
(Q4, OO, Q2): 8,
# A --- R ---> A => { +1/2 (CCW), -3/2 (CW) }
(A1, A2): 9,
(A2, A3): 9,
(A3, A4): 9,
(A4, A1): 9,
(A1, OO, A2): 9,
(A2, OO, A3): 9,
(A3, OO, A4): 9,
(A4, OO, A1): 9,
# A --- L ---> A => { +3/2 (CCW), -1/2 (CW) }
(A1, A4): 10,
(A2, A1): 10,
(A3, A2): 10,
(A4, A3): 10,
(A1, OO, A4): 10,
(A2, OO, A1): 10,
(A3, OO, A2): 10,
(A4, OO, A3): 10,
# Q --- 1 ---> A => { +3/4 (CCW), -5/4 (CW) }
(Q1, A3): 11,
(Q2, A4): 11,
(Q3, A1): 11,
(Q4, A2): 11,
(Q1, OO, A3): 11,
(Q2, OO, A4): 11,
(Q3, OO, A1): 11,
(Q4, OO, A2): 11,
# Q --- 2 ---> A => { +5/4 (CCW), -3/4 (CW) }
(Q1, A4): 12,
(Q2, A1): 12,
(Q3, A2): 12,
(Q4, A3): 12,
(Q1, OO, A4): 12,
(Q2, OO, A1): 12,
(Q3, OO, A2): 12,
(Q4, OO, A3): 12,
# A --- 1 ---> Q => { +5/4 (CCW), -3/4 (CW) }
(A1, Q3): 13,
(A2, Q4): 13,
(A3, Q1): 13,
(A4, Q2): 13,
(A1, OO, Q3): 13,
(A2, OO, Q4): 13,
(A3, OO, Q1): 13,
(A4, OO, Q2): 13,
# A --- 2 ---> Q => { +3/4 (CCW), -5/4 (CW) }
(A1, Q2): 14,
(A2, Q3): 14,
(A3, Q4): 14,
(A4, Q1): 14,
(A1, OO, Q2): 14,
(A2, OO, Q3): 14,
(A3, OO, Q4): 14,
(A4, OO, Q1): 14,
# Q --> OO --> Q => { +1/2 (CCW), -3/2 (CW) }
(Q1, OO, Q2): 15,
(Q2, OO, Q3): 15,
(Q3, OO, Q4): 15,
(Q4, OO, Q1): 15,
# Q --> OO --> Q => { +3/2 (CCW), -1/2 (CW) }
(Q1, OO, Q4): 16,
(Q2, OO, Q1): 16,
(Q3, OO, Q2): 16,
(Q4, OO, Q3): 16,
# A --> OO --> A => { +2 (CCW), 0 (CW) }
(A1, OO, A1): 17,
(A2, OO, A2): 17,
(A3, OO, A3): 17,
(A4, OO, A4): 17,
# Q --> OO --> Q => { +2 (CCW), 0 (CW) }
(Q1, OO, Q1): 18,
(Q2, OO, Q2): 18,
(Q3, OO, Q3): 18,
(Q4, OO, Q4): 18,
}
_values = {
0: [( 0, 1)],
1: [(+1, 4)],
2: [(-1, 4)],
3: [(+1, 4)],
4: [(-1, 4)],
-1: [(+9, 4), (+1, 4)],
-2: [(+7, 4), (-1, 4)],
-3: [(+9, 4), (+1, 4)],
-4: [(+7, 4), (-1, 4)],
+5: [(+1, 2)],
-5: [(-1, 2)],
7: [(+1, 1), (-1, 1)],
8: [(+1, 1), (-1, 1)],
9: [(+1, 2), (-3, 2)],
10: [(+3, 2), (-1, 2)],
11: [(+3, 4), (-5, 4)],
12: [(+5, 4), (-3, 4)],
13: [(+5, 4), (-3, 4)],
14: [(+3, 4), (-5, 4)],
15: [(+1, 2), (-3, 2)],
16: [(+3, 2), (-1, 2)],
17: [(+2, 1), ( 0, 1)],
18: [(+2, 1), ( 0, 1)],
}
def _classify_point(re, im):
"""Return the half-axis (or origin) on which (re, im) point is located. """
if not re and not im:
return OO
if not re:
if im > 0:
return A2
else:
return A4
elif not im:
if re > 0:
return A1
else:
return A3
def _intervals_to_quadrants(intervals, f1, f2, s, t, F):
"""Generate a sequence of extended quadrants from a list of critical points. """
if not intervals:
return []
Q = []
if not f1:
(a, b), _, _ = intervals[0]
if a == b == s:
if len(intervals) == 1:
if dup_eval(f2, t, F) > 0:
return [OO, A2]
else:
return [OO, A4]
else:
(a, _), _, _ = intervals[1]
if dup_eval(f2, (s + a)/2, F) > 0:
Q.extend([OO, A2])
f2_sgn = +1
else:
Q.extend([OO, A4])
f2_sgn = -1
intervals = intervals[1:]
else:
if dup_eval(f2, s, F) > 0:
Q.append(A2)
f2_sgn = +1
else:
Q.append(A4)
f2_sgn = -1
for (a, _), indices, _ in intervals:
Q.append(OO)
if indices[1] % 2 == 1:
f2_sgn = -f2_sgn
if a != t:
if f2_sgn > 0:
Q.append(A2)
else:
Q.append(A4)
return Q
if not f2:
(a, b), _, _ = intervals[0]
if a == b == s:
if len(intervals) == 1:
if dup_eval(f1, t, F) > 0:
return [OO, A1]
else:
return [OO, A3]
else:
(a, _), _, _ = intervals[1]
if dup_eval(f1, (s + a)/2, F) > 0:
Q.extend([OO, A1])
f1_sgn = +1
else:
Q.extend([OO, A3])
f1_sgn = -1
intervals = intervals[1:]
else:
if dup_eval(f1, s, F) > 0:
Q.append(A1)
f1_sgn = +1
else:
Q.append(A3)
f1_sgn = -1
for (a, _), indices, _ in intervals:
Q.append(OO)
if indices[0] % 2 == 1:
f1_sgn = -f1_sgn
if a != t:
if f1_sgn > 0:
Q.append(A1)
else:
Q.append(A3)
return Q
re = dup_eval(f1, s, F)
im = dup_eval(f2, s, F)
if not re or not im:
Q.append(_classify_point(re, im))
if len(intervals) == 1:
re = dup_eval(f1, t, F)
im = dup_eval(f2, t, F)
else:
(a, _), _, _ = intervals[1]
re = dup_eval(f1, (s + a)/2, F)
im = dup_eval(f2, (s + a)/2, F)
intervals = intervals[1:]
if re > 0:
f1_sgn = +1
else:
f1_sgn = -1
if im > 0:
f2_sgn = +1
else:
f2_sgn = -1
sgn = {
(+1, +1): Q1,
(-1, +1): Q2,
(-1, -1): Q3,
(+1, -1): Q4,
}
Q.append(sgn[(f1_sgn, f2_sgn)])
for (a, b), indices, _ in intervals:
if a == b:
re = dup_eval(f1, a, F)
im = dup_eval(f2, a, F)
cls = _classify_point(re, im)
if cls is not None:
Q.append(cls)
if 0 in indices:
if indices[0] % 2 == 1:
f1_sgn = -f1_sgn
if 1 in indices:
if indices[1] % 2 == 1:
f2_sgn = -f2_sgn
if not (a == b and b == t):
Q.append(sgn[(f1_sgn, f2_sgn)])
return Q
def _traverse_quadrants(Q_L1, Q_L2, Q_L3, Q_L4, exclude=None):
"""Transform sequences of quadrants to a sequence of rules. """
if exclude is True:
edges = [1, 1, 0, 0]
corners = {
(0, 1): 1,
(1, 2): 1,
(2, 3): 0,
(3, 0): 1,
}
else:
edges = [0, 0, 0, 0]
corners = {
(0, 1): 0,
(1, 2): 0,
(2, 3): 0,
(3, 0): 0,
}
if exclude is not None and exclude is not True:
exclude = set(exclude)
for i, edge in enumerate(['S', 'E', 'N', 'W']):
if edge in exclude:
edges[i] = 1
for i, corner in enumerate(['SW', 'SE', 'NE', 'NW']):
if corner in exclude:
corners[((i - 1) % 4, i)] = 1
QQ, rules = [Q_L1, Q_L2, Q_L3, Q_L4], []
for i, Q in enumerate(QQ):
if not Q:
continue
if Q[-1] == OO:
Q = Q[:-1]
if Q[0] == OO:
j, Q = (i - 1) % 4, Q[1:]
qq = (QQ[j][-2], OO, Q[0])
if qq in _rules_ambiguous:
rules.append((_rules_ambiguous[qq], corners[(j, i)]))
else:
raise NotImplementedError("3 element rule (corner): " + str(qq))
q1, k = Q[0], 1
while k < len(Q):
q2, k = Q[k], k + 1
if q2 != OO:
qq = (q1, q2)
if qq in _rules_simple:
rules.append((_rules_simple[qq], 0))
elif qq in _rules_ambiguous:
rules.append((_rules_ambiguous[qq], edges[i]))
else:
raise NotImplementedError("2 element rule (inside): " + str(qq))
else:
qq, k = (q1, q2, Q[k]), k + 1
if qq in _rules_ambiguous:
rules.append((_rules_ambiguous[qq], edges[i]))
else:
raise NotImplementedError("3 element rule (edge): " + str(qq))
q1 = qq[-1]
return rules
def _reverse_intervals(intervals):
"""Reverse intervals for traversal from right to left and from top to bottom. """
return [ ((b, a), indices, f) for (a, b), indices, f in reversed(intervals) ]
def _winding_number(T, field):
"""Compute the winding number of the input polynomial, i.e. the number of roots. """
return int(sum([ field(*_values[t][i]) for t, i in T ]) / field(2))
def dup_count_complex_roots(f, K, inf=None, sup=None, exclude=None):
"""Count all roots in [u + v*I, s + t*I] rectangle using Collins-Krandick algorithm. """
if not K.is_ZZ and not K.is_QQ:
raise DomainError("complex root counting is not supported over %s" % K)
if K.is_ZZ:
R, F = K, K.get_field()
else:
R, F = K.get_ring(), K
f = dup_convert(f, K, F)
if inf is None or sup is None:
n, lc = dup_degree(f), abs(dup_LC(f, F))
B = 2*max([ F.quo(abs(c), lc) for c in f ])
if inf is None:
(u, v) = (-B, -B)
else:
(u, v) = inf
if sup is None:
(s, t) = (+B, +B)
else:
(s, t) = sup
f1, f2 = dup_real_imag(f, F)
f1L1F = dmp_eval_in(f1, v, 1, 1, F)
f2L1F = dmp_eval_in(f2, v, 1, 1, F)
_, f1L1R = dup_clear_denoms(f1L1F, F, R, convert=True)
_, f2L1R = dup_clear_denoms(f2L1F, F, R, convert=True)
f1L2F = dmp_eval_in(f1, s, 0, 1, F)
f2L2F = dmp_eval_in(f2, s, 0, 1, F)
_, f1L2R = dup_clear_denoms(f1L2F, F, R, convert=True)
_, f2L2R = dup_clear_denoms(f2L2F, F, R, convert=True)
f1L3F = dmp_eval_in(f1, t, 1, 1, F)
f2L3F = dmp_eval_in(f2, t, 1, 1, F)
_, f1L3R = dup_clear_denoms(f1L3F, F, R, convert=True)
_, f2L3R = dup_clear_denoms(f2L3F, F, R, convert=True)
f1L4F = dmp_eval_in(f1, u, 0, 1, F)
f2L4F = dmp_eval_in(f2, u, 0, 1, F)
_, f1L4R = dup_clear_denoms(f1L4F, F, R, convert=True)
_, f2L4R = dup_clear_denoms(f2L4F, F, R, convert=True)
S_L1 = [f1L1R, f2L1R]
S_L2 = [f1L2R, f2L2R]
S_L3 = [f1L3R, f2L3R]
S_L4 = [f1L4R, f2L4R]
I_L1 = dup_isolate_real_roots_list(S_L1, R, inf=u, sup=s, fast=True, basis=True, strict=True)
I_L2 = dup_isolate_real_roots_list(S_L2, R, inf=v, sup=t, fast=True, basis=True, strict=True)
I_L3 = dup_isolate_real_roots_list(S_L3, R, inf=u, sup=s, fast=True, basis=True, strict=True)
I_L4 = dup_isolate_real_roots_list(S_L4, R, inf=v, sup=t, fast=True, basis=True, strict=True)
I_L3 = _reverse_intervals(I_L3)
I_L4 = _reverse_intervals(I_L4)
Q_L1 = _intervals_to_quadrants(I_L1, f1L1F, f2L1F, u, s, F)
Q_L2 = _intervals_to_quadrants(I_L2, f1L2F, f2L2F, v, t, F)
Q_L3 = _intervals_to_quadrants(I_L3, f1L3F, f2L3F, s, u, F)
Q_L4 = _intervals_to_quadrants(I_L4, f1L4F, f2L4F, t, v, F)
T = _traverse_quadrants(Q_L1, Q_L2, Q_L3, Q_L4, exclude=exclude)
return _winding_number(T, F)
def _vertical_bisection(N, a, b, I, Q, F1, F2, f1, f2, F):
"""Vertical bisection step in Collins-Krandick root isolation algorithm. """
(u, v), (s, t) = a, b
I_L1, I_L2, I_L3, I_L4 = I
Q_L1, Q_L2, Q_L3, Q_L4 = Q
f1L1F, f1L2F, f1L3F, f1L4F = F1
f2L1F, f2L2F, f2L3F, f2L4F = F2
x = (u + s) / 2
f1V = dmp_eval_in(f1, x, 0, 1, F)
f2V = dmp_eval_in(f2, x, 0, 1, F)
I_V = dup_isolate_real_roots_list([f1V, f2V], F, inf=v, sup=t, fast=True, strict=True, basis=True)
I_L1_L, I_L1_R = [], []
I_L2_L, I_L2_R = I_V, I_L2
I_L3_L, I_L3_R = [], []
I_L4_L, I_L4_R = I_L4, _reverse_intervals(I_V)
for I in I_L1:
(a, b), indices, h = I
if a == b:
if a == x:
I_L1_L.append(I)
I_L1_R.append(I)
elif a < x:
I_L1_L.append(I)
else:
I_L1_R.append(I)
else:
if b <= x:
I_L1_L.append(I)
elif a >= x:
I_L1_R.append(I)
else:
a, b = dup_refine_real_root(h, a, b, F.get_ring(), disjoint=x, fast=True)
if b <= x:
I_L1_L.append(((a, b), indices, h))
if a >= x:
I_L1_R.append(((a, b), indices, h))
for I in I_L3:
(b, a), indices, h = I
if a == b:
if a == x:
I_L3_L.append(I)
I_L3_R.append(I)
elif a < x:
I_L3_L.append(I)
else:
I_L3_R.append(I)
else:
if b <= x:
I_L3_L.append(I)
elif a >= x:
I_L3_R.append(I)
else:
a, b = dup_refine_real_root(h, a, b, F.get_ring(), disjoint=x, fast=True)
if b <= x:
I_L3_L.append(((b, a), indices, h))
if a >= x:
I_L3_R.append(((b, a), indices, h))
Q_L1_L = _intervals_to_quadrants(I_L1_L, f1L1F, f2L1F, u, x, F)
Q_L2_L = _intervals_to_quadrants(I_L2_L, f1V, f2V, v, t, F)
Q_L3_L = _intervals_to_quadrants(I_L3_L, f1L3F, f2L3F, x, u, F)
Q_L4_L = Q_L4
Q_L1_R = _intervals_to_quadrants(I_L1_R, f1L1F, f2L1F, x, s, F)
Q_L2_R = Q_L2
Q_L3_R = _intervals_to_quadrants(I_L3_R, f1L3F, f2L3F, s, x, F)
Q_L4_R = _intervals_to_quadrants(I_L4_R, f1V, f2V, t, v, F)
T_L = _traverse_quadrants(Q_L1_L, Q_L2_L, Q_L3_L, Q_L4_L, exclude=True)
T_R = _traverse_quadrants(Q_L1_R, Q_L2_R, Q_L3_R, Q_L4_R, exclude=True)
N_L = _winding_number(T_L, F)
N_R = _winding_number(T_R, F)
I_L = (I_L1_L, I_L2_L, I_L3_L, I_L4_L)
Q_L = (Q_L1_L, Q_L2_L, Q_L3_L, Q_L4_L)
I_R = (I_L1_R, I_L2_R, I_L3_R, I_L4_R)
Q_R = (Q_L1_R, Q_L2_R, Q_L3_R, Q_L4_R)
F1_L = (f1L1F, f1V, f1L3F, f1L4F)
F2_L = (f2L1F, f2V, f2L3F, f2L4F)
F1_R = (f1L1F, f1L2F, f1L3F, f1V)
F2_R = (f2L1F, f2L2F, f2L3F, f2V)
a, b = (u, v), (x, t)
c, d = (x, v), (s, t)
D_L = (N_L, a, b, I_L, Q_L, F1_L, F2_L)
D_R = (N_R, c, d, I_R, Q_R, F1_R, F2_R)
return D_L, D_R
def _horizontal_bisection(N, a, b, I, Q, F1, F2, f1, f2, F):
"""Horizontal bisection step in Collins-Krandick root isolation algorithm. """
(u, v), (s, t) = a, b
I_L1, I_L2, I_L3, I_L4 = I
Q_L1, Q_L2, Q_L3, Q_L4 = Q
f1L1F, f1L2F, f1L3F, f1L4F = F1
f2L1F, f2L2F, f2L3F, f2L4F = F2
y = (v + t) / 2
f1H = dmp_eval_in(f1, y, 1, 1, F)
f2H = dmp_eval_in(f2, y, 1, 1, F)
I_H = dup_isolate_real_roots_list([f1H, f2H], F, inf=u, sup=s, fast=True, strict=True, basis=True)
I_L1_B, I_L1_U = I_L1, I_H
I_L2_B, I_L2_U = [], []
I_L3_B, I_L3_U = _reverse_intervals(I_H), I_L3
I_L4_B, I_L4_U = [], []
for I in I_L2:
(a, b), indices, h = I
if a == b:
if a == y:
I_L2_B.append(I)
I_L2_U.append(I)
elif a < y:
I_L2_B.append(I)
else:
I_L2_U.append(I)
else:
if b <= y:
I_L2_B.append(I)
elif a >= y:
I_L2_U.append(I)
else:
a, b = dup_refine_real_root(h, a, b, F.get_ring(), disjoint=y, fast=True)
if b <= y:
I_L2_B.append(((a, b), indices, h))
if a >= y:
I_L2_U.append(((a, b), indices, h))
for I in I_L4:
(b, a), indices, h = I
if a == b:
if a == y:
I_L4_B.append(I)
I_L4_U.append(I)
elif a < y:
I_L4_B.append(I)
else:
I_L4_U.append(I)
else:
if b <= y:
I_L4_B.append(I)
elif a >= y:
I_L4_U.append(I)
else:
a, b = dup_refine_real_root(h, a, b, F.get_ring(), disjoint=y, fast=True)
if b <= y:
I_L4_B.append(((b, a), indices, h))
if a >= y:
I_L4_U.append(((b, a), indices, h))
Q_L1_B = Q_L1
Q_L2_B = _intervals_to_quadrants(I_L2_B, f1L2F, f2L2F, v, y, F)
Q_L3_B = _intervals_to_quadrants(I_L3_B, f1H, f2H, s, u, F)
Q_L4_B = _intervals_to_quadrants(I_L4_B, f1L4F, f2L4F, y, v, F)
Q_L1_U = _intervals_to_quadrants(I_L1_U, f1H, f2H, u, s, F)
Q_L2_U = _intervals_to_quadrants(I_L2_U, f1L2F, f2L2F, y, t, F)
Q_L3_U = Q_L3
Q_L4_U = _intervals_to_quadrants(I_L4_U, f1L4F, f2L4F, t, y, F)
T_B = _traverse_quadrants(Q_L1_B, Q_L2_B, Q_L3_B, Q_L4_B, exclude=True)
T_U = _traverse_quadrants(Q_L1_U, Q_L2_U, Q_L3_U, Q_L4_U, exclude=True)
N_B = _winding_number(T_B, F)
N_U = _winding_number(T_U, F)
I_B = (I_L1_B, I_L2_B, I_L3_B, I_L4_B)
Q_B = (Q_L1_B, Q_L2_B, Q_L3_B, Q_L4_B)
I_U = (I_L1_U, I_L2_U, I_L3_U, I_L4_U)
Q_U = (Q_L1_U, Q_L2_U, Q_L3_U, Q_L4_U)
F1_B = (f1L1F, f1L2F, f1H, f1L4F)
F2_B = (f2L1F, f2L2F, f2H, f2L4F)
F1_U = (f1H, f1L2F, f1L3F, f1L4F)
F2_U = (f2H, f2L2F, f2L3F, f2L4F)
a, b = (u, v), (s, y)
c, d = (u, y), (s, t)
D_B = (N_B, a, b, I_B, Q_B, F1_B, F2_B)
D_U = (N_U, c, d, I_U, Q_U, F1_U, F2_U)
return D_B, D_U
def _depth_first_select(rectangles):
"""Find a rectangle of minimum area for bisection. """
min_area, j = None, None
for i, (_, (u, v), (s, t), _, _, _, _) in enumerate(rectangles):
area = (s - u)*(t - v)
if min_area is None or area < min_area:
min_area, j = area, i
return rectangles.pop(j)
def _rectangle_small_p(a, b, eps):
"""Return ``True`` if the given rectangle is small enough. """
(u, v), (s, t) = a, b
if eps is not None:
return s - u < eps and t - v < eps
else:
return True
def dup_isolate_complex_roots_sqf(f, K, eps=None, inf=None, sup=None, blackbox=False):
"""Isolate complex roots of a square-free polynomial using Collins-Krandick algorithm. """
if not K.is_ZZ and not K.is_QQ:
raise DomainError("isolation of complex roots is not supported over %s" % K)
if dup_degree(f) <= 0:
return []
if K.is_ZZ:
R, F = K, K.get_field()
else:
R, F = K.get_ring(), K
f = dup_convert(f, K, F)
n, lc = dup_degree(f), abs(dup_LC(f, F))
B = 2*max([ F.quo(abs(c), lc) for c in f ])
(u, v), (s, t) = (-B, F.zero), (B, B)
if inf is not None:
u = inf
if sup is not None:
s = sup
if v < 0 or t <= v or s <= u:
raise ValueError("not a valid complex isolation rectangle")
f1, f2 = dup_real_imag(f, F)
f1L1 = dmp_eval_in(f1, v, 1, 1, F)
f2L1 = dmp_eval_in(f2, v, 1, 1, F)
f1L2 = dmp_eval_in(f1, s, 0, 1, F)
f2L2 = dmp_eval_in(f2, s, 0, 1, F)
f1L3 = dmp_eval_in(f1, t, 1, 1, F)
f2L3 = dmp_eval_in(f2, t, 1, 1, F)
f1L4 = dmp_eval_in(f1, u, 0, 1, F)
f2L4 = dmp_eval_in(f2, u, 0, 1, F)
S_L1 = [f1L1, f2L1]
S_L2 = [f1L2, f2L2]
S_L3 = [f1L3, f2L3]
S_L4 = [f1L4, f2L4]
I_L1 = dup_isolate_real_roots_list(S_L1, F, inf=u, sup=s, fast=True, strict=True, basis=True)
I_L2 = dup_isolate_real_roots_list(S_L2, F, inf=v, sup=t, fast=True, strict=True, basis=True)
I_L3 = dup_isolate_real_roots_list(S_L3, F, inf=u, sup=s, fast=True, strict=True, basis=True)
I_L4 = dup_isolate_real_roots_list(S_L4, F, inf=v, sup=t, fast=True, strict=True, basis=True)
I_L3 = _reverse_intervals(I_L3)
I_L4 = _reverse_intervals(I_L4)
Q_L1 = _intervals_to_quadrants(I_L1, f1L1, f2L1, u, s, F)
Q_L2 = _intervals_to_quadrants(I_L2, f1L2, f2L2, v, t, F)
Q_L3 = _intervals_to_quadrants(I_L3, f1L3, f2L3, s, u, F)
Q_L4 = _intervals_to_quadrants(I_L4, f1L4, f2L4, t, v, F)
T = _traverse_quadrants(Q_L1, Q_L2, Q_L3, Q_L4)
N = _winding_number(T, F)
if not N:
return []
I = (I_L1, I_L2, I_L3, I_L4)
Q = (Q_L1, Q_L2, Q_L3, Q_L4)
F1 = (f1L1, f1L2, f1L3, f1L4)
F2 = (f2L1, f2L2, f2L3, f2L4)
rectangles, roots = [(N, (u, v), (s, t), I, Q, F1, F2)], []
while rectangles:
N, (u, v), (s, t), I, Q, F1, F2 = _depth_first_select(rectangles)
if s - u > t - v:
D_L, D_R = _vertical_bisection(N, (u, v), (s, t), I, Q, F1, F2, f1, f2, F)
N_L, a, b, I_L, Q_L, F1_L, F2_L = D_L
N_R, c, d, I_R, Q_R, F1_R, F2_R = D_R
if N_L >= 1:
if N_L == 1 and _rectangle_small_p(a, b, eps):
roots.append(ComplexInterval(a, b, I_L, Q_L, F1_L, F2_L, f1, f2, F))
else:
rectangles.append(D_L)
if N_R >= 1:
if N_R == 1 and _rectangle_small_p(c, d, eps):
roots.append(ComplexInterval(c, d, I_R, Q_R, F1_R, F2_R, f1, f2, F))
else:
rectangles.append(D_R)
else:
D_B, D_U = _horizontal_bisection(N, (u, v), (s, t), I, Q, F1, F2, f1, f2, F)
N_B, a, b, I_B, Q_B, F1_B, F2_B = D_B
N_U, c, d, I_U, Q_U, F1_U, F2_U = D_U
if N_B >= 1:
if N_B == 1 and _rectangle_small_p(a, b, eps):
roots.append(ComplexInterval(
a, b, I_B, Q_B, F1_B, F2_B, f1, f2, F))
else:
rectangles.append(D_B)
if N_U >= 1:
if N_U == 1 and _rectangle_small_p(c, d, eps):
roots.append(ComplexInterval(
c, d, I_U, Q_U, F1_U, F2_U, f1, f2, F))
else:
rectangles.append(D_U)
_roots, roots = sorted(roots, key=lambda r: (r.ax, r.ay)), []
for root in _roots:
roots.extend([root.conjugate(), root])
if blackbox:
return roots
else:
return [ r.as_tuple() for r in roots ]
def dup_isolate_all_roots_sqf(f, K, eps=None, inf=None, sup=None, fast=False, blackbox=False):
"""Isolate real and complex roots of a square-free polynomial ``f``. """
return (
dup_isolate_real_roots_sqf( f, K, eps=eps, inf=inf, sup=sup, fast=fast, blackbox=blackbox),
dup_isolate_complex_roots_sqf(f, K, eps=eps, inf=inf, sup=sup, blackbox=blackbox))
def dup_isolate_all_roots(f, K, eps=None, inf=None, sup=None, fast=False):
"""Isolate real and complex roots of a non-square-free polynomial ``f``. """
if not K.is_ZZ and not K.is_QQ:
raise DomainError("isolation of real and complex roots is not supported over %s" % K)
_, factors = dup_sqf_list(f, K)
if len(factors) == 1:
((f, k),) = factors
real_part, complex_part = dup_isolate_all_roots_sqf(
f, K, eps=eps, inf=inf, sup=sup, fast=fast)
real_part = [ ((a, b), k) for (a, b) in real_part ]
complex_part = [ ((a, b), k) for (a, b) in complex_part ]
return real_part, complex_part
else:
raise NotImplementedError( "only trivial square-free polynomials are supported")
class RealInterval(object):
"""A fully qualified representation of a real isolation interval. """
def __init__(self, data, f, dom):
"""Initialize new real interval with complete information. """
if len(data) == 2:
s, t = data
self.neg = False
if s < 0:
if t <= 0:
f, s, t, self.neg = dup_mirror(f, dom), -t, -s, True
else:
raise ValueError("can't refine a real root in (%s, %s)" % (s, t))
a, b, c, d = _mobius_from_interval((s, t), dom.get_field())
f = dup_transform(f, dup_strip([a, b]),
dup_strip([c, d]), dom)
self.mobius = a, b, c, d
else:
self.mobius = data[:-1]
self.neg = data[-1]
self.f, self.dom = f, dom
@property
def a(self):
"""Return the position of the left end. """
field = self.dom.get_field()
a, b, c, d = self.mobius
if not self.neg:
if a*d < b*c:
return field(a, c)
return field(b, d)
else:
if a*d > b*c:
return -field(a, c)
return -field(b, d)
@property
def b(self):
"""Return the position of the right end. """
was = self.neg
self.neg = not was
rv = -self.a
self.neg = was
return rv
@property
def dx(self):
"""Return width of the real isolating interval. """
return self.b - self.a
@property
def center(self):
"""Return the center of the real isolating interval. """
return (self.a + self.b)/2
def as_tuple(self):
"""Return tuple representation of real isolating interval. """
return (self.a, self.b)
def __repr__(self):
return "(%s, %s)" % (self.a, self.b)
def is_disjoint(self, other):
"""Return ``True`` if two isolation intervals are disjoint. """
return (self.b <= other.a or other.b <= self.a)
def _inner_refine(self):
"""Internal one step real root refinement procedure. """
if self.mobius is None:
return self
f, mobius = dup_inner_refine_real_root(
self.f, self.mobius, self.dom, steps=1, mobius=True)
return RealInterval(mobius + (self.neg,), f, self.dom)
def refine_disjoint(self, other):
"""Refine an isolating interval until it is disjoint with another one. """
expr = self
while not expr.is_disjoint(other):
expr, other = expr._inner_refine(), other._inner_refine()
return expr, other
def refine_size(self, dx):
"""Refine an isolating interval until it is of sufficiently small size. """
expr = self
while not (expr.dx < dx):
expr = expr._inner_refine()
return expr
def refine_step(self, steps=1):
"""Perform several steps of real root refinement algorithm. """
expr = self
for _ in range(steps):
expr = expr._inner_refine()
return expr
def refine(self):
"""Perform one step of real root refinement algorithm. """
return self._inner_refine()
class ComplexInterval(object):
"""A fully qualified representation of a complex isolation interval.
The printed form is shown as (x1, y1) x (x2, y2): the southwest x northeast
coordinates of the interval's rectangle."""
def __init__(self, a, b, I, Q, F1, F2, f1, f2, dom, conj=False):
"""Initialize new complex interval with complete information. """
self.a, self.b = a, b # the southwest and northeast corner: (x1, y1), (x2, y2)
self.I, self.Q = I, Q
self.f1, self.F1 = f1, F1
self.f2, self.F2 = f2, F2
self.dom = dom
self.conj = conj
@property
def ax(self):
"""Return ``x`` coordinate of south-western corner. """
return self.a[0]
@property
def ay(self):
"""Return ``y`` coordinate of south-western corner. """
if not self.conj:
return self.a[1]
else:
return -self.b[1]
@property
def bx(self):
"""Return ``x`` coordinate of north-eastern corner. """
return self.b[0]
@property
def by(self):
"""Return ``y`` coordinate of north-eastern corner. """
if not self.conj:
return self.b[1]
else:
return -self.a[1]
@property
def dx(self):
"""Return width of the complex isolating interval. """
return self.b[0] - self.a[0]
@property
def dy(self):
"""Return height of the complex isolating interval. """
return self.b[1] - self.a[1]
@property
def center(self):
"""Return the center of the complex isolating interval. """
return ((self.ax + self.bx)/2, (self.ay + self.by)/2)
def as_tuple(self):
"""Return tuple representation of complex isolating interval. """
return ((self.ax, self.ay), (self.bx, self.by))
def __repr__(self):
return "(%s, %s) x (%s, %s)" % (self.ax, self.bx, self.ay, self.by)
def conjugate(self):
"""This complex interval really is located in lower half-plane. """
return ComplexInterval(self.a, self.b, self.I, self.Q,
self.F1, self.F2, self.f1, self.f2, self.dom, conj=True)
def is_disjoint(self, other):
"""Return ``True`` if two isolation intervals are disjoint. """
if self.conj != other.conj:
return True
re_distinct = (self.bx <= other.ax or other.bx <= self.ax)
if re_distinct:
return True
im_distinct = (self.by <= other.ay or other.by <= self.ay)
return im_distinct
def _inner_refine(self):
"""Internal one step complex root refinement procedure. """
(u, v), (s, t) = self.a, self.b
I, Q = self.I, self.Q
f1, F1 = self.f1, self.F1
f2, F2 = self.f2, self.F2
dom = self.dom
if s - u > t - v:
D_L, D_R = _vertical_bisection(1, (u, v), (s, t), I, Q, F1, F2, f1, f2, dom)
if D_L[0] == 1:
_, a, b, I, Q, F1, F2 = D_L
else:
_, a, b, I, Q, F1, F2 = D_R
else:
D_B, D_U = _horizontal_bisection(1, (u, v), (s, t), I, Q, F1, F2, f1, f2, dom)
if D_B[0] == 1:
_, a, b, I, Q, F1, F2 = D_B
else:
_, a, b, I, Q, F1, F2 = D_U
return ComplexInterval(a, b, I, Q, F1, F2, f1, f2, dom, self.conj)
def refine_disjoint(self, other):
"""Refine an isolating interval until it is disjoint with another one. """
expr = self
while not expr.is_disjoint(other):
expr, other = expr._inner_refine(), other._inner_refine()
return expr, other
def refine_size(self, dx, dy=None):
"""Refine an isolating interval until it is of sufficiently small size. """
if dy is None:
dy = dx
expr = self
while not (expr.dx < dx and expr.dy < dy):
expr = expr._inner_refine()
return expr
def refine_step(self, steps=1):
"""Perform several steps of complex root refinement algorithm. """
expr = self
for _ in range(steps):
expr = expr._inner_refine()
return expr
def refine(self):
"""Perform one step of complex root refinement algorithm. """
return self._inner_refine()
|
bsd-3-clause
|
[
624,
10099,
436,
6114,
1738,
30567,
436,
2984,
1132,
434,
18036,
14,
408,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
5840,
14,
15743,
14,
7253,
4316,
492,
334,
272,
11866,
63,
7027,
12,
11866,
63,
5708,
12,
11866,
63,
10956,
12,
272,
11866,
63,
1913,
12,
11866,
63,
4471,
12,
272,
11866,
63,
3916,
12,
272,
11866,
63,
9187,
63,
22795,
9,
199,
199,
504,
5840,
14,
15743,
14,
7253,
18327,
492,
334,
272,
11866,
63,
8705,
12,
11866,
63,
82,
4723,
12,
11866,
63,
13179,
9,
199,
199,
504,
5840,
14,
15743,
14,
848,
409,
5998,
492,
334,
272,
11866,
63,
3584,
63,
848,
22491,
12,
272,
11866,
63,
12324,
12,
11866,
63,
3467,
12,
11866,
63,
4723,
12,
272,
11866,
63,
4711,
12,
272,
11866,
63,
3028,
12,
272,
11866,
63,
2579,
12,
14605,
63,
2579,
63,
262,
12,
272,
11866,
63,
1037,
63,
3808,
1298,
12,
272,
11866,
63,
3093,
63,
14688,
9,
199,
199,
504,
5840,
14,
15743,
14,
3526,
70,
7936,
5998,
492,
334,
272,
11866,
63,
3526,
70,
63,
2064,
12,
11866,
63,
3526,
70,
63,
513,
9,
199,
199,
504,
5840,
14,
15743,
14,
7783,
361,
5998,
492,
334,
272,
11866,
63,
4778,
63,
513,
9,
199,
199,
504,
5840,
14,
15743,
14,
6023,
2550,
492,
334,
272,
15397,
1132,
434,
4276,
12,
272,
14061,
547,
9,
199,
199,
504,
5840,
14,
1018,
14,
15390,
492,
1425,
421,
199,
318,
11866,
63,
270,
12410,
8,
70,
12,
1804,
304,
272,
408,
272,
28040,
314,
1933,
12410,
3414,
402,
1124,
70,
1040,
315,
1124,
38,
59,
88,
30029,
339,
9138,
282,
17225,
18449,
12,
12386,
13,
4624,
11849,
1124,
70,
8,
88,
9719,
2529,
314,
272,
4568,
1933,
12410,
3414,
1124,
70,
63,
16,
8,
88,
395,
14263,
289,
63,
78,
8,
88,
9719,
3247,
701,
447,
10817,
289,
63,
16,
8,
88,
395,
289,
63,
17,
8,
88,
9,
275,
289,
8,
88,
395,
289,
6774,
88,
9,
2126,
289,
63,
78,
275,
446,
13179,
8,
70,
7348,
78,
13,
18,
22999,
88,
395,
289,
7348,
78,
13,
17,
22999,
88,
430,
339,
6058,
272,
12655,
339,
1306,
687,
5840,
14,
15743,
492,
12133,
12,
16679,
272,
1306,
820,
12,
671,
275,
12133,
480,
88,
401,
16679,
9,
339,
1306,
820,
14,
11048,
63,
270,
12410,
8,
88,
538,
19,
446,
499,
10,
88,
538,
18,
435,
671,
446,
650,
9,
272,
359,
88,
538,
19,
446,
499,
10,
88,
538,
18,
435,
671,
446,
650,
12,
650,
10,
88,
538,
18,
446,
841,
10,
88,
435,
413,
12,
499,
15,
25,
10,
88,
435,
5661,
15,
25,
12,
446,
1165,
1965,
15,
20,
61,
339,
14504,
272,
21938,
339,
413,
14,
359,
36,
15556,
719,
1299,
25276,
339,
408,
272,
340,
440,
1804,
14,
1989,
63,
792,
26,
267,
746,
14061,
547,
480,
2425,
1133,
4526,
1933,
12410,
3414,
1806,
450,
83,
2,
450,
1804,
9,
339,
289,
275,
11866,
63,
3526,
70,
63,
2064,
8,
70,
12,
1804,
9,
339,
410,
12410,
275,
359,
70,
12,
11866,
63,
3028,
8,
70,
12,
413,
12,
1804,
1874,
339,
1830,
410,
12410,
1988,
17,
2189,
267,
308,
275,
11866,
63,
13179,
8,
270,
12410,
1988,
18,
467,
410,
12410,
1988,
17,
467,
1804,
9,
267,
410,
12410,
14,
740,
8,
11048,
63,
8705,
8,
83,
12,
1804,
430,
339,
372,
410,
12410,
4439,
17,
61,
199,
199,
318,
11866,
63,
1231,
63,
4142,
63,
3556,
8,
70,
12,
1804,
304,
272,
408,
8564,
314,
491,
14449,
7008,
3914,
367,
314,
7317,
14361,
402,
658,
70,
64,
27,
2126,
491,
14449,
334,
5339,
8228,
5843,
350,
19826,
9,
1990,
477,
27813,
701,
437,
75,
11133,
305,
13,
2848,
806,
13520,
10728,
13,
54,
528,
9503,
305,
14,
10817,
10944,
26,
2126,
21938,
2126,
4580,
8810,
12897,
2297,
598,
14,
437,
75,
11133,
305,
26,
298,
10608,
436,
5843,
350,
19826,
19178,
1209,
21972,
83,
641,
314,
1779,
13468,
402,
314,
30245,
12826,
83,
402,
8467,
8887,
83,
2,
1779,
22142,
402,
29347,
3599,
2699,
27491,
12,
16171,
14,
4114,
12,
3091,
14,
650,
12,
959,
1789,
13,
24416,
12,
8937,
14,
272,
408,
272,
302,
12,
510,
275,
822,
8,
70,
395,
942,
272,
307,
275,
302,
627,
359,
43,
14,
368,
61,
272,
340,
11866,
63,
7027,
8,
70,
12,
1804,
9,
665,
378,
26,
267,
289,
275,
11866,
63,
8705,
8,
70,
12,
1804,
9,
272,
289,
275,
769,
8,
13501,
8,
70,
430,
339,
367,
284,
315,
1425,
8,
16,
12,
302,
304,
267,
340,
289,
59,
73,
61,
2356,
378,
26,
288,
1980,
398,
282,
12,
1413,
44,
275,
1804,
14,
793,
2801,
70,
59,
73,
467,
499,
395,
942,
398,
367,
1335,
315,
1425,
8,
73,
435,
413,
12,
302,
304,
953,
340,
289,
59,
74,
61,
2695,
378,
26,
355,
1980,
953,
1894,
275,
307,
59,
74,
61,
435,
282,
446,
1804,
14,
793,
8,
70,
59,
74,
467,
499,
9,
288,
1413,
44,
14,
740,
779,
81,
5001,
334,
74,
446,
284,
9,
2360,
1335,
566,
398,
340,
440,
1413,
44,
26,
288,
1980,
398,
1894,
275,
1748,
8,
2940,
9,
398,
307,
59,
81,
59,
17,
2677,
275,
307,
59,
81,
59,
17,
2677,
435,
413,
398,
510,
14,
740,
8,
81,
59,
16,
566,
339,
340,
440,
510,
26,
267,
372,
488,
272,
587,
26,
267,
372,
1804,
14,
362,
63,
698,
24851,
18,
25288,
988,
8,
48,
9,
435,
413,
9,
199,
199,
318,
11866,
63,
1231,
63,
2325,
63,
3556,
8,
70,
12,
1804,
304,
272,
408,
8564,
314,
491,
14449,
5117,
3914,
367,
314,
7317,
14361,
402,
658,
70,
64,
27,
2126,
491,
14449,
334,
5339,
8228,
5843,
350,
19826,
9,
1990,
477,
27813,
701,
437,
75,
11133,
305,
13,
2848,
806,
13520,
10728,
13,
54,
528,
9503,
305,
14,
10817,
10944,
26,
2126,
21938,
2126,
4580,
8810,
12897,
2297,
598,
14,
437,
75,
11133,
305,
26,
298,
10608,
436,
5843,
350,
19826,
19178,
1209,
21972,
83,
641,
314,
1779,
13468,
402,
314,
30245,
12826,
83,
402,
8467,
8887,
83,
2,
1779,
22142,
402,
29347,
3599,
2699,
27491
] |
[
10099,
436,
6114,
1738,
30567,
436,
2984,
1132,
434,
18036,
14,
408,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
5840,
14,
15743,
14,
7253,
4316,
492,
334,
272,
11866,
63,
7027,
12,
11866,
63,
5708,
12,
11866,
63,
10956,
12,
272,
11866,
63,
1913,
12,
11866,
63,
4471,
12,
272,
11866,
63,
3916,
12,
272,
11866,
63,
9187,
63,
22795,
9,
199,
199,
504,
5840,
14,
15743,
14,
7253,
18327,
492,
334,
272,
11866,
63,
8705,
12,
11866,
63,
82,
4723,
12,
11866,
63,
13179,
9,
199,
199,
504,
5840,
14,
15743,
14,
848,
409,
5998,
492,
334,
272,
11866,
63,
3584,
63,
848,
22491,
12,
272,
11866,
63,
12324,
12,
11866,
63,
3467,
12,
11866,
63,
4723,
12,
272,
11866,
63,
4711,
12,
272,
11866,
63,
3028,
12,
272,
11866,
63,
2579,
12,
14605,
63,
2579,
63,
262,
12,
272,
11866,
63,
1037,
63,
3808,
1298,
12,
272,
11866,
63,
3093,
63,
14688,
9,
199,
199,
504,
5840,
14,
15743,
14,
3526,
70,
7936,
5998,
492,
334,
272,
11866,
63,
3526,
70,
63,
2064,
12,
11866,
63,
3526,
70,
63,
513,
9,
199,
199,
504,
5840,
14,
15743,
14,
7783,
361,
5998,
492,
334,
272,
11866,
63,
4778,
63,
513,
9,
199,
199,
504,
5840,
14,
15743,
14,
6023,
2550,
492,
334,
272,
15397,
1132,
434,
4276,
12,
272,
14061,
547,
9,
199,
199,
504,
5840,
14,
1018,
14,
15390,
492,
1425,
421,
199,
318,
11866,
63,
270,
12410,
8,
70,
12,
1804,
304,
272,
408,
272,
28040,
314,
1933,
12410,
3414,
402,
1124,
70,
1040,
315,
1124,
38,
59,
88,
30029,
339,
9138,
282,
17225,
18449,
12,
12386,
13,
4624,
11849,
1124,
70,
8,
88,
9719,
2529,
314,
272,
4568,
1933,
12410,
3414,
1124,
70,
63,
16,
8,
88,
395,
14263,
289,
63,
78,
8,
88,
9719,
3247,
701,
447,
10817,
289,
63,
16,
8,
88,
395,
289,
63,
17,
8,
88,
9,
275,
289,
8,
88,
395,
289,
6774,
88,
9,
2126,
289,
63,
78,
275,
446,
13179,
8,
70,
7348,
78,
13,
18,
22999,
88,
395,
289,
7348,
78,
13,
17,
22999,
88,
430,
339,
6058,
272,
12655,
339,
1306,
687,
5840,
14,
15743,
492,
12133,
12,
16679,
272,
1306,
820,
12,
671,
275,
12133,
480,
88,
401,
16679,
9,
339,
1306,
820,
14,
11048,
63,
270,
12410,
8,
88,
538,
19,
446,
499,
10,
88,
538,
18,
435,
671,
446,
650,
9,
272,
359,
88,
538,
19,
446,
499,
10,
88,
538,
18,
435,
671,
446,
650,
12,
650,
10,
88,
538,
18,
446,
841,
10,
88,
435,
413,
12,
499,
15,
25,
10,
88,
435,
5661,
15,
25,
12,
446,
1165,
1965,
15,
20,
61,
339,
14504,
272,
21938,
339,
413,
14,
359,
36,
15556,
719,
1299,
25276,
339,
408,
272,
340,
440,
1804,
14,
1989,
63,
792,
26,
267,
746,
14061,
547,
480,
2425,
1133,
4526,
1933,
12410,
3414,
1806,
450,
83,
2,
450,
1804,
9,
339,
289,
275,
11866,
63,
3526,
70,
63,
2064,
8,
70,
12,
1804,
9,
339,
410,
12410,
275,
359,
70,
12,
11866,
63,
3028,
8,
70,
12,
413,
12,
1804,
1874,
339,
1830,
410,
12410,
1988,
17,
2189,
267,
308,
275,
11866,
63,
13179,
8,
270,
12410,
1988,
18,
467,
410,
12410,
1988,
17,
467,
1804,
9,
267,
410,
12410,
14,
740,
8,
11048,
63,
8705,
8,
83,
12,
1804,
430,
339,
372,
410,
12410,
4439,
17,
61,
199,
199,
318,
11866,
63,
1231,
63,
4142,
63,
3556,
8,
70,
12,
1804,
304,
272,
408,
8564,
314,
491,
14449,
7008,
3914,
367,
314,
7317,
14361,
402,
658,
70,
64,
27,
2126,
491,
14449,
334,
5339,
8228,
5843,
350,
19826,
9,
1990,
477,
27813,
701,
437,
75,
11133,
305,
13,
2848,
806,
13520,
10728,
13,
54,
528,
9503,
305,
14,
10817,
10944,
26,
2126,
21938,
2126,
4580,
8810,
12897,
2297,
598,
14,
437,
75,
11133,
305,
26,
298,
10608,
436,
5843,
350,
19826,
19178,
1209,
21972,
83,
641,
314,
1779,
13468,
402,
314,
30245,
12826,
83,
402,
8467,
8887,
83,
2,
1779,
22142,
402,
29347,
3599,
2699,
27491,
12,
16171,
14,
4114,
12,
3091,
14,
650,
12,
959,
1789,
13,
24416,
12,
8937,
14,
272,
408,
272,
302,
12,
510,
275,
822,
8,
70,
395,
942,
272,
307,
275,
302,
627,
359,
43,
14,
368,
61,
272,
340,
11866,
63,
7027,
8,
70,
12,
1804,
9,
665,
378,
26,
267,
289,
275,
11866,
63,
8705,
8,
70,
12,
1804,
9,
272,
289,
275,
769,
8,
13501,
8,
70,
430,
339,
367,
284,
315,
1425,
8,
16,
12,
302,
304,
267,
340,
289,
59,
73,
61,
2356,
378,
26,
288,
1980,
398,
282,
12,
1413,
44,
275,
1804,
14,
793,
2801,
70,
59,
73,
467,
499,
395,
942,
398,
367,
1335,
315,
1425,
8,
73,
435,
413,
12,
302,
304,
953,
340,
289,
59,
74,
61,
2695,
378,
26,
355,
1980,
953,
1894,
275,
307,
59,
74,
61,
435,
282,
446,
1804,
14,
793,
8,
70,
59,
74,
467,
499,
9,
288,
1413,
44,
14,
740,
779,
81,
5001,
334,
74,
446,
284,
9,
2360,
1335,
566,
398,
340,
440,
1413,
44,
26,
288,
1980,
398,
1894,
275,
1748,
8,
2940,
9,
398,
307,
59,
81,
59,
17,
2677,
275,
307,
59,
81,
59,
17,
2677,
435,
413,
398,
510,
14,
740,
8,
81,
59,
16,
566,
339,
340,
440,
510,
26,
267,
372,
488,
272,
587,
26,
267,
372,
1804,
14,
362,
63,
698,
24851,
18,
25288,
988,
8,
48,
9,
435,
413,
9,
199,
199,
318,
11866,
63,
1231,
63,
2325,
63,
3556,
8,
70,
12,
1804,
304,
272,
408,
8564,
314,
491,
14449,
5117,
3914,
367,
314,
7317,
14361,
402,
658,
70,
64,
27,
2126,
491,
14449,
334,
5339,
8228,
5843,
350,
19826,
9,
1990,
477,
27813,
701,
437,
75,
11133,
305,
13,
2848,
806,
13520,
10728,
13,
54,
528,
9503,
305,
14,
10817,
10944,
26,
2126,
21938,
2126,
4580,
8810,
12897,
2297,
598,
14,
437,
75,
11133,
305,
26,
298,
10608,
436,
5843,
350,
19826,
19178,
1209,
21972,
83,
641,
314,
1779,
13468,
402,
314,
30245,
12826,
83,
402,
8467,
8887,
83,
2,
1779,
22142,
402,
29347,
3599,
2699,
27491,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
navycrow/Sick-Beard
|
lib/imdb/parser/http/searchCharacterParser.py
|
67
|
2793
|
"""
parser.http.searchCharacterParser module (imdb package).
This module provides the HTMLSearchCharacterParser class (and the
search_character_parser instance), used to parse the results of a search
for a given character.
E.g., when searching for the name "Jesse James", the parsed page would be:
http://akas.imdb.com/find?s=Characters;mx=20;q=Jesse+James
Copyright 2007-2009 Davide Alberani <da@erlug.linux.it>
2008 H. Turgut Uyar <uyar@tekir.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
from imdb.utils import analyze_name, build_name
from utils import Extractor, Attribute, analyze_imdbid
from searchMovieParser import DOMHTMLSearchMovieParser, DOMBasicMovieParser
class DOMBasicCharacterParser(DOMBasicMovieParser):
"""Simply get the name of a character and the imdbID.
It's used by the DOMHTMLSearchCharacterParser class to return a result
for a direct match (when a search on IMDb results in a single
character, the web server sends directly the movie page."""
_titleFunct = lambda self, x: analyze_name(x or u'', canonical=False)
class DOMHTMLSearchCharacterParser(DOMHTMLSearchMovieParser):
_BaseParser = DOMBasicCharacterParser
_notDirectHitTitle = '<title>imdb search'
_titleBuilder = lambda self, x: build_name(x, canonical=False)
_linkPrefix = '/character/ch'
_attrs = [Attribute(key='data',
multi=True,
path={
'link': "./a[1]/@href",
'name': "./a[1]/text()"
},
postprocess=lambda x: (
analyze_imdbid(x.get('link') or u''),
{'name': x.get('name')}
))]
extractors = [Extractor(label='search',
path="//td[3]/a[starts-with(@href, " \
"'/character/ch')]/..",
attrs=_attrs)]
_OBJECTS = {
'search_character_parser': ((DOMHTMLSearchCharacterParser,),
{'kind': 'character', '_basic_parser': DOMBasicCharacterParser})
}
|
gpl-3.0
|
[
624,
199,
2087,
14,
1014,
14,
1733,
14852,
2842,
859,
334,
17117,
2559,
680,
199,
199,
2765,
859,
6571,
314,
4163,
5278,
14852,
2842,
1021,
334,
460,
314,
199,
1733,
63,
10856,
63,
2087,
1256,
395,
1202,
370,
2198,
314,
2058,
402,
282,
2754,
199,
509,
282,
1627,
4528,
14,
199,
37,
14,
71,
2020,
1380,
18112,
367,
314,
536,
298,
42,
397,
261,
1603,
14015,
401,
314,
4565,
2034,
3955,
506,
26,
272,
1455,
921,
1151,
305,
14,
17117,
14,
957,
15,
1623,
31,
83,
29,
9272,
27,
9457,
29,
1165,
27,
81,
29,
42,
397,
261,
11,
42,
14015,
199,
199,
7384,
10219,
13,
8664,
577,
65,
5624,
4580,
605,
26455,
665,
983,
32,
281,
32047,
14,
5135,
14,
390,
30,
2049,
9079,
869,
14,
377,
17629,
337,
738,
89,
285,
665,
29514,
285,
32,
266,
75,
723,
14,
1308,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
624,
199,
199,
504,
18232,
14,
1208,
492,
19897,
63,
354,
12,
1900,
63,
354,
199,
504,
3778,
492,
18925,
12,
3882,
12,
19897,
63,
17117,
344,
199,
199,
504,
2754,
19088,
2842,
492,
14316,
4943,
5278,
19088,
2842,
12,
3506,
4567,
2484,
19088,
2842,
421,
199,
533,
3506,
4567,
2484,
14852,
2842,
8,
1649,
4567,
2484,
19088,
2842,
304,
272,
408,
51,
3236,
590,
664,
314,
536,
402,
282,
4528,
436,
314,
18232,
998,
14,
339,
2779,
1159,
1202,
701,
314,
14316,
4943,
5278,
14852,
2842,
1021,
370,
372,
282,
754,
272,
367,
282,
4125,
1336,
334,
6526,
282,
2754,
641,
473,
5127,
66,
2058,
315,
282,
2849,
272,
4528,
12,
314,
3330,
1654,
16178,
5370,
314,
14360,
2034,
1041,
272,
485,
1213,
38,
4638,
275,
2400,
291,
12,
671,
26,
19897,
63,
354,
8,
88,
503,
399,
6448,
11358,
29,
797,
9,
421,
199,
533,
14316,
4943,
5278,
14852,
2842,
8,
10462,
4943,
5278,
19088,
2842,
304,
272,
485,
1563,
2842,
275,
3506,
4567,
2484,
14852,
2842,
272,
485,
1397,
16281,
26852,
6888,
275,
2650,
1213,
30,
17117,
2754,
7,
272,
485,
1213,
6437,
275,
2400,
291,
12,
671,
26,
1900,
63,
354,
8,
88,
12,
11358,
29,
797,
9,
272,
485,
1073,
4793,
275,
1994,
10856,
15,
335,
7,
339,
485,
3288,
275,
359,
1646,
8,
498,
534,
576,
297,
717,
3510,
29,
549,
12,
717,
931,
3126,
1169,
283,
1073,
356,
26069,
65,
59,
17,
12978,
32,
6399,
401,
1169,
283,
354,
356,
26069,
65,
59,
17,
12978,
505,
16493,
1169,
1660,
717,
2963,
1412,
29,
2734,
671,
26,
334,
1169,
19897,
63,
17117,
344,
8,
88,
14,
362,
360,
1073,
358,
503,
399,
7,
659,
1169,
791,
354,
356,
671,
14,
362,
360,
354,
21004,
717,
5082,
61,
272,
2402,
13451,
275,
359,
11039,
8,
1302,
534,
1733,
297,
1169,
931,
628,
501,
2076,
59,
19,
12978,
65,
59,
17116,
13,
1045,
8,
32,
6399,
12,
298,
971,
2511,
3546,
15,
10856,
15,
335,
5440,
15,
703,
401,
1169,
3290,
3699,
3288,
1874,
421,
199,
63,
9868,
51,
275,
469,
267,
283,
1733,
63,
10856,
63,
2087,
356,
3666,
10462,
4943,
5278,
14852,
2842,
4706,
355,
791,
5091,
356,
283,
10856,
297,
2513,
4316,
63,
2087,
356,
3506,
4567,
2484,
14852,
2842,
1552,
199,
93,
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
] |
[
199,
2087,
14,
1014,
14,
1733,
14852,
2842,
859,
334,
17117,
2559,
680,
199,
199,
2765,
859,
6571,
314,
4163,
5278,
14852,
2842,
1021,
334,
460,
314,
199,
1733,
63,
10856,
63,
2087,
1256,
395,
1202,
370,
2198,
314,
2058,
402,
282,
2754,
199,
509,
282,
1627,
4528,
14,
199,
37,
14,
71,
2020,
1380,
18112,
367,
314,
536,
298,
42,
397,
261,
1603,
14015,
401,
314,
4565,
2034,
3955,
506,
26,
272,
1455,
921,
1151,
305,
14,
17117,
14,
957,
15,
1623,
31,
83,
29,
9272,
27,
9457,
29,
1165,
27,
81,
29,
42,
397,
261,
11,
42,
14015,
199,
199,
7384,
10219,
13,
8664,
577,
65,
5624,
4580,
605,
26455,
665,
983,
32,
281,
32047,
14,
5135,
14,
390,
30,
2049,
9079,
869,
14,
377,
17629,
337,
738,
89,
285,
665,
29514,
285,
32,
266,
75,
723,
14,
1308,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
624,
199,
199,
504,
18232,
14,
1208,
492,
19897,
63,
354,
12,
1900,
63,
354,
199,
504,
3778,
492,
18925,
12,
3882,
12,
19897,
63,
17117,
344,
199,
199,
504,
2754,
19088,
2842,
492,
14316,
4943,
5278,
19088,
2842,
12,
3506,
4567,
2484,
19088,
2842,
421,
199,
533,
3506,
4567,
2484,
14852,
2842,
8,
1649,
4567,
2484,
19088,
2842,
304,
272,
408,
51,
3236,
590,
664,
314,
536,
402,
282,
4528,
436,
314,
18232,
998,
14,
339,
2779,
1159,
1202,
701,
314,
14316,
4943,
5278,
14852,
2842,
1021,
370,
372,
282,
754,
272,
367,
282,
4125,
1336,
334,
6526,
282,
2754,
641,
473,
5127,
66,
2058,
315,
282,
2849,
272,
4528,
12,
314,
3330,
1654,
16178,
5370,
314,
14360,
2034,
1041,
272,
485,
1213,
38,
4638,
275,
2400,
291,
12,
671,
26,
19897,
63,
354,
8,
88,
503,
399,
6448,
11358,
29,
797,
9,
421,
199,
533,
14316,
4943,
5278,
14852,
2842,
8,
10462,
4943,
5278,
19088,
2842,
304,
272,
485,
1563,
2842,
275,
3506,
4567,
2484,
14852,
2842,
272,
485,
1397,
16281,
26852,
6888,
275,
2650,
1213,
30,
17117,
2754,
7,
272,
485,
1213,
6437,
275,
2400,
291,
12,
671,
26,
1900,
63,
354,
8,
88,
12,
11358,
29,
797,
9,
272,
485,
1073,
4793,
275,
1994,
10856,
15,
335,
7,
339,
485,
3288,
275,
359,
1646,
8,
498,
534,
576,
297,
717,
3510,
29,
549,
12,
717,
931,
3126,
1169,
283,
1073,
356,
26069,
65,
59,
17,
12978,
32,
6399,
401,
1169,
283,
354,
356,
26069,
65,
59,
17,
12978,
505,
16493,
1169,
1660,
717,
2963,
1412,
29,
2734,
671,
26,
334,
1169,
19897,
63,
17117,
344,
8,
88,
14,
362,
360,
1073,
358,
503,
399,
7,
659,
1169,
791,
354,
356,
671,
14,
362,
360,
354,
21004,
717,
5082,
61,
272,
2402,
13451,
275,
359,
11039,
8,
1302,
534,
1733,
297,
1169,
931,
628,
501,
2076,
59,
19,
12978,
65,
59,
17116,
13,
1045,
8,
32,
6399,
12,
298,
971,
2511,
3546,
15,
10856,
15,
335,
5440,
15,
703,
401,
1169,
3290,
3699,
3288,
1874,
421,
199,
63,
9868,
51,
275,
469,
267,
283,
1733,
63,
10856,
63,
2087,
356,
3666,
10462,
4943,
5278,
14852,
2842,
4706,
355,
791,
5091,
356,
283,
10856,
297,
2513,
4316,
63,
2087,
356,
3506,
4567,
2484,
14852,
2842,
1552,
199,
93,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
OpenAcademy-OpenStack/nova-scheduler
|
nova/tests/virt/vmwareapi/test_vm_util_datastore_selection.py
|
3
|
5170
|
#
# 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 collections
import re
from nova import test
from nova.virt.vmwareapi import vm_util
ResultSet = collections.namedtuple('ResultSet', ['objects'])
ResultSetToken = collections.namedtuple('ResultSet', ['objects', 'token'])
ObjectContent = collections.namedtuple('ObjectContent', ['obj', 'propSet'])
DynamicProperty = collections.namedtuple('Property', ['name', 'val'])
MoRef = collections.namedtuple('ManagedObjectReference', ['value'])
class VMwareVMUtilDatastoreSelectionTestCase(test.NoDBTestCase):
def setUp(self):
super(VMwareVMUtilDatastoreSelectionTestCase, self).setUp()
self.data = [
['VMFS', 'os-some-name', True, 987654321, 12346789],
['NFS', 'another-name', True, 9876543210, 123467890],
['BAD', 'some-name-bad', True, 98765432100, 1234678900],
['VMFS', 'some-name-good', False, 987654321, 12346789],
]
def build_result_set(self, mock_data, name_list=None):
# datastores will have a moref_id of ds-000 and
# so on based on their index in the mock_data list
if name_list is None:
name_list = self.propset_name_list
objects = []
for id, row in enumerate(mock_data):
obj = ObjectContent(
obj=MoRef(value="ds-%03d" % id),
propSet=[])
for index, value in enumerate(row):
obj.propSet.append(
DynamicProperty(name=name_list[index], val=row[index]))
objects.append(obj)
return ResultSet(objects=objects)
@property
def propset_name_list(self):
return ['summary.type', 'summary.name', 'summary.accessible',
'summary.capacity', 'summary.freeSpace']
def test_filter_datastores_simple(self):
datastores = self.build_result_set(self.data)
rec = vm_util._get_datastore_ref_and_name(datastores)
self.assertIsNotNone(rec[0], "could not find datastore!")
self.assertEqual('ds-001', rec[0].value,
"didn't find the right datastore!")
self.assertEqual(123467890, rec[3],
"did not obtain correct freespace!")
def test_filter_datastores_empty(self):
data = []
datastores = self.build_result_set(data)
rec = vm_util._get_datastore_ref_and_name(datastores)
self.assertIsNone(rec)
def test_filter_datastores_no_match(self):
datastores = self.build_result_set(self.data)
datastore_regex = re.compile('no_match.*')
rec = vm_util._get_datastore_ref_and_name(datastores,
datastore_regex)
self.assertIsNone(rec, "did not fail to match datastore properly")
def test_filter_datastores_specific_match(self):
data = [
['VMFS', 'os-some-name', True, 987654321, 1234678],
['NFS', 'another-name', True, 9876543210, 123467890],
['BAD', 'some-name-bad', True, 98765432100, 1234678900],
['VMFS', 'some-name-good', True, 987654321, 12346789],
['VMFS', 'some-other-good', False, 987654321000, 12346789000],
]
# only the DS some-name-good is accessible and matches the regex
datastores = self.build_result_set(data)
datastore_regex = re.compile('.*-good$')
rec = vm_util._get_datastore_ref_and_name(datastores,
datastore_regex)
self.assertIsNotNone(rec, "could not find datastore!")
self.assertEqual('ds-003', rec[0].value,
"didn't find the right datastore!")
self.assertNotEqual('ds-004', rec[0].value,
"accepted an unreachable datastore!")
self.assertEqual('some-name-good', rec[1])
self.assertEqual(12346789, rec[3],
"did not obtain correct freespace!")
self.assertEqual(987654321, rec[2],
"did not obtain correct capacity!")
def test_filter_datastores_missing_props(self):
data = [
['VMFS', 'os-some-name', 987654321, 1234678],
['NFS', 'another-name', 9876543210, 123467890],
]
# no matches are expected when 'summary.accessible' is missing
prop_names = ['summary.type', 'summary.name',
'summary.capacity', 'summary.freeSpace']
datastores = self.build_result_set(data, prop_names)
rec = vm_util._get_datastore_ref_and_name(datastores)
self.assertIsNone(rec, "no matches were expected")
|
apache-2.0
|
[
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,
5055,
199,
646,
295,
199,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
4169,
63,
1974,
199,
199,
21722,
275,
5055,
14,
18921,
360,
21722,
297,
788,
1462,
1105,
199,
21722,
3264,
275,
5055,
14,
18921,
360,
21722,
297,
788,
1462,
297,
283,
1418,
1105,
199,
1692,
2714,
275,
5055,
14,
18921,
360,
1692,
2714,
297,
788,
1113,
297,
283,
4469,
1084,
1105,
199,
14451,
3697,
275,
5055,
14,
18921,
360,
3697,
297,
788,
354,
297,
283,
637,
1105,
199,
3716,
2891,
275,
5055,
14,
18921,
360,
22625,
1692,
5083,
297,
788,
585,
1105,
421,
199,
533,
27391,
6849,
9562,
30444,
7713,
1746,
8,
396,
14,
32437,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
6849,
1068,
6849,
9562,
30444,
7713,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
576,
275,
359,
288,
788,
6849,
7079,
297,
283,
736,
13,
3972,
13,
354,
297,
715,
12,
1749,
1555,
11157,
12638,
12,
14763,
1822,
1407,
467,
288,
788,
46,
7079,
297,
283,
13565,
13,
354,
297,
715,
12,
1749,
1555,
11157,
708,
709,
12,
14763,
1822,
13173,
467,
288,
788,
9439,
297,
283,
3972,
13,
354,
13,
4087,
297,
715,
12,
1749,
1555,
11157,
708,
1960,
12,
14763,
1822,
1407,
383,
467,
288,
788,
6849,
7079,
297,
283,
3972,
13,
354,
13,
8302,
297,
756,
12,
1749,
1555,
11157,
12638,
12,
14763,
1822,
1407,
467,
267,
1622,
339,
347,
1900,
63,
1099,
63,
409,
8,
277,
12,
1683,
63,
576,
12,
536,
63,
513,
29,
403,
304,
267,
327,
666,
18958,
911,
1172,
282,
1655,
70,
63,
344,
402,
6364,
13,
1493,
436,
267,
327,
880,
641,
4079,
641,
3932,
1478,
315,
314,
1683,
63,
576,
769,
267,
340,
536,
63,
513,
365,
488,
26,
288,
536,
63,
513,
275,
291,
14,
4469,
409,
63,
354,
63,
513,
398,
2251,
275,
942,
267,
367,
1305,
12,
1962,
315,
3874,
8,
1805,
63,
576,
304,
288,
1559,
275,
6935,
2714,
8,
355,
1559,
29,
3716,
2891,
8,
585,
628,
795,
3295,
1644,
68,
2,
450,
1305,
395,
355,
5931,
1084,
14285,
288,
367,
1478,
12,
574,
315,
3874,
8,
1143,
304,
355,
1559,
14,
4469,
1084,
14,
740,
8,
490,
21907,
3697,
8,
354,
29,
354,
63,
513,
59,
1080,
467,
1139,
29,
1143,
59,
1080,
2459,
288,
2251,
14,
740,
8,
1113,
9,
267,
372,
30751,
8,
1462,
29,
1462,
9,
339,
768,
1829,
272,
347,
5931,
409,
63,
354,
63,
513,
8,
277,
304,
267,
372,
788,
4705,
14,
466,
297,
283,
4705,
14,
354,
297,
283,
4705,
14,
24669,
297,
355,
283,
4705,
14,
10457,
297,
283,
4705,
14,
4624,
7643,
418,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
4129,
8,
277,
304,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
277,
14,
576,
9,
267,
6488,
275,
4169,
63,
1974,
423,
362,
63,
11450,
63,
1121,
63,
460,
63,
354,
8,
576,
18958,
9,
398,
291,
14,
10389,
8,
2761,
59,
16,
467,
298,
15153,
440,
2342,
12007,
9124,
267,
291,
14,
629,
360,
795,
13,
4587,
297,
6488,
59,
16,
1055,
585,
12,
586,
298,
328,
4272,
1133,
2342,
314,
2451,
12007,
9124,
267,
291,
14,
629,
8,
4321,
1822,
13173,
12,
6488,
59,
19,
467,
586,
298,
14887,
440,
3332,
3211,
289,
5710,
1142,
9124,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
1667,
8,
277,
304,
267,
666,
275,
942,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
576,
9,
398,
6488,
275,
4169,
63,
1974,
423,
362,
63,
11450,
63,
1121,
63,
460,
63,
354,
8,
576,
18958,
9,
398,
291,
14,
7702,
8,
2761,
9,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
889,
63,
1431,
8,
277,
304,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
277,
14,
576,
9,
267,
12007,
63,
3821,
275,
295,
14,
2014,
360,
889,
63,
1431,
24915,
398,
6488,
275,
4169,
63,
1974,
423,
362,
63,
11450,
63,
1121,
63,
460,
63,
354,
8,
576,
18958,
12,
8179,
12007,
63,
3821,
9,
398,
291,
14,
7702,
8,
2761,
12,
298,
14887,
440,
2449,
370,
1336,
12007,
7684,
531,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
6100,
63,
1431,
8,
277,
304,
398,
666,
275,
359,
288,
788,
6849,
7079,
297,
283,
736,
13,
3972,
13,
354,
297,
715,
12,
1749,
1555,
11157,
12638,
12,
14763,
17237,
467,
288,
788,
46,
7079,
297,
283,
13565,
13,
354,
297,
715,
12,
1749,
1555,
11157,
708,
709,
12,
14763,
1822,
13173,
467,
288,
788,
9439,
297,
283,
3972,
13,
354,
13,
4087,
297,
715,
12,
1749,
1555,
11157,
708,
1960,
12,
14763,
1822,
1407,
383,
467,
288,
788,
6849,
7079,
297,
283,
3972,
13,
354,
13,
8302,
297,
715,
12,
1749,
1555,
11157,
12638,
12,
14763,
1822,
1407,
467,
288,
788,
6849,
7079,
297,
283,
3972,
13,
1848,
13,
8302,
297,
756,
12,
1749,
1555,
11157,
708,
5279,
12,
14763,
1822,
1407,
1493,
467,
267,
1622,
267,
327,
1454,
314,
577,
51,
2005,
13,
354,
13,
8302,
365,
17909,
436,
4450,
314,
5163,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
576,
9,
267,
12007,
63,
3821,
275,
295,
14,
2014,
5175,
1837,
8302,
9988,
398,
6488,
275,
4169,
63,
1974
] |
[
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,
5055,
199,
646,
295,
199,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
4169,
63,
1974,
199,
199,
21722,
275,
5055,
14,
18921,
360,
21722,
297,
788,
1462,
1105,
199,
21722,
3264,
275,
5055,
14,
18921,
360,
21722,
297,
788,
1462,
297,
283,
1418,
1105,
199,
1692,
2714,
275,
5055,
14,
18921,
360,
1692,
2714,
297,
788,
1113,
297,
283,
4469,
1084,
1105,
199,
14451,
3697,
275,
5055,
14,
18921,
360,
3697,
297,
788,
354,
297,
283,
637,
1105,
199,
3716,
2891,
275,
5055,
14,
18921,
360,
22625,
1692,
5083,
297,
788,
585,
1105,
421,
199,
533,
27391,
6849,
9562,
30444,
7713,
1746,
8,
396,
14,
32437,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
6849,
1068,
6849,
9562,
30444,
7713,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
576,
275,
359,
288,
788,
6849,
7079,
297,
283,
736,
13,
3972,
13,
354,
297,
715,
12,
1749,
1555,
11157,
12638,
12,
14763,
1822,
1407,
467,
288,
788,
46,
7079,
297,
283,
13565,
13,
354,
297,
715,
12,
1749,
1555,
11157,
708,
709,
12,
14763,
1822,
13173,
467,
288,
788,
9439,
297,
283,
3972,
13,
354,
13,
4087,
297,
715,
12,
1749,
1555,
11157,
708,
1960,
12,
14763,
1822,
1407,
383,
467,
288,
788,
6849,
7079,
297,
283,
3972,
13,
354,
13,
8302,
297,
756,
12,
1749,
1555,
11157,
12638,
12,
14763,
1822,
1407,
467,
267,
1622,
339,
347,
1900,
63,
1099,
63,
409,
8,
277,
12,
1683,
63,
576,
12,
536,
63,
513,
29,
403,
304,
267,
327,
666,
18958,
911,
1172,
282,
1655,
70,
63,
344,
402,
6364,
13,
1493,
436,
267,
327,
880,
641,
4079,
641,
3932,
1478,
315,
314,
1683,
63,
576,
769,
267,
340,
536,
63,
513,
365,
488,
26,
288,
536,
63,
513,
275,
291,
14,
4469,
409,
63,
354,
63,
513,
398,
2251,
275,
942,
267,
367,
1305,
12,
1962,
315,
3874,
8,
1805,
63,
576,
304,
288,
1559,
275,
6935,
2714,
8,
355,
1559,
29,
3716,
2891,
8,
585,
628,
795,
3295,
1644,
68,
2,
450,
1305,
395,
355,
5931,
1084,
14285,
288,
367,
1478,
12,
574,
315,
3874,
8,
1143,
304,
355,
1559,
14,
4469,
1084,
14,
740,
8,
490,
21907,
3697,
8,
354,
29,
354,
63,
513,
59,
1080,
467,
1139,
29,
1143,
59,
1080,
2459,
288,
2251,
14,
740,
8,
1113,
9,
267,
372,
30751,
8,
1462,
29,
1462,
9,
339,
768,
1829,
272,
347,
5931,
409,
63,
354,
63,
513,
8,
277,
304,
267,
372,
788,
4705,
14,
466,
297,
283,
4705,
14,
354,
297,
283,
4705,
14,
24669,
297,
355,
283,
4705,
14,
10457,
297,
283,
4705,
14,
4624,
7643,
418,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
4129,
8,
277,
304,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
277,
14,
576,
9,
267,
6488,
275,
4169,
63,
1974,
423,
362,
63,
11450,
63,
1121,
63,
460,
63,
354,
8,
576,
18958,
9,
398,
291,
14,
10389,
8,
2761,
59,
16,
467,
298,
15153,
440,
2342,
12007,
9124,
267,
291,
14,
629,
360,
795,
13,
4587,
297,
6488,
59,
16,
1055,
585,
12,
586,
298,
328,
4272,
1133,
2342,
314,
2451,
12007,
9124,
267,
291,
14,
629,
8,
4321,
1822,
13173,
12,
6488,
59,
19,
467,
586,
298,
14887,
440,
3332,
3211,
289,
5710,
1142,
9124,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
1667,
8,
277,
304,
267,
666,
275,
942,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
576,
9,
398,
6488,
275,
4169,
63,
1974,
423,
362,
63,
11450,
63,
1121,
63,
460,
63,
354,
8,
576,
18958,
9,
398,
291,
14,
7702,
8,
2761,
9,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
889,
63,
1431,
8,
277,
304,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
277,
14,
576,
9,
267,
12007,
63,
3821,
275,
295,
14,
2014,
360,
889,
63,
1431,
24915,
398,
6488,
275,
4169,
63,
1974,
423,
362,
63,
11450,
63,
1121,
63,
460,
63,
354,
8,
576,
18958,
12,
8179,
12007,
63,
3821,
9,
398,
291,
14,
7702,
8,
2761,
12,
298,
14887,
440,
2449,
370,
1336,
12007,
7684,
531,
339,
347,
511,
63,
1541,
63,
576,
18958,
63,
6100,
63,
1431,
8,
277,
304,
398,
666,
275,
359,
288,
788,
6849,
7079,
297,
283,
736,
13,
3972,
13,
354,
297,
715,
12,
1749,
1555,
11157,
12638,
12,
14763,
17237,
467,
288,
788,
46,
7079,
297,
283,
13565,
13,
354,
297,
715,
12,
1749,
1555,
11157,
708,
709,
12,
14763,
1822,
13173,
467,
288,
788,
9439,
297,
283,
3972,
13,
354,
13,
4087,
297,
715,
12,
1749,
1555,
11157,
708,
1960,
12,
14763,
1822,
1407,
383,
467,
288,
788,
6849,
7079,
297,
283,
3972,
13,
354,
13,
8302,
297,
715,
12,
1749,
1555,
11157,
12638,
12,
14763,
1822,
1407,
467,
288,
788,
6849,
7079,
297,
283,
3972,
13,
1848,
13,
8302,
297,
756,
12,
1749,
1555,
11157,
708,
5279,
12,
14763,
1822,
1407,
1493,
467,
267,
1622,
267,
327,
1454,
314,
577,
51,
2005,
13,
354,
13,
8302,
365,
17909,
436,
4450,
314,
5163,
267,
666,
18958,
275,
291,
14,
1506,
63,
1099,
63,
409,
8,
576,
9,
267,
12007,
63,
3821,
275,
295,
14,
2014,
5175,
1837,
8302,
9988,
398,
6488,
275,
4169,
63,
1974,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yokose-ks/edx-platform
|
common/djangoapps/service_status/test.py
|
88
|
1381
|
"""Test for async task service status"""
from django.utils import unittest
from django.test.client import Client
from django.core.urlresolvers import reverse
import json
class CeleryConfigTest(unittest.TestCase):
"""
Test that we can get a response from Celery
"""
def setUp(self):
"""
Create a django test client
"""
self.client = Client()
self.ping_url = reverse('status.service.celery.ping')
def test_ping(self):
"""
Try to ping celery.
"""
# Access the service status page, which starts a delayed
# asynchronous task
response = self.client.get(self.ping_url)
# HTTP response should be successful
self.assertEqual(response.status_code, 200)
# Expect to get a JSON-serialized dict with
# task and time information
result_dict = json.loads(response.content)
# Was it successful?
self.assertTrue(result_dict['success'])
# We should get a "pong" message back
self.assertEqual(result_dict['value'], "pong")
# We don't know the other dict values exactly,
# but we can assert that they take the right form
self.assertIsInstance(result_dict['task_id'], unicode)
self.assertIsInstance(result_dict['time'], float)
self.assertTrue(result_dict['time'] > 0.0)
|
agpl-3.0
|
[
624,
774,
367,
5316,
2120,
2435,
2004,
624,
199,
199,
504,
1639,
14,
1208,
492,
2882,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
646,
2022,
421,
199,
533,
445,
19028,
2028,
774,
8,
2796,
14,
1746,
304,
272,
408,
272,
1379,
626,
781,
883,
664,
282,
1177,
687,
445,
19028,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
2790,
282,
1639,
511,
1890,
267,
408,
267,
291,
14,
1258,
275,
6810,
342,
267,
291,
14,
4073,
63,
633,
275,
3837,
360,
1205,
14,
1364,
14,
23593,
14,
4073,
358,
339,
347,
511,
63,
4073,
8,
277,
304,
267,
408,
267,
7649,
370,
18249,
22748,
14,
267,
408,
398,
327,
11003,
314,
2435,
2004,
2034,
12,
1314,
9174,
282,
24725,
267,
327,
15608,
2120,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
4073,
63,
633,
9,
398,
327,
3101,
1177,
1077,
506,
9512,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
15100,
370,
664,
282,
4840,
13,
8397,
1211,
543,
267,
327,
2120,
436,
900,
2556,
267,
754,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
9,
398,
327,
644,
305,
652,
9512,
31,
267,
291,
14,
1815,
8,
1099,
63,
807,
459,
3742,
1105,
398,
327,
2136,
1077,
664,
282,
298,
26992,
2,
1245,
1771,
267,
291,
14,
629,
8,
1099,
63,
807,
459,
585,
995,
298,
26992,
531,
398,
327,
2136,
2793,
1133,
5715,
314,
1163,
1211,
1338,
8840,
12,
267,
327,
1325,
781,
883,
702,
626,
2985,
5452,
314,
2451,
1824,
267,
291,
14,
6926,
8,
1099,
63,
807,
459,
1765,
63,
344,
995,
2649,
9,
267,
291,
14,
6926,
8,
1099,
63,
807,
459,
521,
995,
2069,
9,
267,
291,
14,
1815,
8,
1099,
63,
807,
459,
521,
418,
690,
378,
14,
16,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
774,
367,
5316,
2120,
2435,
2004,
624,
199,
199,
504,
1639,
14,
1208,
492,
2882,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
646,
2022,
421,
199,
533,
445,
19028,
2028,
774,
8,
2796,
14,
1746,
304,
272,
408,
272,
1379,
626,
781,
883,
664,
282,
1177,
687,
445,
19028,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
2790,
282,
1639,
511,
1890,
267,
408,
267,
291,
14,
1258,
275,
6810,
342,
267,
291,
14,
4073,
63,
633,
275,
3837,
360,
1205,
14,
1364,
14,
23593,
14,
4073,
358,
339,
347,
511,
63,
4073,
8,
277,
304,
267,
408,
267,
7649,
370,
18249,
22748,
14,
267,
408,
398,
327,
11003,
314,
2435,
2004,
2034,
12,
1314,
9174,
282,
24725,
267,
327,
15608,
2120,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
4073,
63,
633,
9,
398,
327,
3101,
1177,
1077,
506,
9512,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
15100,
370,
664,
282,
4840,
13,
8397,
1211,
543,
267,
327,
2120,
436,
900,
2556,
267,
754,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
9,
398,
327,
644,
305,
652,
9512,
31,
267,
291,
14,
1815,
8,
1099,
63,
807,
459,
3742,
1105,
398,
327,
2136,
1077,
664,
282,
298,
26992,
2,
1245,
1771,
267,
291,
14,
629,
8,
1099,
63,
807,
459,
585,
995,
298,
26992,
531,
398,
327,
2136,
2793,
1133,
5715,
314,
1163,
1211,
1338,
8840,
12,
267,
327,
1325,
781,
883,
702,
626,
2985,
5452,
314,
2451,
1824,
267,
291,
14,
6926,
8,
1099,
63,
807,
459,
1765,
63,
344,
995,
2649,
9,
267,
291,
14,
6926,
8,
1099,
63,
807,
459,
521,
995,
2069,
9,
267,
291,
14,
1815,
8,
1099,
63,
807,
459,
521,
418,
690,
378,
14,
16,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yunify/qingcloud-cli
|
qingcloud/cli/iaas_client/actions/eip/allocate_eips.py
|
1
|
3185
|
# =========================================================================
# Copyright 2012-present Yunify, Inc.
# -------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this work except in compliance with the License.
# You may obtain a copy of the License in the LICENSE file, or 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 qingcloud.cli.iaas_client.actions.base import BaseAction
class AllocateEipsAction(BaseAction):
action = 'AllocateEips'
command = 'allocate-eips'
usage = '%(prog)s --bandwidth <bandwidth> --count <count> [options] [-f <conf_file>]'
@classmethod
def add_ext_arguments(cls, parser):
parser.add_argument('-c', '--count', dest='count',
action='store', type=int, default=1,
help='the number of the eips you want to allocate. Default 1')
parser.add_argument('-b', '--bandwidth', dest='bandwidth',
action='store', type=int, default=None,
help='the bandwidth of the eip. Unit is MB.')
parser.add_argument('-B', '--billing-mode', dest='billing_mode',
action='store', type=str, default="bandwidth",
help='the billing mode of the eip: "bandwidth" or "traffic".')
parser.add_argument('-i', '--need_icp', dest='need_icp',
action='store', type=int, default=0,
help='whether need ICP code.')
parser.add_argument('-n', '--eip_name', dest='eip_name',
action='store', type=str, default='',
help='the short name of eip')
parser.add_argument('--target-user', dest='target_user',
action='store', type=str, default=None,
help='ID of user who will own this resource, should be one of your sub-account.')
parser.add_argument('--associate-mode', dest='associate_mode',
action='store', type=int, default=0,
help='Associate mode: 0 means associate to virtual gateway, 1 means associate to vm')
@classmethod
def build_directive(cls, options):
required_params = {'bandwidth': options.bandwidth}
for param in required_params:
if required_params[param] is None or required_params[param] == '':
print('error: [%s] should be specified' % param)
return None
return {
'count': options.count,
'bandwidth': options.bandwidth,
'billing_mode': options.billing_mode,
'eip_name' : options.eip_name,
'need_icp': options.need_icp,
'target_user': options.target_user,
'associate_mode': options.associate_mode,
}
|
apache-2.0
|
[
3,
7819,
763,
199,
3,
1898,
6029,
13,
1881,
1488,
324,
2021,
12,
3277,
14,
199,
3,
18852,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
1736,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
315,
314,
5113,
570,
12,
503,
737,
26,
199,
3,
199,
3,
221,
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,
7819,
763,
199,
199,
504,
1894,
316,
4091,
14,
2764,
14,
4674,
305,
63,
1258,
14,
3723,
14,
1095,
492,
3523,
3310,
199,
199,
533,
4580,
6280,
37,
6142,
3310,
8,
1563,
3310,
304,
339,
1595,
275,
283,
22712,
37,
6142,
7,
272,
1414,
275,
283,
12991,
13,
69,
6142,
7,
272,
4503,
275,
9487,
6595,
9,
83,
1553,
18358,
665,
18358,
30,
1553,
835,
665,
835,
30,
359,
1419,
61,
5243,
70,
665,
2190,
63,
493,
30,
6616,
339,
768,
3744,
272,
347,
1050,
63,
832,
63,
4958,
8,
1886,
12,
1798,
304,
398,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2850,
835,
297,
2053,
534,
835,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
17,
12,
355,
1720,
534,
1589,
1329,
402,
314,
325,
6142,
1265,
2934,
370,
18310,
14,
3758,
413,
358,
398,
1798,
14,
525,
63,
2094,
3654,
66,
297,
2850,
18358,
297,
2053,
534,
18358,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
403,
12,
355,
1720,
534,
1589,
20434,
402,
314,
325,
711,
14,
12008,
365,
19487,
2659,
398,
1798,
14,
525,
63,
2094,
3654,
34,
297,
2850,
19929,
13,
632,
297,
2053,
534,
19929,
63,
632,
297,
355,
1595,
534,
1617,
297,
730,
29,
495,
12,
849,
628,
18358,
401,
355,
1720,
534,
1589,
32663,
818,
402,
314,
325,
711,
26,
298,
18358,
2,
503,
298,
17297,
1674,
358,
398,
1798,
14,
525,
63,
2094,
3654,
73,
297,
2850,
9321,
63,
530,
80,
297,
2053,
534,
9321,
63,
530,
80,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
16,
12,
355,
1720,
534,
87,
3081,
1929,
473,
2890,
1233,
2659,
398,
1798,
14,
525,
63,
2094,
3654,
78,
297,
2850,
69,
711,
63,
354,
297,
2053,
534,
69,
711,
63,
354,
297,
355,
1595,
534,
1617,
297,
730,
29,
495,
12,
849,
4581,
355,
1720,
534,
1589,
3974,
536,
402,
325,
711,
358,
398,
1798,
14,
525,
63,
2094,
4517,
1375,
13,
751,
297,
2053,
534,
1375,
63,
751,
297,
355,
1595,
534,
1617,
297,
730,
29,
495,
12,
849,
29,
403,
12,
355,
1720,
534,
998,
402,
922,
3963,
911,
5705,
642,
2073,
12,
1077,
506,
1373,
402,
2195,
1007,
13,
2048,
2659,
398,
1798,
14,
525,
63,
2094,
4517,
16021,
13,
632,
297,
2053,
534,
16021,
63,
632,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
16,
12,
355,
1720,
534,
14889,
323,
818,
26,
378,
4910,
20133,
370,
5791,
10391,
12,
413,
4910,
20133,
370,
4169,
358,
339,
768,
3744,
272,
347,
1900,
63,
15047,
8,
1886,
12,
1511,
304,
267,
1415,
63,
1162,
275,
791,
18358,
356,
1511,
14,
18358,
93,
267,
367,
1215,
315,
1415,
63,
1162,
26,
288,
340,
1415,
63,
1162,
59,
635,
61,
365,
488,
503,
1415,
63,
1162,
59,
635,
61,
508,
8061,
355,
870,
360,
705,
26,
8978,
83,
61,
1077,
506,
2013,
7,
450,
1215,
9,
355,
372,
488,
398,
372,
469,
288,
283,
835,
356,
1511,
14,
835,
12,
288,
283,
18358,
356,
1511,
14,
18358,
12,
288,
283,
19929,
63,
632,
356,
1511,
14,
19929,
63,
632,
12,
288,
283,
69,
711,
63,
354,
7,
520,
1511,
14,
69,
711,
63,
354,
12,
288,
283,
9321,
63,
530,
80,
356,
1511,
14,
9321,
63,
530,
80,
12,
288,
283,
1375,
63,
751,
356,
1511,
14,
1375,
63,
751,
12,
288,
283,
16021,
63,
632,
356,
1511,
14,
16021,
63,
632,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7819,
763,
199,
3,
1898,
6029,
13,
1881,
1488,
324,
2021,
12,
3277,
14,
199,
3,
18852,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
1736,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
315,
314,
5113,
570,
12,
503,
737,
26,
199,
3,
199,
3,
221,
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,
7819,
763,
199,
199,
504,
1894,
316,
4091,
14,
2764,
14,
4674,
305,
63,
1258,
14,
3723,
14,
1095,
492,
3523,
3310,
199,
199,
533,
4580,
6280,
37,
6142,
3310,
8,
1563,
3310,
304,
339,
1595,
275,
283,
22712,
37,
6142,
7,
272,
1414,
275,
283,
12991,
13,
69,
6142,
7,
272,
4503,
275,
9487,
6595,
9,
83,
1553,
18358,
665,
18358,
30,
1553,
835,
665,
835,
30,
359,
1419,
61,
5243,
70,
665,
2190,
63,
493,
30,
6616,
339,
768,
3744,
272,
347,
1050,
63,
832,
63,
4958,
8,
1886,
12,
1798,
304,
398,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2850,
835,
297,
2053,
534,
835,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
17,
12,
355,
1720,
534,
1589,
1329,
402,
314,
325,
6142,
1265,
2934,
370,
18310,
14,
3758,
413,
358,
398,
1798,
14,
525,
63,
2094,
3654,
66,
297,
2850,
18358,
297,
2053,
534,
18358,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
403,
12,
355,
1720,
534,
1589,
20434,
402,
314,
325,
711,
14,
12008,
365,
19487,
2659,
398,
1798,
14,
525,
63,
2094,
3654,
34,
297,
2850,
19929,
13,
632,
297,
2053,
534,
19929,
63,
632,
297,
355,
1595,
534,
1617,
297,
730,
29,
495,
12,
849,
628,
18358,
401,
355,
1720,
534,
1589,
32663,
818,
402,
314,
325,
711,
26,
298,
18358,
2,
503,
298,
17297,
1674,
358,
398,
1798,
14,
525,
63,
2094,
3654,
73,
297,
2850,
9321,
63,
530,
80,
297,
2053,
534,
9321,
63,
530,
80,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
16,
12,
355,
1720,
534,
87,
3081,
1929,
473,
2890,
1233,
2659,
398,
1798,
14,
525,
63,
2094,
3654,
78,
297,
2850,
69,
711,
63,
354,
297,
2053,
534,
69,
711,
63,
354,
297,
355,
1595,
534,
1617,
297,
730,
29,
495,
12,
849,
4581,
355,
1720,
534,
1589,
3974,
536,
402,
325,
711,
358,
398,
1798,
14,
525,
63,
2094,
4517,
1375,
13,
751,
297,
2053,
534,
1375,
63,
751,
297,
355,
1595,
534,
1617,
297,
730,
29,
495,
12,
849,
29,
403,
12,
355,
1720,
534,
998,
402,
922,
3963,
911,
5705,
642,
2073,
12,
1077,
506,
1373,
402,
2195,
1007,
13,
2048,
2659,
398,
1798,
14,
525,
63,
2094,
4517,
16021,
13,
632,
297,
2053,
534,
16021,
63,
632,
297,
355,
1595,
534,
1617,
297,
730,
29,
442,
12,
849,
29,
16,
12,
355,
1720,
534,
14889,
323,
818,
26,
378,
4910,
20133,
370,
5791,
10391,
12,
413,
4910,
20133,
370,
4169,
358,
339,
768,
3744,
272,
347,
1900,
63,
15047,
8,
1886,
12,
1511,
304,
267,
1415,
63,
1162,
275,
791,
18358,
356,
1511,
14,
18358,
93,
267,
367,
1215,
315,
1415,
63,
1162,
26,
288,
340,
1415,
63,
1162,
59,
635,
61,
365,
488,
503,
1415,
63,
1162,
59,
635,
61,
508,
8061,
355,
870,
360,
705,
26,
8978,
83,
61,
1077,
506,
2013,
7,
450,
1215,
9,
355,
372,
488,
398,
372,
469,
288,
283,
835,
356,
1511,
14,
835,
12,
288,
283,
18358,
356,
1511,
14,
18358,
12,
288,
283,
19929,
63,
632,
356,
1511,
14,
19929,
63,
632,
12,
288,
283,
69,
711,
63,
354,
7,
520,
1511,
14,
69,
711,
63,
354,
12,
288,
283,
9321,
63,
530,
80,
356,
1511,
14,
9321,
63,
530,
80,
12,
288,
283,
1375,
63,
751,
356,
1511,
14,
1375,
63,
751,
12,
288,
283,
16021,
63,
632,
356,
1511,
14,
16021,
63,
632,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ChenJunor/hue
|
desktop/core/ext-py/Django-1.6.10/django/contrib/sessions/backends/db.py
|
101
|
2929
|
import logging
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.core.exceptions import SuspiciousOperation
from django.db import IntegrityError, transaction, router
from django.utils import timezone
from django.utils.encoding import force_text
class SessionStore(SessionBase):
"""
Implements database session store.
"""
def __init__(self, session_key=None):
super(SessionStore, self).__init__(session_key)
def load(self):
try:
s = Session.objects.get(
session_key=self.session_key,
expire_date__gt=timezone.now()
)
return self.decode(s.session_data)
except (Session.DoesNotExist, SuspiciousOperation) as e:
if isinstance(e, SuspiciousOperation):
logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
logger.warning(force_text(e))
self.create()
return {}
def exists(self, session_key):
return Session.objects.filter(session_key=session_key).exists()
def create(self):
while True:
self._session_key = self._get_new_session_key()
try:
# Save immediately to ensure we have a unique entry in the
# database.
self.save(must_create=True)
except CreateError:
# Key wasn't unique. Try again.
continue
self.modified = True
self._session_cache = {}
return
def save(self, must_create=False):
"""
Saves the current session data to the database. If 'must_create' is
True, a database error will be raised if the saving operation doesn't
create a *new* entry (as opposed to possibly updating an existing
entry).
"""
obj = Session(
session_key=self._get_or_create_session_key(),
session_data=self.encode(self._get_session(no_load=must_create)),
expire_date=self.get_expiry_date()
)
using = router.db_for_write(Session, instance=obj)
try:
with transaction.atomic(using=using):
obj.save(force_insert=must_create, using=using)
except IntegrityError:
if must_create:
raise CreateError
raise
def delete(self, session_key=None):
if session_key is None:
if self.session_key is None:
return
session_key = self.session_key
try:
Session.objects.get(session_key=session_key).delete()
except Session.DoesNotExist:
pass
@classmethod
def clear_expired(cls):
Session.objects.filter(expire_date__lt=timezone.now()).delete()
# At bottom to avoid circular import
from django.contrib.sessions.models import Session
|
apache-2.0
|
[
646,
2050,
199,
199,
504,
1639,
14,
2828,
14,
11676,
14,
7765,
14,
1095,
492,
8596,
1563,
12,
2790,
547,
199,
504,
1639,
14,
1018,
14,
3924,
492,
428,
28651,
6044,
199,
504,
1639,
14,
697,
492,
26864,
12,
6008,
12,
6197,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
199,
533,
8596,
5502,
8,
4434,
1563,
304,
272,
408,
272,
24664,
3050,
2351,
3877,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
1613,
8,
4434,
5502,
12,
291,
2843,
826,
721,
1730,
63,
498,
9,
339,
347,
2248,
8,
277,
304,
267,
862,
26,
288,
308,
275,
8596,
14,
1462,
14,
362,
8,
355,
2351,
63,
498,
29,
277,
14,
1730,
63,
498,
12,
355,
16667,
63,
602,
363,
3308,
29,
7145,
14,
2131,
342,
288,
776,
288,
372,
291,
14,
2708,
8,
83,
14,
1730,
63,
576,
9,
267,
871,
334,
4434,
14,
7400,
12,
428,
28651,
6044,
9,
465,
325,
26,
288,
340,
1228,
8,
69,
12,
428,
28651,
6044,
304,
355,
2512,
275,
2050,
14,
5572,
360,
1176,
14,
4416,
4111,
83,
7,
450,
717,
325,
855,
533,
4914,
354,
3368,
355,
2512,
14,
3764,
8,
3990,
63,
505,
8,
69,
430,
288,
291,
14,
981,
342,
288,
372,
1052,
339,
347,
3495,
8,
277,
12,
2351,
63,
498,
304,
267,
372,
8596,
14,
1462,
14,
1541,
8,
1730,
63,
498,
29,
1730,
63,
498,
680,
2444,
342,
339,
347,
1218,
8,
277,
304,
267,
1830,
715,
26,
288,
291,
423,
1730,
63,
498,
275,
291,
423,
362,
63,
1222,
63,
1730,
63,
498,
342,
288,
862,
26,
355,
327,
11063,
9939,
370,
4868,
781,
1172,
282,
3747,
2397,
315,
314,
355,
327,
3050,
14,
355,
291,
14,
2117,
8,
7790,
63,
981,
29,
549,
9,
288,
871,
2790,
547,
26,
355,
327,
2606,
17373,
1133,
3747,
14,
7649,
4020,
14,
355,
1980,
288,
291,
14,
5540,
275,
715,
288,
291,
423,
1730,
63,
1637,
275,
1052,
288,
372,
339,
347,
3354,
8,
277,
12,
1471,
63,
981,
29,
797,
304,
267,
408,
267,
428,
7047,
314,
1453,
2351,
666,
370,
314,
3050,
14,
982,
283,
7790,
63,
981,
7,
365,
267,
715,
12,
282,
3050,
1125,
911,
506,
4915,
340,
314,
13369,
3439,
3181,
1133,
267,
1218,
282,
627,
1222,
10,
2397,
334,
305,
25068,
370,
12570,
12928,
376,
3411,
267,
2397,
680,
267,
408,
267,
1559,
275,
8596,
8,
288,
2351,
63,
498,
29,
277,
423,
362,
63,
269,
63,
981,
63,
1730,
63,
498,
1062,
288,
2351,
63,
576,
29,
277,
14,
2143,
8,
277,
423,
362,
63,
1730,
8,
889,
63,
912,
29,
7790,
63,
981,
1826,
288,
16667,
63,
602,
29,
277,
14,
362,
63,
16844,
63,
602,
342,
267,
776,
267,
1808,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
4434,
12,
1256,
29,
1113,
9,
267,
862,
26,
288,
543,
6008,
14,
10910,
8,
4941,
29,
4941,
304,
355,
1559,
14,
2117,
8,
3990,
63,
3176,
29,
7790,
63,
981,
12,
1808,
29,
4941,
9,
267,
871,
26864,
26,
288,
340,
1471,
63,
981,
26,
355,
746,
2790,
547,
288,
746,
339,
347,
3145,
8,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
340,
2351,
63,
498,
365,
488,
26,
288,
340,
291,
14,
1730,
63,
498,
365,
488,
26,
355,
372,
288,
2351,
63,
498,
275,
291,
14,
1730,
63,
498,
267,
862,
26,
288,
8596,
14,
1462,
14,
362,
8,
1730,
63,
498,
29,
1730,
63,
498,
680,
1807,
342,
267,
871,
8596,
14,
7400,
26,
288,
986,
339,
768,
3744,
272,
347,
5436,
63,
16340,
8,
1886,
304,
267,
8596,
14,
1462,
14,
1541,
8,
14691,
63,
602,
363,
4116,
29,
7145,
14,
2131,
8801,
1807,
342,
421,
199,
3,
2854,
9048,
370,
5126,
15032,
492,
199,
504,
1639,
14,
2828,
14,
11676,
14,
992,
492,
8596,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
199,
199,
504,
1639,
14,
2828,
14,
11676,
14,
7765,
14,
1095,
492,
8596,
1563,
12,
2790,
547,
199,
504,
1639,
14,
1018,
14,
3924,
492,
428,
28651,
6044,
199,
504,
1639,
14,
697,
492,
26864,
12,
6008,
12,
6197,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
199,
533,
8596,
5502,
8,
4434,
1563,
304,
272,
408,
272,
24664,
3050,
2351,
3877,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
1613,
8,
4434,
5502,
12,
291,
2843,
826,
721,
1730,
63,
498,
9,
339,
347,
2248,
8,
277,
304,
267,
862,
26,
288,
308,
275,
8596,
14,
1462,
14,
362,
8,
355,
2351,
63,
498,
29,
277,
14,
1730,
63,
498,
12,
355,
16667,
63,
602,
363,
3308,
29,
7145,
14,
2131,
342,
288,
776,
288,
372,
291,
14,
2708,
8,
83,
14,
1730,
63,
576,
9,
267,
871,
334,
4434,
14,
7400,
12,
428,
28651,
6044,
9,
465,
325,
26,
288,
340,
1228,
8,
69,
12,
428,
28651,
6044,
304,
355,
2512,
275,
2050,
14,
5572,
360,
1176,
14,
4416,
4111,
83,
7,
450,
717,
325,
855,
533,
4914,
354,
3368,
355,
2512,
14,
3764,
8,
3990,
63,
505,
8,
69,
430,
288,
291,
14,
981,
342,
288,
372,
1052,
339,
347,
3495,
8,
277,
12,
2351,
63,
498,
304,
267,
372,
8596,
14,
1462,
14,
1541,
8,
1730,
63,
498,
29,
1730,
63,
498,
680,
2444,
342,
339,
347,
1218,
8,
277,
304,
267,
1830,
715,
26,
288,
291,
423,
1730,
63,
498,
275,
291,
423,
362,
63,
1222,
63,
1730,
63,
498,
342,
288,
862,
26,
355,
327,
11063,
9939,
370,
4868,
781,
1172,
282,
3747,
2397,
315,
314,
355,
327,
3050,
14,
355,
291,
14,
2117,
8,
7790,
63,
981,
29,
549,
9,
288,
871,
2790,
547,
26,
355,
327,
2606,
17373,
1133,
3747,
14,
7649,
4020,
14,
355,
1980,
288,
291,
14,
5540,
275,
715,
288,
291,
423,
1730,
63,
1637,
275,
1052,
288,
372,
339,
347,
3354,
8,
277,
12,
1471,
63,
981,
29,
797,
304,
267,
408,
267,
428,
7047,
314,
1453,
2351,
666,
370,
314,
3050,
14,
982,
283,
7790,
63,
981,
7,
365,
267,
715,
12,
282,
3050,
1125,
911,
506,
4915,
340,
314,
13369,
3439,
3181,
1133,
267,
1218,
282,
627,
1222,
10,
2397,
334,
305,
25068,
370,
12570,
12928,
376,
3411,
267,
2397,
680,
267,
408,
267,
1559,
275,
8596,
8,
288,
2351,
63,
498,
29,
277,
423,
362,
63,
269,
63,
981,
63,
1730,
63,
498,
1062,
288,
2351,
63,
576,
29,
277,
14,
2143,
8,
277,
423,
362,
63,
1730,
8,
889,
63,
912,
29,
7790,
63,
981,
1826,
288,
16667,
63,
602,
29,
277,
14,
362,
63,
16844,
63,
602,
342,
267,
776,
267,
1808,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
4434,
12,
1256,
29,
1113,
9,
267,
862,
26,
288,
543,
6008,
14,
10910,
8,
4941,
29,
4941,
304,
355,
1559,
14,
2117,
8,
3990,
63,
3176,
29,
7790,
63,
981,
12,
1808,
29,
4941,
9,
267,
871,
26864,
26,
288,
340,
1471,
63,
981,
26,
355,
746,
2790,
547,
288,
746,
339,
347,
3145,
8,
277,
12,
2351,
63,
498,
29,
403,
304,
267,
340,
2351,
63,
498,
365,
488,
26,
288,
340,
291,
14,
1730,
63,
498,
365,
488,
26,
355,
372,
288,
2351,
63,
498,
275,
291,
14,
1730,
63,
498,
267,
862,
26,
288,
8596,
14,
1462,
14,
362,
8,
1730,
63,
498,
29,
1730,
63,
498,
680,
1807,
342,
267,
871,
8596,
14,
7400,
26,
288,
986,
339,
768,
3744,
272,
347,
5436,
63,
16340,
8,
1886,
304,
267,
8596,
14,
1462,
14,
1541,
8,
14691,
63,
602,
363,
4116,
29,
7145,
14,
2131,
8801,
1807,
342,
421,
199,
3,
2854,
9048,
370,
5126,
15032,
492,
199,
504,
1639,
14,
2828,
14,
11676,
14,
992,
492,
8596,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ktan2020/legacy-automation
|
win/Lib/site-packages/wx-3.0-msw/wx/tools/Editra/src/syntax/_actionscript.py
|
1
|
3261
|
###############################################################################
# Name: actionscript.py #
# Purpose: Define ActionScript syntax for highlighting and other features #
# Author: Cody Precord <cprecord@editra.org> #
# Copyright: (c) 2008 Cody Precord <staff@editra.org> #
# License: wxWindows License #
###############################################################################
"""
FILE: actionscript.py
AUTHOR: Cody Precord
@summary: Lexer configuration file for ActionScript
"""
__author__ = "Cody Precord <cprecord@editra.org>"
__svnid__ = "$Id: _actionscript.py 70228 2011-12-31 20:39:16Z CJP $"
__revision__ = "$Revision: 70228 $"
#-----------------------------------------------------------------------------#
# Imports
import wx.stc as stc
# Local Imports
import synglob
import syndata
import _cpp
#-----------------------------------------------------------------------------#
#---- Keyword Specifications ----#
# ActionScript Keywords 0
AS_KEYWORDS = ("break case catch continue default do each else finally for if "
"in label new return super switch throw while with "
# Attribute Keywords
"dynamic final internal native override private protected "
"public static "
# Definition Keywords
"class const extends function get implements interface "
"namespace package set var "
# Directives
"import include use "
# Primary Expression Keywords
"false null this true "
# Special Types
"void Null *")
# ActionScript Keywords 1
# Namespaces and Packages
AS_TYPES = ("AS3 flash_proxy object_proxy flash accessibility display errors "
"events external filters geom media net printing profiler system "
"text ui utils xml ")
#---- Syntax Style Specs ----#
# Same as cpp
#---- Extra Properties ----#
# Same as cpp
#------------------------------------------------------------------------------#
class SyntaxData(syndata.SyntaxDataBase):
"""ActionScript SyntaxData"""
def __init__(self, langid):
super(SyntaxData, self).__init__(langid)
# Setup
self.SetLexer(stc.STC_LEX_CPP)
self.RegisterFeature(synglob.FEATURE_AUTOINDENT, _cpp.AutoIndenter)
def GetKeywords(self):
"""Returns Specified Keywords List """
return [(0, AS_KEYWORDS), (1, AS_TYPES)]
def GetSyntaxSpec(self):
"""Syntax Specifications """
return _cpp.SYNTAX_ITEMS
def GetProperties(self):
"""Returns a list of Extra Properties to set """
return [_cpp.FOLD, _cpp.FOLD_PRE]
def GetCommentPattern(self):
"""Returns a list of characters used to comment a block of code """
return [u'//']
|
mit
|
[
11490,
202,
199,
3,
2812,
26,
1595,
1579,
14,
647,
2476,
9668,
327,
202,
199,
3,
23177,
4070,
26,
13930,
10033,
5229,
6302,
367,
22437,
436,
1163,
4534,
258,
327,
202,
199,
3,
6529,
26,
445,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
30,
22456,
327,
202,
199,
3,
1898,
26,
334,
67,
9,
9079,
445,
1351,
510,
3059,
665,
7018,
32,
6297,
1239,
14,
1308,
30,
12793,
327,
202,
199,
3,
844,
26,
4818,
8647,
844,
2476,
8295,
327,
202,
199,
11490,
2999,
199,
624,
202,
199,
3817,
26,
1595,
1579,
14,
647,
6208,
202,
199,
27938,
26,
445,
1351,
510,
3059,
2476,
12788,
202,
199,
32,
4705,
26,
21125,
2897,
570,
367,
10033,
5229,
202,
6684,
3515,
202,
199,
624,
2999,
199,
363,
2502,
363,
275,
298,
35,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
4335,
202,
199,
363,
6836,
344,
363,
275,
7880,
1304,
26,
485,
1287,
1579,
14,
647,
1520,
996,
1651,
7760,
13,
713,
13,
2192,
3388,
26,
1355,
26,
975,
58,
445,
15819,
2672,
2,
202,
199,
363,
5792,
363,
275,
7880,
12714,
26,
1520,
996,
1651,
2672,
2,
2999,
199,
7656,
4559,
8492,
202,
199,
3,
24339,
202,
199,
646,
4818,
14,
29657,
465,
410,
67,
2999,
199,
3,
10111,
24339,
202,
199,
646,
9560,
6463,
202,
199,
646,
9560,
576,
202,
199,
646,
485,
5910,
2999,
199,
7656,
4559,
8492,
2999,
199,
3,
375,
6431,
5367,
3477,
83,
4099,
3,
2999,
199,
3,
10033,
5229,
2606,
3148,
378,
202,
199,
1179,
63,
32187,
275,
1689,
4785,
1930,
8579,
1980,
849,
886,
1924,
587,
3753,
367,
340,
298,
27514,
298,
262,
1768,
892,
372,
1613,
6258,
7978,
1830,
543,
298,
27514,
327,
3882,
2606,
3148,
27514,
298,
7764,
4242,
5007,
5438,
4278,
5726,
17819,
298,
27514,
298,
3455,
2955,
298,
27514,
327,
29398,
2606,
3148,
27514,
298,
533,
950,
16879,
805,
664,
9031,
3217,
298,
27514,
298,
3251,
2559,
663,
2729,
298,
27514,
327,
3757,
10624,
27514,
298,
646,
2387,
675,
298,
27514,
327,
26710,
22013,
2606,
3148,
27514,
298,
3910,
2973,
642,
2549,
298,
27514,
327,
12568,
18851,
27514,
298,
1647,
12119,
627,
531,
2999,
199,
3,
10033,
5229,
2606,
3148,
413,
202,
199,
3,
2812,
10749,
436,
9954,
7441,
202,
199,
1179,
63,
7893,
275,
1689,
1179,
19,
14775,
63,
3280,
909,
63,
3280,
14775,
1066,
823,
4783,
2929,
2552,
298,
1675,
298,
4368,
5957,
4766,
9671,
5898,
1851,
16116,
23173,
2656,
298,
1675,
298,
505,
8574,
3778,
2748,
6099,
2999,
199,
3,
375,
18377,
19442,
31511,
83,
4099,
3,
202,
199,
3,
14766,
465,
7246,
2999,
199,
3,
375,
11177,
19329,
4099,
3,
202,
199,
3,
14766,
465,
7246,
2999,
199,
20974,
3,
2999,
199,
533,
18377,
1451,
8,
9466,
576,
14,
16626,
1451,
1563,
304,
1128,
408,
3310,
5229,
18377,
1451,
624,
1128,
347,
636,
826,
721,
277,
12,
6339,
344,
304,
1039,
1613,
8,
16626,
1451,
12,
291,
2843,
826,
721,
4159,
344,
9,
4341,
327,
12439,
1039,
291,
14,
1084,
5838,
8,
29657,
14,
840,
35,
63,
8066,
63,
14533,
9,
1039,
291,
14,
7099,
5968,
8,
9466,
6463,
14,
22884,
63,
13883,
29080,
12,
485,
5910,
14,
3358,
607,
848,
351,
9,
2958,
347,
2372,
23611,
8,
277,
304,
1039,
408,
3407,
5367,
1290,
2606,
3148,
3820,
408,
1039,
372,
3842,
16,
12,
4319,
63,
32187,
395,
334,
17,
12,
4319,
63,
7893,
1874,
2958,
347,
2372,
16626,
5307,
8,
277,
304,
1039,
408,
16626,
5367,
3477,
83,
408,
1039,
372,
485,
5910,
14,
20763,
63,
10439,
51,
2958,
347,
2372,
8516,
8,
277,
304,
1039,
408,
3407,
282,
769,
402,
11177,
19329,
370,
663,
408,
1039,
372,
15500,
5910,
14,
38,
5104,
12,
485,
5910,
14,
38,
5104,
63,
4225,
61,
2958,
347,
2372,
7488,
9959,
8,
277,
304,
1039,
408,
3407,
282,
769,
402,
4110,
1202,
370,
3721,
282,
1853,
402,
1233,
408,
1039,
372,
359,
85,
28866,
418,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
202,
199,
3,
2812,
26,
1595,
1579,
14,
647,
2476,
9668,
327,
202,
199,
3,
23177,
4070,
26,
13930,
10033,
5229,
6302,
367,
22437,
436,
1163,
4534,
258,
327,
202,
199,
3,
6529,
26,
445,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
30,
22456,
327,
202,
199,
3,
1898,
26,
334,
67,
9,
9079,
445,
1351,
510,
3059,
665,
7018,
32,
6297,
1239,
14,
1308,
30,
12793,
327,
202,
199,
3,
844,
26,
4818,
8647,
844,
2476,
8295,
327,
202,
199,
11490,
2999,
199,
624,
202,
199,
3817,
26,
1595,
1579,
14,
647,
6208,
202,
199,
27938,
26,
445,
1351,
510,
3059,
2476,
12788,
202,
199,
32,
4705,
26,
21125,
2897,
570,
367,
10033,
5229,
202,
6684,
3515,
202,
199,
624,
2999,
199,
363,
2502,
363,
275,
298,
35,
1351,
510,
3059,
665,
67,
657,
1577,
32,
6297,
1239,
14,
1308,
4335,
202,
199,
363,
6836,
344,
363,
275,
7880,
1304,
26,
485,
1287,
1579,
14,
647,
1520,
996,
1651,
7760,
13,
713,
13,
2192,
3388,
26,
1355,
26,
975,
58,
445,
15819,
2672,
2,
202,
199,
363,
5792,
363,
275,
7880,
12714,
26,
1520,
996,
1651,
2672,
2,
2999,
199,
7656,
4559,
8492,
202,
199,
3,
24339,
202,
199,
646,
4818,
14,
29657,
465,
410,
67,
2999,
199,
3,
10111,
24339,
202,
199,
646,
9560,
6463,
202,
199,
646,
9560,
576,
202,
199,
646,
485,
5910,
2999,
199,
7656,
4559,
8492,
2999,
199,
3,
375,
6431,
5367,
3477,
83,
4099,
3,
2999,
199,
3,
10033,
5229,
2606,
3148,
378,
202,
199,
1179,
63,
32187,
275,
1689,
4785,
1930,
8579,
1980,
849,
886,
1924,
587,
3753,
367,
340,
298,
27514,
298,
262,
1768,
892,
372,
1613,
6258,
7978,
1830,
543,
298,
27514,
327,
3882,
2606,
3148,
27514,
298,
7764,
4242,
5007,
5438,
4278,
5726,
17819,
298,
27514,
298,
3455,
2955,
298,
27514,
327,
29398,
2606,
3148,
27514,
298,
533,
950,
16879,
805,
664,
9031,
3217,
298,
27514,
298,
3251,
2559,
663,
2729,
298,
27514,
327,
3757,
10624,
27514,
298,
646,
2387,
675,
298,
27514,
327,
26710,
22013,
2606,
3148,
27514,
298,
3910,
2973,
642,
2549,
298,
27514,
327,
12568,
18851,
27514,
298,
1647,
12119,
627,
531,
2999,
199,
3,
10033,
5229,
2606,
3148,
413,
202,
199,
3,
2812,
10749,
436,
9954,
7441,
202,
199,
1179,
63,
7893,
275,
1689,
1179,
19,
14775,
63,
3280,
909,
63,
3280,
14775,
1066,
823,
4783,
2929,
2552,
298,
1675,
298,
4368,
5957,
4766,
9671,
5898,
1851,
16116,
23173,
2656,
298,
1675,
298,
505,
8574,
3778,
2748,
6099,
2999,
199,
3,
375,
18377,
19442,
31511,
83,
4099,
3,
202,
199,
3,
14766,
465,
7246,
2999,
199,
3,
375,
11177,
19329,
4099,
3,
202,
199,
3,
14766,
465,
7246,
2999,
199,
20974,
3,
2999,
199,
533,
18377,
1451,
8,
9466,
576,
14,
16626,
1451,
1563,
304,
1128,
408,
3310,
5229,
18377,
1451,
624,
1128,
347,
636,
826,
721,
277,
12,
6339,
344,
304,
1039,
1613,
8,
16626,
1451,
12,
291,
2843,
826,
721,
4159,
344,
9,
4341,
327,
12439,
1039,
291,
14,
1084,
5838,
8,
29657,
14,
840,
35,
63,
8066,
63,
14533,
9,
1039,
291,
14,
7099,
5968,
8,
9466,
6463,
14,
22884,
63,
13883,
29080,
12,
485,
5910,
14,
3358,
607,
848,
351,
9,
2958,
347,
2372,
23611,
8,
277,
304,
1039,
408,
3407,
5367,
1290,
2606,
3148,
3820,
408,
1039,
372,
3842,
16,
12,
4319,
63,
32187,
395,
334,
17,
12,
4319,
63,
7893,
1874,
2958,
347,
2372,
16626,
5307,
8,
277,
304,
1039,
408,
16626,
5367,
3477,
83,
408,
1039,
372,
485,
5910,
14,
20763,
63,
10439,
51,
2958,
347,
2372,
8516,
8,
277,
304,
1039,
408,
3407,
282,
769,
402,
11177,
19329,
370,
663,
408,
1039,
372,
15500,
5910,
14,
38,
5104,
12,
485,
5910,
14,
38,
5104,
63,
4225,
61,
2958,
347,
2372,
7488,
9959,
8,
277,
304,
1039,
408,
3407,
282,
769,
402,
4110,
1202,
370,
3721,
282,
1853,
402,
1233,
408,
1039,
372,
359,
85,
28866,
418,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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_multibytecodec as mbc
codec = _codecs_iso2022.getcodec('iso2022_jp_2')
class Codec(codecs.Codec):
encode = codec.encode
decode = codec.decode
class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
codecs.IncrementalEncoder):
codec = codec
class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
codecs.IncrementalDecoder):
codec = codec
class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
codec = codec
class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
codec = codec
def getregentry():
return codecs.CodecInfo(
name='iso2022_jp_2',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
lgpl-3.0
|
[
3,
199,
3,
11601,
13859,
63,
11538,
63,
18,
14,
647,
26,
2018,
6140,
13732,
367,
9055,
13859,
63,
15819,
63,
18,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
4595,
13859,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
4595,
13859,
14,
362,
9276,
360,
4595,
13859,
63,
11538,
63,
18,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
4595,
13859,
63,
11538,
63,
18,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
11601,
13859,
63,
11538,
63,
18,
14,
647,
26,
2018,
6140,
13732,
367,
9055,
13859,
63,
15819,
63,
18,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
4595,
13859,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
4595,
13859,
14,
362,
9276,
360,
4595,
13859,
63,
11538,
63,
18,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
4595,
13859,
63,
11538,
63,
18,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
CredoReference/edx-platform
|
common/djangoapps/student/tests/test_userstanding.py
|
13
|
4168
|
"""
These are tests for disabling and enabling student accounts, and for making sure
that students with disabled accounts are unable to access the courseware.
"""
import unittest
from django.conf import settings
from django.urls import reverse
from django.test import Client, TestCase
from student.models import UserStanding
from student.tests.factories import UserFactory, UserStandingFactory
class UserStandingTest(TestCase):
"""test suite for user standing view for enabling and disabling accounts"""
def setUp(self):
super(UserStandingTest, self).setUp()
# create users
self.bad_user = UserFactory.create(
username='bad_user',
)
self.good_user = UserFactory.create(
username='good_user',
)
self.non_staff = UserFactory.create(
username='non_staff',
)
self.admin = UserFactory.create(
username='admin',
is_staff=True,
)
# create clients
self.bad_user_client = Client()
self.good_user_client = Client()
self.non_staff_client = Client()
self.admin_client = Client()
for user, client in [
(self.bad_user, self.bad_user_client),
(self.good_user, self.good_user_client),
(self.non_staff, self.non_staff_client),
(self.admin, self.admin_client),
]:
client.login(username=user.username, password='test')
UserStandingFactory.create(
user=self.bad_user,
account_status=UserStanding.ACCOUNT_DISABLED,
changed_by=self.admin
)
# set stock url to test disabled accounts' access to site
self.some_url = '/'
# since it's only possible to disable accounts from lms, we're going
# to skip tests for cms
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_can_access_manage_account_page(self):
response = self.admin_client.get(reverse('manage_user_standing'), {
'user': self.admin,
})
self.assertEqual(response.status_code, 200)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_disable_account(self):
self.assertEqual(
UserStanding.objects.filter(user=self.good_user).count(), 0
)
response = self.admin_client.post(reverse('disable_account_ajax'), {
'username': self.good_user.username,
'account_action': 'disable',
})
self.assertEqual(
UserStanding.objects.get(user=self.good_user).account_status,
UserStanding.ACCOUNT_DISABLED
)
def test_disabled_account_403s(self):
response = self.bad_user_client.get(self.some_url)
self.assertEqual(response.status_code, 403)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_reenable_account(self):
response = self.admin_client.post(reverse('disable_account_ajax'), {
'username': self.bad_user.username,
'account_action': 'reenable'
})
self.assertEqual(
UserStanding.objects.get(user=self.bad_user).account_status,
UserStanding.ACCOUNT_ENABLED
)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_non_staff_cant_access_disable_view(self):
response = self.non_staff_client.get(reverse('manage_user_standing'), {
'user': self.non_staff,
})
self.assertEqual(response.status_code, 404)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_non_staff_cant_disable_account(self):
response = self.non_staff_client.post(reverse('disable_account_ajax'), {
'username': self.good_user.username,
'user': self.non_staff,
'account_action': 'disable'
})
self.assertEqual(response.status_code, 404)
self.assertEqual(
UserStanding.objects.filter(user=self.good_user).count(), 0
)
|
agpl-3.0
|
[
624,
199,
20676,
787,
2295,
367,
30723,
436,
29310,
6474,
12639,
12,
436,
367,
10663,
3238,
199,
9099,
18557,
543,
6980,
12639,
787,
17329,
370,
2879,
314,
20736,
14,
199,
624,
199,
646,
2882,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
396,
492,
6810,
12,
7640,
199,
199,
504,
6474,
14,
992,
492,
2876,
18736,
316,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
12,
2876,
18736,
316,
2927,
421,
199,
533,
2876,
18736,
316,
774,
8,
1746,
304,
272,
408,
396,
5241,
367,
922,
10584,
316,
2455,
367,
29310,
436,
30723,
12639,
624,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
1899,
18736,
316,
774,
12,
291,
680,
5996,
342,
267,
327,
1218,
4390,
267,
291,
14,
4087,
63,
751,
275,
16047,
14,
981,
8,
288,
3434,
534,
4087,
63,
751,
297,
267,
776,
267,
291,
14,
8302,
63,
751,
275,
16047,
14,
981,
8,
288,
3434,
534,
8302,
63,
751,
297,
267,
776,
267,
291,
14,
2865,
63,
7018,
275,
16047,
14,
981,
8,
288,
3434,
534,
2865,
63,
7018,
297,
267,
776,
267,
291,
14,
2113,
275,
16047,
14,
981,
8,
288,
3434,
534,
2113,
297,
288,
365,
63,
7018,
29,
549,
12,
267,
776,
398,
327,
1218,
13431,
267,
291,
14,
4087,
63,
751,
63,
1258,
275,
6810,
342,
267,
291,
14,
8302,
63,
751,
63,
1258,
275,
6810,
342,
267,
291,
14,
2865,
63,
7018,
63,
1258,
275,
6810,
342,
267,
291,
14,
2113,
63,
1258,
275,
6810,
342,
398,
367,
922,
12,
1890,
315,
359,
288,
334,
277,
14,
4087,
63,
751,
12,
291,
14,
4087,
63,
751,
63,
1258,
395,
288,
334,
277,
14,
8302,
63,
751,
12,
291,
14,
8302,
63,
751,
63,
1258,
395,
288,
334,
277,
14,
2865,
63,
7018,
12,
291,
14,
2865,
63,
7018,
63,
1258,
395,
288,
334,
277,
14,
2113,
12,
291,
14,
2113,
63,
1258,
395,
267,
16246,
288,
1890,
14,
2886,
8,
2473,
29,
751,
14,
2473,
12,
2505,
534,
396,
358,
398,
2876,
18736,
316,
2927,
14,
981,
8,
288,
922,
29,
277,
14,
4087,
63,
751,
12,
288,
2933,
63,
1205,
29,
1899,
18736,
316,
14,
18928,
63,
16205,
12,
288,
2896,
63,
991,
29,
277,
14,
2113,
267,
776,
398,
327,
663,
10952,
1166,
370,
511,
6980,
12639,
7,
2879,
370,
4770,
267,
291,
14,
3972,
63,
633,
275,
7324,
398,
327,
3967,
652,
1159,
1454,
3962,
370,
3507,
12639,
687,
21577,
12,
781,
3984,
9995,
267,
327,
370,
3372,
2295,
367,
19240,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
2425,
63,
2732,
63,
9053,
63,
2048,
63,
1606,
8,
277,
304,
267,
1177,
275,
291,
14,
2113,
63,
1258,
14,
362,
8,
4471,
360,
9053,
63,
751,
63,
18126,
659,
469,
288,
283,
751,
356,
291,
14,
2113,
12,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
5993,
63,
2048,
8,
277,
304,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
1541,
8,
751,
29,
277,
14,
8302,
63,
751,
680,
835,
1062,
378,
267,
776,
267,
1177,
275,
291,
14,
2113,
63,
1258,
14,
1932,
8,
4471,
360,
5993,
63,
2048,
63,
12774,
659,
469,
288,
283,
2473,
356,
291,
14,
8302,
63,
751,
14,
2473,
12,
288,
283,
2048,
63,
1287,
356,
283,
5993,
297,
267,
3828,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
362,
8,
751,
29,
277,
14,
8302,
63,
751,
680,
2048,
63,
1205,
12,
288,
2876,
18736,
316,
14,
18928,
63,
16205,
267,
776,
339,
347,
511,
63,
7011,
63,
2048,
63,
13353,
83,
8,
277,
304,
267,
1177,
275,
291,
14,
4087,
63,
751,
63,
1258,
14,
362,
8,
277,
14,
3972,
63,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
13269,
9,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
3441,
461,
63,
2048,
8,
277,
304,
267,
1177,
275,
291,
14,
2113,
63,
1258,
14,
1932,
8,
4471,
360,
5993,
63,
2048,
63,
12774,
659,
469,
288,
283,
2473,
356,
291,
14,
4087,
63,
751,
14,
2473,
12,
288,
283,
2048,
63,
1287,
356,
283,
3441,
461,
7,
267,
3828,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
362,
8,
751,
29,
277,
14,
4087,
63,
751,
680,
2048,
63,
1205,
12,
288,
2876,
18736,
316,
14,
18928,
63,
15704,
267,
776,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
2865,
63,
7018,
63,
67,
867,
63,
2732,
63,
5993,
63,
1345,
8,
277,
304,
267,
1177,
275,
291,
14,
2865,
63,
7018,
63,
1258,
14,
362,
8,
4471,
360,
9053,
63,
751,
63,
18126,
659,
469,
288,
283,
751,
356,
291,
14,
2865,
63,
7018,
12,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
2865,
63,
7018,
63,
67,
867,
63,
5993,
63,
2048,
8,
277,
304,
267,
1177,
275,
291,
14,
2865,
63,
7018,
63,
1258,
14,
1932,
8,
4471,
360,
5993,
63,
2048,
63,
12774,
659,
469,
288,
283,
2473,
356,
291,
14,
8302,
63,
751,
14,
2473,
12,
288,
283,
751,
356,
291,
14,
2865,
63,
7018,
12,
288,
283,
2048,
63,
1287,
356,
283,
5993,
7,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
1541,
8,
751,
29
] |
[
199,
20676,
787,
2295,
367,
30723,
436,
29310,
6474,
12639,
12,
436,
367,
10663,
3238,
199,
9099,
18557,
543,
6980,
12639,
787,
17329,
370,
2879,
314,
20736,
14,
199,
624,
199,
646,
2882,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
396,
492,
6810,
12,
7640,
199,
199,
504,
6474,
14,
992,
492,
2876,
18736,
316,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
12,
2876,
18736,
316,
2927,
421,
199,
533,
2876,
18736,
316,
774,
8,
1746,
304,
272,
408,
396,
5241,
367,
922,
10584,
316,
2455,
367,
29310,
436,
30723,
12639,
624,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
1899,
18736,
316,
774,
12,
291,
680,
5996,
342,
267,
327,
1218,
4390,
267,
291,
14,
4087,
63,
751,
275,
16047,
14,
981,
8,
288,
3434,
534,
4087,
63,
751,
297,
267,
776,
267,
291,
14,
8302,
63,
751,
275,
16047,
14,
981,
8,
288,
3434,
534,
8302,
63,
751,
297,
267,
776,
267,
291,
14,
2865,
63,
7018,
275,
16047,
14,
981,
8,
288,
3434,
534,
2865,
63,
7018,
297,
267,
776,
267,
291,
14,
2113,
275,
16047,
14,
981,
8,
288,
3434,
534,
2113,
297,
288,
365,
63,
7018,
29,
549,
12,
267,
776,
398,
327,
1218,
13431,
267,
291,
14,
4087,
63,
751,
63,
1258,
275,
6810,
342,
267,
291,
14,
8302,
63,
751,
63,
1258,
275,
6810,
342,
267,
291,
14,
2865,
63,
7018,
63,
1258,
275,
6810,
342,
267,
291,
14,
2113,
63,
1258,
275,
6810,
342,
398,
367,
922,
12,
1890,
315,
359,
288,
334,
277,
14,
4087,
63,
751,
12,
291,
14,
4087,
63,
751,
63,
1258,
395,
288,
334,
277,
14,
8302,
63,
751,
12,
291,
14,
8302,
63,
751,
63,
1258,
395,
288,
334,
277,
14,
2865,
63,
7018,
12,
291,
14,
2865,
63,
7018,
63,
1258,
395,
288,
334,
277,
14,
2113,
12,
291,
14,
2113,
63,
1258,
395,
267,
16246,
288,
1890,
14,
2886,
8,
2473,
29,
751,
14,
2473,
12,
2505,
534,
396,
358,
398,
2876,
18736,
316,
2927,
14,
981,
8,
288,
922,
29,
277,
14,
4087,
63,
751,
12,
288,
2933,
63,
1205,
29,
1899,
18736,
316,
14,
18928,
63,
16205,
12,
288,
2896,
63,
991,
29,
277,
14,
2113,
267,
776,
398,
327,
663,
10952,
1166,
370,
511,
6980,
12639,
7,
2879,
370,
4770,
267,
291,
14,
3972,
63,
633,
275,
7324,
398,
327,
3967,
652,
1159,
1454,
3962,
370,
3507,
12639,
687,
21577,
12,
781,
3984,
9995,
267,
327,
370,
3372,
2295,
367,
19240,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
2425,
63,
2732,
63,
9053,
63,
2048,
63,
1606,
8,
277,
304,
267,
1177,
275,
291,
14,
2113,
63,
1258,
14,
362,
8,
4471,
360,
9053,
63,
751,
63,
18126,
659,
469,
288,
283,
751,
356,
291,
14,
2113,
12,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
5993,
63,
2048,
8,
277,
304,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
1541,
8,
751,
29,
277,
14,
8302,
63,
751,
680,
835,
1062,
378,
267,
776,
267,
1177,
275,
291,
14,
2113,
63,
1258,
14,
1932,
8,
4471,
360,
5993,
63,
2048,
63,
12774,
659,
469,
288,
283,
2473,
356,
291,
14,
8302,
63,
751,
14,
2473,
12,
288,
283,
2048,
63,
1287,
356,
283,
5993,
297,
267,
3828,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
362,
8,
751,
29,
277,
14,
8302,
63,
751,
680,
2048,
63,
1205,
12,
288,
2876,
18736,
316,
14,
18928,
63,
16205,
267,
776,
339,
347,
511,
63,
7011,
63,
2048,
63,
13353,
83,
8,
277,
304,
267,
1177,
275,
291,
14,
4087,
63,
751,
63,
1258,
14,
362,
8,
277,
14,
3972,
63,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
13269,
9,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
3441,
461,
63,
2048,
8,
277,
304,
267,
1177,
275,
291,
14,
2113,
63,
1258,
14,
1932,
8,
4471,
360,
5993,
63,
2048,
63,
12774,
659,
469,
288,
283,
2473,
356,
291,
14,
4087,
63,
751,
14,
2473,
12,
288,
283,
2048,
63,
1287,
356,
283,
3441,
461,
7,
267,
3828,
267,
291,
14,
629,
8,
288,
2876,
18736,
316,
14,
1462,
14,
362,
8,
751,
29,
277,
14,
4087,
63,
751,
680,
2048,
63,
1205,
12,
288,
2876,
18736,
316,
14,
18928,
63,
15704,
267,
776,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
2865,
63,
7018,
63,
67,
867,
63,
2732,
63,
5993,
63,
1345,
8,
277,
304,
267,
1177,
275,
291,
14,
2865,
63,
7018,
63,
1258,
14,
362,
8,
4471,
360,
9053,
63,
751,
63,
18126,
659,
469,
288,
283,
751,
356,
291,
14,
2865,
63,
7018,
12,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
2865,
63,
7018,
63,
67,
867,
63,
5993,
63,
2048,
8,
277,
304,
267,
1177,
275,
291,
14,
2865,
63,
7018,
63,
1258,
14,
1932,
8,
4471,
360,
5993,
63,
2048,
63,
12774,
659,
469,
288,
283,
2473,
356,
291,
14,
8302,
63,
751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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
] |
hwuiwon/namebench
|
nb_third_party/httplib2/__init__.py
|
451
|
51082
|
from __future__ import generators
"""
httplib2
A caching http interface that supports ETags and gzip
to conserve bandwidth.
Requires Python 2.3 or later
Changelog:
2007-08-18, Rick: Modified so it's able to use a socks proxy if needed.
"""
__author__ = "Joe Gregorio (joe@bitworking.org)"
__copyright__ = "Copyright 2006, Joe Gregorio"
__contributors__ = ["Thomas Broyer (t.broyer@ltgt.net)",
"James Antill",
"Xavier Verges Farrero",
"Jonathan Feinberg",
"Blair Zajac",
"Sam Ruby",
"Louis Nyffenegger"]
__license__ = "MIT"
__version__ = "$Rev$"
import re
import sys
import email
import email.Utils
import email.Message
import email.FeedParser
import StringIO
import gzip
import zlib
import httplib
import urlparse
import base64
import os
import copy
import calendar
import time
import random
# remove depracated warning in python2.6
try:
from hashlib import sha1 as _sha, md5 as _md5
except ImportError:
import sha
import md5
_sha = sha.new
_md5 = md5.new
import hmac
from gettext import gettext as _
import socket
try:
import socks
except ImportError:
socks = None
# Build the appropriate socket wrapper for ssl
try:
import ssl # python 2.6
_ssl_wrap_socket = ssl.wrap_socket
except ImportError:
def _ssl_wrap_socket(sock, key_file, cert_file):
ssl_sock = socket.ssl(sock, key_file, cert_file)
return httplib.FakeSocket(sock, ssl_sock)
if sys.version_info >= (2,3):
from iri2uri import iri2uri
else:
def iri2uri(uri):
return uri
def has_timeout(timeout): # python 2.6
if hasattr(socket, '_GLOBAL_DEFAULT_TIMEOUT'):
return (timeout is not None and timeout is not socket._GLOBAL_DEFAULT_TIMEOUT)
return (timeout is not None)
__all__ = ['Http', 'Response', 'ProxyInfo', 'HttpLib2Error',
'RedirectMissingLocation', 'RedirectLimit', 'FailedToDecompressContent',
'UnimplementedDigestAuthOptionError', 'UnimplementedHmacDigestAuthOptionError',
'debuglevel']
# The httplib debug level, set to a non-zero value to get debug output
debuglevel = 0
# Python 2.3 support
if sys.version_info < (2,4):
def sorted(seq):
seq.sort()
return seq
# Python 2.3 support
def HTTPResponse__getheaders(self):
"""Return list of (header, value) tuples."""
if self.msg is None:
raise httplib.ResponseNotReady()
return self.msg.items()
if not hasattr(httplib.HTTPResponse, 'getheaders'):
httplib.HTTPResponse.getheaders = HTTPResponse__getheaders
# All exceptions raised here derive from HttpLib2Error
class HttpLib2Error(Exception): pass
# Some exceptions can be caught and optionally
# be turned back into responses.
class HttpLib2ErrorWithResponse(HttpLib2Error):
def __init__(self, desc, response, content):
self.response = response
self.content = content
HttpLib2Error.__init__(self, desc)
class RedirectMissingLocation(HttpLib2ErrorWithResponse): pass
class RedirectLimit(HttpLib2ErrorWithResponse): pass
class FailedToDecompressContent(HttpLib2ErrorWithResponse): pass
class UnimplementedDigestAuthOptionError(HttpLib2ErrorWithResponse): pass
class UnimplementedHmacDigestAuthOptionError(HttpLib2ErrorWithResponse): pass
class RelativeURIError(HttpLib2Error): pass
class ServerNotFoundError(HttpLib2Error): pass
# Open Items:
# -----------
# Proxy support
# Are we removing the cached content too soon on PUT (only delete on 200 Maybe?)
# Pluggable cache storage (supports storing the cache in
# flat files by default. We need a plug-in architecture
# that can support Berkeley DB and Squid)
# == Known Issues ==
# Does not handle a resource that uses conneg and Last-Modified but no ETag as a cache validator.
# Does not handle Cache-Control: max-stale
# Does not use Age: headers when calculating cache freshness.
# The number of redirections to follow before giving up.
# Note that only GET redirects are automatically followed.
# Will also honor 301 requests by saving that info and never
# requesting that URI again.
DEFAULT_MAX_REDIRECTS = 5
# Which headers are hop-by-hop headers by default
HOP_BY_HOP = ['connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'te', 'trailers', 'transfer-encoding', 'upgrade']
def _get_end2end_headers(response):
hopbyhop = list(HOP_BY_HOP)
hopbyhop.extend([x.strip() for x in response.get('connection', '').split(',')])
return [header for header in response.keys() if header not in hopbyhop]
URI = re.compile(r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?")
def parse_uri(uri):
"""Parses a URI using the regex given in Appendix B of RFC 3986.
(scheme, authority, path, query, fragment) = parse_uri(uri)
"""
groups = URI.match(uri).groups()
return (groups[1], groups[3], groups[4], groups[6], groups[8])
def urlnorm(uri):
(scheme, authority, path, query, fragment) = parse_uri(uri)
if not scheme or not authority:
raise RelativeURIError("Only absolute URIs are allowed. uri = %s" % uri)
authority = authority.lower()
scheme = scheme.lower()
if not path:
path = "/"
# Could do syntax based normalization of the URI before
# computing the digest. See Section 6.2.2 of Std 66.
request_uri = query and "?".join([path, query]) or path
scheme = scheme.lower()
defrag_uri = scheme + "://" + authority + request_uri
return scheme, authority, request_uri, defrag_uri
# Cache filename construction (original borrowed from Venus http://intertwingly.net/code/venus/)
re_url_scheme = re.compile(r'^\w+://')
re_slash = re.compile(r'[?/:|]+')
def safename(filename):
"""Return a filename suitable for the cache.
Strips dangerous and common characters to create a filename we
can use to store the cache in.
"""
try:
if re_url_scheme.match(filename):
if isinstance(filename,str):
filename = filename.decode('utf-8')
filename = filename.encode('idna')
else:
filename = filename.encode('idna')
except UnicodeError:
pass
if isinstance(filename,unicode):
filename=filename.encode('utf-8')
filemd5 = _md5(filename).hexdigest()
filename = re_url_scheme.sub("", filename)
filename = re_slash.sub(",", filename)
# limit length of filename
if len(filename)>200:
filename=filename[:200]
return ",".join((filename, filemd5))
NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+')
def _normalize_headers(headers):
return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip()) for (key, value) in headers.iteritems()])
def _parse_cache_control(headers):
retval = {}
if headers.has_key('cache-control'):
parts = headers['cache-control'].split(',')
parts_with_args = [tuple([x.strip().lower() for x in part.split("=", 1)]) for part in parts if -1 != part.find("=")]
parts_wo_args = [(name.strip().lower(), 1) for name in parts if -1 == name.find("=")]
retval = dict(parts_with_args + parts_wo_args)
return retval
# Whether to use a strict mode to parse WWW-Authenticate headers
# Might lead to bad results in case of ill-formed header value,
# so disabled by default, falling back to relaxed parsing.
# Set to true to turn on, usefull for testing servers.
USE_WWW_AUTH_STRICT_PARSING = 0
# In regex below:
# [^\0-\x1f\x7f-\xff()<>@,;:\\\"/[\]?={} \t]+ matches a "token" as defined by HTTP
# "(?:[^\0-\x08\x0A-\x1f\x7f-\xff\\\"]|\\[\0-\x7f])*?" matches a "quoted-string" as defined by HTTP, when LWS have already been replaced by a single space
# Actually, as an auth-param value can be either a token or a quoted-string, they are combined in a single pattern which matches both:
# \"?((?<=\")(?:[^\0-\x1f\x7f-\xff\\\"]|\\[\0-\x7f])*?(?=\")|(?<!\")[^\0-\x08\x0A-\x1f\x7f-\xff()<>@,;:\\\"/[\]?={} \t]+(?!\"))\"?
WWW_AUTH_STRICT = re.compile(r"^(?:\s*(?:,\s*)?([^\0-\x1f\x7f-\xff()<>@,;:\\\"/[\]?={} \t]+)\s*=\s*\"?((?<=\")(?:[^\0-\x08\x0A-\x1f\x7f-\xff\\\"]|\\[\0-\x7f])*?(?=\")|(?<!\")[^\0-\x1f\x7f-\xff()<>@,;:\\\"/[\]?={} \t]+(?!\"))\"?)(.*)$")
WWW_AUTH_RELAXED = re.compile(r"^(?:\s*(?:,\s*)?([^ \t\r\n=]+)\s*=\s*\"?((?<=\")(?:[^\\\"]|\\.)*?(?=\")|(?<!\")[^ \t\r\n,]+(?!\"))\"?)(.*)$")
UNQUOTE_PAIRS = re.compile(r'\\(.)')
def _parse_www_authenticate(headers, headername='www-authenticate'):
"""Returns a dictionary of dictionaries, one dict
per auth_scheme."""
retval = {}
if headers.has_key(headername):
authenticate = headers[headername].strip()
www_auth = USE_WWW_AUTH_STRICT_PARSING and WWW_AUTH_STRICT or WWW_AUTH_RELAXED
while authenticate:
# Break off the scheme at the beginning of the line
if headername == 'authentication-info':
(auth_scheme, the_rest) = ('digest', authenticate)
else:
(auth_scheme, the_rest) = authenticate.split(" ", 1)
# Now loop over all the key value pairs that come after the scheme,
# being careful not to roll into the next scheme
match = www_auth.search(the_rest)
auth_params = {}
while match:
if match and len(match.groups()) == 3:
(key, value, the_rest) = match.groups()
auth_params[key.lower()] = UNQUOTE_PAIRS.sub(r'\1', value) # '\\'.join([x.replace('\\', '') for x in value.split('\\\\')])
match = www_auth.search(the_rest)
retval[auth_scheme.lower()] = auth_params
authenticate = the_rest.strip()
return retval
def _entry_disposition(response_headers, request_headers):
"""Determine freshness from the Date, Expires and Cache-Control headers.
We don't handle the following:
1. Cache-Control: max-stale
2. Age: headers are not used in the calculations.
Not that this algorithm is simpler than you might think
because we are operating as a private (non-shared) cache.
This lets us ignore 's-maxage'. We can also ignore
'proxy-invalidate' since we aren't a proxy.
We will never return a stale document as
fresh as a design decision, and thus the non-implementation
of 'max-stale'. This also lets us safely ignore 'must-revalidate'
since we operate as if every server has sent 'must-revalidate'.
Since we are private we get to ignore both 'public' and
'private' parameters. We also ignore 'no-transform' since
we don't do any transformations.
The 'no-store' parameter is handled at a higher level.
So the only Cache-Control parameters we look at are:
no-cache
only-if-cached
max-age
min-fresh
"""
retval = "STALE"
cc = _parse_cache_control(request_headers)
cc_response = _parse_cache_control(response_headers)
if request_headers.has_key('pragma') and request_headers['pragma'].lower().find('no-cache') != -1:
retval = "TRANSPARENT"
if 'cache-control' not in request_headers:
request_headers['cache-control'] = 'no-cache'
elif cc.has_key('no-cache'):
retval = "TRANSPARENT"
elif cc_response.has_key('no-cache'):
retval = "STALE"
elif cc.has_key('only-if-cached'):
retval = "FRESH"
elif response_headers.has_key('date'):
date = calendar.timegm(email.Utils.parsedate_tz(response_headers['date']))
now = time.time()
current_age = max(0, now - date)
if cc_response.has_key('max-age'):
try:
freshness_lifetime = int(cc_response['max-age'])
except ValueError:
freshness_lifetime = 0
elif response_headers.has_key('expires'):
expires = email.Utils.parsedate_tz(response_headers['expires'])
if None == expires:
freshness_lifetime = 0
else:
freshness_lifetime = max(0, calendar.timegm(expires) - date)
else:
freshness_lifetime = 0
if cc.has_key('max-age'):
try:
freshness_lifetime = int(cc['max-age'])
except ValueError:
freshness_lifetime = 0
if cc.has_key('min-fresh'):
try:
min_fresh = int(cc['min-fresh'])
except ValueError:
min_fresh = 0
current_age += min_fresh
if freshness_lifetime > current_age:
retval = "FRESH"
return retval
def _decompressContent(response, new_content):
content = new_content
try:
encoding = response.get('content-encoding', None)
if encoding in ['gzip', 'deflate']:
if encoding == 'gzip':
content = gzip.GzipFile(fileobj=StringIO.StringIO(new_content)).read()
if encoding == 'deflate':
content = zlib.decompress(content)
response['content-length'] = str(len(content))
# Record the historical presence of the encoding in a way the won't interfere.
response['-content-encoding'] = response['content-encoding']
del response['content-encoding']
except IOError:
content = ""
raise FailedToDecompressContent(_("Content purported to be compressed with %s but failed to decompress.") % response.get('content-encoding'), response, content)
return content
def _updateCache(request_headers, response_headers, content, cache, cachekey):
if cachekey:
cc = _parse_cache_control(request_headers)
cc_response = _parse_cache_control(response_headers)
if cc.has_key('no-store') or cc_response.has_key('no-store'):
cache.delete(cachekey)
else:
info = email.Message.Message()
for key, value in response_headers.iteritems():
if key not in ['status','content-encoding','transfer-encoding']:
info[key] = value
# Add annotations to the cache to indicate what headers
# are variant for this request.
vary = response_headers.get('vary', None)
if vary:
vary_headers = vary.lower().replace(' ', '').split(',')
for header in vary_headers:
key = '-varied-%s' % header
try:
info[key] = request_headers[header]
except KeyError:
pass
status = response_headers.status
if status == 304:
status = 200
status_header = 'status: %d\r\n' % response_headers.status
header_str = info.as_string()
header_str = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", header_str)
text = "".join([status_header, header_str, content])
cache.set(cachekey, text)
def _cnonce():
dig = _md5("%s:%s" % (time.ctime(), ["0123456789"[random.randrange(0, 9)] for i in range(20)])).hexdigest()
return dig[:16]
def _wsse_username_token(cnonce, iso_now, password):
return base64.b64encode(_sha("%s%s%s" % (cnonce, iso_now, password)).digest()).strip()
# For credentials we need two things, first
# a pool of credential to try (not necesarily tied to BAsic, Digest, etc.)
# Then we also need a list of URIs that have already demanded authentication
# That list is tricky since sub-URIs can take the same auth, or the
# auth scheme may change as you descend the tree.
# So we also need each Auth instance to be able to tell us
# how close to the 'top' it is.
class Authentication(object):
def __init__(self, credentials, host, request_uri, headers, response, content, http):
(scheme, authority, path, query, fragment) = parse_uri(request_uri)
self.path = path
self.host = host
self.credentials = credentials
self.http = http
def depth(self, request_uri):
(scheme, authority, path, query, fragment) = parse_uri(request_uri)
return request_uri[len(self.path):].count("/")
def inscope(self, host, request_uri):
# XXX Should we normalize the request_uri?
(scheme, authority, path, query, fragment) = parse_uri(request_uri)
return (host == self.host) and path.startswith(self.path)
def request(self, method, request_uri, headers, content):
"""Modify the request headers to add the appropriate
Authorization header. Over-rise this in sub-classes."""
pass
def response(self, response, content):
"""Gives us a chance to update with new nonces
or such returned from the last authorized response.
Over-rise this in sub-classes if necessary.
Return TRUE is the request is to be retried, for
example Digest may return stale=true.
"""
return False
class BasicAuthentication(Authentication):
def __init__(self, credentials, host, request_uri, headers, response, content, http):
Authentication.__init__(self, credentials, host, request_uri, headers, response, content, http)
def request(self, method, request_uri, headers, content):
"""Modify the request headers to add the appropriate
Authorization header."""
headers['authorization'] = 'Basic ' + base64.b64encode("%s:%s" % self.credentials).strip()
class DigestAuthentication(Authentication):
"""Only do qop='auth' and MD5, since that
is all Apache currently implements"""
def __init__(self, credentials, host, request_uri, headers, response, content, http):
Authentication.__init__(self, credentials, host, request_uri, headers, response, content, http)
challenge = _parse_www_authenticate(response, 'www-authenticate')
self.challenge = challenge['digest']
qop = self.challenge.get('qop', 'auth')
self.challenge['qop'] = ('auth' in [x.strip() for x in qop.split()]) and 'auth' or None
if self.challenge['qop'] is None:
raise UnimplementedDigestAuthOptionError( _("Unsupported value for qop: %s." % qop))
self.challenge['algorithm'] = self.challenge.get('algorithm', 'MD5').upper()
if self.challenge['algorithm'] != 'MD5':
raise UnimplementedDigestAuthOptionError( _("Unsupported value for algorithm: %s." % self.challenge['algorithm']))
self.A1 = "".join([self.credentials[0], ":", self.challenge['realm'], ":", self.credentials[1]])
self.challenge['nc'] = 1
def request(self, method, request_uri, headers, content, cnonce = None):
"""Modify the request headers"""
H = lambda x: _md5(x).hexdigest()
KD = lambda s, d: H("%s:%s" % (s, d))
A2 = "".join([method, ":", request_uri])
self.challenge['cnonce'] = cnonce or _cnonce()
request_digest = '"%s"' % KD(H(self.A1), "%s:%s:%s:%s:%s" % (self.challenge['nonce'],
'%08x' % self.challenge['nc'],
self.challenge['cnonce'],
self.challenge['qop'], H(A2)
))
headers['Authorization'] = 'Digest username="%s", realm="%s", nonce="%s", uri="%s", algorithm=%s, response=%s, qop=%s, nc=%08x, cnonce="%s"' % (
self.credentials[0],
self.challenge['realm'],
self.challenge['nonce'],
request_uri,
self.challenge['algorithm'],
request_digest,
self.challenge['qop'],
self.challenge['nc'],
self.challenge['cnonce'],
)
self.challenge['nc'] += 1
def response(self, response, content):
if not response.has_key('authentication-info'):
challenge = _parse_www_authenticate(response, 'www-authenticate').get('digest', {})
if 'true' == challenge.get('stale'):
self.challenge['nonce'] = challenge['nonce']
self.challenge['nc'] = 1
return True
else:
updated_challenge = _parse_www_authenticate(response, 'authentication-info').get('digest', {})
if updated_challenge.has_key('nextnonce'):
self.challenge['nonce'] = updated_challenge['nextnonce']
self.challenge['nc'] = 1
return False
class HmacDigestAuthentication(Authentication):
"""Adapted from Robert Sayre's code and DigestAuthentication above."""
__author__ = "Thomas Broyer (t.broyer@ltgt.net)"
def __init__(self, credentials, host, request_uri, headers, response, content, http):
Authentication.__init__(self, credentials, host, request_uri, headers, response, content, http)
challenge = _parse_www_authenticate(response, 'www-authenticate')
self.challenge = challenge['hmacdigest']
# TODO: self.challenge['domain']
self.challenge['reason'] = self.challenge.get('reason', 'unauthorized')
if self.challenge['reason'] not in ['unauthorized', 'integrity']:
self.challenge['reason'] = 'unauthorized'
self.challenge['salt'] = self.challenge.get('salt', '')
if not self.challenge.get('snonce'):
raise UnimplementedHmacDigestAuthOptionError( _("The challenge doesn't contain a server nonce, or this one is empty."))
self.challenge['algorithm'] = self.challenge.get('algorithm', 'HMAC-SHA-1')
if self.challenge['algorithm'] not in ['HMAC-SHA-1', 'HMAC-MD5']:
raise UnimplementedHmacDigestAuthOptionError( _("Unsupported value for algorithm: %s." % self.challenge['algorithm']))
self.challenge['pw-algorithm'] = self.challenge.get('pw-algorithm', 'SHA-1')
if self.challenge['pw-algorithm'] not in ['SHA-1', 'MD5']:
raise UnimplementedHmacDigestAuthOptionError( _("Unsupported value for pw-algorithm: %s." % self.challenge['pw-algorithm']))
if self.challenge['algorithm'] == 'HMAC-MD5':
self.hashmod = _md5
else:
self.hashmod = _sha
if self.challenge['pw-algorithm'] == 'MD5':
self.pwhashmod = _md5
else:
self.pwhashmod = _sha
self.key = "".join([self.credentials[0], ":",
self.pwhashmod.new("".join([self.credentials[1], self.challenge['salt']])).hexdigest().lower(),
":", self.challenge['realm']
])
self.key = self.pwhashmod.new(self.key).hexdigest().lower()
def request(self, method, request_uri, headers, content):
"""Modify the request headers"""
keys = _get_end2end_headers(headers)
keylist = "".join(["%s " % k for k in keys])
headers_val = "".join([headers[k] for k in keys])
created = time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime())
cnonce = _cnonce()
request_digest = "%s:%s:%s:%s:%s" % (method, request_uri, cnonce, self.challenge['snonce'], headers_val)
request_digest = hmac.new(self.key, request_digest, self.hashmod).hexdigest().lower()
headers['Authorization'] = 'HMACDigest username="%s", realm="%s", snonce="%s", cnonce="%s", uri="%s", created="%s", response="%s", headers="%s"' % (
self.credentials[0],
self.challenge['realm'],
self.challenge['snonce'],
cnonce,
request_uri,
created,
request_digest,
keylist,
)
def response(self, response, content):
challenge = _parse_www_authenticate(response, 'www-authenticate').get('hmacdigest', {})
if challenge.get('reason') in ['integrity', 'stale']:
return True
return False
class WsseAuthentication(Authentication):
"""This is thinly tested and should not be relied upon.
At this time there isn't any third party server to test against.
Blogger and TypePad implemented this algorithm at one point
but Blogger has since switched to Basic over HTTPS and
TypePad has implemented it wrong, by never issuing a 401
challenge but instead requiring your client to telepathically know that
their endpoint is expecting WSSE profile="UsernameToken"."""
def __init__(self, credentials, host, request_uri, headers, response, content, http):
Authentication.__init__(self, credentials, host, request_uri, headers, response, content, http)
def request(self, method, request_uri, headers, content):
"""Modify the request headers to add the appropriate
Authorization header."""
headers['Authorization'] = 'WSSE profile="UsernameToken"'
iso_now = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
cnonce = _cnonce()
password_digest = _wsse_username_token(cnonce, iso_now, self.credentials[1])
headers['X-WSSE'] = 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"' % (
self.credentials[0],
password_digest,
cnonce,
iso_now)
class GoogleLoginAuthentication(Authentication):
def __init__(self, credentials, host, request_uri, headers, response, content, http):
from urllib import urlencode
Authentication.__init__(self, credentials, host, request_uri, headers, response, content, http)
challenge = _parse_www_authenticate(response, 'www-authenticate')
service = challenge['googlelogin'].get('service', 'xapi')
# Bloggger actually returns the service in the challenge
# For the rest we guess based on the URI
if service == 'xapi' and request_uri.find("calendar") > 0:
service = "cl"
# No point in guessing Base or Spreadsheet
#elif request_uri.find("spreadsheets") > 0:
# service = "wise"
auth = dict(Email=credentials[0], Passwd=credentials[1], service=service, source=headers['user-agent'])
resp, content = self.http.request("https://www.google.com/accounts/ClientLogin", method="POST", body=urlencode(auth), headers={'Content-Type': 'application/x-www-form-urlencoded'})
lines = content.split('\n')
d = dict([tuple(line.split("=", 1)) for line in lines if line])
if resp.status == 403:
self.Auth = ""
else:
self.Auth = d['Auth']
def request(self, method, request_uri, headers, content):
"""Modify the request headers to add the appropriate
Authorization header."""
headers['authorization'] = 'GoogleLogin Auth=' + self.Auth
AUTH_SCHEME_CLASSES = {
"basic": BasicAuthentication,
"wsse": WsseAuthentication,
"digest": DigestAuthentication,
"hmacdigest": HmacDigestAuthentication,
"googlelogin": GoogleLoginAuthentication
}
AUTH_SCHEME_ORDER = ["hmacdigest", "googlelogin", "digest", "wsse", "basic"]
class FileCache(object):
"""Uses a local directory as a store for cached files.
Not really safe to use if multiple threads or processes are going to
be running on the same cache.
"""
def __init__(self, cache, safe=safename): # use safe=lambda x: md5.new(x).hexdigest() for the old behavior
self.cache = cache
self.safe = safe
if not os.path.exists(cache):
os.makedirs(self.cache)
def get(self, key):
retval = None
cacheFullPath = os.path.join(self.cache, self.safe(key))
try:
f = file(cacheFullPath, "rb")
retval = f.read()
f.close()
except IOError:
pass
return retval
def set(self, key, value):
cacheFullPath = os.path.join(self.cache, self.safe(key))
f = file(cacheFullPath, "wb")
f.write(value)
f.close()
def delete(self, key):
cacheFullPath = os.path.join(self.cache, self.safe(key))
if os.path.exists(cacheFullPath):
os.remove(cacheFullPath)
class Credentials(object):
def __init__(self):
self.credentials = []
def add(self, name, password, domain=""):
self.credentials.append((domain.lower(), name, password))
def clear(self):
self.credentials = []
def iter(self, domain):
for (cdomain, name, password) in self.credentials:
if cdomain == "" or domain == cdomain:
yield (name, password)
class KeyCerts(Credentials):
"""Identical to Credentials except that
name/password are mapped to key/cert."""
pass
class ProxyInfo(object):
"""Collect information required to use a proxy."""
def __init__(self, proxy_type, proxy_host, proxy_port, proxy_rdns=None, proxy_user=None, proxy_pass=None):
"""The parameter proxy_type must be set to one of socks.PROXY_TYPE_XXX
constants. For example:
p = ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP, proxy_host='localhost', proxy_port=8000)
"""
self.proxy_type, self.proxy_host, self.proxy_port, self.proxy_rdns, self.proxy_user, self.proxy_pass = proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass
def astuple(self):
return (self.proxy_type, self.proxy_host, self.proxy_port, self.proxy_rdns,
self.proxy_user, self.proxy_pass)
def isgood(self):
return socks and (self.proxy_host != None) and (self.proxy_port != None)
class HTTPConnectionWithTimeout(httplib.HTTPConnection):
"""HTTPConnection subclass that supports timeouts"""
def __init__(self, host, port=None, strict=None, timeout=None, proxy_info=None):
httplib.HTTPConnection.__init__(self, host, port, strict)
self.timeout = timeout
self.proxy_info = proxy_info
def connect(self):
"""Connect to the host and port specified in __init__."""
# Mostly verbatim from httplib.py.
msg = "getaddrinfo returns an empty list"
for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
if self.proxy_info and self.proxy_info.isgood():
self.sock = socks.socksocket(af, socktype, proto)
self.sock.setproxy(*self.proxy_info.astuple())
else:
self.sock = socket.socket(af, socktype, proto)
# Different from httplib: support timeouts.
if has_timeout(self.timeout):
self.sock.settimeout(self.timeout)
# End of difference from httplib.
if self.debuglevel > 0:
print "connect: (%s, %s)" % (self.host, self.port)
self.sock.connect(sa)
except socket.error, msg:
if self.debuglevel > 0:
print 'connect fail:', (self.host, self.port)
if self.sock:
self.sock.close()
self.sock = None
continue
break
if not self.sock:
raise socket.error, msg
class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
"This class allows communication via SSL."
def __init__(self, host, port=None, key_file=None, cert_file=None,
strict=None, timeout=None, proxy_info=None):
httplib.HTTPSConnection.__init__(self, host, port=port, key_file=key_file,
cert_file=cert_file, strict=strict)
self.timeout = timeout
self.proxy_info = proxy_info
def connect(self):
"Connect to a host on a given (SSL) port."
if self.proxy_info and self.proxy_info.isgood():
sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
sock.setproxy(*self.proxy_info.astuple())
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if has_timeout(self.timeout):
sock.settimeout(self.timeout)
sock.connect((self.host, self.port))
self.sock =_ssl_wrap_socket(sock, self.key_file, self.cert_file)
class Http(object):
"""An HTTP client that handles:
- all methods
- caching
- ETags
- compression,
- HTTPS
- Basic
- Digest
- WSSE
and more.
"""
def __init__(self, cache=None, timeout=None, proxy_info=None):
"""The value of proxy_info is a ProxyInfo instance.
If 'cache' is a string then it is used as a directory name
for a disk cache. Otherwise it must be an object that supports
the same interface as FileCache."""
self.proxy_info = proxy_info
# Map domain name to an httplib connection
self.connections = {}
# The location of the cache, for now a directory
# where cached responses are held.
if cache and isinstance(cache, str):
self.cache = FileCache(cache)
else:
self.cache = cache
# Name/password
self.credentials = Credentials()
# Key/cert
self.certificates = KeyCerts()
# authorization objects
self.authorizations = []
# If set to False then no redirects are followed, even safe ones.
self.follow_redirects = True
# Which HTTP methods do we apply optimistic concurrency to, i.e.
# which methods get an "if-match:" etag header added to them.
self.optimistic_concurrency_methods = ["PUT"]
# If 'follow_redirects' is True, and this is set to True then
# all redirecs are followed, including unsafe ones.
self.follow_all_redirects = False
self.ignore_etag = False
self.force_exception_to_status_code = False
self.timeout = timeout
def _auth_from_challenge(self, host, request_uri, headers, response, content):
"""A generator that creates Authorization objects
that can be applied to requests.
"""
challenges = _parse_www_authenticate(response, 'www-authenticate')
for cred in self.credentials.iter(host):
for scheme in AUTH_SCHEME_ORDER:
if challenges.has_key(scheme):
yield AUTH_SCHEME_CLASSES[scheme](cred, host, request_uri, headers, response, content, self)
def add_credentials(self, name, password, domain=""):
"""Add a name and password that will be used
any time a request requires authentication."""
self.credentials.add(name, password, domain)
def add_certificate(self, key, cert, domain):
"""Add a key and cert that will be used
any time a request requires authentication."""
self.certificates.add(key, cert, domain)
def clear_credentials(self):
"""Remove all the names and passwords
that are used for authentication"""
self.credentials.clear()
self.authorizations = []
def _conn_request(self, conn, request_uri, method, body, headers):
for i in range(2):
try:
conn.request(method, request_uri, body, headers)
except socket.gaierror:
conn.close()
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
except (socket.error, httplib.HTTPException):
# Just because the server closed the connection doesn't apparently mean
# that the server didn't send a response.
pass
try:
response = conn.getresponse()
except (socket.error, httplib.HTTPException):
if i == 0:
conn.close()
conn.connect()
continue
else:
raise
else:
content = ""
if method == "HEAD":
response.close()
else:
content = response.read()
response = Response(response)
if method != "HEAD":
content = _decompressContent(response, content)
break
return (response, content)
def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey):
"""Do the actual request using the connection object
and also follow one level of redirects if necessary"""
auths = [(auth.depth(request_uri), auth) for auth in self.authorizations if auth.inscope(host, request_uri)]
auth = auths and sorted(auths)[0][1] or None
if auth:
auth.request(method, request_uri, headers, body)
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
if auth:
if auth.response(response, body):
auth.request(method, request_uri, headers, body)
(response, content) = self._conn_request(conn, request_uri, method, body, headers )
response._stale_digest = 1
if response.status == 401:
for authorization in self._auth_from_challenge(host, request_uri, headers, response, content):
authorization.request(method, request_uri, headers, body)
(response, content) = self._conn_request(conn, request_uri, method, body, headers, )
if response.status != 401:
self.authorizations.append(authorization)
authorization.response(response, body)
break
if (self.follow_all_redirects or (method in ["GET", "HEAD"]) or response.status == 303):
if self.follow_redirects and response.status in [300, 301, 302, 303, 307]:
# Pick out the location header and basically start from the beginning
# remembering first to strip the ETag header and decrement our 'depth'
if redirections:
if not response.has_key('location') and response.status != 300:
raise RedirectMissingLocation( _("Redirected but the response is missing a Location: header."), response, content)
# Fix-up relative redirects (which violate an RFC 2616 MUST)
if response.has_key('location'):
location = response['location']
(scheme, authority, path, query, fragment) = parse_uri(location)
if authority == None:
response['location'] = urlparse.urljoin(absolute_uri, location)
if response.status == 301 and method in ["GET", "HEAD"]:
response['-x-permanent-redirect-url'] = response['location']
if not response.has_key('content-location'):
response['content-location'] = absolute_uri
_updateCache(headers, response, content, self.cache, cachekey)
if headers.has_key('if-none-match'):
del headers['if-none-match']
if headers.has_key('if-modified-since'):
del headers['if-modified-since']
if response.has_key('location'):
location = response['location']
old_response = copy.deepcopy(response)
if not old_response.has_key('content-location'):
old_response['content-location'] = absolute_uri
redirect_method = ((response.status == 303) and (method not in ["GET", "HEAD"])) and "GET" or method
(response, content) = self.request(location, redirect_method, body=body, headers = headers, redirections = redirections - 1)
response.previous = old_response
else:
raise RedirectLimit( _("Redirected more times than rediection_limit allows."), response, content)
elif response.status in [200, 203] and method == "GET":
# Don't cache 206's since we aren't going to handle byte range requests
if not response.has_key('content-location'):
response['content-location'] = absolute_uri
_updateCache(headers, response, content, self.cache, cachekey)
return (response, content)
def _normalize_headers(self, headers):
return _normalize_headers(headers)
# Need to catch and rebrand some exceptions
# Then need to optionally turn all exceptions into status codes
# including all socket.* and httplib.* exceptions.
def request(self, uri, method="GET", body=None, headers=None, redirections=DEFAULT_MAX_REDIRECTS, connection_type=None):
""" Performs a single HTTP request.
The 'uri' is the URI of the HTTP resource and can begin
with either 'http' or 'https'. The value of 'uri' must be an absolute URI.
The 'method' is the HTTP method to perform, such as GET, POST, DELETE, etc.
There is no restriction on the methods allowed.
The 'body' is the entity body to be sent with the request. It is a string
object.
Any extra headers that are to be sent with the request should be provided in the
'headers' dictionary.
The maximum number of redirect to follow before raising an
exception is 'redirections. The default is 5.
The return value is a tuple of (response, content), the first
being and instance of the 'Response' class, the second being
a string that contains the response entity body.
"""
try:
if headers is None:
headers = {}
else:
headers = self._normalize_headers(headers)
if not headers.has_key('user-agent'):
headers['user-agent'] = "Python-httplib2/%s" % __version__
uri = iri2uri(uri)
(scheme, authority, request_uri, defrag_uri) = urlnorm(uri)
domain_port = authority.split(":")[0:2]
if len(domain_port) == 2 and domain_port[1] == '443' and scheme == 'http':
scheme = 'https'
authority = domain_port[0]
conn_key = scheme+":"+authority
if conn_key in self.connections:
conn = self.connections[conn_key]
else:
if not connection_type:
connection_type = (scheme == 'https') and HTTPSConnectionWithTimeout or HTTPConnectionWithTimeout
certs = list(self.certificates.iter(authority))
if scheme == 'https' and certs:
conn = self.connections[conn_key] = connection_type(authority, key_file=certs[0][0],
cert_file=certs[0][1], timeout=self.timeout, proxy_info=self.proxy_info)
else:
conn = self.connections[conn_key] = connection_type(authority, timeout=self.timeout, proxy_info=self.proxy_info)
conn.set_debuglevel(debuglevel)
if method in ["GET", "HEAD"] and 'range' not in headers and 'accept-encoding' not in headers:
headers['accept-encoding'] = 'gzip, deflate'
info = email.Message.Message()
cached_value = None
if self.cache:
cachekey = defrag_uri
cached_value = self.cache.get(cachekey)
if cached_value:
# info = email.message_from_string(cached_value)
#
# Need to replace the line above with the kludge below
# to fix the non-existent bug not fixed in this
# bug report: http://mail.python.org/pipermail/python-bugs-list/2005-September/030289.html
try:
info, content = cached_value.split('\r\n\r\n', 1)
feedparser = email.FeedParser.FeedParser()
feedparser.feed(info)
info = feedparser.close()
feedparser._parse = None
except IndexError:
self.cache.delete(cachekey)
cachekey = None
cached_value = None
else:
cachekey = None
if method in self.optimistic_concurrency_methods and self.cache and info.has_key('etag') and not self.ignore_etag and 'if-match' not in headers:
# http://www.w3.org/1999/04/Editing/
headers['if-match'] = info['etag']
if method not in ["GET", "HEAD"] and self.cache and cachekey:
# RFC 2616 Section 13.10
self.cache.delete(cachekey)
# Check the vary header in the cache to see if this request
# matches what varies in the cache.
if method in ['GET', 'HEAD'] and 'vary' in info:
vary = info['vary']
vary_headers = vary.lower().replace(' ', '').split(',')
for header in vary_headers:
key = '-varied-%s' % header
value = info[key]
if headers.get(header, '') != value:
cached_value = None
break
if cached_value and method in ["GET", "HEAD"] and self.cache and 'range' not in headers:
if info.has_key('-x-permanent-redirect-url'):
# Should cached permanent redirects be counted in our redirection count? For now, yes.
(response, new_content) = self.request(info['-x-permanent-redirect-url'], "GET", headers = headers, redirections = redirections - 1)
response.previous = Response(info)
response.previous.fromcache = True
else:
# Determine our course of action:
# Is the cached entry fresh or stale?
# Has the client requested a non-cached response?
#
# There seems to be three possible answers:
# 1. [FRESH] Return the cache entry w/o doing a GET
# 2. [STALE] Do the GET (but add in cache validators if available)
# 3. [TRANSPARENT] Do a GET w/o any cache validators (Cache-Control: no-cache) on the request
entry_disposition = _entry_disposition(info, headers)
if entry_disposition == "FRESH":
if not cached_value:
info['status'] = '504'
content = ""
response = Response(info)
if cached_value:
response.fromcache = True
return (response, content)
if entry_disposition == "STALE":
if info.has_key('etag') and not self.ignore_etag and not 'if-none-match' in headers:
headers['if-none-match'] = info['etag']
if info.has_key('last-modified') and not 'last-modified' in headers:
headers['if-modified-since'] = info['last-modified']
elif entry_disposition == "TRANSPARENT":
pass
(response, new_content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
if response.status == 304 and method == "GET":
# Rewrite the cache entry with the new end-to-end headers
# Take all headers that are in response
# and overwrite their values in info.
# unless they are hop-by-hop, or are listed in the connection header.
for key in _get_end2end_headers(response):
info[key] = response[key]
merged_response = Response(info)
if hasattr(response, "_stale_digest"):
merged_response._stale_digest = response._stale_digest
_updateCache(headers, merged_response, content, self.cache, cachekey)
response = merged_response
response.status = 200
response.fromcache = True
elif response.status == 200:
content = new_content
else:
self.cache.delete(cachekey)
content = new_content
else:
cc = _parse_cache_control(headers)
if cc.has_key('only-if-cached'):
info['status'] = '504'
response = Response(info)
content = ""
else:
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
except Exception, e:
if self.force_exception_to_status_code:
if isinstance(e, HttpLib2ErrorWithResponse):
response = e.response
content = e.content
response.status = 500
response.reason = str(e)
elif isinstance(e, socket.timeout):
content = "Request Timeout"
response = Response( {
"content-type": "text/plain",
"status": "408",
"content-length": len(content)
})
response.reason = "Request Timeout"
else:
content = str(e)
response = Response( {
"content-type": "text/plain",
"status": "400",
"content-length": len(content)
})
response.reason = "Bad Request"
else:
raise
return (response, content)
class Response(dict):
"""An object more like email.Message than httplib.HTTPResponse."""
"""Is this response from our local cache"""
fromcache = False
"""HTTP protocol version used by server. 10 for HTTP/1.0, 11 for HTTP/1.1. """
version = 11
"Status code returned by server. "
status = 200
"""Reason phrase returned by server."""
reason = "Ok"
previous = None
def __init__(self, info):
# info is either an email.Message or
# an httplib.HTTPResponse object.
if isinstance(info, httplib.HTTPResponse):
for key, value in info.getheaders():
self[key.lower()] = value
self.status = info.status
self['status'] = str(self.status)
self.reason = info.reason
self.version = info.version
elif isinstance(info, email.Message.Message):
for key, value in info.items():
self[key] = value
self.status = int(self['status'])
else:
for key, value in info.iteritems():
self[key] = value
self.status = int(self.get('status', self.status))
def __getattr__(self, name):
if name == 'dict':
return self
else:
raise AttributeError, name
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
16952,
199,
624,
199,
12942,
18,
199,
199,
33,
13627,
1455,
3217,
626,
5171,
662,
9440,
436,
11756,
199,
475,
406,
4909,
20434,
14,
9948,
199,
18153,
2018,
499,
14,
19,
503,
2945,
199,
199,
4001,
793,
26,
199,
9488,
13,
2036,
13,
1085,
12,
820,
2000,
26,
22016,
880,
652,
1159,
7688,
370,
675,
282,
6771,
83,
4566,
340,
4346,
14,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
5691,
69,
29096,
269,
2308,
334,
20241,
32,
2075,
9818,
14,
1308,
2924,
199,
363,
7307,
363,
275,
298,
7384,
8315,
12,
7135,
69,
29096,
269,
2308,
2,
199,
363,
21630,
363,
275,
2097,
52,
526,
5892,
699,
4813,
281,
334,
84,
14,
66,
4813,
281,
32,
4116,
3308,
14,
846,
4186,
272,
298,
42,
14015,
1626,
12587,
401,
272,
298,
56,
7194,
281,
5444,
3389,
481,
285,
264,
293,
401,
272,
298,
42,
265,
1619,
290,
7949,
262,
14630,
401,
272,
298,
34,
416,
723,
3107,
9091,
645,
401,
272,
298,
51,
455,
820,
10972,
401,
272,
298,
44,
810,
374,
653,
89,
556,
6349,
4162,
937,
199,
363,
1682,
363,
275,
298,
13965,
2,
199,
363,
1023,
363,
275,
7880,
26176,
17351,
199,
199,
646,
295,
221,
199,
646,
984,
221,
199,
646,
3031,
199,
646,
3031,
14,
7535,
199,
646,
3031,
14,
2209,
199,
646,
3031,
14,
7658,
2842,
199,
646,
5228,
199,
646,
11756,
199,
646,
12472,
199,
646,
8809,
199,
646,
7097,
199,
646,
1300,
772,
199,
646,
747,
199,
646,
1331,
199,
646,
11234,
199,
646,
900,
199,
646,
2196,
199,
3,
2813,
2657,
345,
3153,
5721,
315,
2366,
18,
14,
22,
199,
893,
26,
272,
687,
8337,
492,
7793,
17,
465,
485,
4835,
12,
6128,
21,
465,
485,
1064,
21,
199,
2590,
3545,
26,
272,
492,
7793,
272,
492,
6128,
21,
272,
485,
4835,
275,
7793,
14,
1222,
272,
485,
1064,
21,
275,
6128,
21,
14,
1222,
199,
646,
20330,
199,
504,
9796,
492,
9796,
465,
485,
199,
646,
2838,
199,
199,
893,
26,
272,
492,
6771,
83,
199,
2590,
3545,
26,
272,
6771,
83,
275,
488,
199,
199,
3,
6516,
314,
5827,
2838,
4975,
367,
6149,
199,
893,
26,
272,
492,
6149,
327,
2366,
499,
14,
22,
272,
485,
4266,
63,
3823,
63,
3450,
275,
6149,
14,
3823,
63,
3450,
199,
2590,
3545,
26,
272,
347,
485,
4266,
63,
3823,
63,
3450,
8,
5096,
12,
790,
63,
493,
12,
6250,
63,
493,
304,
267,
6149,
63,
5096,
275,
2838,
14,
4266,
8,
5096,
12,
790,
63,
493,
12,
6250,
63,
493,
9,
267,
372,
8809,
14,
8249,
3869,
8,
5096,
12,
6149,
63,
5096,
9,
421,
199,
692,
984,
14,
1023,
63,
815,
2356,
334,
18,
12,
19,
304,
272,
687,
24086,
18,
2302,
492,
24086,
18,
2302,
199,
2836,
26,
272,
347,
24086,
18,
2302,
8,
2302,
304,
267,
372,
5108,
199,
199,
318,
965,
63,
2593,
8,
2593,
304,
327,
2366,
499,
14,
22,
272,
340,
2688,
8,
3450,
12,
2513,
13808,
63,
3472,
63,
8899,
735,
267,
372,
334,
2593,
365,
440,
488,
436,
2653,
365,
440,
2838,
423,
13808,
63,
3472,
63,
8899,
9,
272,
372,
334,
2593,
365,
440,
488,
9,
199,
199,
363,
452,
363,
275,
788,
5779,
297,
283,
2364,
297,
283,
4936,
2354,
297,
283,
5779,
4728,
18,
547,
297,
523,
283,
7071,
7718,
6592,
297,
283,
7071,
8407,
297,
283,
4276,
1378,
872,
6447,
2714,
297,
16421,
283,
1358,
13825,
18541,
2817,
16546,
297,
283,
1358,
13825,
40,
3088,
18541,
2817,
16546,
297,
523,
283,
1757,
1896,
418,
421,
199,
3,
710,
8809,
3105,
2166,
12,
663,
370,
282,
2222,
13,
4262,
574,
370,
664,
3105,
1072,
199,
1757,
1896,
275,
378,
421,
199,
3,
2018,
499,
14,
19,
2291,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
20,
304,
272,
347,
3355,
8,
3610,
304,
267,
5412,
14,
3191,
342,
267,
372,
5412,
199,
199,
3,
2018,
499,
14,
19,
2291,
199,
318,
29034,
363,
19958,
83,
8,
277,
304,
272,
408,
1767,
769,
402,
334,
1291,
12,
574,
9,
6346,
1041,
272,
340,
291,
14,
1328,
365,
488,
26,
267,
746,
8809,
14,
2364,
1763,
17960,
342,
272,
372,
291,
14,
1328,
14,
1744,
342,
199,
199,
692,
440,
2688,
8,
12942,
14,
27068,
12,
283,
19958,
83,
735,
272,
8809,
14,
27068,
14,
19958,
83,
275,
29034,
363,
19958,
83,
199,
199,
3,
2900,
4967,
4915,
2348,
23519,
687,
4760,
4728,
18,
547,
199,
533,
4760,
4728,
18,
547,
8,
1726,
304,
986,
199,
199,
3,
6601,
4967,
883,
506,
15604,
436,
14190,
221,
199,
3,
506,
19136,
1771,
1901,
9320,
14,
221,
199,
533,
4760,
4728,
18,
547,
3007,
2364,
8,
5779,
4728,
18,
547,
304,
272,
347,
636,
826,
721,
277,
12,
4328,
12,
1177,
12,
1564,
304,
267,
291,
14,
1310,
275,
1177,
267,
291,
14,
1317,
275,
1564,
267,
4760,
4728,
18,
547,
855,
826,
721,
277,
12,
4328,
9,
199,
199,
533,
18532,
7718,
6592,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
18532,
8407,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
16277,
1378,
872,
6447,
2714,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
1910,
13825,
18541,
2817,
16546,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
1910,
13825,
40,
3088,
18541,
2817,
16546,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
199,
533,
22419,
7639,
547,
8,
5779,
4728,
18,
547,
304,
986,
199,
533,
7146,
10870,
8,
5779,
4728,
18,
547,
304,
986,
199,
199,
3,
3232,
20720,
26,
199,
3,
3001,
2595,
199,
3,
12373,
2291,
199,
199,
3,
23889,
781,
12881,
314,
6328,
1564,
4634,
18930,
641,
18337,
334,
2118,
3145,
641,
1926,
23038,
17076,
199,
199,
3,
7497,
1518,
16725,
2581,
4887,
334,
9823,
16915,
314,
2581,
315,
199,
3,
257,
6829,
1584,
701,
849,
14,
2136,
1929,
282,
14202,
13,
262,
15931,
199,
3,
257,
626,
883,
2291,
23207,
415,
15515,
6249,
436,
428,
28398,
9,
199,
199,
3,
508,
31862,
13383,
83,
508,
199,
3,
12078,
440,
2429,
282,
2073,
626,
4440,
406,
8705,
436,
15237
] |
[
636,
2443,
363,
492,
16952,
199,
624,
199,
12942,
18,
199,
199,
33,
13627,
1455,
3217,
626,
5171,
662,
9440,
436,
11756,
199,
475,
406,
4909,
20434,
14,
9948,
199,
18153,
2018,
499,
14,
19,
503,
2945,
199,
199,
4001,
793,
26,
199,
9488,
13,
2036,
13,
1085,
12,
820,
2000,
26,
22016,
880,
652,
1159,
7688,
370,
675,
282,
6771,
83,
4566,
340,
4346,
14,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
5691,
69,
29096,
269,
2308,
334,
20241,
32,
2075,
9818,
14,
1308,
2924,
199,
363,
7307,
363,
275,
298,
7384,
8315,
12,
7135,
69,
29096,
269,
2308,
2,
199,
363,
21630,
363,
275,
2097,
52,
526,
5892,
699,
4813,
281,
334,
84,
14,
66,
4813,
281,
32,
4116,
3308,
14,
846,
4186,
272,
298,
42,
14015,
1626,
12587,
401,
272,
298,
56,
7194,
281,
5444,
3389,
481,
285,
264,
293,
401,
272,
298,
42,
265,
1619,
290,
7949,
262,
14630,
401,
272,
298,
34,
416,
723,
3107,
9091,
645,
401,
272,
298,
51,
455,
820,
10972,
401,
272,
298,
44,
810,
374,
653,
89,
556,
6349,
4162,
937,
199,
363,
1682,
363,
275,
298,
13965,
2,
199,
363,
1023,
363,
275,
7880,
26176,
17351,
199,
199,
646,
295,
221,
199,
646,
984,
221,
199,
646,
3031,
199,
646,
3031,
14,
7535,
199,
646,
3031,
14,
2209,
199,
646,
3031,
14,
7658,
2842,
199,
646,
5228,
199,
646,
11756,
199,
646,
12472,
199,
646,
8809,
199,
646,
7097,
199,
646,
1300,
772,
199,
646,
747,
199,
646,
1331,
199,
646,
11234,
199,
646,
900,
199,
646,
2196,
199,
3,
2813,
2657,
345,
3153,
5721,
315,
2366,
18,
14,
22,
199,
893,
26,
272,
687,
8337,
492,
7793,
17,
465,
485,
4835,
12,
6128,
21,
465,
485,
1064,
21,
199,
2590,
3545,
26,
272,
492,
7793,
272,
492,
6128,
21,
272,
485,
4835,
275,
7793,
14,
1222,
272,
485,
1064,
21,
275,
6128,
21,
14,
1222,
199,
646,
20330,
199,
504,
9796,
492,
9796,
465,
485,
199,
646,
2838,
199,
199,
893,
26,
272,
492,
6771,
83,
199,
2590,
3545,
26,
272,
6771,
83,
275,
488,
199,
199,
3,
6516,
314,
5827,
2838,
4975,
367,
6149,
199,
893,
26,
272,
492,
6149,
327,
2366,
499,
14,
22,
272,
485,
4266,
63,
3823,
63,
3450,
275,
6149,
14,
3823,
63,
3450,
199,
2590,
3545,
26,
272,
347,
485,
4266,
63,
3823,
63,
3450,
8,
5096,
12,
790,
63,
493,
12,
6250,
63,
493,
304,
267,
6149,
63,
5096,
275,
2838,
14,
4266,
8,
5096,
12,
790,
63,
493,
12,
6250,
63,
493,
9,
267,
372,
8809,
14,
8249,
3869,
8,
5096,
12,
6149,
63,
5096,
9,
421,
199,
692,
984,
14,
1023,
63,
815,
2356,
334,
18,
12,
19,
304,
272,
687,
24086,
18,
2302,
492,
24086,
18,
2302,
199,
2836,
26,
272,
347,
24086,
18,
2302,
8,
2302,
304,
267,
372,
5108,
199,
199,
318,
965,
63,
2593,
8,
2593,
304,
327,
2366,
499,
14,
22,
272,
340,
2688,
8,
3450,
12,
2513,
13808,
63,
3472,
63,
8899,
735,
267,
372,
334,
2593,
365,
440,
488,
436,
2653,
365,
440,
2838,
423,
13808,
63,
3472,
63,
8899,
9,
272,
372,
334,
2593,
365,
440,
488,
9,
199,
199,
363,
452,
363,
275,
788,
5779,
297,
283,
2364,
297,
283,
4936,
2354,
297,
283,
5779,
4728,
18,
547,
297,
523,
283,
7071,
7718,
6592,
297,
283,
7071,
8407,
297,
283,
4276,
1378,
872,
6447,
2714,
297,
16421,
283,
1358,
13825,
18541,
2817,
16546,
297,
283,
1358,
13825,
40,
3088,
18541,
2817,
16546,
297,
523,
283,
1757,
1896,
418,
421,
199,
3,
710,
8809,
3105,
2166,
12,
663,
370,
282,
2222,
13,
4262,
574,
370,
664,
3105,
1072,
199,
1757,
1896,
275,
378,
421,
199,
3,
2018,
499,
14,
19,
2291,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
20,
304,
272,
347,
3355,
8,
3610,
304,
267,
5412,
14,
3191,
342,
267,
372,
5412,
199,
199,
3,
2018,
499,
14,
19,
2291,
199,
318,
29034,
363,
19958,
83,
8,
277,
304,
272,
408,
1767,
769,
402,
334,
1291,
12,
574,
9,
6346,
1041,
272,
340,
291,
14,
1328,
365,
488,
26,
267,
746,
8809,
14,
2364,
1763,
17960,
342,
272,
372,
291,
14,
1328,
14,
1744,
342,
199,
199,
692,
440,
2688,
8,
12942,
14,
27068,
12,
283,
19958,
83,
735,
272,
8809,
14,
27068,
14,
19958,
83,
275,
29034,
363,
19958,
83,
199,
199,
3,
2900,
4967,
4915,
2348,
23519,
687,
4760,
4728,
18,
547,
199,
533,
4760,
4728,
18,
547,
8,
1726,
304,
986,
199,
199,
3,
6601,
4967,
883,
506,
15604,
436,
14190,
221,
199,
3,
506,
19136,
1771,
1901,
9320,
14,
221,
199,
533,
4760,
4728,
18,
547,
3007,
2364,
8,
5779,
4728,
18,
547,
304,
272,
347,
636,
826,
721,
277,
12,
4328,
12,
1177,
12,
1564,
304,
267,
291,
14,
1310,
275,
1177,
267,
291,
14,
1317,
275,
1564,
267,
4760,
4728,
18,
547,
855,
826,
721,
277,
12,
4328,
9,
199,
199,
533,
18532,
7718,
6592,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
18532,
8407,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
16277,
1378,
872,
6447,
2714,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
1910,
13825,
18541,
2817,
16546,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
533,
1910,
13825,
40,
3088,
18541,
2817,
16546,
8,
5779,
4728,
18,
547,
3007,
2364,
304,
986,
199,
199,
533,
22419,
7639,
547,
8,
5779,
4728,
18,
547,
304,
986,
199,
533,
7146,
10870,
8,
5779,
4728,
18,
547,
304,
986,
199,
199,
3,
3232,
20720,
26,
199,
3,
3001,
2595,
199,
3,
12373,
2291,
199,
199,
3,
23889,
781,
12881,
314,
6328,
1564,
4634,
18930,
641,
18337,
334,
2118,
3145,
641,
1926,
23038,
17076,
199,
199,
3,
7497,
1518,
16725,
2581,
4887,
334,
9823,
16915,
314,
2581,
315,
199,
3,
257,
6829,
1584,
701,
849,
14,
2136,
1929,
282,
14202,
13,
262,
15931,
199,
3,
257,
626,
883,
2291,
23207,
415,
15515,
6249,
436,
428,
28398,
9,
199,
199,
3,
508,
31862,
13383,
83,
508,
199,
3,
12078,
440,
2429,
282,
2073,
626,
4440,
406,
8705,
436,
15237,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mhlechner/psi4
|
psi4/driver/inputparser.py
|
1
|
30572
|
#
# @BEGIN LICENSE
#
# Psi4: an open-source quantum chemistry software package
#
# Copyright (c) 2007-2017 The Psi4 Developers.
#
# The copyrights for code used from other parties are included in
# the corresponding files.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# @END LICENSE
#
"""Module with functions to parse the input file and convert
Psithon into standard Python. Particularly, forms psi4
module calls that access the C++ side of Psi4.
"""
## Force Python 3 print syntax, if this is python 2.X
#if sys.hexversion < 0x03000000:
from __future__ import print_function
from __future__ import absolute_import
import re
import os
import sys
import random
from psi4.driver import pubchem
from psi4.driver.p4util.exceptions import *
from psi4.driver.p4util.util import set_memory
from psi4 import core
# globally available regex strings
pubchemre = re.compile(r'^(\s*pubchem\s*:\s*(.*)\n)$', re.MULTILINE | re.IGNORECASE)
# inputfile contents to be preserved from the processor
literals = {}
# experimental - whether to run py statements as they're parsed from psithon
runalso = False
def bad_option_syntax(line):
"""Function to report bad syntax to screen and output file."""
message = ('Unsupported syntax:\n\n%s\n\n' % (line))
raise TestComparisonError(message)
def process_word_quotes(matchobj):
"""Function to determine if argument needs wrapping in quotes as string."""
dollar = matchobj.group(2)
val = matchobj.group(3)
if dollar:
# This is a python variable, make sure that it starts with a letter
if re.match(r'^[A-Za-z][\w]*', val):
return val
else:
message = ("Invalid Python variable: %s" % (val))
raise TestComparisonError(message)
elif re.match(r'^-?\d+\.?\d*(?:[Ee]-?\d+)?$', val):
# This must be a number, don't wrap it in quotes
return val
elif re.match(r'^\'.*\'$', val) or re.match(r'^\".*\"$', val):
# This is already wrapped in quotes, do nothing
return val
else:
# This must be a string
return "\"%s\"" % (val)
def quotify(string, isbasis=False):
"""Function to wrap anything that looks like a string in quotes
and to remove leading dollar signs from python variables. When *basis*
is True, allows commas, since basis sets may have commas and are assured to
not involve arrays.
"""
# This wraps anything that looks like a string in quotes, and removes leading
# dollar signs from python variables
if isbasis:
wordre = re.compile(r'(([$]?)([-+()*.,\w\"\'/\\]+))')
else:
wordre = re.compile(r'(([$]?)([-+()*.\w\"\'/\\]+))')
string = wordre.sub(process_word_quotes, string)
return string
def dequotify(string):
if string[0] == '"' and string[-1] == '"':
return string[1:-1]
else:
return string
def process_option(spaces, module, key, value, line):
"""Function to process a line with set or in a set block
into global/local domain and keyword/value.
"""
module = module.upper()
key = key.upper()
isbasis = True if 'BASIS' in key else False
value = quotify(value.strip(), isbasis=isbasis)
if module == "GLOBALS" or module == "GLOBAL" or module == "" or module.isspace():
# If it's really a global, we need slightly different syntax
if runalso:
core.set_global_option(key, dequotify(value))
return "%score.set_global_option(\"%s\", %s)\n" % (spaces, key, value)
else:
# It's a local option, so we need the module name in there too
if runalso:
core.set_local_option(module, key, dequotify(value))
return "%score.set_local_option(\"%s\", \"%s\", %s)\n" % (spaces, module, key, value)
def process_set_command(matchobj):
"""Function to process match of all individual ``set (module_list)
key {[value_list] or $value or value}``.
"""
result = ""
module_string = ""
if matchobj.group(2):
module_string = matchobj.group(2)
for module in module_string.split(","):
result += process_option(matchobj.group(1), module, matchobj.group(3), matchobj.group(4), matchobj.group(0))
return result
def process_set_commands(matchobj):
"""Function to process match of ``set name? { ... }``."""
spaces = matchobj.group(1)
commands = matchobj.group(3)
command_lines = re.split('\n', commands)
# Remove trailing newline from each line
map(lambda x: x.strip(), command_lines)
result = ""
module_string = ""
command = ""
if matchobj.group(2):
module_string = matchobj.group(2)
for module in module_string.split(","):
for line in command_lines:
# Chomp the trailing newline and accumulate
command += line
if not check_parentheses_and_brackets(command, 0):
# If the brackets don't match up, we need to move on to the next line
# and keep going, until they do match. Only then do we process the command
continue
# Ignore blank/empty lines
if not line or line.isspace():
continue
matchobj = re.match(r'^\s*(\w+)[\s=]+(.*?)$', command)
# Is the syntax correct? If so, process the line
if matchobj:
result += process_option(spaces, module, matchobj.group(1), matchobj.group(2), command)
# Reset the string
command = ""
else:
bad_option_syntax(command)
return result
def process_from_file_command(matchobj):
"""Function that process a match of ``from_file`` in molecule block."""
string = matchobj.group(2)
mol=core.mol_from_file(string,1)
tempmol=[line for line in mol.split('\n') if line.strip() != '']
mol2=set(tempmol)
mol=""
for i in mol2:
mol+=i
mol+="\n"
return mol
def process_pubchem_command(matchobj):
"""Function to process match of ``pubchem`` in molecule block."""
string = matchobj.group(2)
if re.match(r'^\s*[0-9]+\s*$', string):
# This is just a number - must be a CID
pcobj = pubchem.PubChemObj(int(string), '', '')
try:
return pcobj.getMoleculeString()
except Exception as e:
return e.message
else:
# Search pubchem for the provided string
try:
results = pubchem.getPubChemResults(string)
except Exception as e:
return e.message
# N.B. Anything starting with PubchemError will be handled correctly by the molecule parser
# in libmints, which will just print the rest of the string and exit gracefully.
if not results:
# Nothing!
return "PubchemError\n\tNo results were found when searching PubChem for %s.\n" % (string)
elif len(results) == 1:
# There's only 1 result - use it
return results[0].getMoleculeString()
else:
# There are multiple results. Print and exit
msg = "\tPubchemError\n"
msg += "\tMultiple pubchem results were found. Replace\n\n\t\tpubchem:%s\n\n" % (string)
msg += "\twith the Chemical ID number or exact name from one of the following and re-run.\n\n"
msg += "\t Chemical ID IUPAC Name\n\n"
for result in results:
msg += "%s" % (result)
if result.name().lower() == string.lower():
#We've found an exact match!
return result.getMoleculeString()
return msg
def process_molecule_command(matchobj):
"""Function to process match of ``molecule name? { ... }``."""
spaces = matchobj.group(1)
name = matchobj.group(2)
geometry = matchobj.group(3)
geometry = pubchemre.sub(process_pubchem_command, geometry)
from_filere = re.compile(r'^(\s*from_file\s*:\s*(.*)\n)$', re.MULTILINE | re.IGNORECASE)
geometry = from_filere.sub(process_from_file_command,geometry)
molecule = spaces
molecule += 'core.efp_init()\n' # clear EFP object before Molecule read in
molecule += spaces
if name != "":
molecule += '%s = ' % (name)
molecule += 'geometry("""%s"""' % (geometry)
if name != "":
molecule += ',"%s"' % (name)
molecule += ")\n"
molecule += '%score.IO.set_default_namespace("%s")' % (spaces, name)
return molecule
def process_literal_blocks(matchobj):
"""Function to process match of ``literals_psi4_yo-...``."""
return literals[matchobj.group(1)]
def process_cfour_command(matchobj):
"""Function to process match of ``cfour name? { ... }``."""
spaces = matchobj.group(1)
name = matchobj.group(2)
cfourblock = matchobj.group(3)
literalkey = str(random.randint(0, 99999))
literals[literalkey] = cfourblock
return "%score.set_global_option(\"%s\", \"\"\"%s\n\"\"\")\n" % \
(spaces, 'LITERAL_CFOUR', 'literals_psi4_yo-' + literalkey)
def process_extract_command(matchobj):
"""Function to process match of ``extract_subsets``."""
spaces = matchobj.group(1)
name = matchobj.group(2)
result = matchobj.group(0)
result += '%s%s.set_name("%s")' % (spaces, name, name)
result += "\n%score.set_active_molecule(%s)" % (spaces, name)
result += '\n%score.IO.set_default_namespace("%s")' % (spaces, name)
return result
def process_print_command(matchobj):
"""Function to process match of ``print`` and transform
it to ``core.print_out()``.
"""
spaces = matchobj.group(1)
string = matchobj.group(2)
return "%score.print_out(str(%s))\n" % (spaces, str(string))
def process_memory_command(matchobj):
"""Function to process match of ``memory ...``."""
spaces = str(matchobj.group(1))
sig = str(matchobj.group(2))
units = str(matchobj.group(3))
mem_in_bytes = set_memory(sig + units, execute=False)
return "%score.set_memory_bytes(%d)\n" % (spaces, mem_in_bytes)
def basname(name):
"""Imitates BasisSet.make_filename() without the gbs extension"""
return name.lower().replace('+', 'p').replace('*', 's').replace('(', '_').replace(')', '_').replace(',', '_')
def process_basis_block(matchobj):
"""Function to process match of ``basis name? { ... }``."""
spaces = matchobj.group(1)
basistype = matchobj.group(2).upper()
name = matchobj.group(3)
name = ('anonymous' + str(random.randint(0, 999))) if name == '' else name
cleanbas = basname(name).replace('-', '') # further remove hyphens so can be function name
command_lines = re.split('\n', matchobj.group(4))
symbol_re = re.compile(r'^\s*assign\s+(?P<symbol>[A-Z]{1,3})\s+(?P<basis>[-+*\(\)\w]+)\s*$', re.IGNORECASE)
label_re = re.compile(r'^\s*assign\s+(?P<label>(?P<symbol>[A-Z]{1,3})(?:(_\w+)|(\d+))?)\s+(?P<basis>[-+*\(\)\w]+)\s*$', re.IGNORECASE)
all_re = re.compile(r'^\s*assign\s+(?P<basis>[-+*\(\)\w]+)\s*$', re.IGNORECASE)
basislabel = re.compile(r'\s*\[\s*([-*\(\)\w]+)\s*\]\s*')
result = """%sdef basisspec_psi4_yo__%s(mol, role):\n""" % (spaces, cleanbas)
result += """%s basstrings = {}\n""" % (spaces)
# Start by looking for assign lines, and remove them
leftover_lines = []
for line in command_lines:
if symbol_re.match(line):
m = symbol_re.match(line)
result += """%s mol.set_basis_by_symbol("%s", "%s", role=role)\n""" % \
(spaces, m.group('symbol'), m.group('basis'))
elif label_re.match(line):
m = label_re.match(line)
result += """%s mol.set_basis_by_label("%s", "%s", role=role)\n""" % \
(spaces, m.group('label'), m.group('basis'))
elif all_re.match(line):
m = all_re.match(line)
result += """%s mol.set_basis_all_atoms("%s", role=role)\n""" % \
(spaces, m.group('basis'))
else:
# Ignore blank lines and accumulate remainder
if line and not line.isspace():
leftover_lines.append(line.strip())
# Now look for regular basis set definitions
basblock = list(filter(None, basislabel.split('\n'.join(leftover_lines))))
if len(basblock) == 1:
if len(result.split('\n')) == 3:
# case with no [basname] markers where whole block is contents of gbs file
result += """%s mol.set_basis_all_atoms("%s", role=role)\n""" % \
(spaces, name)
result += """%s basstrings['%s'] = \"\"\"\n%s\n\"\"\"\n""" % \
(spaces, basname(name), basblock[0])
else:
message = ("Conflicting basis set specification: assign lines present but shells have no [basname] label.""")
raise TestComparisonError(message)
else:
# case with specs separated by [basname] markers
for idx in range(0, len(basblock), 2):
result += """%s basstrings['%s'] = \"\"\"\n%s\n\"\"\"\n""" % \
(spaces, basname(basblock[idx]), basblock[idx + 1])
result += """%s return basstrings\n""" % (spaces)
result += """{}qcdb.libmintsbasisset.basishorde['{}'] = {}\n""" \
.format(spaces, name.upper(), 'basisspec_psi4_yo__' + cleanbas)
result += """%score.set_global_option(\"%s\", \"%s\")""" % (spaces, basistype, name)
return result
def process_pcm_command(matchobj):
"""Function to process match of ``pcm name? { ... }``."""
spacing = str(matchobj.group(1)) # Ignore..
name = str(matchobj.group(2)) # Ignore..
block = str(matchobj.group(3))
fp = open('pcmsolver.inp', 'w')
fp.write(block)
fp.close()
import pcmsolver
pcmsolver.parse_pcm_input('pcmsolver.inp')
return "" # The file has been written to disk; nothing needed in Psi4 input
def process_external_command(matchobj):
"""Function to process match of ``external name? { ... }``."""
spaces = str(matchobj.group(1))
name = str(matchobj.group(2))
if not name or name.isspace():
name = "extern"
block = str(matchobj.group(3))
lines = re.split('\n', block)
extern = "%sqmmm = QMMM()\n" % (spaces)
NUMBER = "((?:[-+]?\\d*\\.\\d+(?:[DdEe][-+]?\\d+)?)|(?:[-+]?\\d+\\.\\d*(?:[DdEe][-+]?\\d+)?))"
# Comments are all removed by this point
# 0. Remove blank lines
re_blank = re.compile(r'^\s*$')
lines2 = []
for line in lines:
mobj = re_blank.match(line)
if mobj:
pass
else:
lines2.append(line)
lines = lines2
# 1. Look for units [ang|bohr|au|a.u.] defaults to ang
re_units = re.compile(r'^\s*units?[\s=]+((ang)|(angstrom)|(bohr)|(au)|(a\.u\.))$\s*', re.IGNORECASE)
units = 'ang'
lines2 = []
for line in lines:
mobj = re_units.match(line)
if mobj:
unit = mobj.group(1)
if unit in ['bohr', 'au', 'a.u.']:
units = 'bohr'
else:
units = 'ang'
else:
lines2.append(line)
lines = lines2
# 2. Look for basis basisname, defaults to cc-pvdz
# 3. Look for df_basis_scf basisname, defaults to cc-pvdz-jkfit
re_basis = re.compile(r'\s*basis[\s=]+(\S+)\s*$', re.IGNORECASE)
re_df_basis = re.compile(r'\s*df_basis_scf[\s=]+(\S+)\s*$', re.IGNORECASE)
basis = 'cc-pvdz'
df_basis_scf = 'cc-pvdz-jkfit'
lines2 = []
for line in lines:
mobj = re_basis.match(line)
if mobj:
basis = mobj.group(1)
else:
mobj = re_df_basis.match(line)
if mobj:
df_basis_scf = mobj.group(1)
else:
lines2.append(line)
lines = lines2
# 4. Look for charge lines Z x y z, convert according to unit convention
charge_re = re.compile(r'^\s*' + NUMBER + r'\s+' + NUMBER + r'\s+' + NUMBER + r'\s+' + NUMBER + r'\s*$')
lines2 = []
for line in lines:
mobj = charge_re.match(line)
if mobj:
if units == 'ang':
extern += '%sqmmm.addChargeAngstrom(%s,%s,%s,%s)\n' % (spaces, mobj.group(1), mobj.group(2), mobj.group(3), mobj.group(4))
if units == 'bohr':
extern += '%sqmmm.addChargeBohr(%s,%s,%s,%s)\n' % (spaces, mobj.group(1), mobj.group(2), mobj.group(3), mobj.group(4))
else:
lines2.append(line)
lines = lines2
# 5. Look for diffuse regions, which are XYZ molecules seperated by the usual -- lines
spacer_re = re.compile(r'^\s*--\s*$')
frags = []
frags.append([])
for line in lines:
mobj = spacer_re.match(line)
if mobj:
if len(frags[len(frags) - 1]):
frags.append([])
else:
frags[len(frags) - 1].append(line)
extern += '%sextern_mol_temp = core.get_active_molecule()\n' % (spaces)
mol_re = re.compile(r'\s*\S+\s+' + NUMBER + r'\s+' + NUMBER + r'\s+' + NUMBER + r'\s*$')
lines = []
for frag in frags:
if not len(frag):
continue
extern += '%sexternal_diffuse = geometry("""\n' % (spaces)
extern += '%s0 1\n' % (spaces)
for line in frag:
if not mol_re.match(line):
lines.append(line)
else:
extern += '%s%s\n' % (spaces, line)
extern += '%sunits %s\n' % (spaces, units)
extern += '%ssymmetry c1\n' % (spaces)
extern += '%sno_reorient\n' % (spaces)
extern += '%sno_com\n' % (spaces)
extern += '%s""")\n' % (spaces)
extern += "%sdiffuse = Diffuse(external_diffuse,'%s','%s')\n" % (spaces, basis, df_basis_scf)
extern += '%sdiffuse.fitScf()\n' % (spaces)
extern += '%sqmmm.addDiffuse(diffuse)\n' % (spaces)
extern += '\n'
extern += '%score.set_active_molecule(extern_mol_temp)\n' % (spaces)
# 6. If there is anything left, the user messed up
if len(lines):
print('Input parsing for external {}: Extra line(s) present:')
for line in lines:
raise TestComparisonError(line)
# Return is actually an ExternalPotential, not a QMMM
extern += '%sqmmm.populateExtern()\n' % (spaces)
extern += '%s%s = qmmm.extern\n' % (spaces, name)
extern += '%score.set_global_option_python("EXTERN", extern)\n' % (spaces)
return extern
def check_parentheses_and_brackets(input_string, exit_on_error):
"""Function to check that all parenthesis and brackets
in *input_string* are paired. On that condition, *exit_on_error* =1,
otherwise 0.
"""
# This returns 1 if the string's all matched up, 0 otherwise
import collections
# create left to right parenthesis mappings
lrmap = {"(": ")", "[": "]", "{": "}"}
# derive sets of left and right parentheses
lparens = set(lrmap.keys())
rparens = set(lrmap.values())
parenstack = collections.deque()
all_matched = 1
for ch in input_string:
if ch in lparens:
parenstack.append(ch)
elif ch in rparens:
opench = ""
try:
opench = parenstack.pop()
except IndexError:
# Run out of opening parens
all_matched = 0
if exit_on_error:
message = ("Input error: extra %s" % (ch))
raise TestComparisonError(message)
if lrmap[opench] != ch:
# wrong type of parenthesis popped from stack
all_matched = 0
if exit_on_error:
message = ("Input error: %s closed with a %s" % (opench, ch))
raise TestComparisonError(message)
if len(parenstack) != 0:
all_matched = 0
if exit_on_error:
message = ("Input error: Unmatched %s" % (parenstack.pop()))
raise TestComparisonError(message)
return all_matched
def parse_multiline_array(input_list):
"""Function to squash multiline arrays into a single line
until all parentheses and brackets are fully paired.
"""
line = input_list.pop(0)
# Keep adding lines to the current one, until all parens match up
while not check_parentheses_and_brackets(line, 0):
thisline = input_list.pop(0).strip()
line += thisline
return "%s\n" % (line)
def process_multiline_arrays(inputfile):
"""Function to find array inputs that are spread across multiple
lines and squash them into a single line.
"""
# This function takes multiline array inputs, and puts them on a single line
# Start by converting the input to a list, splitting at newlines
input_list = inputfile.split("\n")
set_re = re.compile(r'^(\s*?)set\s+(?:([-,\w]+)\s+)?(\w+)[\s=]+\[.*', re.IGNORECASE)
newinput = ""
while len(input_list):
line = input_list[0]
if set_re.match(line):
# We've found the start of a set matrix [ .... line - hand it off for more checks
newinput += parse_multiline_array(input_list)
else:
# Nothing to do - just add the line to the string
newinput += "%s\n" % (input_list.pop(0))
return newinput
def process_input(raw_input, print_level=1):
"""Function to preprocess *raw input*, the text of the input file, then
parse it, validate it for format, and convert it into legitimate Python.
*raw_input* is printed to the output file unless *print_level* =0. Does
a series of regular expression filters, where the matching portion of the
input is replaced by the output of the corresponding function (in this
module) call. Returns a string concatenating module import lines, a copy
of the user's .psi4rc files, a setting of the scratch directory, a dummy
molecule, and the processed *raw_input*.
"""
# Check if the infile is actually an outfile (yeah we did)
psi4_id = re.compile(r'Psi4: An Open-Source Ab Initio Electronic Structure Package')
if re.search(psi4_id, raw_input):
input_lines = raw_input.split("\n")
input_re = re.compile(r'^\s*?\=\=> Input File <\=\=')
input_start = -1
for line_count in range(len(input_lines)):
line = input_lines[line_count]
if re.match(input_re, line):
input_start = line_count + 3
break
stop_re = re.compile(r'^-{74}')
input_stop = -1
for line_count in range(input_start, len(input_lines)):
line = input_lines[line_count]
if re.match(stop_re, line):
input_stop = line_count
break
if input_start == -1 or input_stop == -1:
message = ('Cannot extract infile from outfile.')
raise TestComparisonError(message)
raw_input = '\n'.join(input_lines[input_start:input_stop])
raw_input += '\n'
# Echo the infile on the outfile
if print_level > 0:
core.print_out("\n ==> Input File <==\n\n")
core.print_out("--------------------------------------------------------------------------\n")
core.print_out(raw_input)
core.print_out("--------------------------------------------------------------------------\n")
core.flush_outfile()
#NOTE: If adding mulitline data to the preprocessor, use ONLY the following syntax:
# function [objname] { ... }
# which has the regex capture group:
#
# r'^(\s*?)FUNCTION\s*(\w*?)\s*\{(.*?)\}', re.MULTILINE | re.DOTALL | re.IGNORECASE
#
# your function is in capture group #1
# your objname is in capture group #2
# your data is in capture group #3
# Sections that are truly to be taken literally (spaces included)
# Must be stored then subbed in the end to escape the normal processing
# Process "cfour name? { ... }"
cfour = re.compile(r'^(\s*?)cfour[=\s]*(\w*?)\s*\{(.*?)\}',
re.MULTILINE | re.DOTALL | re.IGNORECASE)
temp = re.sub(cfour, process_cfour_command, raw_input)
# Return from handling literal blocks to normal processing
# Nuke all comments
comment = re.compile(r'(^|[^\\])#.*')
temp = re.sub(comment, '', temp)
# Now, nuke any escapes from comment lines
comment = re.compile(r'\\#')
temp = re.sub(comment, '#', temp)
# Check the brackets and parentheses match up, as long as this is not a pickle input file
#if not re.search(r'pickle_kw', temp):
# check_parentheses_and_brackets(temp, 1)
# First, remove everything from lines containing only spaces
blankline = re.compile(r'^\s*$')
temp = re.sub(blankline, '', temp, re.MULTILINE)
# Look for things like
# set matrix [
# [ 1, 2 ],
# [ 3, 4 ]
# ]
# and put them on a single line
temp = process_multiline_arrays(temp)
# Process all "set name? { ... }"
set_commands = re.compile(r'^(\s*?)set\s*([-,\w]*?)[\s=]*\{(.*?)\}',
re.MULTILINE | re.DOTALL | re.IGNORECASE)
temp = re.sub(set_commands, process_set_commands, temp)
# Process all individual "set (module_list) key {[value_list] or $value or value}"
# N.B. We have to be careful here, because \s matches \n, leading to potential problems
# with undesired multiline matches. Better the double-negative [^\S\n] instead, which
# will match any space, tab, etc., except a newline
set_command = re.compile(r'^(\s*?)set\s+(?:([-,\w]+)[^\S\n]+)?(\w+)(?:[^\S\n]|=)+((\[.*\])|(\$?[-+,*()\.\w]+))\s*$',
re.MULTILINE | re.IGNORECASE)
temp = re.sub(set_command, process_set_command, temp)
# Process "molecule name? { ... }"
molecule = re.compile(r'^(\s*?)molecule[=\s]*(\w*?)\s*\{(.*?)\}',
re.MULTILINE | re.DOTALL | re.IGNORECASE)
temp = re.sub(molecule, process_molecule_command, temp)
# Process "external name? { ... }"
external = re.compile(r'^(\s*?)external[=\s]*(\w*?)\s*\{(.*?)\}',
re.MULTILINE | re.DOTALL | re.IGNORECASE)
temp = re.sub(external, process_external_command, temp)
# Process "pcm name? { ... }"
pcm = re.compile(r'^(\s*?)pcm[=\s]*(\w*?)\s*\{(.*?)^\}',
re.MULTILINE | re.DOTALL | re.IGNORECASE)
temp = re.sub(pcm, process_pcm_command, temp)
# Then remove repeated newlines
multiplenewlines = re.compile(r'\n+')
temp = re.sub(multiplenewlines, '\n', temp)
# Process " extract"
extract = re.compile(r'(\s*?)(\w+)\s*=\s*\w+\.extract_subsets.*',
re.IGNORECASE)
temp = re.sub(extract, process_extract_command, temp)
# Process "print" and transform it to "core.print_out()"
#print_string = re.compile(r'(\s*?)print\s+(.*)', re.IGNORECASE)
#temp = re.sub(print_string, process_print_command, temp)
# Process "memory ... "
memory_string = re.compile(r'(\s*?)memory\s+(\d*\.?\d+)\s*([KMGTPBE]i?B)',
re.IGNORECASE)
temp = re.sub(memory_string, process_memory_command, temp)
# Process "basis name? { ... }"
basis_block = re.compile(r'^(\s*?)(basis|df_basis_scf|df_basis_mp2|df_basis_cc|df_basis_sapt)[=\s]*(\w*?)\s*\{(.*?)\}',
re.MULTILINE | re.DOTALL | re.IGNORECASE)
temp = re.sub(basis_block, process_basis_block, temp)
# Process literal blocks by substituting back in
lit_block = re.compile(r'literals_psi4_yo-(\d*\d)')
temp = re.sub(lit_block, process_literal_blocks, temp)
future_imports = []
def future_replace(m):
future_imports.append(m.group(0))
return ''
future_string = re.compile('^from __future__ import .*$', flags=re.MULTILINE)
temp = re.sub(future_string, future_replace, temp)
# imports
imports = '\n'.join(future_imports) + '\n'
imports += 'import psi4\n'
imports += 'from psi4 import *\n'
imports += 'from psi4.core import *\n'
imports += 'from psi4.driver.diatomic import anharmonicity\n'
imports += 'from psi4.driver.gaussian_n import *\n'
imports += 'from psi4.driver.aliases import *\n'
imports += 'from psi4.driver.driver_cbs import xtpl_highest_1, scf_xtpl_helgaker_2, scf_xtpl_helgaker_3, corl_xtpl_helgaker_2\n'
imports += 'from psi4.driver.wrapper_database import database, db, DB_RGT, DB_RXN\n'
imports += 'from psi4.driver.wrapper_autofrag import auto_fragments\n'
imports += 'from psi4.driver.constants.physconst import *\n'
imports += 'psi4_io = core.IOManager.shared_object()\n'
# psirc (a baby PSIthon script that might live in ~/.psi4rc)
psirc_file = os.path.expanduser('~') + os.path.sep + '.psi4rc'
if os.path.isfile(psirc_file):
fh = open(psirc_file)
psirc = fh.read()
fh.close()
psirc = psirc.replace('psi4.IOManager', 'psi4.core.IOManager')
else:
psirc = ''
# Override scratch directory if user specified via env_var
scratch = ''
scratch_env = core.get_environment('PSI_SCRATCH')
if len(scratch_env):
scratch += 'psi4_io.set_default_path("%s")\n' % (scratch_env)
blank_mol = 'geometry("""\n'
blank_mol += '0 1\nH\nH 1 0.74\n'
blank_mol += '""","blank_molecule_psi4_yo")\n'
temp = imports + psirc + scratch + blank_mol + temp
# Move up the psi4.core namespace
for func in dir(core):
temp = temp.replace("psi4." + func, "psi4.core." + func)
# Move pseudonamespace for physconst into proper namespace
from psi4.driver.p4util import constants
for pc in dir(constants.physconst):
if not pc.startswith('__'):
temp = temp.replace('psi_' + pc, 'psi4.constants.' + pc)
return temp
if __name__ == "__main__":
result = process_input("""
molecule h2 {
H
H 1 R
R = .9
}
set basis 6-31G**
""")
print("Result\n==========================")
print(result)
|
gpl-2.0
|
[
3,
199,
3,
768,
15947,
5113,
199,
3,
199,
3,
510,
338,
20,
26,
376,
1551,
13,
1365,
15381,
453,
17546,
2664,
27723,
2032,
2559,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
13,
10680,
710,
510,
338,
20,
23493,
14,
199,
3,
199,
3,
710,
4248,
83,
367,
1233,
1202,
687,
1163,
623,
1417,
787,
5120,
315,
199,
3,
314,
5226,
1584,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
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,
642,
2240,
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,
199,
3,
768,
3902,
5113,
199,
3,
199,
199,
624,
2377,
543,
3423,
370,
2198,
314,
1324,
570,
436,
3957,
199,
48,
338,
898,
1901,
4465,
2018,
14,
2235,
6628,
590,
12,
4513,
20742,
20,
199,
578,
4882,
626,
2879,
314,
445,
4176,
5366,
402,
510,
338,
20,
14,
199,
199,
624,
199,
199,
309,
18771,
2018,
650,
870,
6302,
12,
340,
642,
365,
2366,
499,
14,
56,
199,
3,
692,
984,
14,
4097,
1023,
665,
378,
88,
1644,
3273,
26,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
646,
2196,
199,
504,
20742,
20,
14,
3090,
492,
7974,
24448,
199,
504,
20742,
20,
14,
3090,
14,
80,
20,
1974,
14,
3924,
492,
627,
199,
504,
20742,
20,
14,
3090,
14,
80,
20,
1974,
14,
1974,
492,
663,
63,
4844,
199,
504,
20742,
20,
492,
6170,
199,
199,
3,
26662,
2808,
5163,
3326,
199,
5645,
24448,
264,
275,
295,
14,
2014,
8,
82,
31344,
83,
10,
5645,
24448,
60,
83,
10,
3427,
83,
5830,
2795,
2862,
78,
29150,
295,
14,
16661,
1204,
295,
14,
15434,
9,
199,
199,
3,
1324,
493,
4072,
370,
506,
17731,
687,
314,
12495,
199,
5955,
275,
1052,
199,
199,
3,
22820,
446,
3775,
370,
1255,
1134,
9834,
465,
2985,
3984,
4565,
687,
20742,
898,
199,
1065,
12344,
275,
756,
421,
199,
318,
4875,
63,
1422,
63,
7093,
8,
604,
304,
272,
408,
3481,
370,
3622,
4875,
6302,
370,
6426,
436,
1072,
570,
1041,
272,
1245,
275,
661,
12647,
6302,
3427,
78,
60,
78,
5,
83,
60,
78,
60,
78,
7,
450,
334,
604,
430,
272,
746,
1379,
25834,
547,
8,
1188,
9,
421,
199,
318,
2112,
63,
1027,
63,
14005,
8,
1431,
1113,
304,
272,
408,
3481,
370,
6705,
340,
1423,
4839,
19696,
315,
9344,
465,
1059,
1041,
272,
366,
25317,
275,
1336,
1113,
14,
923,
8,
18,
9,
272,
1139,
275,
1336,
1113,
14,
923,
8,
19,
9,
272,
340,
366,
25317,
26,
267,
327,
961,
365,
282,
2366,
1750,
12,
1852,
3238,
626,
652,
9174,
543,
282,
8082,
267,
340,
295,
14,
1431,
8,
82,
23811,
33,
13,
13163,
13,
90,
30679,
87,
22952,
1139,
304,
288,
372,
1139,
267,
587,
26,
288,
1245,
275,
1689,
3364,
2018,
1750,
26,
450,
83,
2,
450,
334,
637,
430,
288,
746,
1379,
25834,
547,
8,
1188,
9,
272,
916,
295,
14,
1431,
8,
82,
4289,
13,
8995,
68,
11,
4537,
8995,
68,
10,
25060,
37,
69,
11285,
8995,
68,
19544,
4268,
1139,
304,
267,
327,
961,
1471,
506,
282,
1329,
12,
2793,
1133,
4816,
652,
315,
9344,
267,
372,
1139,
272,
916,
295,
14,
1431,
8,
82,
15542,
24898,
3985,
4268,
1139,
9,
503,
295,
14,
1431,
8,
82,
15542,
1674,
10,
4451,
4268,
1139,
304,
267,
327,
961,
365,
2575,
8072,
315,
9344,
12,
886,
6548,
267,
372,
1139,
272,
587,
26,
267,
327,
961,
1471,
506,
282,
1059,
267,
372,
1867,
6808,
83,
18781,
450,
334,
637,
9,
421,
199,
318,
28419,
3338,
8,
875,
12,
365,
19220,
29,
797,
304,
272,
408,
3481,
370,
4816,
7003,
626,
10734,
2839,
282,
1059,
315,
9344,
272,
436,
370,
2813,
9186,
366,
25317,
27624,
687,
2366,
2860,
14,
3979,
627,
19220,
10,
272,
365,
715,
12,
6127,
24476,
12,
3967,
5597,
5951,
1443,
1172,
24476,
436,
787,
2661,
3297,
370,
272,
440,
4572,
3344,
6572,
14,
339,
408,
272,
327,
961,
14018,
7003,
626,
10734,
2839,
282,
1059,
315,
9344,
12,
436,
14185,
9186,
272,
327,
366,
25317,
27624,
687,
2366,
2860,
272,
340,
365,
19220,
26,
267,
4349,
264,
275,
295,
14,
2014,
8,
82,
6774,
779,
4,
11843,
31440,
6793,
25608,
2020,
60,
87,
13356,
9807,
1103,
2807,
28435,
272,
587,
26,
267,
4349,
264,
275,
295,
14,
2014,
8,
82,
6774,
779,
4,
11843,
31440,
6793,
25608,
3134,
87,
13356,
9807,
1103,
2807,
28435,
272,
1059,
275,
4349,
264,
14,
954,
8,
1412,
63,
1027,
63,
14005,
12,
1059,
9,
272,
372,
1059,
199,
199,
318,
477,
14209,
3338,
8,
875,
304,
272,
340,
1059,
59,
16,
61,
508,
14788,
436,
1059,
1988,
17,
61,
508,
24536,
267,
372,
1059,
59,
17,
6809,
17,
61,
272,
587,
26,
267,
372,
1059,
421,
199,
318,
2112,
63,
1422,
8,
10749,
12,
859,
12,
790,
12,
574,
12,
1004,
304,
272,
408,
3481,
370,
2112,
282,
1004,
543,
663,
503,
315,
282,
663,
1853,
272,
1901,
2288,
15,
1832,
2881,
436,
4252,
15,
585,
14,
339,
408,
272,
859,
275,
859,
14,
4142,
342,
272,
790,
275,
790,
14,
4142,
342,
272,
365,
19220,
275,
715,
340,
283,
20205,
1311,
7,
315,
790,
587,
756,
272,
574,
275,
28419,
3338,
8,
585,
14,
1913,
1062,
365
] |
[
199,
3,
768,
15947,
5113,
199,
3,
199,
3,
510,
338,
20,
26,
376,
1551,
13,
1365,
15381,
453,
17546,
2664,
27723,
2032,
2559,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
13,
10680,
710,
510,
338,
20,
23493,
14,
199,
3,
199,
3,
710,
4248,
83,
367,
1233,
1202,
687,
1163,
623,
1417,
787,
5120,
315,
199,
3,
314,
5226,
1584,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
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,
642,
2240,
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,
199,
3,
768,
3902,
5113,
199,
3,
199,
199,
624,
2377,
543,
3423,
370,
2198,
314,
1324,
570,
436,
3957,
199,
48,
338,
898,
1901,
4465,
2018,
14,
2235,
6628,
590,
12,
4513,
20742,
20,
199,
578,
4882,
626,
2879,
314,
445,
4176,
5366,
402,
510,
338,
20,
14,
199,
199,
624,
199,
199,
309,
18771,
2018,
650,
870,
6302,
12,
340,
642,
365,
2366,
499,
14,
56,
199,
3,
692,
984,
14,
4097,
1023,
665,
378,
88,
1644,
3273,
26,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
646,
2196,
199,
504,
20742,
20,
14,
3090,
492,
7974,
24448,
199,
504,
20742,
20,
14,
3090,
14,
80,
20,
1974,
14,
3924,
492,
627,
199,
504,
20742,
20,
14,
3090,
14,
80,
20,
1974,
14,
1974,
492,
663,
63,
4844,
199,
504,
20742,
20,
492,
6170,
199,
199,
3,
26662,
2808,
5163,
3326,
199,
5645,
24448,
264,
275,
295,
14,
2014,
8,
82,
31344,
83,
10,
5645,
24448,
60,
83,
10,
3427,
83,
5830,
2795,
2862,
78,
29150,
295,
14,
16661,
1204,
295,
14,
15434,
9,
199,
199,
3,
1324,
493,
4072,
370,
506,
17731,
687,
314,
12495,
199,
5955,
275,
1052,
199,
199,
3,
22820,
446,
3775,
370,
1255,
1134,
9834,
465,
2985,
3984,
4565,
687,
20742,
898,
199,
1065,
12344,
275,
756,
421,
199,
318,
4875,
63,
1422,
63,
7093,
8,
604,
304,
272,
408,
3481,
370,
3622,
4875,
6302,
370,
6426,
436,
1072,
570,
1041,
272,
1245,
275,
661,
12647,
6302,
3427,
78,
60,
78,
5,
83,
60,
78,
60,
78,
7,
450,
334,
604,
430,
272,
746,
1379,
25834,
547,
8,
1188,
9,
421,
199,
318,
2112,
63,
1027,
63,
14005,
8,
1431,
1113,
304,
272,
408,
3481,
370,
6705,
340,
1423,
4839,
19696,
315,
9344,
465,
1059,
1041,
272,
366,
25317,
275,
1336,
1113,
14,
923,
8,
18,
9,
272,
1139,
275,
1336,
1113,
14,
923,
8,
19,
9,
272,
340,
366,
25317,
26,
267,
327,
961,
365,
282,
2366,
1750,
12,
1852,
3238,
626,
652,
9174,
543,
282,
8082,
267,
340,
295,
14,
1431,
8,
82,
23811,
33,
13,
13163,
13,
90,
30679,
87,
22952,
1139,
304,
288,
372,
1139,
267,
587,
26,
288,
1245,
275,
1689,
3364,
2018,
1750,
26,
450,
83,
2,
450,
334,
637,
430,
288,
746,
1379,
25834,
547,
8,
1188,
9,
272,
916,
295,
14,
1431,
8,
82,
4289,
13,
8995,
68,
11,
4537,
8995,
68,
10,
25060,
37,
69,
11285,
8995,
68,
19544,
4268,
1139,
304,
267,
327,
961,
1471,
506,
282,
1329,
12,
2793,
1133,
4816,
652,
315,
9344,
267,
372,
1139,
272,
916,
295,
14,
1431,
8,
82,
15542,
24898,
3985,
4268,
1139,
9,
503,
295,
14,
1431,
8,
82,
15542,
1674,
10,
4451,
4268,
1139,
304,
267,
327,
961,
365,
2575,
8072,
315,
9344,
12,
886,
6548,
267,
372,
1139,
272,
587,
26,
267,
327,
961,
1471,
506,
282,
1059,
267,
372,
1867,
6808,
83,
18781,
450,
334,
637,
9,
421,
199,
318,
28419,
3338,
8,
875,
12,
365,
19220,
29,
797,
304,
272,
408,
3481,
370,
4816,
7003,
626,
10734,
2839,
282,
1059,
315,
9344,
272,
436,
370,
2813,
9186,
366,
25317,
27624,
687,
2366,
2860,
14,
3979,
627,
19220,
10,
272,
365,
715,
12,
6127,
24476,
12,
3967,
5597,
5951,
1443,
1172,
24476,
436,
787,
2661,
3297,
370,
272,
440,
4572,
3344,
6572,
14,
339,
408,
272,
327,
961,
14018,
7003,
626,
10734,
2839,
282,
1059,
315,
9344,
12,
436,
14185,
9186,
272,
327,
366,
25317,
27624,
687,
2366,
2860,
272,
340,
365,
19220,
26,
267,
4349,
264,
275,
295,
14,
2014,
8,
82,
6774,
779,
4,
11843,
31440,
6793,
25608,
2020,
60,
87,
13356,
9807,
1103,
2807,
28435,
272,
587,
26,
267,
4349,
264,
275,
295,
14,
2014,
8,
82,
6774,
779,
4,
11843,
31440,
6793,
25608,
3134,
87,
13356,
9807,
1103,
2807,
28435,
272,
1059,
275,
4349,
264,
14,
954,
8,
1412,
63,
1027,
63,
14005,
12,
1059,
9,
272,
372,
1059,
199,
199,
318,
477,
14209,
3338,
8,
875,
304,
272,
340,
1059,
59,
16,
61,
508,
14788,
436,
1059,
1988,
17,
61,
508,
24536,
267,
372,
1059,
59,
17,
6809,
17,
61,
272,
587,
26,
267,
372,
1059,
421,
199,
318,
2112,
63,
1422,
8,
10749,
12,
859,
12,
790,
12,
574,
12,
1004,
304,
272,
408,
3481,
370,
2112,
282,
1004,
543,
663,
503,
315,
282,
663,
1853,
272,
1901,
2288,
15,
1832,
2881,
436,
4252,
15,
585,
14,
339,
408,
272,
859,
275,
859,
14,
4142,
342,
272,
790,
275,
790,
14,
4142,
342,
272,
365,
19220,
275,
715,
340,
283,
20205,
1311,
7,
315,
790,
587,
756,
272,
574,
275,
28419,
3338,
8,
585,
14,
1913,
1062,
365,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vFense/vFenseAgent-nix
|
agent/deps/mac/Python-2.7.5/lib/python2.7/encodings/utf_16.py
|
404
|
3984
|
""" Python 'utf-16' Codec
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""
import codecs, sys
### Codec APIs
encode = codecs.utf_16_encode
def decode(input, errors='strict'):
return codecs.utf_16_decode(input, errors, True)
class IncrementalEncoder(codecs.IncrementalEncoder):
def __init__(self, errors='strict'):
codecs.IncrementalEncoder.__init__(self, errors)
self.encoder = None
def encode(self, input, final=False):
if self.encoder is None:
result = codecs.utf_16_encode(input, self.errors)[0]
if sys.byteorder == 'little':
self.encoder = codecs.utf_16_le_encode
else:
self.encoder = codecs.utf_16_be_encode
return result
return self.encoder(input, self.errors)[0]
def reset(self):
codecs.IncrementalEncoder.reset(self)
self.encoder = None
def getstate(self):
# state info we return to the caller:
# 0: stream is in natural order for this platform
# 2: endianness hasn't been determined yet
# (we're never writing in unnatural order)
return (2 if self.encoder is None else 0)
def setstate(self, state):
if state:
self.encoder = None
else:
if sys.byteorder == 'little':
self.encoder = codecs.utf_16_le_encode
else:
self.encoder = codecs.utf_16_be_encode
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
def __init__(self, errors='strict'):
codecs.BufferedIncrementalDecoder.__init__(self, errors)
self.decoder = None
def _buffer_decode(self, input, errors, final):
if self.decoder is None:
(output, consumed, byteorder) = \
codecs.utf_16_ex_decode(input, errors, 0, final)
if byteorder == -1:
self.decoder = codecs.utf_16_le_decode
elif byteorder == 1:
self.decoder = codecs.utf_16_be_decode
elif consumed >= 2:
raise UnicodeError("UTF-16 stream does not start with BOM")
return (output, consumed)
return self.decoder(input, self.errors, final)
def reset(self):
codecs.BufferedIncrementalDecoder.reset(self)
self.decoder = None
class StreamWriter(codecs.StreamWriter):
def __init__(self, stream, errors='strict'):
codecs.StreamWriter.__init__(self, stream, errors)
self.encoder = None
def reset(self):
codecs.StreamWriter.reset(self)
self.encoder = None
def encode(self, input, errors='strict'):
if self.encoder is None:
result = codecs.utf_16_encode(input, errors)
if sys.byteorder == 'little':
self.encoder = codecs.utf_16_le_encode
else:
self.encoder = codecs.utf_16_be_encode
return result
else:
return self.encoder(input, errors)
class StreamReader(codecs.StreamReader):
def reset(self):
codecs.StreamReader.reset(self)
try:
del self.decode
except AttributeError:
pass
def decode(self, input, errors='strict'):
(object, consumed, byteorder) = \
codecs.utf_16_ex_decode(input, errors, 0, False)
if byteorder == -1:
self.decode = codecs.utf_16_le_decode
elif byteorder == 1:
self.decode = codecs.utf_16_be_decode
elif consumed>=2:
raise UnicodeError,"UTF-16 stream does not start with BOM"
return (object, consumed)
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='utf-16',
encode=encode,
decode=decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
lgpl-3.0
|
[
624,
2018,
283,
1624,
13,
975,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
12,
984,
199,
199,
5680,
13732,
15913,
199,
199,
2143,
275,
6010,
14,
1624,
63,
975,
63,
2143,
199,
199,
318,
4849,
8,
1210,
12,
2552,
534,
4768,
735,
272,
372,
6010,
14,
1624,
63,
975,
63,
2708,
8,
1210,
12,
2552,
12,
715,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
6010,
14,
17016,
855,
826,
721,
277,
12,
2552,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
340,
291,
14,
9347,
365,
488,
26,
288,
754,
275,
6010,
14,
1624,
63,
975,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
288,
340,
984,
14,
19415,
508,
283,
10182,
356,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
288,
587,
26,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
288,
372,
754,
267,
372,
291,
14,
9347,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
17016,
14,
3958,
8,
277,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
664,
929,
8,
277,
304,
267,
327,
1174,
2256,
781,
372,
370,
314,
8025,
26,
267,
327,
378,
26,
2547,
365,
315,
19981,
1865,
367,
642,
4298,
267,
327,
499,
26,
17638,
4171,
18699,
1133,
2757,
12037,
5966,
267,
327,
334,
1129,
3984,
7078,
3575,
315,
625,
15759,
1865,
9,
267,
372,
334,
18,
340,
291,
14,
9347,
365,
488,
587,
378,
9,
339,
347,
663,
929,
8,
277,
12,
1174,
304,
267,
340,
1174,
26,
288,
291,
14,
9347,
275,
488,
267,
587,
26,
288,
340,
984,
14,
19415,
508,
283,
10182,
356,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
288,
587,
26,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
199,
199,
533,
24385,
8,
8933,
14,
23139,
16703,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
6010,
14,
23139,
16703,
855,
826,
721,
277,
12,
2552,
9,
267,
291,
14,
8813,
275,
488,
339,
347,
485,
2738,
63,
2708,
8,
277,
12,
1324,
12,
2552,
12,
4242,
304,
267,
340,
291,
14,
8813,
365,
488,
26,
288,
334,
1199,
12,
16949,
12,
30310,
9,
275,
971,
355,
6010,
14,
1624,
63,
975,
63,
476,
63,
2708,
8,
1210,
12,
2552,
12,
378,
12,
4242,
9,
288,
340,
30310,
508,
446,
17,
26,
355,
291,
14,
8813,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
288,
916,
30310,
508,
413,
26,
355,
291,
14,
8813,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
288,
916,
16949,
2356,
499,
26,
355,
746,
20872,
480,
6610,
13,
975,
2547,
1630,
440,
1343,
543,
17720,
531,
288,
372,
334,
1199,
12,
16949,
9,
267,
372,
291,
14,
8813,
8,
1210,
12,
291,
14,
2550,
12,
4242,
9,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
23139,
16703,
14,
3958,
8,
277,
9,
267,
291,
14,
8813,
275,
488,
199,
199,
533,
24163,
8,
8933,
14,
16551,
304,
272,
347,
636,
826,
721,
277,
12,
2547,
12,
2552,
534,
4768,
735,
267,
6010,
14,
16551,
855,
826,
721,
277,
12,
2547,
12,
2552,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
16551,
14,
3958,
8,
277,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
3752,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
340,
291,
14,
9347,
365,
488,
26,
288,
754,
275,
6010,
14,
1624,
63,
975,
63,
2143,
8,
1210,
12,
2552,
9,
288,
340,
984,
14,
19415,
508,
283,
10182,
356,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
288,
587,
26,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
288,
372,
754,
267,
587,
26,
288,
372,
291,
14,
9347,
8,
1210,
12,
2552,
9,
199,
199,
533,
22970,
8,
8933,
14,
16132,
304,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
16132,
14,
3958,
8,
277,
9,
267,
862,
26,
288,
2150,
291,
14,
2708,
267,
871,
4281,
26,
288,
986,
339,
347,
4849,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
334,
785,
12,
16949,
12,
30310,
9,
275,
971,
288,
6010,
14,
1624,
63,
975,
63,
476,
63,
2708,
8,
1210,
12,
2552,
12,
378,
12,
756,
9,
267,
340,
30310,
508,
446,
17,
26,
288,
291,
14,
2708,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
267,
916,
30310,
508,
413,
26,
288,
291,
14,
2708,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
267,
916,
16949,
8119,
18,
26,
288,
746,
20872,
4589,
6610,
13,
975,
2547,
1630,
440,
1343,
543,
17720,
2,
267,
372,
334,
785,
12,
16949,
9,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1624,
13,
975,
297,
267,
3752,
29,
2143,
12,
267,
4849,
29,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
1624,
13,
975,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
12,
984,
199,
199,
5680,
13732,
15913,
199,
199,
2143,
275,
6010,
14,
1624,
63,
975,
63,
2143,
199,
199,
318,
4849,
8,
1210,
12,
2552,
534,
4768,
735,
272,
372,
6010,
14,
1624,
63,
975,
63,
2708,
8,
1210,
12,
2552,
12,
715,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
6010,
14,
17016,
855,
826,
721,
277,
12,
2552,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
340,
291,
14,
9347,
365,
488,
26,
288,
754,
275,
6010,
14,
1624,
63,
975,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
288,
340,
984,
14,
19415,
508,
283,
10182,
356,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
288,
587,
26,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
288,
372,
754,
267,
372,
291,
14,
9347,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
17016,
14,
3958,
8,
277,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
664,
929,
8,
277,
304,
267,
327,
1174,
2256,
781,
372,
370,
314,
8025,
26,
267,
327,
378,
26,
2547,
365,
315,
19981,
1865,
367,
642,
4298,
267,
327,
499,
26,
17638,
4171,
18699,
1133,
2757,
12037,
5966,
267,
327,
334,
1129,
3984,
7078,
3575,
315,
625,
15759,
1865,
9,
267,
372,
334,
18,
340,
291,
14,
9347,
365,
488,
587,
378,
9,
339,
347,
663,
929,
8,
277,
12,
1174,
304,
267,
340,
1174,
26,
288,
291,
14,
9347,
275,
488,
267,
587,
26,
288,
340,
984,
14,
19415,
508,
283,
10182,
356,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
288,
587,
26,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
199,
199,
533,
24385,
8,
8933,
14,
23139,
16703,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
6010,
14,
23139,
16703,
855,
826,
721,
277,
12,
2552,
9,
267,
291,
14,
8813,
275,
488,
339,
347,
485,
2738,
63,
2708,
8,
277,
12,
1324,
12,
2552,
12,
4242,
304,
267,
340,
291,
14,
8813,
365,
488,
26,
288,
334,
1199,
12,
16949,
12,
30310,
9,
275,
971,
355,
6010,
14,
1624,
63,
975,
63,
476,
63,
2708,
8,
1210,
12,
2552,
12,
378,
12,
4242,
9,
288,
340,
30310,
508,
446,
17,
26,
355,
291,
14,
8813,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
288,
916,
30310,
508,
413,
26,
355,
291,
14,
8813,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
288,
916,
16949,
2356,
499,
26,
355,
746,
20872,
480,
6610,
13,
975,
2547,
1630,
440,
1343,
543,
17720,
531,
288,
372,
334,
1199,
12,
16949,
9,
267,
372,
291,
14,
8813,
8,
1210,
12,
291,
14,
2550,
12,
4242,
9,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
23139,
16703,
14,
3958,
8,
277,
9,
267,
291,
14,
8813,
275,
488,
199,
199,
533,
24163,
8,
8933,
14,
16551,
304,
272,
347,
636,
826,
721,
277,
12,
2547,
12,
2552,
534,
4768,
735,
267,
6010,
14,
16551,
855,
826,
721,
277,
12,
2547,
12,
2552,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
16551,
14,
3958,
8,
277,
9,
267,
291,
14,
9347,
275,
488,
339,
347,
3752,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
340,
291,
14,
9347,
365,
488,
26,
288,
754,
275,
6010,
14,
1624,
63,
975,
63,
2143,
8,
1210,
12,
2552,
9,
288,
340,
984,
14,
19415,
508,
283,
10182,
356,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
288,
587,
26,
355,
291,
14,
9347,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
288,
372,
754,
267,
587,
26,
288,
372,
291,
14,
9347,
8,
1210,
12,
2552,
9,
199,
199,
533,
22970,
8,
8933,
14,
16132,
304,
339,
347,
5305,
8,
277,
304,
267,
6010,
14,
16132,
14,
3958,
8,
277,
9,
267,
862,
26,
288,
2150,
291,
14,
2708,
267,
871,
4281,
26,
288,
986,
339,
347,
4849,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
334,
785,
12,
16949,
12,
30310,
9,
275,
971,
288,
6010,
14,
1624,
63,
975,
63,
476,
63,
2708,
8,
1210,
12,
2552,
12,
378,
12,
756,
9,
267,
340,
30310,
508,
446,
17,
26,
288,
291,
14,
2708,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
267,
916,
30310,
508,
413,
26,
288,
291,
14,
2708,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
267,
916,
16949,
8119,
18,
26,
288,
746,
20872,
4589,
6610,
13,
975,
2547,
1630,
440,
1343,
543,
17720,
2,
267,
372,
334,
785,
12,
16949,
9,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1624,
13,
975,
297,
267,
3752,
29,
2143,
12,
267,
4849,
29,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
GbalsaC/bitnamiP
|
venv/lib/python2.7/site-packages/dateutil/zoneinfo/__init__.py
|
144
|
2773
|
# -*- coding: utf-8 -*-
"""
Copyright (c) 2003-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
This module offers extensions to the standard Python
datetime module.
"""
from dateutil.tz import tzfile
from tarfile import TarFile
import os
__author__ = "Tomi Pieviläinen <tomi.pievilainen@iki.fi>"
__license__ = "Simplified BSD"
__all__ = ["setcachesize", "gettz", "rebuild"]
CACHE = []
CACHESIZE = 10
class tzfile(tzfile):
def __reduce__(self):
return (gettz, (self._filename,))
def getzoneinfofile():
filenames = sorted(os.listdir(os.path.join(os.path.dirname(__file__))))
filenames.reverse()
for entry in filenames:
if entry.startswith("zoneinfo") and ".tar." in entry:
return os.path.join(os.path.dirname(__file__), entry)
return None
ZONEINFOFILE = getzoneinfofile()
del getzoneinfofile
def setcachesize(size):
global CACHESIZE, CACHE
CACHESIZE = size
del CACHE[size:]
def gettz(name):
tzinfo = None
if ZONEINFOFILE:
for cachedname, tzinfo in CACHE:
if cachedname == name:
break
else:
tf = TarFile.open(ZONEINFOFILE)
try:
zonefile = tf.extractfile(name)
except KeyError:
tzinfo = None
else:
tzinfo = tzfile(zonefile)
tf.close()
CACHE.insert(0, (name, tzinfo))
del CACHE[CACHESIZE:]
return tzinfo
def rebuild(filename, tag=None, format="gz"):
import tempfile, shutil
tmpdir = tempfile.mkdtemp()
zonedir = os.path.join(tmpdir, "zoneinfo")
moduledir = os.path.dirname(__file__)
if tag: tag = "-"+tag
targetname = "zoneinfo%s.tar.%s" % (tag, format)
try:
tf = TarFile.open(filename)
# The "backwards" zone file contains links to other files, so must be
# processed as last
for name in sorted(tf.getnames(),
key=lambda k: k != "backward" and k or "z"):
if not (name.endswith(".sh") or
name.endswith(".tab") or
name == "leapseconds"):
tf.extract(name, tmpdir)
filepath = os.path.join(tmpdir, name)
os.system("zic -d %s %s" % (zonedir, filepath))
tf.close()
target = os.path.join(moduledir, targetname)
for entry in os.listdir(moduledir):
if entry.startswith("zoneinfo") and ".tar." in entry:
os.unlink(os.path.join(moduledir, entry))
tf = TarFile.open(target, "w:%s" % format)
for entry in os.listdir(zonedir):
entrypath = os.path.join(zonedir, entry)
tf.add(entrypath, entry)
tf.close()
finally:
shutil.rmtree(tmpdir)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
7384,
334,
67,
9,
13004,
13,
9397,
221,
598,
833,
1214,
79,
653,
1873,
278,
23009,
665,
71,
833,
1214,
79,
32,
78,
1873,
278,
23009,
14,
846,
30,
199,
199,
2765,
859,
32563,
5478,
370,
314,
4465,
2018,
199,
2083,
859,
14,
199,
624,
199,
504,
22208,
14,
3903,
492,
5823,
493,
199,
504,
13608,
492,
30227,
199,
646,
747,
199,
199,
363,
2502,
363,
275,
298,
52,
676,
73,
510,
1873,
29792,
13733,
262,
287,
665,
475,
2664,
14,
1038,
6857,
382,
1581,
287,
32,
11545,
14,
329,
4335,
199,
363,
1682,
363,
275,
298,
51,
3236,
30200,
6289,
2,
199,
199,
363,
452,
363,
275,
2097,
409,
1637,
890,
401,
298,
362,
3903,
401,
298,
19278,
937,
199,
199,
8677,
275,
942,
199,
3263,
1244,
654,
11025,
275,
1616,
199,
199,
533,
5823,
493,
8,
3903,
493,
304,
272,
347,
636,
5270,
721,
277,
304,
267,
372,
334,
362,
3903,
12,
334,
277,
423,
1501,
4641,
199,
199,
318,
664,
2619,
815,
493,
837,
272,
6203,
275,
3355,
8,
736,
14,
7374,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
363,
7845,
272,
6203,
14,
4471,
342,
272,
367,
2397,
315,
6203,
26,
267,
340,
2397,
14,
2460,
480,
2619,
815,
531,
436,
3680,
5369,
2122,
315,
2397,
26,
288,
372,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
2397,
9,
272,
372,
488,
199,
199,
15353,
4531,
3817,
275,
664,
2619,
815,
493,
342,
199,
199,
2264,
664,
2619,
815,
493,
199,
199,
318,
663,
1637,
890,
8,
890,
304,
272,
2288,
7240,
1244,
654,
11025,
12,
7240,
4576,
272,
7240,
1244,
654,
11025,
275,
1568,
272,
2150,
7240,
4576,
59,
890,
2938,
199,
199,
318,
664,
3903,
8,
354,
304,
272,
10313,
275,
488,
272,
340,
3107,
4817,
4531,
3817,
26,
267,
367,
6328,
354,
12,
10313,
315,
7240,
4576,
26,
288,
340,
6328,
354,
508,
536,
26,
355,
2059,
267,
587,
26,
288,
2833,
275,
30227,
14,
1490,
8,
15353,
4531,
3817,
9,
288,
862,
26,
355,
5718,
493,
275,
2833,
14,
5005,
493,
8,
354,
9,
288,
871,
4067,
26,
355,
10313,
275,
488,
288,
587,
26,
355,
10313,
275,
5823,
493,
8,
2619,
493,
9,
288,
2833,
14,
1600,
342,
288,
7240,
4576,
14,
3176,
8,
16,
12,
334,
354,
12,
10313,
430,
288,
2150,
7240,
4576,
59,
3263,
1244,
654,
11025,
2938,
272,
372,
10313,
199,
199,
318,
22110,
8,
1501,
12,
1947,
29,
403,
12,
1475,
628,
6838,
2349,
272,
492,
5549,
12,
5145,
272,
12885,
275,
5549,
14,
11983,
342,
272,
5718,
694,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
298,
2619,
815,
531,
272,
859,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
272,
340,
1947,
26,
1947,
275,
3905,
7709,
1450,
272,
1347,
354,
275,
298,
2619,
815,
5,
83,
14,
5369,
4111,
83,
2,
450,
334,
1450,
12,
1475,
9,
272,
862,
26,
267,
2833,
275,
30227,
14,
1490,
8,
1501,
9,
267,
327,
710,
298,
22269,
2,
5718,
570,
3509,
6220,
370,
1163,
1584,
12,
880,
1471,
506,
267,
327,
7686,
465,
2061,
267,
367,
536,
315,
3355,
8,
3249,
14,
362,
1247,
1062,
2574,
790,
29,
2734,
1022,
26,
1022,
1137,
298,
15457,
2,
436,
1022,
503,
298,
90,
2349,
288,
340,
440,
334,
354,
14,
4130,
9520,
609,
531,
503,
490,
536,
14,
4130,
9520,
2902,
531,
503,
490,
536,
508,
298,
28764,
4515,
2349,
355,
2833,
14,
5005,
8,
354,
12,
12885,
9,
355,
9911,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
536,
9,
355,
747,
14,
2253,
480,
90,
530,
446,
68,
450,
83,
450,
83,
2,
450,
334,
2619,
694,
12,
9911,
430,
267,
2833,
14,
1600,
342,
267,
1347,
275,
747,
14,
515,
14,
904,
8,
578,
694,
12,
1347,
354,
9,
267,
367,
2397,
315,
747,
14,
7374,
8,
578,
694,
304,
288,
340,
2397,
14,
2460,
480,
2619,
815,
531,
436,
3680,
5369,
2122,
315,
2397,
26,
355,
747,
14,
7162,
8,
736,
14,
515,
14,
904,
8,
578,
694,
12,
2397,
430,
267,
2833,
275,
30227,
14,
1490,
8,
1375,
12,
298,
87,
2689,
83,
2,
450,
1475,
9,
267,
367,
2397,
315,
747,
14,
7374,
8,
2619,
694,
304,
288,
2397,
515,
275,
747,
14,
515,
14,
904,
8,
2619,
694,
12,
2397,
9,
288,
2833,
14,
525,
8,
2373,
515,
12,
2397,
9,
267,
2833,
14,
1600,
342,
272,
3753,
26,
267,
5145,
14,
9242,
8,
8616,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
7384,
334,
67,
9,
13004,
13,
9397,
221,
598,
833,
1214,
79,
653,
1873,
278,
23009,
665,
71,
833,
1214,
79,
32,
78,
1873,
278,
23009,
14,
846,
30,
199,
199,
2765,
859,
32563,
5478,
370,
314,
4465,
2018,
199,
2083,
859,
14,
199,
624,
199,
504,
22208,
14,
3903,
492,
5823,
493,
199,
504,
13608,
492,
30227,
199,
646,
747,
199,
199,
363,
2502,
363,
275,
298,
52,
676,
73,
510,
1873,
29792,
13733,
262,
287,
665,
475,
2664,
14,
1038,
6857,
382,
1581,
287,
32,
11545,
14,
329,
4335,
199,
363,
1682,
363,
275,
298,
51,
3236,
30200,
6289,
2,
199,
199,
363,
452,
363,
275,
2097,
409,
1637,
890,
401,
298,
362,
3903,
401,
298,
19278,
937,
199,
199,
8677,
275,
942,
199,
3263,
1244,
654,
11025,
275,
1616,
199,
199,
533,
5823,
493,
8,
3903,
493,
304,
272,
347,
636,
5270,
721,
277,
304,
267,
372,
334,
362,
3903,
12,
334,
277,
423,
1501,
4641,
199,
199,
318,
664,
2619,
815,
493,
837,
272,
6203,
275,
3355,
8,
736,
14,
7374,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
363,
7845,
272,
6203,
14,
4471,
342,
272,
367,
2397,
315,
6203,
26,
267,
340,
2397,
14,
2460,
480,
2619,
815,
531,
436,
3680,
5369,
2122,
315,
2397,
26,
288,
372,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
2397,
9,
272,
372,
488,
199,
199,
15353,
4531,
3817,
275,
664,
2619,
815,
493,
342,
199,
199,
2264,
664,
2619,
815,
493,
199,
199,
318,
663,
1637,
890,
8,
890,
304,
272,
2288,
7240,
1244,
654,
11025,
12,
7240,
4576,
272,
7240,
1244,
654,
11025,
275,
1568,
272,
2150,
7240,
4576,
59,
890,
2938,
199,
199,
318,
664,
3903,
8,
354,
304,
272,
10313,
275,
488,
272,
340,
3107,
4817,
4531,
3817,
26,
267,
367,
6328,
354,
12,
10313,
315,
7240,
4576,
26,
288,
340,
6328,
354,
508,
536,
26,
355,
2059,
267,
587,
26,
288,
2833,
275,
30227,
14,
1490,
8,
15353,
4531,
3817,
9,
288,
862,
26,
355,
5718,
493,
275,
2833,
14,
5005,
493,
8,
354,
9,
288,
871,
4067,
26,
355,
10313,
275,
488,
288,
587,
26,
355,
10313,
275,
5823,
493,
8,
2619,
493,
9,
288,
2833,
14,
1600,
342,
288,
7240,
4576,
14,
3176,
8,
16,
12,
334,
354,
12,
10313,
430,
288,
2150,
7240,
4576,
59,
3263,
1244,
654,
11025,
2938,
272,
372,
10313,
199,
199,
318,
22110,
8,
1501,
12,
1947,
29,
403,
12,
1475,
628,
6838,
2349,
272,
492,
5549,
12,
5145,
272,
12885,
275,
5549,
14,
11983,
342,
272,
5718,
694,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
298,
2619,
815,
531,
272,
859,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
272,
340,
1947,
26,
1947,
275,
3905,
7709,
1450,
272,
1347,
354,
275,
298,
2619,
815,
5,
83,
14,
5369,
4111,
83,
2,
450,
334,
1450,
12,
1475,
9,
272,
862,
26,
267,
2833,
275,
30227,
14,
1490,
8,
1501,
9,
267,
327,
710,
298,
22269,
2,
5718,
570,
3509,
6220,
370,
1163,
1584,
12,
880,
1471,
506,
267,
327,
7686,
465,
2061,
267,
367,
536,
315,
3355,
8,
3249,
14,
362,
1247,
1062,
2574,
790,
29,
2734,
1022,
26,
1022,
1137,
298,
15457,
2,
436,
1022,
503,
298,
90,
2349,
288,
340,
440,
334,
354,
14,
4130,
9520,
609,
531,
503,
490,
536,
14,
4130,
9520,
2902,
531,
503,
490,
536,
508,
298,
28764,
4515,
2349,
355,
2833,
14,
5005,
8,
354,
12,
12885,
9,
355,
9911,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
536,
9,
355,
747,
14,
2253,
480,
90,
530,
446,
68,
450,
83,
450,
83,
2,
450,
334,
2619,
694,
12,
9911,
430,
267,
2833,
14,
1600,
342,
267,
1347,
275,
747,
14,
515,
14,
904,
8,
578,
694,
12,
1347,
354,
9,
267,
367,
2397,
315,
747,
14,
7374,
8,
578,
694,
304,
288,
340,
2397,
14,
2460,
480,
2619,
815,
531,
436,
3680,
5369,
2122,
315,
2397,
26,
355,
747,
14,
7162,
8,
736,
14,
515,
14,
904,
8,
578,
694,
12,
2397,
430,
267,
2833,
275,
30227,
14,
1490,
8,
1375,
12,
298,
87,
2689,
83,
2,
450,
1475,
9,
267,
367,
2397,
315,
747,
14,
7374,
8,
2619,
694,
304,
288,
2397,
515,
275,
747,
14,
515,
14,
904,
8,
2619,
694,
12,
2397,
9,
288,
2833,
14,
525,
8,
2373,
515,
12,
2397,
9,
267,
2833,
14,
1600,
342,
272,
3753,
26,
267,
5145,
14,
9242,
8,
8616,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ojengwa/odoo
|
addons/product/__init__.py
|
443
|
1120
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import product
import pricelist
import report
import partner
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
3336,
199,
646,
25162,
199,
646,
3622,
199,
646,
5854,
199,
646,
12262,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
3336,
199,
646,
25162,
199,
646,
3622,
199,
646,
5854,
199,
646,
12262,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Kijewski/ctypesgen_to_pxd
|
convert_libc.py
|
1
|
3013
|
#!/usr/bin/env python3
from os import open, O_RDWR, makedirs, devnull
from os.path import abspath, exists, isfile, isdir, dirname
from subprocess import check_call, check_output, STDOUT
from re import compile as compile_re, M
from sys import argv, stderr
# Standard headers as of POSIX.1-2008 (Base Specifications, Issue 7)
# http://pubs.opengroup.org/onlinepubs/9699919799/
_HEADERS = '''
aio
arpa/inet
assert
complex
cpio
ctype
dirent
dlfcn
errno
fcntl
fenv
float
fmtmsg
fnmatch
ftw
glob
grp
iconv
inttypes
iso646
langinfo
libgen
limits
locale
math
monetary
mqueue
ndbm
net/if
netdb
netinet/in
netinet/tcp
nl_types
poll
pthread
pwd
regex
sched
search
semaphore
setjmp
signal
spawn
stdarg
stdbool
stddef
stdint
stdio
stdlib
string
strings
stropts
sys/ipc
sys/mman
sys/msg
sys/resource
sys/select
sys/sem
sys/shm
sys/socket
sys/stat
sys/statvfs
sys/time
sys/times
sys/types
sys/uio
sys/un
sys/utsname
sys/wait
syslog
tar
termios
tgmath
time
trace
ulimit
unistd
utime
utmpx
wchar
wctype
wordexp
alloca
malloc
'''.split()
_include_pattern = compile_re(r'^ (/usr/[+\-./0-9@A-Z_a-z]+)$', M)
_null_fd = open(devnull, O_RDWR)
def main(dest_base='./converted_headers', *args,
root=dirname(abspath(__file__))):
cc1plus = check_output(
('gcc', '-print-prog-name=cc1plus'),
stdin=_null_fd,
stderr=_null_fd,
).decode('UTF-8', 'ignore').split('\n',1)[0]
includepaths = _include_pattern.findall(check_output(
(cc1plus, '-v'),
stdin=_null_fd,
stderr=STDOUT,
).decode('UTF-8', 'ignore').split('\n\n',1)[0])
for header in _HEADERS:
src_paths = [
abspath('%s/%s.h' % (includepath, header))
for includepath in includepaths
]
for src_path in src_paths:
if exists(src_path) and isfile(src_path):
break
else:
print('\nHeader does not exists: ' + header + '. Searched in:',
*src_paths, file=stderr, sep='\n')
continue
dest_path = abspath('%s/%s.pxd' % (dest_base, header))
if exists(dest_path):
print('\nAlready converted:', dest_path, file=stderr)
continue
dest_dir = dirname(dest_path)
if not exists(dest_dir):
makedirs(dest_dir)
check_call(('touch', dest_dir + '/__init__.pxd'))
elif not isdir(dest_dir):
continue
print('\nConverting:', src_path, file=stderr)
check_call(
(root + '/ctypesgen_to_pxd.py',
*args, '-t=h', '-f="<%s.h>"' % header,
src_path, dest_path),
)
if __name__ == '__main__':
main(*argv[1:])
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
504,
747,
492,
1551,
12,
593,
63,
15543,
6524,
12,
1852,
3220,
12,
4866,
2307,
199,
504,
747,
14,
515,
492,
19529,
12,
3495,
12,
29214,
12,
26004,
12,
9017,
199,
504,
3873,
492,
1104,
63,
1250,
12,
1104,
63,
1199,
12,
4384,
12619,
199,
504,
295,
492,
6555,
465,
6555,
63,
264,
12,
603,
199,
504,
984,
492,
9238,
12,
4635,
421,
199,
3,
9739,
2323,
465,
402,
18169,
14,
17,
13,
9300,
334,
1563,
5367,
3477,
83,
12,
13383,
1520,
9,
199,
3,
1455,
921,
5645,
83,
14,
1490,
923,
14,
1308,
15,
15178,
5645,
83,
15,
2534,
5637,
11165,
1020,
15,
199,
199,
63,
21178,
275,
1449,
272,
282,
2308,
272,
601,
387,
15,
10811,
272,
702,
272,
6114,
272,
286,
13937,
272,
16360,
272,
487,
640,
272,
366,
276,
6413,
272,
7554,
272,
12871,
272,
289,
1813,
272,
2069,
272,
7104,
1328,
272,
15951,
272,
289,
8122,
272,
5739,
272,
18598,
272,
284,
5598,
272,
1109,
1313,
272,
11601,
11387,
272,
6339,
815,
272,
1973,
2268,
272,
10976,
272,
5867,
272,
3473,
272,
333,
25759,
695,
272,
333,
1825,
272,
302,
20666,
272,
1851,
15,
692,
272,
1851,
697,
272,
1851,
10811,
15,
262,
272,
1851,
10811,
15,
8815,
272,
12992,
63,
1313,
272,
11271,
272,
299,
2671,
272,
14374,
272,
5163,
272,
10286,
272,
2754,
272,
542,
17185,
272,
663,
74,
311,
272,
4673,
272,
15187,
272,
2418,
1273,
272,
2418,
2245,
272,
2418,
318,
272,
2418,
442,
272,
410,
3006,
272,
26678,
272,
1059,
272,
3326,
272,
410,
293,
8382,
272,
984,
15,
32352,
272,
984,
15,
596,
290,
272,
984,
15,
1328,
272,
984,
15,
1927,
272,
984,
15,
2416,
272,
984,
15,
21678,
272,
984,
15,
609,
77,
272,
984,
15,
3450,
272,
984,
15,
3736,
272,
984,
15,
3736,
20970,
272,
984,
15,
521,
272,
984,
15,
4508,
272,
984,
15,
1313,
272,
984,
15,
1907,
79,
272,
984,
15,
324,
272,
984,
15,
14608,
354,
272,
984,
15,
2573,
272,
22112,
272,
5330,
272,
28725,
272,
22387,
3442,
272,
900,
272,
3307,
272,
399,
3097,
272,
625,
631,
68,
272,
399,
521,
272,
11430,
311,
88,
272,
336,
1560,
272,
336,
3667,
272,
1319,
31450,
339,
741,
320,
696,
272,
333,
9373,
199,
891,
1370,
1294,
342,
421,
199,
63,
2613,
63,
3401,
275,
6555,
63,
264,
8,
82,
4289,
334,
15,
2647,
32418,
7896,
13,
13186,
16,
13,
25,
32,
33,
13,
58,
63,
65,
13,
90,
11896,
4268,
603,
9,
199,
199,
63,
2307,
63,
2592,
275,
1551,
8,
19778,
12,
593,
63,
15543,
6524,
9,
421,
199,
318,
2446,
8,
2614,
63,
1095,
534,
13186,
22818,
63,
2139,
297,
627,
589,
12,
268,
1738,
29,
3475,
8,
4832,
3460,
493,
8964,
304,
272,
7429,
17,
6666,
275,
1104,
63,
1199,
8,
267,
661,
13112,
297,
2475,
1361,
13,
6595,
13,
354,
29,
2055,
17,
6666,
659,
267,
9009,
3699,
2307,
63,
2592,
12,
267,
4635,
3699,
2307,
63,
2592,
12,
272,
7092,
2708,
360,
6610,
13,
24,
297,
283,
4247,
1959,
1294,
2258,
78,
297,
17,
2788,
16,
61,
339,
2387,
3771,
275,
485,
2613,
63,
3401,
14,
6452,
8,
1074,
63,
1199,
8,
267,
334,
2055,
17,
6666,
12,
2475,
86,
659,
267,
9009,
3699,
2307,
63,
2592,
12,
267,
4635,
29,
13850,
12,
272,
7092,
2708,
360,
6610,
13,
24,
297,
283,
4247,
1959,
1294,
2258,
78,
60,
78,
297,
17,
2788,
16,
566,
339,
367,
1406,
315,
485,
21178,
26,
267,
2928,
63,
3771,
275,
359,
288,
19529,
3508,
83,
3149,
83,
14,
72,
7,
450,
334,
2613,
515,
12,
1406,
430,
288,
367,
2387,
515,
315,
2387,
3771,
267,
1622,
267,
367,
2928,
63,
515,
315,
2928,
63,
3771,
26,
288,
340,
3495,
8,
2164,
63,
515,
9,
436,
29214,
8,
2164,
63,
515,
304,
355,
2059,
267,
587,
26,
288,
870,
2258,
78,
2567,
1630,
440,
3495,
26,
283,
435,
1406,
435,
1987,
8730,
379,
315,
6536,
2116,
627,
2164,
63,
3771,
12,
570,
29,
3083,
12,
7375,
17115,
78,
358,
288,
1980,
398,
2053,
63,
515,
275,
19529,
3508,
83,
3149,
83,
14,
80,
2207,
7,
450,
334,
2614,
63,
1095,
12,
1406,
430,
267,
340,
3495,
8,
2614,
63,
515,
304,
288,
870,
2258,
78,
16760,
6702,
6536,
2053,
63,
515,
12,
570,
29,
3083,
9,
288,
1980,
398,
2053,
63,
694,
275,
9017,
8,
2614,
63,
515,
9,
267,
340,
440,
3495,
8,
2614,
63,
694,
304,
288,
1852,
3220,
8,
2614,
63,
694,
9,
288,
1104,
63,
1250,
4725,
12376,
297,
2053,
63,
694,
435,
1994,
363,
826,
4343,
80,
2207,
1333,
267,
916,
440,
26004,
8,
2614,
63,
694,
304,
288,
1980,
398,
870,
2258,
78,
7619,
1337,
6536,
2928,
63,
515,
12,
570,
29,
3083,
9,
267,
1104,
63,
1250,
8,
288,
334,
1231,
435,
1994,
3667,
1226,
287,
63,
475,
63,
80,
2207,
14,
647,
297,
1467,
627,
589,
12,
2475,
84,
29,
72,
297,
2475,
70,
628,
21110,
83,
14,
72,
4335,
7,
450,
1406,
12,
1467,
2928,
63,
515,
12,
2053,
63,
515,
395,
267,
776,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
2031,
3020,
59,
17,
5728,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
504,
747,
492,
1551,
12,
593,
63,
15543,
6524,
12,
1852,
3220,
12,
4866,
2307,
199,
504,
747,
14,
515,
492,
19529,
12,
3495,
12,
29214,
12,
26004,
12,
9017,
199,
504,
3873,
492,
1104,
63,
1250,
12,
1104,
63,
1199,
12,
4384,
12619,
199,
504,
295,
492,
6555,
465,
6555,
63,
264,
12,
603,
199,
504,
984,
492,
9238,
12,
4635,
421,
199,
3,
9739,
2323,
465,
402,
18169,
14,
17,
13,
9300,
334,
1563,
5367,
3477,
83,
12,
13383,
1520,
9,
199,
3,
1455,
921,
5645,
83,
14,
1490,
923,
14,
1308,
15,
15178,
5645,
83,
15,
2534,
5637,
11165,
1020,
15,
199,
199,
63,
21178,
275,
1449,
272,
282,
2308,
272,
601,
387,
15,
10811,
272,
702,
272,
6114,
272,
286,
13937,
272,
16360,
272,
487,
640,
272,
366,
276,
6413,
272,
7554,
272,
12871,
272,
289,
1813,
272,
2069,
272,
7104,
1328,
272,
15951,
272,
289,
8122,
272,
5739,
272,
18598,
272,
284,
5598,
272,
1109,
1313,
272,
11601,
11387,
272,
6339,
815,
272,
1973,
2268,
272,
10976,
272,
5867,
272,
3473,
272,
333,
25759,
695,
272,
333,
1825,
272,
302,
20666,
272,
1851,
15,
692,
272,
1851,
697,
272,
1851,
10811,
15,
262,
272,
1851,
10811,
15,
8815,
272,
12992,
63,
1313,
272,
11271,
272,
299,
2671,
272,
14374,
272,
5163,
272,
10286,
272,
2754,
272,
542,
17185,
272,
663,
74,
311,
272,
4673,
272,
15187,
272,
2418,
1273,
272,
2418,
2245,
272,
2418,
318,
272,
2418,
442,
272,
410,
3006,
272,
26678,
272,
1059,
272,
3326,
272,
410,
293,
8382,
272,
984,
15,
32352,
272,
984,
15,
596,
290,
272,
984,
15,
1328,
272,
984,
15,
1927,
272,
984,
15,
2416,
272,
984,
15,
21678,
272,
984,
15,
609,
77,
272,
984,
15,
3450,
272,
984,
15,
3736,
272,
984,
15,
3736,
20970,
272,
984,
15,
521,
272,
984,
15,
4508,
272,
984,
15,
1313,
272,
984,
15,
1907,
79,
272,
984,
15,
324,
272,
984,
15,
14608,
354,
272,
984,
15,
2573,
272,
22112,
272,
5330,
272,
28725,
272,
22387,
3442,
272,
900,
272,
3307,
272,
399,
3097,
272,
625,
631,
68,
272,
399,
521,
272,
11430,
311,
88,
272,
336,
1560,
272,
336,
3667,
272,
1319,
31450,
339,
741,
320,
696,
272,
333,
9373,
199,
891,
1370,
1294,
342,
421,
199,
63,
2613,
63,
3401,
275,
6555,
63,
264,
8,
82,
4289,
334,
15,
2647,
32418,
7896,
13,
13186,
16,
13,
25,
32,
33,
13,
58,
63,
65,
13,
90,
11896,
4268,
603,
9,
199,
199,
63,
2307,
63,
2592,
275,
1551,
8,
19778,
12,
593,
63,
15543,
6524,
9,
421,
199,
318,
2446,
8,
2614,
63,
1095,
534,
13186,
22818,
63,
2139,
297,
627,
589,
12,
268,
1738,
29,
3475,
8,
4832,
3460,
493,
8964,
304,
272,
7429,
17,
6666,
275,
1104,
63,
1199,
8,
267,
661,
13112,
297,
2475,
1361,
13,
6595,
13,
354,
29,
2055,
17,
6666,
659,
267,
9009,
3699,
2307,
63,
2592,
12,
267,
4635,
3699,
2307,
63,
2592,
12,
272,
7092,
2708,
360,
6610,
13,
24,
297,
283,
4247,
1959,
1294,
2258,
78,
297,
17,
2788,
16,
61,
339,
2387,
3771,
275,
485,
2613,
63,
3401,
14,
6452,
8,
1074,
63,
1199,
8,
267,
334,
2055,
17,
6666,
12,
2475,
86,
659,
267,
9009,
3699,
2307,
63,
2592,
12,
267,
4635,
29,
13850,
12,
272,
7092,
2708,
360,
6610,
13,
24,
297,
283,
4247,
1959,
1294,
2258,
78,
60,
78,
297,
17,
2788,
16,
566,
339,
367,
1406,
315,
485,
21178,
26,
267,
2928,
63,
3771,
275,
359,
288,
19529,
3508,
83,
3149,
83,
14,
72,
7,
450,
334,
2613,
515,
12,
1406,
430,
288,
367,
2387,
515,
315,
2387,
3771,
267,
1622,
267,
367,
2928,
63,
515,
315,
2928,
63,
3771,
26,
288,
340,
3495,
8,
2164,
63,
515,
9,
436,
29214,
8,
2164,
63,
515,
304,
355,
2059,
267,
587,
26,
288,
870,
2258,
78,
2567,
1630,
440,
3495,
26,
283,
435,
1406,
435,
1987,
8730,
379,
315,
6536,
2116,
627,
2164,
63,
3771,
12,
570,
29,
3083,
12,
7375,
17115,
78,
358,
288,
1980,
398,
2053,
63,
515,
275,
19529,
3508,
83,
3149,
83,
14,
80,
2207,
7,
450,
334,
2614,
63,
1095,
12,
1406,
430,
267,
340,
3495,
8,
2614,
63,
515,
304,
288,
870,
2258,
78,
16760,
6702,
6536,
2053,
63,
515,
12,
570,
29,
3083,
9,
288,
1980,
398,
2053,
63,
694,
275,
9017,
8,
2614,
63,
515,
9,
267,
340,
440,
3495,
8,
2614,
63,
694,
304,
288,
1852,
3220,
8,
2614,
63,
694,
9,
288,
1104,
63,
1250,
4725,
12376,
297,
2053,
63,
694,
435,
1994,
363,
826,
4343,
80,
2207,
1333,
267,
916,
440,
26004,
8,
2614,
63,
694,
304,
288,
1980,
398,
870,
2258,
78,
7619,
1337,
6536,
2928,
63,
515,
12,
570,
29,
3083,
9,
267,
1104,
63,
1250,
8,
288,
334,
1231,
435,
1994,
3667,
1226,
287,
63,
475,
63,
80,
2207,
14,
647,
297,
1467,
627,
589,
12,
2475,
84,
29,
72,
297,
2475,
70,
628,
21110,
83,
14,
72,
4335,
7,
450,
1406,
12,
1467,
2928,
63,
515,
12,
2053,
63,
515,
395,
267,
776,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
2031,
3020,
59,
17,
5728,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
smcv/android_kernel_samsung_tuna
|
tools/perf/scripts/python/sctop.py
|
11180
|
1924
|
# system call top
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Periodically displays system-wide system call totals, broken down by
# syscall. If a [comm] arg is specified, only syscalls called by
# [comm] are displayed. If an [interval] arg is specified, the display
# will be refreshed every [interval] seconds. The default interval is
# 3 seconds.
import os, sys, thread, time
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
usage = "perf script -s sctop.py [comm] [interval]\n";
for_comm = None
default_interval = 3
interval = default_interval
if len(sys.argv) > 3:
sys.exit(usage)
if len(sys.argv) > 2:
for_comm = sys.argv[1]
interval = int(sys.argv[2])
elif len(sys.argv) > 1:
try:
interval = int(sys.argv[1])
except ValueError:
for_comm = sys.argv[1]
interval = default_interval
syscalls = autodict()
def trace_begin():
thread.start_new_thread(print_syscall_totals, (interval,))
pass
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals(interval):
while 1:
clear_term()
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
try:
print "%-40s %10d\n" % (syscall_name(id), val),
except TypeError:
pass
syscalls.clear()
time.sleep(interval)
|
gpl-2.0
|
[
3,
2656,
1240,
2746,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
3492,
11273,
1183,
17561,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
199,
3,
18901,
14,
221,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
199,
3,
359,
1404,
61,
787,
9080,
14,
982,
376,
359,
4284,
61,
1680,
365,
2013,
12,
314,
2929,
199,
3,
911,
506,
9236,
379,
4036,
359,
4284,
61,
4696,
14,
221,
710,
849,
6252,
365,
199,
3,
650,
4696,
14,
199,
199,
646,
747,
12,
984,
12,
2462,
12,
900,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
308,
319,
411,
14,
647,
359,
1404,
61,
359,
4284,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
885,
63,
4284,
275,
650,
199,
4284,
275,
849,
63,
4284,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
199,
4164,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
1722,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
507,
198,
4284,
275,
849,
63,
4284,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
2671,
14,
928,
63,
1222,
63,
2671,
8,
1361,
63,
19444,
63,
17552,
12,
334,
4284,
4641,
199,
198,
1529,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
8,
4284,
304,
199,
198,
6710,
413,
26,
507,
198,
3584,
63,
5125,
342,
507,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
686,
198,
1361,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
507,
198,
2836,
26,
686,
198,
1361,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
2742,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
507,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
5264,
298,
9460,
1288,
2742,
198,
509,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
4671,
420,
3837,
275,
715,
304,
686,
198,
893,
26,
1585,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
686,
198,
2590,
3146,
26,
1585,
198,
1529,
507,
198,
14507,
14,
3584,
342,
507,
198,
521,
14,
4532,
8,
4284,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
2746,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
3492,
11273,
1183,
17561,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
199,
3,
18901,
14,
221,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
199,
3,
359,
1404,
61,
787,
9080,
14,
982,
376,
359,
4284,
61,
1680,
365,
2013,
12,
314,
2929,
199,
3,
911,
506,
9236,
379,
4036,
359,
4284,
61,
4696,
14,
221,
710,
849,
6252,
365,
199,
3,
650,
4696,
14,
199,
199,
646,
747,
12,
984,
12,
2462,
12,
900,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
308,
319,
411,
14,
647,
359,
1404,
61,
359,
4284,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
885,
63,
4284,
275,
650,
199,
4284,
275,
849,
63,
4284,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
199,
4164,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
1722,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
507,
198,
4284,
275,
849,
63,
4284,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
2671,
14,
928,
63,
1222,
63,
2671,
8,
1361,
63,
19444,
63,
17552,
12,
334,
4284,
4641,
199,
198,
1529,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
8,
4284,
304,
199,
198,
6710,
413,
26,
507,
198,
3584,
63,
5125,
342,
507,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
686,
198,
1361,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
507,
198,
2836,
26,
686,
198,
1361,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
2742,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
507,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
5264,
298,
9460,
1288,
2742,
198,
509,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
4671,
420,
3837,
275,
715,
304,
686,
198,
893,
26,
1585,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
686,
198,
2590,
3146,
26,
1585,
198,
1529,
507,
198,
14507,
14,
3584,
342,
507,
198,
521,
14,
4532,
8,
4284,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dylanlesko/youtube-dl
|
youtube_dl/extractor/hotnewhiphop.py
|
129
|
2306
|
from __future__ import unicode_literals
import base64
from .common import InfoExtractor
from ..compat import (
compat_urllib_parse,
compat_urllib_request,
)
from ..utils import (
ExtractorError,
HEADRequest,
)
class HotNewHipHopIE(InfoExtractor):
_VALID_URL = r'http://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html'
_TEST = {
'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html',
'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
'info_dict': {
'id': '1435540',
'ext': 'mp3',
'title': 'Freddie Gibbs - Lay It Down'
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
video_url_base64 = self._search_regex(
r'data-path="(.*?)"', webpage, 'video URL', default=None)
if video_url_base64 is None:
video_url = self._search_regex(
r'"contentUrl" content="(.*?)"', webpage, 'content URL')
return self.url_result(video_url, ie='Youtube')
reqdata = compat_urllib_parse.urlencode([
('mediaType', 's'),
('mediaId', video_id),
])
r = compat_urllib_request.Request(
'http://www.hotnewhiphop.com/ajax/media/getActions/', data=reqdata)
r.add_header('Content-Type', 'application/x-www-form-urlencoded')
mkd = self._download_json(
r, video_id, note='Requesting media key',
errnote='Could not download media key')
if 'mediaKey' not in mkd:
raise ExtractorError('Did not get a media key')
redirect_url = base64.b64decode(video_url_base64).decode('utf-8')
redirect_req = HEADRequest(redirect_url)
req = self._request_webpage(
redirect_req, video_id,
note='Resolving final URL', errnote='Could not resolve final URL')
video_url = req.geturl()
if video_url.endswith('.html'):
raise ExtractorError('Redirect failed')
video_title = self._og_search_title(webpage).strip()
return {
'id': video_id,
'url': video_url,
'title': video_title,
'thumbnail': self._og_search_thumbnail(webpage),
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
8434,
63,
4078,
63,
1069,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
13053,
2017,
12,
199,
9,
421,
199,
533,
869,
357,
4665,
40,
711,
13378,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
1014,
921,
1544,
4537,
8885,
1222,
28951,
13376,
4537,
957,
15,
24736,
2229,
48,
28,
344,
23742,
31477,
1360,
7,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8885,
1222,
28951,
13376,
14,
957,
15,
22980,
15130,
13,
71,
1892,
1533,
13,
817,
13,
390,
13,
2110,
13,
19351,
14,
1079,
10156,
2167,
14,
1360,
297,
267,
283,
1064,
21,
356,
283,
18,
67,
18,
2866,
18,
70,
2114,
2829,
845,
65,
25,
66,
19,
66,
18844,
69,
24,
66,
8001,
70,
19,
68,
2534,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1079,
10156,
2167,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
283,
38,
581,
15130,
598,
1892,
1533,
446,
9366,
2779,
13392,
7,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
3991,
63,
633,
63,
1095,
772,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
515,
628,
17140,
32691,
9248,
12,
283,
3722,
2851,
297,
849,
29,
403,
9,
398,
340,
3991,
63,
633,
63,
1095,
772,
365,
488,
26,
288,
3991,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
355,
519,
4065,
1317,
6417,
2,
1564,
628,
17140,
32691,
9248,
12,
283,
1317,
2851,
358,
288,
372,
291,
14,
633,
63,
1099,
8,
3722,
63,
633,
12,
13446,
534,
57,
7715,
358,
398,
2648,
576,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
779,
288,
661,
4603,
804,
297,
283,
83,
659,
288,
661,
4603,
1304,
297,
3991,
63,
344,
395,
267,
4794,
267,
519,
275,
8434,
63,
4078,
63,
1069,
14,
2017,
8,
288,
283,
1014,
921,
1544,
14,
8885,
1222,
28951,
13376,
14,
957,
15,
12774,
15,
4603,
15,
362,
9303,
3678,
666,
29,
2103,
576,
9,
267,
519,
14,
525,
63,
1291,
360,
2714,
13,
804,
297,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
358,
267,
9199,
68,
275,
291,
423,
4249,
63,
1001,
8,
288,
519,
12,
3991,
63,
344,
12,
5317,
534,
2017,
316,
5898,
790,
297,
288,
2329,
4610,
534,
6531,
440,
5235,
5898,
790,
358,
267,
340,
283,
4603,
1197,
7,
440,
315,
9199,
68,
26,
288,
746,
19783,
360,
17366,
440,
664,
282,
5898,
790,
358,
398,
4660,
63,
633,
275,
1300,
772,
14,
66,
772,
2708,
8,
3722,
63,
633,
63,
1095,
772,
680,
2708,
360,
1624,
13,
24,
358,
267,
4660,
63,
2103,
275,
13053,
2017,
8,
4876,
63,
633,
9,
267,
2648,
275,
291,
423,
1069,
63,
12022,
8,
288,
4660,
63,
2103,
12,
3991,
63,
344,
12,
288,
5317,
534,
1322,
393,
4007,
4242,
2851,
297,
2329,
4610,
534,
6531,
440,
7512,
4242,
2851,
358,
267,
3991,
63,
633,
275,
2648,
14,
32130,
342,
267,
340,
3991,
63,
633,
14,
4130,
5175,
1360,
735,
288,
746,
19783,
360,
7071,
3405,
358,
398,
3991,
63,
1213,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
680,
1913,
342,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
1213,
356,
3991,
63,
1213,
12,
288,
283,
8311,
356,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
8434,
63,
4078,
63,
1069,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
13053,
2017,
12,
199,
9,
421,
199,
533,
869,
357,
4665,
40,
711,
13378,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
1014,
921,
1544,
4537,
8885,
1222,
28951,
13376,
4537,
957,
15,
24736,
2229,
48,
28,
344,
23742,
31477,
1360,
7,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8885,
1222,
28951,
13376,
14,
957,
15,
22980,
15130,
13,
71,
1892,
1533,
13,
817,
13,
390,
13,
2110,
13,
19351,
14,
1079,
10156,
2167,
14,
1360,
297,
267,
283,
1064,
21,
356,
283,
18,
67,
18,
2866,
18,
70,
2114,
2829,
845,
65,
25,
66,
19,
66,
18844,
69,
24,
66,
8001,
70,
19,
68,
2534,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1079,
10156,
2167,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
283,
38,
581,
15130,
598,
1892,
1533,
446,
9366,
2779,
13392,
7,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
3991,
63,
633,
63,
1095,
772,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
515,
628,
17140,
32691,
9248,
12,
283,
3722,
2851,
297,
849,
29,
403,
9,
398,
340,
3991,
63,
633,
63,
1095,
772,
365,
488,
26,
288,
3991,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
355,
519,
4065,
1317,
6417,
2,
1564,
628,
17140,
32691,
9248,
12,
283,
1317,
2851,
358,
288,
372,
291,
14,
633,
63,
1099,
8,
3722,
63,
633,
12,
13446,
534,
57,
7715,
358,
398,
2648,
576,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
779,
288,
661,
4603,
804,
297,
283,
83,
659,
288,
661,
4603,
1304,
297,
3991,
63,
344,
395,
267,
4794,
267,
519,
275,
8434,
63,
4078,
63,
1069,
14,
2017,
8,
288,
283,
1014,
921,
1544,
14,
8885,
1222,
28951,
13376,
14,
957,
15,
12774,
15,
4603,
15,
362,
9303,
3678,
666,
29,
2103,
576,
9,
267,
519,
14,
525,
63,
1291,
360,
2714,
13,
804,
297,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
358,
267,
9199,
68,
275,
291,
423,
4249,
63,
1001,
8,
288,
519,
12,
3991,
63,
344,
12,
5317,
534,
2017,
316,
5898,
790,
297,
288,
2329,
4610,
534,
6531,
440,
5235,
5898,
790,
358,
267,
340,
283,
4603,
1197,
7,
440,
315,
9199,
68,
26,
288,
746,
19783,
360,
17366,
440,
664,
282,
5898,
790,
358,
398,
4660,
63,
633,
275,
1300,
772,
14,
66,
772,
2708,
8,
3722,
63,
633,
63,
1095,
772,
680,
2708,
360,
1624,
13,
24,
358,
267,
4660,
63,
2103,
275,
13053,
2017,
8,
4876,
63,
633,
9,
267,
2648,
275,
291,
423,
1069,
63,
12022,
8,
288,
4660,
63,
2103,
12,
3991,
63,
344,
12,
288,
5317,
534,
1322,
393,
4007,
4242,
2851,
297,
2329,
4610,
534,
6531,
440,
7512,
4242,
2851,
358,
267,
3991,
63,
633,
275,
2648,
14,
32130,
342,
267,
340,
3991,
63,
633,
14,
4130,
5175,
1360,
735,
288,
746,
19783,
360,
7071,
3405,
358,
398,
3991,
63,
1213,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
680,
1913,
342,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
1213,
356,
3991,
63,
1213,
12,
288,
283,
8311,
356,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
alkyl1978/gnuradio
|
gr-analog/python/analog/wfm_rcv.py
|
58
|
2782
|
#
# Copyright 2005,2007,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, filter
from fm_emph import fm_deemph
import math
try:
from gnuradio import analog
except ImportError:
import analog_swig as analog
class wfm_rcv(gr.hier_block2):
def __init__ (self, quad_rate, audio_decimation):
"""
Hierarchical block for demodulating a broadcast FM signal.
The input is the downconverted complex baseband signal (gr_complex).
The output is the demodulated audio (float).
Args:
quad_rate: input sample rate of complex baseband input. (float)
audio_decimation: how much to decimate quad_rate to get to audio. (integer)
"""
gr.hier_block2.__init__(self, "wfm_rcv",
gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
volume = 20.
max_dev = 75e3
fm_demod_gain = quad_rate/(2*math.pi*max_dev)
audio_rate = quad_rate / audio_decimation
# We assign to self so that outsiders can grab the demodulator
# if they need to. E.g., to plot its output.
#
# input: complex; output: float
self.fm_demod = analog.quadrature_demod_cf(fm_demod_gain)
# input: float; output: float
self.deemph = fm_deemph(audio_rate)
# compute FIR filter taps for audio filter
width_of_transition_band = audio_rate / 32
audio_coeffs = filter.firdes.low_pass(1.0, # gain
quad_rate, # sampling rate
audio_rate/2 - width_of_transition_band,
width_of_transition_band,
filter.firdes.WIN_HAMMING)
# input: float; output: float
self.audio_filter = filter.fir_filter_fff(audio_decimation, audio_coeffs)
self.connect (self, self.fm_demod, self.audio_filter, self.deemph, self)
|
gpl-3.0
|
[
3,
199,
3,
1898,
11811,
12,
9488,
12,
7409,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
2457,
199,
504,
20831,
63,
2109,
72,
492,
20831,
63,
271,
2109,
72,
199,
646,
3473,
199,
199,
893,
26,
272,
687,
24526,
492,
20439,
199,
2590,
3545,
26,
272,
492,
20439,
63,
9676,
465,
20439,
199,
199,
533,
336,
10886,
63,
1195,
86,
8,
2587,
14,
31184,
63,
1457,
18,
304,
272,
347,
636,
826,
363,
334,
277,
12,
16744,
63,
1866,
12,
10491,
63,
22612,
1615,
304,
267,
408,
267,
869,
16437,
1853,
367,
477,
1494,
20529,
282,
11180,
481,
45,
4673,
14,
398,
710,
1324,
365,
314,
3224,
22818,
6114,
1300,
7877,
4673,
334,
2587,
63,
5254,
680,
267,
710,
1072,
365,
314,
477,
1494,
8097,
10491,
334,
1609,
680,
398,
3033,
26,
288,
16744,
63,
1866,
26,
1324,
2690,
6634,
402,
6114,
1300,
7877,
1324,
14,
334,
1609,
9,
288,
10491,
63,
22612,
1615,
26,
4212,
8298,
370,
12985,
17684,
16744,
63,
1866,
370,
664,
370,
10491,
14,
334,
4115,
9,
267,
408,
199,
198,
2587,
14,
31184,
63,
1457,
18,
855,
826,
721,
277,
12,
298,
87,
10886,
63,
1195,
86,
401,
1585,
198,
2587,
14,
2308,
63,
5233,
8,
17,
12,
413,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
395,
327,
6924,
4955,
1585,
198,
2587,
14,
2308,
63,
5233,
8,
17,
12,
413,
12,
7192,
14,
12590,
63,
1609,
430,
420,
327,
7242,
4955,
398,
3301,
275,
3388,
14,
398,
1390,
63,
2374,
275,
13098,
69,
19,
267,
20831,
63,
271,
1494,
63,
13020,
275,
16744,
63,
1866,
7985,
18,
10,
3442,
14,
1038,
10,
988,
63,
2374,
9,
267,
10491,
63,
1866,
275,
16744,
63,
1866,
1182,
10491,
63,
22612,
1615,
7318,
327,
2136,
5090,
370,
291,
880,
626,
734,
338,
7735,
883,
18200,
314,
477,
1494,
6109,
267,
327,
340,
2985,
1929,
370,
14,
221,
662,
14,
71,
2020,
370,
5137,
2399,
1072,
14,
267,
327,
267,
327,
1324,
26,
6114,
27,
1072,
26,
2069,
267,
291,
14,
10886,
63,
271,
1494,
275,
20439,
14,
14567,
30985,
63,
271,
1494,
63,
2177,
8,
10886,
63,
271,
1494,
63,
13020,
9,
398,
327,
1324,
26,
2069,
27,
1072,
26,
2069,
267,
291,
14,
271,
2109,
72,
275,
20831,
63,
271,
2109,
72,
8,
8130,
63,
1866,
9,
398,
327,
4526,
28137,
2457,
307,
7461,
367,
10491,
2457,
267,
3462,
63,
1618,
63,
14143,
63,
7877,
275,
10491,
63,
1866,
1182,
4337,
267,
10491,
63,
15958,
275,
2457,
14,
1795,
3424,
14,
674,
63,
1529,
8,
17,
14,
16,
12,
3322,
327,
15334,
6343,
16744,
63,
1866,
12,
420,
327,
15877,
6634,
6343,
10491,
63,
1866,
15,
18,
446,
3462,
63,
1618,
63,
14143,
63,
7877,
12,
6343,
3462,
63,
1618,
63,
14143,
63,
7877,
12,
6343,
2457,
14,
1795,
3424,
14,
7941,
63,
40,
1156,
45,
1206,
9,
267,
327,
1324,
26,
2069,
27,
1072,
26,
2069,
267,
291,
14,
8130,
63,
1541,
275,
2457,
14,
1795,
63,
1541,
63,
18190,
8,
8130,
63,
22612,
1615,
12,
10491,
63,
15958,
9,
398,
291,
14,
2242,
334,
277,
12,
291,
14,
10886,
63,
271,
1494,
12,
291,
14,
8130,
63,
1541,
12,
291,
14,
271,
2109,
72,
12,
291,
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
] |
[
199,
3,
1898,
11811,
12,
9488,
12,
7409,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
2457,
199,
504,
20831,
63,
2109,
72,
492,
20831,
63,
271,
2109,
72,
199,
646,
3473,
199,
199,
893,
26,
272,
687,
24526,
492,
20439,
199,
2590,
3545,
26,
272,
492,
20439,
63,
9676,
465,
20439,
199,
199,
533,
336,
10886,
63,
1195,
86,
8,
2587,
14,
31184,
63,
1457,
18,
304,
272,
347,
636,
826,
363,
334,
277,
12,
16744,
63,
1866,
12,
10491,
63,
22612,
1615,
304,
267,
408,
267,
869,
16437,
1853,
367,
477,
1494,
20529,
282,
11180,
481,
45,
4673,
14,
398,
710,
1324,
365,
314,
3224,
22818,
6114,
1300,
7877,
4673,
334,
2587,
63,
5254,
680,
267,
710,
1072,
365,
314,
477,
1494,
8097,
10491,
334,
1609,
680,
398,
3033,
26,
288,
16744,
63,
1866,
26,
1324,
2690,
6634,
402,
6114,
1300,
7877,
1324,
14,
334,
1609,
9,
288,
10491,
63,
22612,
1615,
26,
4212,
8298,
370,
12985,
17684,
16744,
63,
1866,
370,
664,
370,
10491,
14,
334,
4115,
9,
267,
408,
199,
198,
2587,
14,
31184,
63,
1457,
18,
855,
826,
721,
277,
12,
298,
87,
10886,
63,
1195,
86,
401,
1585,
198,
2587,
14,
2308,
63,
5233,
8,
17,
12,
413,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
395,
327,
6924,
4955,
1585,
198,
2587,
14,
2308,
63,
5233,
8,
17,
12,
413,
12,
7192,
14,
12590,
63,
1609,
430,
420,
327,
7242,
4955,
398,
3301,
275,
3388,
14,
398,
1390,
63,
2374,
275,
13098,
69,
19,
267,
20831,
63,
271,
1494,
63,
13020,
275,
16744,
63,
1866,
7985,
18,
10,
3442,
14,
1038,
10,
988,
63,
2374,
9,
267,
10491,
63,
1866,
275,
16744,
63,
1866,
1182,
10491,
63,
22612,
1615,
7318,
327,
2136,
5090,
370,
291,
880,
626,
734,
338,
7735,
883,
18200,
314,
477,
1494,
6109,
267,
327,
340,
2985,
1929,
370,
14,
221,
662,
14,
71,
2020,
370,
5137,
2399,
1072,
14,
267,
327,
267,
327,
1324,
26,
6114,
27,
1072,
26,
2069,
267,
291,
14,
10886,
63,
271,
1494,
275,
20439,
14,
14567,
30985,
63,
271,
1494,
63,
2177,
8,
10886,
63,
271,
1494,
63,
13020,
9,
398,
327,
1324,
26,
2069,
27,
1072,
26,
2069,
267,
291,
14,
271,
2109,
72,
275,
20831,
63,
271,
2109,
72,
8,
8130,
63,
1866,
9,
398,
327,
4526,
28137,
2457,
307,
7461,
367,
10491,
2457,
267,
3462,
63,
1618,
63,
14143,
63,
7877,
275,
10491,
63,
1866,
1182,
4337,
267,
10491,
63,
15958,
275,
2457,
14,
1795,
3424,
14,
674,
63,
1529,
8,
17,
14,
16,
12,
3322,
327,
15334,
6343,
16744,
63,
1866,
12,
420,
327,
15877,
6634,
6343,
10491,
63,
1866,
15,
18,
446,
3462,
63,
1618,
63,
14143,
63,
7877,
12,
6343,
3462,
63,
1618,
63,
14143,
63,
7877,
12,
6343,
2457,
14,
1795,
3424,
14,
7941,
63,
40,
1156,
45,
1206,
9,
267,
327,
1324,
26,
2069,
27,
1072,
26,
2069,
267,
291,
14,
8130,
63,
1541,
275,
2457,
14,
1795,
63,
1541,
63,
18190,
8,
8130,
63,
22612,
1615,
12,
10491,
63,
15958,
9,
398,
291,
14,
2242,
334,
277,
12,
291,
14,
10886,
63,
271,
1494,
12,
291,
14,
8130,
63,
1541,
12,
291,
14,
271,
2109,
72,
12,
291,
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,
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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
] |
chris-allan/openmicroscopy
|
components/tools/OmeroWeb/omeroweb/webgateway/templatetags/common_filters.py
|
3
|
2558
|
# #!/usr/bin/env python
#
#
#
# Copyright (c) 2008 University of Dundee.
#
# 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/>.
#
# Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008.
#
# Version: 1.0
#
import datetime
import traceback
import logging
from django.conf import settings
from django import template
register = template.Library()
logger = logging.getLogger(__name__)
@register.filter
def hash(value, key):
return value[key]
@register.filter
def truncateafter(value, arg):
"""
Truncates a string after a given number of chars
Argument: Number of chars to truncate after
"""
try:
length = int(arg)
except ValueError: # invalid literal for int()
return value # Fail silently.
if not isinstance(value, basestring):
value = str(value)
if (len(value) > length):
return value[:length] + "..."
else:
return value
@register.filter
def truncatebefor(value, arg):
"""
Truncates a string after a given number of chars
Argument: Number of chars to truncate befor
"""
try:
length = int(arg)
except ValueError: # invalid literal for int()
return value # Fail silently.
if not isinstance(value, basestring):
value = str(value)
if (len(value) > length):
return "..."+value[len(value)-length:]
else:
return value
@register.filter
def shortening(value, arg):
try:
length = int(arg)
except ValueError: # invalid literal for int()
return value # Fail silently.
front = length/2-3
end = length/2-3
if not isinstance(value, basestring):
value = str(value)
try:
l = len(value)
if l < length:
return value
elif l >= length:
return value[:front]+"..."+value[l-end:]
except Exception, x:
logger.error(traceback.format_exc())
return value
|
gpl-2.0
|
[
199,
3,
327,
1,
15,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
221,
199,
3,
221,
199,
3,
221,
199,
3,
1898,
334,
67,
9,
9079,
15904,
402,
577,
324,
11192,
14,
221,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
221,
199,
3,
6529,
26,
6832,
6080,
19125,
377,
1096,
583,
1339,
65,
665,
33,
8,
3287,
9,
52,
1096,
583,
1339,
65,
8,
292,
9,
68,
324,
11192,
8,
3287,
9,
645,
8,
3287,
9,
3210,
6244,
9079,
14,
199,
3,
221,
199,
3,
3394,
26,
413,
14,
16,
199,
3,
421,
199,
646,
2197,
199,
646,
5190,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
492,
1978,
199,
199,
2683,
275,
1978,
14,
7424,
342,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
32,
2683,
14,
1541,
199,
318,
2631,
8,
585,
12,
790,
304,
272,
372,
574,
59,
498,
61,
199,
199,
32,
2683,
14,
1541,
199,
318,
14547,
4399,
8,
585,
12,
1680,
304,
272,
408,
272,
25594,
1411,
83,
282,
1059,
2410,
282,
1627,
1329,
402,
8365,
23855,
5886,
26,
4860,
402,
8365,
370,
14547,
2410,
272,
408,
272,
862,
26,
267,
2582,
275,
1109,
8,
1273,
9,
272,
871,
1722,
26,
327,
3866,
8785,
367,
1109,
342,
267,
372,
574,
327,
12176,
18030,
14,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
267,
574,
275,
620,
8,
585,
9,
272,
340,
334,
552,
8,
585,
9,
690,
2582,
304,
267,
372,
574,
1491,
1267,
61,
435,
298,
11500,
272,
587,
26,
267,
372,
574,
199,
199,
32,
2683,
14,
1541,
199,
318,
14547,
1235,
509,
8,
585,
12,
1680,
304,
272,
408,
272,
25594,
1411,
83,
282,
1059,
2410,
282,
1627,
1329,
402,
8365,
23855,
5886,
26,
4860,
402,
8365,
370,
14547,
506,
509,
272,
408,
272,
862,
26,
267,
2582,
275,
1109,
8,
1273,
9,
272,
871,
1722,
26,
327,
3866,
8785,
367,
1109,
342,
267,
372,
574,
327,
12176,
18030,
14,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
267,
574,
275,
620,
8,
585,
9,
272,
340,
334,
552,
8,
585,
9,
690,
2582,
304,
267,
372,
298,
1396,
7709,
585,
59,
552,
8,
585,
7216,
1267,
2938,
272,
587,
26,
267,
372,
574,
199,
199,
32,
2683,
14,
1541,
199,
318,
25123,
316,
8,
585,
12,
1680,
304,
272,
862,
26,
267,
2582,
275,
1109,
8,
1273,
9,
272,
871,
1722,
26,
327,
3866,
8785,
367,
1109,
342,
267,
372,
574,
327,
12176,
18030,
14,
272,
13738,
275,
2582,
15,
18,
13,
19,
272,
1284,
275,
2582,
15,
18,
13,
19,
2286,
340,
440,
1228,
8,
585,
12,
7116,
304,
267,
574,
275,
620,
8,
585,
9,
23855,
862,
26,
4960,
634,
275,
822,
8,
585,
9,
4960,
340,
634,
665,
2582,
26,
7205,
372,
574,
267,
916,
634,
2356,
2582,
26,
7205,
372,
574,
1491,
14708,
2807,
2,
1396,
7709,
585,
59,
76,
13,
500,
2938,
272,
871,
2186,
12,
671,
26,
267,
2512,
14,
705,
8,
6894,
14,
908,
63,
2804,
1012,
267,
372,
574,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3,
327,
1,
15,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
221,
199,
3,
221,
199,
3,
221,
199,
3,
1898,
334,
67,
9,
9079,
15904,
402,
577,
324,
11192,
14,
221,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
221,
199,
3,
6529,
26,
6832,
6080,
19125,
377,
1096,
583,
1339,
65,
665,
33,
8,
3287,
9,
52,
1096,
583,
1339,
65,
8,
292,
9,
68,
324,
11192,
8,
3287,
9,
645,
8,
3287,
9,
3210,
6244,
9079,
14,
199,
3,
221,
199,
3,
3394,
26,
413,
14,
16,
199,
3,
421,
199,
646,
2197,
199,
646,
5190,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
492,
1978,
199,
199,
2683,
275,
1978,
14,
7424,
342,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
32,
2683,
14,
1541,
199,
318,
2631,
8,
585,
12,
790,
304,
272,
372,
574,
59,
498,
61,
199,
199,
32,
2683,
14,
1541,
199,
318,
14547,
4399,
8,
585,
12,
1680,
304,
272,
408,
272,
25594,
1411,
83,
282,
1059,
2410,
282,
1627,
1329,
402,
8365,
23855,
5886,
26,
4860,
402,
8365,
370,
14547,
2410,
272,
408,
272,
862,
26,
267,
2582,
275,
1109,
8,
1273,
9,
272,
871,
1722,
26,
327,
3866,
8785,
367,
1109,
342,
267,
372,
574,
327,
12176,
18030,
14,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
267,
574,
275,
620,
8,
585,
9,
272,
340,
334,
552,
8,
585,
9,
690,
2582,
304,
267,
372,
574,
1491,
1267,
61,
435,
298,
11500,
272,
587,
26,
267,
372,
574,
199,
199,
32,
2683,
14,
1541,
199,
318,
14547,
1235,
509,
8,
585,
12,
1680,
304,
272,
408,
272,
25594,
1411,
83,
282,
1059,
2410,
282,
1627,
1329,
402,
8365,
23855,
5886,
26,
4860,
402,
8365,
370,
14547,
506,
509,
272,
408,
272,
862,
26,
267,
2582,
275,
1109,
8,
1273,
9,
272,
871,
1722,
26,
327,
3866,
8785,
367,
1109,
342,
267,
372,
574,
327,
12176,
18030,
14,
272,
340,
440,
1228,
8,
585,
12,
7116,
304,
267,
574,
275,
620,
8,
585,
9,
272,
340,
334,
552,
8,
585,
9,
690,
2582,
304,
267,
372,
298,
1396,
7709,
585,
59,
552,
8,
585,
7216,
1267,
2938,
272,
587,
26,
267,
372,
574,
199,
199,
32,
2683,
14,
1541,
199,
318,
25123,
316,
8,
585,
12,
1680,
304,
272,
862,
26,
267,
2582,
275,
1109,
8,
1273,
9,
272,
871,
1722,
26,
327,
3866,
8785,
367,
1109,
342,
267,
372,
574,
327,
12176,
18030,
14,
272,
13738,
275,
2582,
15,
18,
13,
19,
272,
1284,
275,
2582,
15,
18,
13,
19,
2286,
340,
440,
1228,
8,
585,
12,
7116,
304,
267,
574,
275,
620,
8,
585,
9,
23855,
862,
26,
4960,
634,
275,
822,
8,
585,
9,
4960,
340,
634,
665,
2582,
26,
7205,
372,
574,
267,
916,
634,
2356,
2582,
26,
7205,
372,
574,
1491,
14708,
2807,
2,
1396,
7709,
585,
59,
76,
13,
500,
2938,
272,
871,
2186,
12,
671,
26,
267,
2512,
14,
705,
8,
6894,
14,
908,
63,
2804,
1012,
267,
372,
574,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ProjectSWGCore/NGECore2
|
scripts/mobiles/endor/hardened_panshee_warrior.py
|
2
|
3153
|
import sys
from services.spawn import MobileTemplate
from services.spawn import WeaponTemplate
from resources.datatables import WeaponType
from resources.datatables import Difficulty
from resources.datatables import Options
from java.util import Vector
def addTemplate(core):
mobileTemplate = MobileTemplate()
mobileTemplate.setCreatureName('hardened_panshee_warrior')
mobileTemplate.setLevel(71)
mobileTemplate.setDifficulty(Difficulty.NORMAL)
mobileTemplate.setMinSpawnDistance(3)
mobileTemplate.setMaxSpawnDistance(5)
mobileTemplate.setDeathblow(False)
mobileTemplate.setScale(1)
mobileTemplate.setSocialGroup('panshee tribe')
mobileTemplate.setAssistRange(1)
mobileTemplate.setOptionsBitmask(128)
mobileTemplate.setStalker(True)
templates = Vector()
templates.add('object/mobile/shared_dressed_ewok_f_01.iff')
templates.add('object/mobile/shared_dressed_ewok_f_02.iff')
templates.add('object/mobile/shared_dressed_ewok_f_03.iff')
templates.add('object/mobile/shared_dressed_ewok_f_04.iff')
templates.add('object/mobile/shared_dressed_ewok_f_05.iff')
templates.add('object/mobile/shared_dressed_ewok_f_06.iff')
templates.add('object/mobile/shared_dressed_ewok_f_07.iff')
templates.add('object/mobile/shared_dressed_ewok_f_08.iff')
templates.add('object/mobile/shared_dressed_ewok_f_09.iff')
templates.add('object/mobile/shared_dressed_ewok_f_10.iff')
templates.add('object/mobile/shared_dressed_ewok_f_11.iff')
templates.add('object/mobile/shared_dressed_ewok_f_12.iff')
templates.add('object/mobile/shared_dressed_ewok_m_01.iff')
templates.add('object/mobile/shared_dressed_ewok_m_02.iff')
templates.add('object/mobile/shared_dressed_ewok_m_03.iff')
templates.add('object/mobile/shared_dressed_ewok_m_04.iff')
templates.add('object/mobile/shared_dressed_ewok_m_05.iff')
templates.add('object/mobile/shared_dressed_ewok_m_06.iff')
templates.add('object/mobile/shared_dressed_ewok_m_07.iff')
templates.add('object/mobile/shared_dressed_ewok_m_08.iff')
templates.add('object/mobile/shared_dressed_ewok_m_09.iff')
templates.add('object/mobile/shared_dressed_ewok_m_10.iff')
templates.add('object/mobile/shared_dressed_ewok_m_11.iff')
templates.add('object/mobile/shared_dressed_ewok_m_12.iff')
mobileTemplate.setTemplates(templates)
weaponTemplates = Vector()
weapontemplate = WeaponTemplate('object/weapon/melee/unarmed/shared_unarmed_default.iff', WeaponType.UNARMED, 1.0, 6, 'kinetic')
weaponTemplates.add(weapontemplate)
mobileTemplate.setWeaponTemplateVector(weaponTemplates)
attacks = Vector()
mobileTemplate.setDefaultAttack('meleeHit')
mobileTemplate.setAttacks(attacks)
lootPoolNames_1 = ['Junk']
lootPoolChances_1 = [100]
lootGroupChance_1 = 65
mobileTemplate.addToLootGroups(lootPoolNames_1,lootPoolChances_1,lootGroupChance_1)
lootPoolNames_2 = ['random_loot_primitives']
lootPoolChances_2 = [100]
lootGroupChance_2 = 35
mobileTemplate.addToLootGroups(lootPoolNames_2,lootPoolChances_2,lootGroupChance_2)
core.spawnService.addMobileTemplate('hardened_panshee_warrior', mobileTemplate)
return
|
lgpl-3.0
|
[
646,
984,
202,
199,
504,
8500,
14,
10212,
492,
29724,
4231,
202,
199,
504,
8500,
14,
10212,
492,
2136,
21921,
4231,
202,
199,
504,
5944,
14,
4616,
292,
5921,
492,
2136,
21921,
804,
202,
199,
504,
5944,
14,
4616,
292,
5921,
492,
577,
692,
24161,
202,
199,
504,
5944,
14,
4616,
292,
5921,
492,
8394,
202,
199,
504,
12120,
14,
1974,
492,
11388,
8065,
199,
318,
1050,
4231,
8,
1018,
304,
1223,
198,
27339,
275,
29724,
4231,
342,
28111,
198,
27339,
14,
409,
5482,
1463,
985,
360,
8210,
848,
379,
63,
80,
796,
26824,
63,
3281,
17942,
358,
1223,
198,
27339,
14,
13548,
8,
3172,
9,
1223,
198,
27339,
14,
409,
36,
692,
24161,
8,
36,
692,
24161,
14,
10765,
9,
10060,
198,
27339,
14,
409,
4649,
12739,
3501,
10076,
8,
19,
9,
1223,
198,
27339,
14,
409,
4261,
12739,
3501,
10076,
8,
21,
9,
1223,
198,
27339,
14,
409,
31577,
66,
674,
8,
797,
9,
1223,
198,
27339,
14,
409,
9944,
8,
17,
9,
1223,
198,
27339,
14,
409,
31356,
2448,
360,
80,
796,
26824,
3229,
1235,
358,
1223,
198,
27339,
14,
409,
2822,
11734,
4709,
8,
17,
9,
1223,
198,
27339,
14,
409,
4558,
4734,
2629,
8,
3933,
9,
1223,
198,
27339,
14,
409,
933,
14976,
8,
549,
9,
4122,
28111,
198,
5876,
275,
11388,
342,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
614,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
996,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1644,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
966,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1717,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1690,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1780,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
2036,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1643,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
709,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
845,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
713,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
614,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
996,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1644,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
966,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1717,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1690,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1780,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
2036,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1643,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
709,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
845,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
713,
14,
15126,
358,
28111,
198,
27339,
14,
409,
17969,
8,
5876,
9,
28111,
198,
30804,
17969,
275,
11388,
342,
1223,
198,
30804,
1160,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
278,
18387,
15,
324,
285,
3594,
15,
5555,
63,
324,
285,
3594,
63,
885,
14,
15126,
297,
2136,
21921,
804,
14,
1734,
12482,
1149,
12,
413,
14,
16,
12,
1227,
12,
283,
75,
1132,
764,
358,
1223,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
9,
1223,
198,
27339,
14,
409,
6004,
21921,
4231,
3646,
8,
30804,
17969,
9,
28111,
198,
292,
21807,
275,
11388,
342,
1223,
198,
27339,
14,
409,
2698,
1271,
13058,
360,
278,
18387,
26852,
358,
1223,
198,
27339,
14,
409,
1271,
21807,
8,
292,
21807,
9,
28111,
198,
320,
357,
5453,
5866,
63,
17,
275,
788,
42,
1778,
418,
1223,
198,
320,
357,
5453,
1049,
13236,
63,
17,
275,
359,
1960,
61,
1223,
198,
320,
357,
2448,
1049,
554,
63,
17,
275,
11738,
1223,
198,
27339,
14,
525,
1378,
2041,
357,
10177,
8,
320,
357,
5453,
5866,
63,
17,
12,
320,
357,
5453,
1049,
13236,
63,
17,
12,
320,
357,
2448,
1049,
554,
63,
17,
9,
28111,
198,
320,
357,
5453,
5866,
63,
18,
275,
788,
2355,
63,
320,
357,
63,
1359,
22337,
418,
1223,
198,
320,
357,
5453,
1049,
13236,
63,
18,
275,
359,
1960,
61,
1223,
198,
320,
357,
2448,
1049,
554,
63,
18,
275
] |
[
984,
202,
199,
504,
8500,
14,
10212,
492,
29724,
4231,
202,
199,
504,
8500,
14,
10212,
492,
2136,
21921,
4231,
202,
199,
504,
5944,
14,
4616,
292,
5921,
492,
2136,
21921,
804,
202,
199,
504,
5944,
14,
4616,
292,
5921,
492,
577,
692,
24161,
202,
199,
504,
5944,
14,
4616,
292,
5921,
492,
8394,
202,
199,
504,
12120,
14,
1974,
492,
11388,
8065,
199,
318,
1050,
4231,
8,
1018,
304,
1223,
198,
27339,
275,
29724,
4231,
342,
28111,
198,
27339,
14,
409,
5482,
1463,
985,
360,
8210,
848,
379,
63,
80,
796,
26824,
63,
3281,
17942,
358,
1223,
198,
27339,
14,
13548,
8,
3172,
9,
1223,
198,
27339,
14,
409,
36,
692,
24161,
8,
36,
692,
24161,
14,
10765,
9,
10060,
198,
27339,
14,
409,
4649,
12739,
3501,
10076,
8,
19,
9,
1223,
198,
27339,
14,
409,
4261,
12739,
3501,
10076,
8,
21,
9,
1223,
198,
27339,
14,
409,
31577,
66,
674,
8,
797,
9,
1223,
198,
27339,
14,
409,
9944,
8,
17,
9,
1223,
198,
27339,
14,
409,
31356,
2448,
360,
80,
796,
26824,
3229,
1235,
358,
1223,
198,
27339,
14,
409,
2822,
11734,
4709,
8,
17,
9,
1223,
198,
27339,
14,
409,
4558,
4734,
2629,
8,
3933,
9,
1223,
198,
27339,
14,
409,
933,
14976,
8,
549,
9,
4122,
28111,
198,
5876,
275,
11388,
342,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
614,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
996,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1644,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
966,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1717,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1690,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1780,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
2036,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
1643,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
709,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
845,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
70,
63,
713,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
614,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
996,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1644,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
966,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1717,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1690,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1780,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
2036,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
1643,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
709,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
845,
14,
15126,
358,
1223,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
546,
745,
63,
77,
63,
713,
14,
15126,
358,
28111,
198,
27339,
14,
409,
17969,
8,
5876,
9,
28111,
198,
30804,
17969,
275,
11388,
342,
1223,
198,
30804,
1160,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
278,
18387,
15,
324,
285,
3594,
15,
5555,
63,
324,
285,
3594,
63,
885,
14,
15126,
297,
2136,
21921,
804,
14,
1734,
12482,
1149,
12,
413,
14,
16,
12,
1227,
12,
283,
75,
1132,
764,
358,
1223,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
9,
1223,
198,
27339,
14,
409,
6004,
21921,
4231,
3646,
8,
30804,
17969,
9,
28111,
198,
292,
21807,
275,
11388,
342,
1223,
198,
27339,
14,
409,
2698,
1271,
13058,
360,
278,
18387,
26852,
358,
1223,
198,
27339,
14,
409,
1271,
21807,
8,
292,
21807,
9,
28111,
198,
320,
357,
5453,
5866,
63,
17,
275,
788,
42,
1778,
418,
1223,
198,
320,
357,
5453,
1049,
13236,
63,
17,
275,
359,
1960,
61,
1223,
198,
320,
357,
2448,
1049,
554,
63,
17,
275,
11738,
1223,
198,
27339,
14,
525,
1378,
2041,
357,
10177,
8,
320,
357,
5453,
5866,
63,
17,
12,
320,
357,
5453,
1049,
13236,
63,
17,
12,
320,
357,
2448,
1049,
554,
63,
17,
9,
28111,
198,
320,
357,
5453,
5866,
63,
18,
275,
788,
2355,
63,
320,
357,
63,
1359,
22337,
418,
1223,
198,
320,
357,
5453,
1049,
13236,
63,
18,
275,
359,
1960,
61,
1223,
198,
320,
357,
2448,
1049,
554,
63,
18,
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,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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
] |
KaranToor/MA450
|
google-cloud-sdk/platform/gsutil/third_party/boto/boto/cloudformation/connection.py
|
127
|
42922
|
# Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import boto
from boto.cloudformation.stack import Stack, StackSummary, StackEvent
from boto.cloudformation.stack import StackResource, StackResourceSummary
from boto.cloudformation.template import Template
from boto.connection import AWSQueryConnection
from boto.regioninfo import RegionInfo
from boto.compat import json
class CloudFormationConnection(AWSQueryConnection):
"""
AWS CloudFormation
AWS CloudFormation enables you to create and manage AWS
infrastructure deployments predictably and repeatedly. AWS
CloudFormation helps you leverage AWS products such as Amazon EC2,
EBS, Amazon SNS, ELB, and Auto Scaling to build highly-reliable,
highly scalable, cost effective applications without worrying
about creating and configuring the underlying AWS infrastructure.
With AWS CloudFormation, you declare all of your resources and
dependencies in a template file. The template defines a collection
of resources as a single unit called a stack. AWS CloudFormation
creates and deletes all member resources of the stack together and
manages all dependencies between the resources for you.
For more information about this product, go to the `CloudFormation
Product Page`_.
Amazon CloudFormation makes use of other AWS products. If you need
additional technical information about a specific AWS product, you
can find the product's technical documentation at
`http://aws.amazon.com/documentation/`_.
"""
APIVersion = boto.config.get('Boto', 'cfn_version', '2010-05-15')
DefaultRegionName = boto.config.get('Boto', 'cfn_region_name', 'us-east-1')
DefaultRegionEndpoint = boto.config.get('Boto', 'cfn_region_endpoint',
'cloudformation.us-east-1.amazonaws.com')
valid_states = (
'CREATE_IN_PROGRESS', 'CREATE_FAILED', 'CREATE_COMPLETE',
'ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'ROLLBACK_COMPLETE',
'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'DELETE_COMPLETE',
'UPDATE_IN_PROGRESS', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS',
'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_IN_PROGRESS',
'UPDATE_ROLLBACK_FAILED',
'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS',
'UPDATE_ROLLBACK_COMPLETE')
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, region=None, path='/',
converter=None, security_token=None, validate_certs=True,
profile_name=None):
if not region:
region = RegionInfo(self, self.DefaultRegionName,
self.DefaultRegionEndpoint, CloudFormationConnection)
self.region = region
super(CloudFormationConnection, self).__init__(aws_access_key_id,
aws_secret_access_key,
is_secure, port, proxy, proxy_port,
proxy_user, proxy_pass,
self.region.endpoint, debug,
https_connection_factory, path,
security_token,
validate_certs=validate_certs,
profile_name=profile_name)
def _required_auth_capability(self):
return ['hmac-v4']
def encode_bool(self, v):
v = bool(v)
return {True: "true", False: "false"}[v]
def _build_create_or_update_params(self, stack_name, template_body,
template_url, parameters, disable_rollback, timeout_in_minutes,
notification_arns, capabilities, on_failure, stack_policy_body,
stack_policy_url, tags, use_previous_template=None,
stack_policy_during_update_body=None,
stack_policy_during_update_url=None):
"""
Helper that creates JSON parameters needed by a Stack Create or
Stack Update call.
:type stack_name: string
:param stack_name:
The name associated with the stack. The name must be unique within your
AWS account.
Must contain only alphanumeric characters (case sensitive) and start
with an alpha character. Maximum length of the name is 255
characters.
:type template_body: string
:param template_body: Structure containing the template body. (For more
information, go to `Template Anatomy`_ in the AWS CloudFormation
User Guide.)
Conditional: You must pass either `UsePreviousTemplate` or one of
`TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
`TemplateUrl` are passed, only `TemplateBody` is used.
`TemplateBody`.
:type template_url: string
:param template_url: Location of file containing the template body. The
URL must point to a template (max size: 307,200 bytes) located in
an S3 bucket in the same region as the stack. For more information,
go to the `Template Anatomy`_ in the AWS CloudFormation User Guide.
Conditional: You must pass either `UsePreviousTemplate` or one of
`TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
`TemplateUrl` are passed, only `TemplateBody` is used.
`TemplateBody`.
:type parameters: list
:param parameters: A list of key/value tuples that specify input
parameters for the stack. A 3-tuple (key, value, bool) may be used to
specify the `UsePreviousValue` option.
:type disable_rollback: boolean
:param disable_rollback: Set to `True` to disable rollback of the stack
if stack creation failed. You can specify either `DisableRollback`
or `OnFailure`, but not both.
Default: `False`
:type timeout_in_minutes: integer
:param timeout_in_minutes: The amount of time that can pass before the
stack status becomes CREATE_FAILED; if `DisableRollback` is not set
or is set to `False`, the stack will be rolled back.
:type notification_arns: list
:param notification_arns: The Simple Notification Service (SNS) topic
ARNs to publish stack related events. You can find your SNS topic
ARNs using the `SNS console`_ or your Command Line Interface (CLI).
:type capabilities: list
:param capabilities: The list of capabilities that you want to allow in
the stack. If your template contains certain resources, you must
specify the CAPABILITY_IAM value for this parameter; otherwise,
this action returns an InsufficientCapabilities error. The
following resources require you to specify the capabilities
parameter: `AWS::CloudFormation::Stack`_, `AWS::IAM::AccessKey`_,
`AWS::IAM::Group`_, `AWS::IAM::InstanceProfile`_,
`AWS::IAM::Policy`_, `AWS::IAM::Role`_, `AWS::IAM::User`_, and
`AWS::IAM::UserToGroupAddition`_.
:type on_failure: string
:param on_failure: Determines what action will be taken if stack
creation fails. This must be one of: DO_NOTHING, ROLLBACK, or
DELETE. You can specify either `OnFailure` or `DisableRollback`,
but not both.
Default: `ROLLBACK`
:type stack_policy_body: string
:param stack_policy_body: Structure containing the stack policy body.
(For more information, go to ` Prevent Updates to Stack Resources`_
in the AWS CloudFormation User Guide.)
If you pass `StackPolicyBody` and `StackPolicyURL`, only
`StackPolicyBody` is used.
:type stack_policy_url: string
:param stack_policy_url: Location of a file containing the stack
policy. The URL must point to a policy (max size: 16KB) located in
an S3 bucket in the same region as the stack. If you pass
`StackPolicyBody` and `StackPolicyURL`, only `StackPolicyBody` is
used.
:type tags: list
:param tags: A set of user-defined `Tags` to associate with this stack,
represented by key/value pairs. Tags defined for the stack are
propagated to EC2 resources that are created as part of the stack.
A maximum number of 10 tags can be specified.
:type use_previous_template: boolean
:param use_previous_template: Set to `True` to use the previous
template instead of uploading a new one via `TemplateBody` or
`TemplateURL`.
Conditional: You must pass either `UsePreviousTemplate` or one of
`TemplateBody` or `TemplateUrl`.
:type stack_policy_during_update_body: string
:param stack_policy_during_update_body: Structure containing the
temporary overriding stack policy body. If you pass
`StackPolicyDuringUpdateBody` and `StackPolicyDuringUpdateURL`,
only `StackPolicyDuringUpdateBody` is used.
If you want to update protected resources, specify a temporary
overriding stack policy during this update. If you do not specify a
stack policy, the current policy that associated with the stack
will be used.
:type stack_policy_during_update_url: string
:param stack_policy_during_update_url: Location of a file containing
the temporary overriding stack policy. The URL must point to a
policy (max size: 16KB) located in an S3 bucket in the same region
as the stack. If you pass `StackPolicyDuringUpdateBody` and
`StackPolicyDuringUpdateURL`, only `StackPolicyDuringUpdateBody` is
used.
If you want to update protected resources, specify a temporary
overriding stack policy during this update. If you do not specify a
stack policy, the current policy that is associated with the stack
will be used.
:rtype: dict
:return: JSON parameters represented as a Python dict.
"""
params = {'ContentType': "JSON", 'StackName': stack_name,
'DisableRollback': self.encode_bool(disable_rollback)}
if template_body:
params['TemplateBody'] = template_body
if template_url:
params['TemplateURL'] = template_url
if use_previous_template is not None:
params['UsePreviousTemplate'] = self.encode_bool(use_previous_template)
if template_body and template_url:
boto.log.warning("If both TemplateBody and TemplateURL are"
" specified, only TemplateBody will be honored by the API")
if parameters and len(parameters) > 0:
for i, parameter_tuple in enumerate(parameters):
key, value = parameter_tuple[:2]
use_previous = (parameter_tuple[2]
if len(parameter_tuple) > 2 else False)
params['Parameters.member.%d.ParameterKey' % (i + 1)] = key
if use_previous:
params['Parameters.member.%d.UsePreviousValue'
% (i + 1)] = self.encode_bool(use_previous)
else:
params['Parameters.member.%d.ParameterValue' % (i + 1)] = value
if capabilities:
for i, value in enumerate(capabilities):
params['Capabilities.member.%d' % (i + 1)] = value
if tags:
for i, (key, value) in enumerate(tags.items()):
params['Tags.member.%d.Key' % (i + 1)] = key
params['Tags.member.%d.Value' % (i + 1)] = value
if notification_arns and len(notification_arns) > 0:
self.build_list_params(params, notification_arns,
"NotificationARNs.member")
if timeout_in_minutes:
params['TimeoutInMinutes'] = int(timeout_in_minutes)
if disable_rollback is not None:
params['DisableRollback'] = str(
disable_rollback).lower()
if on_failure is not None:
params['OnFailure'] = on_failure
if stack_policy_body is not None:
params['StackPolicyBody'] = stack_policy_body
if stack_policy_url is not None:
params['StackPolicyURL'] = stack_policy_url
if stack_policy_during_update_body is not None:
params['StackPolicyDuringUpdateBody'] = stack_policy_during_update_body
if stack_policy_during_update_url is not None:
params['StackPolicyDuringUpdateURL'] = stack_policy_during_update_url
return params
def _do_request(self, call, params, path, method):
"""
Do a request via ``self.make_request`` and parse the JSON response.
:type call: string
:param call: Call name, e.g. ``CreateStack``
:type params: dict
:param params: Dictionary of call parameters
:type path: string
:param path: Server path
:type method: string
:param method: HTTP method to use
:rtype: dict
:return: Parsed JSON response data
"""
response = self.make_request(call, params, path, method)
body = response.read().decode('utf-8')
if response.status == 200:
body = json.loads(body)
return body
else:
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body=body)
def create_stack(self, stack_name, template_body=None, template_url=None,
parameters=None, notification_arns=None, disable_rollback=None,
timeout_in_minutes=None, capabilities=None, tags=None,
on_failure=None, stack_policy_body=None, stack_policy_url=None):
"""
Creates a stack as specified in the template. After the call
completes successfully, the stack creation starts. You can
check the status of the stack via the DescribeStacks API.
Currently, the limit for stacks is 20 stacks per account per
region.
:type stack_name: string
:param stack_name:
The name associated with the stack. The name must be unique within your
AWS account.
Must contain only alphanumeric characters (case sensitive) and start
with an alpha character. Maximum length of the name is 255
characters.
:type template_body: string
:param template_body: Structure containing the template body. (For more
information, go to `Template Anatomy`_ in the AWS CloudFormation
User Guide.)
Conditional: You must pass `TemplateBody` or `TemplateURL`. If both are
passed, only `TemplateBody` is used.
:type template_url: string
:param template_url: Location of file containing the template body. The
URL must point to a template (max size: 307,200 bytes) located in
an S3 bucket in the same region as the stack. For more information,
go to the `Template Anatomy`_ in the AWS CloudFormation User Guide.
Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
passed, only `TemplateBody` is used.
:type parameters: list
:param parameters: A list of key/value tuples that specify input
parameters for the stack.
:type disable_rollback: boolean
:param disable_rollback: Set to `True` to disable rollback of the stack
if stack creation failed. You can specify either `DisableRollback`
or `OnFailure`, but not both.
Default: `False`
:type timeout_in_minutes: integer
:param timeout_in_minutes: The amount of time that can pass before the
stack status becomes CREATE_FAILED; if `DisableRollback` is not set
or is set to `False`, the stack will be rolled back.
:type notification_arns: list
:param notification_arns: The Simple Notification Service (SNS) topic
ARNs to publish stack related events. You can find your SNS topic
ARNs using the `SNS console`_ or your Command Line Interface (CLI).
:type capabilities: list
:param capabilities: The list of capabilities that you want to allow in
the stack. If your template contains certain resources, you must
specify the CAPABILITY_IAM value for this parameter; otherwise,
this action returns an InsufficientCapabilities error. The
following resources require you to specify the capabilities
parameter: `AWS::CloudFormation::Stack`_, `AWS::IAM::AccessKey`_,
`AWS::IAM::Group`_, `AWS::IAM::InstanceProfile`_,
`AWS::IAM::Policy`_, `AWS::IAM::Role`_, `AWS::IAM::User`_, and
`AWS::IAM::UserToGroupAddition`_.
:type on_failure: string
:param on_failure: Determines what action will be taken if stack
creation fails. This must be one of: DO_NOTHING, ROLLBACK, or
DELETE. You can specify either `OnFailure` or `DisableRollback`,
but not both.
Default: `ROLLBACK`
:type stack_policy_body: string
:param stack_policy_body: Structure containing the stack policy body.
(For more information, go to ` Prevent Updates to Stack Resources`_
in the AWS CloudFormation User Guide.)
If you pass `StackPolicyBody` and `StackPolicyURL`, only
`StackPolicyBody` is used.
:type stack_policy_url: string
:param stack_policy_url: Location of a file containing the stack
policy. The URL must point to a policy (max size: 16KB) located in
an S3 bucket in the same region as the stack. If you pass
`StackPolicyBody` and `StackPolicyURL`, only `StackPolicyBody` is
used.
:type tags: dict
:param tags: A set of user-defined `Tags` to associate with this stack,
represented by key/value pairs. Tags defined for the stack are
propagated to EC2 resources that are created as part of the stack.
A maximum number of 10 tags can be specified.
"""
params = self._build_create_or_update_params(stack_name, template_body,
template_url, parameters, disable_rollback, timeout_in_minutes,
notification_arns, capabilities, on_failure, stack_policy_body,
stack_policy_url, tags)
body = self._do_request('CreateStack', params, '/', 'POST')
return body['CreateStackResponse']['CreateStackResult']['StackId']
def update_stack(self, stack_name, template_body=None, template_url=None,
parameters=None, notification_arns=None, disable_rollback=False,
timeout_in_minutes=None, capabilities=None, tags=None,
use_previous_template=None,
stack_policy_during_update_body=None,
stack_policy_during_update_url=None,
stack_policy_body=None, stack_policy_url=None):
"""
Updates a stack as specified in the template. After the call
completes successfully, the stack update starts. You can check
the status of the stack via the DescribeStacks action.
**Note: **You cannot update `AWS::S3::Bucket`_ resources, for
example, to add or modify tags.
To get a copy of the template for an existing stack, you can
use the GetTemplate action.
Tags that were associated with this stack during creation time
will still be associated with the stack after an `UpdateStack`
operation.
For more information about creating an update template,
updating a stack, and monitoring the progress of the update,
see `Updating a Stack`_.
:type stack_name: string
:param stack_name:
The name or stack ID of the stack to update.
Must contain only alphanumeric characters (case sensitive) and start
with an alpha character. Maximum length of the name is 255
characters.
:type template_body: string
:param template_body: Structure containing the template body. (For more
information, go to `Template Anatomy`_ in the AWS CloudFormation
User Guide.)
Conditional: You must pass either `UsePreviousTemplate` or one of
`TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
`TemplateUrl` are passed, only `TemplateBody` is used.
:type template_url: string
:param template_url: Location of file containing the template body. The
URL must point to a template (max size: 307,200 bytes) located in
an S3 bucket in the same region as the stack. For more information,
go to the `Template Anatomy`_ in the AWS CloudFormation User Guide.
Conditional: You must pass either `UsePreviousTemplate` or one of
`TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
`TemplateUrl` are passed, only `TemplateBody` is used.
`TemplateBody`.
:type use_previous_template: boolean
:param use_previous_template: Set to `True` to use the previous
template instead of uploading a new one via `TemplateBody` or
`TemplateURL`.
Conditional: You must pass either `UsePreviousTemplate` or one of
`TemplateBody` or `TemplateUrl`.
:type parameters: list
:param parameters: A list of key/value tuples that specify input
parameters for the stack. A 3-tuple (key, value, bool) may be used to
specify the `UsePreviousValue` option.
:type notification_arns: list
:param notification_arns: The Simple Notification Service (SNS) topic
ARNs to publish stack related events. You can find your SNS topic
ARNs using the `SNS console`_ or your Command Line Interface (CLI).
:type disable_rollback: bool
:param disable_rollback: Indicates whether or not to rollback on
failure.
:type timeout_in_minutes: integer
:param timeout_in_minutes: The amount of time that can pass before the
stack status becomes CREATE_FAILED; if `DisableRollback` is not set
or is set to `False`, the stack will be rolled back.
:type capabilities: list
:param capabilities: The list of capabilities you want to allow in
the stack. Currently, the only valid capability is
'CAPABILITY_IAM'.
:type tags: dict
:param tags: A set of user-defined `Tags` to associate with this stack,
represented by key/value pairs. Tags defined for the stack are
propagated to EC2 resources that are created as part of the stack.
A maximum number of 10 tags can be specified.
:type template_url: string
:param template_url: Location of file containing the template body. The
URL must point to a template located in an S3 bucket in the same
region as the stack. For more information, go to `Template
Anatomy`_ in the AWS CloudFormation User Guide.
Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
passed, only `TemplateBody` is used.
:type stack_policy_during_update_body: string
:param stack_policy_during_update_body: Structure containing the
temporary overriding stack policy body. If you pass
`StackPolicyDuringUpdateBody` and `StackPolicyDuringUpdateURL`,
only `StackPolicyDuringUpdateBody` is used.
If you want to update protected resources, specify a temporary
overriding stack policy during this update. If you do not specify a
stack policy, the current policy that associated with the stack
will be used.
:type stack_policy_during_update_url: string
:param stack_policy_during_update_url: Location of a file containing
the temporary overriding stack policy. The URL must point to a
policy (max size: 16KB) located in an S3 bucket in the same region
as the stack. If you pass `StackPolicyDuringUpdateBody` and
`StackPolicyDuringUpdateURL`, only `StackPolicyDuringUpdateBody` is
used.
If you want to update protected resources, specify a temporary
overriding stack policy during this update. If you do not specify a
stack policy, the current policy that is associated with the stack
will be used.
:rtype: string
:return: The unique Stack ID.
"""
params = self._build_create_or_update_params(stack_name, template_body,
template_url, parameters, disable_rollback, timeout_in_minutes,
notification_arns, capabilities, None, stack_policy_body,
stack_policy_url, tags, use_previous_template,
stack_policy_during_update_body, stack_policy_during_update_url)
body = self._do_request('UpdateStack', params, '/', 'POST')
return body['UpdateStackResponse']['UpdateStackResult']['StackId']
def delete_stack(self, stack_name_or_id):
"""
Deletes a specified stack. Once the call completes
successfully, stack deletion starts. Deleted stacks do not
show up in the DescribeStacks API if the deletion has been
completed successfully.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack.
"""
params = {'ContentType': "JSON", 'StackName': stack_name_or_id}
return self._do_request('DeleteStack', params, '/', 'GET')
def describe_stack_events(self, stack_name_or_id=None, next_token=None):
"""
Returns all stack related events for a specified stack. For
more information about a stack's event history, go to
`Stacks`_ in the AWS CloudFormation User Guide.
Events are returned, even if the stack never existed or has
been successfully deleted.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack.
Default: There is no default value.
:type next_token: string
:param next_token: String that identifies the start of the next list of
events, if there is one.
Default: There is no default value.
"""
params = {}
if stack_name_or_id:
params['StackName'] = stack_name_or_id
if next_token:
params['NextToken'] = next_token
return self.get_list('DescribeStackEvents', params, [('member',
StackEvent)])
def describe_stack_resource(self, stack_name_or_id, logical_resource_id):
"""
Returns a description of the specified resource in the
specified stack.
For deleted stacks, DescribeStackResource returns resource
information for up to 90 days after the stack has been
deleted.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack.
Default: There is no default value.
:type logical_resource_id: string
:param logical_resource_id: The logical name of the resource as
specified in the template.
Default: There is no default value.
"""
params = {'ContentType': "JSON", 'StackName': stack_name_or_id,
'LogicalResourceId': logical_resource_id}
return self._do_request('DescribeStackResource', params, '/', 'GET')
def describe_stack_resources(self, stack_name_or_id=None,
logical_resource_id=None,
physical_resource_id=None):
"""
Returns AWS resource descriptions for running and deleted
stacks. If `StackName` is specified, all the associated
resources that are part of the stack are returned. If
`PhysicalResourceId` is specified, the associated resources of
the stack that the resource belongs to are returned.
Only the first 100 resources will be returned. If your stack
has more resources than this, you should use
`ListStackResources` instead.
For deleted stacks, `DescribeStackResources` returns resource
information for up to 90 days after the stack has been
deleted.
You must specify either `StackName` or `PhysicalResourceId`,
but not both. In addition, you can specify `LogicalResourceId`
to filter the returned result. For more information about
resources, the `LogicalResourceId` and `PhysicalResourceId`,
go to the `AWS CloudFormation User Guide`_.
A `ValidationError` is returned if you specify both
`StackName` and `PhysicalResourceId` in the same request.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack.
Required: Conditional. If you do not specify `StackName`, you must
specify `PhysicalResourceId`.
Default: There is no default value.
:type logical_resource_id: string
:param logical_resource_id: The logical name of the resource as
specified in the template.
Default: There is no default value.
:type physical_resource_id: string
:param physical_resource_id: The name or unique identifier that
corresponds to a physical instance ID of a resource supported by
AWS CloudFormation.
For example, for an Amazon Elastic Compute Cloud (EC2) instance,
`PhysicalResourceId` corresponds to the `InstanceId`. You can pass
the EC2 `InstanceId` to `DescribeStackResources` to find which
stack the instance belongs to and what other resources are part of
the stack.
Required: Conditional. If you do not specify `PhysicalResourceId`, you
must specify `StackName`.
Default: There is no default value.
"""
params = {}
if stack_name_or_id:
params['StackName'] = stack_name_or_id
if logical_resource_id:
params['LogicalResourceId'] = logical_resource_id
if physical_resource_id:
params['PhysicalResourceId'] = physical_resource_id
return self.get_list('DescribeStackResources', params,
[('member', StackResource)])
def describe_stacks(self, stack_name_or_id=None, next_token=None):
"""
Returns the description for the specified stack; if no stack
name was specified, then it returns the description for all
the stacks created.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack.
Default: There is no default value.
:type next_token: string
:param next_token: String that identifies the start of the next list of
stacks, if there is one.
"""
params = {}
if stack_name_or_id:
params['StackName'] = stack_name_or_id
if next_token is not None:
params['NextToken'] = next_token
return self.get_list('DescribeStacks', params, [('member', Stack)])
def get_template(self, stack_name_or_id):
"""
Returns the template body for a specified stack. You can get
the template for running or deleted stacks.
For deleted stacks, GetTemplate returns the template for up to
90 days after the stack has been deleted.
If the template does not exist, a `ValidationError` is
returned.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack, which are not always interchangeable:
+ Running stacks: You can specify either the stack's name or its unique
stack ID.
+ Deleted stacks: You must specify the unique stack ID.
Default: There is no default value.
"""
params = {'ContentType': "JSON", 'StackName': stack_name_or_id}
return self._do_request('GetTemplate', params, '/', 'GET')
def list_stack_resources(self, stack_name_or_id, next_token=None):
"""
Returns descriptions of all resources of the specified stack.
For deleted stacks, ListStackResources returns resource
information for up to 90 days after the stack has been
deleted.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated
with the stack, which are not always interchangeable:
+ Running stacks: You can specify either the stack's name or its unique
stack ID.
+ Deleted stacks: You must specify the unique stack ID.
Default: There is no default value.
:type next_token: string
:param next_token: String that identifies the start of the next list of
stack resource summaries, if there is one.
Default: There is no default value.
"""
params = {'StackName': stack_name_or_id}
if next_token:
params['NextToken'] = next_token
return self.get_list('ListStackResources', params,
[('member', StackResourceSummary)])
def list_stacks(self, stack_status_filters=None, next_token=None):
"""
Returns the summary information for stacks whose status
matches the specified StackStatusFilter. Summary information
for stacks that have been deleted is kept for 90 days after
the stack is deleted. If no StackStatusFilter is specified,
summary information for all stacks is returned (including
existing stacks and stacks that have been deleted).
:type next_token: string
:param next_token: String that identifies the start of the next list of
stacks, if there is one.
Default: There is no default value.
:type stack_status_filter: list
:param stack_status_filter: Stack status to use as a filter. Specify
one or more stack status codes to list only stacks with the
specified status codes. For a complete list of stack status codes,
see the `StackStatus` parameter of the Stack data type.
"""
params = {}
if next_token:
params['NextToken'] = next_token
if stack_status_filters and len(stack_status_filters) > 0:
self.build_list_params(params, stack_status_filters,
"StackStatusFilter.member")
return self.get_list('ListStacks', params,
[('member', StackSummary)])
def validate_template(self, template_body=None, template_url=None):
"""
Validates a specified template.
:type template_body: string
:param template_body: String containing the template body. (For more
information, go to `Template Anatomy`_ in the AWS CloudFormation
User Guide.)
Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
passed, only `TemplateBody` is used.
:type template_url: string
:param template_url: Location of file containing the template body. The
URL must point to a template (max size: 307,200 bytes) located in
an S3 bucket in the same region as the stack. For more information,
go to `Template Anatomy`_ in the AWS CloudFormation User Guide.
Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
passed, only `TemplateBody` is used.
"""
params = {}
if template_body:
params['TemplateBody'] = template_body
if template_url:
params['TemplateURL'] = template_url
if template_body and template_url:
boto.log.warning("If both TemplateBody and TemplateURL are"
" specified, only TemplateBody will be honored by the API")
return self.get_object('ValidateTemplate', params, Template,
verb="POST")
def cancel_update_stack(self, stack_name_or_id=None):
"""
Cancels an update on the specified stack. If the call
completes successfully, the stack will roll back the update
and revert to the previous stack configuration.
Only stacks that are in the UPDATE_IN_PROGRESS state can be
canceled.
:type stack_name_or_id: string
:param stack_name_or_id: The name or the unique identifier associated with
the stack.
"""
params = {}
if stack_name_or_id:
params['StackName'] = stack_name_or_id
return self.get_status('CancelUpdateStack', params)
def estimate_template_cost(self, template_body=None, template_url=None,
parameters=None):
"""
Returns the estimated monthly cost of a template. The return
value is an AWS Simple Monthly Calculator URL with a query
string that describes the resources required to run the
template.
:type template_body: string
:param template_body: Structure containing the template body. (For more
information, go to `Template Anatomy`_ in the AWS CloudFormation
User Guide.)
Conditional: You must pass `TemplateBody` or `TemplateURL`. If both are
passed, only `TemplateBody` is used.
:type template_url: string
:param template_url: Location of file containing the template body. The
URL must point to a template located in an S3 bucket in the same
region as the stack. For more information, go to `Template
Anatomy`_ in the AWS CloudFormation User Guide.
Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
passed, only `TemplateBody` is used.
:type parameters: list
:param parameters: A list of key/value tuples that specify input
parameters for the template.
:rtype: string
:returns: URL to pre-filled cost calculator
"""
params = {'ContentType': "JSON"}
if template_body is not None:
params['TemplateBody'] = template_body
if template_url is not None:
params['TemplateURL'] = template_url
if parameters and len(parameters) > 0:
for i, (key, value) in enumerate(parameters):
params['Parameters.member.%d.ParameterKey' % (i + 1)] = key
params['Parameters.member.%d.ParameterValue' % (i + 1)] = value
response = self._do_request('EstimateTemplateCost', params, '/', 'POST')
return response['EstimateTemplateCostResponse']\
['EstimateTemplateCostResult']\
['Url']
def get_stack_policy(self, stack_name_or_id):
"""
Returns the stack policy for a specified stack. If a stack
doesn't have a policy, a null value is returned.
:type stack_name_or_id: string
:param stack_name_or_id: The name or stack ID that is associated with
the stack whose policy you want to get.
:rtype: string
:return: The policy JSON document
"""
params = {'ContentType': "JSON", 'StackName': stack_name_or_id, }
response = self._do_request('GetStackPolicy', params, '/', 'POST')
return response['GetStackPolicyResponse']\
['GetStackPolicyResult']\
['StackPolicyBody']
def set_stack_policy(self, stack_name_or_id, stack_policy_body=None,
stack_policy_url=None):
"""
Sets a stack policy for a specified stack.
:type stack_name_or_id: string
:param stack_name_or_id: The name or stack ID that you want to
associate a policy with.
:type stack_policy_body: string
:param stack_policy_body: Structure containing the stack policy body.
(For more information, go to ` Prevent Updates to Stack Resources`_
in the AWS CloudFormation User Guide.)
You must pass `StackPolicyBody` or `StackPolicyURL`. If both are
passed, only `StackPolicyBody` is used.
:type stack_policy_url: string
:param stack_policy_url: Location of a file containing the stack
policy. The URL must point to a policy (max size: 16KB) located in
an S3 bucket in the same region as the stack. You must pass
`StackPolicyBody` or `StackPolicyURL`. If both are passed, only
`StackPolicyBody` is used.
"""
params = {'ContentType': "JSON", 'StackName': stack_name_or_id, }
if stack_policy_body is not None:
params['StackPolicyBody'] = stack_policy_body
if stack_policy_url is not None:
params['StackPolicyURL'] = stack_policy_url
response = self._do_request('SetStackPolicy', params, '/', 'POST')
return response['SetStackPolicyResponse']
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
8315,
13,
8664,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
6927,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
646,
6055,
199,
504,
6055,
14,
4091,
1869,
14,
2340,
492,
13894,
12,
13894,
10407,
12,
13894,
2390,
199,
504,
6055,
14,
4091,
1869,
14,
2340,
492,
13894,
4031,
12,
13894,
4031,
10407,
199,
504,
6055,
14,
4091,
1869,
14,
1160,
492,
5458,
199,
504,
6055,
14,
2105,
492,
10168,
3227,
3225,
199,
504,
6055,
14,
4551,
815,
492,
22240,
2354,
199,
504,
6055,
14,
5819,
492,
2022,
421,
199,
533,
8142,
1858,
1615,
3225,
8,
13226,
3227,
3225,
304,
272,
408,
272,
10168,
8142,
1858,
1615,
272,
10168,
8142,
1858,
1615,
22741,
1265,
370,
1218,
436,
9635,
10168,
272,
28890,
6976,
12287,
1470,
12610,
6665,
436,
27714,
14,
10168,
272,
8142,
1858,
1615,
22577,
1265,
1026,
3652,
10168,
7585,
4066,
465,
14347,
15352,
18,
12,
272,
662,
11087,
12,
14347,
428,
2709,
12,
662,
11568,
12,
436,
9195,
17619,
316,
370,
1900,
4721,
590,
13,
26557,
461,
12,
272,
4721,
590,
5269,
461,
12,
7918,
15826,
13103,
1928,
30944,
316,
272,
3595,
6425,
436,
1101,
4039,
314,
8793,
10168,
28890,
6976,
14,
339,
8777,
10168,
8142,
1858,
1615,
12,
1265,
20771,
1006,
402,
2195,
5944,
436,
272,
5124,
315,
282,
1978,
570,
14,
710,
1978,
7890,
282,
3245,
272,
402,
5944,
465,
282,
2849,
4137,
2797,
282,
3464,
14,
10168,
8142,
1858,
1615,
272,
8491,
436,
21812,
1006,
3653,
5944,
402,
314,
3464,
10451,
436,
272,
31965,
1006,
5124,
3382,
314,
5944,
367,
1265,
14,
339,
2104,
1655,
2556,
3595,
642,
3336,
12,
2621,
370,
314,
658,
9089,
1858,
1615,
272,
12705,
10331,
32578,
339,
14347,
8142,
1858,
1615,
7704,
675,
402,
1163,
10168,
7585,
14,
982,
1265,
1929,
272,
4722,
32742,
2556,
3595,
282,
2488,
10168,
3336,
12,
1265,
272,
883,
2342,
314,
3336,
1159,
32742,
3794,
737,
272,
658,
1014,
921,
7231,
14,
15144,
14,
957,
15,
9970,
15,
32578,
272,
408,
272,
3261,
3353,
275,
6055,
14,
888,
14,
362,
360,
20380,
297,
283,
2177,
78,
63,
1023,
297,
283,
6542,
13,
1717,
13,
1046,
358,
272,
3758,
10708,
985,
275,
6055,
14,
888,
14,
362,
360,
20380,
297,
283,
2177,
78,
63,
4551,
63,
354,
297,
283,
527,
13,
14346,
13,
17,
358,
272,
3758,
10708,
11442,
275,
6055,
14,
888,
14,
362,
360,
20380,
297,
283,
2177,
78,
63,
4551,
63,
6520,
297,
4490,
283,
4091,
1869,
14,
527,
13,
14346,
13,
17,
14,
21442,
14,
957,
358,
339,
1686,
63,
4981,
275,
334,
267,
283,
8366,
63,
568,
63,
24547,
297,
283,
8366,
63,
12299,
297,
283,
8366,
63,
15558,
297,
267,
283,
14881,
7111,
63,
568,
63,
24547,
297,
283,
14881,
7111,
63,
12299,
297,
283,
14881,
7111,
63,
15558,
297,
267,
283,
7014,
63,
568,
63,
24547,
297,
283,
7014,
63,
12299,
297,
283,
7014,
63,
15558,
297,
267,
283,
10383,
63,
568,
63,
24547,
297,
283,
10383,
63,
15558,
63,
28663,
2160,
63,
568,
63,
24547,
297,
267,
283,
10383,
63,
15558,
297,
283,
10383,
63,
14881,
7111,
63,
568,
63,
24547,
297,
267,
283,
10383,
63,
14881,
7111,
63,
12299,
297,
267,
283,
10383,
63,
14881,
7111,
63,
15558,
63,
28663,
2160,
63,
568,
63,
24547,
297,
267,
283,
10383,
63,
14881,
7111,
63,
15558,
358,
339,
347,
636,
826,
721,
277,
12,
11488,
63,
2732,
63,
498,
63,
344,
29,
403,
12,
11488,
63,
4731,
63,
2732,
63,
498,
29,
403,
12,
326,
365,
63,
7817,
29,
549,
12,
1844,
29,
403,
12,
4566,
29,
403,
12,
4566,
63,
719,
29,
403,
12,
326,
4566,
63,
751,
29,
403,
12,
4566,
63,
1529,
29,
403,
12,
3105,
29,
16,
12,
326,
4178,
63,
2105,
63,
3702,
29,
403,
12,
4897,
29,
403,
12,
931,
25412,
326,
11109,
29,
403,
12,
6391,
63,
1418,
29,
403,
12,
4107,
63,
8356,
29,
549,
12,
326,
4690,
63,
354,
29,
403,
304,
267,
340,
440,
4897,
26,
288,
4897,
275,
22240,
2354,
8,
277,
12,
291,
14,
2698,
10708,
985,
12,
355,
291,
14,
2698,
10708,
11442,
12,
8142,
1858,
1615,
3225,
9,
267,
291,
14,
4551,
275,
4897,
267,
1613,
8,
9089,
1858,
1615,
3225,
12,
291,
2843,
826,
721,
7231,
63,
2732,
63,
498,
63,
344,
12,
2511,
11488,
63,
4731,
63,
2732,
63,
498,
12,
2511,
365,
63,
7817,
12,
1844,
12,
4566,
12,
4566,
63,
719,
12,
2511,
4566,
63,
751,
12,
4566,
63,
1529,
12,
2511,
291,
14,
4551,
14,
6520,
12,
3105,
12,
2511,
4178,
63,
2105,
63,
3702,
12,
931,
12,
2511,
6391,
63,
1418,
12,
2511,
4107,
63,
8356,
29
] |
[
1898,
334,
67,
9,
8315,
13,
8664,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
6927,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
646,
6055,
199,
504,
6055,
14,
4091,
1869,
14,
2340,
492,
13894,
12,
13894,
10407,
12,
13894,
2390,
199,
504,
6055,
14,
4091,
1869,
14,
2340,
492,
13894,
4031,
12,
13894,
4031,
10407,
199,
504,
6055,
14,
4091,
1869,
14,
1160,
492,
5458,
199,
504,
6055,
14,
2105,
492,
10168,
3227,
3225,
199,
504,
6055,
14,
4551,
815,
492,
22240,
2354,
199,
504,
6055,
14,
5819,
492,
2022,
421,
199,
533,
8142,
1858,
1615,
3225,
8,
13226,
3227,
3225,
304,
272,
408,
272,
10168,
8142,
1858,
1615,
272,
10168,
8142,
1858,
1615,
22741,
1265,
370,
1218,
436,
9635,
10168,
272,
28890,
6976,
12287,
1470,
12610,
6665,
436,
27714,
14,
10168,
272,
8142,
1858,
1615,
22577,
1265,
1026,
3652,
10168,
7585,
4066,
465,
14347,
15352,
18,
12,
272,
662,
11087,
12,
14347,
428,
2709,
12,
662,
11568,
12,
436,
9195,
17619,
316,
370,
1900,
4721,
590,
13,
26557,
461,
12,
272,
4721,
590,
5269,
461,
12,
7918,
15826,
13103,
1928,
30944,
316,
272,
3595,
6425,
436,
1101,
4039,
314,
8793,
10168,
28890,
6976,
14,
339,
8777,
10168,
8142,
1858,
1615,
12,
1265,
20771,
1006,
402,
2195,
5944,
436,
272,
5124,
315,
282,
1978,
570,
14,
710,
1978,
7890,
282,
3245,
272,
402,
5944,
465,
282,
2849,
4137,
2797,
282,
3464,
14,
10168,
8142,
1858,
1615,
272,
8491,
436,
21812,
1006,
3653,
5944,
402,
314,
3464,
10451,
436,
272,
31965,
1006,
5124,
3382,
314,
5944,
367,
1265,
14,
339,
2104,
1655,
2556,
3595,
642,
3336,
12,
2621,
370,
314,
658,
9089,
1858,
1615,
272,
12705,
10331,
32578,
339,
14347,
8142,
1858,
1615,
7704,
675,
402,
1163,
10168,
7585,
14,
982,
1265,
1929,
272,
4722,
32742,
2556,
3595,
282,
2488,
10168,
3336,
12,
1265,
272,
883,
2342,
314,
3336,
1159,
32742,
3794,
737,
272,
658,
1014,
921,
7231,
14,
15144,
14,
957,
15,
9970,
15,
32578,
272,
408,
272,
3261,
3353,
275,
6055,
14,
888,
14,
362,
360,
20380,
297,
283,
2177,
78,
63,
1023,
297,
283,
6542,
13,
1717,
13,
1046,
358,
272,
3758,
10708,
985,
275,
6055,
14,
888,
14,
362,
360,
20380,
297,
283,
2177,
78,
63,
4551,
63,
354,
297,
283,
527,
13,
14346,
13,
17,
358,
272,
3758,
10708,
11442,
275,
6055,
14,
888,
14,
362,
360,
20380,
297,
283,
2177,
78,
63,
4551,
63,
6520,
297,
4490,
283,
4091,
1869,
14,
527,
13,
14346,
13,
17,
14,
21442,
14,
957,
358,
339,
1686,
63,
4981,
275,
334,
267,
283,
8366,
63,
568,
63,
24547,
297,
283,
8366,
63,
12299,
297,
283,
8366,
63,
15558,
297,
267,
283,
14881,
7111,
63,
568,
63,
24547,
297,
283,
14881,
7111,
63,
12299,
297,
283,
14881,
7111,
63,
15558,
297,
267,
283,
7014,
63,
568,
63,
24547,
297,
283,
7014,
63,
12299,
297,
283,
7014,
63,
15558,
297,
267,
283,
10383,
63,
568,
63,
24547,
297,
283,
10383,
63,
15558,
63,
28663,
2160,
63,
568,
63,
24547,
297,
267,
283,
10383,
63,
15558,
297,
283,
10383,
63,
14881,
7111,
63,
568,
63,
24547,
297,
267,
283,
10383,
63,
14881,
7111,
63,
12299,
297,
267,
283,
10383,
63,
14881,
7111,
63,
15558,
63,
28663,
2160,
63,
568,
63,
24547,
297,
267,
283,
10383,
63,
14881,
7111,
63,
15558,
358,
339,
347,
636,
826,
721,
277,
12,
11488,
63,
2732,
63,
498,
63,
344,
29,
403,
12,
11488,
63,
4731,
63,
2732,
63,
498,
29,
403,
12,
326,
365,
63,
7817,
29,
549,
12,
1844,
29,
403,
12,
4566,
29,
403,
12,
4566,
63,
719,
29,
403,
12,
326,
4566,
63,
751,
29,
403,
12,
4566,
63,
1529,
29,
403,
12,
3105,
29,
16,
12,
326,
4178,
63,
2105,
63,
3702,
29,
403,
12,
4897,
29,
403,
12,
931,
25412,
326,
11109,
29,
403,
12,
6391,
63,
1418,
29,
403,
12,
4107,
63,
8356,
29,
549,
12,
326,
4690,
63,
354,
29,
403,
304,
267,
340,
440,
4897,
26,
288,
4897,
275,
22240,
2354,
8,
277,
12,
291,
14,
2698,
10708,
985,
12,
355,
291,
14,
2698,
10708,
11442,
12,
8142,
1858,
1615,
3225,
9,
267,
291,
14,
4551,
275,
4897,
267,
1613,
8,
9089,
1858,
1615,
3225,
12,
291,
2843,
826,
721,
7231,
63,
2732,
63,
498,
63,
344,
12,
2511,
11488,
63,
4731,
63,
2732,
63,
498,
12,
2511,
365,
63,
7817,
12,
1844,
12,
4566,
12,
4566,
63,
719,
12,
2511,
4566,
63,
751,
12,
4566,
63,
1529,
12,
2511,
291,
14,
4551,
14,
6520,
12,
3105,
12,
2511,
4178,
63,
2105,
63,
3702,
12,
931,
12,
2511,
6391,
63,
1418,
12,
2511,
4107,
63,
8356,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sachintaware/sublime-wakatime
|
packages/wakatime/packages/pygments_py3/pygments/lexers/felix.py
|
72
|
9410
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.felix
~~~~~~~~~~~~~~~~~~~~~
Lexer for the Felix language.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.lexer import RegexLexer, include, bygroups, default, words, \
combined
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation
__all__ = ['FelixLexer']
class FelixLexer(RegexLexer):
"""
For `Felix <http://www.felix-lang.org>`_ source code.
.. versionadded:: 1.2
"""
name = 'Felix'
aliases = ['felix', 'flx']
filenames = ['*.flx', '*.flxh']
mimetypes = ['text/x-felix']
preproc = (
'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef',
)
keywords = (
'_', '_deref', 'all', 'as',
'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass',
'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else',
'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except',
'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork',
'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance',
'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace',
'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise',
'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then',
'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto',
'when', 'whilst', 'with', 'yield',
)
keyword_directives = (
'_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export',
'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn',
'package', 'private', 'pod', 'property', 'public', 'publish',
'requires', 'todo', 'virtual', 'use',
)
keyword_declarations = (
'def', 'let', 'ref', 'val', 'var',
)
keyword_types = (
'unit', 'void', 'any', 'bool',
'byte', 'offset',
'address', 'caddress', 'cvaddress', 'vaddress',
'tiny', 'short', 'int', 'long', 'vlong',
'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong',
'int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64',
'float', 'double', 'ldouble',
'complex', 'dcomplex', 'lcomplex',
'imaginary', 'dimaginary', 'limaginary',
'char', 'wchar', 'uchar',
'charp', 'charcp', 'ucharp', 'ucharcp',
'string', 'wstring', 'ustring',
'cont',
'array', 'varray', 'list',
'lvalue', 'opt', 'slice',
)
keyword_constants = (
'false', 'true',
)
operator_words = (
'and', 'not', 'in', 'is', 'isin', 'or', 'xor',
)
name_builtins = (
'_svc', 'while',
)
name_pseudo = (
'root', 'self', 'this',
)
decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?'
tokens = {
'root': [
include('whitespace'),
# Keywords
(words(('axiom', 'ctor', 'fun', 'gen', 'proc', 'reduce',
'union'), suffix=r'\b'),
Keyword, 'funcname'),
(words(('class', 'cclass', 'cstruct', 'obj', 'struct'), suffix=r'\b'),
Keyword, 'classname'),
(r'(instance|module|typeclass)\b', Keyword, 'modulename'),
(words(keywords, suffix=r'\b'), Keyword),
(words(keyword_directives, suffix=r'\b'), Name.Decorator),
(words(keyword_declarations, suffix=r'\b'), Keyword.Declaration),
(words(keyword_types, suffix=r'\b'), Keyword.Type),
(words(keyword_constants, suffix=r'\b'), Keyword.Constant),
# Operators
include('operators'),
# Float Literal
# -- Hex Float
(r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float),
# -- DecimalFloat
(r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float),
(r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?',
Number.Float),
# IntegerLiteral
# -- Binary
(r'0[Bb][01_]+%s' % decimal_suffixes, Number.Bin),
# -- Octal
(r'0[0-7_]+%s' % decimal_suffixes, Number.Oct),
# -- Hexadecimal
(r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex),
# -- Decimal
(r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer),
# Strings
('([rR][cC]?|[cC][rR])"""', String, 'tdqs'),
("([rR][cC]?|[cC][rR])'''", String, 'tsqs'),
('([rR][cC]?|[cC][rR])"', String, 'dqs'),
("([rR][cC]?|[cC][rR])'", String, 'sqs'),
('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')),
("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')),
('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')),
("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')),
# Punctuation
(r'[\[\]{}:(),;?]', Punctuation),
# Labels
(r'[a-zA-Z_]\w*:>', Name.Label),
# Identifiers
(r'(%s)\b' % '|'.join(name_builtins), Name.Builtin),
(r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo),
(r'[a-zA-Z_]\w*', Name),
],
'whitespace': [
(r'\n', Text),
(r'\s+', Text),
include('comment'),
# Preprocessor
(r'#\s*if\s+0', Comment.Preproc, 'if0'),
(r'#', Comment.Preproc, 'macro'),
],
'operators': [
(r'(%s)\b' % '|'.join(operator_words), Operator.Word),
(r'!=|==|<<|>>|\|\||&&|[-~+/*%=<>&^|.$]', Operator),
],
'comment': [
(r'//(.*?)\n', Comment.Single),
(r'/[*]', Comment.Multiline, 'comment2'),
],
'comment2': [
(r'[^/*]', Comment.Multiline),
(r'/[*]', Comment.Multiline, '#push'),
(r'[*]/', Comment.Multiline, '#pop'),
(r'[/*]', Comment.Multiline),
],
'if0': [
(r'^\s*#if.*?(?<!\\)\n', Comment, '#push'),
(r'^\s*#endif.*?(?<!\\)\n', Comment, '#pop'),
(r'.*?\n', Comment),
],
'macro': [
include('comment'),
(r'(import|include)(\s+)(<[^>]*?>)',
bygroups(Comment.Preproc, Text, String), '#pop'),
(r'(import|include)(\s+)("[^"]*?")',
bygroups(Comment.Preproc, Text, String), '#pop'),
(r"(import|include)(\s+)('[^']*?')",
bygroups(Comment.Preproc, Text, String), '#pop'),
(r'[^/\n]+', Comment.Preproc),
# (r'/[*](.|\n)*?[*]/', Comment),
# (r'//.*?\n', Comment, '#pop'),
(r'/', Comment.Preproc),
(r'(?<=\\)\n', Comment.Preproc),
(r'\n', Comment.Preproc, '#pop'),
],
'funcname': [
include('whitespace'),
(r'[a-zA-Z_]\w*', Name.Function, '#pop'),
# anonymous functions
(r'(?=\()', Text, '#pop'),
],
'classname': [
include('whitespace'),
(r'[a-zA-Z_]\w*', Name.Class, '#pop'),
# anonymous classes
(r'(?=\{)', Text, '#pop'),
],
'modulename': [
include('whitespace'),
(r'\[', Punctuation, ('modulename2', 'tvarlist')),
default('modulename2'),
],
'modulename2': [
include('whitespace'),
(r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'),
],
'tvarlist': [
include('whitespace'),
include('operators'),
(r'\[', Punctuation, '#push'),
(r'\]', Punctuation, '#pop'),
(r',', Punctuation),
(r'(with|where)\b', Keyword),
(r'[a-zA-Z_]\w*', Name),
],
'stringescape': [
(r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|'
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
],
'strings': [
(r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
'[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
(r'[^\\\'"%\n]+', String),
# quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),
# unhandled string formatting sign
(r'%', String)
# newlines are an error (use "nl" state)
],
'nl': [
(r'\n', String)
],
'dqs': [
(r'"', String, '#pop'),
# included here again for raw strings
(r'\\\\|\\"|\\\n', String.Escape),
include('strings')
],
'sqs': [
(r"'", String, '#pop'),
# included here again for raw strings
(r"\\\\|\\'|\\\n", String.Escape),
include('strings')
],
'tdqs': [
(r'"""', String, '#pop'),
include('strings'),
include('nl')
],
'tsqs': [
(r"'''", String, '#pop'),
include('strings'),
include('nl')
],
}
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
771,
20528,
272,
18294,
2878,
94,
339,
21125,
367,
314,
7949,
20528,
2637,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
12,
2387,
12,
10259,
12,
849,
12,
5932,
12,
971,
272,
12149,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
272,
4860,
12,
10357,
199,
199,
363,
452,
363,
275,
788,
3456,
20528,
5838,
418,
421,
199,
533,
7949,
20528,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
3456,
20528,
665,
1014,
921,
1544,
14,
771,
20528,
13,
4159,
14,
1308,
18740,
1350,
1233,
14,
339,
2508,
7445,
447,
413,
14,
18,
272,
408,
339,
536,
275,
283,
3456,
20528,
7,
272,
5481,
275,
788,
771,
20528,
297,
283,
2327,
88,
418,
272,
6203,
275,
17855,
2327,
88,
297,
11937,
2327,
29426,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
771,
20528,
418,
339,
876,
4687,
275,
334,
267,
283,
4164,
297,
283,
2836,
297,
283,
13739,
297,
283,
692,
297,
283,
27737,
297,
283,
27708,
297,
272,
776,
339,
7681,
275,
334,
267,
25469,
2513,
29176,
297,
283,
452,
297,
283,
305,
297,
267,
283,
479,
297,
283,
16880,
297,
283,
1250,
297,
283,
3058,
297,
283,
2546,
297,
283,
2546,
889,
297,
283,
67,
533,
297,
267,
283,
600,
297,
283,
15278,
297,
283,
9798,
297,
283,
1117,
297,
283,
4456,
297,
283,
68,
583,
29680,
297,
283,
4164,
297,
283,
2836,
297,
267,
283,
500,
16880,
297,
283,
500,
2546,
297,
283,
13739,
297,
283,
500,
1431,
297,
283,
4869,
297,
283,
2590,
297,
267,
283,
3924,
297,
283,
4921,
297,
283,
15172,
297,
283,
509,
297,
283,
509,
452,
297,
283,
28767,
297,
283,
11796,
297,
267,
283,
7036,
630,
297,
283,
14867,
297,
283,
5425,
297,
283,
692,
297,
283,
24575,
297,
283,
6486,
297,
283,
842,
297,
267,
283,
3266,
297,
283,
11126,
297,
283,
2734,
297,
283,
3813,
297,
283,
1431,
297,
283,
578,
297,
283,
3251,
297,
267,
283,
1222,
297,
283,
889,
4441,
297,
283,
2865,
5125,
297,
283,
1113,
297,
283,
1618,
297,
283,
1490,
297,
283,
1122,
297,
283,
3730,
297,
267,
283,
11191,
297,
283,
1135,
3113,
297,
283,
1135,
1431,
297,
283,
8165,
297,
283,
1107,
297,
283,
1589,
297,
283,
12726,
297,
267,
283,
475,
297,
283,
466,
297,
283,
466,
2546,
297,
283,
9594,
297,
283,
466,
1431,
297,
283,
23426,
297,
283,
384,
475,
297,
267,
283,
6526,
297,
283,
2191,
382,
270,
297,
283,
1045,
297,
283,
11481,
297,
272,
776,
339,
4252,
63,
23216,
275,
334,
267,
2513,
9493,
63,
3929,
297,
2513,
9493,
63,
466,
297,
283,
2030,
297,
283,
3349,
297,
283,
1297,
297,
283,
3790,
297,
267,
283,
1291,
297,
283,
6460,
297,
283,
76,
637,
297,
283,
11300,
297,
283,
889,
6460,
297,
283,
27400,
353,
297,
267,
283,
2491,
297,
283,
4239,
297,
283,
12656,
297,
283,
1829,
297,
283,
3455,
297,
283,
4763,
297,
267,
283,
6537,
297,
283,
11396,
297,
283,
2065,
297,
283,
1180,
297,
272,
776,
339,
4252,
63,
21200,
275,
334,
267,
283,
318,
297,
283,
2723,
297,
283,
1121,
297,
283,
637,
297,
283,
1391,
297,
272,
776,
339,
4252,
63,
1313,
275,
334,
267,
283,
3248,
297,
283,
1647,
297,
283,
1629,
297,
283,
2245,
297,
267,
283,
4414,
297,
221,
283,
2743,
297,
267,
283,
1562,
297,
283,
67,
1562,
297,
283,
5107,
1562,
297,
283,
86,
1562,
297,
267,
283,
9864,
297,
283,
3612,
297,
283,
442,
297,
283,
2809,
297,
283,
86,
2809,
297,
267,
283,
337,
8952,
297,
283,
27170,
297,
283,
86,
3612,
297,
283,
1635,
297,
283,
15688,
297,
283,
9154,
2809,
297,
267,
283,
442,
24,
297,
283,
442,
975,
297,
283,
442,
708,
297,
283,
442,
772,
297,
267,
283,
1635,
24,
297,
283,
1635,
975,
297,
283,
1635,
708,
297,
283,
1635,
772,
297,
267,
283,
1609,
297,
283,
3157,
297,
283,
76,
3157,
297,
267,
283,
5254,
297,
283,
68,
5254,
297,
283,
76,
5254,
297,
267,
283,
32192,
297,
283,
328,
391,
17580,
297,
283,
317,
391,
17580,
297,
267,
283,
1560,
297,
283,
23118,
297,
283,
85,
1560,
297,
267,
283,
1560,
80,
297,
283,
1560,
1850,
297,
283,
85,
1560,
80,
297,
283,
85,
1560,
1850,
297,
267,
283,
875,
297,
283,
87,
875,
297,
283,
85,
875,
297,
267,
283,
11096,
297,
267,
283,
1144,
297,
283,
86,
1144,
297,
283,
513,
297,
267,
283,
76,
585,
297,
283,
2992,
297,
283,
5224,
297,
272,
776,
339,
4252,
63,
5559,
275,
334,
267,
283,
3910,
297,
283,
2052,
297,
272,
776,
339,
4182,
63,
3148,
275,
334,
267,
283,
460,
297,
283,
1397,
297,
283,
262,
297,
283,
374,
297,
283,
25184,
297,
283,
269,
297,
283,
15721,
297,
272,
776,
339,
536,
63,
10372,
275,
334,
267,
2513,
10599,
297,
283,
6710,
297,
272,
776,
339,
536,
63,
22490,
275,
334,
267,
283,
1231,
297,
283,
277,
297,
283,
3749,
297,
272,
776,
339,
6107,
63,
16097,
275,
283,
779,
84,
23433,
18934,
27965,
44,
86,
54,
11752,
914,
92,
4464,
92,
779,
73,
41,
85,
53,
566,
8,
24,
92,
975,
92,
708,
92,
772,
430,
14069,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
2387,
360,
8506,
659,
953,
327,
2606,
3148,
288,
334,
3148,
4725,
1219,
73,
676,
297,
283,
630,
297,
283,
7036,
297,
283,
2268,
297,
283,
4687,
297,
283,
5270,
297,
490,
283,
8888,
659,
4739,
29,
82,
1154,
66,
659,
1467,
6431,
12,
283,
29577,
659,
288,
334,
3148,
4725,
533,
297,
283,
67,
533,
297,
283,
67,
1820,
297,
283,
1113,
297,
283,
1820,
659,
4739,
29,
82,
1154,
66,
659,
1467,
6431,
12,
283,
19851,
659,
288,
334,
82,
6774,
842,
92,
578,
92,
466,
533,
2862,
66,
297,
6431,
12,
283,
22582,
659,
953,
334,
3148,
8
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
771,
20528,
272,
18294,
2878,
94,
339,
21125,
367,
314,
7949,
20528,
2637,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
12,
2387,
12,
10259,
12,
849,
12,
5932,
12,
971,
272,
12149,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
272,
4860,
12,
10357,
199,
199,
363,
452,
363,
275,
788,
3456,
20528,
5838,
418,
421,
199,
533,
7949,
20528,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
3456,
20528,
665,
1014,
921,
1544,
14,
771,
20528,
13,
4159,
14,
1308,
18740,
1350,
1233,
14,
339,
2508,
7445,
447,
413,
14,
18,
272,
408,
339,
536,
275,
283,
3456,
20528,
7,
272,
5481,
275,
788,
771,
20528,
297,
283,
2327,
88,
418,
272,
6203,
275,
17855,
2327,
88,
297,
11937,
2327,
29426,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
771,
20528,
418,
339,
876,
4687,
275,
334,
267,
283,
4164,
297,
283,
2836,
297,
283,
13739,
297,
283,
692,
297,
283,
27737,
297,
283,
27708,
297,
272,
776,
339,
7681,
275,
334,
267,
25469,
2513,
29176,
297,
283,
452,
297,
283,
305,
297,
267,
283,
479,
297,
283,
16880,
297,
283,
1250,
297,
283,
3058,
297,
283,
2546,
297,
283,
2546,
889,
297,
283,
67,
533,
297,
267,
283,
600,
297,
283,
15278,
297,
283,
9798,
297,
283,
1117,
297,
283,
4456,
297,
283,
68,
583,
29680,
297,
283,
4164,
297,
283,
2836,
297,
267,
283,
500,
16880,
297,
283,
500,
2546,
297,
283,
13739,
297,
283,
500,
1431,
297,
283,
4869,
297,
283,
2590,
297,
267,
283,
3924,
297,
283,
4921,
297,
283,
15172,
297,
283,
509,
297,
283,
509,
452,
297,
283,
28767,
297,
283,
11796,
297,
267,
283,
7036,
630,
297,
283,
14867,
297,
283,
5425,
297,
283,
692,
297,
283,
24575,
297,
283,
6486,
297,
283,
842,
297,
267,
283,
3266,
297,
283,
11126,
297,
283,
2734,
297,
283,
3813,
297,
283,
1431,
297,
283,
578,
297,
283,
3251,
297,
267,
283,
1222,
297,
283,
889,
4441,
297,
283,
2865,
5125,
297,
283,
1113,
297,
283,
1618,
297,
283,
1490,
297,
283,
1122,
297,
283,
3730,
297,
267,
283,
11191,
297,
283,
1135,
3113,
297,
283,
1135,
1431,
297,
283,
8165,
297,
283,
1107,
297,
283,
1589,
297,
283,
12726,
297,
267,
283,
475,
297,
283,
466,
297,
283,
466,
2546,
297,
283,
9594,
297,
283,
466,
1431,
297,
283,
23426,
297,
283,
384,
475,
297,
267,
283,
6526,
297,
283,
2191,
382,
270,
297,
283,
1045,
297,
283,
11481,
297,
272,
776,
339,
4252,
63,
23216,
275,
334,
267,
2513,
9493,
63,
3929,
297,
2513,
9493,
63,
466,
297,
283,
2030,
297,
283,
3349,
297,
283,
1297,
297,
283,
3790,
297,
267,
283,
1291,
297,
283,
6460,
297,
283,
76,
637,
297,
283,
11300,
297,
283,
889,
6460,
297,
283,
27400,
353,
297,
267,
283,
2491,
297,
283,
4239,
297,
283,
12656,
297,
283,
1829,
297,
283,
3455,
297,
283,
4763,
297,
267,
283,
6537,
297,
283,
11396,
297,
283,
2065,
297,
283,
1180,
297,
272,
776,
339,
4252,
63,
21200,
275,
334,
267,
283,
318,
297,
283,
2723,
297,
283,
1121,
297,
283,
637,
297,
283,
1391,
297,
272,
776,
339,
4252,
63,
1313,
275,
334,
267,
283,
3248,
297,
283,
1647,
297,
283,
1629,
297,
283,
2245,
297,
267,
283,
4414,
297,
221,
283,
2743,
297,
267,
283,
1562,
297,
283,
67,
1562,
297,
283,
5107,
1562,
297,
283,
86,
1562,
297,
267,
283,
9864,
297,
283,
3612,
297,
283,
442,
297,
283,
2809,
297,
283,
86,
2809,
297,
267,
283,
337,
8952,
297,
283,
27170,
297,
283,
86,
3612,
297,
283,
1635,
297,
283,
15688,
297,
283,
9154,
2809,
297,
267,
283,
442,
24,
297,
283,
442,
975,
297,
283,
442,
708,
297,
283,
442,
772,
297,
267,
283,
1635,
24,
297,
283,
1635,
975,
297,
283,
1635,
708,
297,
283,
1635,
772,
297,
267,
283,
1609,
297,
283,
3157,
297,
283,
76,
3157,
297,
267,
283,
5254,
297,
283,
68,
5254,
297,
283,
76,
5254,
297,
267,
283,
32192,
297,
283,
328,
391,
17580,
297,
283,
317,
391,
17580,
297,
267,
283,
1560,
297,
283,
23118,
297,
283,
85,
1560,
297,
267,
283,
1560,
80,
297,
283,
1560,
1850,
297,
283,
85,
1560,
80,
297,
283,
85,
1560,
1850,
297,
267,
283,
875,
297,
283,
87,
875,
297,
283,
85,
875,
297,
267,
283,
11096,
297,
267,
283,
1144,
297,
283,
86,
1144,
297,
283,
513,
297,
267,
283,
76,
585,
297,
283,
2992,
297,
283,
5224,
297,
272,
776,
339,
4252,
63,
5559,
275,
334,
267,
283,
3910,
297,
283,
2052,
297,
272,
776,
339,
4182,
63,
3148,
275,
334,
267,
283,
460,
297,
283,
1397,
297,
283,
262,
297,
283,
374,
297,
283,
25184,
297,
283,
269,
297,
283,
15721,
297,
272,
776,
339,
536,
63,
10372,
275,
334,
267,
2513,
10599,
297,
283,
6710,
297,
272,
776,
339,
536,
63,
22490,
275,
334,
267,
283,
1231,
297,
283,
277,
297,
283,
3749,
297,
272,
776,
339,
6107,
63,
16097,
275,
283,
779,
84,
23433,
18934,
27965,
44,
86,
54,
11752,
914,
92,
4464,
92,
779,
73,
41,
85,
53,
566,
8,
24,
92,
975,
92,
708,
92,
772,
430,
14069,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
2387,
360,
8506,
659,
953,
327,
2606,
3148,
288,
334,
3148,
4725,
1219,
73,
676,
297,
283,
630,
297,
283,
7036,
297,
283,
2268,
297,
283,
4687,
297,
283,
5270,
297,
490,
283,
8888,
659,
4739,
29,
82,
1154,
66,
659,
1467,
6431,
12,
283,
29577,
659,
288,
334,
3148,
4725,
533,
297,
283,
67,
533,
297,
283,
67,
1820,
297,
283,
1113,
297,
283,
1820,
659,
4739,
29,
82,
1154,
66,
659,
1467,
6431,
12,
283,
19851,
659,
288,
334,
82,
6774,
842,
92,
578,
92,
466,
533,
2862,
66,
297,
6431,
12,
283,
22582,
659,
953,
334,
3148,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
arborh/tensorflow
|
tensorflow/python/lib/io/file_io_test.py
|
7
|
24382
|
# This Python file uses the following encoding: utf-8
# 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.
# =============================================================================
"""Testing File IO operations in file_io.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os.path
import numpy as np
from tensorflow.python.framework import errors
from tensorflow.python.lib.io import file_io
from tensorflow.python.platform import gfile
from tensorflow.python.platform import test
class FileIoTest(test.TestCase):
def setUp(self):
self._base_dir = os.path.join(self.get_temp_dir(), "base_dir")
file_io.create_dir(self._base_dir)
def tearDown(self):
file_io.delete_recursively(self._base_dir)
def testEmptyFilename(self):
f = file_io.FileIO("", mode="r")
with self.assertRaises(errors.NotFoundError):
_ = f.read()
def testFileDoesntExist(self):
file_path = os.path.join(self._base_dir, "temp_file")
self.assertFalse(file_io.file_exists(file_path))
with self.assertRaises(errors.NotFoundError):
_ = file_io.read_file_to_string(file_path)
def testWriteToString(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.write_string_to_file(file_path, "testing")
self.assertTrue(file_io.file_exists(file_path))
file_contents = file_io.read_file_to_string(file_path)
self.assertEqual("testing", file_contents)
def testAtomicWriteStringToFile(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.atomic_write_string_to_file(file_path, "testing")
self.assertTrue(file_io.file_exists(file_path))
file_contents = file_io.read_file_to_string(file_path)
self.assertEqual("testing", file_contents)
def testAtomicWriteStringToFileOverwriteFalse(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.atomic_write_string_to_file(file_path, "old", overwrite=False)
with self.assertRaises(errors.AlreadyExistsError):
file_io.atomic_write_string_to_file(file_path, "new", overwrite=False)
file_contents = file_io.read_file_to_string(file_path)
self.assertEqual("old", file_contents)
file_io.delete_file(file_path)
file_io.atomic_write_string_to_file(file_path, "new", overwrite=False)
file_contents = file_io.read_file_to_string(file_path)
self.assertEqual("new", file_contents)
def testReadBinaryMode(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.write_string_to_file(file_path, "testing")
with file_io.FileIO(file_path, mode="rb") as f:
self.assertEqual(b"testing", f.read())
def testWriteBinaryMode(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, "wb").write("testing")
with file_io.FileIO(file_path, mode="r") as f:
self.assertEqual("testing", f.read())
def testAppend(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="w") as f:
f.write("begin\n")
with file_io.FileIO(file_path, mode="a") as f:
f.write("a1\n")
with file_io.FileIO(file_path, mode="a") as f:
f.write("a2\n")
with file_io.FileIO(file_path, mode="r") as f:
file_contents = f.read()
self.assertEqual("begin\na1\na2\n", file_contents)
def testMultipleFiles(self):
file_prefix = os.path.join(self._base_dir, "temp_file")
for i in range(5000):
f = file_io.FileIO(file_prefix + str(i), mode="w+")
f.write("testing")
f.flush()
self.assertEqual("testing", f.read())
f.close()
def testMultipleWrites(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="w") as f:
f.write("line1\n")
f.write("line2")
file_contents = file_io.read_file_to_string(file_path)
self.assertEqual("line1\nline2", file_contents)
def testFileWriteBadMode(self):
file_path = os.path.join(self._base_dir, "temp_file")
with self.assertRaises(errors.PermissionDeniedError):
file_io.FileIO(file_path, mode="r").write("testing")
def testFileReadBadMode(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
self.assertTrue(file_io.file_exists(file_path))
with self.assertRaises(errors.PermissionDeniedError):
file_io.FileIO(file_path, mode="w").read()
def testFileDelete(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
file_io.delete_file(file_path)
self.assertFalse(file_io.file_exists(file_path))
def testFileDeleteFail(self):
file_path = os.path.join(self._base_dir, "temp_file")
with self.assertRaises(errors.NotFoundError):
file_io.delete_file(file_path)
def testGetMatchingFiles(self):
dir_path = os.path.join(self._base_dir, "temp_dir")
file_io.create_dir(dir_path)
files = ["file1.txt", "file2.txt", "file3.txt", "file*.txt"]
for name in files:
file_path = os.path.join(dir_path, name)
file_io.FileIO(file_path, mode="w").write("testing")
expected_match = [os.path.join(dir_path, name) for name in files]
self.assertItemsEqual(
file_io.get_matching_files(os.path.join(dir_path, "file*.txt")),
expected_match)
self.assertItemsEqual(file_io.get_matching_files(tuple()), [])
files_subset = [
os.path.join(dir_path, files[0]), os.path.join(dir_path, files[2])
]
self.assertItemsEqual(
file_io.get_matching_files(files_subset), files_subset)
file_io.delete_recursively(dir_path)
self.assertFalse(file_io.file_exists(os.path.join(dir_path, "file3.txt")))
def testCreateRecursiveDir(self):
dir_path = os.path.join(self._base_dir, "temp_dir/temp_dir1/temp_dir2")
file_io.recursive_create_dir(dir_path)
file_io.recursive_create_dir(dir_path) # repeat creation
file_path = os.path.join(dir_path, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
self.assertTrue(file_io.file_exists(file_path))
file_io.delete_recursively(os.path.join(self._base_dir, "temp_dir"))
self.assertFalse(file_io.file_exists(file_path))
def testCopy(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
copy_path = os.path.join(self._base_dir, "copy_file")
file_io.copy(file_path, copy_path)
self.assertTrue(file_io.file_exists(copy_path))
f = file_io.FileIO(file_path, mode="r")
self.assertEqual("testing", f.read())
self.assertEqual(7, f.tell())
def testCopyOverwrite(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
copy_path = os.path.join(self._base_dir, "copy_file")
file_io.FileIO(copy_path, mode="w").write("copy")
file_io.copy(file_path, copy_path, overwrite=True)
self.assertTrue(file_io.file_exists(copy_path))
self.assertEqual("testing", file_io.FileIO(file_path, mode="r").read())
def testCopyOverwriteFalse(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
copy_path = os.path.join(self._base_dir, "copy_file")
file_io.FileIO(copy_path, mode="w").write("copy")
with self.assertRaises(errors.AlreadyExistsError):
file_io.copy(file_path, copy_path, overwrite=False)
def testRename(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
rename_path = os.path.join(self._base_dir, "rename_file")
file_io.rename(file_path, rename_path)
self.assertTrue(file_io.file_exists(rename_path))
self.assertFalse(file_io.file_exists(file_path))
def testRenameOverwrite(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
rename_path = os.path.join(self._base_dir, "rename_file")
file_io.FileIO(rename_path, mode="w").write("rename")
file_io.rename(file_path, rename_path, overwrite=True)
self.assertTrue(file_io.file_exists(rename_path))
self.assertFalse(file_io.file_exists(file_path))
def testRenameOverwriteFalse(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
rename_path = os.path.join(self._base_dir, "rename_file")
file_io.FileIO(rename_path, mode="w").write("rename")
with self.assertRaises(errors.AlreadyExistsError):
file_io.rename(file_path, rename_path, overwrite=False)
self.assertTrue(file_io.file_exists(rename_path))
self.assertTrue(file_io.file_exists(file_path))
def testDeleteRecursivelyFail(self):
fake_dir_path = os.path.join(self._base_dir, "temp_dir")
with self.assertRaises(errors.NotFoundError):
file_io.delete_recursively(fake_dir_path)
def testIsDirectory(self):
dir_path = os.path.join(self._base_dir, "test_dir")
# Failure for a non-existing dir.
self.assertFalse(file_io.is_directory(dir_path))
file_io.create_dir(dir_path)
self.assertTrue(file_io.is_directory(dir_path))
file_path = os.path.join(dir_path, "test_file")
file_io.FileIO(file_path, mode="w").write("test")
# False for a file.
self.assertFalse(file_io.is_directory(file_path))
# Test that the value returned from `stat()` has `is_directory` set.
file_statistics = file_io.stat(dir_path)
self.assertTrue(file_statistics.is_directory)
def testListDirectory(self):
dir_path = os.path.join(self._base_dir, "test_dir")
file_io.create_dir(dir_path)
files = ["file1.txt", "file2.txt", "file3.txt"]
for name in files:
file_path = os.path.join(dir_path, name)
file_io.FileIO(file_path, mode="w").write("testing")
subdir_path = os.path.join(dir_path, "sub_dir")
file_io.create_dir(subdir_path)
subdir_file_path = os.path.join(subdir_path, "file4.txt")
file_io.FileIO(subdir_file_path, mode="w").write("testing")
dir_list = file_io.list_directory(dir_path)
self.assertItemsEqual(files + ["sub_dir"], dir_list)
def testListDirectoryFailure(self):
dir_path = os.path.join(self._base_dir, "test_dir")
with self.assertRaises(errors.NotFoundError):
file_io.list_directory(dir_path)
def _setupWalkDirectories(self, dir_path):
# Creating a file structure as follows
# test_dir -> file: file1.txt; dirs: subdir1_1, subdir1_2, subdir1_3
# subdir1_1 -> file: file3.txt
# subdir1_2 -> dir: subdir2
file_io.create_dir(dir_path)
file_io.FileIO(
os.path.join(dir_path, "file1.txt"), mode="w").write("testing")
sub_dirs1 = ["subdir1_1", "subdir1_2", "subdir1_3"]
for name in sub_dirs1:
file_io.create_dir(os.path.join(dir_path, name))
file_io.FileIO(
os.path.join(dir_path, "subdir1_1/file2.txt"),
mode="w").write("testing")
file_io.create_dir(os.path.join(dir_path, "subdir1_2/subdir2"))
def testWalkInOrder(self):
dir_path = os.path.join(self._base_dir, "test_dir")
self._setupWalkDirectories(dir_path)
# Now test the walk (in_order = True)
all_dirs = []
all_subdirs = []
all_files = []
for (w_dir, w_subdirs, w_files) in file_io.walk(dir_path, in_order=True):
all_dirs.append(w_dir)
all_subdirs.append(w_subdirs)
all_files.append(w_files)
self.assertItemsEqual(all_dirs, [dir_path] + [
os.path.join(dir_path, item)
for item in
["subdir1_1", "subdir1_2", "subdir1_2/subdir2", "subdir1_3"]
])
self.assertEqual(dir_path, all_dirs[0])
self.assertLess(
all_dirs.index(os.path.join(dir_path, "subdir1_2")),
all_dirs.index(os.path.join(dir_path, "subdir1_2/subdir2")))
self.assertItemsEqual(all_subdirs[1:5], [[], ["subdir2"], [], []])
self.assertItemsEqual(all_subdirs[0],
["subdir1_1", "subdir1_2", "subdir1_3"])
self.assertItemsEqual(all_files, [["file1.txt"], ["file2.txt"], [], [], []])
self.assertLess(
all_files.index(["file1.txt"]), all_files.index(["file2.txt"]))
def testWalkPostOrder(self):
dir_path = os.path.join(self._base_dir, "test_dir")
self._setupWalkDirectories(dir_path)
# Now test the walk (in_order = False)
all_dirs = []
all_subdirs = []
all_files = []
for (w_dir, w_subdirs, w_files) in file_io.walk(dir_path, in_order=False):
all_dirs.append(w_dir)
all_subdirs.append(w_subdirs)
all_files.append(w_files)
self.assertItemsEqual(all_dirs, [
os.path.join(dir_path, item)
for item in
["subdir1_1", "subdir1_2/subdir2", "subdir1_2", "subdir1_3"]
] + [dir_path])
self.assertEqual(dir_path, all_dirs[4])
self.assertLess(
all_dirs.index(os.path.join(dir_path, "subdir1_2/subdir2")),
all_dirs.index(os.path.join(dir_path, "subdir1_2")))
self.assertItemsEqual(all_subdirs[0:4], [[], [], ["subdir2"], []])
self.assertItemsEqual(all_subdirs[4],
["subdir1_1", "subdir1_2", "subdir1_3"])
self.assertItemsEqual(all_files, [["file2.txt"], [], [], [], ["file1.txt"]])
self.assertLess(
all_files.index(["file2.txt"]), all_files.index(["file1.txt"]))
def testWalkFailure(self):
dir_path = os.path.join(self._base_dir, "test_dir")
# Try walking a directory that wasn't created.
all_dirs = []
all_subdirs = []
all_files = []
for (w_dir, w_subdirs, w_files) in file_io.walk(dir_path, in_order=False):
all_dirs.append(w_dir)
all_subdirs.append(w_subdirs)
all_files.append(w_files)
self.assertItemsEqual(all_dirs, [])
self.assertItemsEqual(all_subdirs, [])
self.assertItemsEqual(all_files, [])
def testStat(self):
file_path = os.path.join(self._base_dir, "temp_file")
file_io.FileIO(file_path, mode="w").write("testing")
file_statistics = file_io.stat(file_path)
os_statistics = os.stat(file_path)
self.assertEqual(7, file_statistics.length)
self.assertEqual(
int(os_statistics.st_mtime), int(file_statistics.mtime_nsec / 1e9))
self.assertFalse(file_statistics.is_directory)
def testReadLine(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="r+") as f:
f.write("testing1\ntesting2\ntesting3\n\ntesting5")
self.assertEqual(36, f.size())
self.assertEqual("testing1\n", f.readline())
self.assertEqual("testing2\n", f.readline())
self.assertEqual("testing3\n", f.readline())
self.assertEqual("\n", f.readline())
self.assertEqual("testing5", f.readline())
self.assertEqual("", f.readline())
def testRead(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="r+") as f:
f.write("testing1\ntesting2\ntesting3\n\ntesting5")
self.assertEqual(36, f.size())
self.assertEqual("testing1\n", f.read(9))
self.assertEqual("testing2\n", f.read(9))
self.assertEqual("t", f.read(1))
self.assertEqual("esting3\n\ntesting5", f.read())
def testTell(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="r+") as f:
f.write("testing1\ntesting2\ntesting3\n\ntesting5")
self.assertEqual(0, f.tell())
self.assertEqual("testing1\n", f.readline())
self.assertEqual(9, f.tell())
self.assertEqual("testing2\n", f.readline())
self.assertEqual(18, f.tell())
self.assertEqual("testing3\n", f.readline())
self.assertEqual(27, f.tell())
self.assertEqual("\n", f.readline())
self.assertEqual(28, f.tell())
self.assertEqual("testing5", f.readline())
self.assertEqual(36, f.tell())
self.assertEqual("", f.readline())
self.assertEqual(36, f.tell())
def testSeek(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="r+") as f:
f.write("testing1\ntesting2\ntesting3\n\ntesting5")
self.assertEqual("testing1\n", f.readline())
self.assertEqual(9, f.tell())
# Seek to 18
f.seek(18)
self.assertEqual(18, f.tell())
self.assertEqual("testing3\n", f.readline())
# Seek back to 9
f.seek(9)
self.assertEqual(9, f.tell())
self.assertEqual("testing2\n", f.readline())
f.seek(0)
self.assertEqual(0, f.tell())
self.assertEqual("testing1\n", f.readline())
with self.assertRaises(errors.InvalidArgumentError):
f.seek(-1)
with self.assertRaises(TypeError):
f.seek()
# TODO(jhseu): Delete after position deprecation.
with self.assertRaises(TypeError):
f.seek(offset=0, position=0)
f.seek(position=9)
self.assertEqual(9, f.tell())
self.assertEqual("testing2\n", f.readline())
def testSeekFromWhat(self):
file_path = os.path.join(self._base_dir, "temp_file")
with file_io.FileIO(file_path, mode="r+") as f:
f.write("testing1\ntesting2\ntesting3\n\ntesting5")
self.assertEqual("testing1\n", f.readline())
self.assertEqual(9, f.tell())
# Seek to 18
f.seek(9, 1)
self.assertEqual(18, f.tell())
self.assertEqual("testing3\n", f.readline())
# Seek back to 9
f.seek(9, 0)
self.assertEqual(9, f.tell())
self.assertEqual("testing2\n", f.readline())
f.seek(-f.size(), 2)
self.assertEqual(0, f.tell())
self.assertEqual("testing1\n", f.readline())
with self.assertRaises(errors.InvalidArgumentError):
f.seek(0, 3)
def testReadingIterator(self):
file_path = os.path.join(self._base_dir, "temp_file")
data = ["testing1\n", "testing2\n", "testing3\n", "\n", "testing5"]
with file_io.FileIO(file_path, mode="r+") as f:
f.write("".join(data))
actual_data = []
for line in f:
actual_data.append(line)
self.assertSequenceEqual(actual_data, data)
def testReadlines(self):
file_path = os.path.join(self._base_dir, "temp_file")
data = ["testing1\n", "testing2\n", "testing3\n", "\n", "testing5"]
f = file_io.FileIO(file_path, mode="r+")
f.write("".join(data))
f.flush()
lines = f.readlines()
self.assertSequenceEqual(lines, data)
def testUTF8StringPath(self):
file_path = os.path.join(self._base_dir, "UTF8测试_file")
file_io.write_string_to_file(file_path, "testing")
with file_io.FileIO(file_path, mode="rb") as f:
self.assertEqual(b"testing", f.read())
def testEof(self):
"""Test that reading past EOF does not raise an exception."""
file_path = os.path.join(self._base_dir, "temp_file")
f = file_io.FileIO(file_path, mode="r+")
content = "testing"
f.write(content)
f.flush()
self.assertEqual(content, f.read(len(content) + 1))
def testUTF8StringPathExists(self):
file_path = os.path.join(self._base_dir, "UTF8测试_file_exist")
file_io.write_string_to_file(file_path, "testing")
v = file_io.file_exists(file_path)
self.assertEqual(v, True)
def testFilecmp(self):
file1 = os.path.join(self._base_dir, "file1")
file_io.write_string_to_file(file1, "This is a sentence\n" * 100)
file2 = os.path.join(self._base_dir, "file2")
file_io.write_string_to_file(file2, "This is another sentence\n" * 100)
file3 = os.path.join(self._base_dir, "file3")
file_io.write_string_to_file(file3, u"This is another sentence\n" * 100)
self.assertFalse(file_io.filecmp(file1, file2))
self.assertTrue(file_io.filecmp(file2, file3))
def testFilecmpSameSize(self):
file1 = os.path.join(self._base_dir, "file1")
file_io.write_string_to_file(file1, "This is a sentence\n" * 100)
file2 = os.path.join(self._base_dir, "file2")
file_io.write_string_to_file(file2, "This is b sentence\n" * 100)
file3 = os.path.join(self._base_dir, "file3")
file_io.write_string_to_file(file3, u"This is b sentence\n" * 100)
self.assertFalse(file_io.filecmp(file1, file2))
self.assertTrue(file_io.filecmp(file2, file3))
def testFilecmpBinary(self):
file1 = os.path.join(self._base_dir, "file1")
file_io.FileIO(file1, "wb").write("testing\n\na")
file2 = os.path.join(self._base_dir, "file2")
file_io.FileIO(file2, "wb").write("testing\n\nb")
file3 = os.path.join(self._base_dir, "file3")
file_io.FileIO(file3, "wb").write("testing\n\nb")
file4 = os.path.join(self._base_dir, "file4")
file_io.FileIO(file4, "wb").write("testing\n\ntesting")
self.assertFalse(file_io.filecmp(file1, file2))
self.assertFalse(file_io.filecmp(file1, file4))
self.assertTrue(file_io.filecmp(file2, file3))
def testFileCrc32(self):
file1 = os.path.join(self._base_dir, "file1")
file_io.write_string_to_file(file1, "This is a sentence\n" * 100)
crc1 = file_io.file_crc32(file1)
file2 = os.path.join(self._base_dir, "file2")
file_io.write_string_to_file(file2, "This is another sentence\n" * 100)
crc2 = file_io.file_crc32(file2)
file3 = os.path.join(self._base_dir, "file3")
file_io.write_string_to_file(file3, "This is another sentence\n" * 100)
crc3 = file_io.file_crc32(file3)
self.assertTrue(crc1 != crc2)
self.assertEqual(crc2, crc3)
def testFileCrc32WithBytes(self):
file1 = os.path.join(self._base_dir, "file1")
file_io.write_string_to_file(file1, "This is a sentence\n" * 100)
crc1 = file_io.file_crc32(file1, block_size=24)
file2 = os.path.join(self._base_dir, "file2")
file_io.write_string_to_file(file2, "This is another sentence\n" * 100)
crc2 = file_io.file_crc32(file2, block_size=24)
file3 = os.path.join(self._base_dir, "file3")
file_io.write_string_to_file(file3, "This is another sentence\n" * 100)
crc3 = file_io.file_crc32(file3, block_size=-1)
self.assertTrue(crc1 != crc2)
self.assertEqual(crc2, crc3)
def testFileCrc32Binary(self):
file1 = os.path.join(self._base_dir, "file1")
file_io.FileIO(file1, "wb").write("testing\n\n")
crc1 = file_io.file_crc32(file1)
file2 = os.path.join(self._base_dir, "file2")
file_io.FileIO(file2, "wb").write("testing\n\n\n")
crc2 = file_io.file_crc32(file2)
file3 = os.path.join(self._base_dir, "file3")
file_io.FileIO(file3, "wb").write("testing\n\n\n")
crc3 = file_io.file_crc32(file3)
self.assertTrue(crc1 != crc2)
self.assertEqual(crc2, crc3)
def testMatchingFilesPermission(self):
# Create top level directory test_dir.
dir_path = os.path.join(self._base_dir, "test_dir")
file_io.create_dir(dir_path)
# Create second level directories `noread` and `any`.
noread_path = os.path.join(dir_path, "noread")
file_io.create_dir(noread_path)
any_path = os.path.join(dir_path, "any")
file_io.create_dir(any_path)
files = ["file1.txt", "file2.txt", "file3.txt"]
for name in files:
file_path = os.path.join(any_path, name)
file_io.FileIO(file_path, mode="w").write("testing")
file_path = os.path.join(noread_path, "file4.txt")
file_io.FileIO(file_path, mode="w").write("testing")
# Change noread to noread access.
os.chmod(noread_path, 0)
expected_match = [os.path.join(any_path, name) for name in files]
self.assertItemsEqual(
file_io.get_matching_files(os.path.join(dir_path, "*", "file*.txt")),
expected_match)
# Change noread back so that it could be cleaned during tearDown.
os.chmod(noread_path, 0o777)
def testFileSeekableWithZip(self):
# Note: Test case for GitHub issue 27276, issue only exposed in python 3.7+.
filename = os.path.join(self._base_dir, "a.npz")
np.savez_compressed(filename, {"a": 1, "b": 2})
with gfile.GFile(filename, "rb") as f:
info = np.load(f, allow_pickle=True)
_ = [i for i in info.items()]
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
961,
2018,
570,
4440,
314,
2569,
2644,
26,
2774,
13,
24,
199,
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,
26237,
199,
624,
9029,
3814,
5004,
5331,
315,
570,
63,
2308,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
14,
515,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
773,
14,
2308,
492,
570,
63,
2308,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
3814,
16512,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
423,
1095,
63,
694,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
298,
1095,
63,
694,
531,
272,
570,
63,
2308,
14,
981,
63,
694,
8,
277,
423,
1095,
63,
694,
9,
819,
347,
6766,
8,
277,
304,
272,
570,
63,
2308,
14,
1807,
63,
6794,
9840,
8,
277,
423,
1095,
63,
694,
9,
819,
347,
511,
4699,
8117,
8,
277,
304,
272,
289,
275,
570,
63,
2308,
14,
26126,
12398,
818,
628,
82,
531,
272,
543,
291,
14,
1855,
8,
2550,
14,
10870,
304,
489,
485,
275,
289,
14,
739,
342,
819,
347,
511,
1173,
6586,
343,
6439,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
291,
14,
3334,
8,
493,
63,
2308,
14,
493,
63,
2444,
8,
493,
63,
515,
430,
272,
543,
291,
14,
1855,
8,
2550,
14,
10870,
304,
489,
485,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
819,
347,
511,
3534,
7756,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
4776,
531,
272,
291,
14,
1815,
8,
493,
63,
2308,
14,
493,
63,
2444,
8,
493,
63,
515,
430,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
4776,
401,
570,
63,
4407,
9,
819,
347,
511,
31931,
3534,
1558,
24320,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
4776,
531,
272,
291,
14,
1815,
8,
493,
63,
2308,
14,
493,
63,
2444,
8,
493,
63,
515,
430,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
4776,
401,
570,
63,
4407,
9,
819,
347,
511,
31931,
3534,
1558,
24320,
5674,
952,
797,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
1753,
401,
8970,
29,
797,
9,
272,
543,
291,
14,
1855,
8,
2550,
14,
16760,
23839,
304,
489,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
1222,
401,
8970,
29,
797,
9,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
1753,
401,
570,
63,
4407,
9,
272,
570,
63,
2308,
14,
1807,
63,
493,
8,
493,
63,
515,
9,
272,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
1222,
401,
8970,
29,
797,
9,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
1222,
401,
570,
63,
4407,
9,
819,
347,
511,
3284,
6636,
1385,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
4776,
531,
272,
543,
570,
63,
2308,
14,
26126,
8,
493,
63,
515,
12,
818,
628,
4848,
531,
465,
289,
26,
489,
291,
14,
629,
8,
66,
2,
4776,
401,
289,
14,
739,
1012,
819,
347,
511,
3534,
6636,
1385,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
26126,
8,
493,
63,
515,
12,
298,
6603,
3471,
952,
480,
4776,
531,
272,
543,
570,
63,
2308,
14,
26126,
8,
493,
63,
515,
12,
818,
628,
82,
531,
465,
289,
26,
489,
291,
14,
629,
480,
4776,
401,
289,
14,
739,
1012,
819,
347,
511,
8310,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14
] |
[
961,
2018,
570,
4440,
314,
2569,
2644,
26,
2774,
13,
24,
199,
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,
26237,
199,
624,
9029,
3814,
5004,
5331,
315,
570,
63,
2308,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
14,
515,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
773,
14,
2308,
492,
570,
63,
2308,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
3814,
16512,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
423,
1095,
63,
694,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
298,
1095,
63,
694,
531,
272,
570,
63,
2308,
14,
981,
63,
694,
8,
277,
423,
1095,
63,
694,
9,
819,
347,
6766,
8,
277,
304,
272,
570,
63,
2308,
14,
1807,
63,
6794,
9840,
8,
277,
423,
1095,
63,
694,
9,
819,
347,
511,
4699,
8117,
8,
277,
304,
272,
289,
275,
570,
63,
2308,
14,
26126,
12398,
818,
628,
82,
531,
272,
543,
291,
14,
1855,
8,
2550,
14,
10870,
304,
489,
485,
275,
289,
14,
739,
342,
819,
347,
511,
1173,
6586,
343,
6439,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
291,
14,
3334,
8,
493,
63,
2308,
14,
493,
63,
2444,
8,
493,
63,
515,
430,
272,
543,
291,
14,
1855,
8,
2550,
14,
10870,
304,
489,
485,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
819,
347,
511,
3534,
7756,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
4776,
531,
272,
291,
14,
1815,
8,
493,
63,
2308,
14,
493,
63,
2444,
8,
493,
63,
515,
430,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
4776,
401,
570,
63,
4407,
9,
819,
347,
511,
31931,
3534,
1558,
24320,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
4776,
531,
272,
291,
14,
1815,
8,
493,
63,
2308,
14,
493,
63,
2444,
8,
493,
63,
515,
430,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
4776,
401,
570,
63,
4407,
9,
819,
347,
511,
31931,
3534,
1558,
24320,
5674,
952,
797,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
1753,
401,
8970,
29,
797,
9,
272,
543,
291,
14,
1855,
8,
2550,
14,
16760,
23839,
304,
489,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
1222,
401,
8970,
29,
797,
9,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
1753,
401,
570,
63,
4407,
9,
272,
570,
63,
2308,
14,
1807,
63,
493,
8,
493,
63,
515,
9,
272,
570,
63,
2308,
14,
10910,
63,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
1222,
401,
8970,
29,
797,
9,
272,
570,
63,
4407,
275,
570,
63,
2308,
14,
739,
63,
493,
63,
475,
63,
875,
8,
493,
63,
515,
9,
272,
291,
14,
629,
480,
1222,
401,
570,
63,
4407,
9,
819,
347,
511,
3284,
6636,
1385,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
952,
63,
875,
63,
475,
63,
493,
8,
493,
63,
515,
12,
298,
4776,
531,
272,
543,
570,
63,
2308,
14,
26126,
8,
493,
63,
515,
12,
818,
628,
4848,
531,
465,
289,
26,
489,
291,
14,
629,
8,
66,
2,
4776,
401,
289,
14,
739,
1012,
819,
347,
511,
3534,
6636,
1385,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
1095,
63,
694,
12,
298,
808,
63,
493,
531,
272,
570,
63,
2308,
14,
26126,
8,
493,
63,
515,
12,
298,
6603,
3471,
952,
480,
4776,
531,
272,
543,
570,
63,
2308,
14,
26126,
8,
493,
63,
515,
12,
818,
628,
82,
531,
465,
289,
26,
489,
291,
14,
629,
480,
4776,
401,
289,
14,
739,
1012,
819,
347,
511,
8310,
8,
277,
304,
272,
570,
63,
515,
275,
747,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,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int
|
footprint/main/publishing/user_initialization.py
|
1
|
5524
|
# UrbanFootprint v1.5
# Copyright (C) 2017 Calthorpe Analytics
#
# This file is part of UrbanFootprint version 1.5
#
# UrbanFootprint is distributed under the terms of the GNU General
# Public License version 3, as published by the Free Software Foundation. This
# code is distributed WITHOUT ANY WARRANTY, without implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License v3 for more details; see <http://www.gnu.org/licenses/>.
import logging
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission, Group, UserManager
from tastypie.models import ApiKey
from django.conf import settings
from footprint.client.configuration.fixture import UserFixture
from footprint.main.lib.functions import get_single_value_or_create
from footprint.main.models.group_hierarchy import GroupHierarchy
__author__ = 'calthorpe_analytics'
logger = logging.getLogger(__name__)
def update_or_create_users():
from footprint.client.configuration.utils import resolve_fixture
init_fixture = resolve_fixture("user", "user", UserFixture, settings.CLIENT)
for user_configuration in init_fixture.users():
update_or_create_user(**user_configuration)
def update_or_create_group(name, config_entity=None, superiors=None):
"""
Create a group and GroupHierarchy instance. Group is the Django Group model, whereas
GroupHierarchy is a Footprint model that associates a Group to superior Groups and to
a ConfigEntity
:param name: Required name of the group
:param config_entity: Optional. Required for config_entity scoped groups. Always null
for the default groups (e.g. Admin, Directory)
:param superiors: Optional superiors to the group. All groups should have superiors except
for the Admin group
:return:
"""
group = get_single_value_or_create(
Group.objects.filter(name=name),
lambda: Group.objects.get_or_create(name=name)[0])
# Make sure the group has full permission to every model
# We limit permission on individual instances
new_permissions = set(Permission.objects.all())-set(group.permissions.all())
group.permissions.add(*new_permissions)
# Track the superiors in our special class
try:
superior_groups = map(lambda superior: Group.objects.get(name=superior), superiors or [])
except:
raise Exception("Expected groups %s to exist but only these exist: %s" %\
(superiors, Group.objects.values_list('name')))
group_hierarchy, created, updated = GroupHierarchy.objects.update_or_create(
group=group,
defaults=dict(config_entity=config_entity)
)
if not created:
group_hierarchy.superiors.clear()
for superior_group in superior_groups:
group_hierarchy.superiors.add(superior_group)
return group
def update_or_create_user(username=None, password=None, email=None, api_key=None, groups=None, is_super_user=False, first_name=None, last_name=None):
"""
Update/Create the user matching the username
:param username: the User.username
:param password: the password
:param email: the user email
:param api_key: the optional api_key, it will be generated otherwise
:param groups: The names of the groups that this user belongs to
:param is_super_user: Default false, True to make a superuser
:param first_name: the user first name
:param last_name: the user last name
:return:
"""
from footprint.main.publishing.user_publishing import on_user_post_save
logger.info("Updating or creating user %s" % username)
user_manager = get_user_model().objects
user = get_single_value_or_create(
user_manager.filter(username=username),
lambda: user_manager.create_user(username, email, password) if \
not is_super_user else \
user_manager.create_superuser(username, email, password))
# Update these in case the configuration was updated
user.email = UserManager.normalize_email(email)
if password:
user.set_password(password)
if first_name:
user.first_name = first_name
if last_name:
user.last_name = last_name
if is_super_user:
user.is_superuser = True
user.save()
# Add the user to the groups.
# Sometimes the users will reference Groups of sibling scenarios that
# haven't been created yet. In this case just create a name-only
# instance of the group.
if groups:
user.groups.clear()
for group in groups:
user.groups.add(Group.objects.get_or_create(name=group)[0])
logger.info("Assigned user %s to groups %s",
user.email,
', '.join(groups)
)
# Make sure the user has permission to update every class
# We limit permissions on individual instances
new_permissions = set(Permission.objects.all())-set(user.user_permissions.all())
user.user_permissions.add(*new_permissions)
api_key_instance = ApiKey.objects.get_or_create(user=user)[0]
if api_key and api_key_instance.key != api_key:
api_key_instance.key = api_key
api_key_instance.save()
# Invoke post-save publishing outside of footprint_init. footprint_init has a ConfigEntity-
# centric way of publishing that this would clash with
if not settings.FOOTPRINT_INIT:
on_user_post_save(sender=get_user_model(), instance=user)
return {'user': user, 'api_key': api_key_instance}
|
gpl-3.0
|
[
199,
3,
738,
4848,
290,
15563,
357,
1361,
373,
17,
14,
21,
199,
3,
1898,
334,
35,
9,
9708,
445,
6130,
269,
321,
14279,
7769,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
738,
4848,
290,
15563,
357,
1361,
1015,
413,
14,
21,
199,
3,
199,
3,
738,
4848,
290,
15563,
357,
1361,
365,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1015,
650,
12,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
961,
199,
3,
1233,
365,
1854,
2428,
1821,
3408,
12,
1928,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
199,
3,
1684,
844,
373,
19,
367,
1655,
2436,
27,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
8779,
12,
5611,
12,
2876,
2988,
199,
504,
307,
27352,
9890,
14,
992,
492,
13986,
1197,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
18913,
1361,
14,
1258,
14,
4758,
14,
5997,
492,
2876,
12812,
199,
504,
18913,
1361,
14,
973,
14,
773,
14,
5777,
492,
664,
63,
4780,
63,
585,
63,
269,
63,
981,
199,
504,
18913,
1361,
14,
973,
14,
992,
14,
923,
63,
14861,
492,
5611,
29460,
421,
199,
363,
2502,
363,
275,
283,
915,
273,
269,
321,
63,
20211,
7,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
1678,
63,
269,
63,
981,
63,
3707,
837,
272,
687,
18913,
1361,
14,
1258,
14,
4758,
14,
1208,
492,
7512,
63,
5997,
272,
4205,
63,
5997,
275,
7512,
63,
5997,
480,
751,
401,
298,
751,
401,
2876,
12812,
12,
2202,
14,
9901,
9,
272,
367,
922,
63,
4758,
315,
4205,
63,
5997,
14,
3707,
837,
267,
1678,
63,
269,
63,
981,
63,
751,
3682,
751,
63,
4758,
9,
421,
199,
318,
1678,
63,
269,
63,
981,
63,
923,
8,
354,
12,
1101,
63,
4502,
29,
403,
12,
1613,
73,
1384,
29,
403,
304,
272,
408,
267,
2790,
282,
1572,
436,
5611,
29460,
1256,
14,
5611,
365,
314,
5634,
5611,
1402,
12,
29781,
267,
5611,
29460,
365,
282,
481,
26974,
1361,
1402,
626,
4035,
2335,
282,
5611,
370,
1613,
15499,
25031,
436,
370,
267,
282,
4094,
7302,
272,
520,
635,
536,
26,
11105,
536,
402,
314,
1572,
272,
520,
635,
1101,
63,
4502,
26,
4879,
14,
11105,
367,
1101,
63,
4502,
27582,
4652,
14,
16763,
2973,
272,
367,
314,
849,
4652,
334,
69,
14,
71,
14,
9516,
12,
15191,
9,
272,
520,
635,
1613,
73,
1384,
26,
4879,
1613,
73,
1384,
370,
314,
1572,
14,
2900,
4652,
1077,
1172,
1613,
73,
1384,
871,
272,
367,
314,
9516,
1572,
272,
520,
1107,
26,
272,
408,
272,
1572,
275,
664,
63,
4780,
63,
585,
63,
269,
63,
981,
8,
267,
5611,
14,
1462,
14,
1541,
8,
354,
29,
354,
395,
267,
2400,
26,
5611,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
272,
327,
4155,
3238,
314,
1572,
965,
2615,
4983,
370,
4036,
1402,
272,
327,
2136,
2304,
4983,
641,
8212,
4454,
272,
892,
63,
6060,
275,
663,
8,
7980,
14,
1462,
14,
452,
1012,
13,
409,
8,
923,
14,
6060,
14,
452,
1012,
272,
1572,
14,
6060,
14,
525,
2031,
1222,
63,
6060,
9,
272,
327,
17507,
314,
1613,
73,
1384,
315,
4154,
4539,
1021,
272,
862,
26,
267,
1613,
15499,
63,
2634,
275,
2341,
8,
2734,
1613,
15499,
26,
5611,
14,
1462,
14,
362,
8,
354,
29,
4792,
15499,
395,
1613,
73,
1384,
503,
3073,
272,
871,
26,
267,
746,
2186,
480,
6964,
4652,
450,
83,
370,
2187,
1325,
1454,
3520,
2187,
26,
450,
83,
2,
450,
60,
1598,
334,
4792,
73,
1384,
12,
5611,
14,
1462,
14,
1459,
63,
513,
360,
354,
7058,
272,
1572,
63,
14861,
12,
2737,
12,
4588,
275,
5611,
29460,
14,
1462,
14,
873,
63,
269,
63,
981,
8,
267,
1572,
29,
923,
12,
267,
4243,
29,
807,
8,
888,
63,
4502,
29,
888,
63,
4502,
9,
272,
776,
272,
340,
440,
2737,
26,
267,
1572,
63,
14861,
14,
4792,
73,
1384,
14,
3584,
342,
272,
367,
1613,
15499,
63,
923,
315,
1613,
15499,
63,
2634,
26,
267,
1572,
63,
14861,
14,
4792,
73,
1384,
14,
525,
8,
4792,
15499,
63,
923,
9,
272,
372,
1572,
199,
199,
318,
1678,
63,
269,
63,
981,
63,
751,
8,
2473,
29,
403,
12,
2505,
29,
403,
12,
3031,
29,
403,
12,
2986,
63,
498,
29,
403,
12,
4652,
29,
403,
12,
365,
63,
4792,
63,
751,
29,
797,
12,
1642,
63,
354,
29,
403,
12,
2061,
63,
354,
29,
403,
304,
272,
408,
267,
6162,
15,
2499,
314,
922,
4877,
314,
3434,
272,
520,
635,
3434,
26,
314,
2876,
14,
2473,
272,
520,
635,
2505,
26,
314,
2505,
272,
520,
635,
3031,
26,
314,
922,
3031,
272,
520,
635,
2986,
63,
498,
26,
314,
2716,
2986,
63,
498,
12,
652,
911,
506,
4046,
4257,
272,
520,
635,
4652,
26,
710,
1561,
402,
314,
4652,
626,
642,
922,
15006,
370,
272,
520,
635,
365,
63,
4792,
63,
751,
26,
3758,
3055,
12,
715,
370,
1852,
282,
32590,
272,
520,
635,
1642,
63,
354,
26,
314,
922,
1642,
536,
272,
520,
635,
2061,
63,
354,
26,
314,
922,
2061,
536,
272,
520,
1107,
26,
272,
408,
339,
687,
18913,
1361,
14,
973,
14,
4763,
316,
14,
751,
63,
4763,
316,
492,
641,
63,
751,
63,
1932,
63,
2117,
339,
2512,
14,
815,
480,
24993,
503,
6425,
922,
450,
83,
2,
450,
3434,
9,
272,
922,
63,
2609,
275,
664,
63,
751,
63,
1238,
1252,
1462,
272,
922,
275,
664,
63,
4780,
63,
585,
63,
269,
63,
981,
8,
267,
922,
63,
2609,
14,
1541,
8,
2473,
29,
2473,
395,
267,
2400,
26,
922,
63,
2609,
14,
981,
63,
751,
8,
2473,
12,
3031,
12,
2505,
9,
340,
971,
288,
440,
365,
63,
4792,
63,
751,
587,
971,
288,
922,
63,
2609,
14,
981,
63,
11434,
8,
2473,
12,
3031,
12,
2505,
430,
2378,
327,
6162,
3520,
315,
1930,
314,
2897,
1990,
4588
] |
[
3,
738,
4848,
290,
15563,
357,
1361,
373,
17,
14,
21,
199,
3,
1898,
334,
35,
9,
9708,
445,
6130,
269,
321,
14279,
7769,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
738,
4848,
290,
15563,
357,
1361,
1015,
413,
14,
21,
199,
3,
199,
3,
738,
4848,
290,
15563,
357,
1361,
365,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1015,
650,
12,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
961,
199,
3,
1233,
365,
1854,
2428,
1821,
3408,
12,
1928,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
199,
3,
1684,
844,
373,
19,
367,
1655,
2436,
27,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
8779,
12,
5611,
12,
2876,
2988,
199,
504,
307,
27352,
9890,
14,
992,
492,
13986,
1197,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
18913,
1361,
14,
1258,
14,
4758,
14,
5997,
492,
2876,
12812,
199,
504,
18913,
1361,
14,
973,
14,
773,
14,
5777,
492,
664,
63,
4780,
63,
585,
63,
269,
63,
981,
199,
504,
18913,
1361,
14,
973,
14,
992,
14,
923,
63,
14861,
492,
5611,
29460,
421,
199,
363,
2502,
363,
275,
283,
915,
273,
269,
321,
63,
20211,
7,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
1678,
63,
269,
63,
981,
63,
3707,
837,
272,
687,
18913,
1361,
14,
1258,
14,
4758,
14,
1208,
492,
7512,
63,
5997,
272,
4205,
63,
5997,
275,
7512,
63,
5997,
480,
751,
401,
298,
751,
401,
2876,
12812,
12,
2202,
14,
9901,
9,
272,
367,
922,
63,
4758,
315,
4205,
63,
5997,
14,
3707,
837,
267,
1678,
63,
269,
63,
981,
63,
751,
3682,
751,
63,
4758,
9,
421,
199,
318,
1678,
63,
269,
63,
981,
63,
923,
8,
354,
12,
1101,
63,
4502,
29,
403,
12,
1613,
73,
1384,
29,
403,
304,
272,
408,
267,
2790,
282,
1572,
436,
5611,
29460,
1256,
14,
5611,
365,
314,
5634,
5611,
1402,
12,
29781,
267,
5611,
29460,
365,
282,
481,
26974,
1361,
1402,
626,
4035,
2335,
282,
5611,
370,
1613,
15499,
25031,
436,
370,
267,
282,
4094,
7302,
272,
520,
635,
536,
26,
11105,
536,
402,
314,
1572,
272,
520,
635,
1101,
63,
4502,
26,
4879,
14,
11105,
367,
1101,
63,
4502,
27582,
4652,
14,
16763,
2973,
272,
367,
314,
849,
4652,
334,
69,
14,
71,
14,
9516,
12,
15191,
9,
272,
520,
635,
1613,
73,
1384,
26,
4879,
1613,
73,
1384,
370,
314,
1572,
14,
2900,
4652,
1077,
1172,
1613,
73,
1384,
871,
272,
367,
314,
9516,
1572,
272,
520,
1107,
26,
272,
408,
272,
1572,
275,
664,
63,
4780,
63,
585,
63,
269,
63,
981,
8,
267,
5611,
14,
1462,
14,
1541,
8,
354,
29,
354,
395,
267,
2400,
26,
5611,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
354,
29,
354,
2788,
16,
566,
272,
327,
4155,
3238,
314,
1572,
965,
2615,
4983,
370,
4036,
1402,
272,
327,
2136,
2304,
4983,
641,
8212,
4454,
272,
892,
63,
6060,
275,
663,
8,
7980,
14,
1462,
14,
452,
1012,
13,
409,
8,
923,
14,
6060,
14,
452,
1012,
272,
1572,
14,
6060,
14,
525,
2031,
1222,
63,
6060,
9,
272,
327,
17507,
314,
1613,
73,
1384,
315,
4154,
4539,
1021,
272,
862,
26,
267,
1613,
15499,
63,
2634,
275,
2341,
8,
2734,
1613,
15499,
26,
5611,
14,
1462,
14,
362,
8,
354,
29,
4792,
15499,
395,
1613,
73,
1384,
503,
3073,
272,
871,
26,
267,
746,
2186,
480,
6964,
4652,
450,
83,
370,
2187,
1325,
1454,
3520,
2187,
26,
450,
83,
2,
450,
60,
1598,
334,
4792,
73,
1384,
12,
5611,
14,
1462,
14,
1459,
63,
513,
360,
354,
7058,
272,
1572,
63,
14861,
12,
2737,
12,
4588,
275,
5611,
29460,
14,
1462,
14,
873,
63,
269,
63,
981,
8,
267,
1572,
29,
923,
12,
267,
4243,
29,
807,
8,
888,
63,
4502,
29,
888,
63,
4502,
9,
272,
776,
272,
340,
440,
2737,
26,
267,
1572,
63,
14861,
14,
4792,
73,
1384,
14,
3584,
342,
272,
367,
1613,
15499,
63,
923,
315,
1613,
15499,
63,
2634,
26,
267,
1572,
63,
14861,
14,
4792,
73,
1384,
14,
525,
8,
4792,
15499,
63,
923,
9,
272,
372,
1572,
199,
199,
318,
1678,
63,
269,
63,
981,
63,
751,
8,
2473,
29,
403,
12,
2505,
29,
403,
12,
3031,
29,
403,
12,
2986,
63,
498,
29,
403,
12,
4652,
29,
403,
12,
365,
63,
4792,
63,
751,
29,
797,
12,
1642,
63,
354,
29,
403,
12,
2061,
63,
354,
29,
403,
304,
272,
408,
267,
6162,
15,
2499,
314,
922,
4877,
314,
3434,
272,
520,
635,
3434,
26,
314,
2876,
14,
2473,
272,
520,
635,
2505,
26,
314,
2505,
272,
520,
635,
3031,
26,
314,
922,
3031,
272,
520,
635,
2986,
63,
498,
26,
314,
2716,
2986,
63,
498,
12,
652,
911,
506,
4046,
4257,
272,
520,
635,
4652,
26,
710,
1561,
402,
314,
4652,
626,
642,
922,
15006,
370,
272,
520,
635,
365,
63,
4792,
63,
751,
26,
3758,
3055,
12,
715,
370,
1852,
282,
32590,
272,
520,
635,
1642,
63,
354,
26,
314,
922,
1642,
536,
272,
520,
635,
2061,
63,
354,
26,
314,
922,
2061,
536,
272,
520,
1107,
26,
272,
408,
339,
687,
18913,
1361,
14,
973,
14,
4763,
316,
14,
751,
63,
4763,
316,
492,
641,
63,
751,
63,
1932,
63,
2117,
339,
2512,
14,
815,
480,
24993,
503,
6425,
922,
450,
83,
2,
450,
3434,
9,
272,
922,
63,
2609,
275,
664,
63,
751,
63,
1238,
1252,
1462,
272,
922,
275,
664,
63,
4780,
63,
585,
63,
269,
63,
981,
8,
267,
922,
63,
2609,
14,
1541,
8,
2473,
29,
2473,
395,
267,
2400,
26,
922,
63,
2609,
14,
981,
63,
751,
8,
2473,
12,
3031,
12,
2505,
9,
340,
971,
288,
440,
365,
63,
4792,
63,
751,
587,
971,
288,
922,
63,
2609,
14,
981,
63,
11434,
8,
2473,
12,
3031,
12,
2505,
430,
2378,
327,
6162,
3520,
315,
1930,
314,
2897,
1990,
4588,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mttr/django
|
django/db/backends/postgresql/features.py
|
158
|
1063
|
from django.db.backends.base.features import BaseDatabaseFeatures
from django.db.utils import InterfaceError
class DatabaseFeatures(BaseDatabaseFeatures):
allows_group_by_selected_pks = True
can_return_id_from_insert = True
has_real_datatype = True
has_native_uuid_field = True
has_native_duration_field = True
driver_supports_timedelta_args = True
can_defer_constraint_checks = True
has_select_for_update = True
has_select_for_update_nowait = True
has_bulk_insert = True
uses_savepoints = True
can_release_savepoints = True
supports_tablespaces = True
supports_transactions = True
can_introspect_autofield = True
can_introspect_ip_address_field = True
can_introspect_small_integer_field = True
can_distinct_on_fields = True
can_rollback_ddl = True
supports_combined_alters = True
nulls_order_largest = True
closed_cursor_error_class = InterfaceError
has_case_insensitive_like = False
requires_sqlparse_for_splitting = False
greatest_least_ignores_nulls = True
|
bsd-3-clause
|
[
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
3179,
492,
29103,
10807,
199,
504,
1639,
14,
697,
14,
1208,
492,
14816,
547,
421,
199,
533,
8692,
10807,
8,
1563,
7243,
10807,
304,
272,
6127,
63,
923,
63,
991,
63,
5511,
63,
27323,
275,
715,
272,
883,
63,
1107,
63,
344,
63,
504,
63,
3176,
275,
715,
272,
965,
63,
3093,
63,
14184,
275,
715,
272,
965,
63,
6106,
63,
2580,
63,
698,
275,
715,
272,
965,
63,
6106,
63,
5553,
63,
698,
275,
715,
272,
5253,
63,
9823,
63,
7473,
63,
589,
275,
715,
272,
883,
63,
11610,
63,
5631,
63,
8625,
275,
715,
272,
965,
63,
2416,
63,
509,
63,
873,
275,
715,
272,
965,
63,
2416,
63,
509,
63,
873,
63,
20870,
275,
715,
272,
965,
63,
9377,
63,
3176,
275,
715,
272,
4440,
63,
2117,
3438,
275,
715,
272,
883,
63,
3221,
63,
2117,
3438,
275,
715,
272,
5171,
63,
1224,
10749,
275,
715,
272,
5171,
63,
13754,
275,
715,
272,
883,
63,
29553,
63,
2495,
698,
275,
715,
272,
883,
63,
29553,
63,
711,
63,
1562,
63,
698,
275,
715,
272,
883,
63,
29553,
63,
7241,
63,
4115,
63,
698,
275,
715,
272,
883,
63,
12926,
63,
265,
63,
955,
275,
715,
272,
883,
63,
10437,
63,
17102,
275,
715,
272,
5171,
63,
17583,
63,
31185,
275,
715,
272,
302,
13072,
63,
1648,
63,
9828,
3199,
275,
715,
272,
6876,
63,
3937,
63,
705,
63,
533,
275,
14816,
547,
272,
965,
63,
2546,
63,
15851,
63,
2930,
275,
756,
272,
5074,
63,
3009,
1122,
63,
509,
63,
1294,
1337,
275,
756,
272,
486,
622,
270,
63,
11790,
63,
11050,
470,
63,
24976,
275,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
697,
14,
7765,
14,
1095,
14,
3179,
492,
29103,
10807,
199,
504,
1639,
14,
697,
14,
1208,
492,
14816,
547,
421,
199,
533,
8692,
10807,
8,
1563,
7243,
10807,
304,
272,
6127,
63,
923,
63,
991,
63,
5511,
63,
27323,
275,
715,
272,
883,
63,
1107,
63,
344,
63,
504,
63,
3176,
275,
715,
272,
965,
63,
3093,
63,
14184,
275,
715,
272,
965,
63,
6106,
63,
2580,
63,
698,
275,
715,
272,
965,
63,
6106,
63,
5553,
63,
698,
275,
715,
272,
5253,
63,
9823,
63,
7473,
63,
589,
275,
715,
272,
883,
63,
11610,
63,
5631,
63,
8625,
275,
715,
272,
965,
63,
2416,
63,
509,
63,
873,
275,
715,
272,
965,
63,
2416,
63,
509,
63,
873,
63,
20870,
275,
715,
272,
965,
63,
9377,
63,
3176,
275,
715,
272,
4440,
63,
2117,
3438,
275,
715,
272,
883,
63,
3221,
63,
2117,
3438,
275,
715,
272,
5171,
63,
1224,
10749,
275,
715,
272,
5171,
63,
13754,
275,
715,
272,
883,
63,
29553,
63,
2495,
698,
275,
715,
272,
883,
63,
29553,
63,
711,
63,
1562,
63,
698,
275,
715,
272,
883,
63,
29553,
63,
7241,
63,
4115,
63,
698,
275,
715,
272,
883,
63,
12926,
63,
265,
63,
955,
275,
715,
272,
883,
63,
10437,
63,
17102,
275,
715,
272,
5171,
63,
17583,
63,
31185,
275,
715,
272,
302,
13072,
63,
1648,
63,
9828,
3199,
275,
715,
272,
6876,
63,
3937,
63,
705,
63,
533,
275,
14816,
547,
272,
965,
63,
2546,
63,
15851,
63,
2930,
275,
756,
272,
5074,
63,
3009,
1122,
63,
509,
63,
1294,
1337,
275,
756,
272,
486,
622,
270,
63,
11790,
63,
11050,
470,
63,
24976,
275,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SurfasJones/icecream-info
|
icecream/lib/python2.7/site-packages/pip/backwardcompat/__init__.py
|
394
|
3756
|
"""Stuff that differs in different Python versions and platform
distributions."""
import os
import imp
import sys
import site
__all__ = ['WindowsError']
uses_pycache = hasattr(imp, 'cache_from_source')
class NeverUsedException(Exception):
"""this exception should never be raised"""
try:
WindowsError = WindowsError
except NameError:
WindowsError = NeverUsedException
try:
#new in Python 3.3
PermissionError = PermissionError
except NameError:
PermissionError = NeverUsedException
console_encoding = sys.__stdout__.encoding
if sys.version_info >= (3,):
from io import StringIO, BytesIO
from functools import reduce
from urllib.error import URLError, HTTPError
from queue import Queue, Empty
from urllib.request import url2pathname, urlretrieve, pathname2url
from email import message as emailmessage
import urllib.parse as urllib
import urllib.request as urllib2
import configparser as ConfigParser
import xmlrpc.client as xmlrpclib
import urllib.parse as urlparse
import http.client as httplib
def cmp(a, b):
return (a > b) - (a < b)
def b(s):
return s.encode('utf-8')
def u(s):
return s.decode('utf-8')
def console_to_str(s):
try:
return s.decode(console_encoding)
except UnicodeDecodeError:
return s.decode('utf_8')
def get_http_message_param(http_message, param, default_value):
return http_message.get_param(param, default_value)
bytes = bytes
string_types = (str,)
raw_input = input
else:
from cStringIO import StringIO
from urllib2 import URLError, HTTPError
from Queue import Queue, Empty
from urllib import url2pathname, urlretrieve, pathname2url
from email import Message as emailmessage
import urllib
import urllib2
import urlparse
import ConfigParser
import xmlrpclib
import httplib
def b(s):
return s
def u(s):
return s
def console_to_str(s):
return s
def get_http_message_param(http_message, param, default_value):
result = http_message.getparam(param)
return result or default_value
bytes = str
string_types = (basestring,)
reduce = reduce
cmp = cmp
raw_input = raw_input
BytesIO = StringIO
from distutils.sysconfig import get_python_lib, get_python_version
#site.USER_SITE was created in py2.6
user_site = getattr(site, 'USER_SITE', None)
def product(*args, **kwds):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = list(map(tuple, args)) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x + [y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
def get_path_uid(path):
"""
Return path's uid.
Does not follow symlinks: https://github.com/pypa/pip/pull/935#discussion_r5307003
Placed this function in backwardcompat due to differences on AIX and Jython,
that should eventually go away.
:raises OSError: When path is a symlink or can't be read.
"""
if hasattr(os, 'O_NOFOLLOW'):
fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)
file_uid = os.fstat(fd).st_uid
os.close(fd)
else: # AIX and Jython
# WARNING: time of check vulnerabity, but best we can do w/o NOFOLLOW
if not os.path.islink(path):
# older versions of Jython don't have `os.fstat`
file_uid = os.stat(path).st_uid
else:
# raise OSError for parity with os.O_NOFOLLOW above
raise OSError("%s is a symlink; Will not return uid for symlinks" % path)
return file_uid
|
mit
|
[
624,
933,
3043,
626,
22754,
315,
3365,
2018,
5459,
436,
4298,
199,
5613,
1041,
199,
199,
646,
747,
199,
646,
1742,
199,
646,
984,
199,
646,
4770,
199,
199,
363,
452,
363,
275,
788,
8647,
547,
418,
199,
199,
5589,
63,
647,
1637,
275,
2688,
8,
3236,
12,
283,
1637,
63,
504,
63,
1365,
358,
199,
199,
533,
5612,
422,
9167,
1726,
8,
1726,
304,
272,
408,
3749,
1919,
1077,
7078,
506,
4915,
624,
199,
199,
893,
26,
272,
23950,
275,
23950,
199,
2590,
12746,
26,
272,
23950,
275,
5612,
422,
9167,
1726,
199,
199,
893,
26,
272,
327,
1222,
315,
2018,
650,
14,
19,
272,
8779,
547,
275,
8779,
547,
199,
2590,
12746,
26,
272,
8779,
547,
275,
5612,
422,
9167,
1726,
199,
199,
6614,
63,
2991,
275,
984,
855,
2703,
4343,
2991,
199,
199,
692,
984,
14,
1023,
63,
815,
2356,
334,
19,
16095,
272,
687,
5890,
492,
5228,
12,
11808,
272,
687,
9143,
492,
7114,
272,
687,
4011,
14,
705,
492,
30794,
12,
15050,
272,
687,
4126,
492,
10703,
12,
9630,
272,
687,
4011,
14,
1069,
492,
1166,
18,
12445,
12,
1166,
14270,
12,
11776,
18,
633,
272,
687,
3031,
492,
1245,
465,
3031,
1188,
272,
492,
4011,
14,
1122,
465,
4011,
272,
492,
4011,
14,
1069,
465,
4011,
18,
272,
492,
21230,
465,
14196,
272,
492,
15432,
14,
1258,
465,
19122,
272,
492,
4011,
14,
1122,
465,
7097,
272,
492,
1455,
14,
1258,
465,
8809,
339,
347,
10467,
8,
65,
12,
330,
304,
267,
372,
334,
65,
690,
330,
9,
446,
334,
65,
665,
330,
9,
339,
347,
330,
8,
83,
304,
267,
372,
308,
14,
2143,
360,
1624,
13,
24,
358,
339,
347,
399,
8,
83,
304,
267,
372,
308,
14,
2708,
360,
1624,
13,
24,
358,
339,
347,
8559,
63,
475,
63,
495,
8,
83,
304,
267,
862,
26,
288,
372,
308,
14,
2708,
8,
6614,
63,
2991,
9,
267,
871,
18965,
26,
288,
372,
308,
14,
2708,
360,
1624,
63,
24,
358,
339,
347,
664,
63,
1014,
63,
1188,
63,
635,
8,
1014,
63,
1188,
12,
1215,
12,
849,
63,
585,
304,
267,
372,
1455,
63,
1188,
14,
362,
63,
635,
8,
635,
12,
849,
63,
585,
9,
339,
2783,
275,
2783,
272,
1059,
63,
1313,
275,
334,
495,
4258,
272,
3066,
63,
1210,
275,
1324,
199,
2836,
26,
272,
687,
15073,
492,
5228,
272,
687,
4011,
18,
492,
30794,
12,
15050,
272,
687,
10703,
492,
10703,
12,
9630,
272,
687,
4011,
492,
1166,
18,
12445,
12,
1166,
14270,
12,
11776,
18,
633,
272,
687,
3031,
492,
6430,
465,
3031,
1188,
272,
492,
4011,
272,
492,
4011,
18,
272,
492,
7097,
272,
492,
14196,
272,
492,
19122,
272,
492,
8809,
339,
347,
330,
8,
83,
304,
267,
372,
308,
339,
347,
399,
8,
83,
304,
267,
372,
308,
339,
347,
8559,
63,
475,
63,
495,
8,
83,
304,
267,
372,
308,
339,
347,
664,
63,
1014,
63,
1188,
63,
635,
8,
1014,
63,
1188,
12,
1215,
12,
849,
63,
585,
304,
267,
754,
275,
1455,
63,
1188,
14,
362,
635,
8,
635,
9,
267,
372,
754,
503,
849,
63,
585,
339,
2783,
275,
620,
272,
1059,
63,
1313,
275,
334,
17628,
4258,
272,
7114,
275,
7114,
272,
10467,
275,
10467,
272,
3066,
63,
1210,
275,
3066,
63,
1210,
272,
11808,
275,
5228,
421,
199,
504,
7065,
14,
24030,
492,
664,
63,
1548,
63,
773,
12,
664,
63,
1548,
63,
1023,
199,
199,
3,
2124,
14,
3791,
63,
7917,
1990,
2737,
315,
1134,
18,
14,
22,
199,
751,
63,
2124,
275,
2519,
8,
2124,
12,
283,
3791,
63,
7917,
297,
488,
9,
421,
199,
318,
3336,
2031,
589,
12,
1011,
10340,
304,
272,
327,
3336,
360,
31578,
297,
283,
1702,
358,
10541,
437,
88,
437,
89,
699,
88,
4885,
445,
88,
18461,
577,
88,
577,
89,
272,
327,
3336,
8,
1842,
8,
18,
395,
11982,
29,
19,
9,
10541,
21551,
378,
614,
378,
709,
378,
845,
2948,
14313,
16814,
20128,
272,
20092,
275,
769,
8,
1130,
8,
2960,
12,
1249,
430,
627,
16286,
14,
362,
360,
8755,
297,
413,
9,
272,
754,
275,
3474,
2677,
272,
367,
4203,
315,
20092,
26,
267,
754,
275,
359,
88,
435,
359,
89,
61,
367,
671,
315,
754,
367,
612,
315,
4203,
61,
272,
367,
12441,
315,
754,
26,
267,
1995,
2008,
8,
8788,
9,
421,
199,
318,
664,
63,
515,
63,
1535,
8,
515,
304,
272,
408,
272,
1432,
931,
1159,
1747,
14,
339,
12078,
440,
2035,
19891,
26,
4178,
921,
5031,
14,
957,
15,
647,
387,
15,
9983,
15,
9302,
15,
32258,
3,
14410,
63,
82,
21,
11516,
8262,
339,
10902,
68,
642,
805,
315,
13388,
5819,
7037,
370,
15109,
641,
437,
3867,
436,
25333,
12,
272,
626,
1077,
21356,
2621,
13437,
14,
339,
520,
3536,
6440,
26,
3979,
931,
365,
282,
15296,
503,
883,
1133,
506,
1586,
14,
272,
408,
272,
340,
2688,
8,
736,
12,
283,
47,
63,
2826,
38,
29905,
735,
267,
6111,
275,
747,
14,
1490,
8,
515,
12,
747,
14,
47,
63,
15543,
10452,
1204,
747,
14,
47,
63,
2826,
38,
29905,
9,
267,
570,
63,
1535,
275,
747,
14,
32127,
8,
2592,
680,
270,
63,
1535,
267,
747,
14,
1600,
8,
2592,
9,
272,
587,
26,
221,
327,
437,
3867,
436,
25333,
267,
327,
14750,
26,
900,
402,
1104,
373,
21406,
371,
1209,
12,
1325,
5526,
781,
883,
886,
336,
15,
79,
653,
3359,
29905,
267,
340,
440,
747,
14,
515,
14,
20719,
8,
515,
304,
288,
327,
12731,
5459,
402,
25333,
2793,
1133,
1172,
658,
736,
14,
32127,
64,
288,
570,
63,
1535,
275,
747,
14,
3736,
8,
515,
680,
270,
63,
1535,
267,
587,
26,
288,
327,
746,
6440,
367,
623,
1209,
543,
747,
14,
47,
63,
2826,
38,
29905,
3432,
288,
746,
6440,
3647,
83,
365,
282,
15296,
27,
12823,
440,
372,
1747,
367,
19891,
2,
450,
931,
9,
272,
372,
570,
63,
1535,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
933,
3043,
626,
22754,
315,
3365,
2018,
5459,
436,
4298,
199,
5613,
1041,
199,
199,
646,
747,
199,
646,
1742,
199,
646,
984,
199,
646,
4770,
199,
199,
363,
452,
363,
275,
788,
8647,
547,
418,
199,
199,
5589,
63,
647,
1637,
275,
2688,
8,
3236,
12,
283,
1637,
63,
504,
63,
1365,
358,
199,
199,
533,
5612,
422,
9167,
1726,
8,
1726,
304,
272,
408,
3749,
1919,
1077,
7078,
506,
4915,
624,
199,
199,
893,
26,
272,
23950,
275,
23950,
199,
2590,
12746,
26,
272,
23950,
275,
5612,
422,
9167,
1726,
199,
199,
893,
26,
272,
327,
1222,
315,
2018,
650,
14,
19,
272,
8779,
547,
275,
8779,
547,
199,
2590,
12746,
26,
272,
8779,
547,
275,
5612,
422,
9167,
1726,
199,
199,
6614,
63,
2991,
275,
984,
855,
2703,
4343,
2991,
199,
199,
692,
984,
14,
1023,
63,
815,
2356,
334,
19,
16095,
272,
687,
5890,
492,
5228,
12,
11808,
272,
687,
9143,
492,
7114,
272,
687,
4011,
14,
705,
492,
30794,
12,
15050,
272,
687,
4126,
492,
10703,
12,
9630,
272,
687,
4011,
14,
1069,
492,
1166,
18,
12445,
12,
1166,
14270,
12,
11776,
18,
633,
272,
687,
3031,
492,
1245,
465,
3031,
1188,
272,
492,
4011,
14,
1122,
465,
4011,
272,
492,
4011,
14,
1069,
465,
4011,
18,
272,
492,
21230,
465,
14196,
272,
492,
15432,
14,
1258,
465,
19122,
272,
492,
4011,
14,
1122,
465,
7097,
272,
492,
1455,
14,
1258,
465,
8809,
339,
347,
10467,
8,
65,
12,
330,
304,
267,
372,
334,
65,
690,
330,
9,
446,
334,
65,
665,
330,
9,
339,
347,
330,
8,
83,
304,
267,
372,
308,
14,
2143,
360,
1624,
13,
24,
358,
339,
347,
399,
8,
83,
304,
267,
372,
308,
14,
2708,
360,
1624,
13,
24,
358,
339,
347,
8559,
63,
475,
63,
495,
8,
83,
304,
267,
862,
26,
288,
372,
308,
14,
2708,
8,
6614,
63,
2991,
9,
267,
871,
18965,
26,
288,
372,
308,
14,
2708,
360,
1624,
63,
24,
358,
339,
347,
664,
63,
1014,
63,
1188,
63,
635,
8,
1014,
63,
1188,
12,
1215,
12,
849,
63,
585,
304,
267,
372,
1455,
63,
1188,
14,
362,
63,
635,
8,
635,
12,
849,
63,
585,
9,
339,
2783,
275,
2783,
272,
1059,
63,
1313,
275,
334,
495,
4258,
272,
3066,
63,
1210,
275,
1324,
199,
2836,
26,
272,
687,
15073,
492,
5228,
272,
687,
4011,
18,
492,
30794,
12,
15050,
272,
687,
10703,
492,
10703,
12,
9630,
272,
687,
4011,
492,
1166,
18,
12445,
12,
1166,
14270,
12,
11776,
18,
633,
272,
687,
3031,
492,
6430,
465,
3031,
1188,
272,
492,
4011,
272,
492,
4011,
18,
272,
492,
7097,
272,
492,
14196,
272,
492,
19122,
272,
492,
8809,
339,
347,
330,
8,
83,
304,
267,
372,
308,
339,
347,
399,
8,
83,
304,
267,
372,
308,
339,
347,
8559,
63,
475,
63,
495,
8,
83,
304,
267,
372,
308,
339,
347,
664,
63,
1014,
63,
1188,
63,
635,
8,
1014,
63,
1188,
12,
1215,
12,
849,
63,
585,
304,
267,
754,
275,
1455,
63,
1188,
14,
362,
635,
8,
635,
9,
267,
372,
754,
503,
849,
63,
585,
339,
2783,
275,
620,
272,
1059,
63,
1313,
275,
334,
17628,
4258,
272,
7114,
275,
7114,
272,
10467,
275,
10467,
272,
3066,
63,
1210,
275,
3066,
63,
1210,
272,
11808,
275,
5228,
421,
199,
504,
7065,
14,
24030,
492,
664,
63,
1548,
63,
773,
12,
664,
63,
1548,
63,
1023,
199,
199,
3,
2124,
14,
3791,
63,
7917,
1990,
2737,
315,
1134,
18,
14,
22,
199,
751,
63,
2124,
275,
2519,
8,
2124,
12,
283,
3791,
63,
7917,
297,
488,
9,
421,
199,
318,
3336,
2031,
589,
12,
1011,
10340,
304,
272,
327,
3336,
360,
31578,
297,
283,
1702,
358,
10541,
437,
88,
437,
89,
699,
88,
4885,
445,
88,
18461,
577,
88,
577,
89,
272,
327,
3336,
8,
1842,
8,
18,
395,
11982,
29,
19,
9,
10541,
21551,
378,
614,
378,
709,
378,
845,
2948,
14313,
16814,
20128,
272,
20092,
275,
769,
8,
1130,
8,
2960,
12,
1249,
430,
627,
16286,
14,
362,
360,
8755,
297,
413,
9,
272,
754,
275,
3474,
2677,
272,
367,
4203,
315,
20092,
26,
267,
754,
275,
359,
88,
435,
359,
89,
61,
367,
671,
315,
754,
367,
612,
315,
4203,
61,
272,
367,
12441,
315,
754,
26,
267,
1995,
2008,
8,
8788,
9,
421,
199,
318,
664,
63,
515,
63,
1535,
8,
515,
304,
272,
408,
272,
1432,
931,
1159,
1747,
14,
339,
12078,
440,
2035,
19891,
26,
4178,
921,
5031,
14,
957,
15,
647,
387,
15,
9983,
15,
9302,
15,
32258,
3,
14410,
63,
82,
21,
11516,
8262,
339,
10902,
68,
642,
805,
315,
13388,
5819,
7037,
370,
15109,
641,
437,
3867,
436,
25333,
12,
272,
626,
1077,
21356,
2621,
13437,
14,
339,
520,
3536,
6440,
26,
3979,
931,
365,
282,
15296,
503,
883,
1133,
506,
1586,
14,
272,
408,
272,
340,
2688,
8,
736,
12,
283,
47,
63,
2826,
38,
29905,
735,
267,
6111,
275,
747,
14,
1490,
8,
515,
12,
747,
14,
47,
63,
15543,
10452,
1204,
747,
14,
47,
63,
2826,
38,
29905,
9,
267,
570,
63,
1535,
275,
747,
14,
32127,
8,
2592,
680,
270,
63,
1535,
267,
747,
14,
1600,
8,
2592,
9,
272,
587,
26,
221,
327,
437,
3867,
436,
25333,
267,
327,
14750,
26,
900,
402,
1104,
373,
21406,
371,
1209,
12,
1325,
5526,
781,
883,
886,
336,
15,
79,
653,
3359,
29905,
267,
340,
440,
747,
14,
515,
14,
20719,
8,
515,
304,
288,
327,
12731,
5459,
402,
25333,
2793,
1133,
1172,
658,
736,
14,
32127,
64,
288,
570,
63,
1535,
275,
747,
14,
3736,
8,
515,
680,
270,
63,
1535,
267,
587,
26,
288,
327,
746,
6440,
367,
623,
1209,
543,
747,
14,
47,
63,
2826,
38,
29905,
3432,
288,
746,
6440,
3647,
83,
365,
282,
15296,
27,
12823,
440,
372,
1747,
367,
19891,
2,
450,
931,
9,
272,
372,
570,
63,
1535,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BhupeshGupta/erpnext
|
erpnext/manufacturing/doctype/production_order/test_production_order.py
|
7
|
2388
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import unittest
import frappe
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
from erpnext.manufacturing.doctype.production_order.production_order import make_stock_entry
from erpnext.stock.doctype.stock_entry import test_stock_entry
class TestProductionOrder(unittest.TestCase):
def check_planned_qty(self):
set_perpetual_inventory(0)
planned0 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") or 0
pro_doc = frappe.copy_doc(test_records[0])
pro_doc.insert()
pro_doc.submit()
# add raw materials to stores
test_stock_entry.make_stock_entry("_Test Item", None, "Stores - _TC", 100, 100)
test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "Stores - _TC", 100, 100)
# from stores to wip
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4))
for d in s.get("mtn_details"):
d.s_warehouse = "Stores - _TC"
s.fiscal_year = "_Test Fiscal Year 2013"
s.posting_date = "2013-01-02"
s.insert()
s.submit()
# from wip to fg
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 4))
s.fiscal_year = "_Test Fiscal Year 2013"
s.posting_date = "2013-01-03"
s.insert()
s.submit()
self.assertEqual(frappe.db.get_value("Production Order", pro_doc.name,
"produced_qty"), 4)
planned1 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty")
self.assertEqual(planned1 - planned0, 6)
return pro_doc
def test_over_production(self):
from erpnext.manufacturing.doctype.production_order.production_order import StockOverProductionError
pro_doc = self.check_planned_qty()
test_stock_entry.make_stock_entry("_Test Item", None, "_Test Warehouse - _TC", 100, 100)
test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "_Test Warehouse - _TC", 100, 100)
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 7))
s.fiscal_year = "_Test Fiscal Year 2013"
s.posting_date = "2013-01-04"
s.insert()
self.assertRaises(StockOverProductionError, s.submit)
test_records = frappe.get_test_records('Production Order')
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
421,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2882,
199,
646,
6950,
199,
504,
29106,
14,
6088,
14,
6356,
14,
9533,
63,
18905,
14,
396,
63,
9533,
63,
18905,
492,
663,
63,
529,
321,
1688,
63,
7212,
199,
504,
29106,
14,
1237,
7415,
319,
4039,
14,
6356,
14,
10777,
63,
1648,
14,
10777,
63,
1648,
492,
1852,
63,
6088,
63,
2373,
199,
504,
29106,
14,
6088,
14,
6356,
14,
6088,
63,
2373,
492,
511,
63,
6088,
63,
2373,
199,
199,
533,
1379,
26432,
4738,
8,
2796,
14,
1746,
304,
199,
198,
318,
1104,
63,
20235,
63,
5643,
8,
277,
304,
507,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
16,
9,
2742,
198,
20235,
16,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
13394,
401,
2420,
1053,
63,
600,
582,
2668,
774,
481,
39,
7020,
401,
298,
12806,
582,
2668,
774,
644,
11499,
413,
446,
485,
5708,
6018,
298,
20235,
63,
5643,
531,
503,
378,
2742,
198,
496,
63,
1301,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
16,
566,
507,
198,
496,
63,
1301,
14,
3176,
342,
507,
198,
496,
63,
1301,
14,
7275,
342,
2742,
198,
3,
1050,
3066,
8418,
370,
14086,
507,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
401,
488,
12,
298,
4759,
470,
446,
485,
5708,
401,
2948,
12,
2948,
9,
507,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
14621,
8055,
17827,
2948,
401,
488,
12,
298,
4759,
470,
446,
485,
5708,
401,
2948,
12,
2948,
9,
2742,
198,
3,
687,
14086,
370,
336,
711,
507,
198,
83,
275,
6950,
14,
362,
63,
1301,
8,
1875,
63,
6088,
63,
2373,
8,
496,
63,
1301,
14,
354,
12,
298,
15787,
27507,
401,
841,
430,
507,
198,
509,
366,
315,
308,
14,
362,
480,
2037,
78,
63,
5087,
2349,
686,
198,
68,
14,
83,
63,
12806,
275,
298,
4759,
470,
446,
485,
5708,
2,
507,
198,
83,
14,
18646,
63,
3403,
275,
2668,
774,
481,
15734,
28497,
6171,
2,
507,
198,
83,
14,
23980,
63,
602,
275,
298,
6965,
13,
614,
13,
996,
2,
507,
198,
83,
14,
3176,
342,
507,
198,
83,
14,
7275,
342,
2742,
198,
3,
687,
336,
711,
370,
16587,
507,
198,
83,
275,
6950,
14,
362,
63,
1301,
8,
1875,
63,
6088,
63,
2373,
8,
496,
63,
1301,
14,
354,
12,
298,
2395,
17391,
401,
841,
430,
507,
198,
83,
14,
18646,
63,
3403,
275,
2668,
774,
481,
15734,
28497,
6171,
2,
507,
198,
83,
14,
23980,
63,
602,
275,
298,
6965,
13,
614,
13,
1644,
2,
507,
198,
83,
14,
3176,
342,
507,
198,
83,
14,
7275,
342,
2742,
198,
277,
14,
629,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
26432,
9240,
401,
557,
63,
1301,
14,
354,
12,
686,
198,
2,
7832,
68,
63,
5643,
1288,
841,
9,
507,
198,
20235,
17,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
13394,
401,
2420,
1053,
63,
600,
582,
2668,
774,
481,
39,
7020,
401,
298,
12806,
582,
2668,
774,
644,
11499,
413,
446,
485,
5708,
6018,
298,
20235,
63,
5643,
531,
507,
198,
277,
14,
629,
8,
20235,
17,
446,
1620,
9386,
16,
12,
1227,
9,
2742,
198,
1107,
557,
63,
1301,
421,
198,
318,
511,
63,
1883,
63,
10777,
8,
277,
304,
507,
198,
504,
29106,
14,
1237,
7415,
319,
4039,
14,
6356,
14,
10777,
63,
1648,
14,
10777,
63,
1648,
492,
28406,
5674,
26432,
547,
507,
198,
496,
63,
1301,
275,
291,
14,
1074,
63,
20235,
63,
5643,
342,
2742,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
401,
488,
12,
2668,
774,
644,
11499,
446,
485,
5708,
401,
2948,
12,
2948,
9,
507,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
14621,
8055,
17827,
2948,
401,
488,
12,
2668,
774,
644,
11499,
446,
485,
5708,
401,
2948,
12,
2948,
9,
2742,
198,
83,
275,
6950,
14,
362,
63,
1301,
8,
1875,
63,
6088,
63,
2373,
8,
496,
63,
1301,
14,
354,
12,
298,
2395,
17391,
401,
1520,
430,
507,
198,
83,
14,
18646,
63,
3403,
275,
2668,
774,
481,
15734,
28497,
6171,
2,
507,
198,
83,
14,
23980,
63,
602,
275,
298,
6965,
13,
614,
13,
966,
2,
507,
198,
83,
14,
3176,
342,
2742,
198,
277,
14,
1855,
8,
17103,
5674,
26432,
547,
12,
308,
14,
7275,
9,
199,
199,
396,
63,
6502,
275,
6950,
14,
362,
63,
396,
63,
6502,
360,
26432,
9240,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
421,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2882,
199,
646,
6950,
199,
504,
29106,
14,
6088,
14,
6356,
14,
9533,
63,
18905,
14,
396,
63,
9533,
63,
18905,
492,
663,
63,
529,
321,
1688,
63,
7212,
199,
504,
29106,
14,
1237,
7415,
319,
4039,
14,
6356,
14,
10777,
63,
1648,
14,
10777,
63,
1648,
492,
1852,
63,
6088,
63,
2373,
199,
504,
29106,
14,
6088,
14,
6356,
14,
6088,
63,
2373,
492,
511,
63,
6088,
63,
2373,
199,
199,
533,
1379,
26432,
4738,
8,
2796,
14,
1746,
304,
199,
198,
318,
1104,
63,
20235,
63,
5643,
8,
277,
304,
507,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
16,
9,
2742,
198,
20235,
16,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
13394,
401,
2420,
1053,
63,
600,
582,
2668,
774,
481,
39,
7020,
401,
298,
12806,
582,
2668,
774,
644,
11499,
413,
446,
485,
5708,
6018,
298,
20235,
63,
5643,
531,
503,
378,
2742,
198,
496,
63,
1301,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
16,
566,
507,
198,
496,
63,
1301,
14,
3176,
342,
507,
198,
496,
63,
1301,
14,
7275,
342,
2742,
198,
3,
1050,
3066,
8418,
370,
14086,
507,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
401,
488,
12,
298,
4759,
470,
446,
485,
5708,
401,
2948,
12,
2948,
9,
507,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
14621,
8055,
17827,
2948,
401,
488,
12,
298,
4759,
470,
446,
485,
5708,
401,
2948,
12,
2948,
9,
2742,
198,
3,
687,
14086,
370,
336,
711,
507,
198,
83,
275,
6950,
14,
362,
63,
1301,
8,
1875,
63,
6088,
63,
2373,
8,
496,
63,
1301,
14,
354,
12,
298,
15787,
27507,
401,
841,
430,
507,
198,
509,
366,
315,
308,
14,
362,
480,
2037,
78,
63,
5087,
2349,
686,
198,
68,
14,
83,
63,
12806,
275,
298,
4759,
470,
446,
485,
5708,
2,
507,
198,
83,
14,
18646,
63,
3403,
275,
2668,
774,
481,
15734,
28497,
6171,
2,
507,
198,
83,
14,
23980,
63,
602,
275,
298,
6965,
13,
614,
13,
996,
2,
507,
198,
83,
14,
3176,
342,
507,
198,
83,
14,
7275,
342,
2742,
198,
3,
687,
336,
711,
370,
16587,
507,
198,
83,
275,
6950,
14,
362,
63,
1301,
8,
1875,
63,
6088,
63,
2373,
8,
496,
63,
1301,
14,
354,
12,
298,
2395,
17391,
401,
841,
430,
507,
198,
83,
14,
18646,
63,
3403,
275,
2668,
774,
481,
15734,
28497,
6171,
2,
507,
198,
83,
14,
23980,
63,
602,
275,
298,
6965,
13,
614,
13,
1644,
2,
507,
198,
83,
14,
3176,
342,
507,
198,
83,
14,
7275,
342,
2742,
198,
277,
14,
629,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
26432,
9240,
401,
557,
63,
1301,
14,
354,
12,
686,
198,
2,
7832,
68,
63,
5643,
1288,
841,
9,
507,
198,
20235,
17,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
13394,
401,
2420,
1053,
63,
600,
582,
2668,
774,
481,
39,
7020,
401,
298,
12806,
582,
2668,
774,
644,
11499,
413,
446,
485,
5708,
6018,
298,
20235,
63,
5643,
531,
507,
198,
277,
14,
629,
8,
20235,
17,
446,
1620,
9386,
16,
12,
1227,
9,
2742,
198,
1107,
557,
63,
1301,
421,
198,
318,
511,
63,
1883,
63,
10777,
8,
277,
304,
507,
198,
504,
29106,
14,
1237,
7415,
319,
4039,
14,
6356,
14,
10777,
63,
1648,
14,
10777,
63,
1648,
492,
28406,
5674,
26432,
547,
507,
198,
496,
63,
1301,
275,
291,
14,
1074,
63,
20235,
63,
5643,
342,
2742,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
401,
488,
12,
2668,
774,
644,
11499,
446,
485,
5708,
401,
2948,
12,
2948,
9,
507,
198,
396,
63,
6088,
63,
2373,
14,
1875,
63,
6088,
63,
2373,
11008,
774,
7020,
14621,
8055,
17827,
2948,
401,
488,
12,
2668,
774,
644,
11499,
446,
485,
5708,
401,
2948,
12,
2948,
9,
2742,
198,
83,
275,
6950,
14,
362,
63,
1301,
8,
1875,
63,
6088,
63,
2373,
8,
496,
63,
1301,
14,
354,
12,
298,
2395,
17391,
401,
1520,
430,
507,
198,
83,
14,
18646,
63,
3403,
275,
2668,
774,
481,
15734,
28497,
6171,
2,
507,
198,
83,
14,
23980,
63,
602,
275,
298,
6965,
13,
614,
13,
966,
2,
507,
198,
83,
14,
3176,
342,
2742,
198,
277,
14,
1855,
8,
17103,
5674,
26432,
547,
12,
308,
14,
7275,
9,
199,
199,
396,
63,
6502,
275,
6950,
14,
362,
63,
396,
63,
6502,
360,
26432,
9240,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
petteyg/intellij-community
|
python/lib/Lib/wsgiref/handlers.py
|
104
|
15596
|
"""Base classes for server/gateway implementations"""
from types import StringType
from util import FileWrapper, guess_scheme, is_hop_by_hop
from headers import Headers
import sys, os, time
__all__ = ['BaseHandler', 'SimpleHandler', 'BaseCGIHandler', 'CGIHandler']
try:
dict
except NameError:
def dict(items):
d = {}
for k,v in items:
d[k] = v
return d
try:
True
False
except NameError:
True = not None
False = not True
# Weekday and month names for HTTP date/time formatting; always English!
_weekdayname = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
_monthname = [None, # Dummy so we can use 1-based month numbers
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
def format_date_time(timestamp):
year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
_weekdayname[wd], day, _monthname[month], year, hh, mm, ss
)
class BaseHandler:
"""Manage the invocation of a WSGI application"""
# Configuration parameters; can override per-subclass or per-instance
wsgi_version = (1,0)
wsgi_multithread = True
wsgi_multiprocess = True
wsgi_run_once = False
origin_server = True # We are transmitting direct to client
http_version = "1.0" # Version that should be used for response
server_software = None # String name of server software, if any
# os_environ is used to supply configuration from the OS environment:
# by default it's a copy of 'os.environ' as of import time, but you can
# override this in e.g. your __init__ method.
os_environ = dict(os.environ.items())
# Collaborator classes
wsgi_file_wrapper = FileWrapper # set to None to disable
headers_class = Headers # must be a Headers-like class
# Error handling (also per-subclass or per-instance)
traceback_limit = None # Print entire traceback to self.get_stderr()
error_status = "500 Dude, this is whack!"
error_headers = [('Content-Type','text/plain')]
error_body = "A server error occurred. Please contact the administrator."
# State variables (don't mess with these)
status = result = None
headers_sent = False
headers = None
bytes_sent = 0
def run(self, application):
"""Invoke the application"""
# Note to self: don't move the close()! Asynchronous servers shouldn't
# call close() from finish_response(), so if you close() anywhere but
# the double-error branch here, you'll break asynchronous servers by
# prematurely closing. Async servers must return from 'run()' without
# closing if there might still be output to iterate over.
try:
self.setup_environ()
self.result = application(self.environ, self.start_response)
self.finish_response()
except:
try:
self.handle_error()
except:
# If we get an error handling an error, just give up already!
self.close()
raise # ...and let the actual server figure it out.
def setup_environ(self):
"""Set up the environment for one request"""
env = self.environ = self.os_environ.copy()
self.add_cgi_vars()
env['wsgi.input'] = self.get_stdin()
env['wsgi.errors'] = self.get_stderr()
env['wsgi.version'] = self.wsgi_version
env['wsgi.run_once'] = self.wsgi_run_once
env['wsgi.url_scheme'] = self.get_scheme()
env['wsgi.multithread'] = self.wsgi_multithread
env['wsgi.multiprocess'] = self.wsgi_multiprocess
if self.wsgi_file_wrapper is not None:
env['wsgi.file_wrapper'] = self.wsgi_file_wrapper
if self.origin_server and self.server_software:
env.setdefault('SERVER_SOFTWARE',self.server_software)
def finish_response(self):
"""Send any iterable data, then close self and the iterable
Subclasses intended for use in asynchronous servers will
want to redefine this method, such that it sets up callbacks
in the event loop to iterate over the data, and to call
'self.close()' once the response is finished.
"""
if not self.result_is_file() or not self.sendfile():
for data in self.result:
self.write(data)
self.finish_content()
self.close()
def get_scheme(self):
"""Return the URL scheme being used"""
return guess_scheme(self.environ)
def set_content_length(self):
"""Compute Content-Length or switch to chunked encoding if possible"""
try:
blocks = len(self.result)
except (TypeError,AttributeError,NotImplementedError):
pass
else:
if blocks==1:
self.headers['Content-Length'] = str(self.bytes_sent)
return
# XXX Try for chunked encoding if origin server and client is 1.1
def cleanup_headers(self):
"""Make any necessary header changes or defaults
Subclasses can extend this to add other defaults.
"""
if not self.headers.has_key('Content-Length'):
self.set_content_length()
def start_response(self, status, headers,exc_info=None):
"""'start_response()' callable as specified by PEP 333"""
if exc_info:
try:
if self.headers_sent:
# Re-raise original exception if headers sent
raise exc_info[0], exc_info[1], exc_info[2]
finally:
exc_info = None # avoid dangling circular ref
elif self.headers is not None:
raise AssertionError("Headers already set!")
assert type(status) is StringType,"Status must be a string"
assert len(status)>=4,"Status must be at least 4 characters"
assert int(status[:3]),"Status message must begin w/3-digit code"
assert status[3]==" ", "Status message must have a space after code"
if __debug__:
for name,val in headers:
assert type(name) is StringType,"Header names must be strings"
assert type(val) is StringType,"Header values must be strings"
assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
self.status = status
self.headers = self.headers_class(headers)
return self.write
def send_preamble(self):
"""Transmit version/status/date/server, via self._write()"""
if self.origin_server:
if self.client_is_modern():
self._write('HTTP/%s %s\r\n' % (self.http_version,self.status))
if not self.headers.has_key('Date'):
self._write(
'Date: %s\r\n' % format_date_time(time.time())
)
if self.server_software and not self.headers.has_key('Server'):
self._write('Server: %s\r\n' % self.server_software)
else:
self._write('Status: %s\r\n' % self.status)
def write(self, data):
"""'write()' callable as specified by PEP 333"""
assert type(data) is StringType,"write() argument must be string"
if not self.status:
raise AssertionError("write() before start_response()")
elif not self.headers_sent:
# Before the first output, send the stored headers
self.bytes_sent = len(data) # make sure we know content-length
self.send_headers()
else:
self.bytes_sent += len(data)
# XXX check Content-Length and truncate if too many bytes written?
self._write(data)
self._flush()
def sendfile(self):
"""Platform-specific file transmission
Override this method in subclasses to support platform-specific
file transmission. It is only called if the application's
return iterable ('self.result') is an instance of
'self.wsgi_file_wrapper'.
This method should return a true value if it was able to actually
transmit the wrapped file-like object using a platform-specific
approach. It should return a false value if normal iteration
should be used instead. An exception can be raised to indicate
that transmission was attempted, but failed.
NOTE: this method should call 'self.send_headers()' if
'self.headers_sent' is false and it is going to attempt direct
transmission of the file.
"""
return False # No platform-specific transmission by default
def finish_content(self):
"""Ensure headers and content have both been sent"""
if not self.headers_sent:
self.headers['Content-Length'] = "0"
self.send_headers()
else:
pass # XXX check if content-length was too short?
def close(self):
"""Close the iterable (if needed) and reset all instance vars
Subclasses may want to also drop the client connection.
"""
try:
if hasattr(self.result,'close'):
self.result.close()
finally:
self.result = self.headers = self.status = self.environ = None
self.bytes_sent = 0; self.headers_sent = False
def send_headers(self):
"""Transmit headers to the client, via self._write()"""
self.cleanup_headers()
self.headers_sent = True
if not self.origin_server or self.client_is_modern():
self.send_preamble()
self._write(str(self.headers))
def result_is_file(self):
"""True if 'self.result' is an instance of 'self.wsgi_file_wrapper'"""
wrapper = self.wsgi_file_wrapper
return wrapper is not None and isinstance(self.result,wrapper)
def client_is_modern(self):
"""True if client can accept status and headers"""
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
def log_exception(self,exc_info):
"""Log the 'exc_info' tuple in the server log
Subclasses may override to retarget the output or change its format.
"""
try:
from traceback import print_exception
stderr = self.get_stderr()
print_exception(
exc_info[0], exc_info[1], exc_info[2],
self.traceback_limit, stderr
)
stderr.flush()
finally:
exc_info = None
def handle_error(self):
"""Log current error, and send error output to client if possible"""
self.log_exception(sys.exc_info())
if not self.headers_sent:
self.result = self.error_output(self.environ, self.start_response)
self.finish_response()
# XXX else: attempt advanced recovery techniques for HTML or text?
def error_output(self, environ, start_response):
"""WSGI mini-app to create error output
By default, this just uses the 'error_status', 'error_headers',
and 'error_body' attributes to generate an output page. It can
be overridden in a subclass to dynamically generate diagnostics,
choose an appropriate message for the user's preferred language, etc.
Note, however, that it's not recommended from a security perspective to
spit out diagnostics to any old user; ideally, you should have to do
something special to enable diagnostic output, which is why we don't
include any here!
"""
start_response(self.error_status,self.error_headers[:],sys.exc_info())
return [self.error_body]
# Pure abstract methods; *must* be overridden in subclasses
def _write(self,data):
"""Override in subclass to buffer data for send to client
It's okay if this method actually transmits the data; BaseHandler
just separates write and flush operations for greater efficiency
when the underlying system actually has such a distinction.
"""
raise NotImplementedError
def _flush(self):
"""Override in subclass to force sending of recent '_write()' calls
It's okay if this method is a no-op (i.e., if '_write()' actually
sends the data.
"""
raise NotImplementedError
def get_stdin(self):
"""Override in subclass to return suitable 'wsgi.input'"""
raise NotImplementedError
def get_stderr(self):
"""Override in subclass to return suitable 'wsgi.errors'"""
raise NotImplementedError
def add_cgi_vars(self):
"""Override in subclass to insert CGI variables in 'self.environ'"""
raise NotImplementedError
class SimpleHandler(BaseHandler):
"""Handler that's just initialized with streams, environment, etc.
This handler subclass is intended for synchronous HTTP/1.0 origin servers,
and handles sending the entire response output, given the correct inputs.
Usage::
handler = SimpleHandler(
inp,out,err,env, multithread=False, multiprocess=True
)
handler.run(app)"""
def __init__(self,stdin,stdout,stderr,environ,
multithread=True, multiprocess=False
):
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.base_env = environ
self.wsgi_multithread = multithread
self.wsgi_multiprocess = multiprocess
def get_stdin(self):
return self.stdin
def get_stderr(self):
return self.stderr
def add_cgi_vars(self):
self.environ.update(self.base_env)
def _write(self,data):
self.stdout.write(data)
self._write = self.stdout.write
def _flush(self):
self.stdout.flush()
self._flush = self.stdout.flush
class BaseCGIHandler(SimpleHandler):
"""CGI-like systems using input/output/error streams and environ mapping
Usage::
handler = BaseCGIHandler(inp,out,err,env)
handler.run(app)
This handler class is useful for gateway protocols like ReadyExec and
FastCGI, that have usable input/output/error streams and an environment
mapping. It's also the base class for CGIHandler, which just uses
sys.stdin, os.environ, and so on.
The constructor also takes keyword arguments 'multithread' and
'multiprocess' (defaulting to 'True' and 'False' respectively) to control
the configuration sent to the application. It sets 'origin_server' to
False (to enable CGI-like output), and assumes that 'wsgi.run_once' is
False.
"""
origin_server = False
class CGIHandler(BaseCGIHandler):
"""CGI-based invocation via sys.stdin/stdout/stderr and os.environ
Usage::
CGIHandler().run(app)
The difference between this class and BaseCGIHandler is that it always
uses 'wsgi.run_once' of 'True', 'wsgi.multithread' of 'False', and
'wsgi.multiprocess' of 'True'. It does not take any initialization
parameters, but always uses 'sys.stdin', 'os.environ', and friends.
If you need to override any of these parameters, use BaseCGIHandler
instead.
"""
wsgi_run_once = True
def __init__(self):
BaseCGIHandler.__init__(
self, sys.stdin, sys.stdout, sys.stderr, dict(os.environ.items()),
multithread=False, multiprocess=True
)
#
|
apache-2.0
|
[
624,
1563,
3992,
367,
1654,
15,
7019,
12591,
624,
199,
199,
504,
2943,
492,
32654,
199,
504,
4884,
492,
3814,
4590,
12,
9519,
63,
5512,
12,
365,
63,
13376,
63,
991,
63,
13376,
199,
504,
2323,
492,
21391,
199,
199,
646,
984,
12,
747,
12,
900,
199,
199,
363,
452,
363,
275,
788,
1563,
2461,
297,
283,
3184,
2461,
297,
283,
1563,
21337,
2461,
297,
283,
21337,
2461,
418,
199,
199,
893,
26,
272,
1211,
199,
2590,
12746,
26,
272,
347,
1211,
8,
1744,
304,
267,
366,
275,
1052,
267,
367,
1022,
12,
86,
315,
2974,
26,
288,
366,
59,
75,
61,
275,
373,
267,
372,
366,
199,
199,
893,
26,
272,
715,
272,
756,
199,
2590,
12746,
26,
272,
715,
275,
440,
488,
272,
756,
275,
440,
715,
421,
199,
3,
31072,
2977,
436,
5794,
1561,
367,
3101,
1434,
15,
521,
10803,
27,
3544,
20144,
1,
199,
63,
12451,
354,
275,
2097,
6671,
401,
298,
52,
310,
401,
298,
55,
379,
401,
298,
2719,
85,
401,
298,
22533,
401,
298,
22332,
401,
298,
22546,
937,
199,
63,
4482,
354,
275,
359,
403,
12,
327,
9762,
880,
781,
883,
675,
413,
13,
6788,
5794,
5579,
1598,
298,
19825,
401,
298,
27717,
401,
298,
10570,
401,
298,
33,
2700,
401,
298,
15586,
401,
298,
42,
324,
401,
1598,
298,
42,
348,
401,
298,
21640,
401,
298,
23337,
401,
298,
17584,
401,
298,
1944,
86,
401,
298,
8584,
937,
199,
199,
318,
1475,
63,
602,
63,
521,
8,
3954,
304,
272,
5361,
12,
5794,
12,
5382,
12,
25783,
12,
8562,
12,
10110,
12,
20792,
12,
612,
12,
1315,
275,
900,
14,
22227,
8,
3954,
9,
272,
372,
2071,
83,
12,
450,
996,
68,
450,
19,
83,
450,
20,
68,
450,
996,
68,
2689,
996,
68,
2689,
996,
68,
19152,
2,
450,
334,
267,
485,
12451,
354,
59,
2989,
467,
5382,
12,
485,
4482,
354,
59,
4482,
467,
5361,
12,
25783,
12,
8562,
12,
10110,
272,
776,
4388,
199,
533,
3523,
2461,
26,
272,
408,
20588,
314,
19569,
402,
282,
9279,
4223,
624,
339,
327,
11595,
2633,
27,
883,
4278,
1126,
13,
6083,
503,
1126,
13,
842,
272,
12464,
63,
1023,
275,
334,
17,
12,
16,
9,
272,
12464,
63,
3029,
2671,
275,
715,
272,
12464,
63,
3029,
1412,
275,
715,
272,
12464,
63,
1065,
63,
5089,
275,
756,
339,
6330,
63,
1000,
275,
715,
259,
327,
2136,
787,
27754,
1337,
4125,
370,
1890,
272,
1455,
63,
1023,
221,
275,
298,
17,
14,
16,
2,
257,
327,
3394,
626,
1077,
506,
1202,
367,
1177,
272,
1654,
63,
15619,
275,
488,
221,
327,
2624,
536,
402,
1654,
2032,
12,
340,
1263,
339,
327,
747,
63,
2314,
365,
1202,
370,
17169,
2897,
687,
314,
4403,
3734,
26,
272,
327,
701,
849,
652,
1159,
282,
1331,
402,
283,
736,
14,
2314,
7,
465,
402,
492,
900,
12,
1325,
1265,
883,
272,
327,
4278,
642,
315,
325,
14,
71,
14,
2195,
636,
826,
363,
1083,
14,
272,
747,
63,
2314,
275,
1211,
8,
736,
14,
2314,
14,
1744,
1012,
339,
327,
3626,
5561,
10676,
3992,
272,
12464,
63,
493,
63,
5029,
275,
3814,
4590,
258,
327,
663,
370,
488,
370,
3507,
272,
2323,
63,
533,
275,
21391,
3777,
327,
1471,
506,
282,
21391,
13,
2930,
1021,
339,
327,
4520,
7252,
334,
12344,
1126,
13,
6083,
503,
1126,
13,
842,
9,
272,
5190,
63,
3097,
275,
488,
221,
327,
9101,
8039,
5190,
370,
291,
14,
362,
63,
3083,
342,
272,
1125,
63,
1205,
275,
298,
5783,
577,
3786,
12,
642,
365,
704,
564,
9539,
272,
1125,
63,
2139,
275,
4274,
2714,
13,
804,
1673,
505,
15,
6104,
5440,
272,
1125,
63,
2030,
275,
298,
33,
1654,
1125,
8920,
14,
221,
7754,
8966,
314,
31056,
2122,
339,
327,
8511,
2860,
334,
13196,
1133,
15634,
543,
3520,
9,
272,
2004,
275,
754,
275,
488,
272,
2323,
63,
1150,
275,
756,
272,
2323,
275,
488,
272,
2783,
63,
1150,
275,
378,
6905,
421,
2378,
347,
1255,
8,
277,
12,
4223,
304,
267,
408,
27736,
314,
4223,
624,
267,
327,
3390,
370,
291,
26,
2793,
1133,
4057,
314,
4002,
342,
1,
221,
3709,
9865,
8037,
9296,
1133,
267,
327,
1240,
4002,
342,
687,
9578,
63,
1310,
1062,
880,
340,
1265,
4002,
342,
26523,
1325,
267,
327,
314,
4270,
13,
705,
5246,
2348,
12,
1265,
7171,
2059,
15608,
8037,
701,
267,
327,
876,
19925,
590,
11261,
14,
221,
15223,
8037,
1471,
372,
687,
283,
1065,
11716,
1928,
267,
327,
11261,
340,
2337,
5594,
5139,
506,
1072,
370,
13974,
1806,
14,
267,
862,
26,
288,
291,
14,
2758,
63,
2314,
342,
288,
291,
14,
1099,
275,
4223,
8,
277,
14,
2314,
12,
291,
14,
928,
63,
1310,
9,
288,
291,
14,
8192,
63,
1310,
342,
267,
871,
26,
288,
862,
26,
355,
291,
14,
2479,
63,
705,
342,
288,
871,
26,
355,
327,
982,
781,
664,
376,
1125,
7252,
376,
1125,
12,
2951,
8120,
1536,
2575,
1,
355,
291,
14,
1600,
342,
355,
746,
257,
327,
2263,
460,
4691,
314,
3503,
1654,
9658,
652,
734,
14,
2378,
347,
3272,
63,
2314,
8,
277,
304,
267,
408,
1084,
1536,
314,
3734,
367,
1373,
1056,
624,
398,
2589,
275,
291,
14,
2314,
275,
291,
14,
736,
63,
2314,
14,
1574,
342,
267,
291,
14,
525,
63,
13814,
63,
2936,
342,
398,
2589,
459,
6508,
14,
1210,
418,
263,
275,
291,
14,
362,
63,
6626,
342,
267,
2589,
459,
6508,
14,
2550,
418,
755,
275,
291,
14,
362,
63,
3083,
342,
267,
2589,
459,
6508,
14,
1023,
418,
420,
275,
291,
14,
6508,
63,
1023,
267,
2589,
459,
6508,
14,
1065,
63,
5089,
418,
258,
275,
291,
14,
6508,
63,
1065,
63,
5089,
267,
2589,
459,
6508,
14,
633,
63,
5512,
418,
257,
275,
291,
14,
362,
63,
5512,
342,
267,
2589,
459,
6508,
14,
3029,
2671,
418,
221,
275,
291,
14,
6508,
63,
3029,
2671,
267,
2589,
459,
6508,
14,
3029,
1412,
418,
275,
291,
14,
6508,
63,
3029,
1412,
398,
340,
291,
14,
6508,
63,
493,
63,
5029,
365,
440,
488,
26,
288,
2589,
459,
6508,
14,
493,
63,
5029,
418,
275,
291,
14,
6508,
63,
493,
63,
5029,
398,
340,
291,
14,
6493,
63,
1000,
436,
291,
14
] |
[
1563,
3992,
367,
1654,
15,
7019,
12591,
624,
199,
199,
504,
2943,
492,
32654,
199,
504,
4884,
492,
3814,
4590,
12,
9519,
63,
5512,
12,
365,
63,
13376,
63,
991,
63,
13376,
199,
504,
2323,
492,
21391,
199,
199,
646,
984,
12,
747,
12,
900,
199,
199,
363,
452,
363,
275,
788,
1563,
2461,
297,
283,
3184,
2461,
297,
283,
1563,
21337,
2461,
297,
283,
21337,
2461,
418,
199,
199,
893,
26,
272,
1211,
199,
2590,
12746,
26,
272,
347,
1211,
8,
1744,
304,
267,
366,
275,
1052,
267,
367,
1022,
12,
86,
315,
2974,
26,
288,
366,
59,
75,
61,
275,
373,
267,
372,
366,
199,
199,
893,
26,
272,
715,
272,
756,
199,
2590,
12746,
26,
272,
715,
275,
440,
488,
272,
756,
275,
440,
715,
421,
199,
3,
31072,
2977,
436,
5794,
1561,
367,
3101,
1434,
15,
521,
10803,
27,
3544,
20144,
1,
199,
63,
12451,
354,
275,
2097,
6671,
401,
298,
52,
310,
401,
298,
55,
379,
401,
298,
2719,
85,
401,
298,
22533,
401,
298,
22332,
401,
298,
22546,
937,
199,
63,
4482,
354,
275,
359,
403,
12,
327,
9762,
880,
781,
883,
675,
413,
13,
6788,
5794,
5579,
1598,
298,
19825,
401,
298,
27717,
401,
298,
10570,
401,
298,
33,
2700,
401,
298,
15586,
401,
298,
42,
324,
401,
1598,
298,
42,
348,
401,
298,
21640,
401,
298,
23337,
401,
298,
17584,
401,
298,
1944,
86,
401,
298,
8584,
937,
199,
199,
318,
1475,
63,
602,
63,
521,
8,
3954,
304,
272,
5361,
12,
5794,
12,
5382,
12,
25783,
12,
8562,
12,
10110,
12,
20792,
12,
612,
12,
1315,
275,
900,
14,
22227,
8,
3954,
9,
272,
372,
2071,
83,
12,
450,
996,
68,
450,
19,
83,
450,
20,
68,
450,
996,
68,
2689,
996,
68,
2689,
996,
68,
19152,
2,
450,
334,
267,
485,
12451,
354,
59,
2989,
467,
5382,
12,
485,
4482,
354,
59,
4482,
467,
5361,
12,
25783,
12,
8562,
12,
10110,
272,
776,
4388,
199,
533,
3523,
2461,
26,
272,
408,
20588,
314,
19569,
402,
282,
9279,
4223,
624,
339,
327,
11595,
2633,
27,
883,
4278,
1126,
13,
6083,
503,
1126,
13,
842,
272,
12464,
63,
1023,
275,
334,
17,
12,
16,
9,
272,
12464,
63,
3029,
2671,
275,
715,
272,
12464,
63,
3029,
1412,
275,
715,
272,
12464,
63,
1065,
63,
5089,
275,
756,
339,
6330,
63,
1000,
275,
715,
259,
327,
2136,
787,
27754,
1337,
4125,
370,
1890,
272,
1455,
63,
1023,
221,
275,
298,
17,
14,
16,
2,
257,
327,
3394,
626,
1077,
506,
1202,
367,
1177,
272,
1654,
63,
15619,
275,
488,
221,
327,
2624,
536,
402,
1654,
2032,
12,
340,
1263,
339,
327,
747,
63,
2314,
365,
1202,
370,
17169,
2897,
687,
314,
4403,
3734,
26,
272,
327,
701,
849,
652,
1159,
282,
1331,
402,
283,
736,
14,
2314,
7,
465,
402,
492,
900,
12,
1325,
1265,
883,
272,
327,
4278,
642,
315,
325,
14,
71,
14,
2195,
636,
826,
363,
1083,
14,
272,
747,
63,
2314,
275,
1211,
8,
736,
14,
2314,
14,
1744,
1012,
339,
327,
3626,
5561,
10676,
3992,
272,
12464,
63,
493,
63,
5029,
275,
3814,
4590,
258,
327,
663,
370,
488,
370,
3507,
272,
2323,
63,
533,
275,
21391,
3777,
327,
1471,
506,
282,
21391,
13,
2930,
1021,
339,
327,
4520,
7252,
334,
12344,
1126,
13,
6083,
503,
1126,
13,
842,
9,
272,
5190,
63,
3097,
275,
488,
221,
327,
9101,
8039,
5190,
370,
291,
14,
362,
63,
3083,
342,
272,
1125,
63,
1205,
275,
298,
5783,
577,
3786,
12,
642,
365,
704,
564,
9539,
272,
1125,
63,
2139,
275,
4274,
2714,
13,
804,
1673,
505,
15,
6104,
5440,
272,
1125,
63,
2030,
275,
298,
33,
1654,
1125,
8920,
14,
221,
7754,
8966,
314,
31056,
2122,
339,
327,
8511,
2860,
334,
13196,
1133,
15634,
543,
3520,
9,
272,
2004,
275,
754,
275,
488,
272,
2323,
63,
1150,
275,
756,
272,
2323,
275,
488,
272,
2783,
63,
1150,
275,
378,
6905,
421,
2378,
347,
1255,
8,
277,
12,
4223,
304,
267,
408,
27736,
314,
4223,
624,
267,
327,
3390,
370,
291,
26,
2793,
1133,
4057,
314,
4002,
342,
1,
221,
3709,
9865,
8037,
9296,
1133,
267,
327,
1240,
4002,
342,
687,
9578,
63,
1310,
1062,
880,
340,
1265,
4002,
342,
26523,
1325,
267,
327,
314,
4270,
13,
705,
5246,
2348,
12,
1265,
7171,
2059,
15608,
8037,
701,
267,
327,
876,
19925,
590,
11261,
14,
221,
15223,
8037,
1471,
372,
687,
283,
1065,
11716,
1928,
267,
327,
11261,
340,
2337,
5594,
5139,
506,
1072,
370,
13974,
1806,
14,
267,
862,
26,
288,
291,
14,
2758,
63,
2314,
342,
288,
291,
14,
1099,
275,
4223,
8,
277,
14,
2314,
12,
291,
14,
928,
63,
1310,
9,
288,
291,
14,
8192,
63,
1310,
342,
267,
871,
26,
288,
862,
26,
355,
291,
14,
2479,
63,
705,
342,
288,
871,
26,
355,
327,
982,
781,
664,
376,
1125,
7252,
376,
1125,
12,
2951,
8120,
1536,
2575,
1,
355,
291,
14,
1600,
342,
355,
746,
257,
327,
2263,
460,
4691,
314,
3503,
1654,
9658,
652,
734,
14,
2378,
347,
3272,
63,
2314,
8,
277,
304,
267,
408,
1084,
1536,
314,
3734,
367,
1373,
1056,
624,
398,
2589,
275,
291,
14,
2314,
275,
291,
14,
736,
63,
2314,
14,
1574,
342,
267,
291,
14,
525,
63,
13814,
63,
2936,
342,
398,
2589,
459,
6508,
14,
1210,
418,
263,
275,
291,
14,
362,
63,
6626,
342,
267,
2589,
459,
6508,
14,
2550,
418,
755,
275,
291,
14,
362,
63,
3083,
342,
267,
2589,
459,
6508,
14,
1023,
418,
420,
275,
291,
14,
6508,
63,
1023,
267,
2589,
459,
6508,
14,
1065,
63,
5089,
418,
258,
275,
291,
14,
6508,
63,
1065,
63,
5089,
267,
2589,
459,
6508,
14,
633,
63,
5512,
418,
257,
275,
291,
14,
362,
63,
5512,
342,
267,
2589,
459,
6508,
14,
3029,
2671,
418,
221,
275,
291,
14,
6508,
63,
3029,
2671,
267,
2589,
459,
6508,
14,
3029,
1412,
418,
275,
291,
14,
6508,
63,
3029,
1412,
398,
340,
291,
14,
6508,
63,
493,
63,
5029,
365,
440,
488,
26,
288,
2589,
459,
6508,
14,
493,
63,
5029,
418,
275,
291,
14,
6508,
63,
493,
63,
5029,
398,
340,
291,
14,
6493,
63,
1000,
436,
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
] |
CuonDeveloper/cuon
|
cuon_client/cuon/Think/SingleThink.py
|
3
|
1731
|
# -*- coding: utf-8 -*-
##Copyright (C) [2005] [Jürgen Hamel, D-32584 Löhne]
##This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
##published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
##This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
##warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
##for more details.
##You should have received a copy of the GNU General Public License along with this program; if not, write to the
##Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
from cuon.Databases.SingleData import SingleData
import logging
import pygtk
pygtk.require('2.0')
import gtk
#import gtk.glade
import gobject
class SingleThink(SingleData):
def __init__(self, allTables):
SingleData.__init__(self)
# tables.dbd and address
self.sNameOfTable = "thinking"
self.xmlTableDef = 0
# self.loadTable()
# self.saveTable()
self.loadTable(allTables)
self.setStore( gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_UINT) )
self.listHeader['names'] = ['title', 'designation', 'ID']
self.listHeader['size'] = [25,10,25,25,10]
print "number of Columns "
print len(self.table.Columns)
#
self.cType = 'html'
# def readNonWidgetEntries(self, dicValues):
# print 'readNonWidgetEntries(self) by SingleWeb2'
# dicValues['ctype'] = [self.cType, 'string']
# return dicValues
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
7384,
334,
35,
9,
359,
9397,
61,
221,
359,
42,
17709,
82,
2268,
869,
14868,
12,
577,
13,
708,
12248,
491,
14614,
72,
685,
61,
199,
199,
309,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
8987,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
199,
309,
3281,
1312,
369,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
199,
309,
509,
1655,
2436,
14,
199,
199,
309,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
309,
10146,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
9948,
199,
504,
286,
21615,
14,
7243,
83,
14,
7200,
1451,
492,
13050,
1451,
199,
646,
2050,
199,
646,
1134,
12275,
199,
647,
12275,
14,
4365,
360,
18,
14,
16,
358,
199,
646,
8116,
199,
3,
646,
8116,
14,
31589,
199,
646,
25595,
4388,
199,
533,
13050,
2719,
2292,
8,
7200,
1451,
304,
25979,
347,
636,
826,
721,
277,
12,
1006,
18845,
304,
398,
13050,
1451,
855,
826,
721,
277,
9,
267,
327,
6716,
14,
697,
68,
436,
2287,
267,
291,
14,
83,
985,
3466,
3186,
275,
221,
298,
29727,
316,
2,
267,
291,
14,
1652,
3186,
6172,
275,
378,
267,
327,
291,
14,
912,
3186,
342,
267,
327,
291,
14,
2117,
3186,
342,
398,
291,
14,
912,
3186,
8,
452,
18845,
9,
267,
291,
14,
409,
5502,
8,
8116,
14,
1296,
5502,
8,
71,
785,
14,
2711,
63,
5353,
12,
25595,
14,
2711,
63,
5353,
12,
221,
25595,
14,
2711,
63,
17459,
9,
776,
267,
291,
14,
513,
2567,
459,
1247,
418,
275,
788,
1213,
297,
283,
14748,
425,
297,
283,
998,
418,
267,
291,
14,
513,
2567,
459,
890,
418,
275,
359,
821,
12,
709,
12,
821,
12,
821,
12,
709,
61,
267,
870,
298,
1955,
402,
3626,
2346,
298,
267,
870,
822,
8,
277,
14,
1224,
14,
15086,
9,
267,
327,
267,
291,
14,
67,
804,
275,
283,
1360,
7,
9948,
199,
3,
259,
347,
1586,
6932,
3339,
17816,
8,
277,
12,
12219,
6550,
304,
199,
3,
755,
870,
283,
739,
6932,
3339,
17816,
8,
277,
9,
701,
13050,
5926,
18,
7,
199,
3,
263,
12219,
6550,
459,
3667,
418,
275,
359,
277,
14,
67,
804,
12,
283,
875,
418,
199,
3,
263,
372,
12219,
6550,
257,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
7384,
334,
35,
9,
359,
9397,
61,
221,
359,
42,
17709,
82,
2268,
869,
14868,
12,
577,
13,
708,
12248,
491,
14614,
72,
685,
61,
199,
199,
309,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
8987,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
199,
309,
3281,
1312,
369,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
199,
309,
509,
1655,
2436,
14,
199,
199,
309,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
309,
10146,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
9948,
199,
504,
286,
21615,
14,
7243,
83,
14,
7200,
1451,
492,
13050,
1451,
199,
646,
2050,
199,
646,
1134,
12275,
199,
647,
12275,
14,
4365,
360,
18,
14,
16,
358,
199,
646,
8116,
199,
3,
646,
8116,
14,
31589,
199,
646,
25595,
4388,
199,
533,
13050,
2719,
2292,
8,
7200,
1451,
304,
25979,
347,
636,
826,
721,
277,
12,
1006,
18845,
304,
398,
13050,
1451,
855,
826,
721,
277,
9,
267,
327,
6716,
14,
697,
68,
436,
2287,
267,
291,
14,
83,
985,
3466,
3186,
275,
221,
298,
29727,
316,
2,
267,
291,
14,
1652,
3186,
6172,
275,
378,
267,
327,
291,
14,
912,
3186,
342,
267,
327,
291,
14,
2117,
3186,
342,
398,
291,
14,
912,
3186,
8,
452,
18845,
9,
267,
291,
14,
409,
5502,
8,
8116,
14,
1296,
5502,
8,
71,
785,
14,
2711,
63,
5353,
12,
25595,
14,
2711,
63,
5353,
12,
221,
25595,
14,
2711,
63,
17459,
9,
776,
267,
291,
14,
513,
2567,
459,
1247,
418,
275,
788,
1213,
297,
283,
14748,
425,
297,
283,
998,
418,
267,
291,
14,
513,
2567,
459,
890,
418,
275,
359,
821,
12,
709,
12,
821,
12,
821,
12,
709,
61,
267,
870,
298,
1955,
402,
3626,
2346,
298,
267,
870,
822,
8,
277,
14,
1224,
14,
15086,
9,
267,
327,
267,
291,
14,
67,
804,
275,
283,
1360,
7,
9948,
199,
3,
259,
347,
1586,
6932,
3339,
17816,
8,
277,
12,
12219,
6550,
304,
199,
3,
755,
870,
283,
739,
6932,
3339,
17816,
8,
277,
9,
701,
13050,
5926,
18,
7,
199,
3,
263,
12219,
6550,
459,
3667,
418,
275,
359,
277,
14,
67,
804,
12,
283,
875,
418,
199,
3,
263,
372,
12219,
6550,
257,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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