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
|
|---|---|---|---|---|---|---|---|---|
google-research/google-research
|
poem/core/keypoint_profiles.py
|
1
|
48752
|
# coding=utf-8
# Copyright 2021 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Keypoint profile class and utility functions."""
import abc
import enum
import six
import tensorflow as tf
from poem.core import keypoint_utils
class LeftRightType(enum.Enum):
"""Keypoint/segment left/right type."""
UNKNOWN = 0
CENTRAL = 1
LEFT = 2
RIGHT = 3
def infer_keypoint_left_right_type(left_right_types, indices):
"""Infers keypoint left/right type.
The inferred left/right type is decided as follows:
1. If either type is UNKNOWN, returns UNKNOWN.
2. If both types are the same, returns this type.
3. If one type is CENTRAL, and the other type is LEFT or RIGHT, returns the
other type.
4. If one type is LEFT and the other type is RIGHT, returns CENTRAL.
Args:
left_right_types: A list of LeftRightType enum values for all keypoints.
indices: A list of integers for keypoint indices.
Returns:
A LeftRightType enum value for inferred type.
Raises:
ValueError: If any index is out of range.
"""
if not indices:
return LeftRightType.UNKNOWN
def lookup(i):
if i < 0 or i >= len(left_right_types):
raise ValueError('Left/right type index is out of range: %d.' % i)
return left_right_types[i]
if len(indices) == 1:
return lookup(indices[0])
output_type = LeftRightType.CENTRAL
for i in indices:
current_type = lookup(i)
if current_type == LeftRightType.UNKNOWN:
return LeftRightType.UNKNOWN
if output_type == LeftRightType.CENTRAL:
output_type = current_type
elif current_type != LeftRightType.CENTRAL and current_type != output_type:
output_type = LeftRightType.CENTRAL
return output_type
def infer_segment_left_right_type(left_right_types, start_indices, end_indices):
"""Infers segment left/right type.
The inferred left/right type is decided as follows:
1. If either type is UNKNOWN, returns UNKNOWN.
2. If both types are the same, returns this type.
3. If one type is CENTRAL, and the other type is LEFT or RIGHT, returns the
other type.
4. If one type is LEFT and the other type is RIGHT, returns CENTRAL.
Args:
left_right_types: A list of LeftRightType enum values for all keypoints.
start_indices: A list of integers for LHS keypoint indices.
end_indices: A list of integers for RHS keypoint indices.
Returns:
A LeftRightType enum value for inferred type.
"""
lhs_type = infer_keypoint_left_right_type(left_right_types, start_indices)
rhs_type = infer_keypoint_left_right_type(left_right_types, end_indices)
if lhs_type == LeftRightType.UNKNOWN or rhs_type == LeftRightType.UNKNOWN:
return LeftRightType.UNKNOWN
if lhs_type == LeftRightType.CENTRAL:
return rhs_type
if rhs_type == LeftRightType.CENTRAL:
return lhs_type
return lhs_type if lhs_type == rhs_type else LeftRightType.CENTRAL
class KeypointProfile(six.with_metaclass(abc.ABCMeta, object)):
"""Keypoint profile base class."""
def __init__(self,
name,
keypoint_names,
offset_keypoint_names,
scale_keypoint_name_pairs,
scale_distance_reduction_fn,
scale_unit,
segment_name_pairs,
head_keypoint_name=None,
neck_keypoint_name=None,
left_shoulder_keypoint_name=None,
right_shoulder_keypoint_name=None,
left_elbow_keypoint_name=None,
right_elbow_keypoint_name=None,
left_wrist_keypoint_name=None,
right_wrist_keypoint_name=None,
spine_keypoint_name=None,
pelvis_keypoint_name=None,
left_hip_keypoint_name=None,
right_hip_keypoint_name=None,
left_knee_keypoint_name=None,
right_knee_keypoint_name=None,
left_ankle_keypoint_name=None,
right_ankle_keypoint_name=None):
"""Initializer."""
self._name = name
self._keypoint_names = [name for name, _ in keypoint_names]
self._keypoint_left_right_types = [
left_right_type for _, left_right_type in keypoint_names
]
self._offset_keypoint_index = [
self._keypoint_names.index(keypoint_name)
for keypoint_name in offset_keypoint_names
]
self._scale_keypoint_index_pairs = []
for start_names, end_names in scale_keypoint_name_pairs:
self._scale_keypoint_index_pairs.append(
([self._keypoint_names.index(name) for name in start_names],
[self._keypoint_names.index(name) for name in end_names]))
self._scale_distance_reduction_fn = scale_distance_reduction_fn
self._scale_unit = scale_unit
self._segment_index_pairs = []
for start_names, end_names in segment_name_pairs:
self._segment_index_pairs.append(
([self._keypoint_names.index(name) for name in start_names],
[self._keypoint_names.index(name) for name in end_names]))
self._head_keypoint_name = head_keypoint_name
self._neck_keypoint_name = neck_keypoint_name
self._left_shoulder_keypoint_name = left_shoulder_keypoint_name
self._right_shoulder_keypoint_name = right_shoulder_keypoint_name
self._left_elbow_keypoint_name = left_elbow_keypoint_name
self._right_elbow_keypoint_name = right_elbow_keypoint_name
self._left_wrist_keypoint_name = left_wrist_keypoint_name
self._right_wrist_keypoint_name = right_wrist_keypoint_name
self._spine_keypoint_name = spine_keypoint_name
self._pelvis_keypoint_name = pelvis_keypoint_name
self._left_hip_keypoint_name = left_hip_keypoint_name
self._right_hip_keypoint_name = right_hip_keypoint_name
self._left_knee_keypoint_name = left_knee_keypoint_name
self._right_knee_keypoint_name = right_knee_keypoint_name
self._left_ankle_keypoint_name = left_ankle_keypoint_name
self._right_ankle_keypoint_name = right_ankle_keypoint_name
@property
def name(self):
"""Gets keypoint profile name."""
return self._name
@property
def keypoint_names(self):
"""Gets keypoint names."""
return self._keypoint_names
@property
@abc.abstractmethod
def keypoint_dim(self):
"""Gets keypoint dimensionality."""
raise NotImplementedError
@property
def keypoint_num(self):
"""Gets number of keypoints."""
return len(self._keypoint_names)
def keypoint_left_right_type(self, keypoint_index):
"""Gets keypoint left/right type given index."""
if isinstance(keypoint_index, int):
keypoint_index = [keypoint_index]
return infer_keypoint_left_right_type(self._keypoint_left_right_types,
keypoint_index)
def segment_left_right_type(self, start_index, end_index):
"""Gets segment left/right type given index."""
if isinstance(start_index, int):
start_index = [start_index]
if isinstance(end_index, int):
end_index = [end_index]
return infer_segment_left_right_type(self._keypoint_left_right_types,
start_index, end_index)
@property
def offset_keypoint_index(self):
"""Gets offset keypoint index."""
return self._offset_keypoint_index
@property
def scale_keypoint_index_pairs(self):
"""Gets scale keypoint index pairs."""
return self._scale_keypoint_index_pairs
@property
def scale_unit(self):
"""Gets scale unit."""
return self._scale_unit
@property
def segment_index_pairs(self):
"""Gets segment index pairs."""
return self._segment_index_pairs
@property
def keypoint_affinity_matrix(self):
"""Gets keypoint affinity matrix.
If a segment has multi-point end, all pairs of relevant points are
considered as in affinity.
Returns:
matrix: A double list of floats for the keypoint affinity matrix.
Raises:
ValueError: If affinity matrix has any isolated node.
"""
matrix = [[0.0
for _ in range(self.keypoint_num)]
for _ in range(self.keypoint_num)]
# Self-affinity.
for i in range(self.keypoint_num):
matrix[i][i] = 1.0
for lhs_index, rhs_index in self._segment_index_pairs:
for i in lhs_index:
for j in lhs_index:
matrix[i][j] = 1.0
matrix[j][i] = 1.0
for i in rhs_index:
for j in rhs_index:
matrix[i][j] = 1.0
matrix[j][i] = 1.0
for i in lhs_index:
for j in rhs_index:
matrix[i][j] = 1.0
matrix[j][i] = 1.0
# Check if the affinity matrix is valid, i.e., each node must have degree
# greater than 1 (no isolated node).
for row in matrix:
if sum(row) <= 1.0:
raise ValueError(
'Affinity matrix has a node with degree less than 2: %s.' %
str(matrix))
return matrix
def keypoint_index(self, keypoint_name, raise_error_if_not_found=False):
"""Gets keypoint index given name.
If `raise_error_if_not_found` is True, raises ValueError if keypoint does
not exist. Otherwise, returns -1 if keypoint does not exist.
Args:
keypoint_name: A string for keypoint name to find index of.
raise_error_if_not_found: A boolean for whether to raise ValueError if
keypoint does not exist.
Returns:
An integer for keypoint index.
Raises:
ValueError: If keypoint does not exist and `raise_error_if_not_found` is
True.
"""
if keypoint_name in self._keypoint_names:
return self._keypoint_names.index(keypoint_name)
if raise_error_if_not_found:
raise ValueError('Failed to find keypoint: `%s`.' % str(keypoint_name))
return -1
@property
def head_keypoint_index(self):
"""Gets head keypoint index."""
if not self._head_keypoint_name:
raise ValueError('Head keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._head_keypoint_name
]
@property
def neck_keypoint_index(self):
"""Gets neck keypoint index."""
if not self._neck_keypoint_name:
raise ValueError('Neck keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._neck_keypoint_name
]
@property
def left_shoulder_keypoint_index(self):
"""Gets left shoulder keypoint index."""
if not self._left_shoulder_keypoint_name:
raise ValueError('Left shoulder keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._left_shoulder_keypoint_name
]
@property
def right_shoulder_keypoint_index(self):
"""Gets right shoulder keypoint index."""
if not self._right_shoulder_keypoint_name:
raise ValueError('Right shoulder keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._right_shoulder_keypoint_name
]
@property
def left_elbow_keypoint_index(self):
"""Gets left elbow keypoint index."""
if not self._left_elbow_keypoint_name:
raise ValueError('Left elbow keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._left_elbow_keypoint_name
]
@property
def right_elbow_keypoint_index(self):
"""Gets right elbow keypoint index."""
if not self._right_elbow_keypoint_name:
raise ValueError('Right elbow keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._right_elbow_keypoint_name
]
@property
def left_wrist_keypoint_index(self):
"""Gets left wrist keypoint index."""
if not self._left_wrist_keypoint_name:
raise ValueError('Left wrist keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._left_wrist_keypoint_name
]
@property
def right_wrist_keypoint_index(self):
"""Gets right wrist keypoint index."""
if not self._right_wrist_keypoint_name:
raise ValueError('Right wrist keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._right_wrist_keypoint_name
]
@property
def spine_keypoint_index(self):
"""Gets spine keypoint index."""
if not self._spine_keypoint_name:
raise ValueError('Spine keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._spine_keypoint_name
]
@property
def pelvis_keypoint_index(self):
"""Gets pelvis keypoint index."""
if not self._pelvis_keypoint_name:
raise ValueError('Pelvis keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._pelvis_keypoint_name
]
@property
def left_hip_keypoint_index(self):
"""Gets left hip keypoint index."""
if not self._left_hip_keypoint_name:
raise ValueError('Left hip keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._left_hip_keypoint_name
]
@property
def right_hip_keypoint_index(self):
"""Gets right hip keypoint index."""
if not self._right_hip_keypoint_name:
raise ValueError('Right hip keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._right_hip_keypoint_name
]
@property
def left_knee_keypoint_index(self):
"""Gets left knee keypoint index."""
if not self._left_knee_keypoint_name:
raise ValueError('Left knee keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._left_knee_keypoint_name
]
@property
def right_knee_keypoint_index(self):
"""Gets right knee keypoint index."""
if not self._right_knee_keypoint_name:
raise ValueError('Right knee keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._right_knee_keypoint_name
]
@property
def left_ankle_keypoint_index(self):
"""Gets left ankle keypoint index."""
if not self._left_ankle_keypoint_name:
raise ValueError('Left ankle keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._left_ankle_keypoint_name
]
@property
def right_ankle_keypoint_index(self):
"""Gets right ankle keypoint index."""
if not self._right_ankle_keypoint_name:
raise ValueError('Right ankle keypoint is not specified.')
return [
self.keypoint_index(name, raise_error_if_not_found=True)
for name in self._right_ankle_keypoint_name
]
@property
def standard_part_names(self):
"""Gets all standard part names."""
return [
'HEAD', 'NECK', 'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_ELBOW',
'RIGHT_ELBOW', 'LEFT_WRIST', 'RIGHT_WRIST', 'SPINE', 'PELVIS',
'LEFT_HIP', 'RIGHT_HIP', 'LEFT_KNEE', 'RIGHT_KNEE', 'LEFT_ANKLE',
'RIGHT_ANKLE'
]
def get_standard_part_index(self, part_name):
"""Gets part index by standardized name."""
if part_name.upper() == 'HEAD':
return self.head_keypoint_index
if part_name.upper() == 'NECK':
return self.neck_keypoint_index
if part_name.upper() == 'LEFT_SHOULDER':
return self.left_shoulder_keypoint_index
if part_name.upper() == 'RIGHT_SHOULDER':
return self.right_shoulder_keypoint_index
if part_name.upper() == 'LEFT_ELBOW':
return self.left_elbow_keypoint_index
if part_name.upper() == 'RIGHT_ELBOW':
return self.right_elbow_keypoint_index
if part_name.upper() == 'LEFT_WRIST':
return self.left_wrist_keypoint_index
if part_name.upper() == 'RIGHT_WRIST':
return self.right_wrist_keypoint_index
if part_name.upper() == 'SPINE':
return self.spine_keypoint_index
if part_name.upper() == 'PELVIS':
return self.pelvis_keypoint_index
if part_name.upper() == 'LEFT_HIP':
return self.left_hip_keypoint_index
if part_name.upper() == 'RIGHT_HIP':
return self.right_hip_keypoint_index
if part_name.upper() == 'LEFT_KNEE':
return self.left_knee_keypoint_index
if part_name.upper() == 'RIGHT_KNEE':
return self.right_knee_keypoint_index
if part_name.upper() == 'LEFT_ANKLE':
return self.left_ankle_keypoint_index
if part_name.upper() == 'RIGHT_ANKLE':
return self.right_ankle_keypoint_index
raise ValueError('Unsupported part name: `%s`.' % part_name)
def normalize(self, keypoints, keypoint_masks=None):
"""Normalizes keypoints."""
del keypoint_masks
return keypoint_utils.normalize_points(
keypoints,
offset_point_indices=self._offset_keypoint_index,
scale_distance_point_index_pairs=self._scale_keypoint_index_pairs,
scale_distance_reduction_fn=self._scale_distance_reduction_fn,
scale_unit=self._scale_unit)
def denormalize(self,
normalized_keypoints,
offset_points,
scale_distances,
keypoint_masks=None):
"""Denormalizes keypoints."""
del keypoint_masks
return (normalized_keypoints / self._scale_unit * scale_distances +
offset_points)
class KeypointProfile3D(KeypointProfile):
"""3D keypoint profile base class."""
def __init__(self,
name,
keypoint_names,
offset_keypoint_names,
scale_keypoint_name_pairs,
segment_name_pairs,
scale_distance_reduction_fn=tf.math.reduce_sum,
scale_unit=1.0,
head_keypoint_name=None,
neck_keypoint_name=None,
left_shoulder_keypoint_name=None,
right_shoulder_keypoint_name=None,
left_elbow_keypoint_name=None,
right_elbow_keypoint_name=None,
left_wrist_keypoint_name=None,
right_wrist_keypoint_name=None,
spine_keypoint_name=None,
pelvis_keypoint_name=None,
left_hip_keypoint_name=None,
right_hip_keypoint_name=None,
left_knee_keypoint_name=None,
right_knee_keypoint_name=None,
left_ankle_keypoint_name=None,
right_ankle_keypoint_name=None):
"""Initializer."""
super(KeypointProfile3D, self).__init__(
name=name,
keypoint_names=keypoint_names,
offset_keypoint_names=offset_keypoint_names,
scale_keypoint_name_pairs=scale_keypoint_name_pairs,
scale_distance_reduction_fn=scale_distance_reduction_fn,
scale_unit=scale_unit,
segment_name_pairs=segment_name_pairs,
head_keypoint_name=head_keypoint_name,
neck_keypoint_name=neck_keypoint_name,
left_shoulder_keypoint_name=left_shoulder_keypoint_name,
right_shoulder_keypoint_name=right_shoulder_keypoint_name,
left_elbow_keypoint_name=left_elbow_keypoint_name,
right_elbow_keypoint_name=right_elbow_keypoint_name,
left_wrist_keypoint_name=left_wrist_keypoint_name,
right_wrist_keypoint_name=right_wrist_keypoint_name,
spine_keypoint_name=spine_keypoint_name,
pelvis_keypoint_name=pelvis_keypoint_name,
left_hip_keypoint_name=left_hip_keypoint_name,
right_hip_keypoint_name=right_hip_keypoint_name,
left_knee_keypoint_name=left_knee_keypoint_name,
right_knee_keypoint_name=right_knee_keypoint_name,
left_ankle_keypoint_name=left_ankle_keypoint_name,
right_ankle_keypoint_name=right_ankle_keypoint_name)
@property
def keypoint_dim(self):
"""Gets keypoint dimensionality."""
return 3
class KeypointProfile2D(KeypointProfile):
"""2D keypoint profile base class."""
def __init__(self,
name,
keypoint_names,
offset_keypoint_names,
scale_keypoint_name_pairs,
segment_name_pairs,
compatible_keypoint_name_dict=None,
scale_distance_reduction_fn=tf.math.reduce_max,
scale_unit=0.5,
head_keypoint_name=None,
neck_keypoint_name=None,
left_shoulder_keypoint_name=None,
right_shoulder_keypoint_name=None,
left_elbow_keypoint_name=None,
right_elbow_keypoint_name=None,
left_wrist_keypoint_name=None,
right_wrist_keypoint_name=None,
spine_keypoint_name=None,
pelvis_keypoint_name=None,
left_hip_keypoint_name=None,
right_hip_keypoint_name=None,
left_knee_keypoint_name=None,
right_knee_keypoint_name=None,
left_ankle_keypoint_name=None,
right_ankle_keypoint_name=None):
"""Initializer."""
super(KeypointProfile2D, self).__init__(
name=name,
keypoint_names=keypoint_names,
offset_keypoint_names=offset_keypoint_names,
scale_keypoint_name_pairs=scale_keypoint_name_pairs,
scale_distance_reduction_fn=scale_distance_reduction_fn,
scale_unit=scale_unit,
segment_name_pairs=segment_name_pairs,
head_keypoint_name=head_keypoint_name,
neck_keypoint_name=neck_keypoint_name,
left_shoulder_keypoint_name=left_shoulder_keypoint_name,
right_shoulder_keypoint_name=right_shoulder_keypoint_name,
left_elbow_keypoint_name=left_elbow_keypoint_name,
right_elbow_keypoint_name=right_elbow_keypoint_name,
left_wrist_keypoint_name=left_wrist_keypoint_name,
right_wrist_keypoint_name=right_wrist_keypoint_name,
spine_keypoint_name=spine_keypoint_name,
pelvis_keypoint_name=pelvis_keypoint_name,
left_hip_keypoint_name=left_hip_keypoint_name,
right_hip_keypoint_name=right_hip_keypoint_name,
left_knee_keypoint_name=left_knee_keypoint_name,
right_knee_keypoint_name=right_knee_keypoint_name,
left_ankle_keypoint_name=left_ankle_keypoint_name,
right_ankle_keypoint_name=right_ankle_keypoint_name)
self._compatible_keypoint_name_dict = {}
if compatible_keypoint_name_dict is not None:
for _, compatible_keypoint_names in compatible_keypoint_name_dict.items():
if len(compatible_keypoint_names) != len(self._keypoint_names):
raise ValueError('Compatible keypoint names must be of the same size '
'as keypoint names.')
self._compatible_keypoint_name_dict = compatible_keypoint_name_dict
@property
def keypoint_dim(self):
"""Gets keypoint dimensionality."""
return 2
@property
def compatible_keypoint_name_dict(self):
"""Gets compatible keypoint name dictionary."""
return self._compatible_keypoint_name_dict
class Std16KeypointProfile3D(KeypointProfile3D):
"""Standard 3D 16-keypoint profile."""
def __init__(self):
"""Initializer."""
super(Std16KeypointProfile3D,
self).__init__(
name='3DSTD16',
keypoint_names=[('HEAD', LeftRightType.CENTRAL),
('NECK', LeftRightType.CENTRAL),
('LEFT_SHOULDER', LeftRightType.LEFT),
('RIGHT_SHOULDER', LeftRightType.RIGHT),
('LEFT_ELBOW', LeftRightType.LEFT),
('RIGHT_ELBOW', LeftRightType.RIGHT),
('LEFT_WRIST', LeftRightType.LEFT),
('RIGHT_WRIST', LeftRightType.RIGHT),
('SPINE', LeftRightType.CENTRAL),
('PELVIS', LeftRightType.CENTRAL),
('LEFT_HIP', LeftRightType.LEFT),
('RIGHT_HIP', LeftRightType.RIGHT),
('LEFT_KNEE', LeftRightType.LEFT),
('RIGHT_KNEE', LeftRightType.RIGHT),
('LEFT_ANKLE', LeftRightType.LEFT),
('RIGHT_ANKLE', LeftRightType.RIGHT)],
offset_keypoint_names=['PELVIS'],
scale_keypoint_name_pairs=[(['NECK'], ['SPINE']),
(['SPINE'], ['PELVIS'])],
segment_name_pairs=[(['HEAD'], ['NECK']),
(['NECK'], ['LEFT_SHOULDER']),
(['NECK'], ['RIGHT_SHOULDER']),
(['NECK'], ['SPINE']),
(['LEFT_SHOULDER'], ['LEFT_ELBOW']),
(['RIGHT_SHOULDER'], ['RIGHT_ELBOW']),
(['LEFT_ELBOW'], ['LEFT_WRIST']),
(['RIGHT_ELBOW'], ['RIGHT_WRIST']),
(['SPINE'], ['PELVIS']),
(['PELVIS'], ['LEFT_HIP']),
(['PELVIS'], ['RIGHT_HIP']),
(['LEFT_HIP'], ['LEFT_KNEE']),
(['RIGHT_HIP'], ['RIGHT_KNEE']),
(['LEFT_KNEE'], ['LEFT_ANKLE']),
(['RIGHT_KNEE'], ['RIGHT_ANKLE'])],
head_keypoint_name=['HEAD'],
neck_keypoint_name=['NECK'],
left_shoulder_keypoint_name=['LEFT_SHOULDER'],
right_shoulder_keypoint_name=['RIGHT_SHOULDER'],
left_elbow_keypoint_name=['LEFT_ELBOW'],
right_elbow_keypoint_name=['RIGHT_ELBOW'],
left_wrist_keypoint_name=['LEFT_WRIST'],
right_wrist_keypoint_name=['RIGHT_WRIST'],
spine_keypoint_name=['SPINE'],
pelvis_keypoint_name=['PELVIS'],
left_hip_keypoint_name=['LEFT_HIP'],
right_hip_keypoint_name=['RIGHT_HIP'],
left_knee_keypoint_name=['LEFT_KNEE'],
right_knee_keypoint_name=['RIGHT_KNEE'],
left_ankle_keypoint_name=['LEFT_ANKLE'],
right_ankle_keypoint_name=['RIGHT_ANKLE'])
class Std13KeypointProfile3D(KeypointProfile3D):
"""Standard 3D 13-keypoint profile."""
def __init__(self):
"""Initializer."""
super(Std13KeypointProfile3D, self).__init__(
name='3DSTD13',
keypoint_names=[('HEAD', LeftRightType.CENTRAL),
('LEFT_SHOULDER', LeftRightType.LEFT),
('RIGHT_SHOULDER', LeftRightType.RIGHT),
('LEFT_ELBOW', LeftRightType.LEFT),
('RIGHT_ELBOW', LeftRightType.RIGHT),
('LEFT_WRIST', LeftRightType.LEFT),
('RIGHT_WRIST', LeftRightType.RIGHT),
('LEFT_HIP', LeftRightType.LEFT),
('RIGHT_HIP', LeftRightType.RIGHT),
('LEFT_KNEE', LeftRightType.LEFT),
('RIGHT_KNEE', LeftRightType.RIGHT),
('LEFT_ANKLE', LeftRightType.LEFT),
('RIGHT_ANKLE', LeftRightType.RIGHT)],
offset_keypoint_names=['LEFT_HIP', 'RIGHT_HIP'],
scale_keypoint_name_pairs=[(['LEFT_SHOULDER', 'RIGHT_SHOULDER'],
['LEFT_HIP', 'RIGHT_HIP'])],
segment_name_pairs=[
(['HEAD'], ['LEFT_SHOULDER', 'RIGHT_SHOULDER']),
(['LEFT_SHOULDER', 'RIGHT_SHOULDER'], ['LEFT_SHOULDER']),
(['LEFT_SHOULDER', 'RIGHT_SHOULDER'], ['RIGHT_SHOULDER']),
(['LEFT_SHOULDER', 'RIGHT_SHOULDER'],
['LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_HIP', 'RIGHT_HIP']),
(['LEFT_SHOULDER'], ['LEFT_ELBOW']),
(['RIGHT_SHOULDER'], ['RIGHT_ELBOW']),
(['LEFT_ELBOW'], ['LEFT_WRIST']),
(['RIGHT_ELBOW'], ['RIGHT_WRIST']),
(['LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_HIP',
'RIGHT_HIP'], ['LEFT_HIP', 'RIGHT_HIP']),
(['LEFT_HIP', 'RIGHT_HIP'], ['LEFT_HIP']),
(['LEFT_HIP', 'RIGHT_HIP'], ['RIGHT_HIP']),
(['LEFT_HIP'], ['LEFT_KNEE']), (['RIGHT_HIP'], ['RIGHT_KNEE']),
(['LEFT_KNEE'], ['LEFT_ANKLE']), (['RIGHT_KNEE'], ['RIGHT_ANKLE'])
],
head_keypoint_name=['HEAD'],
neck_keypoint_name=['LEFT_SHOULDER', 'RIGHT_SHOULDER'],
left_shoulder_keypoint_name=['LEFT_SHOULDER'],
right_shoulder_keypoint_name=['RIGHT_SHOULDER'],
left_elbow_keypoint_name=['LEFT_ELBOW'],
right_elbow_keypoint_name=['RIGHT_ELBOW'],
left_wrist_keypoint_name=['LEFT_WRIST'],
right_wrist_keypoint_name=['RIGHT_WRIST'],
spine_keypoint_name=[
'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_HIP', 'RIGHT_HIP'
],
pelvis_keypoint_name=['LEFT_HIP', 'RIGHT_HIP'],
left_hip_keypoint_name=['LEFT_HIP'],
right_hip_keypoint_name=['RIGHT_HIP'],
left_knee_keypoint_name=['LEFT_KNEE'],
right_knee_keypoint_name=['RIGHT_KNEE'],
left_ankle_keypoint_name=['LEFT_ANKLE'],
right_ankle_keypoint_name=['RIGHT_ANKLE'])
class LegacyH36m17KeypointProfile3D(KeypointProfile3D):
"""Legacy Human3.6M 3D 17-keypoint profile."""
def __init__(self):
"""Initializer."""
super(LegacyH36m17KeypointProfile3D, self).__init__(
name='LEGACY_3DH36M17',
keypoint_names=[('Hip', LeftRightType.CENTRAL),
('Head', LeftRightType.CENTRAL),
('Neck/Nose', LeftRightType.CENTRAL),
('Thorax', LeftRightType.CENTRAL),
('LShoulder', LeftRightType.LEFT),
('RShoulder', LeftRightType.RIGHT),
('LElbow', LeftRightType.LEFT),
('RElbow', LeftRightType.RIGHT),
('LWrist', LeftRightType.LEFT),
('RWrist', LeftRightType.RIGHT),
('Spine', LeftRightType.CENTRAL),
('LHip', LeftRightType.LEFT),
('RHip', LeftRightType.RIGHT),
('LKnee', LeftRightType.LEFT),
('RKnee', LeftRightType.RIGHT),
('LFoot', LeftRightType.LEFT),
('RFoot', LeftRightType.RIGHT)],
offset_keypoint_names=['Hip'],
scale_keypoint_name_pairs=[(['Hip'], ['Spine']),
(['Spine'], ['Thorax'])],
segment_name_pairs=[(['Hip'], ['Spine']), (['Hip'], ['LHip']),
(['Hip'], ['RHip']), (['Spine'], ['Thorax']),
(['LHip'], ['LKnee']), (['RHip'], ['RKnee']),
(['LKnee'], ['LFoot']), (['RKnee'], ['RFoot']),
(['Thorax'], ['Neck/Nose']),
(['Thorax'], ['LShoulder']),
(['Thorax'], ['RShoulder']),
(['Neck/Nose'], ['Head']),
(['LShoulder'], ['LElbow']),
(['RShoulder'], ['RElbow']),
(['LElbow'], ['LWrist']), (['RElbow'], ['RWrist'])],
head_keypoint_name=['Head'],
neck_keypoint_name=['Thorax'],
left_shoulder_keypoint_name=['LShoulder'],
right_shoulder_keypoint_name=['RShoulder'],
left_elbow_keypoint_name=['LElbow'],
right_elbow_keypoint_name=['RElbow'],
left_wrist_keypoint_name=['LWrist'],
right_wrist_keypoint_name=['RWrist'],
spine_keypoint_name=['Spine'],
pelvis_keypoint_name=['Hip'],
left_hip_keypoint_name=['LHip'],
right_hip_keypoint_name=['RHip'],
left_knee_keypoint_name=['LKnee'],
right_knee_keypoint_name=['RKnee'],
left_ankle_keypoint_name=['LFoot'],
right_ankle_keypoint_name=['RFoot'])
class LegacyH36m13KeypointProfile3D(KeypointProfile3D):
"""Legacy Human3.6M 3D 13-keypoint profile."""
def __init__(self):
"""Initializer."""
super(LegacyH36m13KeypointProfile3D, self).__init__(
name='LEGACY_3DH36M13',
keypoint_names=[('Head', LeftRightType.CENTRAL),
('LShoulder', LeftRightType.LEFT),
('RShoulder', LeftRightType.RIGHT),
('LElbow', LeftRightType.LEFT),
('RElbow', LeftRightType.RIGHT),
('LWrist', LeftRightType.LEFT),
('RWrist', LeftRightType.RIGHT),
('LHip', LeftRightType.LEFT),
('RHip', LeftRightType.RIGHT),
('LKnee', LeftRightType.LEFT),
('RKnee', LeftRightType.RIGHT),
('LFoot', LeftRightType.LEFT),
('RFoot', LeftRightType.RIGHT)],
offset_keypoint_names=['LHip'],
scale_keypoint_name_pairs=[
(['LHip', 'RHip'], ['LShoulder', 'RShoulder']),
],
segment_name_pairs=[(['LHip', 'RHip'], ['LShoulder', 'RShoulder']),
(['LHip', 'RHip'], ['LHip']),
(['LHip', 'RHip'], ['RHip']), (['LHip'], ['LKnee']),
(['RHip'], ['RKnee']), (['LKnee'], ['LFoot']),
(['RKnee'], ['RFoot']),
(['LShoulder', 'RShoulder'], ['Head']),
(['LShoulder', 'RShoulder'], ['LShoulder']),
(['LShoulder', 'RShoulder'], ['RShoulder']),
(['LShoulder'], ['LElbow']),
(['RShoulder'], ['RElbow']),
(['LElbow'], ['LWrist']), (['RElbow'], ['RWrist'])],
head_keypoint_name=['Head'],
neck_keypoint_name=['LShoulder', 'RShoulder'],
left_shoulder_keypoint_name=['LShoulder'],
right_shoulder_keypoint_name=['RShoulder'],
left_elbow_keypoint_name=['LElbow'],
right_elbow_keypoint_name=['RElbow'],
left_wrist_keypoint_name=['LWrist'],
right_wrist_keypoint_name=['RWrist'],
spine_keypoint_name=['LShoulder', 'RShoulder', 'LHip', 'RHip'],
pelvis_keypoint_name=['LHip', 'RHip'],
left_hip_keypoint_name=['LHip'],
right_hip_keypoint_name=['RHip'],
left_knee_keypoint_name=['LKnee'],
right_knee_keypoint_name=['RKnee'],
left_ankle_keypoint_name=['LFoot'],
right_ankle_keypoint_name=['RFoot'])
class LegacyMpii3dhp17KeypointProfile3D(KeypointProfile3D):
"""Legacy MPII-3DHP 3D 17-keypoint profile."""
def __init__(self):
"""Initializer."""
super(LegacyMpii3dhp17KeypointProfile3D, self).__init__(
name='LEGACY_3DMPII3DHP17',
keypoint_names=[('pelvis', LeftRightType.CENTRAL),
('head', LeftRightType.CENTRAL),
('neck', LeftRightType.CENTRAL),
('head_top', LeftRightType.CENTRAL),
('left_shoulder', LeftRightType.LEFT),
('right_shoulder', LeftRightType.RIGHT),
('left_elbow', LeftRightType.LEFT),
('right_elbow', LeftRightType.RIGHT),
('left_wrist', LeftRightType.LEFT),
('right_wrist', LeftRightType.RIGHT),
('spine', LeftRightType.CENTRAL),
('left_hip', LeftRightType.LEFT),
('right_hip', LeftRightType.RIGHT),
('left_knee', LeftRightType.LEFT),
('right_knee', LeftRightType.RIGHT),
('left_ankle', LeftRightType.LEFT),
('right_ankle', LeftRightType.RIGHT)],
offset_keypoint_names=['pelvis'],
scale_keypoint_name_pairs=[(['pelvis'], ['spine']),
(['spine'], ['neck'])],
segment_name_pairs=[(['pelvis'], ['spine']), (['pelvis'], ['left_hip']),
(['pelvis'], ['right_hip']), (['spine'], ['neck']),
(['left_hip'], ['left_knee']),
(['right_hip'], ['right_knee']),
(['left_knee'], ['left_ankle']),
(['right_knee'], ['right_ankle']),
(['neck'], ['head']), (['neck'], ['left_shoulder']),
(['neck'], ['right_shoulder']),
(['head'], ['head_top']),
(['left_shoulder'], ['left_elbow']),
(['right_shoulder'], ['right_elbow']),
(['left_elbow'], ['left_wrist']),
(['right_elbow'], ['right_wrist'])],
head_keypoint_name=['head'],
neck_keypoint_name=['neck'],
left_shoulder_keypoint_name=['left_shoulder'],
right_shoulder_keypoint_name=['right_shoulder'],
left_elbow_keypoint_name=['left_elbow'],
right_elbow_keypoint_name=['right_elbow'],
left_wrist_keypoint_name=['left_wrist'],
right_wrist_keypoint_name=['right_wrist'],
spine_keypoint_name=['spine'],
pelvis_keypoint_name=['pelvis'],
left_hip_keypoint_name=['left_hip'],
right_hip_keypoint_name=['right_hip'],
left_knee_keypoint_name=['left_knee'],
right_knee_keypoint_name=['right_knee'],
left_ankle_keypoint_name=['left_ankle'],
right_ankle_keypoint_name=['right_ankle'])
class Std13KeypointProfile2D(KeypointProfile2D):
"""Standard 2D 13-keypoint profile."""
def __init__(self):
"""Initializer."""
super(Std13KeypointProfile2D, self).__init__(
name='2DSTD13',
keypoint_names=[('NOSE_TIP', LeftRightType.CENTRAL),
('LEFT_SHOULDER', LeftRightType.LEFT),
('RIGHT_SHOULDER', LeftRightType.RIGHT),
('LEFT_ELBOW', LeftRightType.LEFT),
('RIGHT_ELBOW', LeftRightType.RIGHT),
('LEFT_WRIST', LeftRightType.LEFT),
('RIGHT_WRIST', LeftRightType.RIGHT),
('LEFT_HIP', LeftRightType.LEFT),
('RIGHT_HIP', LeftRightType.RIGHT),
('LEFT_KNEE', LeftRightType.LEFT),
('RIGHT_KNEE', LeftRightType.RIGHT),
('LEFT_ANKLE', LeftRightType.LEFT),
('RIGHT_ANKLE', LeftRightType.RIGHT)],
offset_keypoint_names=['LEFT_HIP', 'RIGHT_HIP'],
scale_keypoint_name_pairs=[(['LEFT_SHOULDER'], ['RIGHT_SHOULDER']),
(['LEFT_SHOULDER'], ['LEFT_HIP']),
(['LEFT_SHOULDER'], ['RIGHT_HIP']),
(['RIGHT_SHOULDER'], ['LEFT_HIP']),
(['RIGHT_SHOULDER'], ['RIGHT_HIP']),
(['LEFT_HIP'], ['RIGHT_HIP'])],
segment_name_pairs=[(['NOSE_TIP'], ['LEFT_SHOULDER']),
(['NOSE_TIP'], ['RIGHT_SHOULDER']),
(['LEFT_SHOULDER'], ['RIGHT_SHOULDER']),
(['LEFT_SHOULDER'], ['LEFT_ELBOW']),
(['RIGHT_SHOULDER'], ['RIGHT_ELBOW']),
(['LEFT_ELBOW'], ['LEFT_WRIST']),
(['RIGHT_ELBOW'], ['RIGHT_WRIST']),
(['LEFT_SHOULDER'], ['LEFT_HIP']),
(['RIGHT_SHOULDER'], ['RIGHT_HIP']),
(['LEFT_HIP'], ['RIGHT_HIP']),
(['LEFT_HIP'], ['LEFT_KNEE']),
(['RIGHT_HIP'], ['RIGHT_KNEE']),
(['LEFT_KNEE'], ['LEFT_ANKLE']),
(['RIGHT_KNEE'], ['RIGHT_ANKLE'])],
compatible_keypoint_name_dict={
'3DSTD16': [
'HEAD', 'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_ELBOW',
'RIGHT_ELBOW', 'LEFT_WRIST', 'RIGHT_WRIST', 'LEFT_HIP',
'RIGHT_HIP', 'LEFT_KNEE', 'RIGHT_KNEE', 'LEFT_ANKLE',
'RIGHT_ANKLE'
],
'3DSTD13': [
'HEAD', 'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_ELBOW',
'RIGHT_ELBOW', 'LEFT_WRIST', 'RIGHT_WRIST', 'LEFT_HIP',
'RIGHT_HIP', 'LEFT_KNEE', 'RIGHT_KNEE', 'LEFT_ANKLE',
'RIGHT_ANKLE'
],
'LEGACY_3DH36M17': [
'Head', 'LShoulder', 'RShoulder', 'LElbow', 'RElbow', 'LWrist',
'RWrist', 'LHip', 'RHip', 'LKnee', 'RKnee', 'LFoot', 'RFoot'
],
'LEGACY_3DMPII3DHP17': [
'head', 'left_shoulder', 'right_shoulder', 'left_elbow',
'right_elbow', 'left_wrist', 'right_wrist', 'left_hip',
'right_hip', 'left_knee', 'right_knee', 'left_ankle',
'right_ankle'
],
},
head_keypoint_name=['NOSE_TIP'],
neck_keypoint_name=['LEFT_SHOULDER', 'RIGHT_SHOULDER'],
left_shoulder_keypoint_name=['LEFT_SHOULDER'],
right_shoulder_keypoint_name=['RIGHT_SHOULDER'],
left_elbow_keypoint_name=['LEFT_ELBOW'],
right_elbow_keypoint_name=['RIGHT_ELBOW'],
left_wrist_keypoint_name=['LEFT_WRIST'],
right_wrist_keypoint_name=['RIGHT_WRIST'],
spine_keypoint_name=[
'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_HIP', 'RIGHT_HIP'
],
pelvis_keypoint_name=['LEFT_HIP', 'RIGHT_HIP'],
left_hip_keypoint_name=['LEFT_HIP'],
right_hip_keypoint_name=['RIGHT_HIP'],
left_knee_keypoint_name=['LEFT_KNEE'],
right_knee_keypoint_name=['RIGHT_KNEE'],
left_ankle_keypoint_name=['LEFT_ANKLE'],
right_ankle_keypoint_name=['RIGHT_ANKLE'])
class LegacyCoco13KeypointProfile2D(Std13KeypointProfile2D):
"""Legacy COCO 2D 13-keypoint profile.
This profile is the same as the `2DSTD13` profil, except the name.
"""
def __init__(self):
"""Initializer."""
super(LegacyCoco13KeypointProfile2D, self).__init__()
self._name = 'LEGACY_2DCOCO13'
class LegacyH36m13KeypointProfile2D(KeypointProfile2D):
"""Legacy Human3.6M 2D 13-keypoint profile."""
def __init__(self):
"""Initializer."""
super(LegacyH36m13KeypointProfile2D,
self).__init__(
name='LEGACY_2DH36M13',
keypoint_names=[('Head', LeftRightType.CENTRAL),
('LShoulder', LeftRightType.LEFT),
('RShoulder', LeftRightType.RIGHT),
('LElbow', LeftRightType.LEFT),
('RElbow', LeftRightType.RIGHT),
('LWrist', LeftRightType.LEFT),
('RWrist', LeftRightType.RIGHT),
('LHip', LeftRightType.LEFT),
('RHip', LeftRightType.RIGHT),
('LKnee', LeftRightType.LEFT),
('RKnee', LeftRightType.RIGHT),
('LFoot', LeftRightType.LEFT),
('RFoot', LeftRightType.RIGHT)],
offset_keypoint_names=['LHip', 'RHip'],
scale_keypoint_name_pairs=[(['LShoulder'], ['RShoulder']),
(['LShoulder'], ['LHip']),
(['LShoulder'], ['RHip']),
(['RShoulder'], ['LHip']),
(['RShoulder'], ['RHip']),
(['LHip'], ['RHip'])],
segment_name_pairs=[(['Head'], ['LShoulder']),
(['Head'], ['RShoulder']),
(['LShoulder'], ['LElbow']),
(['LElbow'], ['LWrist']),
(['RShoulder'], ['RElbow']),
(['RElbow'], ['RWrist']),
(['LShoulder'], ['LHip']),
(['RShoulder'], ['RHip']),
(['LHip'], ['LKnee']), (['LKnee'], ['LFoot']),
(['RHip'], ['RKnee']), (['RKnee'], ['RFoot']),
(['LShoulder'], ['RShoulder']),
(['LHip'], ['RHip'])],
compatible_keypoint_name_dict={
'3DSTD16': [
'HEAD', 'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_ELBOW',
'RIGHT_ELBOW', 'LEFT_WRIST', 'RIGHT_WRIST', 'LEFT_HIP',
'RIGHT_HIP', 'LEFT_KNEE', 'RIGHT_KNEE', 'LEFT_ANKLE',
'RIGHT_ANKLE'
],
'3DSTD13': [
'HEAD', 'LEFT_SHOULDER', 'RIGHT_SHOULDER', 'LEFT_ELBOW',
'RIGHT_ELBOW', 'LEFT_WRIST', 'RIGHT_WRIST', 'LEFT_HIP',
'RIGHT_HIP', 'LEFT_KNEE', 'RIGHT_KNEE', 'LEFT_ANKLE',
'RIGHT_ANKLE'
],
'LEGACY_3DH36M17': [
'Head', 'LShoulder', 'RShoulder', 'LElbow', 'RElbow',
'LWrist', 'RWrist', 'LHip', 'RHip', 'LKnee', 'RKnee',
'LFoot', 'RFoot'
],
'LEGACY_3DMPII3DHP17': [
'head', 'left_shoulder', 'right_shoulder', 'left_elbow',
'right_elbow', 'left_wrist', 'right_wrist', 'left_hip',
'right_hip', 'left_knee', 'right_knee', 'left_ankle',
'right_ankle'
],
},
head_keypoint_name=['Head'],
neck_keypoint_name=['LShoulder', 'RShoulder'],
left_shoulder_keypoint_name=['LShoulder'],
right_shoulder_keypoint_name=['RShoulder'],
left_elbow_keypoint_name=['LElbow'],
right_elbow_keypoint_name=['RElbow'],
left_wrist_keypoint_name=['LWrist'],
right_wrist_keypoint_name=['RWrist'],
spine_keypoint_name=['LShoulder', 'RShoulder', 'LHip', 'RHip'],
pelvis_keypoint_name=['LHip', 'RHip'],
left_hip_keypoint_name=['LHip'],
right_hip_keypoint_name=['RHip'],
left_knee_keypoint_name=['LKnee'],
right_knee_keypoint_name=['RKnee'],
left_ankle_keypoint_name=['LFoot'],
right_ankle_keypoint_name=['RFoot'])
def create_keypoint_profile_or_die(keypoint_profile_name):
"""Creates keypoint profile based on name.
Args:
keypoint_profile_name: A string for keypoint profile name.
Returns:
A keypint profile class object.
Raises:
ValueError: If keypoint profile name is unsupported.
"""
if keypoint_profile_name == '3DSTD16':
return Std16KeypointProfile3D()
if keypoint_profile_name == '3DSTD13':
return Std13KeypointProfile3D()
if keypoint_profile_name == 'LEGACY_3DH36M17':
return LegacyH36m17KeypointProfile3D()
if keypoint_profile_name == 'LEGACY_3DH36M13':
return LegacyH36m13KeypointProfile3D()
if keypoint_profile_name == 'LEGACY_3DMPII3DHP17':
return LegacyMpii3dhp17KeypointProfile3D()
if keypoint_profile_name == '2DSTD13':
return Std13KeypointProfile2D()
if keypoint_profile_name == 'LEGACY_2DCOCO13':
return LegacyCoco13KeypointProfile2D()
if keypoint_profile_name == 'LEGACY_2DH36M13':
return LegacyH36m13KeypointProfile2D()
raise ValueError('Unsupported keypoint profile name: `%s`.' %
str(keypoint_profile_name))
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
499,
15385,
710,
4475,
26993,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
1197,
1403,
4690,
1021,
436,
11420,
3423,
1041,
199,
199,
646,
13022,
199,
646,
4952,
199,
199,
646,
3816,
199,
646,
3228,
465,
2833,
199,
199,
504,
1115,
5633,
14,
1018,
492,
790,
1403,
63,
1208,
421,
199,
533,
29350,
9121,
804,
8,
4869,
14,
5081,
304,
523,
408,
1197,
1403,
15,
9255,
3602,
15,
1019,
730,
1041,
523,
24740,
275,
378,
523,
445,
1309,
50,
748,
275,
413,
523,
6578,
275,
499,
523,
7052,
275,
650,
421,
199,
318,
18538,
63,
498,
1403,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
4918,
304,
523,
408,
17354,
1192,
790,
1403,
3602,
15,
1019,
730,
14,
819,
710,
22515,
3602,
15,
1019,
730,
365,
12985,
770,
465,
11924,
26,
523,
413,
14,
982,
1902,
730,
365,
24740,
12,
2529,
24740,
14,
523,
499,
14,
982,
3865,
2943,
787,
314,
2011,
12,
2529,
642,
730,
14,
523,
650,
14,
982,
1373,
730,
365,
445,
1309,
50,
748,
12,
436,
314,
1163,
730,
365,
6578,
503,
7052,
12,
2529,
314,
1362,
1163,
730,
14,
523,
841,
14,
982,
1373,
730,
365,
6578,
436,
314,
1163,
730,
365,
7052,
12,
2529,
445,
1309,
50,
748,
14,
819,
3033,
26,
272,
3602,
63,
1019,
63,
1313,
26,
437,
769,
402,
29350,
9121,
804,
4952,
1338,
367,
1006,
790,
3438,
14,
272,
4918,
26,
437,
769,
402,
9446,
367,
790,
1403,
4918,
14,
819,
1803,
26,
272,
437,
29350,
9121,
804,
4952,
574,
367,
22515,
730,
14,
819,
6218,
26,
272,
1722,
26,
982,
1263,
1478,
365,
734,
402,
1425,
14,
523,
408,
523,
340,
440,
4918,
26,
272,
372,
29350,
9121,
804,
14,
11588,
819,
347,
4237,
8,
73,
304,
272,
340,
284,
665,
378,
503,
284,
2356,
822,
8,
3039,
63,
1019,
63,
1313,
304,
489,
746,
1722,
360,
8185,
15,
1019,
730,
1478,
365,
734,
402,
1425,
26,
450,
68,
3530,
450,
284,
9,
272,
372,
3602,
63,
1019,
63,
1313,
59,
73,
61,
819,
340,
822,
8,
4108,
9,
508,
413,
26,
272,
372,
4237,
8,
4108,
59,
16,
566,
819,
1072,
63,
466,
275,
29350,
9121,
804,
14,
17349,
50,
748,
523,
367,
284,
315,
4918,
26,
272,
1453,
63,
466,
275,
4237,
8,
73,
9,
272,
340,
1453,
63,
466,
508,
29350,
9121,
804,
14,
11588,
26,
489,
372,
29350,
9121,
804,
14,
11588,
272,
340,
1072,
63,
466,
508,
29350,
9121,
804,
14,
17349,
50,
748,
26,
489,
1072,
63,
466,
275,
1453,
63,
466,
272,
916,
1453,
63,
466,
1137,
29350,
9121,
804,
14,
17349,
50,
748,
436,
1453,
63,
466,
1137,
1072,
63,
466,
26,
489,
1072,
63,
466,
275,
29350,
9121,
804,
14,
17349,
50,
748,
523,
372,
1072,
63,
466,
421,
199,
318,
18538,
63,
9255,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
1343,
63,
4108,
12,
1284,
63,
4108,
304,
523,
408,
17354,
1192,
8135,
3602,
15,
1019,
730,
14,
819,
710,
22515,
3602,
15,
1019,
730,
365,
12985,
770,
465,
11924,
26,
523,
413,
14,
982,
1902,
730,
365,
24740,
12,
2529,
24740,
14,
523,
499,
14,
982,
3865,
2943,
787,
314,
2011,
12,
2529,
642,
730,
14,
523,
650,
14,
982,
1373,
730,
365,
445,
1309,
50,
748,
12,
436,
314,
1163,
730,
365,
6578,
503,
7052,
12,
2529,
314,
1362,
1163,
730,
14,
523,
841,
14,
982,
1373,
730,
365,
6578,
436,
314,
1163,
730,
365,
7052,
12,
2529,
445,
1309,
50,
748,
14,
819,
3033,
26,
272,
3602,
63,
1019,
63,
1313,
26,
437,
769,
402,
29350,
9121,
804,
4952,
1338,
367,
1006,
790,
3438,
14,
272,
1343,
63,
4108,
26,
437,
769,
402,
9446,
367,
491,
15467,
790,
1403,
4918,
14,
272,
1284,
63,
4108,
26,
437,
769,
402,
9446,
367,
820,
15467,
790,
1403,
4918,
14,
819,
1803,
26,
272,
437,
29350,
9121,
804,
4952,
574,
367,
22515,
730,
14,
523,
408,
523,
13180,
63,
466,
275,
18538,
63,
498,
1403,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
1343,
63,
4108,
9,
523,
9085,
63,
466,
275,
18538,
63,
498,
1403,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
1284,
63,
4108,
9,
523,
340,
13180,
63,
466,
508,
29350,
9121,
804,
14,
11588,
503,
9085,
63,
466,
508,
29350,
9121,
804,
14,
11588,
26,
272,
372,
29350,
9121,
804,
14,
11588,
523,
340,
13180,
63,
466,
508,
29350,
9121,
804,
14,
17349,
50,
748,
26,
272,
372,
9085,
63,
466,
523,
340,
9085,
63,
466,
508,
29350,
9121,
804,
14,
17349,
50,
748,
26,
272,
372,
13180,
63,
466,
523,
372,
13180,
63,
466,
340,
13180,
63,
466,
508,
9085,
63,
466,
587,
29350,
9121,
804,
14,
17349,
50,
748,
421,
199,
533,
2606,
1403,
5736,
8,
4174,
14,
1045,
63,
6577,
8,
3175,
14,
22254,
12,
909,
2298,
523,
408,
1197,
1403,
4690,
1300,
1021,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
536,
12,
2049,
790,
1403,
63,
1247,
12,
2049,
3268,
63,
498,
1403,
63,
1247,
12,
2049,
4666,
63,
498,
1403,
63,
354,
63,
7322,
12,
2049,
4666,
63,
5590,
63,
22508,
63,
2324,
12,
2049,
4666,
63,
3248,
12,
2049,
8135,
63,
354,
63,
7322,
12,
2049,
4854,
63,
498,
1403,
63,
354
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
499,
15385,
710,
4475,
26993,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
1197,
1403,
4690,
1021,
436,
11420,
3423,
1041,
199,
199,
646,
13022,
199,
646,
4952,
199,
199,
646,
3816,
199,
646,
3228,
465,
2833,
199,
199,
504,
1115,
5633,
14,
1018,
492,
790,
1403,
63,
1208,
421,
199,
533,
29350,
9121,
804,
8,
4869,
14,
5081,
304,
523,
408,
1197,
1403,
15,
9255,
3602,
15,
1019,
730,
1041,
523,
24740,
275,
378,
523,
445,
1309,
50,
748,
275,
413,
523,
6578,
275,
499,
523,
7052,
275,
650,
421,
199,
318,
18538,
63,
498,
1403,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
4918,
304,
523,
408,
17354,
1192,
790,
1403,
3602,
15,
1019,
730,
14,
819,
710,
22515,
3602,
15,
1019,
730,
365,
12985,
770,
465,
11924,
26,
523,
413,
14,
982,
1902,
730,
365,
24740,
12,
2529,
24740,
14,
523,
499,
14,
982,
3865,
2943,
787,
314,
2011,
12,
2529,
642,
730,
14,
523,
650,
14,
982,
1373,
730,
365,
445,
1309,
50,
748,
12,
436,
314,
1163,
730,
365,
6578,
503,
7052,
12,
2529,
314,
1362,
1163,
730,
14,
523,
841,
14,
982,
1373,
730,
365,
6578,
436,
314,
1163,
730,
365,
7052,
12,
2529,
445,
1309,
50,
748,
14,
819,
3033,
26,
272,
3602,
63,
1019,
63,
1313,
26,
437,
769,
402,
29350,
9121,
804,
4952,
1338,
367,
1006,
790,
3438,
14,
272,
4918,
26,
437,
769,
402,
9446,
367,
790,
1403,
4918,
14,
819,
1803,
26,
272,
437,
29350,
9121,
804,
4952,
574,
367,
22515,
730,
14,
819,
6218,
26,
272,
1722,
26,
982,
1263,
1478,
365,
734,
402,
1425,
14,
523,
408,
523,
340,
440,
4918,
26,
272,
372,
29350,
9121,
804,
14,
11588,
819,
347,
4237,
8,
73,
304,
272,
340,
284,
665,
378,
503,
284,
2356,
822,
8,
3039,
63,
1019,
63,
1313,
304,
489,
746,
1722,
360,
8185,
15,
1019,
730,
1478,
365,
734,
402,
1425,
26,
450,
68,
3530,
450,
284,
9,
272,
372,
3602,
63,
1019,
63,
1313,
59,
73,
61,
819,
340,
822,
8,
4108,
9,
508,
413,
26,
272,
372,
4237,
8,
4108,
59,
16,
566,
819,
1072,
63,
466,
275,
29350,
9121,
804,
14,
17349,
50,
748,
523,
367,
284,
315,
4918,
26,
272,
1453,
63,
466,
275,
4237,
8,
73,
9,
272,
340,
1453,
63,
466,
508,
29350,
9121,
804,
14,
11588,
26,
489,
372,
29350,
9121,
804,
14,
11588,
272,
340,
1072,
63,
466,
508,
29350,
9121,
804,
14,
17349,
50,
748,
26,
489,
1072,
63,
466,
275,
1453,
63,
466,
272,
916,
1453,
63,
466,
1137,
29350,
9121,
804,
14,
17349,
50,
748,
436,
1453,
63,
466,
1137,
1072,
63,
466,
26,
489,
1072,
63,
466,
275,
29350,
9121,
804,
14,
17349,
50,
748,
523,
372,
1072,
63,
466,
421,
199,
318,
18538,
63,
9255,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
1343,
63,
4108,
12,
1284,
63,
4108,
304,
523,
408,
17354,
1192,
8135,
3602,
15,
1019,
730,
14,
819,
710,
22515,
3602,
15,
1019,
730,
365,
12985,
770,
465,
11924,
26,
523,
413,
14,
982,
1902,
730,
365,
24740,
12,
2529,
24740,
14,
523,
499,
14,
982,
3865,
2943,
787,
314,
2011,
12,
2529,
642,
730,
14,
523,
650,
14,
982,
1373,
730,
365,
445,
1309,
50,
748,
12,
436,
314,
1163,
730,
365,
6578,
503,
7052,
12,
2529,
314,
1362,
1163,
730,
14,
523,
841,
14,
982,
1373,
730,
365,
6578,
436,
314,
1163,
730,
365,
7052,
12,
2529,
445,
1309,
50,
748,
14,
819,
3033,
26,
272,
3602,
63,
1019,
63,
1313,
26,
437,
769,
402,
29350,
9121,
804,
4952,
1338,
367,
1006,
790,
3438,
14,
272,
1343,
63,
4108,
26,
437,
769,
402,
9446,
367,
491,
15467,
790,
1403,
4918,
14,
272,
1284,
63,
4108,
26,
437,
769,
402,
9446,
367,
820,
15467,
790,
1403,
4918,
14,
819,
1803,
26,
272,
437,
29350,
9121,
804,
4952,
574,
367,
22515,
730,
14,
523,
408,
523,
13180,
63,
466,
275,
18538,
63,
498,
1403,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
1343,
63,
4108,
9,
523,
9085,
63,
466,
275,
18538,
63,
498,
1403,
63,
3039,
63,
1019,
63,
466,
8,
3039,
63,
1019,
63,
1313,
12,
1284,
63,
4108,
9,
523,
340,
13180,
63,
466,
508,
29350,
9121,
804,
14,
11588,
503,
9085,
63,
466,
508,
29350,
9121,
804,
14,
11588,
26,
272,
372,
29350,
9121,
804,
14,
11588,
523,
340,
13180,
63,
466,
508,
29350,
9121,
804,
14,
17349,
50,
748,
26,
272,
372,
9085,
63,
466,
523,
340,
9085,
63,
466,
508,
29350,
9121,
804,
14,
17349,
50,
748,
26,
272,
372,
13180,
63,
466,
523,
372,
13180,
63,
466,
340,
13180,
63,
466,
508,
9085,
63,
466,
587,
29350,
9121,
804,
14,
17349,
50,
748,
421,
199,
533,
2606,
1403,
5736,
8,
4174,
14,
1045,
63,
6577,
8,
3175,
14,
22254,
12,
909,
2298,
523,
408,
1197,
1403,
4690,
1300,
1021,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
536,
12,
2049,
790,
1403,
63,
1247,
12,
2049,
3268,
63,
498,
1403,
63,
1247,
12,
2049,
4666,
63,
498,
1403,
63,
354,
63,
7322,
12,
2049,
4666,
63,
5590,
63,
22508,
63,
2324,
12,
2049,
4666,
63,
3248,
12,
2049,
8135,
63,
354,
63,
7322,
12,
2049,
4854,
63,
498,
1403,
63,
354,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mollstam/UnrealPy
|
UnrealPyEmbed/Development/Python/2015.08.07-Python2710-x64-Source-vs2015/Python27/Source/boto-2.38.0/boto/sqs/queue.py
|
60
|
17724
|
# Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""
Represents an SQS Queue
"""
from boto.compat import urllib
from boto.sqs.message import Message
class Queue(object):
def __init__(self, connection=None, url=None, message_class=Message):
self.connection = connection
self.url = url
self.message_class = message_class
self.visibility_timeout = None
def __repr__(self):
return 'Queue(%s)' % self.url
def _id(self):
if self.url:
val = urllib.parse.urlparse(self.url)[2]
else:
val = self.url
return val
id = property(_id)
def _name(self):
if self.url:
val = urllib.parse.urlparse(self.url)[2].split('/')[2]
else:
val = self.url
return val
name = property(_name)
def _arn(self):
parts = self.id.split('/')
return 'arn:aws:sqs:%s:%s:%s' % (
self.connection.region.name, parts[1], parts[2])
arn = property(_arn)
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
if name == 'QueueUrl':
self.url = value
elif name == 'VisibilityTimeout':
self.visibility_timeout = int(value)
else:
setattr(self, name, value)
def set_message_class(self, message_class):
"""
Set the message class that should be used when instantiating
messages read from the queue. By default, the class
:class:`boto.sqs.message.Message` is used but this can be overriden
with any class that behaves like a message.
:type message_class: Message-like class
:param message_class: The new Message class
"""
self.message_class = message_class
def get_attributes(self, attributes='All'):
"""
Retrieves attributes about this queue object and returns
them in an Attribute instance (subclass of a Dictionary).
:type attributes: string
:param attributes: String containing one of:
ApproximateNumberOfMessages,
ApproximateNumberOfMessagesNotVisible,
VisibilityTimeout,
CreatedTimestamp,
LastModifiedTimestamp,
Policy
ReceiveMessageWaitTimeSeconds
:rtype: Attribute object
:return: An Attribute object which is a mapping type holding the
requested name/value pairs
"""
return self.connection.get_queue_attributes(self, attributes)
def set_attribute(self, attribute, value):
"""
Set a new value for an attribute of the Queue.
:type attribute: String
:param attribute: The name of the attribute you want to set. The
only valid value at this time is: VisibilityTimeout
:type value: int
:param value: The new value for the attribute.
For VisibilityTimeout the value must be an
integer number of seconds from 0 to 86400.
:rtype: bool
:return: True if successful, otherwise False.
"""
return self.connection.set_queue_attribute(self, attribute, value)
def get_timeout(self):
"""
Get the visibility timeout for the queue.
:rtype: int
:return: The number of seconds as an integer.
"""
a = self.get_attributes('VisibilityTimeout')
return int(a['VisibilityTimeout'])
def set_timeout(self, visibility_timeout):
"""
Set the visibility timeout for the queue.
:type visibility_timeout: int
:param visibility_timeout: The desired timeout in seconds
"""
retval = self.set_attribute('VisibilityTimeout', visibility_timeout)
if retval:
self.visibility_timeout = visibility_timeout
return retval
def add_permission(self, label, aws_account_id, action_name):
"""
Add a permission to a queue.
:type label: str or unicode
:param label: A unique identification of the permission you are setting.
Maximum of 80 characters ``[0-9a-zA-Z_-]``
Example, AliceSendMessage
:type aws_account_id: str or unicode
:param principal_id: The AWS account number of the principal who
will be given permission. The principal must have an AWS account,
but does not need to be signed up for Amazon SQS. For information
about locating the AWS account identification.
:type action_name: str or unicode
:param action_name: The action. Valid choices are:
SendMessage|ReceiveMessage|DeleteMessage|
ChangeMessageVisibility|GetQueueAttributes|*
:rtype: bool
:return: True if successful, False otherwise.
"""
return self.connection.add_permission(self, label, aws_account_id,
action_name)
def remove_permission(self, label):
"""
Remove a permission from a queue.
:type label: str or unicode
:param label: The unique label associated with the permission
being removed.
:rtype: bool
:return: True if successful, False otherwise.
"""
return self.connection.remove_permission(self, label)
def read(self, visibility_timeout=None, wait_time_seconds=None,
message_attributes=None):
"""
Read a single message from the queue.
:type visibility_timeout: int
:param visibility_timeout: The timeout for this message in seconds
:type wait_time_seconds: int
:param wait_time_seconds: The duration (in seconds) for which the call
will wait for a message to arrive in the queue before returning.
If a message is available, the call will return sooner than
wait_time_seconds.
:type message_attributes: list
:param message_attributes: The name(s) of additional message
attributes to return. The default is to return no additional
message attributes. Use ``['All']`` or ``['.*']`` to return all.
:rtype: :class:`boto.sqs.message.Message`
:return: A single message or None if queue is empty
"""
rs = self.get_messages(1, visibility_timeout,
wait_time_seconds=wait_time_seconds,
message_attributes=message_attributes)
if len(rs) == 1:
return rs[0]
else:
return None
def write(self, message, delay_seconds=None):
"""
Add a single message to the queue.
:type message: Message
:param message: The message to be written to the queue
:rtype: :class:`boto.sqs.message.Message`
:return: The :class:`boto.sqs.message.Message` object that was written.
"""
new_msg = self.connection.send_message(self,
message.get_body_encoded(), delay_seconds=delay_seconds,
message_attributes=message.message_attributes)
message.id = new_msg.id
message.md5 = new_msg.md5
return message
def write_batch(self, messages):
"""
Delivers up to 10 messages in a single request.
:type messages: List of lists.
:param messages: A list of lists or tuples. Each inner
tuple represents a single message to be written
and consists of and ID (string) that must be unique
within the list of messages, the message body itself
which can be a maximum of 64K in length, an
integer which represents the delay time (in seconds)
for the message (0-900) before the message will
be delivered to the queue, and an optional dict of
message attributes like those passed to ``send_message``
in the connection class.
"""
return self.connection.send_message_batch(self, messages)
def new_message(self, body='', **kwargs):
"""
Create new message of appropriate class.
:type body: message body
:param body: The body of the newly created message (optional).
:rtype: :class:`boto.sqs.message.Message`
:return: A new Message object
"""
m = self.message_class(self, body, **kwargs)
m.queue = self
return m
# get a variable number of messages, returns a list of messages
def get_messages(self, num_messages=1, visibility_timeout=None,
attributes=None, wait_time_seconds=None,
message_attributes=None):
"""
Get a variable number of messages.
:type num_messages: int
:param num_messages: The maximum number of messages to read from
the queue.
:type visibility_timeout: int
:param visibility_timeout: The VisibilityTimeout for the messages read.
:type attributes: str
:param attributes: The name of additional attribute to return
with response or All if you want all attributes. The
default is to return no additional attributes. Valid
values: All SenderId SentTimestamp ApproximateReceiveCount
ApproximateFirstReceiveTimestamp
:type wait_time_seconds: int
:param wait_time_seconds: The duration (in seconds) for which the call
will wait for a message to arrive in the queue before returning.
If a message is available, the call will return sooner than
wait_time_seconds.
:type message_attributes: list
:param message_attributes: The name(s) of additional message
attributes to return. The default is to return no additional
message attributes. Use ``['All']`` or ``['.*']`` to return all.
:rtype: list
:return: A list of :class:`boto.sqs.message.Message` objects.
"""
return self.connection.receive_message(
self, number_messages=num_messages,
visibility_timeout=visibility_timeout, attributes=attributes,
wait_time_seconds=wait_time_seconds,
message_attributes=message_attributes)
def delete_message(self, message):
"""
Delete a message from the queue.
:type message: :class:`boto.sqs.message.Message`
:param message: The :class:`boto.sqs.message.Message` object to delete.
:rtype: bool
:return: True if successful, False otherwise
"""
return self.connection.delete_message(self, message)
def delete_message_batch(self, messages):
"""
Deletes a list of messages in a single request.
:type messages: List of :class:`boto.sqs.message.Message` objects.
:param messages: A list of message objects.
"""
return self.connection.delete_message_batch(self, messages)
def change_message_visibility_batch(self, messages):
"""
A batch version of change_message_visibility that can act
on up to 10 messages at a time.
:type messages: List of tuples.
:param messages: A list of tuples where each tuple consists
of a :class:`boto.sqs.message.Message` object and an integer
that represents the new visibility timeout for that message.
"""
return self.connection.change_message_visibility_batch(self, messages)
def delete(self):
"""
Delete the queue.
"""
return self.connection.delete_queue(self)
def purge(self):
"""
Purge all messages in the queue.
"""
return self.connection.purge_queue(self)
def clear(self, page_size=10, vtimeout=10):
"""Deprecated utility function to remove all messages from a queue"""
return self.purge()
def count(self, page_size=10, vtimeout=10):
"""
Utility function to count the number of messages in a queue.
Note: This function now calls GetQueueAttributes to obtain
an 'approximate' count of the number of messages in a queue.
"""
a = self.get_attributes('ApproximateNumberOfMessages')
return int(a['ApproximateNumberOfMessages'])
def count_slow(self, page_size=10, vtimeout=10):
"""
Deprecated. This is the old 'count' method that actually counts
the messages by reading them all. This gives an accurate count but
is very slow for queues with non-trivial number of messasges.
Instead, use get_attributes('ApproximateNumberOfMessages') to take
advantage of the new SQS capability. This is retained only for
the unit tests.
"""
n = 0
l = self.get_messages(page_size, vtimeout)
while l:
for m in l:
n += 1
l = self.get_messages(page_size, vtimeout)
return n
def dump(self, file_name, page_size=10, vtimeout=10, sep='\n'):
"""Utility function to dump the messages in a queue to a file
NOTE: Page size must be < 10 else SQS errors"""
fp = open(file_name, 'wb')
n = 0
l = self.get_messages(page_size, vtimeout)
while l:
for m in l:
fp.write(m.get_body())
if sep:
fp.write(sep)
n += 1
l = self.get_messages(page_size, vtimeout)
fp.close()
return n
def save_to_file(self, fp, sep='\n'):
"""
Read all messages from the queue and persist them to file-like object.
Messages are written to the file and the 'sep' string is written
in between messages. Messages are deleted from the queue after
being written to the file.
Returns the number of messages saved.
"""
n = 0
m = self.read()
while m:
n += 1
fp.write(m.get_body())
if sep:
fp.write(sep)
self.delete_message(m)
m = self.read()
return n
def save_to_filename(self, file_name, sep='\n'):
"""
Read all messages from the queue and persist them to local file.
Messages are written to the file and the 'sep' string is written
in between messages. Messages are deleted from the queue after
being written to the file.
Returns the number of messages saved.
"""
fp = open(file_name, 'wb')
n = self.save_to_file(fp, sep)
fp.close()
return n
# for backwards compatibility
save = save_to_filename
def save_to_s3(self, bucket):
"""
Read all messages from the queue and persist them to S3.
Messages are stored in the S3 bucket using a naming scheme of::
<queue_id>/<message_id>
Messages are deleted from the queue after being saved to S3.
Returns the number of messages saved.
"""
n = 0
m = self.read()
while m:
n += 1
key = bucket.new_key('%s/%s' % (self.id, m.id))
key.set_contents_from_string(m.get_body())
self.delete_message(m)
m = self.read()
return n
def load_from_s3(self, bucket, prefix=None):
"""
Load messages previously saved to S3.
"""
n = 0
if prefix:
prefix = '%s/' % prefix
else:
prefix = '%s/' % self.id[1:]
rs = bucket.list(prefix=prefix)
for key in rs:
n += 1
m = self.new_message(key.get_contents_as_string())
self.write(m)
return n
def load_from_file(self, fp, sep='\n'):
"""Utility function to load messages from a file-like object to a queue"""
n = 0
body = ''
l = fp.readline()
while l:
if l == sep:
m = Message(self, body)
self.write(m)
n += 1
print('writing message %d' % n)
body = ''
else:
body = body + l
l = fp.readline()
return n
def load_from_filename(self, file_name, sep='\n'):
"""Utility function to load messages from a local filename to a queue"""
fp = open(file_name, 'rb')
n = self.load_from_file(fp, sep)
fp.close()
return n
# for backward compatibility
load = load_from_filename
|
mit
|
[
3,
1898,
334,
67,
9,
8315,
13,
8664,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
18089,
376,
428,
23298,
10703,
199,
624,
199,
504,
6055,
14,
5819,
492,
4011,
199,
504,
6055,
14,
31603,
14,
1188,
492,
6430,
421,
199,
533,
10703,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
1166,
29,
403,
12,
1245,
63,
533,
29,
2209,
304,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
1188,
63,
533,
275,
1245,
63,
533,
267,
291,
14,
11269,
63,
2593,
275,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
3737,
4042,
83,
3171,
450,
291,
14,
633,
339,
347,
485,
344,
8,
277,
304,
267,
340,
291,
14,
633,
26,
288,
1139,
275,
4011,
14,
1122,
14,
10290,
8,
277,
14,
633,
2788,
18,
61,
267,
587,
26,
288,
1139,
275,
291,
14,
633,
267,
372,
1139,
272,
1305,
275,
3324,
1547,
344,
9,
339,
347,
485,
354,
8,
277,
304,
267,
340,
291,
14,
633,
26,
288,
1139,
275,
4011,
14,
1122,
14,
10290,
8,
277,
14,
633,
2788,
18,
1055,
1294,
30746,
18,
61,
267,
587,
26,
288,
1139,
275,
291,
14,
633,
267,
372,
221,
1139,
272,
536,
275,
3324,
1547,
354,
9,
339,
347,
485,
1060,
8,
277,
304,
267,
4184,
275,
291,
14,
344,
14,
1294,
7825,
267,
372,
283,
1060,
26,
7231,
26,
31603,
2689,
83,
2689,
83,
2689,
83,
7,
450,
334,
288,
291,
14,
2105,
14,
4551,
14,
354,
12,
4184,
59,
17,
467,
4184,
59,
18,
566,
272,
601,
78,
275,
3324,
1547,
1060,
9,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
3737,
6417,
356,
288,
291,
14,
633,
275,
574,
267,
916,
536,
508,
283,
24735,
6372,
356,
288,
291,
14,
11269,
63,
2593,
275,
1109,
8,
585,
9,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
663,
63,
1188,
63,
533,
8,
277,
12,
1245,
63,
533,
304,
267,
408,
267,
2494,
314,
1245,
1021,
626,
1077,
506,
1202,
1380,
9034,
1958,
267,
3788,
1586,
687,
314,
4126,
14,
221,
4885,
849,
12,
314,
1021,
267,
520,
533,
1705,
10914,
14,
31603,
14,
1188,
14,
2209,
64,
365,
1202,
1325,
642,
883,
506,
1806,
25045,
267,
543,
1263,
1021,
626,
25113,
2839,
282,
1245,
14,
398,
520,
466,
1245,
63,
533,
26,
6430,
13,
2930,
1021,
267,
520,
635,
1245,
63,
533,
26,
221,
710,
892,
6430,
1021,
267,
408,
267,
291,
14,
1188,
63,
533,
275,
1245,
63,
533,
339,
347,
664,
63,
2987,
8,
277,
12,
3004,
534,
2422,
735,
267,
408,
267,
27940,
3004,
3595,
642,
4126,
909,
436,
2529,
267,
3062,
315,
376,
3882,
1256,
334,
6083,
402,
282,
11932,
680,
398,
520,
466,
3004,
26,
1059,
267,
520,
635,
3004,
26,
2624,
3035,
1373,
402,
26,
2574,
13450,
8221,
6897,
16030,
14508,
12,
2574,
13450,
8221,
6897,
16030,
14508,
1763,
14917,
12,
2574,
6561,
4783,
6372,
12,
2574,
18208,
10239,
12,
2574,
15237,
11911,
10239,
12,
2574,
18141,
2574,
799,
5251,
2209,
7536,
1366,
13165,
267,
520,
4500,
26,
3882,
909,
267,
520,
1107,
26,
1626,
3882,
909,
1314,
365,
282,
4412,
730,
17573,
314,
326,
5839,
536,
15,
585,
6342,
267,
408,
267,
372,
291,
14,
2105,
14,
362,
63,
1825,
63,
2987,
8,
277,
12,
3004,
9,
339,
347,
663,
63,
3215,
8,
277,
12,
2225,
12,
574,
304,
267,
408,
267,
2494,
282,
892,
574,
367,
376,
2225,
402,
314,
10703,
14,
398,
520,
466,
2225,
26,
2624,
267,
520,
635,
2225,
26,
710,
536,
402,
314,
2225,
1265,
2934,
370,
663,
14,
221,
710,
2574,
1454,
1686,
574,
737,
642,
900,
365,
26,
6561,
4783,
6372,
267,
520,
466,
574,
26,
1109,
267,
520,
635,
574,
26,
710,
892,
574,
367,
314,
2225,
14,
288,
2104,
6561,
4783,
6372,
314,
574,
1471,
506,
376,
288,
3000,
1329,
402,
4696,
687,
378,
370,
31200,
14,
398,
520,
4500,
26,
2155,
267,
520,
1107,
26,
715,
340,
9512,
12,
4257,
756,
14,
267,
408,
267,
372,
291,
14,
2105,
14,
409,
63,
1825,
63,
3215,
8,
277,
12,
2225,
12,
574,
9,
339,
347,
664,
63,
2593,
8,
277,
304,
267,
408,
267,
2372,
314,
6887,
2653,
367,
314,
4126,
14,
398,
520,
4500,
26,
1109,
267,
520,
1107,
26,
710,
1329,
402,
4696,
465,
376,
3000,
14,
267,
408,
267,
282,
275,
291,
14,
362,
63,
2987,
360,
24735,
6372,
358,
267,
372,
1109,
8,
65,
459,
24735,
6372,
1105,
339,
347,
663,
63,
2593
] |
[
1898,
334,
67,
9,
8315,
13,
8664,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
18089,
376,
428,
23298,
10703,
199,
624,
199,
504,
6055,
14,
5819,
492,
4011,
199,
504,
6055,
14,
31603,
14,
1188,
492,
6430,
421,
199,
533,
10703,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
1166,
29,
403,
12,
1245,
63,
533,
29,
2209,
304,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
1188,
63,
533,
275,
1245,
63,
533,
267,
291,
14,
11269,
63,
2593,
275,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
3737,
4042,
83,
3171,
450,
291,
14,
633,
339,
347,
485,
344,
8,
277,
304,
267,
340,
291,
14,
633,
26,
288,
1139,
275,
4011,
14,
1122,
14,
10290,
8,
277,
14,
633,
2788,
18,
61,
267,
587,
26,
288,
1139,
275,
291,
14,
633,
267,
372,
1139,
272,
1305,
275,
3324,
1547,
344,
9,
339,
347,
485,
354,
8,
277,
304,
267,
340,
291,
14,
633,
26,
288,
1139,
275,
4011,
14,
1122,
14,
10290,
8,
277,
14,
633,
2788,
18,
1055,
1294,
30746,
18,
61,
267,
587,
26,
288,
1139,
275,
291,
14,
633,
267,
372,
221,
1139,
272,
536,
275,
3324,
1547,
354,
9,
339,
347,
485,
1060,
8,
277,
304,
267,
4184,
275,
291,
14,
344,
14,
1294,
7825,
267,
372,
283,
1060,
26,
7231,
26,
31603,
2689,
83,
2689,
83,
2689,
83,
7,
450,
334,
288,
291,
14,
2105,
14,
4551,
14,
354,
12,
4184,
59,
17,
467,
4184,
59,
18,
566,
272,
601,
78,
275,
3324,
1547,
1060,
9,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
3737,
6417,
356,
288,
291,
14,
633,
275,
574,
267,
916,
536,
508,
283,
24735,
6372,
356,
288,
291,
14,
11269,
63,
2593,
275,
1109,
8,
585,
9,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
663,
63,
1188,
63,
533,
8,
277,
12,
1245,
63,
533,
304,
267,
408,
267,
2494,
314,
1245,
1021,
626,
1077,
506,
1202,
1380,
9034,
1958,
267,
3788,
1586,
687,
314,
4126,
14,
221,
4885,
849,
12,
314,
1021,
267,
520,
533,
1705,
10914,
14,
31603,
14,
1188,
14,
2209,
64,
365,
1202,
1325,
642,
883,
506,
1806,
25045,
267,
543,
1263,
1021,
626,
25113,
2839,
282,
1245,
14,
398,
520,
466,
1245,
63,
533,
26,
6430,
13,
2930,
1021,
267,
520,
635,
1245,
63,
533,
26,
221,
710,
892,
6430,
1021,
267,
408,
267,
291,
14,
1188,
63,
533,
275,
1245,
63,
533,
339,
347,
664,
63,
2987,
8,
277,
12,
3004,
534,
2422,
735,
267,
408,
267,
27940,
3004,
3595,
642,
4126,
909,
436,
2529,
267,
3062,
315,
376,
3882,
1256,
334,
6083,
402,
282,
11932,
680,
398,
520,
466,
3004,
26,
1059,
267,
520,
635,
3004,
26,
2624,
3035,
1373,
402,
26,
2574,
13450,
8221,
6897,
16030,
14508,
12,
2574,
13450,
8221,
6897,
16030,
14508,
1763,
14917,
12,
2574,
6561,
4783,
6372,
12,
2574,
18208,
10239,
12,
2574,
15237,
11911,
10239,
12,
2574,
18141,
2574,
799,
5251,
2209,
7536,
1366,
13165,
267,
520,
4500,
26,
3882,
909,
267,
520,
1107,
26,
1626,
3882,
909,
1314,
365,
282,
4412,
730,
17573,
314,
326,
5839,
536,
15,
585,
6342,
267,
408,
267,
372,
291,
14,
2105,
14,
362,
63,
1825,
63,
2987,
8,
277,
12,
3004,
9,
339,
347,
663,
63,
3215,
8,
277,
12,
2225,
12,
574,
304,
267,
408,
267,
2494,
282,
892,
574,
367,
376,
2225,
402,
314,
10703,
14,
398,
520,
466,
2225,
26,
2624,
267,
520,
635,
2225,
26,
710,
536,
402,
314,
2225,
1265,
2934,
370,
663,
14,
221,
710,
2574,
1454,
1686,
574,
737,
642,
900,
365,
26,
6561,
4783,
6372,
267,
520,
466,
574,
26,
1109,
267,
520,
635,
574,
26,
710,
892,
574,
367,
314,
2225,
14,
288,
2104,
6561,
4783,
6372,
314,
574,
1471,
506,
376,
288,
3000,
1329,
402,
4696,
687,
378,
370,
31200,
14,
398,
520,
4500,
26,
2155,
267,
520,
1107,
26,
715,
340,
9512,
12,
4257,
756,
14,
267,
408,
267,
372,
291,
14,
2105,
14,
409,
63,
1825,
63,
3215,
8,
277,
12,
2225,
12,
574,
9,
339,
347,
664,
63,
2593,
8,
277,
304,
267,
408,
267,
2372,
314,
6887,
2653,
367,
314,
4126,
14,
398,
520,
4500,
26,
1109,
267,
520,
1107,
26,
710,
1329,
402,
4696,
465,
376,
3000,
14,
267,
408,
267,
282,
275,
291,
14,
362,
63,
2987,
360,
24735,
6372,
358,
267,
372,
1109,
8,
65,
459,
24735,
6372,
1105,
339,
347,
663,
63,
2593,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
montagnero/political-affiliation-prediction
|
newsreader.py
|
2
|
11936
|
# -*- coding: utf-8 -*-
from sklearn.decomposition import KernelPCA
from sklearn.metrics.pairwise import pairwise_distances
from scipy.stats.mstats import zscore
import glob
import json
import re
import datetime
import os
import cPickle
import codecs
import itertools
from sklearn.feature_extraction.text import TfidfVectorizer
from scipy import double,triu,ones,hstack,arange,reshape,zeros,setdiff1d,array,zeros,eye,argmax,percentile
def get_news(sources=['spiegel','faz','welt','zeit'], folder='model'):
'''
Collects all news articles from political ressort of major German newspapers
Articles are transformed to BoW vectors and assigned to a political party
For better visualization, articles' BoW vectors are also clustered into topics
INPUT
folder the model folder containing classifier and BoW transformer
sources a list of strings for each newspaper for which a crawl is implemented
default ['zeit','sz']
'''
import classifier
from bs4 import BeautifulSoup
from api import fetch_url
import urllib2
news = dict([(source,[]) for source in sources])
# the classifier for prediction of political affiliation
clf = classifier.Classifier(folder=folder)
for source in sources:
if source is 'spiegel':
# fetching articles from sueddeutsche.de/politik
url = 'http://www.spiegel.de/politik'
site = BeautifulSoup(urllib2.urlopen(url).read())
titles = site.findAll("div", { "class" : "teaser" })
urls = ['http://www.spiegel.de'+a.findNext('a')['href'] for a in titles]
if source is 'faz':
# fetching articles from sueddeutsche.de/politik
url = 'http://www.faz.net/aktuell/politik'
site = BeautifulSoup(urllib2.urlopen(url).read())
titles = site.findAll("a", { "class" : "TeaserHeadLink" })
urls = ['http://www.faz.net'+a['href'] for a in titles]
if source is 'welt':
# fetching articles from sueddeutsche.de/politik
url = 'http://www.welt.de/politik'
site = BeautifulSoup(urllib2.urlopen(url).read())
titles = site.findAll("a", { "class" : "as_teaser-kicker" })
urls = [a['href'] for a in titles]
if source is 'sz-without-readability':
# fetching articles from sueddeutsche.de/politik
url = 'http://www.sueddeutsche.de/politik'
site = BeautifulSoup(urllib2.urlopen(url).read())
titles = site.findAll("div", { "class" : "teaser" })
urls = [a.findNext('a')['href'] for a in titles]
if source is 'zeit':
# fetching articles from zeit.de/politik
url = 'http://www.zeit.de/politik'
site = BeautifulSoup(urllib2.urlopen(url).read())
titles = site.findAll("span", { "class" : "supertitle" })
urls = [a.parent['href'] for a in titles if a.parent['href'].find('/2015-')>0]
print "Found %d articles on %s"%(len(urls),url)
# predict party from url for this source
print "Predicting %s"%source
articles = []
for url in urls:
try:
title,text = fetch_url(url)
prediction = clf.predict(text)
prediction['url'] = url
articles.append((title,prediction))
except:
print('Could not get text from %s'%url)
pass
news[source] = dict(articles)
# save results
datestr = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
open(folder+'/news-%s'%(datestr) + '.json', 'wb').write(json.dumps(news,ensure_ascii=False).encode('utf8'))
def all_saved_news(folder='model'):
import glob
from string import digits
# get just the most recent news articles file (assuming date label ordering)
news = json.load(open(glob.glob(folder+'/news*.json')[-1],"r"))
# collect text data from all articles
articles, data = [], []
for source in news.keys():
for title, article in news[source].items():
# remove numbers
for d in digits: article['text'] = article['text'].replace(d,'')
data.append(article['text'])
predictions = [prediction['probability'] for prediction in article['prediction']]
articles.append({
'source':source,
'title':title,
'url':article['url'],
'prediction':article['prediction'],
'predictedLabel':article['prediction'][argmax(predictions)]['party']
})
return articles, data
def pairwise_dists(data, nneighbors=10, folder='model', dist='l2'):
'''
Computes pairwise distances between bag-of-words vectors of articles
INPUT
folder model folder
nneighbors number of closest neighbors to include in distance list
'''
stopwords = codecs.open("stopwords.txt", "r", encoding="utf-8", errors='ignore').readlines()[5:]
stops = map(lambda x:x.lower().strip(),stopwords)
# using now stopwords and filtering out digits
bow = TfidfVectorizer(min_df=2,stop_words=stops)
X = bow.fit_transform(data)
print 'Computing %s pairwise distances'%dist
# KPCA transform bow vectors
if dist is 'l2_kpca_zscore':
K = pairwise_distances(X,metric='l2',n_jobs=1)
perc = 50.0
width = percentile(K.flatten(),perc)
Xc = zscore(KernelPCA(n_components=50,kernel='rbf',gamma=width).fit_transform(X))
K = pairwise_distances(Xc,metric='l2',n_jobs=1)
elif dist is 'l2_kpca':
K = pairwise_distances(X,metric='l2',n_jobs=1)
perc = 100./len(data)
width = percentile(K.flatten(),perc)
Xc = KernelPCA(n_components=50,kernel='rbf',gamma=width).fit_transform(X)
K = pairwise_distances(Xc,metric='l2',n_jobs=1)
elif dist is 'l2':
K = pairwise_distances(X,metric='l2',n_jobs=1)
elif dist is 'l1':
K = pairwise_distances(X,metric='l1',n_jobs=1)
# collect closest neighbors
distances = []
for urlidx in range(len(data)):
idx = (K[urlidx,:]).argsort()[1:nneighbors+1]
for sidx in idx:
distances.append([urlidx,sidx,(idx==sidx).nonzero()[0][0]])
return distances
def load_sentiment(negative='SentiWS_v1.8c/SentiWS_v1.8c_Negative.txt',\
positive='SentiWS_v1.8c/SentiWS_v1.8c_Positive.txt'):
words = dict()
for line in open(negative).readlines():
parts = line.strip('\n').split('\t')
words[parts[0].split('|')[0]] = double(parts[1])
if len(parts)>2:
for inflection in parts[2].strip('\n').split(','):
words[inflection] = double(parts[1])
for line in open(positive).readlines():
parts = line.strip('\n').split('\t')
words[parts[0].split('|')[0]] = double(parts[1])
if len(parts)>2:
for inflection in parts[2].strip('\n').split(','):
words[inflection] = double(parts[1])
return words
def get_sentiments(data):
# filtering out some noise words
stops = map(lambda x:x.lower().strip(),open('stopwords.txt').readlines()[6:])
# vectorize non-stopwords
bow = TfidfVectorizer(min_df=2,stop_words=stops)
X = bow.fit_transform(data)
# map sentiment vector to bow space
words = load_sentiment()
sentiment_vec = zeros(X.shape[1])
for key in words.keys():
if bow.vocabulary_.has_key(key):
sentiment_vec[bow.vocabulary_[key]] = words[key]
# compute sentiments
return X.dot(sentiment_vec)
def kpca_cluster(data,nclusters=100,ncomponents=40,topwhat=10,zscored=False):
'''
Computes clustering of bag-of-words vectors of articles
INPUT
folder model folder
nclusters number of clusters
'''
from sklearn.cluster import KMeans
# filtering out some noise words
stops = map(lambda x:x.lower().strip(),open('stopwords.txt').readlines()[6:])
# vectorize non-stopwords
bow = TfidfVectorizer(min_df=2,stop_words=stops)
X = bow.fit_transform(data)
# creating bow-index-to-word map
idx2word = dict(zip(bow.vocabulary_.values(),bow.vocabulary_.keys()))
# using now stopwords and filtering out digits
print 'Computing pairwise distances'
K = pairwise_distances(X,metric='l2',n_jobs=1)
perc = 50.0
width = percentile(K.flatten(),perc)
# KPCA transform bow vectors
Xc = KernelPCA(n_components=ncomponents,kernel='rbf',gamma=width).fit_transform(X)
if zscored:
Xc = zscore(Xc)
# compute clusters
km = KMeans(n_clusters=nclusters).fit(Xc)
Xc = km.predict(Xc)
clusters = []
for icluster in range(nclusters):
nmembers = (Xc==icluster).sum()
if True:#nmembers < len(data) / 5.0 and nmembers > 1: # only group clusters big enough but not too big
members = (Xc==icluster).nonzero()[0]
topwordidx = array(X[members,:].sum(axis=0))[0].argsort()[-topwhat:][::-1]
topwords = ' '.join([idx2word[wi] for wi in topwordidx])
meanDist = triu(pairwise_distances(X[members,:],metric='l2',n_jobs=1)).sum()
meanDist = meanDist / (len(members) + (len(members)**2 - len(members))/2.0)
# print u'Cluster %d'%icluster + u' %d members'%nmembers + u' mean Distance %f'%meanDist + u'\n\t'+topwords
clusters.append({
'name':'Cluster-%d'%icluster,
'description': topwords,
'members': list(members),
'meanL2Distances': meanDist
})
return clusters
def party_cluster(articles):
clusters = []
keyf = lambda a: a[1]['predictedLabel']
for k, group in itertools.groupby(sorted(enumerate(articles), key=keyf), keyf):
clusters.append({
'name': k,
'description': k,
'members': [index_article_tuple[0] for index_article_tuple in group]
})
return clusters
def write_distances_json(folder='model'):
articles, data = all_saved_news(folder)
dists = ['l2_kpca']
distances_json = {
'articles': articles,
'sentiments': json.dumps(get_sentiments(data).tolist()),
'distances': [
{ 'name': dist, 'distances': pairwise_dists(data,dist = dist) } for dist in dists
],
'clusterings': [
{ 'name': 'Parteivorhersage', 'clusters': party_cluster(articles) },
{ 'name': 'Ähnlichkeit', 'clusters': kpca_cluster(data,nclusters=len(articles)/2,ncomponents=40,zscored=False) },
]
}
# save article with party prediction and distances to closest articles
datestr = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
open(folder+'/distances-%s'%(datestr)+'.json', 'wb').write(json.dumps(distances_json))
# also save that latest version for the visualization
open(folder+'/distances.json', 'wb').write(json.dumps(distances_json))
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(\
description='Downloads, transforms and clusters news articles')
parser.add_argument('-f','--folder',help='Folder to store text files [./model]',\
default='model')
parser.add_argument('-d','--download',help='If files should be downloaded',\
action='store_true', default=False)
parser.add_argument('-p','--distances',help='If pairwise distances of text should be computed',\
action='store_true', default=False)
args = vars(parser.parse_args())
if not os.path.isdir(args['folder']):
os.mkdir(args['folder'])
if args['download']:
get_news(folder=args['folder'])
if args['distances']:
write_distances_json(folder=args['folder'])
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
6357,
14,
31384,
492,
24901,
23852,
199,
504,
6357,
14,
6759,
14,
25069,
492,
24859,
63,
15482,
199,
504,
7026,
14,
3200,
14,
77,
3200,
492,
1315,
3397,
199,
646,
5739,
199,
646,
2022,
199,
646,
295,
199,
646,
2197,
199,
646,
747,
199,
646,
17572,
199,
646,
6010,
199,
646,
7975,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
377,
23274,
26165,
199,
504,
7026,
492,
4270,
12,
599,
85,
12,
4548,
12,
20949,
12,
5605,
12,
5217,
12,
4250,
12,
409,
3028,
17,
68,
12,
1144,
12,
4250,
12,
15240,
12,
16383,
12,
21188,
199,
199,
318,
664,
63,
13224,
8,
4553,
2968,
681,
1873,
24920,
1673,
667,
90,
1673,
87,
15330,
1673,
806,
390,
995,
4922,
534,
1238,
735,
272,
1449,
272,
19649,
83,
1006,
19497,
23242,
687,
1115,
317,
3294,
295,
385,
361,
402,
12160,
22261,
1237,
892,
3770,
32206,
272,
8281,
83,
787,
14834,
370,
5088,
55,
11102,
436,
7943,
370,
282,
1115,
317,
3294,
17135,
272,
2104,
8034,
13104,
2072,
12,
23242,
7,
5088,
55,
11102,
787,
2597,
824,
527,
3014,
1901,
17398,
339,
21955,
272,
4922,
420,
314,
1402,
4922,
3035,
12429,
436,
5088,
55,
21484,
272,
5274,
258,
282,
769,
402,
3326,
367,
1924,
892,
3770,
529,
367,
1314,
282,
286,
22910,
365,
6366,
355,
849,
788,
806,
390,
1673,
11803,
418,
339,
1449,
272,
492,
12429,
272,
687,
9922,
20,
492,
17132,
272,
687,
2986,
492,
5267,
63,
633,
272,
492,
4011,
18,
2286,
19497,
275,
1211,
7694,
1365,
14343,
566,
367,
1350,
315,
5274,
566,
23855,
327,
314,
12429,
367,
12044,
402,
1115,
317,
3294,
23528,
18835,
272,
6975,
275,
12429,
14,
8508,
8,
3741,
29,
3741,
9,
2286,
367,
1350,
315,
5274,
26,
398,
340,
1350,
365,
283,
681,
1873,
24920,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
681,
1873,
24920,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
3015,
401,
469,
298,
533,
2,
520,
298,
266,
65,
332,
2,
3828,
288,
8187,
275,
788,
1014,
921,
1544,
14,
681,
1873,
24920,
14,
271,
6828,
65,
14,
1623,
5765,
360,
65,
24211,
6399,
418,
367,
282,
315,
16194,
61,
881,
267,
340,
1350,
365,
283,
667,
90,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
667,
90,
14,
846,
15,
1151,
84,
310,
914,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
65,
401,
469,
298,
533,
2,
520,
298,
52,
4489,
332,
11664,
3834,
2,
3828,
288,
8187,
275,
788,
1014,
921,
1544,
14,
667,
90,
14,
846,
6828,
65,
459,
6399,
418,
367,
282,
315,
16194,
61,
881,
267,
340,
1350,
365,
283,
87,
15330,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
87,
15330,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
65,
401,
469,
298,
533,
2,
520,
298,
305,
63,
266,
65,
332,
13,
31257,
281,
2,
3828,
288,
8187,
275,
359,
65,
459,
6399,
418,
367,
282,
315,
16194,
61,
881,
267,
340,
1350,
365,
283,
11803,
13,
7395,
13,
29814,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
3309,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
3015,
401,
469,
298,
533,
2,
520,
298,
266,
65,
332,
2,
3828,
288,
8187,
275,
359,
65,
14,
1623,
5765,
360,
65,
24211,
6399,
418,
367,
282,
315,
16194,
61,
267,
267,
340,
1350,
365,
283,
806,
390,
356,
288,
327,
21239,
23242,
687,
29986,
390,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
806,
390,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
3751,
401,
469,
298,
533,
2,
520,
298,
4792,
1213,
2,
3828,
288,
8187,
275,
359,
65,
14,
1708,
459,
6399,
418,
367,
282,
315,
16194,
340,
282,
14,
1708,
459,
6399,
2278,
1623,
2336,
7806,
25815,
30,
16,
61,
398,
870,
298,
3601,
450,
68,
23242,
641,
450,
83,
14007,
552,
8,
3603,
395,
633,
9,
881,
267,
327,
12610,
17135,
687,
1166,
367,
642,
1350,
267,
870,
298,
28240,
316,
450,
83,
6808,
1365,
267,
23242,
275,
942,
267,
367,
1166,
315,
8187,
26,
288,
862,
26,
355,
2538,
12,
505,
275,
5267,
63,
633,
8,
633,
9,
355,
12044,
275,
6975,
14,
6892,
8,
505,
9,
355,
12044,
459,
633,
418,
275,
1166,
355,
23242,
14,
740,
1332,
1213,
12,
14845,
430,
288,
871,
26,
355,
870,
360,
6531,
440,
664,
1318,
687,
450,
83,
5956,
633,
9,
355,
986,
398,
19497,
59,
1365,
61,
275,
1211,
8,
19813,
9,
339,
327,
3354,
2058,
272,
1434,
495,
275,
2197,
14,
2083,
14,
2131,
1252,
6205,
3647,
57,
3295,
77,
3295,
68,
3295,
40,
3295,
45,
3295,
51,
531,
272,
1551,
8,
3741,
23164,
13224,
3295,
83,
13328,
602,
495,
9,
435,
1987,
1001,
297,
283,
6603,
1959,
952,
8,
1001,
14,
4180,
8,
13224,
12,
7505,
63,
4371,
29,
797,
680,
2143,
360,
1624,
24,
1333,
199,
199,
318,
1006,
63,
8420,
63,
13224,
8,
3741,
534,
1238,
735,
272,
492,
5739,
272,
687,
1059,
492,
7576,
272,
327,
664,
2951,
314,
4750,
8058,
19497,
23242,
570,
334,
405,
12848,
1434,
1768,
7794,
9,
272,
19497,
275,
2022,
14,
912,
8,
1490
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
6357,
14,
31384,
492,
24901,
23852,
199,
504,
6357,
14,
6759,
14,
25069,
492,
24859,
63,
15482,
199,
504,
7026,
14,
3200,
14,
77,
3200,
492,
1315,
3397,
199,
646,
5739,
199,
646,
2022,
199,
646,
295,
199,
646,
2197,
199,
646,
747,
199,
646,
17572,
199,
646,
6010,
199,
646,
7975,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
377,
23274,
26165,
199,
504,
7026,
492,
4270,
12,
599,
85,
12,
4548,
12,
20949,
12,
5605,
12,
5217,
12,
4250,
12,
409,
3028,
17,
68,
12,
1144,
12,
4250,
12,
15240,
12,
16383,
12,
21188,
199,
199,
318,
664,
63,
13224,
8,
4553,
2968,
681,
1873,
24920,
1673,
667,
90,
1673,
87,
15330,
1673,
806,
390,
995,
4922,
534,
1238,
735,
272,
1449,
272,
19649,
83,
1006,
19497,
23242,
687,
1115,
317,
3294,
295,
385,
361,
402,
12160,
22261,
1237,
892,
3770,
32206,
272,
8281,
83,
787,
14834,
370,
5088,
55,
11102,
436,
7943,
370,
282,
1115,
317,
3294,
17135,
272,
2104,
8034,
13104,
2072,
12,
23242,
7,
5088,
55,
11102,
787,
2597,
824,
527,
3014,
1901,
17398,
339,
21955,
272,
4922,
420,
314,
1402,
4922,
3035,
12429,
436,
5088,
55,
21484,
272,
5274,
258,
282,
769,
402,
3326,
367,
1924,
892,
3770,
529,
367,
1314,
282,
286,
22910,
365,
6366,
355,
849,
788,
806,
390,
1673,
11803,
418,
339,
1449,
272,
492,
12429,
272,
687,
9922,
20,
492,
17132,
272,
687,
2986,
492,
5267,
63,
633,
272,
492,
4011,
18,
2286,
19497,
275,
1211,
7694,
1365,
14343,
566,
367,
1350,
315,
5274,
566,
23855,
327,
314,
12429,
367,
12044,
402,
1115,
317,
3294,
23528,
18835,
272,
6975,
275,
12429,
14,
8508,
8,
3741,
29,
3741,
9,
2286,
367,
1350,
315,
5274,
26,
398,
340,
1350,
365,
283,
681,
1873,
24920,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
681,
1873,
24920,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
3015,
401,
469,
298,
533,
2,
520,
298,
266,
65,
332,
2,
3828,
288,
8187,
275,
788,
1014,
921,
1544,
14,
681,
1873,
24920,
14,
271,
6828,
65,
14,
1623,
5765,
360,
65,
24211,
6399,
418,
367,
282,
315,
16194,
61,
881,
267,
340,
1350,
365,
283,
667,
90,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
667,
90,
14,
846,
15,
1151,
84,
310,
914,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
65,
401,
469,
298,
533,
2,
520,
298,
52,
4489,
332,
11664,
3834,
2,
3828,
288,
8187,
275,
788,
1014,
921,
1544,
14,
667,
90,
14,
846,
6828,
65,
459,
6399,
418,
367,
282,
315,
16194,
61,
881,
267,
340,
1350,
365,
283,
87,
15330,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
87,
15330,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
65,
401,
469,
298,
533,
2,
520,
298,
305,
63,
266,
65,
332,
13,
31257,
281,
2,
3828,
288,
8187,
275,
359,
65,
459,
6399,
418,
367,
282,
315,
16194,
61,
881,
267,
340,
1350,
365,
283,
11803,
13,
7395,
13,
29814,
356,
288,
327,
21239,
23242,
687,
308,
310,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
3309,
10282,
14608,
595,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
3015,
401,
469,
298,
533,
2,
520,
298,
266,
65,
332,
2,
3828,
288,
8187,
275,
359,
65,
14,
1623,
5765,
360,
65,
24211,
6399,
418,
367,
282,
315,
16194,
61,
267,
267,
340,
1350,
365,
283,
806,
390,
356,
288,
327,
21239,
23242,
687,
29986,
390,
14,
271,
15,
555,
317,
30298,
288,
1166,
275,
283,
1014,
921,
1544,
14,
806,
390,
14,
271,
15,
555,
317,
30298,
7,
288,
4770,
275,
17132,
8,
4078,
18,
14,
10890,
8,
633,
680,
739,
1012,
288,
16194,
275,
4770,
14,
32651,
480,
3751,
401,
469,
298,
533,
2,
520,
298,
4792,
1213,
2,
3828,
288,
8187,
275,
359,
65,
14,
1708,
459,
6399,
418,
367,
282,
315,
16194,
340,
282,
14,
1708,
459,
6399,
2278,
1623,
2336,
7806,
25815,
30,
16,
61,
398,
870,
298,
3601,
450,
68,
23242,
641,
450,
83,
14007,
552,
8,
3603,
395,
633,
9,
881,
267,
327,
12610,
17135,
687,
1166,
367,
642,
1350,
267,
870,
298,
28240,
316,
450,
83,
6808,
1365,
267,
23242,
275,
942,
267,
367,
1166,
315,
8187,
26,
288,
862,
26,
355,
2538,
12,
505,
275,
5267,
63,
633,
8,
633,
9,
355,
12044,
275,
6975,
14,
6892,
8,
505,
9,
355,
12044,
459,
633,
418,
275,
1166,
355,
23242,
14,
740,
1332,
1213,
12,
14845,
430,
288,
871,
26,
355,
870,
360,
6531,
440,
664,
1318,
687,
450,
83,
5956,
633,
9,
355,
986,
398,
19497,
59,
1365,
61,
275,
1211,
8,
19813,
9,
339,
327,
3354,
2058,
272,
1434,
495,
275,
2197,
14,
2083,
14,
2131,
1252,
6205,
3647,
57,
3295,
77,
3295,
68,
3295,
40,
3295,
45,
3295,
51,
531,
272,
1551,
8,
3741,
23164,
13224,
3295,
83,
13328,
602,
495,
9,
435,
1987,
1001,
297,
283,
6603,
1959,
952,
8,
1001,
14,
4180,
8,
13224,
12,
7505,
63,
4371,
29,
797,
680,
2143,
360,
1624,
24,
1333,
199,
199,
318,
1006,
63,
8420,
63,
13224,
8,
3741,
534,
1238,
735,
272,
492,
5739,
272,
687,
1059,
492,
7576,
272,
327,
664,
2951,
314,
4750,
8058,
19497,
23242,
570,
334,
405,
12848,
1434,
1768,
7794,
9,
272,
19497,
275,
2022,
14,
912,
8,
1490,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nrwahl2/ansible
|
lib/ansible/module_utils/crypto.py
|
8
|
4967
|
# -*- coding: utf-8 -*-
#
# (c) 2016, Yanis Guenane <yanis+ansible@guenane.org>
#
# 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/>.
try:
from OpenSSL import crypto
except ImportError:
# An error will be raised in the calling class to let the end
# user know that OpenSSL couldn't be found.
pass
import abc
import errno
import hashlib
import os
from ansible.module_utils import six
class OpenSSLObjectError(Exception):
pass
def get_fingerprint(path, passphrase=None):
"""Generate the fingerprint of the public key. """
fingerprint = {}
privatekey = load_privatekey(path, passphrase)
try:
publickey = crypto.dump_publickey(crypto.FILETYPE_ASN1, privatekey)
for algo in hashlib.algorithms:
f = getattr(hashlib, algo)
pubkey_digest = f(publickey).hexdigest()
fingerprint[algo] = ':'.join(pubkey_digest[i:i + 2] for i in range(0, len(pubkey_digest), 2))
except AttributeError:
# If PyOpenSSL < 16.0 crypto.dump_publickey() will fail.
# By doing this we prevent the code from raising an error
# yet we return no value in the fingerprint hash.
pass
return fingerprint
def load_privatekey(path, passphrase=None):
"""Load the specified OpenSSL private key."""
try:
if passphrase:
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
open(path, 'rb').read(),
passphrase)
else:
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
open(path, 'rb').read())
return privatekey
except (IOError, OSError) as exc:
raise OpenSSLObjectError(exc)
def load_certificate(path):
"""Load the specified certificate."""
try:
cert_content = open(path, 'rb').read()
cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_content)
return cert
except (IOError, OSError) as exc:
raise OpenSSLObjectError(exc)
def load_certificate_request(path):
"""Load the specified certificate signing request."""
try:
csr_content = open(path, 'rb').read()
csr = crypto.load_certificate_request(crypto.FILETYPE_PEM, csr_content)
return csr
except (IOError, OSError) as exc:
raise OpenSSLObjectError(exc)
keyUsageLong = {
"digitalSignature": "Digital Signature",
"nonRepudiation": "Non Repudiation",
"keyEncipherment": "Key Encipherment",
"dataEncipherment": "Data Encipherment",
"keyAgreement": "Key Agreement",
"keyCertSign": "Certificate Sign",
"cRLSign": "CRL Sign",
"encipherOnly": "Encipher Only",
"decipherOnly": "Decipher Only",
}
extendedKeyUsageLong = {
"serverAuth": "TLS Web Server Authentication",
"clientAuth": "TLS Web Client Authentication",
"codeSigning": "Code Signing",
"emailProtection": "E-mail Protection",
"timeStamping": "Time Stamping",
"OCSPSigning": "OCSP Signing",
}
@six.add_metaclass(abc.ABCMeta)
class OpenSSLObject(object):
def __init__(self, path, state, force, check_mode):
self.path = path
self.state = state
self.force = force
self.name = os.path.basename(path)
self.changed = False
self.check_mode = check_mode
def check(self, module, perms_required=True):
"""Ensure the resource is in its desired state."""
def _check_state():
return os.path.exists(self.path)
def _check_perms(module):
file_args = module.load_file_common_arguments(module.params)
return not module.set_fs_attributes_if_different(file_args, False)
if not perms_required:
return _check_state()
return _check_state() and _check_perms(module)
@abc.abstractmethod
def dump(self):
"""Serialize the object into a dictionary."""
pass
@abc.abstractmethod
def generate(self):
"""Generate the resource."""
pass
def remove(self):
"""Remove the resource from the filesystem."""
try:
os.remove(self.path)
self.changed = True
except OSError as exc:
if exc.errno != errno.ENOENT:
raise OpenSSLObjectError(exc)
else:
pass
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
7800,
12,
1488,
7199,
12436,
287,
5865,
665,
89,
7199,
11,
4853,
32,
6051,
287,
5865,
14,
1308,
30,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
893,
26,
272,
687,
14296,
492,
13230,
199,
2590,
3545,
26,
272,
327,
1626,
1125,
911,
506,
4915,
315,
314,
6358,
1021,
370,
4691,
314,
1284,
272,
327,
922,
5715,
626,
14296,
21554,
1133,
506,
1911,
14,
272,
986,
199,
199,
646,
13022,
199,
646,
7554,
199,
646,
8337,
199,
646,
747,
199,
199,
504,
3242,
14,
578,
63,
1208,
492,
3816,
421,
199,
533,
3232,
2300,
30113,
547,
8,
1726,
304,
272,
986,
421,
199,
318,
664,
63,
15077,
8,
515,
12,
22432,
29,
403,
304,
272,
408,
6864,
314,
18020,
402,
314,
4575,
790,
14,
408,
339,
18020,
275,
1052,
339,
5726,
498,
275,
2248,
63,
4239,
498,
8,
515,
12,
22432,
9,
272,
862,
26,
267,
7974,
8442,
14655,
275,
13230,
14,
2724,
63,
5645,
8442,
14655,
8,
10316,
14,
5110,
17509,
63,
21696,
17,
12,
5726,
498,
9,
267,
367,
24633,
315,
8337,
14,
24365,
26,
288,
289,
275,
2519,
8,
24722,
12,
24633,
9,
288,
25887,
63,
5671,
275,
289,
8,
5645,
8442,
14655,
680,
11453,
342,
288,
18020,
59,
21734,
61,
275,
29010,
904,
8,
17178,
63,
5671,
59,
73,
26,
73,
435,
499,
61,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
17178,
63,
5671,
395,
499,
430,
272,
871,
4281,
26,
267,
327,
982,
1611,
22791,
665,
3193,
14,
16,
13230,
14,
2724,
63,
5645,
8442,
14655,
342,
911,
2449,
14,
267,
327,
4885,
9689,
642,
781,
7981,
314,
1233,
687,
17026,
376,
1125,
267,
327,
5966,
781,
372,
949,
574,
315,
314,
18020,
2631,
14,
267,
986,
339,
372,
18020,
421,
199,
318,
2248,
63,
4239,
498,
8,
515,
12,
22432,
29,
403,
304,
272,
408,
6200,
314,
2013,
14296,
5726,
790,
1041,
339,
862,
26,
267,
340,
22432,
26,
288,
5726,
498,
275,
13230,
14,
912,
63,
4239,
498,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
6059,
1551,
8,
515,
12,
283,
4848,
1959,
739,
1062,
6059,
22432,
9,
267,
587,
26,
288,
5726,
498,
275,
13230,
14,
912,
63,
4239,
498,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
6059,
1551,
8,
515,
12,
283,
4848,
1959,
739,
1012,
398,
372,
5726,
498,
272,
871,
334,
13760,
12,
6440,
9,
465,
3178,
26,
267,
746,
3232,
2300,
30113,
547,
8,
2804,
9,
421,
199,
318,
2248,
63,
6999,
8,
515,
304,
272,
408,
6200,
314,
2013,
5897,
1041,
339,
862,
26,
267,
6250,
63,
1317,
275,
1551,
8,
515,
12,
283,
4848,
1959,
739,
342,
267,
6250,
275,
13230,
14,
912,
63,
6999,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
6250,
63,
1317,
9,
267,
372,
6250,
272,
871,
334,
13760,
12,
6440,
9,
465,
3178,
26,
267,
746,
3232,
2300,
30113,
547,
8,
2804,
9,
421,
199,
318,
2248,
63,
6999,
63,
1069,
8,
515,
304,
272,
408,
6200,
314,
2013,
5897,
18057,
1056,
1041,
339,
862,
26,
267,
22258,
63,
1317,
275,
1551,
8,
515,
12,
283,
4848,
1959,
739,
342,
267,
22258,
275,
13230,
14,
912,
63,
6999,
63,
1069,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
22258,
63,
1317,
9,
267,
372,
22258,
272,
871,
334,
13760,
12,
6440,
9,
465,
3178,
26,
267,
746,
3232,
2300,
30113,
547,
8,
2804,
9,
421,
199,
498,
7692,
9551,
275,
469,
272,
298,
25888,
10014,
582,
298,
32660,
18603,
401,
272,
298,
2865,
497,
3165,
328,
425,
582,
298,
6932,
799,
3165,
328,
425,
401,
272,
298,
498,
1327,
9231,
434,
582,
298,
1197,
3447,
9231,
434,
401,
272,
298,
576,
1327,
9231,
434,
582,
298,
1451,
3447,
9231,
434,
401,
272,
298,
498,
24061,
582,
298,
1197,
28629,
401,
272,
298,
498,
14768,
4940,
582,
298,
11414,
6632,
401,
272,
298,
67,
2431,
4940,
582,
298,
35,
2431,
6632,
401,
272,
298,
287,
9231,
5903,
582,
298,
1327,
9231,
5972,
401,
272,
298,
271,
9231,
5903,
582,
298,
872,
9231,
5972,
401,
199,
93,
199,
199,
10525,
1197,
7692,
9551,
275,
469,
272,
298,
1000,
2817,
582,
298,
10224,
6001,
7146,
15995,
401,
272,
298,
1258,
2817,
582,
298,
10224,
6001,
6810,
15995,
401,
272,
298,
600,
4940,
316,
582,
298,
3034,
6632,
316,
401,
272,
298,
2123,
32322,
582,
298,
37,
13,
1198,
2165,
5860,
401,
272,
298,
521,
16649,
316,
582,
298,
1366,
7083,
311,
316,
401,
272,
298,
47,
30635,
4940,
316,
582,
298,
47,
30635,
6632,
316,
401,
199,
93,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
3232,
2300,
30113,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
931,
12,
1174,
12,
3542,
12,
1104,
63,
632,
304,
267,
291,
14,
515,
275,
931,
267,
291,
14,
929,
275,
1174,
267,
291,
14,
3990,
275,
3542,
267,
291,
14,
354,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
267,
291,
14,
2489,
275,
756,
267,
291,
14,
1074,
63,
632,
275,
1104,
63,
632,
339,
347,
1104,
8,
277,
12,
859,
12,
17340,
63,
2427,
29,
549,
304,
267,
408,
13913,
314,
2073,
365,
315,
2399,
6387,
1174,
1041,
398,
347,
485,
1074,
63,
929,
837,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
7800,
12,
1488,
7199,
12436,
287,
5865,
665,
89,
7199,
11,
4853,
32,
6051,
287,
5865,
14,
1308,
30,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
893,
26,
272,
687,
14296,
492,
13230,
199,
2590,
3545,
26,
272,
327,
1626,
1125,
911,
506,
4915,
315,
314,
6358,
1021,
370,
4691,
314,
1284,
272,
327,
922,
5715,
626,
14296,
21554,
1133,
506,
1911,
14,
272,
986,
199,
199,
646,
13022,
199,
646,
7554,
199,
646,
8337,
199,
646,
747,
199,
199,
504,
3242,
14,
578,
63,
1208,
492,
3816,
421,
199,
533,
3232,
2300,
30113,
547,
8,
1726,
304,
272,
986,
421,
199,
318,
664,
63,
15077,
8,
515,
12,
22432,
29,
403,
304,
272,
408,
6864,
314,
18020,
402,
314,
4575,
790,
14,
408,
339,
18020,
275,
1052,
339,
5726,
498,
275,
2248,
63,
4239,
498,
8,
515,
12,
22432,
9,
272,
862,
26,
267,
7974,
8442,
14655,
275,
13230,
14,
2724,
63,
5645,
8442,
14655,
8,
10316,
14,
5110,
17509,
63,
21696,
17,
12,
5726,
498,
9,
267,
367,
24633,
315,
8337,
14,
24365,
26,
288,
289,
275,
2519,
8,
24722,
12,
24633,
9,
288,
25887,
63,
5671,
275,
289,
8,
5645,
8442,
14655,
680,
11453,
342,
288,
18020,
59,
21734,
61,
275,
29010,
904,
8,
17178,
63,
5671,
59,
73,
26,
73,
435,
499,
61,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
17178,
63,
5671,
395,
499,
430,
272,
871,
4281,
26,
267,
327,
982,
1611,
22791,
665,
3193,
14,
16,
13230,
14,
2724,
63,
5645,
8442,
14655,
342,
911,
2449,
14,
267,
327,
4885,
9689,
642,
781,
7981,
314,
1233,
687,
17026,
376,
1125,
267,
327,
5966,
781,
372,
949,
574,
315,
314,
18020,
2631,
14,
267,
986,
339,
372,
18020,
421,
199,
318,
2248,
63,
4239,
498,
8,
515,
12,
22432,
29,
403,
304,
272,
408,
6200,
314,
2013,
14296,
5726,
790,
1041,
339,
862,
26,
267,
340,
22432,
26,
288,
5726,
498,
275,
13230,
14,
912,
63,
4239,
498,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
6059,
1551,
8,
515,
12,
283,
4848,
1959,
739,
1062,
6059,
22432,
9,
267,
587,
26,
288,
5726,
498,
275,
13230,
14,
912,
63,
4239,
498,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
6059,
1551,
8,
515,
12,
283,
4848,
1959,
739,
1012,
398,
372,
5726,
498,
272,
871,
334,
13760,
12,
6440,
9,
465,
3178,
26,
267,
746,
3232,
2300,
30113,
547,
8,
2804,
9,
421,
199,
318,
2248,
63,
6999,
8,
515,
304,
272,
408,
6200,
314,
2013,
5897,
1041,
339,
862,
26,
267,
6250,
63,
1317,
275,
1551,
8,
515,
12,
283,
4848,
1959,
739,
342,
267,
6250,
275,
13230,
14,
912,
63,
6999,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
6250,
63,
1317,
9,
267,
372,
6250,
272,
871,
334,
13760,
12,
6440,
9,
465,
3178,
26,
267,
746,
3232,
2300,
30113,
547,
8,
2804,
9,
421,
199,
318,
2248,
63,
6999,
63,
1069,
8,
515,
304,
272,
408,
6200,
314,
2013,
5897,
18057,
1056,
1041,
339,
862,
26,
267,
22258,
63,
1317,
275,
1551,
8,
515,
12,
283,
4848,
1959,
739,
342,
267,
22258,
275,
13230,
14,
912,
63,
6999,
63,
1069,
8,
10316,
14,
5110,
17509,
63,
24160,
12,
22258,
63,
1317,
9,
267,
372,
22258,
272,
871,
334,
13760,
12,
6440,
9,
465,
3178,
26,
267,
746,
3232,
2300,
30113,
547,
8,
2804,
9,
421,
199,
498,
7692,
9551,
275,
469,
272,
298,
25888,
10014,
582,
298,
32660,
18603,
401,
272,
298,
2865,
497,
3165,
328,
425,
582,
298,
6932,
799,
3165,
328,
425,
401,
272,
298,
498,
1327,
9231,
434,
582,
298,
1197,
3447,
9231,
434,
401,
272,
298,
576,
1327,
9231,
434,
582,
298,
1451,
3447,
9231,
434,
401,
272,
298,
498,
24061,
582,
298,
1197,
28629,
401,
272,
298,
498,
14768,
4940,
582,
298,
11414,
6632,
401,
272,
298,
67,
2431,
4940,
582,
298,
35,
2431,
6632,
401,
272,
298,
287,
9231,
5903,
582,
298,
1327,
9231,
5972,
401,
272,
298,
271,
9231,
5903,
582,
298,
872,
9231,
5972,
401,
199,
93,
199,
199,
10525,
1197,
7692,
9551,
275,
469,
272,
298,
1000,
2817,
582,
298,
10224,
6001,
7146,
15995,
401,
272,
298,
1258,
2817,
582,
298,
10224,
6001,
6810,
15995,
401,
272,
298,
600,
4940,
316,
582,
298,
3034,
6632,
316,
401,
272,
298,
2123,
32322,
582,
298,
37,
13,
1198,
2165,
5860,
401,
272,
298,
521,
16649,
316,
582,
298,
1366,
7083,
311,
316,
401,
272,
298,
47,
30635,
4940,
316,
582,
298,
47,
30635,
6632,
316,
401,
199,
93,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
3232,
2300,
30113,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
931,
12,
1174,
12,
3542,
12,
1104,
63,
632,
304,
267,
291,
14,
515,
275,
931,
267,
291,
14,
929,
275,
1174,
267,
291,
14,
3990,
275,
3542,
267,
291,
14,
354,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
267,
291,
14,
2489,
275,
756,
267,
291,
14,
1074,
63,
632,
275,
1104,
63,
632,
339,
347,
1104,
8,
277,
12,
859,
12,
17340,
63,
2427,
29,
549,
304,
267,
408,
13913,
314,
2073,
365,
315,
2399,
6387,
1174,
1041,
398,
347,
485,
1074,
63,
929,
837,
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
] |
IndonesiaX/edx-platform
|
lms/djangoapps/django_comment_client/base/urls.py
|
63
|
2810
|
"""
Base urls for the django_comment_client.
"""
from django.conf.urls import url, patterns
urlpatterns = patterns(
'django_comment_client.base.views',
url(r'upload$', 'upload', name='upload'),
url(r'threads/(?P<thread_id>[\w\-]+)/update$', 'update_thread', name='update_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/reply$', 'create_comment', name='create_comment'),
url(r'threads/(?P<thread_id>[\w\-]+)/delete', 'delete_thread', name='delete_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/upvote$', 'vote_for_thread', {'value': 'up'}, name='upvote_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/downvote$', 'vote_for_thread', {'value': 'down'}, name='downvote_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/flagAbuse$', 'flag_abuse_for_thread', name='flag_abuse_for_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_thread', name='un_flag_abuse_for_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unvote$', 'undo_vote_for_thread', name='undo_vote_for_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/pin$', 'pin_thread', name='pin_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unpin$', 'un_pin_thread', name='un_pin_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/follow$', 'follow_thread', name='follow_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unfollow$', 'unfollow_thread', name='unfollow_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/close$', 'openclose_thread', name='openclose_thread'),
url(r'comments/(?P<comment_id>[\w\-]+)/update$', 'update_comment', name='update_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/endorse$', 'endorse_comment', name='endorse_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/reply$', 'create_sub_comment', name='create_sub_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/delete$', 'delete_comment', name='delete_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/upvote$', 'vote_for_comment', {'value': 'up'}, name='upvote_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/downvote$', 'vote_for_comment', {'value': 'down'}, name='downvote_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/unvote$', 'undo_vote_for_comment', name='undo_vote_for_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/flagAbuse$', 'flag_abuse_for_comment', name='flag_abuse_for_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_comment', name='un_flag_abuse_for_comment'),
url(r'^(?P<commentable_id>[\w\-.]+)/threads/create$', 'create_thread', name='create_thread'),
url(r'^(?P<commentable_id>[\w\-.]+)/follow$', 'follow_commentable', name='follow_commentable'),
url(r'^(?P<commentable_id>[\w\-.]+)/unfollow$', 'unfollow_commentable', name='unfollow_commentable'),
url(r'users$', 'users', name='users'),
)
|
agpl-3.0
|
[
624,
199,
1563,
8187,
367,
314,
1639,
63,
3349,
63,
1258,
14,
199,
624,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
12,
7970,
199,
199,
20050,
275,
7970,
8,
272,
283,
1176,
63,
3349,
63,
1258,
14,
1095,
14,
4196,
297,
339,
1166,
8,
82,
7,
5064,
4268,
283,
5064,
297,
536,
534,
5064,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
873,
4268,
283,
873,
63,
2671,
297,
536,
534,
873,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
8102,
4268,
283,
981,
63,
3349,
297,
536,
534,
981,
63,
3349,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
1807,
297,
283,
1807,
63,
2671,
297,
536,
534,
1807,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
384,
14317,
4268,
283,
14317,
63,
509,
63,
2671,
297,
791,
585,
356,
283,
384,
2267,
536,
534,
384,
14317,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
2110,
14317,
4268,
283,
14317,
63,
509,
63,
2671,
297,
791,
585,
356,
283,
2110,
2267,
536,
534,
2110,
14317,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
4173,
33,
464,
261,
4268,
283,
4173,
63,
371,
1180,
63,
509,
63,
2671,
297,
536,
534,
4173,
63,
371,
1180,
63,
509,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
5318,
33,
464,
261,
4268,
283,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
2671,
297,
536,
534,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
14317,
4268,
283,
11833,
63,
14317,
63,
509,
63,
2671,
297,
536,
534,
11833,
63,
14317,
63,
509,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
7751,
4268,
283,
7751,
63,
2671,
297,
536,
534,
7751,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
7751,
4268,
283,
324,
63,
7751,
63,
2671,
297,
536,
534,
324,
63,
7751,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
7207,
4268,
283,
7207,
63,
2671,
297,
536,
534,
7207,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
7207,
4268,
283,
324,
7207,
63,
2671,
297,
536,
534,
324,
7207,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
1600,
4268,
283,
1490,
1600,
63,
2671,
297,
536,
534,
1490,
1600,
63,
2671,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
873,
4268,
283,
873,
63,
3349,
297,
536,
534,
873,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
7454,
261,
4268,
283,
7454,
261,
63,
3349,
297,
536,
534,
7454,
261,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
8102,
4268,
283,
981,
63,
954,
63,
3349,
297,
536,
534,
981,
63,
954,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
1807,
4268,
283,
1807,
63,
3349,
297,
536,
534,
1807,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
384,
14317,
4268,
283,
14317,
63,
509,
63,
3349,
297,
791,
585,
356,
283,
384,
2267,
536,
534,
384,
14317,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
2110,
14317,
4268,
283,
14317,
63,
509,
63,
3349,
297,
791,
585,
356,
283,
2110,
2267,
536,
534,
2110,
14317,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
324,
14317,
4268,
283,
11833,
63,
14317,
63,
509,
63,
3349,
297,
536,
534,
11833,
63,
14317,
63,
509,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
4173,
33,
464,
261,
4268,
283,
4173,
63,
371,
1180,
63,
509,
63,
3349,
297,
536,
534,
4173,
63,
371,
1180,
63,
509,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
324,
5318,
33,
464,
261,
4268,
283,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
3349,
297,
536,
534,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
3349,
659,
272,
1166,
8,
82,
24550,
48,
28,
3349,
461,
63,
344,
24693,
87,
16185,
14,
24598,
6962,
15,
981,
4268,
283,
981,
63,
2671,
297,
536,
534,
981,
63,
2671,
659,
272,
1166,
8,
82,
24550,
48,
28,
3349,
461,
63,
344,
24693,
87,
16185,
14,
24598,
7207,
4268,
283,
7207,
63,
3349,
461,
297,
536,
534,
7207,
63,
3349,
461,
659,
272,
1166,
8,
82,
24550,
48,
28,
3349,
461,
63,
344,
24693,
87,
16185,
14,
24598,
324,
7207,
4268,
283,
324,
7207,
63,
3349,
461,
297,
536,
534,
324,
7207,
63,
3349,
461,
659,
272,
1166,
8,
82,
7,
3707,
4268,
283,
3707,
297,
536,
534,
3707,
659,
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
] |
[
199,
1563,
8187,
367,
314,
1639,
63,
3349,
63,
1258,
14,
199,
624,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
12,
7970,
199,
199,
20050,
275,
7970,
8,
272,
283,
1176,
63,
3349,
63,
1258,
14,
1095,
14,
4196,
297,
339,
1166,
8,
82,
7,
5064,
4268,
283,
5064,
297,
536,
534,
5064,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
873,
4268,
283,
873,
63,
2671,
297,
536,
534,
873,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
8102,
4268,
283,
981,
63,
3349,
297,
536,
534,
981,
63,
3349,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
1807,
297,
283,
1807,
63,
2671,
297,
536,
534,
1807,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
384,
14317,
4268,
283,
14317,
63,
509,
63,
2671,
297,
791,
585,
356,
283,
384,
2267,
536,
534,
384,
14317,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
2110,
14317,
4268,
283,
14317,
63,
509,
63,
2671,
297,
791,
585,
356,
283,
2110,
2267,
536,
534,
2110,
14317,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
4173,
33,
464,
261,
4268,
283,
4173,
63,
371,
1180,
63,
509,
63,
2671,
297,
536,
534,
4173,
63,
371,
1180,
63,
509,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
5318,
33,
464,
261,
4268,
283,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
2671,
297,
536,
534,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
14317,
4268,
283,
11833,
63,
14317,
63,
509,
63,
2671,
297,
536,
534,
11833,
63,
14317,
63,
509,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
7751,
4268,
283,
7751,
63,
2671,
297,
536,
534,
7751,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
7751,
4268,
283,
324,
63,
7751,
63,
2671,
297,
536,
534,
324,
63,
7751,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
7207,
4268,
283,
7207,
63,
2671,
297,
536,
534,
7207,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
324,
7207,
4268,
283,
324,
7207,
63,
2671,
297,
536,
534,
324,
7207,
63,
2671,
659,
272,
1166,
8,
82,
1133,
72,
15656,
9448,
48,
28,
2671,
63,
344,
24693,
87,
16185,
24598,
1600,
4268,
283,
1490,
1600,
63,
2671,
297,
536,
534,
1490,
1600,
63,
2671,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
873,
4268,
283,
873,
63,
3349,
297,
536,
534,
873,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
7454,
261,
4268,
283,
7454,
261,
63,
3349,
297,
536,
534,
7454,
261,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
8102,
4268,
283,
981,
63,
954,
63,
3349,
297,
536,
534,
981,
63,
954,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
1807,
4268,
283,
1807,
63,
3349,
297,
536,
534,
1807,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
384,
14317,
4268,
283,
14317,
63,
509,
63,
3349,
297,
791,
585,
356,
283,
384,
2267,
536,
534,
384,
14317,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
2110,
14317,
4268,
283,
14317,
63,
509,
63,
3349,
297,
791,
585,
356,
283,
2110,
2267,
536,
534,
2110,
14317,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
324,
14317,
4268,
283,
11833,
63,
14317,
63,
509,
63,
3349,
297,
536,
534,
11833,
63,
14317,
63,
509,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
4173,
33,
464,
261,
4268,
283,
4173,
63,
371,
1180,
63,
509,
63,
3349,
297,
536,
534,
4173,
63,
371,
1180,
63,
509,
63,
3349,
659,
272,
1166,
8,
82,
7,
6223,
9448,
48,
28,
3349,
63,
344,
24693,
87,
16185,
24598,
324,
5318,
33,
464,
261,
4268,
283,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
3349,
297,
536,
534,
324,
63,
4173,
63,
371,
1180,
63,
509,
63,
3349,
659,
272,
1166,
8,
82,
24550,
48,
28,
3349,
461,
63,
344,
24693,
87,
16185,
14,
24598,
6962,
15,
981,
4268,
283,
981,
63,
2671,
297,
536,
534,
981,
63,
2671,
659,
272,
1166,
8,
82,
24550,
48,
28,
3349,
461,
63,
344,
24693,
87,
16185,
14,
24598,
7207,
4268,
283,
7207,
63,
3349,
461,
297,
536,
534,
7207,
63,
3349,
461,
659,
272,
1166,
8,
82,
24550,
48,
28,
3349,
461,
63,
344,
24693,
87,
16185,
14,
24598,
324,
7207,
4268,
283,
324,
7207,
63,
3349,
461,
297,
536,
534,
324,
7207,
63,
3349,
461,
659,
272,
1166,
8,
82,
7,
3707,
4268,
283,
3707,
297,
536,
534,
3707,
659,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
stilobique/UE4-Tools
|
controllers/data_buffer.py
|
1
|
3448
|
import bpy
import pyperclip
from math import degrees
class DataBuffer(bpy.types.Operator):
"""Export data Position, Rotation and Scale of all selected element"""
bl_idname = "object.data_buffer"
bl_label = "Paste information buffer"
def execute(self, context):
objs = context.selected_objects
string_data_prefixe = 'Begin Map \n'' Begin Level \n'
string_data_suffixe = ' End Level\n''Begin Surface\n''End ' \
'Surface\n''End Map'
string_data = ""
for element in objs:
if element is not None:
position_x = str(round(element.location.x * 100, 2))
position_y = str(round(element.location.y * -100, 2))
position_z = str(round(element.location.z * 100, 2))
rotation_pitch = str(round(degrees(element.rotation_euler.y), 2))
rotation_yaw = str(round(degrees(element.rotation_euler.z),
2)* -1)
rotation_roll = str(round(degrees(element.rotation_euler.x), 2))
string_data = string_data + \
' Begin Actor '\
'Class=StaticMeshActor '\
'Name=' + element.name + ' ' \
'Archetype=StaticMeshActor'\
'\'/Script/Engine.Default__StaticMeshActor\'\n'\
' Begin Object Class=StaticMeshComponent '\
'Name=StaticMeshComponent0 '\
'ObjName=StaticMeshComponent0 ' \
'Archetype=StaticMeshComponent'\
'\'/Script/Engine.Default__StaticMeshActor:StaticMeshComponent0' \
'\'\n'\
' End Object\n'\
' Begin Object '\
'Name=StaticMeshComponent0\n'\
' StaticMesh=StaticMesh\'/Engine/EditorMeshes/EditorCube' \
'.EditorCube\' \n'\
' RelativeLocation=(X=' + position_x + ',Y=' + \
position_y + ',Z=' + position_z + ')\n'\
' RelativeScale3D=(X=' + str(round(element.scale.x, 2)) + ',' \
'Y=' + str(round(element.scale.y, 2)) + ',' \
'Z=' + \
str(round(element.scale.z, 2)) + ')\n'\
' RelativeRotation=(Pitch=' + rotation_pitch + ',Yaw=' + \
rotation_yaw + ',' \
'Roll=' + \
rotation_roll + ')\n'\
' CustomProperties\n' \
' End Object\n' \
' StaticMeshComponent=StaticMeshComponent0\n' \
' Components(0)=StaticMeshComponent0\n' \
' RootComponent=StaticMeshComponent0\n' \
' ActorLabel="' + element.name + '"\n' \
' End Actor\n' \
else:
self.report({'WARNING'}, "Select an object(s).")
return {'CANCELLED'}
string_complete = string_data_prefixe + string_data \
+ string_data_suffixe
# copyBuffer(objs[0].name)
pyperclip.copy(string_complete)
print(string_complete)
self.report({'INFO'}, "Data copied on your Buffer.")
return {'FINISHED'}
def register():
bpy.utils.register_class(DataBuffer)
def unregister():
bpy.utils.unregister_class(DataBuffer)
if __name__ == "__main__":
register()
|
gpl-3.0
|
[
646,
20575,
199,
646,
1134,
529,
7548,
199,
199,
504,
3473,
492,
14358,
421,
199,
533,
3918,
3299,
8,
66,
647,
14,
1313,
14,
7961,
304,
272,
408,
11399,
666,
15483,
12,
28642,
436,
22869,
402,
1006,
4895,
1819,
624,
272,
6826,
63,
344,
354,
275,
298,
785,
14,
576,
63,
2738,
2,
272,
6826,
63,
1302,
275,
298,
48,
9209,
2556,
3335,
2,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
13474,
275,
1067,
14,
5511,
63,
1462,
267,
1059,
63,
576,
63,
1861,
69,
275,
283,
5595,
9672,
971,
78,
891,
257,
25754,
20400,
971,
78,
7,
267,
1059,
63,
576,
63,
4511,
69,
275,
283,
257,
9599,
20400,
60,
78,
891,
5595,
29564,
60,
78,
891,
3005,
283,
971,
2892,
283,
16923,
60,
78,
891,
3005,
9672,
7,
267,
1059,
63,
576,
275,
3087,
398,
367,
1819,
315,
13474,
26,
288,
340,
1819,
365,
440,
488,
26,
355,
3421,
63,
88,
275,
620,
8,
2363,
8,
2108,
14,
1985,
14,
88,
627,
2948,
12,
499,
430,
355,
3421,
63,
89,
275,
620,
8,
2363,
8,
2108,
14,
1985,
14,
89,
627,
446,
1960,
12,
499,
430,
355,
3421,
63,
90,
275,
620,
8,
2363,
8,
2108,
14,
1985,
14,
90,
627,
2948,
12,
499,
430,
355,
13038,
63,
16966,
275,
620,
8,
2363,
8,
20251,
8,
2108,
14,
15362,
63,
69,
19345,
14,
89,
395,
499,
430,
355,
13038,
63,
89,
10084,
275,
620,
8,
2363,
8,
20251,
8,
2108,
14,
15362,
63,
69,
19345,
14,
90,
395,
1460,
499,
3342,
446,
17,
9,
355,
13038,
63,
2827,
275,
620,
8,
2363,
8,
20251,
8,
2108,
14,
15362,
63,
69,
19345,
14,
88,
395,
499,
430,
355,
1059,
63,
576,
275,
1059,
63,
576,
435,
971,
272,
283,
420,
25754,
437,
630,
1557,
288,
283,
2543,
29,
9278,
12241,
12258,
1557,
288,
283,
985,
534,
435,
1819,
14,
354,
435,
283,
283,
971,
288,
283,
1596,
595,
466,
29,
9278,
12241,
12258,
1154,
288,
1557,
9807,
5229,
15,
8524,
14,
2698,
363,
9278,
12241,
12258,
24908,
78,
1154,
272,
283,
260,
25754,
6935,
8089,
29,
9278,
12241,
7004,
1557,
355,
283,
985,
29,
9278,
12241,
7004,
16,
1557,
355,
283,
5665,
985,
29,
9278,
12241,
7004,
16,
283,
971,
355,
283,
1596,
595,
466,
29,
9278,
12241,
7004,
1154,
355,
1557,
9807,
5229,
15,
8524,
14,
2698,
363,
9278,
12241,
12258,
26,
9278,
12241,
7004,
16,
7,
971,
639,
1557,
1154,
78,
1154,
272,
283,
260,
9599,
6935,
60,
78,
1154,
272,
283,
260,
25754,
6935,
1557,
355,
283,
985,
29,
9278,
12241,
7004,
16,
60,
78,
1154,
272,
283,
3322,
13599,
12241,
29,
9278,
12241,
3985,
15,
8524,
15,
10423,
12241,
397,
15,
10423,
25043,
7,
971,
639,
1987,
10423,
25043,
3985,
971,
78,
1154,
272,
283,
3322,
22419,
6592,
2687,
56,
534,
435,
3421,
63,
88,
435,
1656,
57,
534,
435,
971,
272,
3421,
63,
89,
435,
1656,
58,
534,
435,
3421,
63,
90,
435,
283,
2862,
78,
1154,
272,
283,
3322,
22419,
9944,
19,
36,
2687,
56,
534,
435,
620,
8,
2363,
8,
2108,
14,
3467,
14,
88,
12,
499,
430,
435,
13647,
971,
21709,
283,
57,
534,
435,
620,
8,
2363,
8,
2108,
14,
3467,
14,
89,
12,
499,
430,
435,
13647,
971,
6684,
420,
283,
58,
534,
435,
971,
272,
620,
8,
2363,
8,
2108,
14,
3467,
14,
90,
12,
499,
430,
435,
283,
2862,
78,
1154,
272,
283,
3322,
22419,
28247,
2687,
48,
9414,
534,
435,
13038,
63,
16966,
435,
1656,
57,
10084,
534,
435,
971,
272,
13038,
63,
89,
10084,
435,
13647,
971,
16854,
283,
24363,
534,
435,
971,
272,
13038,
63,
2827,
435,
283,
2862,
78,
1154,
272,
283,
3322,
8388,
8516,
60,
78,
7,
971,
272,
283,
260,
9599,
6935,
60,
78,
7,
971,
272,
283,
260,
13599,
12241,
7004,
29,
9278,
12241,
7004,
16,
60,
78,
7,
971,
272,
283,
260,
17823,
8,
16,
23397,
9278,
12241,
7004,
16,
60,
78,
7,
971,
272,
283,
260,
12826,
7004,
29,
9278,
12241,
7004,
16,
60,
78,
7,
971,
272,
283,
260,
437,
630,
4314,
26957,
435,
1819,
14,
354,
435,
283,
3212,
78,
7,
971,
272,
283,
420,
9599,
437,
630,
60,
78,
7,
971,
953,
587,
26,
355,
291,
14,
3070,
3252,
9171,
2267,
298,
5446,
376,
909,
8,
83,
26744,
2234,
372,
791,
20707,
5290,
936,
398,
1059,
63,
4883,
275,
1059,
63,
576,
63,
1861,
69,
435,
1059,
63,
576,
971,
2079,
435,
1059,
63,
576,
63,
4511,
69,
398,
327,
1331,
3299,
8,
8718,
59,
16,
1055,
354,
9,
267,
1134,
529,
7548,
14,
1574,
8,
875,
63,
4883,
9,
398,
870,
8,
875,
63,
4883,
9,
7318,
291,
14,
3070,
3252,
4531,
2267,
298,
1451,
8876,
641,
2195,
26661,
2685,
267,
372,
791,
17383,
20450,
936,
421,
199,
318,
2274,
837,
272,
20575,
14,
1208,
14,
2683,
63,
533,
8,
1451,
3299,
9,
421,
199,
318,
24369,
837,
272,
20575,
14,
1208,
14,
18408,
63,
533,
8,
1451,
3299,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2274,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
20575,
199,
646,
1134,
529,
7548,
199,
199,
504,
3473,
492,
14358,
421,
199,
533,
3918,
3299,
8,
66,
647,
14,
1313,
14,
7961,
304,
272,
408,
11399,
666,
15483,
12,
28642,
436,
22869,
402,
1006,
4895,
1819,
624,
272,
6826,
63,
344,
354,
275,
298,
785,
14,
576,
63,
2738,
2,
272,
6826,
63,
1302,
275,
298,
48,
9209,
2556,
3335,
2,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
13474,
275,
1067,
14,
5511,
63,
1462,
267,
1059,
63,
576,
63,
1861,
69,
275,
283,
5595,
9672,
971,
78,
891,
257,
25754,
20400,
971,
78,
7,
267,
1059,
63,
576,
63,
4511,
69,
275,
283,
257,
9599,
20400,
60,
78,
891,
5595,
29564,
60,
78,
891,
3005,
283,
971,
2892,
283,
16923,
60,
78,
891,
3005,
9672,
7,
267,
1059,
63,
576,
275,
3087,
398,
367,
1819,
315,
13474,
26,
288,
340,
1819,
365,
440,
488,
26,
355,
3421,
63,
88,
275,
620,
8,
2363,
8,
2108,
14,
1985,
14,
88,
627,
2948,
12,
499,
430,
355,
3421,
63,
89,
275,
620,
8,
2363,
8,
2108,
14,
1985,
14,
89,
627,
446,
1960,
12,
499,
430,
355,
3421,
63,
90,
275,
620,
8,
2363,
8,
2108,
14,
1985,
14,
90,
627,
2948,
12,
499,
430,
355,
13038,
63,
16966,
275,
620,
8,
2363,
8,
20251,
8,
2108,
14,
15362,
63,
69,
19345,
14,
89,
395,
499,
430,
355,
13038,
63,
89,
10084,
275,
620,
8,
2363,
8,
20251,
8,
2108,
14,
15362,
63,
69,
19345,
14,
90,
395,
1460,
499,
3342,
446,
17,
9,
355,
13038,
63,
2827,
275,
620,
8,
2363,
8,
20251,
8,
2108,
14,
15362,
63,
69,
19345,
14,
88,
395,
499,
430,
355,
1059,
63,
576,
275,
1059,
63,
576,
435,
971,
272,
283,
420,
25754,
437,
630,
1557,
288,
283,
2543,
29,
9278,
12241,
12258,
1557,
288,
283,
985,
534,
435,
1819,
14,
354,
435,
283,
283,
971,
288,
283,
1596,
595,
466,
29,
9278,
12241,
12258,
1154,
288,
1557,
9807,
5229,
15,
8524,
14,
2698,
363,
9278,
12241,
12258,
24908,
78,
1154,
272,
283,
260,
25754,
6935,
8089,
29,
9278,
12241,
7004,
1557,
355,
283,
985,
29,
9278,
12241,
7004,
16,
1557,
355,
283,
5665,
985,
29,
9278,
12241,
7004,
16,
283,
971,
355,
283,
1596,
595,
466,
29,
9278,
12241,
7004,
1154,
355,
1557,
9807,
5229,
15,
8524,
14,
2698,
363,
9278,
12241,
12258,
26,
9278,
12241,
7004,
16,
7,
971,
639,
1557,
1154,
78,
1154,
272,
283,
260,
9599,
6935,
60,
78,
1154,
272,
283,
260,
25754,
6935,
1557,
355,
283,
985,
29,
9278,
12241,
7004,
16,
60,
78,
1154,
272,
283,
3322,
13599,
12241,
29,
9278,
12241,
3985,
15,
8524,
15,
10423,
12241,
397,
15,
10423,
25043,
7,
971,
639,
1987,
10423,
25043,
3985,
971,
78,
1154,
272,
283,
3322,
22419,
6592,
2687,
56,
534,
435,
3421,
63,
88,
435,
1656,
57,
534,
435,
971,
272,
3421,
63,
89,
435,
1656,
58,
534,
435,
3421,
63,
90,
435,
283,
2862,
78,
1154,
272,
283,
3322,
22419,
9944,
19,
36,
2687,
56,
534,
435,
620,
8,
2363,
8,
2108,
14,
3467,
14,
88,
12,
499,
430,
435,
13647,
971,
21709,
283,
57,
534,
435,
620,
8,
2363,
8,
2108,
14,
3467,
14,
89,
12,
499,
430,
435,
13647,
971,
6684,
420,
283,
58,
534,
435,
971,
272,
620,
8,
2363,
8,
2108,
14,
3467,
14,
90,
12,
499,
430,
435,
283,
2862,
78,
1154,
272,
283,
3322,
22419,
28247,
2687,
48,
9414,
534,
435,
13038,
63,
16966,
435,
1656,
57,
10084,
534,
435,
971,
272,
13038,
63,
89,
10084,
435,
13647,
971,
16854,
283,
24363,
534,
435,
971,
272,
13038,
63,
2827,
435,
283,
2862,
78,
1154,
272,
283,
3322,
8388,
8516,
60,
78,
7,
971,
272,
283,
260,
9599,
6935,
60,
78,
7,
971,
272,
283,
260,
13599,
12241,
7004,
29,
9278,
12241,
7004,
16,
60,
78,
7,
971,
272,
283,
260,
17823,
8,
16,
23397,
9278,
12241,
7004,
16,
60,
78,
7,
971,
272,
283,
260,
12826,
7004,
29,
9278,
12241,
7004,
16,
60,
78,
7,
971,
272,
283,
260,
437,
630,
4314,
26957,
435,
1819,
14,
354,
435,
283,
3212,
78,
7,
971,
272,
283,
420,
9599,
437,
630,
60,
78,
7,
971,
953,
587,
26,
355,
291,
14,
3070,
3252,
9171,
2267,
298,
5446,
376,
909,
8,
83,
26744,
2234,
372,
791,
20707,
5290,
936,
398,
1059,
63,
4883,
275,
1059,
63,
576,
63,
1861,
69,
435,
1059,
63,
576,
971,
2079,
435,
1059,
63,
576,
63,
4511,
69,
398,
327,
1331,
3299,
8,
8718,
59,
16,
1055,
354,
9,
267,
1134,
529,
7548,
14,
1574,
8,
875,
63,
4883,
9,
398,
870,
8,
875,
63,
4883,
9,
7318,
291,
14,
3070,
3252,
4531,
2267,
298,
1451,
8876,
641,
2195,
26661,
2685,
267,
372,
791,
17383,
20450,
936,
421,
199,
318,
2274,
837,
272,
20575,
14,
1208,
14,
2683,
63,
533,
8,
1451,
3299,
9,
421,
199,
318,
24369,
837,
272,
20575,
14,
1208,
14,
18408,
63,
533,
8,
1451,
3299,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2274,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
stephane-martin/salt-debian-packaging
|
salt-2016.3.3/salt/pillar/http_yaml.py
|
2
|
1157
|
# -*- coding: utf-8 -*-
"""
A module that adds data to the Pillar structure retrieved by an http request
Configuring the HTTP_YAML ext_pillar
====================================
Set the following Salt config to setup Foreman as external pillar source:
.. code-block:: yaml
ext_pillar:
- http_yaml:
url: http://example.com/api/minion_id
::TODO::
username: username
password: password
Module Documentation
====================
"""
from __future__ import absolute_import
# Import python libs
import logging
def ext_pillar(minion_id,
pillar, # pylint: disable=W0613
url=None):
"""
Read pillar data from HTTP response.
:param url String to make request
:returns dict with pillar data to add
:returns empty if error
"""
# Set up logging
log = logging.getLogger(__name__)
data = __salt__['http.query'](url=url, decode=True, decode_type='yaml')
if 'dict' in data:
return data['dict']
log.error('Error caught on query to' + url + '\nMore Info:\n')
for k, v in data.iteritems():
log.error(k + ' : ' + v)
return {}
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
33,
859,
626,
9584,
666,
370,
314,
510,
778,
285,
5523,
12396,
701,
376,
1455,
1056,
421,
199,
2028,
4039,
314,
3101,
63,
23103,
1599,
63,
80,
778,
285,
199,
2486,
532,
199,
199,
1084,
314,
2569,
428,
4478,
1101,
370,
3272,
21684,
1237,
465,
5957,
299,
778,
285,
1350,
26,
199,
199,
703,
1233,
13,
1457,
447,
8864,
819,
1599,
63,
80,
778,
285,
26,
272,
446,
1455,
63,
5963,
26,
267,
1166,
26,
1455,
921,
2694,
14,
957,
15,
1246,
15,
827,
1636,
63,
344,
267,
3800,
11768,
447,
267,
3434,
26,
3434,
267,
2505,
26,
2505,
199,
199,
2377,
15249,
199,
1280,
532,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
3,
3161,
2366,
20314,
199,
646,
2050,
421,
199,
318,
1599,
63,
80,
778,
285,
8,
827,
1636,
63,
344,
12,
2049,
299,
778,
285,
12,
221,
327,
4287,
26,
3507,
29,
55,
1690,
969,
2049,
1166,
29,
403,
304,
272,
408,
272,
5574,
299,
778,
285,
666,
687,
3101,
1177,
14,
339,
520,
635,
1166,
2624,
370,
1852,
1056,
272,
520,
5808,
1211,
543,
299,
778,
285,
666,
370,
1050,
272,
520,
5808,
2701,
340,
1125,
272,
408,
272,
327,
2494,
1536,
2050,
272,
943,
275,
2050,
14,
5572,
3460,
354,
3368,
339,
666,
275,
636,
12597,
23010,
1014,
14,
1131,
21407,
633,
29,
633,
12,
4849,
29,
549,
12,
4849,
63,
466,
534,
5963,
358,
339,
340,
283,
807,
7,
315,
666,
26,
267,
372,
666,
459,
807,
418,
339,
943,
14,
705,
360,
547,
15604,
641,
1827,
370,
7,
435,
1166,
435,
1557,
78,
11053,
10332,
3427,
78,
358,
339,
367,
1022,
12,
373,
315,
666,
14,
4611,
837,
267,
943,
14,
705,
8,
75,
435,
283,
520,
283,
435,
373,
9,
339,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
33,
859,
626,
9584,
666,
370,
314,
510,
778,
285,
5523,
12396,
701,
376,
1455,
1056,
421,
199,
2028,
4039,
314,
3101,
63,
23103,
1599,
63,
80,
778,
285,
199,
2486,
532,
199,
199,
1084,
314,
2569,
428,
4478,
1101,
370,
3272,
21684,
1237,
465,
5957,
299,
778,
285,
1350,
26,
199,
199,
703,
1233,
13,
1457,
447,
8864,
819,
1599,
63,
80,
778,
285,
26,
272,
446,
1455,
63,
5963,
26,
267,
1166,
26,
1455,
921,
2694,
14,
957,
15,
1246,
15,
827,
1636,
63,
344,
267,
3800,
11768,
447,
267,
3434,
26,
3434,
267,
2505,
26,
2505,
199,
199,
2377,
15249,
199,
1280,
532,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
3,
3161,
2366,
20314,
199,
646,
2050,
421,
199,
318,
1599,
63,
80,
778,
285,
8,
827,
1636,
63,
344,
12,
2049,
299,
778,
285,
12,
221,
327,
4287,
26,
3507,
29,
55,
1690,
969,
2049,
1166,
29,
403,
304,
272,
408,
272,
5574,
299,
778,
285,
666,
687,
3101,
1177,
14,
339,
520,
635,
1166,
2624,
370,
1852,
1056,
272,
520,
5808,
1211,
543,
299,
778,
285,
666,
370,
1050,
272,
520,
5808,
2701,
340,
1125,
272,
408,
272,
327,
2494,
1536,
2050,
272,
943,
275,
2050,
14,
5572,
3460,
354,
3368,
339,
666,
275,
636,
12597,
23010,
1014,
14,
1131,
21407,
633,
29,
633,
12,
4849,
29,
549,
12,
4849,
63,
466,
534,
5963,
358,
339,
340,
283,
807,
7,
315,
666,
26,
267,
372,
666,
459,
807,
418,
339,
943,
14,
705,
360,
547,
15604,
641,
1827,
370,
7,
435,
1166,
435,
1557,
78,
11053,
10332,
3427,
78,
358,
339,
367,
1022,
12,
373,
315,
666,
14,
4611,
837,
267,
943,
14,
705,
8,
75,
435,
283,
520,
283,
435,
373,
9,
339,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
CTSRD-SOAAP/chromium-42.0.2311.135
|
native_client/pnacl/driver/tests/pnacl_ld_options_test.py
|
4
|
2777
|
#!/usr/bin/python
# Copyright (c) 2014 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests of the pnacl driver.
This tests that pnacl-ld manages linking and LLVM opt flags correctly.
"""
import cStringIO
import re
import unittest
from driver_env import env
import driver_log
import driver_test_utils
import driver_tools
class TestLDOptions(driver_test_utils.DriverTesterCommon):
def setUp(self):
super(TestLDOptions, self).setUp()
driver_test_utils.ApplyTestEnvOverrides(env)
def getBitcode(self, finalized=True):
# Even --dry-run requires a file to exist, so make a fake bitcode file.
# It even cares that the file is really bitcode.
with self.getTemp(suffix='.ll', close=False) as t:
with self.getTemp(suffix='.o') as o:
t.write('''
define i32 @_start() {
ret i32 0
}
''')
t.close()
driver_tools.RunDriver('pnacl-as', [t.name, '-o', o.name])
return o
def checkLDOptNumRuns(self, bitcode, flags, num_runs):
""" Given a |bitcode| file the |arch| and additional pnacl-ld |flags|,
check that opt will only be run |num_runs| times. """
# TODO(jvoung): Get rid of INHERITED_DRIVER_ARGS, which leaks across runs.
env.set('INHERITED_DRIVER_ARGS', '')
temp_output = self.getTemp()
capture_out = cStringIO.StringIO()
driver_log.Log.CaptureToStream(capture_out)
driver_tools.RunDriver('pnacl-ld',
['--pnacl-driver-verbose',
'--dry-run',
bitcode.name,
'-o', temp_output.name] + flags)
driver_log.Log.ResetStreams()
out = capture_out.getvalue()
split_out = out.splitlines()
count = 0
for line in split_out:
if re.search('Running: .*opt( |\.exe)', line):
count += 1
self.assertEqual(num_runs, count)
def test_num_opt_runs(self):
""" Test that pnacl-ld will merge or not merge runs of LLVM's opt tool"""
if driver_test_utils.CanRunHost():
bitcode = self.getBitcode()
# Test O2, static. Opt should run all passes in one go.
self.checkLDOptNumRuns(
bitcode,
['-O2', '-static'],
1)
# Test with separate runs per pass.
self.checkLDOptNumRuns(
bitcode,
['-O2', '-static', '--pnacl-run-passes-separately'],
3)
# Same with strip-all.
self.checkLDOptNumRuns(
bitcode,
['-O2', '-static', '--strip-all'],
1)
self.checkLDOptNumRuns(
bitcode,
['-O2', '-static', '--strip-all', '--pnacl-run-passes-separately'],
4)
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6927,
710,
653,
1905,
6810,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
2925,
402,
314,
299,
7745,
5253,
14,
199,
199,
2765,
2295,
626,
299,
7745,
13,
1447,
31965,
25833,
436,
491,
28631,
2450,
3285,
6657,
14,
199,
624,
199,
199,
646,
15073,
199,
646,
295,
199,
646,
2882,
199,
199,
504,
5253,
63,
1813,
492,
2589,
199,
646,
5253,
63,
793,
199,
646,
5253,
63,
396,
63,
1208,
199,
646,
5253,
63,
2537,
199,
199,
533,
1379,
44,
1649,
494,
83,
8,
3090,
63,
396,
63,
1208,
14,
6158,
22403,
7844,
304,
523,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
44,
1649,
494,
83,
12,
291,
680,
5996,
342,
272,
5253,
63,
396,
63,
1208,
14,
16581,
774,
7744,
27586,
8,
1813,
9,
819,
347,
664,
4734,
600,
8,
277,
12,
4242,
1759,
29,
549,
304,
272,
327,
22207,
1553,
10481,
13,
1065,
5074,
282,
570,
370,
2187,
12,
880,
1852,
282,
4026,
4546,
600,
570,
14,
272,
327,
2779,
2755,
1704,
470,
626,
314,
570,
365,
7710,
4546,
600,
14,
272,
543,
291,
14,
362,
6530,
8,
4511,
15637,
914,
297,
4002,
29,
797,
9,
465,
307,
26,
489,
543,
291,
14,
362,
6530,
8,
4511,
15637,
79,
358,
465,
312,
26,
267,
307,
14,
952,
10505,
199,
4640,
284,
708,
19915,
928,
342,
469,
523,
2203,
284,
708,
378,
199,
93,
199,
12310,
267,
307,
14,
1600,
342,
267,
5253,
63,
2537,
14,
2540,
6158,
360,
80,
7745,
13,
305,
297,
359,
84,
14,
354,
12,
2475,
79,
297,
312,
14,
354,
566,
267,
372,
312,
8330,
347,
1104,
44,
1649,
541,
5667,
16291,
8,
277,
12,
4546,
600,
12,
3285,
12,
1967,
63,
10802,
304,
272,
408,
9138,
282,
1204,
2075,
600,
92,
570,
314,
1204,
1047,
92,
436,
4722,
299,
7745,
13,
1447,
1204,
2469,
18712,
272,
1104,
626,
2450,
911,
1454,
506,
1255,
1204,
1507,
63,
10802,
92,
5431,
14,
408,
272,
327,
3254,
8,
74,
2392,
10335,
304,
2372,
16146,
402,
1621,
3452,
649,
1149,
63,
23401,
63,
13990,
12,
1314,
1026,
14631,
9371,
7858,
14,
272,
2589,
14,
409,
360,
568,
3452,
649,
1149,
63,
23401,
63,
13990,
297,
4074,
272,
2388,
63,
1199,
275,
291,
14,
362,
6530,
342,
272,
12296,
63,
548,
275,
15073,
14,
6424,
342,
272,
5253,
63,
793,
14,
2445,
14,
16640,
1378,
3296,
8,
12685,
63,
548,
9,
272,
5253,
63,
2537,
14,
2540,
6158,
360,
80,
7745,
13,
1447,
297,
2574,
14574,
80,
7745,
13,
3090,
13,
3832,
297,
1169,
2850,
10481,
13,
1065,
297,
1169,
4546,
600,
14,
354,
12,
1169,
2475,
79,
297,
2388,
63,
1199,
14,
354,
61,
435,
3285,
9,
272,
5253,
63,
793,
14,
2445,
14,
9637,
19358,
342,
272,
734,
275,
12296,
63,
548,
14,
7150,
342,
272,
3715,
63,
548,
275,
734,
14,
7644,
342,
272,
2338,
275,
378,
272,
367,
1004,
315,
3715,
63,
548,
26,
489,
340,
295,
14,
1733,
360,
9602,
26,
23076,
2992,
8,
1204,
4537,
5803,
3196,
1004,
304,
267,
2338,
847,
413,
272,
291,
14,
629,
8,
1507,
63,
10802,
12,
2338,
9,
819,
347,
511,
63,
1507,
63,
2992,
63,
10802,
8,
277,
304,
272,
408,
1379,
626,
299,
7745,
13,
1447,
911,
5389,
503,
440,
5389,
7858,
402,
491,
28631,
1159,
2450,
4744,
624,
272,
340,
5253,
63,
396,
63,
1208,
14,
6049,
2540,
4965,
837,
489,
4546,
600,
275,
291,
14,
362,
4734,
600,
342,
489,
327,
1379,
593,
18,
12,
2955,
14,
593,
541,
1077,
1255,
1006,
14933,
315,
1373,
2621,
14,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
995,
881,
413,
9,
489,
327,
1379,
543,
7396,
7858,
1126,
986,
14,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
297,
2850,
80,
7745,
13,
1065,
13,
16027,
13,
6175,
13824,
995,
881,
650,
9,
489,
327,
14766,
543,
6202,
13,
452,
14,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
297,
2850,
1913,
13,
452,
995,
881,
413,
9,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
297,
2850,
1913,
13,
452,
297,
2850,
80,
7745,
13,
1065,
13,
16027,
13,
6175,
13824,
995,
881,
841,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6927,
710,
653,
1905,
6810,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
2925,
402,
314,
299,
7745,
5253,
14,
199,
199,
2765,
2295,
626,
299,
7745,
13,
1447,
31965,
25833,
436,
491,
28631,
2450,
3285,
6657,
14,
199,
624,
199,
199,
646,
15073,
199,
646,
295,
199,
646,
2882,
199,
199,
504,
5253,
63,
1813,
492,
2589,
199,
646,
5253,
63,
793,
199,
646,
5253,
63,
396,
63,
1208,
199,
646,
5253,
63,
2537,
199,
199,
533,
1379,
44,
1649,
494,
83,
8,
3090,
63,
396,
63,
1208,
14,
6158,
22403,
7844,
304,
523,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
44,
1649,
494,
83,
12,
291,
680,
5996,
342,
272,
5253,
63,
396,
63,
1208,
14,
16581,
774,
7744,
27586,
8,
1813,
9,
819,
347,
664,
4734,
600,
8,
277,
12,
4242,
1759,
29,
549,
304,
272,
327,
22207,
1553,
10481,
13,
1065,
5074,
282,
570,
370,
2187,
12,
880,
1852,
282,
4026,
4546,
600,
570,
14,
272,
327,
2779,
2755,
1704,
470,
626,
314,
570,
365,
7710,
4546,
600,
14,
272,
543,
291,
14,
362,
6530,
8,
4511,
15637,
914,
297,
4002,
29,
797,
9,
465,
307,
26,
489,
543,
291,
14,
362,
6530,
8,
4511,
15637,
79,
358,
465,
312,
26,
267,
307,
14,
952,
10505,
199,
4640,
284,
708,
19915,
928,
342,
469,
523,
2203,
284,
708,
378,
199,
93,
199,
12310,
267,
307,
14,
1600,
342,
267,
5253,
63,
2537,
14,
2540,
6158,
360,
80,
7745,
13,
305,
297,
359,
84,
14,
354,
12,
2475,
79,
297,
312,
14,
354,
566,
267,
372,
312,
8330,
347,
1104,
44,
1649,
541,
5667,
16291,
8,
277,
12,
4546,
600,
12,
3285,
12,
1967,
63,
10802,
304,
272,
408,
9138,
282,
1204,
2075,
600,
92,
570,
314,
1204,
1047,
92,
436,
4722,
299,
7745,
13,
1447,
1204,
2469,
18712,
272,
1104,
626,
2450,
911,
1454,
506,
1255,
1204,
1507,
63,
10802,
92,
5431,
14,
408,
272,
327,
3254,
8,
74,
2392,
10335,
304,
2372,
16146,
402,
1621,
3452,
649,
1149,
63,
23401,
63,
13990,
12,
1314,
1026,
14631,
9371,
7858,
14,
272,
2589,
14,
409,
360,
568,
3452,
649,
1149,
63,
23401,
63,
13990,
297,
4074,
272,
2388,
63,
1199,
275,
291,
14,
362,
6530,
342,
272,
12296,
63,
548,
275,
15073,
14,
6424,
342,
272,
5253,
63,
793,
14,
2445,
14,
16640,
1378,
3296,
8,
12685,
63,
548,
9,
272,
5253,
63,
2537,
14,
2540,
6158,
360,
80,
7745,
13,
1447,
297,
2574,
14574,
80,
7745,
13,
3090,
13,
3832,
297,
1169,
2850,
10481,
13,
1065,
297,
1169,
4546,
600,
14,
354,
12,
1169,
2475,
79,
297,
2388,
63,
1199,
14,
354,
61,
435,
3285,
9,
272,
5253,
63,
793,
14,
2445,
14,
9637,
19358,
342,
272,
734,
275,
12296,
63,
548,
14,
7150,
342,
272,
3715,
63,
548,
275,
734,
14,
7644,
342,
272,
2338,
275,
378,
272,
367,
1004,
315,
3715,
63,
548,
26,
489,
340,
295,
14,
1733,
360,
9602,
26,
23076,
2992,
8,
1204,
4537,
5803,
3196,
1004,
304,
267,
2338,
847,
413,
272,
291,
14,
629,
8,
1507,
63,
10802,
12,
2338,
9,
819,
347,
511,
63,
1507,
63,
2992,
63,
10802,
8,
277,
304,
272,
408,
1379,
626,
299,
7745,
13,
1447,
911,
5389,
503,
440,
5389,
7858,
402,
491,
28631,
1159,
2450,
4744,
624,
272,
340,
5253,
63,
396,
63,
1208,
14,
6049,
2540,
4965,
837,
489,
4546,
600,
275,
291,
14,
362,
4734,
600,
342,
489,
327,
1379,
593,
18,
12,
2955,
14,
593,
541,
1077,
1255,
1006,
14933,
315,
1373,
2621,
14,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
995,
881,
413,
9,
489,
327,
1379,
543,
7396,
7858,
1126,
986,
14,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
297,
2850,
80,
7745,
13,
1065,
13,
16027,
13,
6175,
13824,
995,
881,
650,
9,
489,
327,
14766,
543,
6202,
13,
452,
14,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
297,
2850,
1913,
13,
452,
995,
881,
413,
9,
489,
291,
14,
1074,
44,
1649,
541,
5667,
16291,
8,
881,
4546,
600,
12,
881,
11573,
47,
18,
297,
2475,
1986,
297,
2850,
1913,
13,
452,
297,
2850,
80,
7745,
13,
1065,
13,
16027,
13,
6175,
13824,
995,
881,
841,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1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
dstrockis/outlook-autocategories
|
lib/google/api/billing_pb2.py
|
17
|
4489
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/api/billing.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2
from google.api import metric_pb2 as google_dot_api_dot_metric__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='google/api/billing.proto',
package='google.api',
syntax='proto3',
serialized_pb=_b('\n\x18google/api/billing.proto\x12\ngoogle.api\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/metric.proto\"H\n\x07\x42illing\x12\x0f\n\x07metrics\x18\x01 \x03(\t\x12,\n\x05rules\x18\x05 \x03(\x0b\x32\x1d.google.api.BillingStatusRule\"?\n\x11\x42illingStatusRule\x12\x10\n\x08selector\x18\x01 \x01(\t\x12\x18\n\x10\x61llowed_statuses\x18\x02 \x03(\tB \n\x0e\x63om.google.apiB\x0c\x42illingProtoP\x01\x62\x06proto3')
,
dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_api_dot_metric__pb2.DESCRIPTOR,])
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
_BILLING = _descriptor.Descriptor(
name='Billing',
full_name='google.api.Billing',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='metrics', full_name='google.api.Billing.metrics', index=0,
number=1, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='rules', full_name='google.api.Billing.rules', index=1,
number=5, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=95,
serialized_end=167,
)
_BILLINGSTATUSRULE = _descriptor.Descriptor(
name='BillingStatusRule',
full_name='google.api.BillingStatusRule',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='selector', full_name='google.api.BillingStatusRule.selector', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='allowed_statuses', full_name='google.api.BillingStatusRule.allowed_statuses', index=1,
number=2, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=169,
serialized_end=232,
)
_BILLING.fields_by_name['rules'].message_type = _BILLINGSTATUSRULE
DESCRIPTOR.message_types_by_name['Billing'] = _BILLING
DESCRIPTOR.message_types_by_name['BillingStatusRule'] = _BILLINGSTATUSRULE
Billing = _reflection.GeneratedProtocolMessageType('Billing', (_message.Message,), dict(
DESCRIPTOR = _BILLING,
__module__ = 'google.api.billing_pb2'
# @@protoc_insertion_point(class_scope:google.api.Billing)
))
_sym_db.RegisterMessage(Billing)
BillingStatusRule = _reflection.GeneratedProtocolMessageType('BillingStatusRule', (_message.Message,), dict(
DESCRIPTOR = _BILLINGSTATUSRULE,
__module__ = 'google.api.billing_pb2'
# @@protoc_insertion_point(class_scope:google.api.BillingStatusRule)
))
_sym_db.RegisterMessage(BillingStatusRule)
DESCRIPTOR.has_options = True
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\016com.google.apiB\014BillingProtoP\001'))
# @@protoc_insertion_point(module_scope)
|
apache-2.0
|
[
3,
17065,
701,
314,
4113,
3335,
6365,
14,
221,
3506,
2845,
24981,
1,
199,
3,
1350,
26,
6233,
15,
1246,
15,
19929,
14,
2625,
199,
199,
646,
984,
199,
63,
66,
29,
1274,
14,
1023,
63,
815,
59,
16,
61,
28,
19,
436,
334,
2734,
671,
26,
88,
9,
503,
334,
2734,
671,
26,
88,
14,
2143,
360,
10378,
17,
1333,
199,
504,
6233,
14,
7204,
492,
5872,
465,
485,
4120,
199,
504,
6233,
14,
7204,
492,
1245,
465,
485,
1188,
199,
504,
6233,
14,
7204,
492,
25572,
465,
485,
14906,
199,
504,
6233,
14,
7204,
492,
5272,
63,
4659,
465,
485,
5155,
63,
4659,
199,
504,
6233,
14,
7204,
492,
5872,
63,
3317,
18,
199,
3,
13365,
16311,
63,
14739,
63,
1403,
8,
12775,
9,
199,
199,
63,
3840,
63,
697,
275,
485,
5155,
63,
4659,
14,
2698,
342,
421,
199,
504,
6233,
14,
1246,
492,
15538,
63,
3317,
18,
465,
6233,
63,
3287,
63,
1246,
63,
3287,
63,
11270,
363,
3317,
18,
199,
504,
6233,
14,
1246,
492,
6370,
63,
3317,
18,
465,
6233,
63,
3287,
63,
1246,
63,
3287,
63,
5165,
363,
3317,
18,
421,
199,
7580,
275,
485,
4120,
14,
23859,
8,
523,
536,
534,
3098,
15,
1246,
15,
19929,
14,
2625,
297,
523,
2559,
534,
3098,
14,
1246,
297,
523,
6302,
534,
2625,
19,
297,
523,
6380,
63,
3317,
3699,
66,
2258,
78,
60,
88,
1085,
3098,
15,
1246,
15,
19929,
14,
2625,
60,
88,
713,
60,
78,
3098,
14,
1246,
60,
88,
17,
65,
60,
88,
17,
67,
3098,
15,
1246,
15,
11270,
14,
2625,
60,
88,
17,
65,
60,
88,
1196,
3098,
15,
1246,
15,
5165,
14,
2625,
4451,
40,
60,
78,
60,
88,
1780,
60,
88,
2260,
12687,
60,
88,
713,
60,
88,
16,
70,
60,
78,
60,
88,
1780,
6759,
60,
88,
1085,
60,
88,
614,
971,
88,
1644,
2961,
84,
60,
88,
713,
4202,
78,
60,
88,
1717,
4423,
60,
88,
1085,
60,
88,
1717,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
17,
68,
14,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
4451,
8995,
78,
60,
88,
845,
60,
88,
2260,
12687,
3694,
5065,
60,
88,
713,
60,
88,
709,
60,
78,
60,
88,
2036,
6662,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
84,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
60,
88,
2976,
76,
674,
379,
63,
17084,
60,
88,
1085,
60,
88,
996,
971,
88,
1644,
2961,
84,
34,
971,
78,
60,
88,
16,
69,
60,
88,
2766,
676,
14,
3098,
14,
1246,
34,
60,
88,
16,
67,
60,
88,
2260,
12687,
8548,
48,
60,
88,
614,
60,
88,
2789,
60,
88,
1690,
2625,
19,
358,
523,
2360,
523,
5124,
1524,
3098,
63,
3287,
63,
1246,
63,
3287,
63,
11270,
363,
3317,
18,
14,
7580,
12,
3098,
63,
3287,
63,
1246,
63,
3287,
63,
5165,
363,
3317,
18,
14,
7580,
30453,
199,
63,
3840,
63,
697,
14,
7099,
23859,
8,
7580,
9,
6905,
199,
63,
34,
14961,
1206,
275,
485,
4120,
14,
4311,
8,
523,
536,
534,
34,
12687,
297,
523,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
297,
523,
1788,
29,
403,
12,
523,
570,
29,
7580,
12,
523,
3035,
63,
466,
29,
403,
12,
523,
1504,
1524,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
6759,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
14,
6759,
297,
1478,
29,
16,
12,
489,
1329,
29,
17,
12,
730,
29,
25,
12,
7246,
63,
466,
29,
25,
12,
1768,
29,
19,
12,
489,
965,
63,
885,
63,
585,
29,
797,
12,
849,
63,
585,
6034,
489,
1245,
63,
466,
29,
403,
12,
4952,
63,
466,
29,
403,
12,
3035,
63,
466,
29,
403,
12,
489,
365,
63,
3435,
29,
797,
12,
3329,
63,
2645,
29,
403,
12,
489,
1511,
29,
403,
395,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
4423,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
14,
4423,
297,
1478,
29,
17,
12,
489,
1329,
29,
21,
12,
730,
29,
845,
12,
7246,
63,
466,
29,
709,
12,
1768,
29,
19,
12,
489,
965,
63,
885,
63,
585,
29,
797,
12,
849,
63,
585,
6034,
489,
1245,
63,
466,
29,
403,
12,
4952,
63,
466,
29,
403,
12,
3035,
63,
466,
29,
403,
12,
489,
365,
63,
3435,
29,
797,
12,
3329,
63,
2645,
29,
403,
12,
489,
1511,
29,
403,
395,
523,
2156,
523,
5478,
1524,
523,
2156,
523,
6032,
63,
1313,
6034,
523,
4952,
63,
1313,
1524,
523,
2156,
523,
1511,
29,
403,
12,
523,
365,
63,
18363,
29,
797,
12,
523,
6302,
534,
2625,
19,
297,
523,
3329,
63,
8404,
6034,
523,
20753,
1524,
523,
2156,
523,
6380,
63,
928,
29,
2720,
12,
523,
6380,
63,
500,
29,
10806,
12,
199,
9,
421,
199,
63,
34,
14961,
1206,
6305,
13578,
275,
485,
4120,
14,
4311,
8,
523,
536,
534,
34,
12687,
3694,
5065,
297,
523,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
297,
523,
1788,
29,
403,
12,
523,
570,
29,
7580,
12,
523,
3035,
63,
466,
29,
403,
12,
523,
1504,
1524,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
6662,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
14,
6662,
297,
1478,
29,
16,
12,
489,
1329,
29,
17,
12,
730,
29,
25,
12,
7246,
63,
466,
29,
25,
12,
1768,
29,
17,
12,
489,
965,
63,
885,
63,
585,
29,
797,
12,
849,
63,
585,
3699,
66,
25639,
2708,
360,
1624,
13,
24,
659,
489,
1245,
63,
466,
29,
403,
12,
4952,
63,
466,
29,
403,
12,
3035,
63,
466,
29,
403,
12,
489,
365,
63,
3435,
29,
797,
12,
3329,
63,
2645,
29,
403,
12,
489,
1511,
29,
403,
395,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
6541,
63,
17084,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
14,
6541,
63,
17084,
297,
1478,
29,
17,
12,
489,
1329,
29,
18,
12,
730,
29,
25,
12,
7246,
63,
466,
29,
25,
12,
1768,
29,
19,
12,
489,
965,
63,
885
] |
[
17065,
701,
314,
4113,
3335,
6365,
14,
221,
3506,
2845,
24981,
1,
199,
3,
1350,
26,
6233,
15,
1246,
15,
19929,
14,
2625,
199,
199,
646,
984,
199,
63,
66,
29,
1274,
14,
1023,
63,
815,
59,
16,
61,
28,
19,
436,
334,
2734,
671,
26,
88,
9,
503,
334,
2734,
671,
26,
88,
14,
2143,
360,
10378,
17,
1333,
199,
504,
6233,
14,
7204,
492,
5872,
465,
485,
4120,
199,
504,
6233,
14,
7204,
492,
1245,
465,
485,
1188,
199,
504,
6233,
14,
7204,
492,
25572,
465,
485,
14906,
199,
504,
6233,
14,
7204,
492,
5272,
63,
4659,
465,
485,
5155,
63,
4659,
199,
504,
6233,
14,
7204,
492,
5872,
63,
3317,
18,
199,
3,
13365,
16311,
63,
14739,
63,
1403,
8,
12775,
9,
199,
199,
63,
3840,
63,
697,
275,
485,
5155,
63,
4659,
14,
2698,
342,
421,
199,
504,
6233,
14,
1246,
492,
15538,
63,
3317,
18,
465,
6233,
63,
3287,
63,
1246,
63,
3287,
63,
11270,
363,
3317,
18,
199,
504,
6233,
14,
1246,
492,
6370,
63,
3317,
18,
465,
6233,
63,
3287,
63,
1246,
63,
3287,
63,
5165,
363,
3317,
18,
421,
199,
7580,
275,
485,
4120,
14,
23859,
8,
523,
536,
534,
3098,
15,
1246,
15,
19929,
14,
2625,
297,
523,
2559,
534,
3098,
14,
1246,
297,
523,
6302,
534,
2625,
19,
297,
523,
6380,
63,
3317,
3699,
66,
2258,
78,
60,
88,
1085,
3098,
15,
1246,
15,
19929,
14,
2625,
60,
88,
713,
60,
78,
3098,
14,
1246,
60,
88,
17,
65,
60,
88,
17,
67,
3098,
15,
1246,
15,
11270,
14,
2625,
60,
88,
17,
65,
60,
88,
1196,
3098,
15,
1246,
15,
5165,
14,
2625,
4451,
40,
60,
78,
60,
88,
1780,
60,
88,
2260,
12687,
60,
88,
713,
60,
88,
16,
70,
60,
78,
60,
88,
1780,
6759,
60,
88,
1085,
60,
88,
614,
971,
88,
1644,
2961,
84,
60,
88,
713,
4202,
78,
60,
88,
1717,
4423,
60,
88,
1085,
60,
88,
1717,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
17,
68,
14,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
4451,
8995,
78,
60,
88,
845,
60,
88,
2260,
12687,
3694,
5065,
60,
88,
713,
60,
88,
709,
60,
78,
60,
88,
2036,
6662,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
84,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
60,
88,
2976,
76,
674,
379,
63,
17084,
60,
88,
1085,
60,
88,
996,
971,
88,
1644,
2961,
84,
34,
971,
78,
60,
88,
16,
69,
60,
88,
2766,
676,
14,
3098,
14,
1246,
34,
60,
88,
16,
67,
60,
88,
2260,
12687,
8548,
48,
60,
88,
614,
60,
88,
2789,
60,
88,
1690,
2625,
19,
358,
523,
2360,
523,
5124,
1524,
3098,
63,
3287,
63,
1246,
63,
3287,
63,
11270,
363,
3317,
18,
14,
7580,
12,
3098,
63,
3287,
63,
1246,
63,
3287,
63,
5165,
363,
3317,
18,
14,
7580,
30453,
199,
63,
3840,
63,
697,
14,
7099,
23859,
8,
7580,
9,
6905,
199,
63,
34,
14961,
1206,
275,
485,
4120,
14,
4311,
8,
523,
536,
534,
34,
12687,
297,
523,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
297,
523,
1788,
29,
403,
12,
523,
570,
29,
7580,
12,
523,
3035,
63,
466,
29,
403,
12,
523,
1504,
1524,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
6759,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
14,
6759,
297,
1478,
29,
16,
12,
489,
1329,
29,
17,
12,
730,
29,
25,
12,
7246,
63,
466,
29,
25,
12,
1768,
29,
19,
12,
489,
965,
63,
885,
63,
585,
29,
797,
12,
849,
63,
585,
6034,
489,
1245,
63,
466,
29,
403,
12,
4952,
63,
466,
29,
403,
12,
3035,
63,
466,
29,
403,
12,
489,
365,
63,
3435,
29,
797,
12,
3329,
63,
2645,
29,
403,
12,
489,
1511,
29,
403,
395,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
4423,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
14,
4423,
297,
1478,
29,
17,
12,
489,
1329,
29,
21,
12,
730,
29,
845,
12,
7246,
63,
466,
29,
709,
12,
1768,
29,
19,
12,
489,
965,
63,
885,
63,
585,
29,
797,
12,
849,
63,
585,
6034,
489,
1245,
63,
466,
29,
403,
12,
4952,
63,
466,
29,
403,
12,
3035,
63,
466,
29,
403,
12,
489,
365,
63,
3435,
29,
797,
12,
3329,
63,
2645,
29,
403,
12,
489,
1511,
29,
403,
395,
523,
2156,
523,
5478,
1524,
523,
2156,
523,
6032,
63,
1313,
6034,
523,
4952,
63,
1313,
1524,
523,
2156,
523,
1511,
29,
403,
12,
523,
365,
63,
18363,
29,
797,
12,
523,
6302,
534,
2625,
19,
297,
523,
3329,
63,
8404,
6034,
523,
20753,
1524,
523,
2156,
523,
6380,
63,
928,
29,
2720,
12,
523,
6380,
63,
500,
29,
10806,
12,
199,
9,
421,
199,
63,
34,
14961,
1206,
6305,
13578,
275,
485,
4120,
14,
4311,
8,
523,
536,
534,
34,
12687,
3694,
5065,
297,
523,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
297,
523,
1788,
29,
403,
12,
523,
570,
29,
7580,
12,
523,
3035,
63,
466,
29,
403,
12,
523,
1504,
1524,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
6662,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
14,
6662,
297,
1478,
29,
16,
12,
489,
1329,
29,
17,
12,
730,
29,
25,
12,
7246,
63,
466,
29,
25,
12,
1768,
29,
17,
12,
489,
965,
63,
885,
63,
585,
29,
797,
12,
849,
63,
585,
3699,
66,
25639,
2708,
360,
1624,
13,
24,
659,
489,
1245,
63,
466,
29,
403,
12,
4952,
63,
466,
29,
403,
12,
3035,
63,
466,
29,
403,
12,
489,
365,
63,
3435,
29,
797,
12,
3329,
63,
2645,
29,
403,
12,
489,
1511,
29,
403,
395,
272,
485,
4120,
14,
8510,
8,
489,
536,
534,
6541,
63,
17084,
297,
2615,
63,
354,
534,
3098,
14,
1246,
14,
34,
12687,
3694,
5065,
14,
6541,
63,
17084,
297,
1478,
29,
17,
12,
489,
1329,
29,
18,
12,
730,
29,
25,
12,
7246,
63,
466,
29,
25,
12,
1768,
29,
19,
12,
489,
965,
63,
885,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tensorflow/tensorflow
|
tensorflow/python/debug/wrappers/grpc_wrapper.py
|
25
|
8662
|
# 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.
# ==============================================================================
"""Debugger wrapper session that sends debug data to file:// URLs."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import signal
import sys
import traceback
import six
# Google-internal import(s).
from tensorflow.python.debug.lib import common
from tensorflow.python.debug.wrappers import framework
def publish_traceback(debug_server_urls,
graph,
feed_dict,
fetches,
old_graph_version):
"""Publish traceback and source code if graph version is new.
`graph.version` is compared with `old_graph_version`. If the former is higher
(i.e., newer), the graph traceback and the associated source code is sent to
the debug server at the specified gRPC URLs.
Args:
debug_server_urls: A single gRPC debug server URL as a `str` or a `list` of
debug server URLs.
graph: A Python `tf.Graph` object.
feed_dict: Feed dictionary given to the `Session.run()` call.
fetches: Fetches from the `Session.run()` call.
old_graph_version: Old graph version to compare to.
Returns:
If `graph.version > old_graph_version`, the new graph version as an `int`.
Else, the `old_graph_version` is returned.
"""
# TODO(cais): Consider moving this back to the top, after grpc becomes a
# pip dependency of tensorflow or tf_debug.
# pylint:disable=g-import-not-at-top
from tensorflow.python.debug.lib import source_remote
# pylint:enable=g-import-not-at-top
if graph.version > old_graph_version:
run_key = common.get_run_key(feed_dict, fetches)
source_remote.send_graph_tracebacks(
debug_server_urls, run_key, traceback.extract_stack(), graph,
send_source=True)
return graph.version
else:
return old_graph_version
class GrpcDebugWrapperSession(framework.NonInteractiveDebugWrapperSession):
"""Debug Session wrapper that send debug data to gRPC stream(s)."""
def __init__(self,
sess,
grpc_debug_server_addresses,
watch_fn=None,
thread_name_filter=None,
log_usage=True):
"""Constructor of DumpingDebugWrapperSession.
Args:
sess: The TensorFlow `Session` object being wrapped.
grpc_debug_server_addresses: (`str` or `list` of `str`) Single or a list
of the gRPC debug server addresses, in the format of
<host:port>, with or without the "grpc://" prefix. For example:
"localhost:7000",
["localhost:7000", "192.168.0.2:8000"]
watch_fn: (`Callable`) A Callable that can be used to define per-run
debug ops and watched tensors. See the doc of
`NonInteractiveDebugWrapperSession.__init__()` for details.
thread_name_filter: Regular-expression white list for threads on which the
wrapper session will be active. See doc of `BaseDebugWrapperSession` for
more details.
log_usage: (`bool`) whether the usage of this class is to be logged.
Raises:
TypeError: If `grpc_debug_server_addresses` is not a `str` or a `list`
of `str`.
"""
if log_usage:
pass # No logging for open-source.
framework.NonInteractiveDebugWrapperSession.__init__(
self, sess, watch_fn=watch_fn, thread_name_filter=thread_name_filter)
if isinstance(grpc_debug_server_addresses, str):
self._grpc_debug_server_urls = [
self._normalize_grpc_url(grpc_debug_server_addresses)]
elif isinstance(grpc_debug_server_addresses, list):
self._grpc_debug_server_urls = []
for address in grpc_debug_server_addresses:
if not isinstance(address, str):
raise TypeError(
"Expected type str in list grpc_debug_server_addresses, "
"received type %s" % type(address))
self._grpc_debug_server_urls.append(self._normalize_grpc_url(address))
else:
raise TypeError(
"Expected type str or list in grpc_debug_server_addresses, "
"received type %s" % type(grpc_debug_server_addresses))
def prepare_run_debug_urls(self, fetches, feed_dict):
"""Implementation of abstract method in superclass.
See doc of `NonInteractiveDebugWrapperSession.prepare_run_debug_urls()`
for details.
Args:
fetches: Same as the `fetches` argument to `Session.run()`
feed_dict: Same as the `feed_dict` argument to `Session.run()`
Returns:
debug_urls: (`str` or `list` of `str`) file:// debug URLs to be used in
this `Session.run()` call.
"""
return self._grpc_debug_server_urls
def _normalize_grpc_url(self, address):
return (common.GRPC_URL_PREFIX + address
if not address.startswith(common.GRPC_URL_PREFIX) else address)
def _signal_handler(unused_signal, unused_frame):
while True:
response = six.moves.input(
"\nSIGINT received. Quit program? (Y/n): ").strip()
if response in ("", "Y", "y"):
sys.exit(0)
elif response in ("N", "n"):
break
def register_signal_handler():
try:
signal.signal(signal.SIGINT, _signal_handler)
except ValueError:
# This can happen if we are not in the MainThread.
pass
class TensorBoardDebugWrapperSession(GrpcDebugWrapperSession):
"""A tfdbg Session wrapper that can be used with TensorBoard Debugger Plugin.
This wrapper is the same as `GrpcDebugWrapperSession`, except that it uses a
predefined `watch_fn` that
1) uses `DebugIdentity` debug ops with the `gated_grpc` attribute set to
`True` to allow the interactive enabling and disabling of tensor
breakpoints.
2) watches all tensors in the graph.
This saves the need for the user to define a `watch_fn`.
"""
def __init__(self,
sess,
grpc_debug_server_addresses,
thread_name_filter=None,
send_traceback_and_source_code=True,
log_usage=True):
"""Constructor of TensorBoardDebugWrapperSession.
Args:
sess: The `tf.compat.v1.Session` instance to be wrapped.
grpc_debug_server_addresses: gRPC address(es) of debug server(s), as a
`str` or a `list` of `str`s. E.g., "localhost:2333",
"grpc://localhost:2333", ["192.168.0.7:2333", "192.168.0.8:2333"].
thread_name_filter: Optional filter for thread names.
send_traceback_and_source_code: Whether traceback of graph elements and
the source code are to be sent to the debug server(s).
log_usage: Whether the usage of this class is to be logged (if
applicable).
"""
def _gated_grpc_watch_fn(fetches, feeds):
del fetches, feeds # Unused.
return framework.WatchOptions(
debug_ops=["DebugIdentity(gated_grpc=true)"])
super(TensorBoardDebugWrapperSession, self).__init__(
sess,
grpc_debug_server_addresses,
watch_fn=_gated_grpc_watch_fn,
thread_name_filter=thread_name_filter,
log_usage=log_usage)
self._send_traceback_and_source_code = send_traceback_and_source_code
# Keeps track of the latest version of Python graph object that has been
# sent to the debug servers.
self._sent_graph_version = -1
register_signal_handler()
def run(self,
fetches,
feed_dict=None,
options=None,
run_metadata=None,
callable_runner=None,
callable_runner_args=None,
callable_options=None):
if self._send_traceback_and_source_code:
self._sent_graph_version = publish_traceback(
self._grpc_debug_server_urls, self.graph, feed_dict, fetches,
self._sent_graph_version)
return super(TensorBoardDebugWrapperSession, self).run(
fetches,
feed_dict=feed_dict,
options=options,
run_metadata=run_metadata,
callable_runner=callable_runner,
callable_runner_args=callable_runner_args,
callable_options=callable_options)
|
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,
31521,
4975,
2351,
626,
16178,
3105,
666,
370,
570,
921,
10867,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
4673,
199,
646,
984,
199,
646,
5190,
199,
199,
646,
3816,
199,
199,
3,
4475,
13,
4672,
492,
8,
83,
680,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
2863,
199,
504,
3228,
14,
1548,
14,
1757,
14,
21148,
492,
10059,
421,
199,
318,
2780,
63,
6894,
8,
1757,
63,
1000,
63,
3603,
12,
1993,
3343,
12,
1993,
4733,
63,
807,
12,
1993,
28053,
12,
1993,
2269,
63,
2180,
63,
1023,
304,
523,
408,
13956,
5190,
436,
1350,
1233,
340,
3343,
1015,
365,
892,
14,
819,
658,
2180,
14,
1023,
64,
365,
13524,
543,
658,
1753,
63,
2180,
63,
1023,
2313,
982,
314,
26610,
365,
10948,
523,
334,
73,
14,
69,
2020,
15666,
395,
314,
3343,
5190,
436,
314,
4568,
1350,
1233,
365,
4847,
370,
523,
314,
3105,
1654,
737,
314,
2013,
30700,
10867,
14,
819,
3033,
26,
272,
3105,
63,
1000,
63,
3603,
26,
437,
2849,
30700,
3105,
1654,
2851,
465,
282,
658,
495,
64,
503,
282,
658,
513,
64,
402,
489,
3105,
1654,
10867,
14,
272,
3343,
26,
437,
2018,
658,
3249,
14,
4578,
64,
909,
14,
272,
4733,
63,
807,
26,
16261,
2600,
1627,
370,
314,
658,
4434,
14,
1065,
11995,
1240,
14,
272,
28053,
26,
16347,
397,
687,
314,
658,
4434,
14,
1065,
11995,
1240,
14,
272,
2269,
63,
2180,
63,
1023,
26,
21238,
3343,
1015,
370,
6540,
370,
14,
819,
1803,
26,
272,
982,
658,
2180,
14,
1023,
690,
2269,
63,
2180,
63,
1023,
3559,
314,
892,
3343,
1015,
465,
376,
658,
442,
2313,
272,
19524,
12,
314,
658,
1753,
63,
2180,
63,
1023,
64,
365,
2138,
14,
523,
408,
523,
327,
3254,
8,
696,
374,
304,
24413,
12876,
642,
1771,
370,
314,
2746,
12,
2410,
19753,
15410,
282,
523,
327,
7305,
5936,
402,
3228,
503,
2833,
63,
1757,
14,
523,
327,
4287,
26,
5993,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
523,
687,
3228,
14,
1548,
14,
1757,
14,
773,
492,
1350,
63,
3846,
523,
327,
4287,
26,
4296,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
523,
340,
3343,
14,
1023,
690,
2269,
63,
2180,
63,
1023,
26,
272,
1255,
63,
498,
275,
2863,
14,
362,
63,
1065,
63,
498,
8,
3871,
63,
807,
12,
28053,
9,
272,
1350,
63,
3846,
14,
2254,
63,
2180,
63,
6894,
83,
8,
267,
3105,
63,
1000,
63,
3603,
12,
1255,
63,
498,
12,
5190,
14,
5005,
63,
2340,
1062,
3343,
12,
267,
3222,
63,
1365,
29,
549,
9,
272,
372,
3343,
14,
1023,
523,
587,
26,
272,
372,
2269,
63,
2180,
63,
1023,
421,
199,
533,
598,
4354,
7084,
4590,
4434,
8,
4857,
14,
6932,
23879,
7084,
4590,
4434,
304,
523,
408,
7084,
8596,
4975,
626,
3222,
3105,
666,
370,
30700,
2547,
8,
83,
10477,
819,
347,
636,
826,
721,
277,
12,
2049,
4043,
12,
2049,
19753,
63,
1757,
63,
1000,
63,
7423,
12,
2049,
9626,
63,
2324,
29,
403,
12,
2049,
2462,
63,
354,
63,
1541,
29,
403,
12,
2049,
943,
63,
3807,
29,
549,
304,
272,
408,
11447,
402,
19460,
316,
7084,
4590,
4434,
14,
339,
3033,
26,
489,
4043,
26,
710,
9134,
658,
4434,
64,
909,
3769,
8072,
14,
489,
19753,
63,
1757,
63,
1000,
63,
7423,
26,
13493,
495,
64,
503,
658,
513,
64,
402,
658,
495,
10522,
13050,
503,
282,
769,
267,
402,
314,
30700,
3105,
1654,
7149,
12,
315,
314,
1475,
402,
267,
665,
1102,
26,
719,
6244,
543,
503,
1928,
314,
298,
15391,
30443,
2403,
14,
2104,
2893,
26,
881,
298,
5967,
26,
23,
1493,
401,
881,
2097,
5967,
26,
23,
1493,
401,
298,
5756,
14,
6568,
14,
16,
14,
18,
26,
15214,
937,
489,
9626,
63,
2324,
26,
13493,
16410,
10522,
437,
16975,
626,
883,
506,
1202,
370,
5627,
1126,
13,
1065,
267,
3105,
4156,
436,
9626,
379,
10519,
14,
1666,
314,
1382,
402,
267,
658,
6932,
23879,
7084,
4590,
4434,
855,
826,
4533,
64,
367,
2436,
14,
489,
2462,
63,
354,
63,
1541,
26,
18528,
13,
5599,
10424,
769,
367,
7183,
641,
1314,
314,
267,
4975,
2351,
911,
506,
4702,
14,
1666,
1382,
402,
658,
1563,
7084,
4590,
4434,
64,
367,
267,
1655,
2436,
14,
489,
943,
63,
3807,
26,
13493,
2245,
10522,
3775,
314,
4503,
402,
642,
1021,
365,
370,
506,
10367,
14,
339,
6218,
26,
2126,
3146,
26,
982,
658,
15391,
63,
1757,
63,
1000,
63,
7423,
64,
365,
440,
282,
658,
495,
64,
503,
282,
658,
513,
64,
268,
402,
658,
495,
2313,
272,
408,
339,
340,
943,
63,
3807,
26,
489,
986,
221,
327,
3091,
2050,
367,
1551,
13,
1365,
14,
339,
10059,
14,
6932,
23879,
7084,
4590,
4434,
855,
826,
721,
267,
291,
12,
4043,
12,
9626,
63,
2324,
29,
6821,
63,
2324,
12,
2462,
63,
354,
63,
1541,
29,
2671,
63,
354,
63,
1541,
9,
339,
340,
1228,
8,
15391,
63,
1757,
63,
1000,
63,
7423,
12,
620,
304,
489,
291,
423,
15391,
63,
1757,
63,
1000,
63,
3603,
275,
359,
881,
291,
423,
7721,
63,
15391,
63,
633,
8,
15391,
63,
1757,
63,
1000,
63,
7423,
1874,
272,
916,
1228
] |
[
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,
31521,
4975,
2351,
626,
16178,
3105,
666,
370,
570,
921,
10867,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
4673,
199,
646,
984,
199,
646,
5190,
199,
199,
646,
3816,
199,
199,
3,
4475,
13,
4672,
492,
8,
83,
680,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
2863,
199,
504,
3228,
14,
1548,
14,
1757,
14,
21148,
492,
10059,
421,
199,
318,
2780,
63,
6894,
8,
1757,
63,
1000,
63,
3603,
12,
1993,
3343,
12,
1993,
4733,
63,
807,
12,
1993,
28053,
12,
1993,
2269,
63,
2180,
63,
1023,
304,
523,
408,
13956,
5190,
436,
1350,
1233,
340,
3343,
1015,
365,
892,
14,
819,
658,
2180,
14,
1023,
64,
365,
13524,
543,
658,
1753,
63,
2180,
63,
1023,
2313,
982,
314,
26610,
365,
10948,
523,
334,
73,
14,
69,
2020,
15666,
395,
314,
3343,
5190,
436,
314,
4568,
1350,
1233,
365,
4847,
370,
523,
314,
3105,
1654,
737,
314,
2013,
30700,
10867,
14,
819,
3033,
26,
272,
3105,
63,
1000,
63,
3603,
26,
437,
2849,
30700,
3105,
1654,
2851,
465,
282,
658,
495,
64,
503,
282,
658,
513,
64,
402,
489,
3105,
1654,
10867,
14,
272,
3343,
26,
437,
2018,
658,
3249,
14,
4578,
64,
909,
14,
272,
4733,
63,
807,
26,
16261,
2600,
1627,
370,
314,
658,
4434,
14,
1065,
11995,
1240,
14,
272,
28053,
26,
16347,
397,
687,
314,
658,
4434,
14,
1065,
11995,
1240,
14,
272,
2269,
63,
2180,
63,
1023,
26,
21238,
3343,
1015,
370,
6540,
370,
14,
819,
1803,
26,
272,
982,
658,
2180,
14,
1023,
690,
2269,
63,
2180,
63,
1023,
3559,
314,
892,
3343,
1015,
465,
376,
658,
442,
2313,
272,
19524,
12,
314,
658,
1753,
63,
2180,
63,
1023,
64,
365,
2138,
14,
523,
408,
523,
327,
3254,
8,
696,
374,
304,
24413,
12876,
642,
1771,
370,
314,
2746,
12,
2410,
19753,
15410,
282,
523,
327,
7305,
5936,
402,
3228,
503,
2833,
63,
1757,
14,
523,
327,
4287,
26,
5993,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
523,
687,
3228,
14,
1548,
14,
1757,
14,
773,
492,
1350,
63,
3846,
523,
327,
4287,
26,
4296,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
523,
340,
3343,
14,
1023,
690,
2269,
63,
2180,
63,
1023,
26,
272,
1255,
63,
498,
275,
2863,
14,
362,
63,
1065,
63,
498,
8,
3871,
63,
807,
12,
28053,
9,
272,
1350,
63,
3846,
14,
2254,
63,
2180,
63,
6894,
83,
8,
267,
3105,
63,
1000,
63,
3603,
12,
1255,
63,
498,
12,
5190,
14,
5005,
63,
2340,
1062,
3343,
12,
267,
3222,
63,
1365,
29,
549,
9,
272,
372,
3343,
14,
1023,
523,
587,
26,
272,
372,
2269,
63,
2180,
63,
1023,
421,
199,
533,
598,
4354,
7084,
4590,
4434,
8,
4857,
14,
6932,
23879,
7084,
4590,
4434,
304,
523,
408,
7084,
8596,
4975,
626,
3222,
3105,
666,
370,
30700,
2547,
8,
83,
10477,
819,
347,
636,
826,
721,
277,
12,
2049,
4043,
12,
2049,
19753,
63,
1757,
63,
1000,
63,
7423,
12,
2049,
9626,
63,
2324,
29,
403,
12,
2049,
2462,
63,
354,
63,
1541,
29,
403,
12,
2049,
943,
63,
3807,
29,
549,
304,
272,
408,
11447,
402,
19460,
316,
7084,
4590,
4434,
14,
339,
3033,
26,
489,
4043,
26,
710,
9134,
658,
4434,
64,
909,
3769,
8072,
14,
489,
19753,
63,
1757,
63,
1000,
63,
7423,
26,
13493,
495,
64,
503,
658,
513,
64,
402,
658,
495,
10522,
13050,
503,
282,
769,
267,
402,
314,
30700,
3105,
1654,
7149,
12,
315,
314,
1475,
402,
267,
665,
1102,
26,
719,
6244,
543,
503,
1928,
314,
298,
15391,
30443,
2403,
14,
2104,
2893,
26,
881,
298,
5967,
26,
23,
1493,
401,
881,
2097,
5967,
26,
23,
1493,
401,
298,
5756,
14,
6568,
14,
16,
14,
18,
26,
15214,
937,
489,
9626,
63,
2324,
26,
13493,
16410,
10522,
437,
16975,
626,
883,
506,
1202,
370,
5627,
1126,
13,
1065,
267,
3105,
4156,
436,
9626,
379,
10519,
14,
1666,
314,
1382,
402,
267,
658,
6932,
23879,
7084,
4590,
4434,
855,
826,
4533,
64,
367,
2436,
14,
489,
2462,
63,
354,
63,
1541,
26,
18528,
13,
5599,
10424,
769,
367,
7183,
641,
1314,
314,
267,
4975,
2351,
911,
506,
4702,
14,
1666,
1382,
402,
658,
1563,
7084,
4590,
4434,
64,
367,
267,
1655,
2436,
14,
489,
943,
63,
3807,
26,
13493,
2245,
10522,
3775,
314,
4503,
402,
642,
1021,
365,
370,
506,
10367,
14,
339,
6218,
26,
2126,
3146,
26,
982,
658,
15391,
63,
1757,
63,
1000,
63,
7423,
64,
365,
440,
282,
658,
495,
64,
503,
282,
658,
513,
64,
268,
402,
658,
495,
2313,
272,
408,
339,
340,
943,
63,
3807,
26,
489,
986,
221,
327,
3091,
2050,
367,
1551,
13,
1365,
14,
339,
10059,
14,
6932,
23879,
7084,
4590,
4434,
855,
826,
721,
267,
291,
12,
4043,
12,
9626,
63,
2324,
29,
6821,
63,
2324,
12,
2462,
63,
354,
63,
1541,
29,
2671,
63,
354,
63,
1541,
9,
339,
340,
1228,
8,
15391,
63,
1757,
63,
1000,
63,
7423,
12,
620,
304,
489,
291,
423,
15391,
63,
1757,
63,
1000,
63,
3603,
275,
359,
881,
291,
423,
7721,
63,
15391,
63,
633,
8,
15391,
63,
1757,
63,
1000,
63,
7423,
1874,
272,
916,
1228,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sgerhart/ansible
|
lib/ansible/plugins/cliconf/iosxr.py
|
21
|
9274
|
#
# (c) 2017 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
import json
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_text
from ansible.module_utils.common._collections_compat import Mapping
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.config import NetworkConfig, dumps
from ansible.module_utils.network.common.utils import to_list
from ansible.module_utils.network.iosxr.iosxr import sanitize_config, mask_config_blocks_from_diff
from ansible.plugins.cliconf import CliconfBase
class Cliconf(CliconfBase):
def get_device_info(self):
device_info = {}
device_info['network_os'] = 'iosxr'
reply = self.get('show version | utility head -n 20')
data = to_text(reply, errors='surrogate_or_strict').strip()
match = re.search(r'Version (\S+)$', data, re.M)
if match:
device_info['network_os_version'] = match.group(1)
match = re.search(r'image file is "(.+)"', data)
if match:
device_info['network_os_image'] = match.group(1)
match = re.search(r'^Cisco (.+) \(revision', data, re.M)
if match:
device_info['network_os_model'] = match.group(1)
match = re.search(r'^(.+) uptime', data, re.M)
if match:
device_info['network_os_hostname'] = match.group(1)
return device_info
def configure(self, admin=False):
prompt = to_text(self._connection.get_prompt(), errors='surrogate_or_strict').strip()
if not prompt.endswith(')#'):
if admin and 'admin-' not in prompt:
self.send_command('admin')
self.send_command('configure terminal')
def abort(self, admin=False):
prompt = to_text(self._connection.get_prompt(), errors='surrogate_or_strict').strip()
if prompt.endswith(')#'):
self.send_command('abort')
if admin and 'admin-' in prompt:
self.send_command('exit')
def get_config(self, source='running', format='text', flags=None):
if source not in ['running']:
raise ValueError("fetching configuration from %s is not supported" % source)
lookup = {'running': 'running-config'}
cmd = 'show {0} '.format(lookup[source])
cmd += ' '.join(to_list(flags))
cmd = cmd.strip()
return self.send_command(cmd)
def edit_config(self, candidate=None, commit=True, admin=False, replace=None, comment=None, label=None):
operations = self.get_device_operations()
self.check_edit_config_capability(operations, candidate, commit, replace, comment)
resp = {}
results = []
requests = []
self.configure(admin=admin)
if replace:
candidate = 'load {0}'.format(replace)
for line in to_list(candidate):
if not isinstance(line, Mapping):
line = {'command': line}
cmd = line['command']
results.append(self.send_command(**line))
requests.append(cmd)
if commit:
self.commit(comment=comment, label=label, replace=replace)
else:
self.discard_changes()
self.abort(admin=admin)
resp['request'] = requests
resp['response'] = results
return resp
def get_diff(self, candidate=None, running=None, diff_match='line', diff_ignore_lines=None, path=None, diff_replace='line'):
diff = {}
device_operations = self.get_device_operations()
option_values = self.get_option_values()
if candidate is None and device_operations['supports_generate_diff']:
raise ValueError("candidate configuration is required to generate diff")
if diff_match not in option_values['diff_match']:
raise ValueError("'match' value %s in invalid, valid values are %s" % (diff_match, ', '.join(option_values['diff_match'])))
if diff_replace not in option_values['diff_replace']:
raise ValueError("'replace' value %s in invalid, valid values are %s" % (diff_replace, ', '.join(option_values['diff_replace'])))
# prepare candidate configuration
sanitized_candidate = sanitize_config(candidate)
candidate_obj = NetworkConfig(indent=1)
candidate_obj.load(sanitized_candidate)
if running and diff_match != 'none':
# running configuration
running = mask_config_blocks_from_diff(running, candidate, "ansible")
running = sanitize_config(running)
running_obj = NetworkConfig(indent=1, contents=running, ignore_lines=diff_ignore_lines)
configdiffobjs = candidate_obj.difference(running_obj, path=path, match=diff_match, replace=diff_replace)
else:
configdiffobjs = candidate_obj.items
diff['config_diff'] = dumps(configdiffobjs, 'commands') if configdiffobjs else ''
return diff
def get(self, command=None, prompt=None, answer=None, sendonly=False, newline=True, output=None, check_all=False):
if output:
raise ValueError("'output' value %s is not supported for get" % output)
return self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline, check_all=check_all)
def commit(self, comment=None, label=None, replace=None):
cmd_obj = {}
if replace:
cmd_obj['command'] = 'commit replace'
cmd_obj['prompt'] = 'This commit will replace or remove the entire running configuration'
cmd_obj['answer'] = 'yes'
else:
if comment and label:
cmd_obj['command'] = 'commit label {0} comment {1}'.format(label, comment)
elif comment:
cmd_obj['command'] = 'commit comment {0}'.format(comment)
elif label:
cmd_obj['command'] = 'commit label {0}'.format(label)
else:
cmd_obj['command'] = 'commit'
self.send_command(**cmd_obj)
def run_commands(self, commands=None, check_rc=True):
if commands is None:
raise ValueError("'commands' value is required")
responses = list()
for cmd in to_list(commands):
if not isinstance(cmd, Mapping):
cmd = {'command': cmd}
output = cmd.pop('output', None)
if output:
raise ValueError("'output' value %s is not supported for run_commands" % output)
try:
out = self.send_command(**cmd)
except AnsibleConnectionFailure as e:
if check_rc:
raise
out = getattr(e, 'err', e)
if out is not None:
try:
out = to_text(out, errors='surrogate_or_strict').strip()
except UnicodeError:
raise ConnectionError(message=u'Failed to decode output from %s: %s' % (cmd, to_text(out)))
try:
out = json.loads(out)
except ValueError:
pass
responses.append(out)
return responses
def discard_changes(self):
self.send_command('abort')
def get_device_operations(self):
return {
'supports_diff_replace': True,
'supports_commit': True,
'supports_rollback': False,
'supports_defaults': False,
'supports_onbox_diff': False,
'supports_commit_comment': True,
'supports_multiline_delimiter': False,
'supports_diff_match': True,
'supports_diff_ignore_lines': True,
'supports_generate_diff': True,
'supports_replace': True,
'supports_admin': True,
'supports_commit_label': True
}
def get_option_values(self):
return {
'format': ['text'],
'diff_match': ['line', 'strict', 'exact', 'none'],
'diff_replace': ['line', 'block', 'config'],
'output': []
}
def get_capabilities(self):
result = {}
result['rpc'] = self.get_base_rpc() + ['commit', 'discard_changes', 'get_diff', 'configure', 'exit']
result['network_api'] = 'cliconf'
result['device_info'] = self.get_device_info()
result['device_operations'] = self.get_device_operations()
result.update(self.get_option_values())
return json.dumps(result)
|
mit
|
[
3,
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
3242,
14,
2550,
492,
2622,
3225,
6782,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
423,
7882,
63,
5819,
492,
12340,
199,
504,
3242,
14,
578,
63,
1208,
14,
2105,
492,
25417,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
888,
492,
7220,
2028,
12,
16864,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
1208,
492,
370,
63,
513,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
9207,
15775,
14,
9207,
15775,
492,
21077,
63,
888,
12,
3656,
63,
888,
63,
4166,
63,
504,
63,
3028,
199,
504,
3242,
14,
5265,
14,
2764,
2190,
492,
445,
317,
2190,
1563,
421,
199,
533,
445,
317,
2190,
8,
20653,
2190,
1563,
304,
339,
347,
664,
63,
1782,
63,
815,
8,
277,
304,
267,
2243,
63,
815,
275,
1052,
398,
2243,
63,
815,
459,
1200,
63,
736,
418,
275,
283,
9207,
15775,
7,
267,
9351,
275,
291,
14,
362,
360,
2384,
1015,
1204,
11420,
4854,
446,
78,
3388,
358,
267,
666,
275,
370,
63,
505,
8,
8102,
12,
2552,
534,
16380,
63,
269,
63,
4768,
1959,
1913,
342,
398,
1336,
275,
295,
14,
1733,
8,
82,
7,
3353,
14749,
51,
8771,
4268,
666,
12,
295,
14,
45,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
1023,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
1336,
275,
295,
14,
1733,
8,
82,
7,
1569,
570,
365,
7340,
6977,
32691,
666,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
1569,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
1336,
275,
295,
14,
1733,
8,
82,
4289,
17540,
334,
6977,
9,
25445,
5792,
297,
666,
12,
295,
14,
45,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
1238,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
1336,
275,
295,
14,
1733,
8,
82,
31996,
6977,
9,
1536,
521,
297,
666,
12,
295,
14,
45,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
4269,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
372,
2243,
63,
815,
339,
347,
7908,
8,
277,
12,
4628,
29,
797,
304,
267,
8457,
275,
370,
63,
505,
8,
277,
423,
2105,
14,
362,
63,
7650,
1062,
2552,
534,
16380,
63,
269,
63,
4768,
1959,
1913,
342,
267,
340,
440,
8457,
14,
4130,
15938,
3,
735,
288,
340,
4628,
436,
283,
2113,
15668,
440,
315,
8457,
26,
355,
291,
14,
2254,
63,
1531,
360,
2113,
358,
288,
291,
14,
2254,
63,
1531,
360,
6472,
11167,
358,
339,
347,
12004,
8,
277,
12,
4628,
29,
797,
304,
267,
8457,
275,
370,
63,
505,
8,
277,
423,
2105,
14,
362,
63,
7650,
1062,
2552,
534,
16380,
63,
269,
63,
4768,
1959,
1913,
342,
267,
340,
8457,
14,
4130,
15938,
3,
735,
288,
291,
14,
2254,
63,
1531,
360,
13845,
358,
288,
340,
4628,
436,
283,
2113,
15668,
315,
8457,
26,
355,
291,
14,
2254,
63,
1531,
360,
2224,
358,
339,
347,
664,
63,
888,
8,
277,
12,
1350,
534,
5720,
297,
1475,
534,
505,
297,
3285,
29,
403,
304,
267,
340,
1350,
440,
315,
788,
5720,
2565,
288,
746,
1722,
480,
3535,
316,
2897,
687,
450,
83,
365,
440,
3748,
2,
450,
1350,
9,
398,
4237,
275,
791,
5720,
356,
283,
5720,
13,
888,
936,
398,
2088,
275,
283,
2384,
469,
16,
93,
1987,
908,
8,
3892,
59,
1365,
566,
267,
2088,
847,
283,
1987,
904,
8,
475,
63,
513,
8,
2469,
430,
267,
2088,
275,
2088,
14,
1913,
342,
398,
372,
291,
14,
2254,
63,
1531,
8,
1760,
9,
339,
347,
5283,
63,
888,
8,
277,
12,
7627,
29,
403,
12,
5532,
29,
549,
12,
4628,
29,
797,
12,
3350,
29,
403,
12,
3721,
29,
403,
12,
1768,
29,
403,
304,
267,
5331,
275,
291,
14,
362,
63,
1782,
63,
8170,
342,
267,
291,
14,
1074,
63,
3773,
63,
888,
63,
21181,
8,
8170,
12,
7627,
12,
5532,
12,
3350,
12,
3721,
9,
398,
3085,
275,
1052,
267,
2058,
275,
942,
267,
4145,
275,
942,
398,
291,
14,
6472,
8,
2113,
29,
2113,
9,
398,
340,
3350,
26,
288,
7627,
275,
283,
912,
469,
16,
5285,
908,
8,
1814,
9,
398,
367,
1004,
315,
370,
63,
513,
8,
9007,
304,
288,
340,
440,
1228,
8,
604,
12,
12340,
304,
355,
1004,
275,
791,
1531,
356,
1004,
93,
288,
2088,
275,
1004,
459,
1531,
418,
288,
2058,
14,
740,
8,
277,
14,
2254,
63,
1531,
3682,
604,
430,
288,
4145,
14,
740,
8,
1760,
9,
398,
340,
5532,
26,
288,
291,
14,
3543,
8,
3349,
29,
3349,
12,
1768,
29,
1302,
12,
3350,
29,
1814,
9,
267,
587,
26,
288,
291,
14,
14394,
63,
6627,
342,
398,
291,
14,
13845,
8,
2113,
29,
2113,
9,
398,
3085,
459,
1069,
418,
275,
4145,
267
] |
[
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
3242,
14,
2550,
492,
2622,
3225,
6782,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
423,
7882,
63,
5819,
492,
12340,
199,
504,
3242,
14,
578,
63,
1208,
14,
2105,
492,
25417,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
888,
492,
7220,
2028,
12,
16864,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
1208,
492,
370,
63,
513,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
9207,
15775,
14,
9207,
15775,
492,
21077,
63,
888,
12,
3656,
63,
888,
63,
4166,
63,
504,
63,
3028,
199,
504,
3242,
14,
5265,
14,
2764,
2190,
492,
445,
317,
2190,
1563,
421,
199,
533,
445,
317,
2190,
8,
20653,
2190,
1563,
304,
339,
347,
664,
63,
1782,
63,
815,
8,
277,
304,
267,
2243,
63,
815,
275,
1052,
398,
2243,
63,
815,
459,
1200,
63,
736,
418,
275,
283,
9207,
15775,
7,
267,
9351,
275,
291,
14,
362,
360,
2384,
1015,
1204,
11420,
4854,
446,
78,
3388,
358,
267,
666,
275,
370,
63,
505,
8,
8102,
12,
2552,
534,
16380,
63,
269,
63,
4768,
1959,
1913,
342,
398,
1336,
275,
295,
14,
1733,
8,
82,
7,
3353,
14749,
51,
8771,
4268,
666,
12,
295,
14,
45,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
1023,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
1336,
275,
295,
14,
1733,
8,
82,
7,
1569,
570,
365,
7340,
6977,
32691,
666,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
1569,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
1336,
275,
295,
14,
1733,
8,
82,
4289,
17540,
334,
6977,
9,
25445,
5792,
297,
666,
12,
295,
14,
45,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
1238,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
1336,
275,
295,
14,
1733,
8,
82,
31996,
6977,
9,
1536,
521,
297,
666,
12,
295,
14,
45,
9,
267,
340,
1336,
26,
288,
2243,
63,
815,
459,
1200,
63,
736,
63,
4269,
418,
275,
1336,
14,
923,
8,
17,
9,
398,
372,
2243,
63,
815,
339,
347,
7908,
8,
277,
12,
4628,
29,
797,
304,
267,
8457,
275,
370,
63,
505,
8,
277,
423,
2105,
14,
362,
63,
7650,
1062,
2552,
534,
16380,
63,
269,
63,
4768,
1959,
1913,
342,
267,
340,
440,
8457,
14,
4130,
15938,
3,
735,
288,
340,
4628,
436,
283,
2113,
15668,
440,
315,
8457,
26,
355,
291,
14,
2254,
63,
1531,
360,
2113,
358,
288,
291,
14,
2254,
63,
1531,
360,
6472,
11167,
358,
339,
347,
12004,
8,
277,
12,
4628,
29,
797,
304,
267,
8457,
275,
370,
63,
505,
8,
277,
423,
2105,
14,
362,
63,
7650,
1062,
2552,
534,
16380,
63,
269,
63,
4768,
1959,
1913,
342,
267,
340,
8457,
14,
4130,
15938,
3,
735,
288,
291,
14,
2254,
63,
1531,
360,
13845,
358,
288,
340,
4628,
436,
283,
2113,
15668,
315,
8457,
26,
355,
291,
14,
2254,
63,
1531,
360,
2224,
358,
339,
347,
664,
63,
888,
8,
277,
12,
1350,
534,
5720,
297,
1475,
534,
505,
297,
3285,
29,
403,
304,
267,
340,
1350,
440,
315,
788,
5720,
2565,
288,
746,
1722,
480,
3535,
316,
2897,
687,
450,
83,
365,
440,
3748,
2,
450,
1350,
9,
398,
4237,
275,
791,
5720,
356,
283,
5720,
13,
888,
936,
398,
2088,
275,
283,
2384,
469,
16,
93,
1987,
908,
8,
3892,
59,
1365,
566,
267,
2088,
847,
283,
1987,
904,
8,
475,
63,
513,
8,
2469,
430,
267,
2088,
275,
2088,
14,
1913,
342,
398,
372,
291,
14,
2254,
63,
1531,
8,
1760,
9,
339,
347,
5283,
63,
888,
8,
277,
12,
7627,
29,
403,
12,
5532,
29,
549,
12,
4628,
29,
797,
12,
3350,
29,
403,
12,
3721,
29,
403,
12,
1768,
29,
403,
304,
267,
5331,
275,
291,
14,
362,
63,
1782,
63,
8170,
342,
267,
291,
14,
1074,
63,
3773,
63,
888,
63,
21181,
8,
8170,
12,
7627,
12,
5532,
12,
3350,
12,
3721,
9,
398,
3085,
275,
1052,
267,
2058,
275,
942,
267,
4145,
275,
942,
398,
291,
14,
6472,
8,
2113,
29,
2113,
9,
398,
340,
3350,
26,
288,
7627,
275,
283,
912,
469,
16,
5285,
908,
8,
1814,
9,
398,
367,
1004,
315,
370,
63,
513,
8,
9007,
304,
288,
340,
440,
1228,
8,
604,
12,
12340,
304,
355,
1004,
275,
791,
1531,
356,
1004,
93,
288,
2088,
275,
1004,
459,
1531,
418,
288,
2058,
14,
740,
8,
277,
14,
2254,
63,
1531,
3682,
604,
430,
288,
4145,
14,
740,
8,
1760,
9,
398,
340,
5532,
26,
288,
291,
14,
3543,
8,
3349,
29,
3349,
12,
1768,
29,
1302,
12,
3350,
29,
1814,
9,
267,
587,
26,
288,
291,
14,
14394,
63,
6627,
342,
398,
291,
14,
13845,
8,
2113,
29,
2113,
9,
398,
3085,
459,
1069,
418,
275,
4145,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
naresh21/synergetics-edx-platform
|
common/test/acceptance/tests/lms/test_lms_user_preview.py
|
7
|
17053
|
# -*- coding: utf-8 -*-
"""
Tests the "preview" selector in the LMS that allows changing between Staff, Student, and Content Groups.
"""
from nose.plugins.attrib import attr
from common.test.acceptance.tests.helpers import UniqueCourseTest, create_user_partition_json
from common.test.acceptance.pages.studio.auto_auth import AutoAuthPage
from common.test.acceptance.pages.lms.courseware import CoursewarePage
from common.test.acceptance.pages.lms.instructor_dashboard import InstructorDashboardPage
from common.test.acceptance.pages.lms.staff_view import StaffPage
from common.test.acceptance.fixtures.course import CourseFixture, XBlockFixtureDesc
from bok_choy.promise import EmptyPromise
from xmodule.partitions.partitions import Group
from textwrap import dedent
@attr(shard=10)
class StaffViewTest(UniqueCourseTest):
"""
Tests that verify the staff view.
"""
USERNAME = "STAFF_TESTER"
EMAIL = "johndoe@example.com"
def setUp(self):
super(StaffViewTest, self).setUp()
self.courseware_page = CoursewarePage(self.browser, self.course_id)
# Install a course with sections/problems, tabs, updates, and handouts
self.course_fixture = CourseFixture(
self.course_info['org'], self.course_info['number'],
self.course_info['run'], self.course_info['display_name']
)
self.populate_course_fixture(self.course_fixture) # pylint: disable=no-member
self.course_fixture.install()
# Auto-auth register for the course.
# Do this as global staff so that you will see the Staff View
AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL,
course_id=self.course_id, staff=True).visit()
def _goto_staff_page(self):
"""
Open staff page with assertion
"""
self.courseware_page.visit()
staff_page = StaffPage(self.browser, self.course_id)
self.assertEqual(staff_page.staff_view_mode, 'Staff')
return staff_page
@attr(shard=10)
class CourseWithoutContentGroupsTest(StaffViewTest):
"""
Setup for tests that have no content restricted to specific content groups.
"""
def populate_course_fixture(self, course_fixture):
"""
Populates test course with chapter, sequential, and 2 problems.
"""
problem_data = dedent("""
<problem markdown="Simple Problem" max_attempts="" weight="">
<p>Choose Yes.</p>
<choiceresponse>
<checkboxgroup>
<choice correct="true">Yes</choice>
</checkboxgroup>
</choiceresponse>
</problem>
""")
course_fixture.add_children(
XBlockFixtureDesc('chapter', 'Test Section').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection').add_children(
XBlockFixtureDesc('problem', 'Test Problem 1', data=problem_data),
XBlockFixtureDesc('problem', 'Test Problem 2', data=problem_data)
)
)
)
@attr(shard=10)
class StaffViewToggleTest(CourseWithoutContentGroupsTest):
"""
Tests for the staff view toggle button.
"""
def test_instructor_tab_visibility(self):
"""
Test that the instructor tab is hidden when viewing as a student.
"""
course_page = self._goto_staff_page()
self.assertTrue(course_page.has_tab('Instructor'))
course_page.set_staff_view_mode('Student')
self.assertEqual(course_page.staff_view_mode, 'Student')
self.assertFalse(course_page.has_tab('Instructor'))
@attr(shard=10)
class StaffDebugTest(CourseWithoutContentGroupsTest):
"""
Tests that verify the staff debug info.
"""
def test_reset_attempts_empty(self):
"""
Test that we reset even when there is no student state
"""
staff_debug_page = self._goto_staff_page().open_staff_debug_info()
staff_debug_page.reset_attempts()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(
u'Successfully reset the attempts for user {}'.format(self.USERNAME), msg,
)
def test_delete_state_empty(self):
"""
Test that we delete properly even when there isn't state to delete.
"""
staff_debug_page = self._goto_staff_page().open_staff_debug_info()
staff_debug_page.delete_state()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(
u'Successfully deleted student state for user {}'.format(self.USERNAME), msg,
)
def test_reset_attempts_state(self):
"""
Successfully reset the student attempts
"""
staff_page = self._goto_staff_page()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.reset_attempts()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(
u'Successfully reset the attempts for user {}'.format(self.USERNAME), msg,
)
def test_rescore_problem(self):
"""
Rescore the student
"""
staff_page = self._goto_staff_page()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.rescore()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully rescored problem for user {}'.format(self.USERNAME), msg)
def test_rescore_problem_if_higher(self):
"""
Rescore the student
"""
staff_page = self._goto_staff_page()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.rescore_if_higher()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully rescored problem to improve score for user {}'.format(self.USERNAME), msg)
def test_student_state_delete(self):
"""
Successfully delete the student state with an answer
"""
staff_page = self._goto_staff_page()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.delete_state()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully deleted student state for user {}'.format(self.USERNAME), msg)
def test_student_by_email(self):
"""
Successfully reset the student attempts using their email address
"""
staff_page = self._goto_staff_page()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.reset_attempts(self.EMAIL)
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully reset the attempts for user {}'.format(self.EMAIL), msg)
def test_bad_student(self):
"""
Test negative response with invalid user
"""
staff_page = self._goto_staff_page()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.delete_state('INVALIDUSER')
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Failed to delete student state for user. User does not exist.', msg)
def test_reset_attempts_for_problem_loaded_via_ajax(self):
"""
Successfully reset the student attempts for problem loaded via ajax.
"""
staff_page = self._goto_staff_page()
staff_page.load_problem_via_ajax()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.reset_attempts()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully reset the attempts for user {}'.format(self.USERNAME), msg)
def test_rescore_state_for_problem_loaded_via_ajax(self):
"""
Rescore the student for problem loaded via ajax.
"""
staff_page = self._goto_staff_page()
staff_page.load_problem_via_ajax()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.rescore()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully rescored problem for user {}'.format(self.USERNAME), msg)
def test_student_state_delete_for_problem_loaded_via_ajax(self):
"""
Successfully delete the student state for problem loaded via ajax.
"""
staff_page = self._goto_staff_page()
staff_page.load_problem_via_ajax()
staff_page.answer_problem()
staff_debug_page = staff_page.open_staff_debug_info()
staff_debug_page.delete_state()
msg = staff_debug_page.idash_msg[0]
self.assertEqual(u'Successfully deleted student state for user {}'.format(self.USERNAME), msg)
class CourseWithContentGroupsTest(StaffViewTest):
"""
Verifies that changing the "View this course as" selector works properly for content groups.
"""
def setUp(self):
super(CourseWithContentGroupsTest, self).setUp()
# pylint: disable=protected-access
self.course_fixture._update_xblock(self.course_fixture._course_location, {
"metadata": {
u"user_partitions": [
create_user_partition_json(
0,
'Configuration alpha,beta',
'Content Group Partition',
[Group("0", 'alpha'), Group("1", 'beta')],
scheme="cohort"
)
],
},
})
def populate_course_fixture(self, course_fixture):
"""
Populates test course with chapter, sequential, and 3 problems.
One problem is visible to all, one problem is visible only to Group "alpha", and
one problem is visible only to Group "beta".
"""
problem_data = dedent("""
<problem markdown="Simple Problem" max_attempts="" weight="">
<choiceresponse>
<label>Choose Yes.</label>
<checkboxgroup>
<choice correct="true">Yes</choice>
</checkboxgroup>
</choiceresponse>
</problem>
""")
self.alpha_text = "VISIBLE TO ALPHA"
self.beta_text = "VISIBLE TO BETA"
self.everyone_text = "VISIBLE TO EVERYONE"
course_fixture.add_children(
XBlockFixtureDesc('chapter', 'Test Section').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection').add_children(
XBlockFixtureDesc('vertical', 'Test Unit').add_children(
XBlockFixtureDesc(
'problem', self.alpha_text, data=problem_data, metadata={"group_access": {0: [0]}}
),
XBlockFixtureDesc(
'problem', self.beta_text, data=problem_data, metadata={"group_access": {0: [1]}}
),
XBlockFixtureDesc('problem', self.everyone_text, data=problem_data)
)
)
)
)
@attr(shard=10)
def test_staff_sees_all_problems(self):
"""
Scenario: Staff see all problems
Given I have a course with a cohort user partition
And problems that are associated with specific groups in the user partition
When I view the courseware in the LMS with staff access
Then I see all the problems, regardless of their group_access property
"""
course_page = self._goto_staff_page()
verify_expected_problem_visibility(self, course_page, [self.alpha_text, self.beta_text, self.everyone_text])
@attr(shard=3)
def test_student_not_in_content_group(self):
"""
Scenario: When previewing as a student, only content visible to all is shown
Given I have a course with a cohort user partition
And problems that are associated with specific groups in the user partition
When I view the courseware in the LMS with staff access
And I change to previewing as a Student
Then I see only problems visible to all users
"""
course_page = self._goto_staff_page()
course_page.set_staff_view_mode('Student')
verify_expected_problem_visibility(self, course_page, [self.everyone_text])
@attr(shard=3)
def test_as_student_in_alpha(self):
"""
Scenario: When previewing as a student in group alpha, only content visible to alpha is shown
Given I have a course with a cohort user partition
And problems that are associated with specific groups in the user partition
When I view the courseware in the LMS with staff access
And I change to previewing as a Student in group alpha
Then I see only problems visible to group alpha
"""
course_page = self._goto_staff_page()
course_page.set_staff_view_mode('Student in alpha')
verify_expected_problem_visibility(self, course_page, [self.alpha_text, self.everyone_text])
@attr(shard=3)
def test_as_student_in_beta(self):
"""
Scenario: When previewing as a student in group beta, only content visible to beta is shown
Given I have a course with a cohort user partition
And problems that are associated with specific groups in the user partition
When I view the courseware in the LMS with staff access
And I change to previewing as a Student in group beta
Then I see only problems visible to group beta
"""
course_page = self._goto_staff_page()
course_page.set_staff_view_mode('Student in beta')
verify_expected_problem_visibility(self, course_page, [self.beta_text, self.everyone_text])
def create_cohorts_and_assign_students(self, student_a_username, student_b_username):
"""
Adds 2 manual cohorts, linked to content groups, to the course.
Each cohort is assigned one student.
"""
instructor_dashboard_page = InstructorDashboardPage(self.browser, self.course_id)
instructor_dashboard_page.visit()
cohort_management_page = instructor_dashboard_page.select_cohort_management()
cohort_management_page.is_cohorted = True
def add_cohort_with_student(cohort_name, content_group, student):
""" Create cohort and assign student to it. """
cohort_management_page.add_cohort(cohort_name, content_group=content_group)
cohort_management_page.add_students_to_selected_cohort([student])
add_cohort_with_student("Cohort Alpha", "alpha", student_a_username)
add_cohort_with_student("Cohort Beta", "beta", student_b_username)
cohort_management_page.wait_for_ajax()
@attr(shard=3)
def test_as_specific_student(self):
student_a_username = 'tass_student_a'
student_b_username = 'tass_student_b'
AutoAuthPage(self.browser, username=student_a_username, course_id=self.course_id, no_login=True).visit()
AutoAuthPage(self.browser, username=student_b_username, course_id=self.course_id, no_login=True).visit()
self.create_cohorts_and_assign_students(student_a_username, student_b_username)
# Masquerade as student in alpha cohort:
course_page = self._goto_staff_page()
course_page.set_staff_view_mode_specific_student(student_a_username)
verify_expected_problem_visibility(self, course_page, [self.alpha_text, self.everyone_text])
# Masquerade as student in beta cohort:
course_page.set_staff_view_mode_specific_student(student_b_username)
verify_expected_problem_visibility(self, course_page, [self.beta_text, self.everyone_text])
@attr('a11y')
def test_course_page(self):
"""
Run accessibility audit for course staff pages.
"""
course_page = self._goto_staff_page()
course_page.a11y_audit.config.set_rules({
'ignore': [
'aria-allowed-attr', # TODO: AC-559
'aria-roles', # TODO: AC-559,
'aria-valid-attr', # TODO: AC-559
'color-contrast', # TODO: AC-559
'link-href', # TODO: AC-559
'section', # TODO: AC-559
]
})
course_page.a11y_audit.check_for_accessibility_errors()
def verify_expected_problem_visibility(test, courseware_page, expected_problems):
"""
Helper method that checks that the expected problems are visible on the current page.
"""
test.assertEqual(
len(expected_problems), courseware_page.num_xblock_components, "Incorrect number of visible problems"
)
for index, expected_problem in enumerate(expected_problems):
test.assertIn(expected_problem, courseware_page.xblock_components[index].text)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2925,
314,
298,
7780,
2,
9759,
315,
314,
27540,
626,
6127,
13729,
3382,
25910,
12,
17246,
12,
436,
6646,
25031,
14,
199,
624,
421,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
504,
2863,
14,
396,
14,
28519,
14,
2219,
14,
7546,
492,
18276,
6979,
774,
12,
1218,
63,
751,
63,
5312,
63,
1001,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
19806,
14,
2495,
63,
1178,
492,
9195,
2817,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
15807,
14,
17744,
492,
5531,
1068,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
15807,
14,
14891,
63,
9743,
492,
26150,
30122,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
15807,
14,
7018,
63,
1345,
492,
25910,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
8769,
14,
1972,
492,
5531,
12812,
12,
28802,
199,
504,
330,
745,
63,
2239,
89,
14,
12741,
572,
492,
9630,
32303,
199,
504,
9872,
14,
12553,
14,
12553,
492,
5611,
199,
504,
13390,
492,
22622,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
25910,
2768,
774,
8,
11427,
6979,
774,
304,
272,
408,
272,
6496,
626,
4911,
314,
12622,
2455,
14,
272,
408,
272,
13044,
2339,
275,
298,
840,
25900,
63,
15472,
1157,
2,
272,
32320,
275,
298,
31073,
977,
13361,
32,
2694,
14,
957,
2,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
18963,
2768,
774,
12,
291,
680,
5996,
342,
398,
291,
14,
17744,
63,
1606,
275,
5531,
1068,
3276,
8,
277,
14,
5750,
12,
291,
14,
1972,
63,
344,
9,
398,
327,
13276,
282,
2518,
543,
10189,
15,
22959,
12,
12187,
12,
7029,
12,
436,
4926,
16816,
267,
291,
14,
1972,
63,
5997,
275,
5531,
12812,
8,
288,
291,
14,
1972,
63,
815,
459,
1308,
995,
291,
14,
1972,
63,
815,
459,
1955,
995,
288,
291,
14,
1972,
63,
815,
459,
1065,
995,
291,
14,
1972,
63,
815,
459,
2918,
63,
354,
418,
267,
776,
398,
291,
14,
13817,
63,
1972,
63,
5997,
8,
277,
14,
1972,
63,
5997,
9,
221,
327,
4287,
26,
3507,
29,
889,
13,
1114,
398,
291,
14,
1972,
63,
5997,
14,
3174,
342,
398,
327,
9195,
13,
1178,
2274,
367,
314,
2518,
14,
267,
327,
4226,
642,
465,
2288,
12622,
880,
626,
1265,
911,
1937,
314,
25910,
10935,
267,
9195,
2817,
3276,
8,
277,
14,
5750,
12,
3434,
29,
277,
14,
11958,
12,
3031,
29,
277,
14,
10089,
12,
2151,
2518,
63,
344,
29,
277,
14,
1972,
63,
344,
12,
12622,
29,
549,
680,
5427,
342,
339,
347,
485,
14867,
63,
7018,
63,
1606,
8,
277,
304,
267,
408,
267,
3232,
12622,
2034,
543,
14412,
267,
408,
267,
291,
14,
17744,
63,
1606,
14,
5427,
342,
267,
12622,
63,
1606,
275,
25910,
3276,
8,
277,
14,
5750,
12,
291,
14,
1972,
63,
344,
9,
267,
291,
14,
629,
8,
7018,
63,
1606,
14,
7018,
63,
1345,
63,
632,
12,
283,
18963,
358,
267,
372,
12622,
63,
1606,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
5531,
12450,
2714,
10177,
774,
8,
18963,
2768,
774,
304,
272,
408,
272,
12439,
367,
2295,
626,
1172,
949,
1564,
15297,
370,
2488,
1564,
4652,
14,
272,
408,
339,
347,
13904,
63,
1972,
63,
5997,
8,
277,
12,
2518,
63,
5997,
304,
267,
408,
267,
13244,
15409,
511,
2518,
543,
17044,
12,
23381,
12,
436,
499,
8826,
14,
267,
408,
267,
5160,
63,
576,
275,
22622,
4852,
288,
665,
6462,
18502,
628,
3184,
20980,
2,
1390,
63,
13143,
9287,
5401,
9287,
30,
1598,
665,
80,
30,
23932,
29715,
9758,
80,
30,
1598,
665,
5095,
1310,
30,
355,
665,
13456,
923,
30,
2116,
665,
5095,
3211,
628,
2052,
1743,
12555,
1108,
5095,
30,
355,
3068,
13456,
923,
30,
1598,
3068,
5095,
1310,
30,
288,
3068,
6462,
30,
267,
7857,
398,
2518,
63,
5997,
14,
525,
63,
3223,
8,
288,
28802,
360,
11316,
297,
283,
774,
15247,
1959,
525,
63,
3223,
8,
355,
28802,
360,
16211,
297,
283,
774,
4804,
2792,
1959,
525,
63,
3223,
8,
490,
28802,
360,
6462,
297,
283,
774,
20980,
413,
297,
666,
29,
6462,
63,
576,
395,
490,
28802,
360,
6462,
297,
283,
774,
20980,
499,
297,
666,
29,
6462,
63,
576,
9,
355,
776,
288,
776,
267,
776,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
25910,
2768,
24743,
774,
8,
6979,
12450,
2714,
10177,
774,
304,
272,
408,
272,
6496,
367,
314,
12622,
2455,
19420,
5528,
14,
272,
408,
272,
347,
511,
63,
14891,
63,
2902,
63,
11269,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
17724,
5174,
365,
8752,
1380,
2455,
316,
465,
282,
6474,
14,
267,
408,
398,
2518,
63,
1606,
275,
291,
423,
14867,
63,
7018,
63,
1606,
342,
267,
291,
14,
1815,
8,
1972,
63,
1606,
14,
1989,
63,
2902,
360,
30742,
1333,
267,
2518,
63,
1606,
14,
409,
63,
7018,
63,
1345,
63,
632,
360,
18086,
358,
267,
291,
14,
629,
8,
1972,
63,
1606,
14,
7018,
63,
1345,
63,
632,
12,
283,
18086,
358,
267,
291,
14,
3334,
8,
1972,
63,
1606,
14,
1989,
63,
2902,
360,
30742,
1333,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
25910,
7084,
774,
8,
6979,
12450,
2714,
10177,
774,
304,
272,
408,
272,
6496,
626,
4911,
314,
12622,
3105,
2256,
14,
272,
408,
272,
347,
511,
63,
3958,
63,
13143,
63,
1667,
8,
277,
304,
267,
408,
267,
1379,
626,
781,
5305,
2755,
1380,
2337,
365,
949,
6474,
1174,
267,
408,
398,
12622,
63,
1757,
63,
1606,
275,
291,
423,
14867,
63,
7018,
63,
1606,
1252,
1490,
63,
7018,
63,
1757,
63,
815,
342,
267,
12622,
63,
1757,
63,
1606,
14,
3958,
63,
13143,
342,
267,
1499,
275,
12622,
63,
1757,
63,
1606,
14,
344,
1119,
63,
1328,
59,
16,
61,
267,
291,
14,
629,
8,
288,
399,
7,
25001,
5305,
314,
12454,
367,
922,
9499,
908,
8,
277,
14,
11958,
395,
1499,
12,
267,
776,
339,
347,
511,
63,
1807,
63,
929,
63,
1667,
8,
277,
304,
267,
408,
267,
1379,
626,
781,
3145,
7684,
2755,
1380,
2337,
5712
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2925,
314,
298,
7780,
2,
9759,
315,
314,
27540,
626,
6127,
13729,
3382,
25910,
12,
17246,
12,
436,
6646,
25031,
14,
199,
624,
421,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
504,
2863,
14,
396,
14,
28519,
14,
2219,
14,
7546,
492,
18276,
6979,
774,
12,
1218,
63,
751,
63,
5312,
63,
1001,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
19806,
14,
2495,
63,
1178,
492,
9195,
2817,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
15807,
14,
17744,
492,
5531,
1068,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
15807,
14,
14891,
63,
9743,
492,
26150,
30122,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
5856,
14,
15807,
14,
7018,
63,
1345,
492,
25910,
3276,
199,
504,
2863,
14,
396,
14,
28519,
14,
8769,
14,
1972,
492,
5531,
12812,
12,
28802,
199,
504,
330,
745,
63,
2239,
89,
14,
12741,
572,
492,
9630,
32303,
199,
504,
9872,
14,
12553,
14,
12553,
492,
5611,
199,
504,
13390,
492,
22622,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
25910,
2768,
774,
8,
11427,
6979,
774,
304,
272,
408,
272,
6496,
626,
4911,
314,
12622,
2455,
14,
272,
408,
272,
13044,
2339,
275,
298,
840,
25900,
63,
15472,
1157,
2,
272,
32320,
275,
298,
31073,
977,
13361,
32,
2694,
14,
957,
2,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
18963,
2768,
774,
12,
291,
680,
5996,
342,
398,
291,
14,
17744,
63,
1606,
275,
5531,
1068,
3276,
8,
277,
14,
5750,
12,
291,
14,
1972,
63,
344,
9,
398,
327,
13276,
282,
2518,
543,
10189,
15,
22959,
12,
12187,
12,
7029,
12,
436,
4926,
16816,
267,
291,
14,
1972,
63,
5997,
275,
5531,
12812,
8,
288,
291,
14,
1972,
63,
815,
459,
1308,
995,
291,
14,
1972,
63,
815,
459,
1955,
995,
288,
291,
14,
1972,
63,
815,
459,
1065,
995,
291,
14,
1972,
63,
815,
459,
2918,
63,
354,
418,
267,
776,
398,
291,
14,
13817,
63,
1972,
63,
5997,
8,
277,
14,
1972,
63,
5997,
9,
221,
327,
4287,
26,
3507,
29,
889,
13,
1114,
398,
291,
14,
1972,
63,
5997,
14,
3174,
342,
398,
327,
9195,
13,
1178,
2274,
367,
314,
2518,
14,
267,
327,
4226,
642,
465,
2288,
12622,
880,
626,
1265,
911,
1937,
314,
25910,
10935,
267,
9195,
2817,
3276,
8,
277,
14,
5750,
12,
3434,
29,
277,
14,
11958,
12,
3031,
29,
277,
14,
10089,
12,
2151,
2518,
63,
344,
29,
277,
14,
1972,
63,
344,
12,
12622,
29,
549,
680,
5427,
342,
339,
347,
485,
14867,
63,
7018,
63,
1606,
8,
277,
304,
267,
408,
267,
3232,
12622,
2034,
543,
14412,
267,
408,
267,
291,
14,
17744,
63,
1606,
14,
5427,
342,
267,
12622,
63,
1606,
275,
25910,
3276,
8,
277,
14,
5750,
12,
291,
14,
1972,
63,
344,
9,
267,
291,
14,
629,
8,
7018,
63,
1606,
14,
7018,
63,
1345,
63,
632,
12,
283,
18963,
358,
267,
372,
12622,
63,
1606,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
5531,
12450,
2714,
10177,
774,
8,
18963,
2768,
774,
304,
272,
408,
272,
12439,
367,
2295,
626,
1172,
949,
1564,
15297,
370,
2488,
1564,
4652,
14,
272,
408,
339,
347,
13904,
63,
1972,
63,
5997,
8,
277,
12,
2518,
63,
5997,
304,
267,
408,
267,
13244,
15409,
511,
2518,
543,
17044,
12,
23381,
12,
436,
499,
8826,
14,
267,
408,
267,
5160,
63,
576,
275,
22622,
4852,
288,
665,
6462,
18502,
628,
3184,
20980,
2,
1390,
63,
13143,
9287,
5401,
9287,
30,
1598,
665,
80,
30,
23932,
29715,
9758,
80,
30,
1598,
665,
5095,
1310,
30,
355,
665,
13456,
923,
30,
2116,
665,
5095,
3211,
628,
2052,
1743,
12555,
1108,
5095,
30,
355,
3068,
13456,
923,
30,
1598,
3068,
5095,
1310,
30,
288,
3068,
6462,
30,
267,
7857,
398,
2518,
63,
5997,
14,
525,
63,
3223,
8,
288,
28802,
360,
11316,
297,
283,
774,
15247,
1959,
525,
63,
3223,
8,
355,
28802,
360,
16211,
297,
283,
774,
4804,
2792,
1959,
525,
63,
3223,
8,
490,
28802,
360,
6462,
297,
283,
774,
20980,
413,
297,
666,
29,
6462,
63,
576,
395,
490,
28802,
360,
6462,
297,
283,
774,
20980,
499,
297,
666,
29,
6462,
63,
576,
9,
355,
776,
288,
776,
267,
776,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
25910,
2768,
24743,
774,
8,
6979,
12450,
2714,
10177,
774,
304,
272,
408,
272,
6496,
367,
314,
12622,
2455,
19420,
5528,
14,
272,
408,
272,
347,
511,
63,
14891,
63,
2902,
63,
11269,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
17724,
5174,
365,
8752,
1380,
2455,
316,
465,
282,
6474,
14,
267,
408,
398,
2518,
63,
1606,
275,
291,
423,
14867,
63,
7018,
63,
1606,
342,
267,
291,
14,
1815,
8,
1972,
63,
1606,
14,
1989,
63,
2902,
360,
30742,
1333,
267,
2518,
63,
1606,
14,
409,
63,
7018,
63,
1345,
63,
632,
360,
18086,
358,
267,
291,
14,
629,
8,
1972,
63,
1606,
14,
7018,
63,
1345,
63,
632,
12,
283,
18086,
358,
267,
291,
14,
3334,
8,
1972,
63,
1606,
14,
1989,
63,
2902,
360,
30742,
1333,
421,
199,
32,
962,
8,
10810,
29,
709,
9,
199,
533,
25910,
7084,
774,
8,
6979,
12450,
2714,
10177,
774,
304,
272,
408,
272,
6496,
626,
4911,
314,
12622,
3105,
2256,
14,
272,
408,
272,
347,
511,
63,
3958,
63,
13143,
63,
1667,
8,
277,
304,
267,
408,
267,
1379,
626,
781,
5305,
2755,
1380,
2337,
365,
949,
6474,
1174,
267,
408,
398,
12622,
63,
1757,
63,
1606,
275,
291,
423,
14867,
63,
7018,
63,
1606,
1252,
1490,
63,
7018,
63,
1757,
63,
815,
342,
267,
12622,
63,
1757,
63,
1606,
14,
3958,
63,
13143,
342,
267,
1499,
275,
12622,
63,
1757,
63,
1606,
14,
344,
1119,
63,
1328,
59,
16,
61,
267,
291,
14,
629,
8,
288,
399,
7,
25001,
5305,
314,
12454,
367,
922,
9499,
908,
8,
277,
14,
11958,
395,
1499,
12,
267,
776,
339,
347,
511,
63,
1807,
63,
929,
63,
1667,
8,
277,
304,
267,
408,
267,
1379,
626,
781,
3145,
7684,
2755,
1380,
2337,
5712,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
umitproject/site-status
|
django/db/models/sql/where.py
|
289
|
13163
|
"""
Code to manage the creation and SQL rendering of 'where' constraints.
"""
import datetime
from itertools import repeat
from django.utils import tree
from django.db.models.fields import Field
from django.db.models.query_utils import QueryWrapper
from datastructures import EmptyResultSet, FullResultSet
# Connection types
AND = 'AND'
OR = 'OR'
class EmptyShortCircuit(Exception):
"""
Internal exception used to indicate that a "matches nothing" node should be
added to the where-clause.
"""
pass
class WhereNode(tree.Node):
"""
Used to represent the SQL where-clause.
The class is tied to the Query class that created it (in order to create
the correct SQL).
The children in this tree are usually either Q-like objects or lists of
[table_alias, field_name, db_type, lookup_type, value_annotation,
params]. However, a child could also be any class with as_sql() and
relabel_aliases() methods.
"""
default = AND
def add(self, data, connector):
"""
Add a node to the where-tree. If the data is a list or tuple, it is
expected to be of the form (obj, lookup_type, value), where obj is
a Constraint object, and is then slightly munged before being stored
(to avoid storing any reference to field objects). Otherwise, the 'data'
is stored unchanged and can be any class with an 'as_sql()' method.
"""
if not isinstance(data, (list, tuple)):
super(WhereNode, self).add(data, connector)
return
obj, lookup_type, value = data
if hasattr(value, '__iter__') and hasattr(value, 'next'):
# Consume any generators immediately, so that we can determine
# emptiness and transform any non-empty values correctly.
value = list(value)
# The "annotation" parameter is used to pass auxilliary information
# about the value(s) to the query construction. Specifically, datetime
# and empty values need special handling. Other types could be used
# here in the future (using Python types is suggested for consistency).
if isinstance(value, datetime.datetime):
annotation = datetime.datetime
elif hasattr(value, 'value_annotation'):
annotation = value.value_annotation
else:
annotation = bool(value)
if hasattr(obj, "prepare"):
value = obj.prepare(lookup_type, value)
super(WhereNode, self).add((obj, lookup_type, annotation, value),
connector)
return
super(WhereNode, self).add((obj, lookup_type, annotation, value),
connector)
def as_sql(self, qn, connection):
"""
Returns the SQL version of the where clause and the value to be
substituted in. Returns None, None if this node is empty.
If 'node' is provided, that is the root of the SQL generation
(generally not needed except by the internal implementation for
recursion).
"""
if not self.children:
return None, []
result = []
result_params = []
empty = True
for child in self.children:
try:
if hasattr(child, 'as_sql'):
sql, params = child.as_sql(qn=qn, connection=connection)
else:
# A leaf node in the tree.
sql, params = self.make_atom(child, qn, connection)
except EmptyResultSet:
if self.connector == AND and not self.negated:
# We can bail out early in this particular case (only).
raise
elif self.negated:
empty = False
continue
except FullResultSet:
if self.connector == OR:
if self.negated:
empty = True
break
# We match everything. No need for any constraints.
return '', []
if self.negated:
empty = True
continue
empty = False
if sql:
result.append(sql)
result_params.extend(params)
if empty:
raise EmptyResultSet
conn = ' %s ' % self.connector
sql_string = conn.join(result)
if sql_string:
if self.negated:
sql_string = 'NOT (%s)' % sql_string
elif len(self.children) != 1:
sql_string = '(%s)' % sql_string
return sql_string, result_params
def make_atom(self, child, qn, connection):
"""
Turn a tuple (table_alias, column_name, db_type, lookup_type,
value_annot, params) into valid SQL.
Returns the string for the SQL fragment and the parameters to use for
it.
"""
lvalue, lookup_type, value_annot, params_or_value = child
if hasattr(lvalue, 'process'):
try:
lvalue, params = lvalue.process(lookup_type, params_or_value, connection)
except EmptyShortCircuit:
raise EmptyResultSet
else:
params = Field().get_db_prep_lookup(lookup_type, params_or_value,
connection=connection, prepared=True)
if isinstance(lvalue, tuple):
# A direct database column lookup.
field_sql = self.sql_for_columns(lvalue, qn, connection)
else:
# A smart object with an as_sql() method.
field_sql = lvalue.as_sql(qn, connection)
if value_annot is datetime.datetime:
cast_sql = connection.ops.datetime_cast_sql()
else:
cast_sql = '%s'
if hasattr(params, 'as_sql'):
extra, params = params.as_sql(qn, connection)
cast_sql = ''
else:
extra = ''
if (len(params) == 1 and params[0] == '' and lookup_type == 'exact'
and connection.features.interprets_empty_strings_as_nulls):
lookup_type = 'isnull'
value_annot = True
if lookup_type in connection.operators:
format = "%s %%s %%s" % (connection.ops.lookup_cast(lookup_type),)
return (format % (field_sql,
connection.operators[lookup_type] % cast_sql,
extra), params)
if lookup_type == 'in':
if not value_annot:
raise EmptyResultSet
if extra:
return ('%s IN %s' % (field_sql, extra), params)
max_in_list_size = connection.ops.max_in_list_size()
if max_in_list_size and len(params) > max_in_list_size:
# Break up the params list into an OR of manageable chunks.
in_clause_elements = ['(']
for offset in xrange(0, len(params), max_in_list_size):
if offset > 0:
in_clause_elements.append(' OR ')
in_clause_elements.append('%s IN (' % field_sql)
group_size = min(len(params) - offset, max_in_list_size)
param_group = ', '.join(repeat('%s', group_size))
in_clause_elements.append(param_group)
in_clause_elements.append(')')
in_clause_elements.append(')')
return ''.join(in_clause_elements), params
else:
return ('%s IN (%s)' % (field_sql,
', '.join(repeat('%s', len(params)))),
params)
elif lookup_type in ('range', 'year'):
return ('%s BETWEEN %%s and %%s' % field_sql, params)
elif lookup_type in ('month', 'day', 'week_day'):
return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type, field_sql),
params)
elif lookup_type == 'isnull':
return ('%s IS %sNULL' % (field_sql,
(not value_annot and 'NOT ' or '')), ())
elif lookup_type == 'search':
return (connection.ops.fulltext_search_sql(field_sql), params)
elif lookup_type in ('regex', 'iregex'):
return connection.ops.regex_lookup(lookup_type) % (field_sql, cast_sql), params
raise TypeError('Invalid lookup_type: %r' % lookup_type)
def sql_for_columns(self, data, qn, connection):
"""
Returns the SQL fragment used for the left-hand side of a column
constraint (for example, the "T1.foo" portion in the clause
"WHERE ... T1.foo = 6").
"""
table_alias, name, db_type = data
if table_alias:
lhs = '%s.%s' % (qn(table_alias), qn(name))
else:
lhs = qn(name)
return connection.ops.field_cast_sql(db_type) % lhs
def relabel_aliases(self, change_map, node=None):
"""
Relabels the alias values of any children. 'change_map' is a dictionary
mapping old (current) alias values to the new values.
"""
if not node:
node = self
for pos, child in enumerate(node.children):
if hasattr(child, 'relabel_aliases'):
child.relabel_aliases(change_map)
elif isinstance(child, tree.Node):
self.relabel_aliases(change_map, child)
elif isinstance(child, (list, tuple)):
if isinstance(child[0], (list, tuple)):
elt = list(child[0])
if elt[0] in change_map:
elt[0] = change_map[elt[0]]
node.children[pos] = (tuple(elt),) + child[1:]
else:
child[0].relabel_aliases(change_map)
# Check if the query value also requires relabelling
if hasattr(child[3], 'relabel_aliases'):
child[3].relabel_aliases(change_map)
class EverythingNode(object):
"""
A node that matches everything.
"""
def as_sql(self, qn=None, connection=None):
raise FullResultSet
def relabel_aliases(self, change_map, node=None):
return
class NothingNode(object):
"""
A node that matches nothing.
"""
def as_sql(self, qn=None, connection=None):
raise EmptyResultSet
def relabel_aliases(self, change_map, node=None):
return
class ExtraWhere(object):
def __init__(self, sqls, params):
self.sqls = sqls
self.params = params
def as_sql(self, qn=None, connection=None):
return " AND ".join(self.sqls), tuple(self.params or ())
class Constraint(object):
"""
An object that can be passed to WhereNode.add() and knows how to
pre-process itself prior to including in the WhereNode.
"""
def __init__(self, alias, col, field):
self.alias, self.col, self.field = alias, col, field
def __getstate__(self):
"""Save the state of the Constraint for pickling.
Fields aren't necessarily pickleable, because they can have
callable default values. So, instead of pickling the field
store a reference so we can restore it manually
"""
obj_dict = self.__dict__.copy()
if self.field:
obj_dict['model'] = self.field.model
obj_dict['field_name'] = self.field.name
del obj_dict['field']
return obj_dict
def __setstate__(self, data):
"""Restore the constraint """
model = data.pop('model', None)
field_name = data.pop('field_name', None)
self.__dict__.update(data)
if model is not None:
self.field = model._meta.get_field(field_name)
else:
self.field = None
def prepare(self, lookup_type, value):
if self.field:
return self.field.get_prep_lookup(lookup_type, value)
return value
def process(self, lookup_type, value, connection):
"""
Returns a tuple of data suitable for inclusion in a WhereNode
instance.
"""
# Because of circular imports, we need to import this here.
from django.db.models.base import ObjectDoesNotExist
try:
if self.field:
params = self.field.get_db_prep_lookup(lookup_type, value,
connection=connection, prepared=True)
db_type = self.field.db_type(connection=connection)
else:
# This branch is used at times when we add a comparison to NULL
# (we don't really want to waste time looking up the associated
# field object at the calling location).
params = Field().get_db_prep_lookup(lookup_type, value,
connection=connection, prepared=True)
db_type = None
except ObjectDoesNotExist:
raise EmptyShortCircuit
return (self.alias, self.col, db_type), params
def relabel_aliases(self, change_map):
if self.alias in change_map:
self.alias = change_map[self.alias]
|
agpl-3.0
|
[
624,
199,
3034,
370,
9635,
314,
7143,
436,
5385,
14066,
402,
283,
4509,
7,
9565,
14,
199,
624,
199,
646,
2197,
199,
504,
7975,
492,
11982,
199,
199,
504,
1639,
14,
1208,
492,
3123,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
5024,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
63,
1208,
492,
8133,
4590,
199,
504,
666,
13547,
492,
9630,
21722,
12,
16579,
21722,
199,
199,
3,
8113,
2943,
199,
3649,
275,
283,
3649,
7,
199,
726,
275,
283,
726,
7,
199,
199,
533,
9630,
10039,
35,
14221,
8,
1726,
304,
272,
408,
272,
12624,
1919,
1202,
370,
6623,
626,
282,
298,
6742,
6548,
2,
1031,
1077,
506,
272,
3483,
370,
314,
2382,
13,
8501,
14,
272,
408,
272,
986,
199,
199,
533,
17685,
1716,
8,
2350,
14,
1716,
304,
272,
408,
272,
8051,
370,
2954,
314,
5385,
2382,
13,
8501,
14,
339,
710,
1021,
365,
29142,
370,
314,
8133,
1021,
626,
2737,
652,
334,
262,
1865,
370,
1218,
272,
314,
3211,
5385,
680,
339,
710,
4978,
315,
642,
3123,
787,
9987,
1902,
1413,
13,
2930,
2251,
503,
5548,
402,
272,
359,
1224,
63,
3620,
12,
901,
63,
354,
12,
1592,
63,
466,
12,
4237,
63,
466,
12,
574,
63,
9340,
12,
272,
1862,
1055,
9738,
12,
282,
1982,
4293,
2597,
506,
1263,
1021,
543,
465,
63,
3009,
342,
436,
272,
295,
1302,
63,
8602,
342,
3102,
14,
272,
408,
272,
849,
275,
2401,
339,
347,
1050,
8,
277,
12,
666,
12,
13252,
304,
267,
408,
267,
2654,
282,
1031,
370,
314,
2382,
13,
2350,
14,
982,
314,
666,
365,
282,
769,
503,
2008,
12,
652,
365,
267,
1420,
370,
506,
402,
314,
1824,
334,
1113,
12,
4237,
63,
466,
12,
574,
395,
2382,
1559,
365,
267,
282,
25889,
909,
12,
436,
365,
2066,
18023,
333,
324,
3046,
2544,
3769,
5489,
267,
334,
475,
5126,
16915,
1263,
3659,
370,
901,
2251,
680,
6630,
12,
314,
283,
576,
7,
267,
365,
5489,
14874,
436,
883,
506,
1263,
1021,
543,
376,
283,
305,
63,
3009,
11716,
1083,
14,
267,
408,
267,
340,
440,
1228,
8,
576,
12,
334,
513,
12,
2008,
2298,
288,
1613,
8,
26493,
1716,
12,
291,
680,
525,
8,
576,
12,
13252,
9,
288,
372,
398,
1559,
12,
4237,
63,
466,
12,
574,
275,
666,
267,
340,
2688,
8,
585,
12,
2560,
1661,
13766,
436,
2688,
8,
585,
12,
283,
2184,
735,
288,
327,
1448,
3639,
1263,
16952,
9939,
12,
880,
626,
781,
883,
6705,
288,
327,
325,
4787,
9585,
436,
5793,
1263,
2222,
13,
1667,
1338,
6657,
14,
288,
574,
275,
769,
8,
585,
9,
398,
327,
710,
298,
9340,
2,
2725,
365,
1202,
370,
986,
11593,
8148,
695,
2556,
267,
327,
3595,
314,
574,
8,
83,
9,
370,
314,
1827,
14538,
14,
30836,
12,
2197,
267,
327,
436,
2701,
1338,
1929,
4539,
7252,
14,
5439,
2943,
4293,
506,
1202,
267,
327,
2348,
315,
314,
6466,
334,
4941,
2018,
2943,
365,
25697,
367,
17754,
680,
267,
340,
1228,
8,
585,
12,
2197,
14,
2083,
304,
288,
11262,
275,
2197,
14,
2083,
267,
916,
2688,
8,
585,
12,
283,
585,
63,
9340,
735,
288,
11262,
275,
574,
14,
585,
63,
9340,
267,
587,
26,
288,
11262,
275,
2155,
8,
585,
9,
398,
340,
2688,
8,
1113,
12,
298,
6726,
2349,
288,
574,
275,
1559,
14,
6726,
8,
3892,
63,
466,
12,
574,
9,
288,
1613,
8,
26493,
1716,
12,
291,
680,
525,
1332,
1113,
12,
4237,
63,
466,
12,
11262,
12,
574,
395,
355,
13252,
9,
288,
372,
398,
1613,
8,
26493,
1716,
12,
291,
680,
525,
1332,
1113,
12,
4237,
63,
466,
12,
11262,
12,
574,
395,
355,
13252,
9,
339,
347,
465,
63,
3009,
8,
277,
12,
18293,
12,
1950,
304,
267,
408,
267,
1803,
314,
5385,
1015,
402,
314,
2382,
8502,
436,
314,
574,
370,
506,
267,
10004,
4241,
315,
14,
1803,
488,
12,
488,
340,
642,
1031,
365,
2701,
14,
398,
982,
283,
932,
7,
365,
2741,
12,
626,
365,
314,
1738,
402,
314,
5385,
10152,
267,
334,
2038,
1183,
440,
4346,
871,
701,
314,
5007,
4514,
367,
267,
16189,
680,
267,
408,
267,
340,
440,
291,
14,
3223,
26,
288,
372,
488,
12,
942,
267,
754,
275,
942,
267,
754,
63,
1162,
275,
942,
267,
2701,
275,
715,
267,
367,
1982,
315,
291,
14,
3223,
26,
288,
862,
26,
355,
340,
2688,
8,
1739,
12,
283,
305,
63,
3009,
735,
490,
3875,
12,
1862,
275,
1982,
14,
305,
63,
3009,
8,
15156,
29,
15156,
12,
1950,
29,
2105,
9,
355,
587,
26,
490,
327,
437,
11747,
1031,
315,
314,
3123,
14,
490,
3875,
12,
1862,
275,
291,
14,
1875,
63,
4188,
8,
1739,
12,
18293,
12,
1950,
9,
953,
871,
9630,
21722,
26,
355,
340,
291,
14,
11815,
508,
2401,
436,
440,
291,
14,
8705,
972,
26,
490,
327,
2136,
883,
31571,
734,
14670,
315,
642,
6770,
1930,
334,
2118,
680,
490,
746,
355,
916,
291,
14,
8705,
972,
26,
490,
2701,
275,
756,
355,
1980,
288,
871,
16579,
21722,
26,
355,
340,
291,
14,
11815,
508,
1549,
26,
490,
340,
291,
14,
8705,
972,
26,
717,
2701,
275,
715,
717,
2059,
490,
327,
2136,
1336,
8137,
14,
3091,
1929,
367,
1263,
9565,
14,
490,
372,
3260,
942,
355,
340,
291,
14,
8705,
972,
26,
490,
2701,
275,
715,
355,
1980,
953,
2701,
275,
756,
288,
340,
3875,
26,
355,
754,
14,
740,
8,
3009,
9,
355,
754,
63,
1162,
14,
2880,
8,
1162,
9,
267,
340,
2701,
26,
288,
746,
9630,
21722,
398,
2557,
275,
283,
450,
83,
283,
450,
291,
14,
11815,
267,
3875,
63,
875,
275,
2557,
14,
904,
8,
1099,
9,
267,
340,
3875,
63,
875,
26,
288,
340,
291,
14,
8705,
972,
26,
355,
3875,
63,
875,
275,
283,
4609,
4366,
83,
3171,
450,
3875,
63,
875,
288,
916,
822,
8,
277,
14,
3223,
9,
1137,
413,
26,
355,
3875,
63,
875,
275,
25676,
83,
3171,
450,
3875,
63,
875,
267,
372,
3875,
63,
875,
12,
754,
63,
1162,
339,
347,
1852,
63,
4188,
8,
277,
12,
1982,
12,
18293,
12,
1950,
304,
267,
408,
267,
16147,
282,
2008,
334,
1224,
63,
3620,
12,
2763,
63,
354,
12
] |
[
199,
3034,
370,
9635,
314,
7143,
436,
5385,
14066,
402,
283,
4509,
7,
9565,
14,
199,
624,
199,
646,
2197,
199,
504,
7975,
492,
11982,
199,
199,
504,
1639,
14,
1208,
492,
3123,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
5024,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
63,
1208,
492,
8133,
4590,
199,
504,
666,
13547,
492,
9630,
21722,
12,
16579,
21722,
199,
199,
3,
8113,
2943,
199,
3649,
275,
283,
3649,
7,
199,
726,
275,
283,
726,
7,
199,
199,
533,
9630,
10039,
35,
14221,
8,
1726,
304,
272,
408,
272,
12624,
1919,
1202,
370,
6623,
626,
282,
298,
6742,
6548,
2,
1031,
1077,
506,
272,
3483,
370,
314,
2382,
13,
8501,
14,
272,
408,
272,
986,
199,
199,
533,
17685,
1716,
8,
2350,
14,
1716,
304,
272,
408,
272,
8051,
370,
2954,
314,
5385,
2382,
13,
8501,
14,
339,
710,
1021,
365,
29142,
370,
314,
8133,
1021,
626,
2737,
652,
334,
262,
1865,
370,
1218,
272,
314,
3211,
5385,
680,
339,
710,
4978,
315,
642,
3123,
787,
9987,
1902,
1413,
13,
2930,
2251,
503,
5548,
402,
272,
359,
1224,
63,
3620,
12,
901,
63,
354,
12,
1592,
63,
466,
12,
4237,
63,
466,
12,
574,
63,
9340,
12,
272,
1862,
1055,
9738,
12,
282,
1982,
4293,
2597,
506,
1263,
1021,
543,
465,
63,
3009,
342,
436,
272,
295,
1302,
63,
8602,
342,
3102,
14,
272,
408,
272,
849,
275,
2401,
339,
347,
1050,
8,
277,
12,
666,
12,
13252,
304,
267,
408,
267,
2654,
282,
1031,
370,
314,
2382,
13,
2350,
14,
982,
314,
666,
365,
282,
769,
503,
2008,
12,
652,
365,
267,
1420,
370,
506,
402,
314,
1824,
334,
1113,
12,
4237,
63,
466,
12,
574,
395,
2382,
1559,
365,
267,
282,
25889,
909,
12,
436,
365,
2066,
18023,
333,
324,
3046,
2544,
3769,
5489,
267,
334,
475,
5126,
16915,
1263,
3659,
370,
901,
2251,
680,
6630,
12,
314,
283,
576,
7,
267,
365,
5489,
14874,
436,
883,
506,
1263,
1021,
543,
376,
283,
305,
63,
3009,
11716,
1083,
14,
267,
408,
267,
340,
440,
1228,
8,
576,
12,
334,
513,
12,
2008,
2298,
288,
1613,
8,
26493,
1716,
12,
291,
680,
525,
8,
576,
12,
13252,
9,
288,
372,
398,
1559,
12,
4237,
63,
466,
12,
574,
275,
666,
267,
340,
2688,
8,
585,
12,
2560,
1661,
13766,
436,
2688,
8,
585,
12,
283,
2184,
735,
288,
327,
1448,
3639,
1263,
16952,
9939,
12,
880,
626,
781,
883,
6705,
288,
327,
325,
4787,
9585,
436,
5793,
1263,
2222,
13,
1667,
1338,
6657,
14,
288,
574,
275,
769,
8,
585,
9,
398,
327,
710,
298,
9340,
2,
2725,
365,
1202,
370,
986,
11593,
8148,
695,
2556,
267,
327,
3595,
314,
574,
8,
83,
9,
370,
314,
1827,
14538,
14,
30836,
12,
2197,
267,
327,
436,
2701,
1338,
1929,
4539,
7252,
14,
5439,
2943,
4293,
506,
1202,
267,
327,
2348,
315,
314,
6466,
334,
4941,
2018,
2943,
365,
25697,
367,
17754,
680,
267,
340,
1228,
8,
585,
12,
2197,
14,
2083,
304,
288,
11262,
275,
2197,
14,
2083,
267,
916,
2688,
8,
585,
12,
283,
585,
63,
9340,
735,
288,
11262,
275,
574,
14,
585,
63,
9340,
267,
587,
26,
288,
11262,
275,
2155,
8,
585,
9,
398,
340,
2688,
8,
1113,
12,
298,
6726,
2349,
288,
574,
275,
1559,
14,
6726,
8,
3892,
63,
466,
12,
574,
9,
288,
1613,
8,
26493,
1716,
12,
291,
680,
525,
1332,
1113,
12,
4237,
63,
466,
12,
11262,
12,
574,
395,
355,
13252,
9,
288,
372,
398,
1613,
8,
26493,
1716,
12,
291,
680,
525,
1332,
1113,
12,
4237,
63,
466,
12,
11262,
12,
574,
395,
355,
13252,
9,
339,
347,
465,
63,
3009,
8,
277,
12,
18293,
12,
1950,
304,
267,
408,
267,
1803,
314,
5385,
1015,
402,
314,
2382,
8502,
436,
314,
574,
370,
506,
267,
10004,
4241,
315,
14,
1803,
488,
12,
488,
340,
642,
1031,
365,
2701,
14,
398,
982,
283,
932,
7,
365,
2741,
12,
626,
365,
314,
1738,
402,
314,
5385,
10152,
267,
334,
2038,
1183,
440,
4346,
871,
701,
314,
5007,
4514,
367,
267,
16189,
680,
267,
408,
267,
340,
440,
291,
14,
3223,
26,
288,
372,
488,
12,
942,
267,
754,
275,
942,
267,
754,
63,
1162,
275,
942,
267,
2701,
275,
715,
267,
367,
1982,
315,
291,
14,
3223,
26,
288,
862,
26,
355,
340,
2688,
8,
1739,
12,
283,
305,
63,
3009,
735,
490,
3875,
12,
1862,
275,
1982,
14,
305,
63,
3009,
8,
15156,
29,
15156,
12,
1950,
29,
2105,
9,
355,
587,
26,
490,
327,
437,
11747,
1031,
315,
314,
3123,
14,
490,
3875,
12,
1862,
275,
291,
14,
1875,
63,
4188,
8,
1739,
12,
18293,
12,
1950,
9,
953,
871,
9630,
21722,
26,
355,
340,
291,
14,
11815,
508,
2401,
436,
440,
291,
14,
8705,
972,
26,
490,
327,
2136,
883,
31571,
734,
14670,
315,
642,
6770,
1930,
334,
2118,
680,
490,
746,
355,
916,
291,
14,
8705,
972,
26,
490,
2701,
275,
756,
355,
1980,
288,
871,
16579,
21722,
26,
355,
340,
291,
14,
11815,
508,
1549,
26,
490,
340,
291,
14,
8705,
972,
26,
717,
2701,
275,
715,
717,
2059,
490,
327,
2136,
1336,
8137,
14,
3091,
1929,
367,
1263,
9565,
14,
490,
372,
3260,
942,
355,
340,
291,
14,
8705,
972,
26,
490,
2701,
275,
715,
355,
1980,
953,
2701,
275,
756,
288,
340,
3875,
26,
355,
754,
14,
740,
8,
3009,
9,
355,
754,
63,
1162,
14,
2880,
8,
1162,
9,
267,
340,
2701,
26,
288,
746,
9630,
21722,
398,
2557,
275,
283,
450,
83,
283,
450,
291,
14,
11815,
267,
3875,
63,
875,
275,
2557,
14,
904,
8,
1099,
9,
267,
340,
3875,
63,
875,
26,
288,
340,
291,
14,
8705,
972,
26,
355,
3875,
63,
875,
275,
283,
4609,
4366,
83,
3171,
450,
3875,
63,
875,
288,
916,
822,
8,
277,
14,
3223,
9,
1137,
413,
26,
355,
3875,
63,
875,
275,
25676,
83,
3171,
450,
3875,
63,
875,
267,
372,
3875,
63,
875,
12,
754,
63,
1162,
339,
347,
1852,
63,
4188,
8,
277,
12,
1982,
12,
18293,
12,
1950,
304,
267,
408,
267,
16147,
282,
2008,
334,
1224,
63,
3620,
12,
2763,
63,
354,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
neudesk/neucloud
|
openstack_dashboard/dashboards/admin/roles/tests.py
|
8
|
4038
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core.urlresolvers import reverse
from django import http
from mox import IgnoreArg # noqa
from mox import IsA # noqa
from openstack_dashboard import api
from openstack_dashboard.test import helpers as test
ROLES_INDEX_URL = reverse('horizon:admin:roles:index')
ROLES_CREATE_URL = reverse('horizon:admin:roles:create')
ROLES_UPDATE_URL = reverse('horizon:admin:roles:update', args=[1])
class RolesViewTests(test.BaseAdminViewTests):
@test.create_stubs({api.keystone: ('role_list',)})
def test_index(self):
api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
self.mox.ReplayAll()
res = self.client.get(ROLES_INDEX_URL)
self.assertContains(res, 'Create Role')
self.assertContains(res, 'Edit')
self.assertContains(res, 'Delete Role')
self.assertTemplateUsed(res, 'admin/roles/index.html')
self.assertItemsEqual(res.context['table'].data, self.roles.list())
@test.create_stubs({api.keystone: ('role_list',
'keystone_can_edit_role', )})
def test_index_with_keystone_can_edit_role_false(self):
api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
api.keystone.keystone_can_edit_role() \
.MultipleTimes().AndReturn(False)
self.mox.ReplayAll()
res = self.client.get(ROLES_INDEX_URL)
self.assertNotContains(res, 'Create Role')
self.assertNotContains(res, 'Edit')
self.assertNotContains(res, 'Delete Role')
self.assertTemplateUsed(res, 'admin/roles/index.html')
self.assertItemsEqual(res.context['table'].data, self.roles.list())
@test.create_stubs({api.keystone: ('role_create', )})
def test_create(self):
role = self.roles.first()
api.keystone.role_create(IgnoreArg(), role.name).AndReturn(role)
self.mox.ReplayAll()
formData = {'method': 'CreateRoleForm', 'name': role.name}
res = self.client.post(ROLES_CREATE_URL, formData)
self.assertNoFormErrors(res)
self.assertMessageCount(success=1)
@test.create_stubs({api.keystone: ('role_get', 'role_update')})
def test_update(self):
role = self.roles.first()
new_role_name = 'test_name'
api.keystone.role_get(IsA(http.HttpRequest), role.id).AndReturn(role)
api.keystone.role_update(IsA(http.HttpRequest),
role.id,
new_role_name).AndReturn(None)
self.mox.ReplayAll()
formData = {'method': 'UpdateRoleForm',
'id': role.id,
'name': new_role_name}
res = self.client.post(ROLES_UPDATE_URL, formData)
self.assertNoFormErrors(res)
self.assertMessageCount(success=1)
@test.create_stubs({api.keystone: ('role_list', 'role_delete')})
def test_delete(self):
role = self.roles.first()
api.keystone.role_list(IsA(http.HttpRequest)) \
.AndReturn(self.roles.list())
api.keystone.role_delete(IsA(http.HttpRequest),
role.id).AndReturn(None)
self.mox.ReplayAll()
formData = {'action': 'roles__delete__%s' % role.id}
res = self.client.post(ROLES_INDEX_URL, formData)
self.assertNoFormErrors(res)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
492,
1455,
199,
199,
504,
18610,
492,
14092,
6373,
221,
327,
8151,
199,
504,
18610,
492,
29719,
221,
327,
8151,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
421,
199,
6245,
654,
63,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
8050,
26,
1080,
358,
199,
6245,
654,
63,
8366,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
8050,
26,
981,
358,
199,
6245,
654,
63,
10383,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
8050,
26,
873,
297,
1249,
1524,
17,
566,
421,
199,
533,
6848,
2978,
2768,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
272,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
513,
9538,
1552,
272,
347,
511,
63,
1080,
8,
277,
304,
267,
2986,
14,
19143,
14,
3756,
63,
513,
8,
19288,
8801,
8572,
8,
277,
14,
8050,
14,
513,
1012,
398,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
6245,
654,
63,
10215,
63,
2632,
9,
267,
291,
14,
9535,
8,
470,
12,
283,
2499,
18033,
358,
267,
291,
14,
9535,
8,
470,
12,
283,
4685,
358,
267,
291,
14,
9535,
8,
470,
12,
283,
5392,
18033,
358,
398,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
8050,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
291,
14,
8050,
14,
513,
1012,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
513,
297,
4318,
283,
19143,
63,
2425,
63,
3773,
63,
3756,
297,
776,
1552,
272,
347,
511,
63,
1080,
63,
1045,
63,
19143,
63,
2425,
63,
3773,
63,
3756,
63,
3910,
8,
277,
304,
267,
2986,
14,
19143,
14,
3756,
63,
513,
8,
19288,
8801,
8572,
8,
277,
14,
8050,
14,
513,
1012,
267,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
3756,
342,
971,
288,
1275,
8433,
17687,
1252,
8572,
8,
797,
9,
267,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
6245,
654,
63,
10215,
63,
2632,
9,
398,
291,
14,
23218,
8,
470,
12,
283,
2499,
18033,
358,
267,
291,
14,
23218,
8,
470,
12,
283,
4685,
358,
267,
291,
14,
23218,
8,
470,
12,
283,
5392,
18033,
358,
398,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
8050,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
291,
14,
8050,
14,
513,
1012,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
981,
297,
776,
1552,
272,
347,
511,
63,
981,
8,
277,
304,
267,
4719,
275,
291,
14,
8050,
14,
2246,
342,
398,
2986,
14,
19143,
14,
3756,
63,
981,
8,
19288,
1062,
4719,
14,
354,
680,
8572,
8,
3756,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1824,
1451,
275,
791,
765,
356,
283,
2499,
7422,
2821,
297,
283,
354,
356,
4719,
14,
354,
93,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
6245,
654,
63,
8366,
63,
2632,
12,
1824,
1451,
9,
398,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
291,
14,
479,
2209,
2353,
8,
3742,
29,
17,
9,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
362,
297,
283,
3756,
63,
873,
22220,
272,
347,
511,
63,
873,
8,
277,
304,
267,
4719,
275,
291,
14,
8050,
14,
2246,
342,
267,
892,
63,
3756,
63,
354,
275,
283,
396,
63,
354,
7,
398,
2986,
14,
19143,
14,
3756,
63,
362,
8,
14104,
8,
1014,
14,
10441,
395,
4719,
14,
344,
680,
8572,
8,
3756,
9,
267,
2986,
14,
19143,
14,
3756,
63,
873,
8,
14104,
8,
1014,
14,
10441,
395,
639,
4719,
14,
344,
12,
639,
892,
63,
3756,
63,
354,
680,
8572,
8,
403,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1824,
1451,
275,
791,
765,
356,
283,
4152,
7422,
2821,
297,
490,
283,
344,
356,
4719,
14,
344,
12,
490,
283,
354,
356,
892,
63,
3756,
63,
354,
93,
398,
522,
275,
291,
14,
1258,
14,
1932,
8,
6245,
654,
63,
10383,
63,
2632,
12,
1824,
1451,
9,
398,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
291,
14,
479,
2209,
2353,
8,
3742,
29,
17,
9,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
513,
297,
283,
3756,
63,
1807,
22220,
272,
347,
511,
63,
1807,
8,
277,
304,
267,
4719,
275,
291,
14,
8050,
14,
2246,
342,
398,
2986,
14,
19143,
14,
3756,
63,
513,
8,
14104,
8,
1014,
14,
10441,
430,
971,
1169,
1275,
8572,
8,
277,
14,
8050,
14,
513,
1012,
267,
2986,
14,
19143,
14,
3756,
63,
1807,
8,
14104,
8,
1014,
14,
10441,
395,
639,
4719,
14,
344,
680,
8572,
8,
403,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1824,
1451,
275,
791,
1287,
356,
283,
8050,
363,
1807,
363,
5,
83,
7,
450,
4719,
14,
344
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
492,
1455,
199,
199,
504,
18610,
492,
14092,
6373,
221,
327,
8151,
199,
504,
18610,
492,
29719,
221,
327,
8151,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
421,
199,
6245,
654,
63,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
8050,
26,
1080,
358,
199,
6245,
654,
63,
8366,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
8050,
26,
981,
358,
199,
6245,
654,
63,
10383,
63,
2632,
275,
3837,
360,
16561,
26,
2113,
26,
8050,
26,
873,
297,
1249,
1524,
17,
566,
421,
199,
533,
6848,
2978,
2768,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
272,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
513,
9538,
1552,
272,
347,
511,
63,
1080,
8,
277,
304,
267,
2986,
14,
19143,
14,
3756,
63,
513,
8,
19288,
8801,
8572,
8,
277,
14,
8050,
14,
513,
1012,
398,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
6245,
654,
63,
10215,
63,
2632,
9,
267,
291,
14,
9535,
8,
470,
12,
283,
2499,
18033,
358,
267,
291,
14,
9535,
8,
470,
12,
283,
4685,
358,
267,
291,
14,
9535,
8,
470,
12,
283,
5392,
18033,
358,
398,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
8050,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
291,
14,
8050,
14,
513,
1012,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
513,
297,
4318,
283,
19143,
63,
2425,
63,
3773,
63,
3756,
297,
776,
1552,
272,
347,
511,
63,
1080,
63,
1045,
63,
19143,
63,
2425,
63,
3773,
63,
3756,
63,
3910,
8,
277,
304,
267,
2986,
14,
19143,
14,
3756,
63,
513,
8,
19288,
8801,
8572,
8,
277,
14,
8050,
14,
513,
1012,
267,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
3756,
342,
971,
288,
1275,
8433,
17687,
1252,
8572,
8,
797,
9,
267,
291,
14,
6625,
14,
12982,
342,
398,
522,
275,
291,
14,
1258,
14,
362,
8,
6245,
654,
63,
10215,
63,
2632,
9,
398,
291,
14,
23218,
8,
470,
12,
283,
2499,
18033,
358,
267,
291,
14,
23218,
8,
470,
12,
283,
4685,
358,
267,
291,
14,
23218,
8,
470,
12,
283,
5392,
18033,
358,
398,
291,
14,
19661,
8,
470,
12,
283,
2113,
15,
8050,
15,
1080,
14,
1360,
358,
267,
291,
14,
19673,
8,
470,
14,
1100,
459,
1224,
2278,
576,
12,
291,
14,
8050,
14,
513,
1012,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
981,
297,
776,
1552,
272,
347,
511,
63,
981,
8,
277,
304,
267,
4719,
275,
291,
14,
8050,
14,
2246,
342,
398,
2986,
14,
19143,
14,
3756,
63,
981,
8,
19288,
1062,
4719,
14,
354,
680,
8572,
8,
3756,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1824,
1451,
275,
791,
765,
356,
283,
2499,
7422,
2821,
297,
283,
354,
356,
4719,
14,
354,
93,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
6245,
654,
63,
8366,
63,
2632,
12,
1824,
1451,
9,
398,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
291,
14,
479,
2209,
2353,
8,
3742,
29,
17,
9,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
362,
297,
283,
3756,
63,
873,
22220,
272,
347,
511,
63,
873,
8,
277,
304,
267,
4719,
275,
291,
14,
8050,
14,
2246,
342,
267,
892,
63,
3756,
63,
354,
275,
283,
396,
63,
354,
7,
398,
2986,
14,
19143,
14,
3756,
63,
362,
8,
14104,
8,
1014,
14,
10441,
395,
4719,
14,
344,
680,
8572,
8,
3756,
9,
267,
2986,
14,
19143,
14,
3756,
63,
873,
8,
14104,
8,
1014,
14,
10441,
395,
639,
4719,
14,
344,
12,
639,
892,
63,
3756,
63,
354,
680,
8572,
8,
403,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1824,
1451,
275,
791,
765,
356,
283,
4152,
7422,
2821,
297,
490,
283,
344,
356,
4719,
14,
344,
12,
490,
283,
354,
356,
892,
63,
3756,
63,
354,
93,
398,
522,
275,
291,
14,
1258,
14,
1932,
8,
6245,
654,
63,
10383,
63,
2632,
12,
1824,
1451,
9,
398,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
291,
14,
479,
2209,
2353,
8,
3742,
29,
17,
9,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
19143,
26,
661,
3756,
63,
513,
297,
283,
3756,
63,
1807,
22220,
272,
347,
511,
63,
1807,
8,
277,
304,
267,
4719,
275,
291,
14,
8050,
14,
2246,
342,
398,
2986,
14,
19143,
14,
3756,
63,
513,
8,
14104,
8,
1014,
14,
10441,
430,
971,
1169,
1275,
8572,
8,
277,
14,
8050,
14,
513,
1012,
267,
2986,
14,
19143,
14,
3756,
63,
1807,
8,
14104,
8,
1014,
14,
10441,
395,
639,
4719,
14,
344,
680,
8572,
8,
403,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1824,
1451,
275,
791,
1287,
356,
283,
8050,
363,
1807,
363,
5,
83,
7,
450,
4719,
14,
344,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Didacti/botornado
|
boto/ec2/autoscale/activity.py
|
57
|
3059
|
# Copyright (c) 2009-2011 Reza Lotun http://reza.lotun.name/
#
# 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.
from datetime import datetime
class Activity(object):
def __init__(self, connection=None):
self.connection = connection
self.start_time = None
self.end_time = None
self.activity_id = None
self.progress = None
self.status_code = None
self.cause = None
self.description = None
self.status_message = None
self.group_name = None
def __repr__(self):
return 'Activity<%s>: For group:%s, progress:%s, cause:%s' % (self.activity_id,
self.group_name,
self.status_message,
self.cause)
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
if name == 'ActivityId':
self.activity_id = value
elif name == 'AutoScalingGroupName':
self.group_name = value
elif name == 'StartTime':
try:
self.start_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%fZ')
except ValueError:
self.start_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
elif name == 'EndTime':
try:
self.end_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%fZ')
except ValueError:
self.end_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
elif name == 'Progress':
self.progress = value
elif name == 'Cause':
self.cause = value
elif name == 'Description':
self.description = value
elif name == 'StatusMessage':
self.status_message = value
elif name == 'StatusCode':
self.status_code = value
else:
setattr(self, name, value)
|
mit
|
[
3,
1898,
334,
67,
9,
8937,
13,
8128,
799,
8076,
491,
357,
324,
1455,
921,
264,
8076,
14,
1653,
324,
14,
354,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
504,
2197,
492,
2197,
421,
199,
533,
21885,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
928,
63,
521,
275,
488,
267,
291,
14,
500,
63,
521,
275,
488,
267,
291,
14,
8240,
63,
344,
275,
488,
267,
291,
14,
5734,
275,
488,
267,
291,
14,
1205,
63,
600,
275,
488,
267,
291,
14,
2651,
275,
488,
267,
291,
14,
1802,
275,
488,
267,
291,
14,
1205,
63,
1188,
275,
488,
267,
291,
14,
923,
63,
354,
275,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
14350,
21110,
83,
20020,
2104,
1572,
2689,
83,
12,
6696,
2689,
83,
12,
7675,
2689,
83,
7,
450,
334,
277,
14,
8240,
63,
344,
12,
6684,
420,
291,
14,
923,
63,
354,
12,
6684,
420,
291,
14,
1205,
63,
1188,
12,
6684,
420,
291,
14,
2651,
9,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
14350,
1304,
356,
288,
291,
14,
8240,
63,
344,
275,
574,
267,
916,
536,
508,
283,
3358,
26416,
14405,
356,
288,
291,
14,
923,
63,
354,
275,
574,
267,
916,
536,
508,
283,
25087,
356,
288,
862,
26,
355,
291,
14,
928,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
58,
358,
288,
871,
1722,
26,
355,
291,
14,
928,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
358,
267,
916,
536,
508,
283,
3005,
1366,
356,
288,
862,
26,
355,
291,
14,
500,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
58,
358,
288,
871,
1722,
26,
355,
291,
14,
500,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
358,
267,
916,
536,
508,
283,
11504,
356,
288,
291,
14,
5734,
275,
574,
267,
916,
536,
508,
283,
3630,
1180,
356,
288,
291,
14,
2651,
275,
574,
267,
916,
536,
508,
283,
5831,
356,
288,
291,
14,
1802,
275,
574,
267,
916,
536,
508,
283,
3694,
2209,
356,
288,
291,
14,
1205,
63,
1188,
275,
574,
267,
916,
536,
508,
283,
23018,
356,
288,
291,
14,
1205,
63,
600,
275,
574,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8937,
13,
8128,
799,
8076,
491,
357,
324,
1455,
921,
264,
8076,
14,
1653,
324,
14,
354,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
504,
2197,
492,
2197,
421,
199,
533,
21885,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
928,
63,
521,
275,
488,
267,
291,
14,
500,
63,
521,
275,
488,
267,
291,
14,
8240,
63,
344,
275,
488,
267,
291,
14,
5734,
275,
488,
267,
291,
14,
1205,
63,
600,
275,
488,
267,
291,
14,
2651,
275,
488,
267,
291,
14,
1802,
275,
488,
267,
291,
14,
1205,
63,
1188,
275,
488,
267,
291,
14,
923,
63,
354,
275,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
14350,
21110,
83,
20020,
2104,
1572,
2689,
83,
12,
6696,
2689,
83,
12,
7675,
2689,
83,
7,
450,
334,
277,
14,
8240,
63,
344,
12,
6684,
420,
291,
14,
923,
63,
354,
12,
6684,
420,
291,
14,
1205,
63,
1188,
12,
6684,
420,
291,
14,
2651,
9,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
14350,
1304,
356,
288,
291,
14,
8240,
63,
344,
275,
574,
267,
916,
536,
508,
283,
3358,
26416,
14405,
356,
288,
291,
14,
923,
63,
354,
275,
574,
267,
916,
536,
508,
283,
25087,
356,
288,
862,
26,
355,
291,
14,
928,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
58,
358,
288,
871,
1722,
26,
355,
291,
14,
928,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
358,
267,
916,
536,
508,
283,
3005,
1366,
356,
288,
862,
26,
355,
291,
14,
500,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
58,
358,
288,
871,
1722,
26,
355,
291,
14,
500,
63,
521,
275,
2197,
14,
9866,
8,
585,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
358,
267,
916,
536,
508,
283,
11504,
356,
288,
291,
14,
5734,
275,
574,
267,
916,
536,
508,
283,
3630,
1180,
356,
288,
291,
14,
2651,
275,
574,
267,
916,
536,
508,
283,
5831,
356,
288,
291,
14,
1802,
275,
574,
267,
916,
536,
508,
283,
3694,
2209,
356,
288,
291,
14,
1205,
63,
1188,
275,
574,
267,
916,
536,
508,
283,
23018,
356,
288,
291,
14,
1205,
63,
600,
275,
574,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
posquit0/dotfiles
|
vim/.vim/ycm_extra_conf.py
|
1
|
6657
|
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS 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.
#
# For more information, please refer to <http://unlicense.org/>
import os
import ycm_core
# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
#'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-isystem',
'../BoostParts',
'-isystem',
# This path will only work on OS X, but extra paths that don't exist are not
# harmful
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'./ClangCompleter',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/include',
'-isystem',
'/usr/include',
'-isystem',
'/usr/local/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include',
]
# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break
if new_flag:
new_flags.append( new_flag )
return new_flags
def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
def GetCompilationInfoForFile( filename ):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
compilation_info = database.GetCompilationInfoForFile(
replacement_file )
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )
def FlagsForFile( filename, **kwargs ):
if database:
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None
final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
try:
final_flags.remove( '-stdlib=libc++' )
except ValueError:
pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
|
mit
|
[
3,
961,
570,
365,
2845,
18233,
1334,
314,
14629,
86,
19,
12,
1314,
365,
314,
4190,
367,
314,
4618,
199,
3,
402,
2047,
14175,
1352,
14,
199,
3,
199,
3,
11842,
1159,
314,
4190,
1318,
367,
642,
570,
26,
199,
3,
199,
3,
961,
365,
2867,
436,
625,
10945,
453,
18897,
2032,
14286,
1901,
314,
4575,
2881,
14,
199,
3,
199,
3,
6184,
368,
365,
2867,
370,
1331,
12,
2811,
12,
2780,
12,
675,
12,
6555,
12,
12743,
12,
503,
199,
3,
11207,
642,
2032,
12,
1902,
315,
1350,
1233,
1824,
503,
465,
282,
10311,
199,
3,
3366,
12,
367,
1263,
12016,
12,
2414,
23012,
503,
2222,
13,
957,
23012,
12,
436,
701,
1263,
199,
3,
4910,
14,
199,
3,
199,
3,
1010,
1335,
17656,
328,
2452,
626,
27159,
4248,
1127,
3569,
12,
314,
4132,
503,
11462,
199,
3,
402,
642,
2032,
477,
10188,
1263,
436,
1006,
4248,
13518,
315,
314,
199,
3,
2032,
370,
314,
4575,
2881,
14,
2136,
1852,
642,
477,
21171,
367,
314,
22477,
3269,
199,
3,
402,
314,
4575,
737,
7031,
436,
370,
314,
477,
599,
434,
402,
4154,
946,
32030,
436,
199,
3,
3182,
1384,
14,
2136,
315,
7169,
642,
477,
21171,
370,
506,
376,
1806,
84,
2454,
402,
199,
3,
295,
472,
392,
2453,
434,
315,
1126,
8096,
24180,
402,
1006,
3451,
436,
6466,
4481,
370,
642,
199,
3,
2032,
1334,
4248,
4179,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
10610,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
199,
3,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
199,
3,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
199,
3,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
3,
2104,
1655,
2556,
12,
8749,
10618,
370,
665,
1014,
921,
324,
1682,
14,
1308,
3133,
199,
199,
646,
747,
199,
646,
612,
4400,
63,
1018,
199,
199,
3,
5723,
787,
314,
18653,
3285,
626,
911,
506,
1202,
315,
1930,
2337,
1159,
949,
199,
3,
18653,
3050,
663,
334,
991,
849,
12,
1373,
365,
440,
663,
680,
199,
3,
6624,
9011,
5749,
21716,
1634,
12846,
14,
1488,
654,
12,
5749,
2281,
2334,
577,
22045,
1488,
22050,
25227,
6262,
742,
3412,
3593,
1206,
2381,
14,
199,
2469,
275,
359,
199,
12418,
18018,
297,
199,
12418,
55,
2911,
297,
199,
12418,
55,
705,
297,
199,
3,
12418,
55,
67,
4176,
2905,
13,
5819,
297,
199,
12418,
55,
889,
13,
2809,
13,
2809,
297,
199,
12418,
55,
889,
13,
3808,
31764,
13,
16358,
297,
199,
12418,
70,
3924,
297,
199,
12418,
10872,
5287,
297,
199,
3,
2047,
2948,
5,
886,
2845,
1929,
446,
36,
4701,
63,
1981,
3986,
63,
12558,
775,
540,
315,
2195,
3285,
27,
1454,
314,
1488,
9249,
199,
3,
1350,
1233,
4839,
652,
14,
199,
12418,
36,
4701,
63,
1981,
3986,
63,
12558,
775,
540,
297,
199,
3,
5749,
2281,
5025,
2596,
1441,
1,
23952,
282,
3905,
1516,
18987,
10297,
4335,
3305,
12,
25444,
7859,
1133,
5715,
1314,
199,
3,
2637,
370,
675,
1380,
1013,
5662,
2323,
14,
2002,
652,
911,
9519,
14,
8857,
590,
14,
2002,
445,
4176,
199,
3,
2323,
911,
506,
10311,
465,
445,
2323,
14,
2047,
2793,
1133,
2934,
626,
880,
12112,
26194,
4165,
199,
3,
282,
3905,
1516,
18987,
10297,
23167,
199,
3,
2104,
282,
445,
2199,
12,
1265,
3955,
663,
642,
370,
6020,
2839,
283,
67,
1020,
7,
3140,
402,
199,
3,
283,
67,
4176,
845,
1370,
199,
12418,
1516,
29,
67,
4176,
845,
297,
199,
3,
2263,
460,
314,
2011,
8377,
13538,
367,
314,
10628,
446,
88,
945,
1314,
9314,
314,
199,
3,
2637,
626,
314,
1584,
370,
506,
10311,
787,
5313,
315,
14,
961,
365,
19762,
199,
3,
12082,
367,
286,
4176,
2323,
14,
199,
3,
2104,
282,
445,
2199,
12,
1265,
3955,
663,
642,
370,
283,
67,
7,
3140,
402,
283,
67,
4176,
1370,
199,
12418,
88,
297,
199,
7,
67,
31249,
199,
12418,
374,
3045,
297,
199,
7,
5093,
18814,
28662,
297,
199,
12418,
374,
3045,
297,
199,
3,
961,
931,
911,
1454,
1736,
641,
4403,
1323,
12,
1325,
2402,
3792,
626,
2793,
1133,
2187,
787,
440,
199,
3,
394,
5362,
1893,
199,
9807,
3989,
15,
7424,
15,
30052,
15,
4718,
14,
4857,
15,
9883,
297,
199,
12418,
374,
3045,
297,
199,
7,
5093,
29257,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
7,
5093,
29257,
15,
2537,
15,
16066,
15,
2613,
297,
199,
12418,
41,
297,
199,
1370,
297,
199,
12418,
41,
297,
199,
1370,
15,
1968,
621,
6600,
351,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
15,
8385,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
15,
8385,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
9807,
2647,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
9807,
2647,
15,
1832,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
9807,
31907,
15,
18442,
14,
571,
15,
11383,
15,
31032,
15,
5157,
17419,
15,
18442,
2698,
14,
88,
319,
21943,
4429,
15,
2647,
15,
1393,
15,
5093,
2613,
15,
67,
4176,
15,
86,
17,
297,
199,
12418,
374,
3045,
297,
199,
9807,
31907,
15,
18442,
14,
571,
15,
11383,
15,
31032,
15,
5157,
17419,
15,
18442,
2698,
14,
88,
319,
21943,
4429,
15,
2647,
15,
2613,
297,
199,
61,
421,
199,
3,
2494,
642,
370,
314,
3679,
931,
370,
314,
4922,
334,
4609,
314,
570,
21866,
3035,
314,
199,
3,
6555,
63,
4405,
14,
1001,
570,
370,
675,
626,
3140,
402,
283,
2469,
1370,
1666,
2348,
367,
199,
3,
1655,
2436,
26,
1455,
921,
16066,
14,
29257,
14,
1308,
15,
4757,
15,
6243,
2404,
13696,
7243,
14,
1360,
199,
3,
199,
3,
2047,
883,
664,
21355,
370
] |
[
961,
570,
365,
2845,
18233,
1334,
314,
14629,
86,
19,
12,
1314,
365,
314,
4190,
367,
314,
4618,
199,
3,
402,
2047,
14175,
1352,
14,
199,
3,
199,
3,
11842,
1159,
314,
4190,
1318,
367,
642,
570,
26,
199,
3,
199,
3,
961,
365,
2867,
436,
625,
10945,
453,
18897,
2032,
14286,
1901,
314,
4575,
2881,
14,
199,
3,
199,
3,
6184,
368,
365,
2867,
370,
1331,
12,
2811,
12,
2780,
12,
675,
12,
6555,
12,
12743,
12,
503,
199,
3,
11207,
642,
2032,
12,
1902,
315,
1350,
1233,
1824,
503,
465,
282,
10311,
199,
3,
3366,
12,
367,
1263,
12016,
12,
2414,
23012,
503,
2222,
13,
957,
23012,
12,
436,
701,
1263,
199,
3,
4910,
14,
199,
3,
199,
3,
1010,
1335,
17656,
328,
2452,
626,
27159,
4248,
1127,
3569,
12,
314,
4132,
503,
11462,
199,
3,
402,
642,
2032,
477,
10188,
1263,
436,
1006,
4248,
13518,
315,
314,
199,
3,
2032,
370,
314,
4575,
2881,
14,
2136,
1852,
642,
477,
21171,
367,
314,
22477,
3269,
199,
3,
402,
314,
4575,
737,
7031,
436,
370,
314,
477,
599,
434,
402,
4154,
946,
32030,
436,
199,
3,
3182,
1384,
14,
2136,
315,
7169,
642,
477,
21171,
370,
506,
376,
1806,
84,
2454,
402,
199,
3,
295,
472,
392,
2453,
434,
315,
1126,
8096,
24180,
402,
1006,
3451,
436,
6466,
4481,
370,
642,
199,
3,
2032,
1334,
4248,
4179,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
10610,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
199,
3,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
199,
3,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
199,
3,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
3,
2104,
1655,
2556,
12,
8749,
10618,
370,
665,
1014,
921,
324,
1682,
14,
1308,
3133,
199,
199,
646,
747,
199,
646,
612,
4400,
63,
1018,
199,
199,
3,
5723,
787,
314,
18653,
3285,
626,
911,
506,
1202,
315,
1930,
2337,
1159,
949,
199,
3,
18653,
3050,
663,
334,
991,
849,
12,
1373,
365,
440,
663,
680,
199,
3,
6624,
9011,
5749,
21716,
1634,
12846,
14,
1488,
654,
12,
5749,
2281,
2334,
577,
22045,
1488,
22050,
25227,
6262,
742,
3412,
3593,
1206,
2381,
14,
199,
2469,
275,
359,
199,
12418,
18018,
297,
199,
12418,
55,
2911,
297,
199,
12418,
55,
705,
297,
199,
3,
12418,
55,
67,
4176,
2905,
13,
5819,
297,
199,
12418,
55,
889,
13,
2809,
13,
2809,
297,
199,
12418,
55,
889,
13,
3808,
31764,
13,
16358,
297,
199,
12418,
70,
3924,
297,
199,
12418,
10872,
5287,
297,
199,
3,
2047,
2948,
5,
886,
2845,
1929,
446,
36,
4701,
63,
1981,
3986,
63,
12558,
775,
540,
315,
2195,
3285,
27,
1454,
314,
1488,
9249,
199,
3,
1350,
1233,
4839,
652,
14,
199,
12418,
36,
4701,
63,
1981,
3986,
63,
12558,
775,
540,
297,
199,
3,
5749,
2281,
5025,
2596,
1441,
1,
23952,
282,
3905,
1516,
18987,
10297,
4335,
3305,
12,
25444,
7859,
1133,
5715,
1314,
199,
3,
2637,
370,
675,
1380,
1013,
5662,
2323,
14,
2002,
652,
911,
9519,
14,
8857,
590,
14,
2002,
445,
4176,
199,
3,
2323,
911,
506,
10311,
465,
445,
2323,
14,
2047,
2793,
1133,
2934,
626,
880,
12112,
26194,
4165,
199,
3,
282,
3905,
1516,
18987,
10297,
23167,
199,
3,
2104,
282,
445,
2199,
12,
1265,
3955,
663,
642,
370,
6020,
2839,
283,
67,
1020,
7,
3140,
402,
199,
3,
283,
67,
4176,
845,
1370,
199,
12418,
1516,
29,
67,
4176,
845,
297,
199,
3,
2263,
460,
314,
2011,
8377,
13538,
367,
314,
10628,
446,
88,
945,
1314,
9314,
314,
199,
3,
2637,
626,
314,
1584,
370,
506,
10311,
787,
5313,
315,
14,
961,
365,
19762,
199,
3,
12082,
367,
286,
4176,
2323,
14,
199,
3,
2104,
282,
445,
2199,
12,
1265,
3955,
663,
642,
370,
283,
67,
7,
3140,
402,
283,
67,
4176,
1370,
199,
12418,
88,
297,
199,
7,
67,
31249,
199,
12418,
374,
3045,
297,
199,
7,
5093,
18814,
28662,
297,
199,
12418,
374,
3045,
297,
199,
3,
961,
931,
911,
1454,
1736,
641,
4403,
1323,
12,
1325,
2402,
3792,
626,
2793,
1133,
2187,
787,
440,
199,
3,
394,
5362,
1893,
199,
9807,
3989,
15,
7424,
15,
30052,
15,
4718,
14,
4857,
15,
9883,
297,
199,
12418,
374,
3045,
297,
199,
7,
5093,
29257,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
7,
5093,
29257,
15,
2537,
15,
16066,
15,
2613,
297,
199,
12418,
41,
297,
199,
1370,
297,
199,
12418,
41,
297,
199,
1370,
15,
1968,
621,
6600,
351,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
15,
8385,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
15,
8385,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
297,
199,
12418,
374,
3045,
297,
199,
1370,
15,
2219,
15,
71,
1805,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
9807,
2647,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
9807,
2647,
15,
1832,
15,
2613,
297,
199,
12418,
374,
3045,
297,
199,
9807,
31907,
15,
18442,
14,
571,
15,
11383,
15,
31032,
15,
5157,
17419,
15,
18442,
2698,
14,
88,
319,
21943,
4429,
15,
2647,
15,
1393,
15,
5093,
2613,
15,
67,
4176,
15,
86,
17,
297,
199,
12418,
374,
3045,
297,
199,
9807,
31907,
15,
18442,
14,
571,
15,
11383,
15,
31032,
15,
5157,
17419,
15,
18442,
2698,
14,
88,
319,
21943,
4429,
15,
2647,
15,
2613,
297,
199,
61,
421,
199,
3,
2494,
642,
370,
314,
3679,
931,
370,
314,
4922,
334,
4609,
314,
570,
21866,
3035,
314,
199,
3,
6555,
63,
4405,
14,
1001,
570,
370,
675,
626,
3140,
402,
283,
2469,
1370,
1666,
2348,
367,
199,
3,
1655,
2436,
26,
1455,
921,
16066,
14,
29257,
14,
1308,
15,
4757,
15,
6243,
2404,
13696,
7243,
14,
1360,
199,
3,
199,
3,
2047,
883,
664,
21355,
370,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
liamgh/liamgreenhughes-sl4a-tf101
|
python-build/python-libs/gdata/src/gdata/tlslite/utils/Cryptlib_AES.py
|
359
|
1364
|
"""Cryptlib AES implementation."""
from cryptomath import *
from AES import *
if cryptlibpyLoaded:
def new(key, mode, IV):
return Cryptlib_AES(key, mode, IV)
class Cryptlib_AES(AES):
def __init__(self, key, mode, IV):
AES.__init__(self, key, mode, IV, "cryptlib")
self.context = cryptlib_py.cryptCreateContext(cryptlib_py.CRYPT_UNUSED, cryptlib_py.CRYPT_ALGO_AES)
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_MODE, cryptlib_py.CRYPT_MODE_CBC)
cryptlib_py.cryptSetAttribute(self.context, cryptlib_py.CRYPT_CTXINFO_KEYSIZE, len(key))
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_KEY, key)
cryptlib_py.cryptSetAttributeString(self.context, cryptlib_py.CRYPT_CTXINFO_IV, IV)
def __del__(self):
cryptlib_py.cryptDestroyContext(self.context)
def encrypt(self, plaintext):
AES.encrypt(self, plaintext)
bytes = stringToBytes(plaintext)
cryptlib_py.cryptEncrypt(self.context, bytes)
return bytesToString(bytes)
def decrypt(self, ciphertext):
AES.decrypt(self, ciphertext)
bytes = stringToBytes(ciphertext)
cryptlib_py.cryptDecrypt(self.context, bytes)
return bytesToString(bytes)
|
apache-2.0
|
[
624,
35,
13656,
773,
19093,
4514,
1041,
199,
199,
504,
13230,
3442,
492,
627,
199,
504,
19093,
492,
627,
199,
199,
692,
21570,
773,
647,
19757,
26,
339,
347,
892,
8,
498,
12,
818,
12,
27892,
304,
267,
372,
445,
13656,
773,
63,
14494,
8,
498,
12,
818,
12,
27892,
9,
339,
1021,
445,
13656,
773,
63,
14494,
8,
14494,
304,
398,
347,
636,
826,
721,
277,
12,
790,
12,
818,
12,
27892,
304,
288,
19093,
855,
826,
721,
277,
12,
790,
12,
818,
12,
27892,
12,
298,
4997,
773,
531,
288,
291,
14,
1100,
275,
21570,
773,
63,
647,
14,
4997,
2499,
2998,
8,
4997,
773,
63,
647,
14,
19079,
63,
53,
27726,
12,
21570,
773,
63,
647,
14,
19079,
63,
748,
13160,
63,
14494,
9,
288,
21570,
773,
63,
647,
14,
4997,
24131,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
6963,
12,
21570,
773,
63,
647,
14,
19079,
63,
6963,
63,
18255,
9,
288,
21570,
773,
63,
647,
14,
4997,
24131,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
3078,
4305,
12,
822,
8,
498,
430,
288,
21570,
773,
63,
647,
14,
4997,
24131,
1558,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
3078,
12,
790,
9,
288,
21570,
773,
63,
647,
14,
4997,
24131,
1558,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
6882,
12,
27892,
9,
398,
347,
636,
2264,
721,
277,
304,
1467,
21570,
773,
63,
647,
14,
4997,
14704,
2998,
8,
277,
14,
1100,
9,
398,
347,
14645,
8,
277,
12,
18577,
304,
288,
19093,
14,
11929,
8,
277,
12,
18577,
9,
288,
2783,
275,
1059,
1378,
5571,
8,
17426,
9,
288,
21570,
773,
63,
647,
14,
4997,
1327,
4997,
8,
277,
14,
1100,
12,
2783,
9,
288,
372,
2783,
7756,
8,
2394,
9,
398,
347,
20090,
8,
277,
12,
29147,
304,
288,
19093,
14,
15682,
8,
277,
12,
29147,
9,
288,
2783,
275,
1059,
1378,
5571,
8,
27661,
9,
288,
21570,
773,
63,
647,
14,
4997,
8584,
13656,
8,
277,
14,
1100,
12,
2783,
9,
288,
372,
2783,
7756,
8,
2394,
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
] |
[
35,
13656,
773,
19093,
4514,
1041,
199,
199,
504,
13230,
3442,
492,
627,
199,
504,
19093,
492,
627,
199,
199,
692,
21570,
773,
647,
19757,
26,
339,
347,
892,
8,
498,
12,
818,
12,
27892,
304,
267,
372,
445,
13656,
773,
63,
14494,
8,
498,
12,
818,
12,
27892,
9,
339,
1021,
445,
13656,
773,
63,
14494,
8,
14494,
304,
398,
347,
636,
826,
721,
277,
12,
790,
12,
818,
12,
27892,
304,
288,
19093,
855,
826,
721,
277,
12,
790,
12,
818,
12,
27892,
12,
298,
4997,
773,
531,
288,
291,
14,
1100,
275,
21570,
773,
63,
647,
14,
4997,
2499,
2998,
8,
4997,
773,
63,
647,
14,
19079,
63,
53,
27726,
12,
21570,
773,
63,
647,
14,
19079,
63,
748,
13160,
63,
14494,
9,
288,
21570,
773,
63,
647,
14,
4997,
24131,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
6963,
12,
21570,
773,
63,
647,
14,
19079,
63,
6963,
63,
18255,
9,
288,
21570,
773,
63,
647,
14,
4997,
24131,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
3078,
4305,
12,
822,
8,
498,
430,
288,
21570,
773,
63,
647,
14,
4997,
24131,
1558,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
3078,
12,
790,
9,
288,
21570,
773,
63,
647,
14,
4997,
24131,
1558,
8,
277,
14,
1100,
12,
21570,
773,
63,
647,
14,
19079,
63,
21524,
4531,
63,
6882,
12,
27892,
9,
398,
347,
636,
2264,
721,
277,
304,
1467,
21570,
773,
63,
647,
14,
4997,
14704,
2998,
8,
277,
14,
1100,
9,
398,
347,
14645,
8,
277,
12,
18577,
304,
288,
19093,
14,
11929,
8,
277,
12,
18577,
9,
288,
2783,
275,
1059,
1378,
5571,
8,
17426,
9,
288,
21570,
773,
63,
647,
14,
4997,
1327,
4997,
8,
277,
14,
1100,
12,
2783,
9,
288,
372,
2783,
7756,
8,
2394,
9,
398,
347,
20090,
8,
277,
12,
29147,
304,
288,
19093,
14,
15682,
8,
277,
12,
29147,
9,
288,
2783,
275,
1059,
1378,
5571,
8,
27661,
9,
288,
21570,
773,
63,
647,
14,
4997,
8584,
13656,
8,
277,
14,
1100,
12,
2783,
9,
288,
372,
2783,
7756,
8,
2394,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrquim/mrquimrepo
|
repo/script.module.youtube.dl/lib/youtube_dl/downloader/__init__.py
|
59
|
1576
|
from __future__ import unicode_literals
from .common import FileDownloader
from .f4m import F4mFD
from .hls import HlsFD
from .http import HttpFD
from .rtmp import RtmpFD
from .dash import DashSegmentsFD
from .rtsp import RtspFD
from .ism import IsmFD
from .external import (
get_external_downloader,
FFmpegFD,
)
from ..utils import (
determine_protocol,
)
PROTOCOL_MAP = {
'rtmp': RtmpFD,
'm3u8_native': HlsFD,
'm3u8': FFmpegFD,
'mms': RtspFD,
'rtsp': RtspFD,
'f4m': F4mFD,
'http_dash_segments': DashSegmentsFD,
'ism': IsmFD,
}
def get_suitable_downloader(info_dict, params={}):
"""Get the downloader class that can handle the info dict."""
protocol = determine_protocol(info_dict)
info_dict['protocol'] = protocol
# if (info_dict.get('start_time') or info_dict.get('end_time')) and not info_dict.get('requested_formats') and FFmpegFD.can_download(info_dict):
# return FFmpegFD
external_downloader = params.get('external_downloader')
if external_downloader is not None:
ed = get_external_downloader(external_downloader)
if ed.can_download(info_dict):
return ed
if protocol.startswith('m3u8') and info_dict.get('is_live'):
return FFmpegFD
if protocol == 'm3u8' and params.get('hls_prefer_native') is True:
return HlsFD
if protocol == 'm3u8_native' and params.get('hls_prefer_native') is False:
return FFmpegFD
return PROTOCOL_MAP.get(protocol, HttpFD)
__all__ = [
'get_suitable_downloader',
'FileDownloader',
]
|
gpl-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
3814,
3514,
3422,
199,
504,
1275,
70,
20,
77,
492,
481,
20,
77,
7902,
199,
504,
1275,
30252,
492,
869,
478,
7902,
199,
504,
1275,
1014,
492,
4760,
7902,
199,
504,
1275,
29649,
492,
820,
2791,
7902,
199,
504,
1275,
6760,
492,
577,
1119,
23287,
7902,
199,
504,
1275,
2591,
681,
492,
820,
84,
681,
7902,
199,
504,
1275,
19185,
492,
473,
3300,
7902,
199,
504,
1275,
5159,
492,
334,
272,
664,
63,
5159,
63,
22846,
12,
272,
25046,
16801,
7902,
12,
199,
9,
199,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
3922,
12,
199,
9,
199,
199,
9583,
63,
5443,
275,
469,
272,
283,
29649,
356,
820,
2791,
7902,
12,
272,
283,
77,
19,
85,
24,
63,
6106,
356,
869,
478,
7902,
12,
272,
283,
77,
19,
85,
24,
356,
25046,
16801,
7902,
12,
272,
283,
596,
83,
356,
820,
84,
681,
7902,
12,
272,
283,
2591,
681,
356,
820,
84,
681,
7902,
12,
272,
283,
70,
20,
77,
356,
481,
20,
77,
7902,
12,
272,
283,
1014,
63,
6760,
63,
13879,
356,
577,
1119,
23287,
7902,
12,
272,
283,
19185,
356,
473,
3300,
7902,
12,
199,
93,
421,
199,
318,
664,
63,
83,
10020,
63,
22846,
8,
815,
63,
807,
12,
1862,
16420,
272,
408,
1002,
314,
3224,
3422,
1021,
626,
883,
2429,
314,
2256,
1211,
1041,
272,
4113,
275,
6705,
63,
3922,
8,
815,
63,
807,
9,
272,
2256,
63,
807,
459,
3922,
418,
275,
4113,
339,
327,
340,
334,
815,
63,
807,
14,
362,
360,
928,
63,
521,
358,
503,
2256,
63,
807,
14,
362,
360,
500,
63,
521,
1333,
436,
440,
2256,
63,
807,
14,
362,
360,
11151,
63,
6321,
358,
436,
25046,
16801,
7902,
14,
2425,
63,
4249,
8,
815,
63,
807,
304,
272,
327,
258,
372,
25046,
16801,
7902,
339,
5957,
63,
22846,
275,
1862,
14,
362,
360,
5159,
63,
22846,
358,
272,
340,
5957,
63,
22846,
365,
440,
488,
26,
267,
3988,
275,
664,
63,
5159,
63,
22846,
8,
5159,
63,
22846,
9,
267,
340,
3988,
14,
2425,
63,
4249,
8,
815,
63,
807,
304,
288,
372,
3988,
339,
340,
4113,
14,
2460,
360,
77,
19,
85,
24,
358,
436,
2256,
63,
807,
14,
362,
360,
374,
63,
6442,
735,
267,
372,
25046,
16801,
7902,
339,
340,
4113,
508,
283,
77,
19,
85,
24,
7,
436,
1862,
14,
362,
360,
30252,
63,
24283,
63,
6106,
358,
365,
715,
26,
267,
372,
869,
478,
7902,
339,
340,
4113,
508,
283,
77,
19,
85,
24,
63,
6106,
7,
436,
1862,
14,
362,
360,
30252,
63,
24283,
63,
6106,
358,
365,
756,
26,
267,
372,
25046,
16801,
7902,
339,
372,
3611,
2566,
3978,
63,
5443,
14,
362,
8,
3922,
12,
4760,
7902,
9,
421,
199,
363,
452,
363,
275,
359,
272,
283,
362,
63,
83,
10020,
63,
22846,
297,
272,
283,
1173,
3514,
3422,
297,
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
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
3814,
3514,
3422,
199,
504,
1275,
70,
20,
77,
492,
481,
20,
77,
7902,
199,
504,
1275,
30252,
492,
869,
478,
7902,
199,
504,
1275,
1014,
492,
4760,
7902,
199,
504,
1275,
29649,
492,
820,
2791,
7902,
199,
504,
1275,
6760,
492,
577,
1119,
23287,
7902,
199,
504,
1275,
2591,
681,
492,
820,
84,
681,
7902,
199,
504,
1275,
19185,
492,
473,
3300,
7902,
199,
504,
1275,
5159,
492,
334,
272,
664,
63,
5159,
63,
22846,
12,
272,
25046,
16801,
7902,
12,
199,
9,
199,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
3922,
12,
199,
9,
199,
199,
9583,
63,
5443,
275,
469,
272,
283,
29649,
356,
820,
2791,
7902,
12,
272,
283,
77,
19,
85,
24,
63,
6106,
356,
869,
478,
7902,
12,
272,
283,
77,
19,
85,
24,
356,
25046,
16801,
7902,
12,
272,
283,
596,
83,
356,
820,
84,
681,
7902,
12,
272,
283,
2591,
681,
356,
820,
84,
681,
7902,
12,
272,
283,
70,
20,
77,
356,
481,
20,
77,
7902,
12,
272,
283,
1014,
63,
6760,
63,
13879,
356,
577,
1119,
23287,
7902,
12,
272,
283,
19185,
356,
473,
3300,
7902,
12,
199,
93,
421,
199,
318,
664,
63,
83,
10020,
63,
22846,
8,
815,
63,
807,
12,
1862,
16420,
272,
408,
1002,
314,
3224,
3422,
1021,
626,
883,
2429,
314,
2256,
1211,
1041,
272,
4113,
275,
6705,
63,
3922,
8,
815,
63,
807,
9,
272,
2256,
63,
807,
459,
3922,
418,
275,
4113,
339,
327,
340,
334,
815,
63,
807,
14,
362,
360,
928,
63,
521,
358,
503,
2256,
63,
807,
14,
362,
360,
500,
63,
521,
1333,
436,
440,
2256,
63,
807,
14,
362,
360,
11151,
63,
6321,
358,
436,
25046,
16801,
7902,
14,
2425,
63,
4249,
8,
815,
63,
807,
304,
272,
327,
258,
372,
25046,
16801,
7902,
339,
5957,
63,
22846,
275,
1862,
14,
362,
360,
5159,
63,
22846,
358,
272,
340,
5957,
63,
22846,
365,
440,
488,
26,
267,
3988,
275,
664,
63,
5159,
63,
22846,
8,
5159,
63,
22846,
9,
267,
340,
3988,
14,
2425,
63,
4249,
8,
815,
63,
807,
304,
288,
372,
3988,
339,
340,
4113,
14,
2460,
360,
77,
19,
85,
24,
358,
436,
2256,
63,
807,
14,
362,
360,
374,
63,
6442,
735,
267,
372,
25046,
16801,
7902,
339,
340,
4113,
508,
283,
77,
19,
85,
24,
7,
436,
1862,
14,
362,
360,
30252,
63,
24283,
63,
6106,
358,
365,
715,
26,
267,
372,
869,
478,
7902,
339,
340,
4113,
508,
283,
77,
19,
85,
24,
63,
6106,
7,
436,
1862,
14,
362,
360,
30252,
63,
24283,
63,
6106,
358,
365,
756,
26,
267,
372,
25046,
16801,
7902,
339,
372,
3611,
2566,
3978,
63,
5443,
14,
362,
8,
3922,
12,
4760,
7902,
9,
421,
199,
363,
452,
363,
275,
359,
272,
283,
362,
63,
83,
10020,
63,
22846,
297,
272,
283,
1173,
3514,
3422,
297,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
oinopion/django
|
django/db/migrations/state.py
|
20
|
24499
|
from __future__ import unicode_literals
import copy
from collections import OrderedDict
from contextlib import contextmanager
from django.apps import AppConfig
from django.apps.registry import Apps, apps as global_apps
from django.conf import settings
from django.db import models
from django.db.models.fields.proxy import OrderWrt
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT
from django.db.models.options import DEFAULT_NAMES, normalize_together
from django.db.models.utils import make_model_tuple
from django.utils import six
from django.utils.encoding import force_text, smart_text
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
from django.utils.version import get_docs_version
from .exceptions import InvalidBasesError
def _get_app_label_and_model_name(model, app_label=''):
if isinstance(model, six.string_types):
split = model.split('.', 1)
return (tuple(split) if len(split) == 2 else (app_label, split[0]))
else:
return model._meta.app_label, model._meta.model_name
def get_related_models_recursive(model):
"""
Returns all models that have a direct or indirect relationship
to the given model.
Relationships are either defined by explicit relational fields, like
ForeignKey, ManyToManyField or OneToOneField, or by inheriting from another
model (a superclass is related to its subclasses, but not vice versa). Note,
however, that a model inheriting from a concrete model is also related to
its superclass through the implicit *_ptr OneToOneField on the subclass.
"""
def _related_models(m):
return [
f.related_model for f in m._meta.get_fields(include_parents=True, include_hidden=True)
if f.is_relation and not isinstance(f.related_model, six.string_types)
] + [
subclass for subclass in m.__subclasses__()
if issubclass(subclass, models.Model)
]
seen = set()
queue = _related_models(model)
for rel_mod in queue:
rel_app_label, rel_model_name = rel_mod._meta.app_label, rel_mod._meta.model_name
if (rel_app_label, rel_model_name) in seen:
continue
seen.add((rel_app_label, rel_model_name))
queue.extend(_related_models(rel_mod))
return seen - {(model._meta.app_label, model._meta.model_name)}
class ProjectState(object):
"""
Represents the entire project's overall state.
This is the item that is passed around - we do it here rather than at the
app level so that cross-app FKs/etc. resolve properly.
"""
def __init__(self, models=None, real_apps=None):
self.models = models or {}
# Apps to include from main registry, usually unmigrated ones
self.real_apps = real_apps or []
def add_model(self, model_state):
app_label, model_name = model_state.app_label, model_state.name_lower
self.models[(app_label, model_name)] = model_state
if 'apps' in self.__dict__: # hasattr would cache the property
self.reload_model(app_label, model_name)
def remove_model(self, app_label, model_name):
del self.models[app_label, model_name]
if 'apps' in self.__dict__: # hasattr would cache the property
self.apps.unregister_model(app_label, model_name)
# Need to do this explicitly since unregister_model() doesn't clear
# the cache automatically (#24513)
self.apps.clear_cache()
def reload_model(self, app_label, model_name):
if 'apps' in self.__dict__: # hasattr would cache the property
try:
old_model = self.apps.get_model(app_label, model_name)
except LookupError:
related_models = set()
else:
# Get all relations to and from the old model before reloading,
# as _meta.apps may change
related_models = get_related_models_recursive(old_model)
# Get all outgoing references from the model to be rendered
model_state = self.models[(app_label, model_name)]
# Directly related models are the models pointed to by ForeignKeys,
# OneToOneFields, and ManyToManyFields.
direct_related_models = set()
for name, field in model_state.fields:
if field.is_relation:
if field.remote_field.model == RECURSIVE_RELATIONSHIP_CONSTANT:
continue
rel_app_label, rel_model_name = _get_app_label_and_model_name(field.related_model, app_label)
direct_related_models.add((rel_app_label, rel_model_name.lower()))
# For all direct related models recursively get all related models.
related_models.update(direct_related_models)
for rel_app_label, rel_model_name in direct_related_models:
try:
rel_model = self.apps.get_model(rel_app_label, rel_model_name)
except LookupError:
pass
else:
related_models.update(get_related_models_recursive(rel_model))
# Include the model itself
related_models.add((app_label, model_name))
# Unregister all related models
with self.apps.bulk_update():
for rel_app_label, rel_model_name in related_models:
self.apps.unregister_model(rel_app_label, rel_model_name)
states_to_be_rendered = []
# Gather all models states of those models that will be rerendered.
# This includes:
# 1. All related models of unmigrated apps
for model_state in self.apps.real_models:
if (model_state.app_label, model_state.name_lower) in related_models:
states_to_be_rendered.append(model_state)
# 2. All related models of migrated apps
for rel_app_label, rel_model_name in related_models:
try:
model_state = self.models[rel_app_label, rel_model_name]
except KeyError:
pass
else:
states_to_be_rendered.append(model_state)
# Render all models
self.apps.render_multiple(states_to_be_rendered)
def clone(self):
"Returns an exact copy of this ProjectState"
new_state = ProjectState(
models={k: v.clone() for k, v in self.models.items()},
real_apps=self.real_apps,
)
if 'apps' in self.__dict__:
new_state.apps = self.apps.clone()
return new_state
@cached_property
def apps(self):
return StateApps(self.real_apps, self.models)
@property
def concrete_apps(self):
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
return self.apps
@classmethod
def from_apps(cls, apps):
"Takes in an Apps and returns a ProjectState matching it"
app_models = {}
for model in apps.get_models(include_swapped=True):
model_state = ModelState.from_model(model)
app_models[(model_state.app_label, model_state.name_lower)] = model_state
return cls(app_models)
def __eq__(self, other):
if set(self.models.keys()) != set(other.models.keys()):
return False
if set(self.real_apps) != set(other.real_apps):
return False
return all(model == other.models[key] for key, model in self.models.items())
def __ne__(self, other):
return not (self == other)
class AppConfigStub(AppConfig):
"""
Stubs a Django AppConfig. Only provides a label, and a dict of models.
"""
# Not used, but required by AppConfig.__init__
path = ''
def __init__(self, label):
self.label = label
# App-label and app-name are not the same thing, so technically passing
# in the label here is wrong. In practice, migrations don't care about
# the app name, but we need something unique, and the label works fine.
super(AppConfigStub, self).__init__(label, None)
def import_models(self, all_models):
self.models = all_models
class StateApps(Apps):
"""
Subclass of the global Apps registry class to better handle dynamic model
additions and removals.
"""
def __init__(self, real_apps, models, ignore_swappable=False):
# Any apps in self.real_apps should have all their models included
# in the render. We don't use the original model instances as there
# are some variables that refer to the Apps object.
# FKs/M2Ms from real apps are also not included as they just
# mess things up with partial states (due to lack of dependencies)
self.real_models = []
for app_label in real_apps:
app = global_apps.get_app_config(app_label)
for model in app.get_models():
self.real_models.append(ModelState.from_model(model, exclude_rels=True))
# Populate the app registry with a stub for each application.
app_labels = {model_state.app_label for model_state in models.values()}
app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
super(StateApps, self).__init__(app_configs)
self.render_multiple(list(models.values()) + self.real_models)
# There shouldn't be any operations pending at this point.
pending_models = set(self._pending_operations)
if ignore_swappable:
pending_models -= {make_model_tuple(settings.AUTH_USER_MODEL)}
if pending_models:
msg = "Unhandled pending operations for models: %s"
labels = (".".join(model_key) for model_key in self._pending_operations)
raise ValueError(msg % ", ".join(labels))
@contextmanager
def bulk_update(self):
# Avoid clearing each model's cache for each change. Instead, clear
# all caches when we're finished updating the model instances.
ready = self.ready
self.ready = False
try:
yield
finally:
self.ready = ready
self.clear_cache()
def render_multiple(self, model_states):
# We keep trying to render the models in a loop, ignoring invalid
# base errors, until the size of the unrendered models doesn't
# decrease by at least one, meaning there's a base dependency loop/
# missing base.
if not model_states:
return
# Prevent that all model caches are expired for each render.
with self.bulk_update():
unrendered_models = model_states
while unrendered_models:
new_unrendered_models = []
for model in unrendered_models:
try:
model.render(self)
except InvalidBasesError:
new_unrendered_models.append(model)
if len(new_unrendered_models) == len(unrendered_models):
raise InvalidBasesError(
"Cannot resolve bases for %r\nThis can happen if you are inheriting models from an "
"app with migrations (e.g. contrib.auth)\n in an app with no migrations; see "
"https://docs.djangoproject.com/en/%s/topics/migrations/#dependencies "
"for more" % (new_unrendered_models, get_docs_version())
)
unrendered_models = new_unrendered_models
def clone(self):
"""
Return a clone of this registry, mainly used by the migration framework.
"""
clone = StateApps([], {})
clone.all_models = copy.deepcopy(self.all_models)
clone.app_configs = copy.deepcopy(self.app_configs)
# No need to actually clone them, they'll never change
clone.real_models = self.real_models
return clone
def register_model(self, app_label, model):
self.all_models[app_label][model._meta.model_name] = model
if app_label not in self.app_configs:
self.app_configs[app_label] = AppConfigStub(app_label)
self.app_configs[app_label].models = OrderedDict()
self.app_configs[app_label].models[model._meta.model_name] = model
self.do_pending_operations(model)
self.clear_cache()
def unregister_model(self, app_label, model_name):
try:
del self.all_models[app_label][model_name]
del self.app_configs[app_label].models[model_name]
except KeyError:
pass
class ModelState(object):
"""
Represents a Django Model. We don't use the actual Model class
as it's not designed to have its options changed - instead, we
mutate this one and then render it into a Model as required.
Note that while you are allowed to mutate .fields, you are not allowed
to mutate the Field instances inside there themselves - you must instead
assign new ones, as these are not detached during a clone.
"""
def __init__(self, app_label, name, fields, options=None, bases=None, managers=None):
self.app_label = app_label
self.name = force_text(name)
self.fields = fields
self.options = options or {}
self.bases = bases or (models.Model, )
self.managers = managers or []
# Sanity-check that fields is NOT a dict. It must be ordered.
if isinstance(self.fields, dict):
raise ValueError("ModelState.fields cannot be a dict - it must be a list of 2-tuples.")
for name, field in fields:
# Sanity-check that fields are NOT already bound to a model.
if hasattr(field, 'model'):
raise ValueError(
'ModelState.fields cannot be bound to a model - "%s" is.' % name
)
# Sanity-check that relation fields are NOT referring to a model class.
if field.is_relation and hasattr(field.related_model, '_meta'):
raise ValueError(
'ModelState.fields cannot refer to a model class - "%s.to" does. '
'Use a string reference instead.' % name
)
if field.many_to_many and hasattr(field.remote_field.through, '_meta'):
raise ValueError(
'ModelState.fields cannot refer to a model class - "%s.through" does. '
'Use a string reference instead.' % name
)
@cached_property
def name_lower(self):
return self.name.lower()
@classmethod
def from_model(cls, model, exclude_rels=False):
"""
Feed me a model, get a ModelState representing it out.
"""
# Deconstruct the fields
fields = []
for field in model._meta.local_fields:
if getattr(field, "remote_field", None) and exclude_rels:
continue
if isinstance(field, OrderWrt):
continue
name, path, args, kwargs = field.deconstruct()
field_class = import_string(path)
try:
fields.append((name, field_class(*args, **kwargs)))
except TypeError as e:
raise TypeError("Couldn't reconstruct field %s on %s: %s" % (
name,
model._meta.label,
e,
))
if not exclude_rels:
for field in model._meta.local_many_to_many:
name, path, args, kwargs = field.deconstruct()
field_class = import_string(path)
try:
fields.append((name, field_class(*args, **kwargs)))
except TypeError as e:
raise TypeError("Couldn't reconstruct m2m field %s on %s: %s" % (
name,
model._meta.object_name,
e,
))
# Extract the options
options = {}
for name in DEFAULT_NAMES:
# Ignore some special options
if name in ["apps", "app_label"]:
continue
elif name in model._meta.original_attrs:
if name == "unique_together":
ut = model._meta.original_attrs["unique_together"]
options[name] = set(normalize_together(ut))
elif name == "index_together":
it = model._meta.original_attrs["index_together"]
options[name] = set(normalize_together(it))
else:
options[name] = model._meta.original_attrs[name]
# Force-convert all options to text_type (#23226)
options = cls.force_text_recursive(options)
# If we're ignoring relationships, remove all field-listing model
# options (that option basically just means "make a stub model")
if exclude_rels:
for key in ["unique_together", "index_together", "order_with_respect_to"]:
if key in options:
del options[key]
def flatten_bases(model):
bases = []
for base in model.__bases__:
if hasattr(base, "_meta") and base._meta.abstract:
bases.extend(flatten_bases(base))
else:
bases.append(base)
return bases
# We can't rely on __mro__ directly because we only want to flatten
# abstract models and not the whole tree. However by recursing on
# __bases__ we may end up with duplicates and ordering issues, we
# therefore discard any duplicates and reorder the bases according
# to their index in the MRO.
flattened_bases = sorted(set(flatten_bases(model)), key=lambda x: model.__mro__.index(x))
# Make our record
bases = tuple(
(
base._meta.label_lower
if hasattr(base, "_meta") else
base
)
for base in flattened_bases
)
# Ensure at least one base inherits from models.Model
if not any((isinstance(base, six.string_types) or issubclass(base, models.Model)) for base in bases):
bases = (models.Model,)
# Constructs all managers on the model
managers_mapping = {}
def reconstruct_manager(mgr):
as_manager, manager_path, qs_path, args, kwargs = mgr.deconstruct()
if as_manager:
qs_class = import_string(qs_path)
instance = qs_class.as_manager()
else:
manager_class = import_string(manager_path)
instance = manager_class(*args, **kwargs)
# We rely on the ordering of the creation_counter of the original
# instance
name = force_text(mgr.name)
managers_mapping[name] = (mgr.creation_counter, instance)
if hasattr(model, "_default_manager"):
default_manager_name = force_text(model._default_manager.name)
# Make sure the default manager is always the first
if model._default_manager.use_in_migrations:
reconstruct_manager(model._default_manager)
else:
# Force this manager to be the first and thus default
managers_mapping[default_manager_name] = (0, models.Manager())
# Sort all managers by their creation counter
for _, manager, _ in sorted(model._meta.managers):
if manager.name == "_base_manager" or not manager.use_in_migrations:
continue
reconstruct_manager(manager)
# Sort all managers by their creation counter but take only name and
# instance for further processing
managers = [
(name, instance) for name, (cc, instance) in
sorted(managers_mapping.items(), key=lambda v: v[1])
]
if managers == [(default_manager_name, models.Manager())]:
managers = []
else:
managers = []
# Construct the new ModelState
return cls(
model._meta.app_label,
model._meta.object_name,
fields,
options,
bases,
managers,
)
@classmethod
def force_text_recursive(cls, value):
if isinstance(value, six.string_types):
return smart_text(value)
elif isinstance(value, list):
return [cls.force_text_recursive(x) for x in value]
elif isinstance(value, tuple):
return tuple(cls.force_text_recursive(x) for x in value)
elif isinstance(value, set):
return set(cls.force_text_recursive(x) for x in value)
elif isinstance(value, dict):
return {
cls.force_text_recursive(k): cls.force_text_recursive(v)
for k, v in value.items()
}
return value
def construct_fields(self):
"Deep-clone the fields using deconstruction"
for name, field in self.fields:
_, path, args, kwargs = field.deconstruct()
field_class = import_string(path)
yield name, field_class(*args, **kwargs)
def construct_managers(self):
"Deep-clone the managers using deconstruction"
# Sort all managers by their creation counter
sorted_managers = sorted(self.managers, key=lambda v: v[1].creation_counter)
for mgr_name, manager in sorted_managers:
mgr_name = force_text(mgr_name)
as_manager, manager_path, qs_path, args, kwargs = manager.deconstruct()
if as_manager:
qs_class = import_string(qs_path)
yield mgr_name, qs_class.as_manager()
else:
manager_class = import_string(manager_path)
yield mgr_name, manager_class(*args, **kwargs)
def clone(self):
"Returns an exact copy of this ModelState"
return self.__class__(
app_label=self.app_label,
name=self.name,
fields=list(self.fields),
options=dict(self.options),
bases=self.bases,
managers=list(self.managers),
)
def render(self, apps):
"Creates a Model object from our current state into the given apps"
# First, make a Meta object
meta_contents = {'app_label': self.app_label, "apps": apps}
meta_contents.update(self.options)
meta = type(str("Meta"), tuple(), meta_contents)
# Then, work out our bases
try:
bases = tuple(
(apps.get_model(base) if isinstance(base, six.string_types) else base)
for base in self.bases
)
except LookupError:
raise InvalidBasesError("Cannot resolve one or more bases from %r" % (self.bases,))
# Turn fields into a dict for the body, add other bits
body = dict(self.construct_fields())
body['Meta'] = meta
body['__module__'] = "__fake__"
# Restore managers
body.update(self.construct_managers())
# Then, make a Model object (apps.register_model is called in __new__)
return type(
str(self.name),
bases,
body,
)
def get_field_by_name(self, name):
for fname, field in self.fields:
if fname == name:
return field
raise ValueError("No field called %s on model %s" % (name, self.name))
def __repr__(self):
return "<ModelState: '%s.%s'>" % (self.app_label, self.name)
def __eq__(self, other):
return (
(self.app_label == other.app_label) and
(self.name == other.name) and
(len(self.fields) == len(other.fields)) and
all((k1 == k2 and (f1.deconstruct()[1:] == f2.deconstruct()[1:]))
for (k1, f1), (k2, f2) in zip(self.fields, other.fields)) and
(self.options == other.options) and
(self.bases == other.bases) and
(self.managers == other.managers)
)
def __ne__(self, other):
return not (self == other)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1331,
199,
504,
5055,
492,
8773,
199,
504,
15502,
492,
27608,
199,
199,
504,
1639,
14,
5181,
492,
4693,
2028,
199,
504,
1639,
14,
5181,
14,
5189,
492,
4693,
83,
12,
8686,
465,
2288,
63,
5181,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
14,
3280,
492,
9240,
55,
2591,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
14,
2407,
492,
19461,
1230,
2684,
2524,
63,
13604,
2594,
3234,
1772,
63,
25825,
199,
504,
1639,
14,
697,
14,
992,
14,
1419,
492,
6186,
63,
14546,
12,
7666,
63,
6314,
199,
504,
1639,
14,
697,
14,
992,
14,
1208,
492,
1852,
63,
1238,
63,
2960,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
12,
11179,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
875,
199,
504,
1639,
14,
1208,
14,
1023,
492,
664,
63,
4757,
63,
1023,
199,
199,
504,
1275,
3924,
492,
6378,
1563,
83,
547,
421,
199,
318,
485,
362,
63,
571,
63,
1302,
63,
460,
63,
1238,
63,
354,
8,
1238,
12,
1145,
63,
1302,
9280,
272,
340,
1228,
8,
1238,
12,
3816,
14,
875,
63,
1313,
304,
267,
3715,
275,
1402,
14,
1294,
14078,
413,
9,
267,
372,
334,
2960,
8,
1294,
9,
340,
822,
8,
1294,
9,
508,
499,
587,
334,
571,
63,
1302,
12,
3715,
59,
16,
2459,
272,
587,
26,
267,
372,
1402,
423,
2024,
14,
571,
63,
1302,
12,
1402,
423,
2024,
14,
1238,
63,
354,
421,
199,
318,
664,
63,
2407,
63,
992,
63,
9931,
8,
1238,
304,
272,
408,
272,
1803,
1006,
1709,
626,
1172,
282,
4125,
503,
19458,
8931,
272,
370,
314,
1627,
1402,
14,
339,
23230,
3319,
83,
787,
1902,
3247,
701,
5027,
5850,
279,
1504,
12,
2839,
272,
12718,
12,
28409,
503,
7309,
13216,
12,
503,
701,
29927,
687,
4573,
272,
1402,
334,
65,
17035,
365,
4048,
370,
2399,
9180,
12,
1325,
440,
1321,
301,
809,
2231,
680,
3390,
12,
272,
13432,
12,
626,
282,
1402,
29927,
687,
282,
13801,
1402,
365,
2597,
4048,
370,
272,
2399,
17035,
4012,
314,
9227,
20841,
4695,
7309,
13216,
641,
314,
5516,
14,
272,
408,
272,
347,
485,
2407,
63,
992,
8,
77,
304,
267,
372,
359,
288,
289,
14,
2407,
63,
1238,
367,
289,
315,
333,
423,
2024,
14,
362,
63,
955,
8,
2613,
63,
8859,
29,
549,
12,
2387,
63,
5642,
29,
549,
9,
288,
340,
289,
14,
374,
63,
5690,
436,
440,
1228,
8,
70,
14,
2407,
63,
1238,
12,
3816,
14,
875,
63,
1313,
9,
267,
1622,
435,
359,
288,
5516,
367,
5516,
315,
333,
855,
19094,
4533,
288,
340,
11602,
8,
6083,
12,
1709,
14,
1685,
9,
267,
1622,
339,
6775,
275,
663,
342,
272,
4126,
275,
485,
2407,
63,
992,
8,
1238,
9,
272,
367,
4668,
63,
1494,
315,
4126,
26,
267,
4668,
63,
571,
63,
1302,
12,
4668,
63,
1238,
63,
354,
275,
4668,
63,
1494,
423,
2024,
14,
571,
63,
1302,
12,
4668,
63,
1494,
423,
2024,
14,
1238,
63,
354,
267,
340,
334,
3369,
63,
571,
63,
1302,
12,
4668,
63,
1238,
63,
354,
9,
315,
6775,
26,
288,
1980,
267,
6775,
14,
525,
1332,
3369,
63,
571,
63,
1302,
12,
4668,
63,
1238,
63,
354,
430,
267,
4126,
14,
2880,
1547,
2407,
63,
992,
8,
3369,
63,
1494,
430,
272,
372,
6775,
446,
26458,
1238,
423,
2024,
14,
571,
63,
1302,
12,
1402,
423,
2024,
14,
1238,
63,
354,
6769,
421,
199,
533,
7290,
2223,
8,
785,
304,
272,
408,
272,
21591,
314,
8039,
2199,
1159,
20347,
1174,
14,
272,
961,
365,
314,
1242,
626,
365,
3032,
6818,
446,
781,
886,
652,
2348,
7830,
2419,
737,
314,
272,
1145,
2166,
880,
626,
8059,
13,
571,
18821,
83,
15,
6839,
14,
7512,
7684,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1709,
29,
403,
12,
3363,
63,
5181,
29,
403,
304,
267,
291,
14,
992,
275,
1709,
503,
1052,
267,
327,
4693,
83,
370,
2387,
687,
2446,
7086,
12,
9987,
625,
31544,
7869,
267,
291,
14,
3093,
63,
5181,
275,
3363,
63,
5181,
503,
942,
339,
347,
1050,
63,
1238,
8,
277,
12,
1402,
63,
929,
304,
267,
1145,
63,
1302,
12,
1402,
63,
354,
275,
1402,
63,
929,
14,
571,
63,
1302,
12,
1402,
63,
929,
14,
354,
63,
2325,
267,
291,
14,
992,
7528,
571,
63,
1302,
12,
1402,
63,
354,
1874,
275,
1402,
63,
929,
267,
340,
283,
5181,
7,
315,
291,
855,
807,
10651,
221,
327,
2688,
3955,
2581,
314,
3324,
288,
291,
14,
9233,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
9,
339,
347,
2813,
63,
1238,
8,
277,
12,
1145,
63,
1302,
12,
1402,
63,
354,
304,
267,
2150,
291,
14,
992,
59,
571,
63,
1302,
12,
1402,
63,
354,
61,
267,
340,
283,
5181,
7,
315,
291,
855,
807,
10651,
221,
327,
2688,
3955,
2581,
314,
3324,
288,
291,
14,
5181,
14,
18408,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
9,
288,
327,
14012,
370,
886,
642,
7662,
3967,
24369,
63,
1238,
342,
3181,
1133,
5436,
288,
327,
314,
2581,
5847,
15196,
11677,
969,
9,
288,
291,
14,
5181,
14,
3584,
63,
1637,
342,
339,
347,
13101,
63,
1238,
8,
277,
12,
1145,
63,
1302,
12,
1402,
63,
354,
304,
267,
340,
283,
5181,
7,
315,
291,
855,
807,
10651,
221,
327,
2688,
3955,
2581,
314,
3324,
288,
862,
26,
355,
2269,
63,
1238,
275,
291,
14,
5181,
14,
362,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
9,
288,
871,
19021,
26,
355,
4048,
63,
992,
275,
663,
342,
288,
587,
26,
355,
327,
2372,
1006,
16109,
370,
436,
687,
314,
2269,
1402,
2544,
295,
8786,
12,
355,
327,
465,
485,
2024,
14,
5181,
1443,
1570,
355,
4048,
63,
992,
275,
664,
63,
2407,
63,
992,
63,
9931,
8,
1753,
63,
1238,
9,
953,
327,
2372,
1006,
21507,
6941,
687,
314,
1402,
370,
506,
8018
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1331,
199,
504,
5055,
492,
8773,
199,
504,
15502,
492,
27608,
199,
199,
504,
1639,
14,
5181,
492,
4693,
2028,
199,
504,
1639,
14,
5181,
14,
5189,
492,
4693,
83,
12,
8686,
465,
2288,
63,
5181,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
14,
3280,
492,
9240,
55,
2591,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
14,
2407,
492,
19461,
1230,
2684,
2524,
63,
13604,
2594,
3234,
1772,
63,
25825,
199,
504,
1639,
14,
697,
14,
992,
14,
1419,
492,
6186,
63,
14546,
12,
7666,
63,
6314,
199,
504,
1639,
14,
697,
14,
992,
14,
1208,
492,
1852,
63,
1238,
63,
2960,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
12,
11179,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
875,
199,
504,
1639,
14,
1208,
14,
1023,
492,
664,
63,
4757,
63,
1023,
199,
199,
504,
1275,
3924,
492,
6378,
1563,
83,
547,
421,
199,
318,
485,
362,
63,
571,
63,
1302,
63,
460,
63,
1238,
63,
354,
8,
1238,
12,
1145,
63,
1302,
9280,
272,
340,
1228,
8,
1238,
12,
3816,
14,
875,
63,
1313,
304,
267,
3715,
275,
1402,
14,
1294,
14078,
413,
9,
267,
372,
334,
2960,
8,
1294,
9,
340,
822,
8,
1294,
9,
508,
499,
587,
334,
571,
63,
1302,
12,
3715,
59,
16,
2459,
272,
587,
26,
267,
372,
1402,
423,
2024,
14,
571,
63,
1302,
12,
1402,
423,
2024,
14,
1238,
63,
354,
421,
199,
318,
664,
63,
2407,
63,
992,
63,
9931,
8,
1238,
304,
272,
408,
272,
1803,
1006,
1709,
626,
1172,
282,
4125,
503,
19458,
8931,
272,
370,
314,
1627,
1402,
14,
339,
23230,
3319,
83,
787,
1902,
3247,
701,
5027,
5850,
279,
1504,
12,
2839,
272,
12718,
12,
28409,
503,
7309,
13216,
12,
503,
701,
29927,
687,
4573,
272,
1402,
334,
65,
17035,
365,
4048,
370,
2399,
9180,
12,
1325,
440,
1321,
301,
809,
2231,
680,
3390,
12,
272,
13432,
12,
626,
282,
1402,
29927,
687,
282,
13801,
1402,
365,
2597,
4048,
370,
272,
2399,
17035,
4012,
314,
9227,
20841,
4695,
7309,
13216,
641,
314,
5516,
14,
272,
408,
272,
347,
485,
2407,
63,
992,
8,
77,
304,
267,
372,
359,
288,
289,
14,
2407,
63,
1238,
367,
289,
315,
333,
423,
2024,
14,
362,
63,
955,
8,
2613,
63,
8859,
29,
549,
12,
2387,
63,
5642,
29,
549,
9,
288,
340,
289,
14,
374,
63,
5690,
436,
440,
1228,
8,
70,
14,
2407,
63,
1238,
12,
3816,
14,
875,
63,
1313,
9,
267,
1622,
435,
359,
288,
5516,
367,
5516,
315,
333,
855,
19094,
4533,
288,
340,
11602,
8,
6083,
12,
1709,
14,
1685,
9,
267,
1622,
339,
6775,
275,
663,
342,
272,
4126,
275,
485,
2407,
63,
992,
8,
1238,
9,
272,
367,
4668,
63,
1494,
315,
4126,
26,
267,
4668,
63,
571,
63,
1302,
12,
4668,
63,
1238,
63,
354,
275,
4668,
63,
1494,
423,
2024,
14,
571,
63,
1302,
12,
4668,
63,
1494,
423,
2024,
14,
1238,
63,
354,
267,
340,
334,
3369,
63,
571,
63,
1302,
12,
4668,
63,
1238,
63,
354,
9,
315,
6775,
26,
288,
1980,
267,
6775,
14,
525,
1332,
3369,
63,
571,
63,
1302,
12,
4668,
63,
1238,
63,
354,
430,
267,
4126,
14,
2880,
1547,
2407,
63,
992,
8,
3369,
63,
1494,
430,
272,
372,
6775,
446,
26458,
1238,
423,
2024,
14,
571,
63,
1302,
12,
1402,
423,
2024,
14,
1238,
63,
354,
6769,
421,
199,
533,
7290,
2223,
8,
785,
304,
272,
408,
272,
21591,
314,
8039,
2199,
1159,
20347,
1174,
14,
272,
961,
365,
314,
1242,
626,
365,
3032,
6818,
446,
781,
886,
652,
2348,
7830,
2419,
737,
314,
272,
1145,
2166,
880,
626,
8059,
13,
571,
18821,
83,
15,
6839,
14,
7512,
7684,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1709,
29,
403,
12,
3363,
63,
5181,
29,
403,
304,
267,
291,
14,
992,
275,
1709,
503,
1052,
267,
327,
4693,
83,
370,
2387,
687,
2446,
7086,
12,
9987,
625,
31544,
7869,
267,
291,
14,
3093,
63,
5181,
275,
3363,
63,
5181,
503,
942,
339,
347,
1050,
63,
1238,
8,
277,
12,
1402,
63,
929,
304,
267,
1145,
63,
1302,
12,
1402,
63,
354,
275,
1402,
63,
929,
14,
571,
63,
1302,
12,
1402,
63,
929,
14,
354,
63,
2325,
267,
291,
14,
992,
7528,
571,
63,
1302,
12,
1402,
63,
354,
1874,
275,
1402,
63,
929,
267,
340,
283,
5181,
7,
315,
291,
855,
807,
10651,
221,
327,
2688,
3955,
2581,
314,
3324,
288,
291,
14,
9233,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
9,
339,
347,
2813,
63,
1238,
8,
277,
12,
1145,
63,
1302,
12,
1402,
63,
354,
304,
267,
2150,
291,
14,
992,
59,
571,
63,
1302,
12,
1402,
63,
354,
61,
267,
340,
283,
5181,
7,
315,
291,
855,
807,
10651,
221,
327,
2688,
3955,
2581,
314,
3324,
288,
291,
14,
5181,
14,
18408,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
9,
288,
327,
14012,
370,
886,
642,
7662,
3967,
24369,
63,
1238,
342,
3181,
1133,
5436,
288,
327,
314,
2581,
5847,
15196,
11677,
969,
9,
288,
291,
14,
5181,
14,
3584,
63,
1637,
342,
339,
347,
13101,
63,
1238,
8,
277,
12,
1145,
63,
1302,
12,
1402,
63,
354,
304,
267,
340,
283,
5181,
7,
315,
291,
855,
807,
10651,
221,
327,
2688,
3955,
2581,
314,
3324,
288,
862,
26,
355,
2269,
63,
1238,
275,
291,
14,
5181,
14,
362,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
9,
288,
871,
19021,
26,
355,
4048,
63,
992,
275,
663,
342,
288,
587,
26,
355,
327,
2372,
1006,
16109,
370,
436,
687,
314,
2269,
1402,
2544,
295,
8786,
12,
355,
327,
465,
485,
2024,
14,
5181,
1443,
1570,
355,
4048,
63,
992,
275,
664,
63,
2407,
63,
992,
63,
9931,
8,
1753,
63,
1238,
9,
953,
327,
2372,
1006,
21507,
6941,
687,
314,
1402,
370,
506,
8018,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Jack-Q/GYP-copy
|
pylib/gyp/MSVSSettings_test.py
|
395
|
65937
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for the MSVSSettings.py file."""
import StringIO
import unittest
import gyp.MSVSSettings as MSVSSettings
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.stderr = StringIO.StringIO()
def _ExpectedWarnings(self, expected):
"""Compares recorded lines to expected warnings."""
self.stderr.seek(0)
actual = self.stderr.read().split('\n')
actual = [line for line in actual if line]
self.assertEqual(sorted(expected), sorted(actual))
def testValidateMSVSSettings_tool_names(self):
"""Tests that only MSVS tool names are allowed."""
MSVSSettings.ValidateMSVSSettings(
{'VCCLCompilerTool': {},
'VCLinkerTool': {},
'VCMIDLTool': {},
'foo': {},
'VCResourceCompilerTool': {},
'VCLibrarianTool': {},
'VCManifestTool': {},
'ClCompile': {}},
self.stderr)
self._ExpectedWarnings([
'Warning: unrecognized tool foo',
'Warning: unrecognized tool ClCompile'])
def testValidateMSVSSettings_settings(self):
"""Tests that for invalid MSVS settings."""
MSVSSettings.ValidateMSVSSettings(
{'VCCLCompilerTool': {
'AdditionalIncludeDirectories': 'folder1;folder2',
'AdditionalOptions': ['string1', 'string2'],
'AdditionalUsingDirectories': 'folder1;folder2',
'AssemblerListingLocation': 'a_file_name',
'AssemblerOutput': '0',
'BasicRuntimeChecks': '5',
'BrowseInformation': 'fdkslj',
'BrowseInformationFile': 'a_file_name',
'BufferSecurityCheck': 'true',
'CallingConvention': '-1',
'CompileAs': '1',
'DebugInformationFormat': '2',
'DefaultCharIsUnsigned': 'true',
'Detect64BitPortabilityProblems': 'true',
'DisableLanguageExtensions': 'true',
'DisableSpecificWarnings': 'string1;string2',
'EnableEnhancedInstructionSet': '1',
'EnableFiberSafeOptimizations': 'true',
'EnableFunctionLevelLinking': 'true',
'EnableIntrinsicFunctions': 'true',
'EnablePREfast': 'true',
'Enableprefast': 'bogus',
'ErrorReporting': '1',
'ExceptionHandling': '1',
'ExpandAttributedSource': 'true',
'FavorSizeOrSpeed': '1',
'FloatingPointExceptions': 'true',
'FloatingPointModel': '1',
'ForceConformanceInForLoopScope': 'true',
'ForcedIncludeFiles': 'file1;file2',
'ForcedUsingFiles': 'file1;file2',
'GeneratePreprocessedFile': '1',
'GenerateXMLDocumentationFiles': 'true',
'IgnoreStandardIncludePath': 'true',
'InlineFunctionExpansion': '1',
'KeepComments': 'true',
'MinimalRebuild': 'true',
'ObjectFile': 'a_file_name',
'OmitDefaultLibName': 'true',
'OmitFramePointers': 'true',
'OpenMP': 'true',
'Optimization': '1',
'PrecompiledHeaderFile': 'a_file_name',
'PrecompiledHeaderThrough': 'a_file_name',
'PreprocessorDefinitions': 'string1;string2',
'ProgramDataBaseFileName': 'a_file_name',
'RuntimeLibrary': '1',
'RuntimeTypeInfo': 'true',
'ShowIncludes': 'true',
'SmallerTypeCheck': 'true',
'StringPooling': 'true',
'StructMemberAlignment': '1',
'SuppressStartupBanner': 'true',
'TreatWChar_tAsBuiltInType': 'true',
'UndefineAllPreprocessorDefinitions': 'true',
'UndefinePreprocessorDefinitions': 'string1;string2',
'UseFullPaths': 'true',
'UsePrecompiledHeader': '1',
'UseUnicodeResponseFiles': 'true',
'WarnAsError': 'true',
'WarningLevel': '1',
'WholeProgramOptimization': 'true',
'XMLDocumentationFileName': 'a_file_name',
'ZZXYZ': 'bogus'},
'VCLinkerTool': {
'AdditionalDependencies': 'file1;file2',
'AdditionalDependencies_excluded': 'file3',
'AdditionalLibraryDirectories': 'folder1;folder2',
'AdditionalManifestDependencies': 'file1;file2',
'AdditionalOptions': 'a string1',
'AddModuleNamesToAssembly': 'file1;file2',
'AllowIsolation': 'true',
'AssemblyDebug': '2',
'AssemblyLinkResource': 'file1;file2',
'BaseAddress': 'a string1',
'CLRImageType': '2',
'CLRThreadAttribute': '2',
'CLRUnmanagedCodeCheck': 'true',
'DataExecutionPrevention': '2',
'DelayLoadDLLs': 'file1;file2',
'DelaySign': 'true',
'Driver': '2',
'EmbedManagedResourceFile': 'file1;file2',
'EnableCOMDATFolding': '2',
'EnableUAC': 'true',
'EntryPointSymbol': 'a string1',
'ErrorReporting': '2',
'FixedBaseAddress': '2',
'ForceSymbolReferences': 'file1;file2',
'FunctionOrder': 'a_file_name',
'GenerateDebugInformation': 'true',
'GenerateManifest': 'true',
'GenerateMapFile': 'true',
'HeapCommitSize': 'a string1',
'HeapReserveSize': 'a string1',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreDefaultLibraryNames': 'file1;file2',
'IgnoreEmbeddedIDL': 'true',
'IgnoreImportLibrary': 'true',
'ImportLibrary': 'a_file_name',
'KeyContainer': 'a_file_name',
'KeyFile': 'a_file_name',
'LargeAddressAware': '2',
'LinkIncremental': '2',
'LinkLibraryDependencies': 'true',
'LinkTimeCodeGeneration': '2',
'ManifestFile': 'a_file_name',
'MapExports': 'true',
'MapFileName': 'a_file_name',
'MergedIDLBaseFileName': 'a_file_name',
'MergeSections': 'a string1',
'MidlCommandFile': 'a_file_name',
'ModuleDefinitionFile': 'a_file_name',
'OptimizeForWindows98': '1',
'OptimizeReferences': '2',
'OutputFile': 'a_file_name',
'PerUserRedirection': 'true',
'Profile': 'true',
'ProfileGuidedDatabase': 'a_file_name',
'ProgramDatabaseFile': 'a_file_name',
'RandomizedBaseAddress': '2',
'RegisterOutput': 'true',
'ResourceOnlyDLL': 'true',
'SetChecksum': 'true',
'ShowProgress': '2',
'StackCommitSize': 'a string1',
'StackReserveSize': 'a string1',
'StripPrivateSymbols': 'a_file_name',
'SubSystem': '2',
'SupportUnloadOfDelayLoadedDLL': 'true',
'SuppressStartupBanner': 'true',
'SwapRunFromCD': 'true',
'SwapRunFromNet': 'true',
'TargetMachine': '2',
'TerminalServerAware': '2',
'TurnOffAssemblyGeneration': 'true',
'TypeLibraryFile': 'a_file_name',
'TypeLibraryResourceID': '33',
'UACExecutionLevel': '2',
'UACUIAccess': 'true',
'UseLibraryDependencyInputs': 'true',
'UseUnicodeResponseFiles': 'true',
'Version': 'a string1'},
'VCMIDLTool': {
'AdditionalIncludeDirectories': 'folder1;folder2',
'AdditionalOptions': 'a string1',
'CPreprocessOptions': 'a string1',
'DefaultCharType': '1',
'DLLDataFileName': 'a_file_name',
'EnableErrorChecks': '1',
'ErrorCheckAllocations': 'true',
'ErrorCheckBounds': 'true',
'ErrorCheckEnumRange': 'true',
'ErrorCheckRefPointers': 'true',
'ErrorCheckStubData': 'true',
'GenerateStublessProxies': 'true',
'GenerateTypeLibrary': 'true',
'HeaderFileName': 'a_file_name',
'IgnoreStandardIncludePath': 'true',
'InterfaceIdentifierFileName': 'a_file_name',
'MkTypLibCompatible': 'true',
'notgood': 'bogus',
'OutputDirectory': 'a string1',
'PreprocessorDefinitions': 'string1;string2',
'ProxyFileName': 'a_file_name',
'RedirectOutputAndErrors': 'a_file_name',
'StructMemberAlignment': '1',
'SuppressStartupBanner': 'true',
'TargetEnvironment': '1',
'TypeLibraryName': 'a_file_name',
'UndefinePreprocessorDefinitions': 'string1;string2',
'ValidateParameters': 'true',
'WarnAsError': 'true',
'WarningLevel': '1'},
'VCResourceCompilerTool': {
'AdditionalOptions': 'a string1',
'AdditionalIncludeDirectories': 'folder1;folder2',
'Culture': '1003',
'IgnoreStandardIncludePath': 'true',
'notgood2': 'bogus',
'PreprocessorDefinitions': 'string1;string2',
'ResourceOutputFileName': 'a string1',
'ShowProgress': 'true',
'SuppressStartupBanner': 'true',
'UndefinePreprocessorDefinitions': 'string1;string2'},
'VCLibrarianTool': {
'AdditionalDependencies': 'file1;file2',
'AdditionalLibraryDirectories': 'folder1;folder2',
'AdditionalOptions': 'a string1',
'ExportNamedFunctions': 'string1;string2',
'ForceSymbolReferences': 'a string1',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreSpecificDefaultLibraries': 'file1;file2',
'LinkLibraryDependencies': 'true',
'ModuleDefinitionFile': 'a_file_name',
'OutputFile': 'a_file_name',
'SuppressStartupBanner': 'true',
'UseUnicodeResponseFiles': 'true'},
'VCManifestTool': {
'AdditionalManifestFiles': 'file1;file2',
'AdditionalOptions': 'a string1',
'AssemblyIdentity': 'a string1',
'ComponentFileName': 'a_file_name',
'DependencyInformationFile': 'a_file_name',
'GenerateCatalogFiles': 'true',
'InputResourceManifests': 'a string1',
'ManifestResourceFile': 'a_file_name',
'OutputManifestFile': 'a_file_name',
'RegistrarScriptFile': 'a_file_name',
'ReplacementsFile': 'a_file_name',
'SuppressStartupBanner': 'true',
'TypeLibraryFile': 'a_file_name',
'UpdateFileHashes': 'truel',
'UpdateFileHashesSearchPath': 'a_file_name',
'UseFAT32Workaround': 'true',
'UseUnicodeResponseFiles': 'true',
'VerboseOutput': 'true'}},
self.stderr)
self._ExpectedWarnings([
'Warning: for VCCLCompilerTool/BasicRuntimeChecks, '
'index value (5) not in expected range [0, 4)',
'Warning: for VCCLCompilerTool/BrowseInformation, '
"invalid literal for int() with base 10: 'fdkslj'",
'Warning: for VCCLCompilerTool/CallingConvention, '
'index value (-1) not in expected range [0, 4)',
'Warning: for VCCLCompilerTool/DebugInformationFormat, '
'converted value for 2 not specified.',
'Warning: unrecognized setting VCCLCompilerTool/Enableprefast',
'Warning: unrecognized setting VCCLCompilerTool/ZZXYZ',
'Warning: for VCLinkerTool/TargetMachine, '
'converted value for 2 not specified.',
'Warning: unrecognized setting VCMIDLTool/notgood',
'Warning: unrecognized setting VCResourceCompilerTool/notgood2',
'Warning: for VCManifestTool/UpdateFileHashes, '
"expected bool; got 'truel'"
''])
def testValidateMSBuildSettings_settings(self):
"""Tests that for invalid MSBuild settings."""
MSVSSettings.ValidateMSBuildSettings(
{'ClCompile': {
'AdditionalIncludeDirectories': 'folder1;folder2',
'AdditionalOptions': ['string1', 'string2'],
'AdditionalUsingDirectories': 'folder1;folder2',
'AssemblerListingLocation': 'a_file_name',
'AssemblerOutput': 'NoListing',
'BasicRuntimeChecks': 'StackFrameRuntimeCheck',
'BrowseInformation': 'false',
'BrowseInformationFile': 'a_file_name',
'BufferSecurityCheck': 'true',
'BuildingInIDE': 'true',
'CallingConvention': 'Cdecl',
'CompileAs': 'CompileAsC',
'CompileAsManaged': 'Pure',
'CreateHotpatchableImage': 'true',
'DebugInformationFormat': 'ProgramDatabase',
'DisableLanguageExtensions': 'true',
'DisableSpecificWarnings': 'string1;string2',
'EnableEnhancedInstructionSet': 'StreamingSIMDExtensions',
'EnableFiberSafeOptimizations': 'true',
'EnablePREfast': 'true',
'Enableprefast': 'bogus',
'ErrorReporting': 'Prompt',
'ExceptionHandling': 'SyncCThrow',
'ExpandAttributedSource': 'true',
'FavorSizeOrSpeed': 'Neither',
'FloatingPointExceptions': 'true',
'FloatingPointModel': 'Precise',
'ForceConformanceInForLoopScope': 'true',
'ForcedIncludeFiles': 'file1;file2',
'ForcedUsingFiles': 'file1;file2',
'FunctionLevelLinking': 'false',
'GenerateXMLDocumentationFiles': 'true',
'IgnoreStandardIncludePath': 'true',
'InlineFunctionExpansion': 'OnlyExplicitInline',
'IntrinsicFunctions': 'false',
'MinimalRebuild': 'true',
'MultiProcessorCompilation': 'true',
'ObjectFileName': 'a_file_name',
'OmitDefaultLibName': 'true',
'OmitFramePointers': 'true',
'OpenMPSupport': 'true',
'Optimization': 'Disabled',
'PrecompiledHeader': 'NotUsing',
'PrecompiledHeaderFile': 'a_file_name',
'PrecompiledHeaderOutputFile': 'a_file_name',
'PreprocessKeepComments': 'true',
'PreprocessorDefinitions': 'string1;string2',
'PreprocessOutputPath': 'a string1',
'PreprocessSuppressLineNumbers': 'false',
'PreprocessToFile': 'false',
'ProcessorNumber': '33',
'ProgramDataBaseFileName': 'a_file_name',
'RuntimeLibrary': 'MultiThreaded',
'RuntimeTypeInfo': 'true',
'ShowIncludes': 'true',
'SmallerTypeCheck': 'true',
'StringPooling': 'true',
'StructMemberAlignment': '1Byte',
'SuppressStartupBanner': 'true',
'TrackerLogDirectory': 'a_folder',
'TreatSpecificWarningsAsErrors': 'string1;string2',
'TreatWarningAsError': 'true',
'TreatWChar_tAsBuiltInType': 'true',
'UndefineAllPreprocessorDefinitions': 'true',
'UndefinePreprocessorDefinitions': 'string1;string2',
'UseFullPaths': 'true',
'UseUnicodeForAssemblerListing': 'true',
'WarningLevel': 'TurnOffAllWarnings',
'WholeProgramOptimization': 'true',
'XMLDocumentationFileName': 'a_file_name',
'ZZXYZ': 'bogus'},
'Link': {
'AdditionalDependencies': 'file1;file2',
'AdditionalLibraryDirectories': 'folder1;folder2',
'AdditionalManifestDependencies': 'file1;file2',
'AdditionalOptions': 'a string1',
'AddModuleNamesToAssembly': 'file1;file2',
'AllowIsolation': 'true',
'AssemblyDebug': '',
'AssemblyLinkResource': 'file1;file2',
'BaseAddress': 'a string1',
'BuildingInIDE': 'true',
'CLRImageType': 'ForceIJWImage',
'CLRSupportLastError': 'Enabled',
'CLRThreadAttribute': 'MTAThreadingAttribute',
'CLRUnmanagedCodeCheck': 'true',
'CreateHotPatchableImage': 'X86Image',
'DataExecutionPrevention': 'false',
'DelayLoadDLLs': 'file1;file2',
'DelaySign': 'true',
'Driver': 'NotSet',
'EmbedManagedResourceFile': 'file1;file2',
'EnableCOMDATFolding': 'false',
'EnableUAC': 'true',
'EntryPointSymbol': 'a string1',
'FixedBaseAddress': 'false',
'ForceFileOutput': 'Enabled',
'ForceSymbolReferences': 'file1;file2',
'FunctionOrder': 'a_file_name',
'GenerateDebugInformation': 'true',
'GenerateMapFile': 'true',
'HeapCommitSize': 'a string1',
'HeapReserveSize': 'a string1',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreEmbeddedIDL': 'true',
'IgnoreSpecificDefaultLibraries': 'a_file_list',
'ImageHasSafeExceptionHandlers': 'true',
'ImportLibrary': 'a_file_name',
'KeyContainer': 'a_file_name',
'KeyFile': 'a_file_name',
'LargeAddressAware': 'false',
'LinkDLL': 'true',
'LinkErrorReporting': 'SendErrorReport',
'LinkStatus': 'true',
'LinkTimeCodeGeneration': 'UseLinkTimeCodeGeneration',
'ManifestFile': 'a_file_name',
'MapExports': 'true',
'MapFileName': 'a_file_name',
'MergedIDLBaseFileName': 'a_file_name',
'MergeSections': 'a string1',
'MidlCommandFile': 'a_file_name',
'MinimumRequiredVersion': 'a string1',
'ModuleDefinitionFile': 'a_file_name',
'MSDOSStubFileName': 'a_file_name',
'NoEntryPoint': 'true',
'OptimizeReferences': 'false',
'OutputFile': 'a_file_name',
'PerUserRedirection': 'true',
'PreventDllBinding': 'true',
'Profile': 'true',
'ProfileGuidedDatabase': 'a_file_name',
'ProgramDatabaseFile': 'a_file_name',
'RandomizedBaseAddress': 'false',
'RegisterOutput': 'true',
'SectionAlignment': '33',
'SetChecksum': 'true',
'ShowProgress': 'LinkVerboseREF',
'SpecifySectionAttributes': 'a string1',
'StackCommitSize': 'a string1',
'StackReserveSize': 'a string1',
'StripPrivateSymbols': 'a_file_name',
'SubSystem': 'Console',
'SupportNobindOfDelayLoadedDLL': 'true',
'SupportUnloadOfDelayLoadedDLL': 'true',
'SuppressStartupBanner': 'true',
'SwapRunFromCD': 'true',
'SwapRunFromNET': 'true',
'TargetMachine': 'MachineX86',
'TerminalServerAware': 'false',
'TrackerLogDirectory': 'a_folder',
'TreatLinkerWarningAsErrors': 'true',
'TurnOffAssemblyGeneration': 'true',
'TypeLibraryFile': 'a_file_name',
'TypeLibraryResourceID': '33',
'UACExecutionLevel': 'AsInvoker',
'UACUIAccess': 'true',
'Version': 'a string1'},
'ResourceCompile': {
'AdditionalIncludeDirectories': 'folder1;folder2',
'AdditionalOptions': 'a string1',
'Culture': '0x236',
'IgnoreStandardIncludePath': 'true',
'NullTerminateStrings': 'true',
'PreprocessorDefinitions': 'string1;string2',
'ResourceOutputFileName': 'a string1',
'ShowProgress': 'true',
'SuppressStartupBanner': 'true',
'TrackerLogDirectory': 'a_folder',
'UndefinePreprocessorDefinitions': 'string1;string2'},
'Midl': {
'AdditionalIncludeDirectories': 'folder1;folder2',
'AdditionalOptions': 'a string1',
'ApplicationConfigurationMode': 'true',
'ClientStubFile': 'a_file_name',
'CPreprocessOptions': 'a string1',
'DefaultCharType': 'Signed',
'DllDataFileName': 'a_file_name',
'EnableErrorChecks': 'EnableCustom',
'ErrorCheckAllocations': 'true',
'ErrorCheckBounds': 'true',
'ErrorCheckEnumRange': 'true',
'ErrorCheckRefPointers': 'true',
'ErrorCheckStubData': 'true',
'GenerateClientFiles': 'Stub',
'GenerateServerFiles': 'None',
'GenerateStublessProxies': 'true',
'GenerateTypeLibrary': 'true',
'HeaderFileName': 'a_file_name',
'IgnoreStandardIncludePath': 'true',
'InterfaceIdentifierFileName': 'a_file_name',
'LocaleID': '33',
'MkTypLibCompatible': 'true',
'OutputDirectory': 'a string1',
'PreprocessorDefinitions': 'string1;string2',
'ProxyFileName': 'a_file_name',
'RedirectOutputAndErrors': 'a_file_name',
'ServerStubFile': 'a_file_name',
'StructMemberAlignment': 'NotSet',
'SuppressCompilerWarnings': 'true',
'SuppressStartupBanner': 'true',
'TargetEnvironment': 'Itanium',
'TrackerLogDirectory': 'a_folder',
'TypeLibFormat': 'NewFormat',
'TypeLibraryName': 'a_file_name',
'UndefinePreprocessorDefinitions': 'string1;string2',
'ValidateAllParameters': 'true',
'WarnAsError': 'true',
'WarningLevel': '1'},
'Lib': {
'AdditionalDependencies': 'file1;file2',
'AdditionalLibraryDirectories': 'folder1;folder2',
'AdditionalOptions': 'a string1',
'DisplayLibrary': 'a string1',
'ErrorReporting': 'PromptImmediately',
'ExportNamedFunctions': 'string1;string2',
'ForceSymbolReferences': 'a string1',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreSpecificDefaultLibraries': 'file1;file2',
'LinkTimeCodeGeneration': 'true',
'MinimumRequiredVersion': 'a string1',
'ModuleDefinitionFile': 'a_file_name',
'Name': 'a_file_name',
'OutputFile': 'a_file_name',
'RemoveObjects': 'file1;file2',
'SubSystem': 'Console',
'SuppressStartupBanner': 'true',
'TargetMachine': 'MachineX86i',
'TrackerLogDirectory': 'a_folder',
'TreatLibWarningAsErrors': 'true',
'UseUnicodeResponseFiles': 'true',
'Verbose': 'true'},
'Manifest': {
'AdditionalManifestFiles': 'file1;file2',
'AdditionalOptions': 'a string1',
'AssemblyIdentity': 'a string1',
'ComponentFileName': 'a_file_name',
'EnableDPIAwareness': 'fal',
'GenerateCatalogFiles': 'truel',
'GenerateCategoryTags': 'true',
'InputResourceManifests': 'a string1',
'ManifestFromManagedAssembly': 'a_file_name',
'notgood3': 'bogus',
'OutputManifestFile': 'a_file_name',
'OutputResourceManifests': 'a string1',
'RegistrarScriptFile': 'a_file_name',
'ReplacementsFile': 'a_file_name',
'SuppressDependencyElement': 'true',
'SuppressStartupBanner': 'true',
'TrackerLogDirectory': 'a_folder',
'TypeLibraryFile': 'a_file_name',
'UpdateFileHashes': 'true',
'UpdateFileHashesSearchPath': 'a_file_name',
'VerboseOutput': 'true'},
'ProjectReference': {
'LinkLibraryDependencies': 'true',
'UseLibraryDependencyInputs': 'true'},
'ManifestResourceCompile': {
'ResourceOutputFileName': 'a_file_name'},
'': {
'EmbedManifest': 'true',
'GenerateManifest': 'true',
'IgnoreImportLibrary': 'true',
'LinkIncremental': 'false'}},
self.stderr)
self._ExpectedWarnings([
'Warning: unrecognized setting ClCompile/Enableprefast',
'Warning: unrecognized setting ClCompile/ZZXYZ',
'Warning: unrecognized setting Manifest/notgood3',
'Warning: for Manifest/GenerateCatalogFiles, '
"expected bool; got 'truel'",
'Warning: for Lib/TargetMachine, unrecognized enumerated value '
'MachineX86i',
"Warning: for Manifest/EnableDPIAwareness, expected bool; got 'fal'"])
def testConvertToMSBuildSettings_empty(self):
"""Tests an empty conversion."""
msvs_settings = {}
expected_msbuild_settings = {}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings,
self.stderr)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
def testConvertToMSBuildSettings_minimal(self):
"""Tests a minimal conversion."""
msvs_settings = {
'VCCLCompilerTool': {
'AdditionalIncludeDirectories': 'dir1',
'AdditionalOptions': '/foo',
'BasicRuntimeChecks': '0',
},
'VCLinkerTool': {
'LinkTimeCodeGeneration': '1',
'ErrorReporting': '1',
'DataExecutionPrevention': '2',
},
}
expected_msbuild_settings = {
'ClCompile': {
'AdditionalIncludeDirectories': 'dir1',
'AdditionalOptions': '/foo',
'BasicRuntimeChecks': 'Default',
},
'Link': {
'LinkTimeCodeGeneration': 'UseLinkTimeCodeGeneration',
'LinkErrorReporting': 'PromptImmediately',
'DataExecutionPrevention': 'true',
},
}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings,
self.stderr)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
def testConvertToMSBuildSettings_warnings(self):
"""Tests conversion that generates warnings."""
msvs_settings = {
'VCCLCompilerTool': {
'AdditionalIncludeDirectories': '1',
'AdditionalOptions': '2',
# These are incorrect values:
'BasicRuntimeChecks': '12',
'BrowseInformation': '21',
'UsePrecompiledHeader': '13',
'GeneratePreprocessedFile': '14'},
'VCLinkerTool': {
# These are incorrect values:
'Driver': '10',
'LinkTimeCodeGeneration': '31',
'ErrorReporting': '21',
'FixedBaseAddress': '6'},
'VCResourceCompilerTool': {
# Custom
'Culture': '1003'}}
expected_msbuild_settings = {
'ClCompile': {
'AdditionalIncludeDirectories': '1',
'AdditionalOptions': '2'},
'Link': {},
'ResourceCompile': {
# Custom
'Culture': '0x03eb'}}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings,
self.stderr)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([
'Warning: while converting VCCLCompilerTool/BasicRuntimeChecks to '
'MSBuild, index value (12) not in expected range [0, 4)',
'Warning: while converting VCCLCompilerTool/BrowseInformation to '
'MSBuild, index value (21) not in expected range [0, 3)',
'Warning: while converting VCCLCompilerTool/UsePrecompiledHeader to '
'MSBuild, index value (13) not in expected range [0, 3)',
'Warning: while converting VCCLCompilerTool/GeneratePreprocessedFile to '
'MSBuild, value must be one of [0, 1, 2]; got 14',
'Warning: while converting VCLinkerTool/Driver to '
'MSBuild, index value (10) not in expected range [0, 4)',
'Warning: while converting VCLinkerTool/LinkTimeCodeGeneration to '
'MSBuild, index value (31) not in expected range [0, 5)',
'Warning: while converting VCLinkerTool/ErrorReporting to '
'MSBuild, index value (21) not in expected range [0, 3)',
'Warning: while converting VCLinkerTool/FixedBaseAddress to '
'MSBuild, index value (6) not in expected range [0, 3)',
])
def testConvertToMSBuildSettings_full_synthetic(self):
"""Tests conversion of all the MSBuild settings."""
msvs_settings = {
'VCCLCompilerTool': {
'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'AdditionalUsingDirectories': 'folder1;folder2;folder3',
'AssemblerListingLocation': 'a_file_name',
'AssemblerOutput': '0',
'BasicRuntimeChecks': '1',
'BrowseInformation': '2',
'BrowseInformationFile': 'a_file_name',
'BufferSecurityCheck': 'true',
'CallingConvention': '0',
'CompileAs': '1',
'DebugInformationFormat': '4',
'DefaultCharIsUnsigned': 'true',
'Detect64BitPortabilityProblems': 'true',
'DisableLanguageExtensions': 'true',
'DisableSpecificWarnings': 'd1;d2;d3',
'EnableEnhancedInstructionSet': '0',
'EnableFiberSafeOptimizations': 'true',
'EnableFunctionLevelLinking': 'true',
'EnableIntrinsicFunctions': 'true',
'EnablePREfast': 'true',
'ErrorReporting': '1',
'ExceptionHandling': '2',
'ExpandAttributedSource': 'true',
'FavorSizeOrSpeed': '0',
'FloatingPointExceptions': 'true',
'FloatingPointModel': '1',
'ForceConformanceInForLoopScope': 'true',
'ForcedIncludeFiles': 'file1;file2;file3',
'ForcedUsingFiles': 'file1;file2;file3',
'GeneratePreprocessedFile': '1',
'GenerateXMLDocumentationFiles': 'true',
'IgnoreStandardIncludePath': 'true',
'InlineFunctionExpansion': '2',
'KeepComments': 'true',
'MinimalRebuild': 'true',
'ObjectFile': 'a_file_name',
'OmitDefaultLibName': 'true',
'OmitFramePointers': 'true',
'OpenMP': 'true',
'Optimization': '3',
'PrecompiledHeaderFile': 'a_file_name',
'PrecompiledHeaderThrough': 'a_file_name',
'PreprocessorDefinitions': 'd1;d2;d3',
'ProgramDataBaseFileName': 'a_file_name',
'RuntimeLibrary': '0',
'RuntimeTypeInfo': 'true',
'ShowIncludes': 'true',
'SmallerTypeCheck': 'true',
'StringPooling': 'true',
'StructMemberAlignment': '1',
'SuppressStartupBanner': 'true',
'TreatWChar_tAsBuiltInType': 'true',
'UndefineAllPreprocessorDefinitions': 'true',
'UndefinePreprocessorDefinitions': 'd1;d2;d3',
'UseFullPaths': 'true',
'UsePrecompiledHeader': '1',
'UseUnicodeResponseFiles': 'true',
'WarnAsError': 'true',
'WarningLevel': '2',
'WholeProgramOptimization': 'true',
'XMLDocumentationFileName': 'a_file_name'},
'VCLinkerTool': {
'AdditionalDependencies': 'file1;file2;file3',
'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
'AdditionalLibraryDirectories_excluded': 'folder1;folder2;folder3',
'AdditionalManifestDependencies': 'file1;file2;file3',
'AdditionalOptions': 'a_string',
'AddModuleNamesToAssembly': 'file1;file2;file3',
'AllowIsolation': 'true',
'AssemblyDebug': '0',
'AssemblyLinkResource': 'file1;file2;file3',
'BaseAddress': 'a_string',
'CLRImageType': '1',
'CLRThreadAttribute': '2',
'CLRUnmanagedCodeCheck': 'true',
'DataExecutionPrevention': '0',
'DelayLoadDLLs': 'file1;file2;file3',
'DelaySign': 'true',
'Driver': '1',
'EmbedManagedResourceFile': 'file1;file2;file3',
'EnableCOMDATFolding': '0',
'EnableUAC': 'true',
'EntryPointSymbol': 'a_string',
'ErrorReporting': '0',
'FixedBaseAddress': '1',
'ForceSymbolReferences': 'file1;file2;file3',
'FunctionOrder': 'a_file_name',
'GenerateDebugInformation': 'true',
'GenerateManifest': 'true',
'GenerateMapFile': 'true',
'HeapCommitSize': 'a_string',
'HeapReserveSize': 'a_string',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreDefaultLibraryNames': 'file1;file2;file3',
'IgnoreEmbeddedIDL': 'true',
'IgnoreImportLibrary': 'true',
'ImportLibrary': 'a_file_name',
'KeyContainer': 'a_file_name',
'KeyFile': 'a_file_name',
'LargeAddressAware': '2',
'LinkIncremental': '1',
'LinkLibraryDependencies': 'true',
'LinkTimeCodeGeneration': '2',
'ManifestFile': 'a_file_name',
'MapExports': 'true',
'MapFileName': 'a_file_name',
'MergedIDLBaseFileName': 'a_file_name',
'MergeSections': 'a_string',
'MidlCommandFile': 'a_file_name',
'ModuleDefinitionFile': 'a_file_name',
'OptimizeForWindows98': '1',
'OptimizeReferences': '0',
'OutputFile': 'a_file_name',
'PerUserRedirection': 'true',
'Profile': 'true',
'ProfileGuidedDatabase': 'a_file_name',
'ProgramDatabaseFile': 'a_file_name',
'RandomizedBaseAddress': '1',
'RegisterOutput': 'true',
'ResourceOnlyDLL': 'true',
'SetChecksum': 'true',
'ShowProgress': '0',
'StackCommitSize': 'a_string',
'StackReserveSize': 'a_string',
'StripPrivateSymbols': 'a_file_name',
'SubSystem': '2',
'SupportUnloadOfDelayLoadedDLL': 'true',
'SuppressStartupBanner': 'true',
'SwapRunFromCD': 'true',
'SwapRunFromNet': 'true',
'TargetMachine': '3',
'TerminalServerAware': '2',
'TurnOffAssemblyGeneration': 'true',
'TypeLibraryFile': 'a_file_name',
'TypeLibraryResourceID': '33',
'UACExecutionLevel': '1',
'UACUIAccess': 'true',
'UseLibraryDependencyInputs': 'false',
'UseUnicodeResponseFiles': 'true',
'Version': 'a_string'},
'VCResourceCompilerTool': {
'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'Culture': '1003',
'IgnoreStandardIncludePath': 'true',
'PreprocessorDefinitions': 'd1;d2;d3',
'ResourceOutputFileName': 'a_string',
'ShowProgress': 'true',
'SuppressStartupBanner': 'true',
'UndefinePreprocessorDefinitions': 'd1;d2;d3'},
'VCMIDLTool': {
'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'CPreprocessOptions': 'a_string',
'DefaultCharType': '0',
'DLLDataFileName': 'a_file_name',
'EnableErrorChecks': '2',
'ErrorCheckAllocations': 'true',
'ErrorCheckBounds': 'true',
'ErrorCheckEnumRange': 'true',
'ErrorCheckRefPointers': 'true',
'ErrorCheckStubData': 'true',
'GenerateStublessProxies': 'true',
'GenerateTypeLibrary': 'true',
'HeaderFileName': 'a_file_name',
'IgnoreStandardIncludePath': 'true',
'InterfaceIdentifierFileName': 'a_file_name',
'MkTypLibCompatible': 'true',
'OutputDirectory': 'a_string',
'PreprocessorDefinitions': 'd1;d2;d3',
'ProxyFileName': 'a_file_name',
'RedirectOutputAndErrors': 'a_file_name',
'StructMemberAlignment': '3',
'SuppressStartupBanner': 'true',
'TargetEnvironment': '1',
'TypeLibraryName': 'a_file_name',
'UndefinePreprocessorDefinitions': 'd1;d2;d3',
'ValidateParameters': 'true',
'WarnAsError': 'true',
'WarningLevel': '4'},
'VCLibrarianTool': {
'AdditionalDependencies': 'file1;file2;file3',
'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
'AdditionalLibraryDirectories_excluded': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'ExportNamedFunctions': 'd1;d2;d3',
'ForceSymbolReferences': 'a_string',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreSpecificDefaultLibraries': 'file1;file2;file3',
'LinkLibraryDependencies': 'true',
'ModuleDefinitionFile': 'a_file_name',
'OutputFile': 'a_file_name',
'SuppressStartupBanner': 'true',
'UseUnicodeResponseFiles': 'true'},
'VCManifestTool': {
'AdditionalManifestFiles': 'file1;file2;file3',
'AdditionalOptions': 'a_string',
'AssemblyIdentity': 'a_string',
'ComponentFileName': 'a_file_name',
'DependencyInformationFile': 'a_file_name',
'EmbedManifest': 'true',
'GenerateCatalogFiles': 'true',
'InputResourceManifests': 'a_string',
'ManifestResourceFile': 'my_name',
'OutputManifestFile': 'a_file_name',
'RegistrarScriptFile': 'a_file_name',
'ReplacementsFile': 'a_file_name',
'SuppressStartupBanner': 'true',
'TypeLibraryFile': 'a_file_name',
'UpdateFileHashes': 'true',
'UpdateFileHashesSearchPath': 'a_file_name',
'UseFAT32Workaround': 'true',
'UseUnicodeResponseFiles': 'true',
'VerboseOutput': 'true'}}
expected_msbuild_settings = {
'ClCompile': {
'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string /J',
'AdditionalUsingDirectories': 'folder1;folder2;folder3',
'AssemblerListingLocation': 'a_file_name',
'AssemblerOutput': 'NoListing',
'BasicRuntimeChecks': 'StackFrameRuntimeCheck',
'BrowseInformation': 'true',
'BrowseInformationFile': 'a_file_name',
'BufferSecurityCheck': 'true',
'CallingConvention': 'Cdecl',
'CompileAs': 'CompileAsC',
'DebugInformationFormat': 'EditAndContinue',
'DisableLanguageExtensions': 'true',
'DisableSpecificWarnings': 'd1;d2;d3',
'EnableEnhancedInstructionSet': 'NotSet',
'EnableFiberSafeOptimizations': 'true',
'EnablePREfast': 'true',
'ErrorReporting': 'Prompt',
'ExceptionHandling': 'Async',
'ExpandAttributedSource': 'true',
'FavorSizeOrSpeed': 'Neither',
'FloatingPointExceptions': 'true',
'FloatingPointModel': 'Strict',
'ForceConformanceInForLoopScope': 'true',
'ForcedIncludeFiles': 'file1;file2;file3',
'ForcedUsingFiles': 'file1;file2;file3',
'FunctionLevelLinking': 'true',
'GenerateXMLDocumentationFiles': 'true',
'IgnoreStandardIncludePath': 'true',
'InlineFunctionExpansion': 'AnySuitable',
'IntrinsicFunctions': 'true',
'MinimalRebuild': 'true',
'ObjectFileName': 'a_file_name',
'OmitDefaultLibName': 'true',
'OmitFramePointers': 'true',
'OpenMPSupport': 'true',
'Optimization': 'Full',
'PrecompiledHeader': 'Create',
'PrecompiledHeaderFile': 'a_file_name',
'PrecompiledHeaderOutputFile': 'a_file_name',
'PreprocessKeepComments': 'true',
'PreprocessorDefinitions': 'd1;d2;d3',
'PreprocessSuppressLineNumbers': 'false',
'PreprocessToFile': 'true',
'ProgramDataBaseFileName': 'a_file_name',
'RuntimeLibrary': 'MultiThreaded',
'RuntimeTypeInfo': 'true',
'ShowIncludes': 'true',
'SmallerTypeCheck': 'true',
'StringPooling': 'true',
'StructMemberAlignment': '1Byte',
'SuppressStartupBanner': 'true',
'TreatWarningAsError': 'true',
'TreatWChar_tAsBuiltInType': 'true',
'UndefineAllPreprocessorDefinitions': 'true',
'UndefinePreprocessorDefinitions': 'd1;d2;d3',
'UseFullPaths': 'true',
'WarningLevel': 'Level2',
'WholeProgramOptimization': 'true',
'XMLDocumentationFileName': 'a_file_name'},
'Link': {
'AdditionalDependencies': 'file1;file2;file3',
'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
'AdditionalManifestDependencies': 'file1;file2;file3',
'AdditionalOptions': 'a_string',
'AddModuleNamesToAssembly': 'file1;file2;file3',
'AllowIsolation': 'true',
'AssemblyDebug': '',
'AssemblyLinkResource': 'file1;file2;file3',
'BaseAddress': 'a_string',
'CLRImageType': 'ForceIJWImage',
'CLRThreadAttribute': 'STAThreadingAttribute',
'CLRUnmanagedCodeCheck': 'true',
'DataExecutionPrevention': '',
'DelayLoadDLLs': 'file1;file2;file3',
'DelaySign': 'true',
'Driver': 'Driver',
'EmbedManagedResourceFile': 'file1;file2;file3',
'EnableCOMDATFolding': '',
'EnableUAC': 'true',
'EntryPointSymbol': 'a_string',
'FixedBaseAddress': 'false',
'ForceSymbolReferences': 'file1;file2;file3',
'FunctionOrder': 'a_file_name',
'GenerateDebugInformation': 'true',
'GenerateMapFile': 'true',
'HeapCommitSize': 'a_string',
'HeapReserveSize': 'a_string',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreEmbeddedIDL': 'true',
'IgnoreSpecificDefaultLibraries': 'file1;file2;file3',
'ImportLibrary': 'a_file_name',
'KeyContainer': 'a_file_name',
'KeyFile': 'a_file_name',
'LargeAddressAware': 'true',
'LinkErrorReporting': 'NoErrorReport',
'LinkTimeCodeGeneration': 'PGInstrument',
'ManifestFile': 'a_file_name',
'MapExports': 'true',
'MapFileName': 'a_file_name',
'MergedIDLBaseFileName': 'a_file_name',
'MergeSections': 'a_string',
'MidlCommandFile': 'a_file_name',
'ModuleDefinitionFile': 'a_file_name',
'NoEntryPoint': 'true',
'OptimizeReferences': '',
'OutputFile': 'a_file_name',
'PerUserRedirection': 'true',
'Profile': 'true',
'ProfileGuidedDatabase': 'a_file_name',
'ProgramDatabaseFile': 'a_file_name',
'RandomizedBaseAddress': 'false',
'RegisterOutput': 'true',
'SetChecksum': 'true',
'ShowProgress': 'NotSet',
'StackCommitSize': 'a_string',
'StackReserveSize': 'a_string',
'StripPrivateSymbols': 'a_file_name',
'SubSystem': 'Windows',
'SupportUnloadOfDelayLoadedDLL': 'true',
'SuppressStartupBanner': 'true',
'SwapRunFromCD': 'true',
'SwapRunFromNET': 'true',
'TargetMachine': 'MachineARM',
'TerminalServerAware': 'true',
'TurnOffAssemblyGeneration': 'true',
'TypeLibraryFile': 'a_file_name',
'TypeLibraryResourceID': '33',
'UACExecutionLevel': 'HighestAvailable',
'UACUIAccess': 'true',
'Version': 'a_string'},
'ResourceCompile': {
'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'Culture': '0x03eb',
'IgnoreStandardIncludePath': 'true',
'PreprocessorDefinitions': 'd1;d2;d3',
'ResourceOutputFileName': 'a_string',
'ShowProgress': 'true',
'SuppressStartupBanner': 'true',
'UndefinePreprocessorDefinitions': 'd1;d2;d3'},
'Midl': {
'AdditionalIncludeDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'CPreprocessOptions': 'a_string',
'DefaultCharType': 'Unsigned',
'DllDataFileName': 'a_file_name',
'EnableErrorChecks': 'All',
'ErrorCheckAllocations': 'true',
'ErrorCheckBounds': 'true',
'ErrorCheckEnumRange': 'true',
'ErrorCheckRefPointers': 'true',
'ErrorCheckStubData': 'true',
'GenerateStublessProxies': 'true',
'GenerateTypeLibrary': 'true',
'HeaderFileName': 'a_file_name',
'IgnoreStandardIncludePath': 'true',
'InterfaceIdentifierFileName': 'a_file_name',
'MkTypLibCompatible': 'true',
'OutputDirectory': 'a_string',
'PreprocessorDefinitions': 'd1;d2;d3',
'ProxyFileName': 'a_file_name',
'RedirectOutputAndErrors': 'a_file_name',
'StructMemberAlignment': '4',
'SuppressStartupBanner': 'true',
'TargetEnvironment': 'Win32',
'TypeLibraryName': 'a_file_name',
'UndefinePreprocessorDefinitions': 'd1;d2;d3',
'ValidateAllParameters': 'true',
'WarnAsError': 'true',
'WarningLevel': '4'},
'Lib': {
'AdditionalDependencies': 'file1;file2;file3',
'AdditionalLibraryDirectories': 'folder1;folder2;folder3',
'AdditionalOptions': 'a_string',
'ExportNamedFunctions': 'd1;d2;d3',
'ForceSymbolReferences': 'a_string',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreSpecificDefaultLibraries': 'file1;file2;file3',
'ModuleDefinitionFile': 'a_file_name',
'OutputFile': 'a_file_name',
'SuppressStartupBanner': 'true',
'UseUnicodeResponseFiles': 'true'},
'Manifest': {
'AdditionalManifestFiles': 'file1;file2;file3',
'AdditionalOptions': 'a_string',
'AssemblyIdentity': 'a_string',
'ComponentFileName': 'a_file_name',
'GenerateCatalogFiles': 'true',
'InputResourceManifests': 'a_string',
'OutputManifestFile': 'a_file_name',
'RegistrarScriptFile': 'a_file_name',
'ReplacementsFile': 'a_file_name',
'SuppressStartupBanner': 'true',
'TypeLibraryFile': 'a_file_name',
'UpdateFileHashes': 'true',
'UpdateFileHashesSearchPath': 'a_file_name',
'VerboseOutput': 'true'},
'ManifestResourceCompile': {
'ResourceOutputFileName': 'my_name'},
'ProjectReference': {
'LinkLibraryDependencies': 'true',
'UseLibraryDependencyInputs': 'false'},
'': {
'EmbedManifest': 'true',
'GenerateManifest': 'true',
'IgnoreImportLibrary': 'true',
'LinkIncremental': 'false'}}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings,
self.stderr)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
def testConvertToMSBuildSettings_actual(self):
"""Tests the conversion of an actual project.
A VS2008 project with most of the options defined was created through the
VS2008 IDE. It was then converted to VS2010. The tool settings found in
the .vcproj and .vcxproj files were converted to the two dictionaries
msvs_settings and expected_msbuild_settings.
Note that for many settings, the VS2010 converter adds macros like
%(AdditionalIncludeDirectories) to make sure than inherited values are
included. Since the Gyp projects we generate do not use inheritance,
we removed these macros. They were:
ClCompile:
AdditionalIncludeDirectories: ';%(AdditionalIncludeDirectories)'
AdditionalOptions: ' %(AdditionalOptions)'
AdditionalUsingDirectories: ';%(AdditionalUsingDirectories)'
DisableSpecificWarnings: ';%(DisableSpecificWarnings)',
ForcedIncludeFiles: ';%(ForcedIncludeFiles)',
ForcedUsingFiles: ';%(ForcedUsingFiles)',
PreprocessorDefinitions: ';%(PreprocessorDefinitions)',
UndefinePreprocessorDefinitions:
';%(UndefinePreprocessorDefinitions)',
Link:
AdditionalDependencies: ';%(AdditionalDependencies)',
AdditionalLibraryDirectories: ';%(AdditionalLibraryDirectories)',
AdditionalManifestDependencies:
';%(AdditionalManifestDependencies)',
AdditionalOptions: ' %(AdditionalOptions)',
AddModuleNamesToAssembly: ';%(AddModuleNamesToAssembly)',
AssemblyLinkResource: ';%(AssemblyLinkResource)',
DelayLoadDLLs: ';%(DelayLoadDLLs)',
EmbedManagedResourceFile: ';%(EmbedManagedResourceFile)',
ForceSymbolReferences: ';%(ForceSymbolReferences)',
IgnoreSpecificDefaultLibraries:
';%(IgnoreSpecificDefaultLibraries)',
ResourceCompile:
AdditionalIncludeDirectories: ';%(AdditionalIncludeDirectories)',
AdditionalOptions: ' %(AdditionalOptions)',
PreprocessorDefinitions: ';%(PreprocessorDefinitions)',
Manifest:
AdditionalManifestFiles: ';%(AdditionalManifestFiles)',
AdditionalOptions: ' %(AdditionalOptions)',
InputResourceManifests: ';%(InputResourceManifests)',
"""
msvs_settings = {
'VCCLCompilerTool': {
'AdditionalIncludeDirectories': 'dir1',
'AdditionalOptions': '/more',
'AdditionalUsingDirectories': 'test',
'AssemblerListingLocation': '$(IntDir)\\a',
'AssemblerOutput': '1',
'BasicRuntimeChecks': '3',
'BrowseInformation': '1',
'BrowseInformationFile': '$(IntDir)\\e',
'BufferSecurityCheck': 'false',
'CallingConvention': '1',
'CompileAs': '1',
'DebugInformationFormat': '4',
'DefaultCharIsUnsigned': 'true',
'Detect64BitPortabilityProblems': 'true',
'DisableLanguageExtensions': 'true',
'DisableSpecificWarnings': 'abc',
'EnableEnhancedInstructionSet': '1',
'EnableFiberSafeOptimizations': 'true',
'EnableFunctionLevelLinking': 'true',
'EnableIntrinsicFunctions': 'true',
'EnablePREfast': 'true',
'ErrorReporting': '2',
'ExceptionHandling': '2',
'ExpandAttributedSource': 'true',
'FavorSizeOrSpeed': '2',
'FloatingPointExceptions': 'true',
'FloatingPointModel': '1',
'ForceConformanceInForLoopScope': 'false',
'ForcedIncludeFiles': 'def',
'ForcedUsingFiles': 'ge',
'GeneratePreprocessedFile': '2',
'GenerateXMLDocumentationFiles': 'true',
'IgnoreStandardIncludePath': 'true',
'InlineFunctionExpansion': '1',
'KeepComments': 'true',
'MinimalRebuild': 'true',
'ObjectFile': '$(IntDir)\\b',
'OmitDefaultLibName': 'true',
'OmitFramePointers': 'true',
'OpenMP': 'true',
'Optimization': '3',
'PrecompiledHeaderFile': '$(IntDir)\\$(TargetName).pche',
'PrecompiledHeaderThrough': 'StdAfx.hd',
'PreprocessorDefinitions': 'WIN32;_DEBUG;_CONSOLE',
'ProgramDataBaseFileName': '$(IntDir)\\vc90b.pdb',
'RuntimeLibrary': '3',
'RuntimeTypeInfo': 'false',
'ShowIncludes': 'true',
'SmallerTypeCheck': 'true',
'StringPooling': 'true',
'StructMemberAlignment': '3',
'SuppressStartupBanner': 'false',
'TreatWChar_tAsBuiltInType': 'false',
'UndefineAllPreprocessorDefinitions': 'true',
'UndefinePreprocessorDefinitions': 'wer',
'UseFullPaths': 'true',
'UsePrecompiledHeader': '0',
'UseUnicodeResponseFiles': 'false',
'WarnAsError': 'true',
'WarningLevel': '3',
'WholeProgramOptimization': 'true',
'XMLDocumentationFileName': '$(IntDir)\\c'},
'VCLinkerTool': {
'AdditionalDependencies': 'zx',
'AdditionalLibraryDirectories': 'asd',
'AdditionalManifestDependencies': 's2',
'AdditionalOptions': '/mor2',
'AddModuleNamesToAssembly': 'd1',
'AllowIsolation': 'false',
'AssemblyDebug': '1',
'AssemblyLinkResource': 'd5',
'BaseAddress': '23423',
'CLRImageType': '3',
'CLRThreadAttribute': '1',
'CLRUnmanagedCodeCheck': 'true',
'DataExecutionPrevention': '0',
'DelayLoadDLLs': 'd4',
'DelaySign': 'true',
'Driver': '2',
'EmbedManagedResourceFile': 'd2',
'EnableCOMDATFolding': '1',
'EnableUAC': 'false',
'EntryPointSymbol': 'f5',
'ErrorReporting': '2',
'FixedBaseAddress': '1',
'ForceSymbolReferences': 'd3',
'FunctionOrder': 'fssdfsd',
'GenerateDebugInformation': 'true',
'GenerateManifest': 'false',
'GenerateMapFile': 'true',
'HeapCommitSize': '13',
'HeapReserveSize': '12',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreDefaultLibraryNames': 'flob;flok',
'IgnoreEmbeddedIDL': 'true',
'IgnoreImportLibrary': 'true',
'ImportLibrary': 'f4',
'KeyContainer': 'f7',
'KeyFile': 'f6',
'LargeAddressAware': '2',
'LinkIncremental': '0',
'LinkLibraryDependencies': 'false',
'LinkTimeCodeGeneration': '1',
'ManifestFile':
'$(IntDir)\\$(TargetFileName).2intermediate.manifest',
'MapExports': 'true',
'MapFileName': 'd5',
'MergedIDLBaseFileName': 'f2',
'MergeSections': 'f5',
'MidlCommandFile': 'f1',
'ModuleDefinitionFile': 'sdsd',
'OptimizeForWindows98': '2',
'OptimizeReferences': '2',
'OutputFile': '$(OutDir)\\$(ProjectName)2.exe',
'PerUserRedirection': 'true',
'Profile': 'true',
'ProfileGuidedDatabase': '$(TargetDir)$(TargetName).pgdd',
'ProgramDatabaseFile': 'Flob.pdb',
'RandomizedBaseAddress': '1',
'RegisterOutput': 'true',
'ResourceOnlyDLL': 'true',
'SetChecksum': 'false',
'ShowProgress': '1',
'StackCommitSize': '15',
'StackReserveSize': '14',
'StripPrivateSymbols': 'd3',
'SubSystem': '1',
'SupportUnloadOfDelayLoadedDLL': 'true',
'SuppressStartupBanner': 'false',
'SwapRunFromCD': 'true',
'SwapRunFromNet': 'true',
'TargetMachine': '1',
'TerminalServerAware': '1',
'TurnOffAssemblyGeneration': 'true',
'TypeLibraryFile': 'f3',
'TypeLibraryResourceID': '12',
'UACExecutionLevel': '2',
'UACUIAccess': 'true',
'UseLibraryDependencyInputs': 'true',
'UseUnicodeResponseFiles': 'false',
'Version': '333'},
'VCResourceCompilerTool': {
'AdditionalIncludeDirectories': 'f3',
'AdditionalOptions': '/more3',
'Culture': '3084',
'IgnoreStandardIncludePath': 'true',
'PreprocessorDefinitions': '_UNICODE;UNICODE2',
'ResourceOutputFileName': '$(IntDir)/$(InputName)3.res',
'ShowProgress': 'true'},
'VCManifestTool': {
'AdditionalManifestFiles': 'sfsdfsd',
'AdditionalOptions': 'afdsdafsd',
'AssemblyIdentity': 'sddfdsadfsa',
'ComponentFileName': 'fsdfds',
'DependencyInformationFile': '$(IntDir)\\mt.depdfd',
'EmbedManifest': 'false',
'GenerateCatalogFiles': 'true',
'InputResourceManifests': 'asfsfdafs',
'ManifestResourceFile':
'$(IntDir)\\$(TargetFileName).embed.manifest.resfdsf',
'OutputManifestFile': '$(TargetPath).manifestdfs',
'RegistrarScriptFile': 'sdfsfd',
'ReplacementsFile': 'sdffsd',
'SuppressStartupBanner': 'false',
'TypeLibraryFile': 'sfsd',
'UpdateFileHashes': 'true',
'UpdateFileHashesSearchPath': 'sfsd',
'UseFAT32Workaround': 'true',
'UseUnicodeResponseFiles': 'false',
'VerboseOutput': 'true'}}
expected_msbuild_settings = {
'ClCompile': {
'AdditionalIncludeDirectories': 'dir1',
'AdditionalOptions': '/more /J',
'AdditionalUsingDirectories': 'test',
'AssemblerListingLocation': '$(IntDir)a',
'AssemblerOutput': 'AssemblyCode',
'BasicRuntimeChecks': 'EnableFastChecks',
'BrowseInformation': 'true',
'BrowseInformationFile': '$(IntDir)e',
'BufferSecurityCheck': 'false',
'CallingConvention': 'FastCall',
'CompileAs': 'CompileAsC',
'DebugInformationFormat': 'EditAndContinue',
'DisableLanguageExtensions': 'true',
'DisableSpecificWarnings': 'abc',
'EnableEnhancedInstructionSet': 'StreamingSIMDExtensions',
'EnableFiberSafeOptimizations': 'true',
'EnablePREfast': 'true',
'ErrorReporting': 'Queue',
'ExceptionHandling': 'Async',
'ExpandAttributedSource': 'true',
'FavorSizeOrSpeed': 'Size',
'FloatingPointExceptions': 'true',
'FloatingPointModel': 'Strict',
'ForceConformanceInForLoopScope': 'false',
'ForcedIncludeFiles': 'def',
'ForcedUsingFiles': 'ge',
'FunctionLevelLinking': 'true',
'GenerateXMLDocumentationFiles': 'true',
'IgnoreStandardIncludePath': 'true',
'InlineFunctionExpansion': 'OnlyExplicitInline',
'IntrinsicFunctions': 'true',
'MinimalRebuild': 'true',
'ObjectFileName': '$(IntDir)b',
'OmitDefaultLibName': 'true',
'OmitFramePointers': 'true',
'OpenMPSupport': 'true',
'Optimization': 'Full',
'PrecompiledHeader': 'NotUsing', # Actual conversion gives ''
'PrecompiledHeaderFile': 'StdAfx.hd',
'PrecompiledHeaderOutputFile': '$(IntDir)$(TargetName).pche',
'PreprocessKeepComments': 'true',
'PreprocessorDefinitions': 'WIN32;_DEBUG;_CONSOLE',
'PreprocessSuppressLineNumbers': 'true',
'PreprocessToFile': 'true',
'ProgramDataBaseFileName': '$(IntDir)vc90b.pdb',
'RuntimeLibrary': 'MultiThreadedDebugDLL',
'RuntimeTypeInfo': 'false',
'ShowIncludes': 'true',
'SmallerTypeCheck': 'true',
'StringPooling': 'true',
'StructMemberAlignment': '4Bytes',
'SuppressStartupBanner': 'false',
'TreatWarningAsError': 'true',
'TreatWChar_tAsBuiltInType': 'false',
'UndefineAllPreprocessorDefinitions': 'true',
'UndefinePreprocessorDefinitions': 'wer',
'UseFullPaths': 'true',
'WarningLevel': 'Level3',
'WholeProgramOptimization': 'true',
'XMLDocumentationFileName': '$(IntDir)c'},
'Link': {
'AdditionalDependencies': 'zx',
'AdditionalLibraryDirectories': 'asd',
'AdditionalManifestDependencies': 's2',
'AdditionalOptions': '/mor2',
'AddModuleNamesToAssembly': 'd1',
'AllowIsolation': 'false',
'AssemblyDebug': 'true',
'AssemblyLinkResource': 'd5',
'BaseAddress': '23423',
'CLRImageType': 'ForceSafeILImage',
'CLRThreadAttribute': 'MTAThreadingAttribute',
'CLRUnmanagedCodeCheck': 'true',
'DataExecutionPrevention': '',
'DelayLoadDLLs': 'd4',
'DelaySign': 'true',
'Driver': 'UpOnly',
'EmbedManagedResourceFile': 'd2',
'EnableCOMDATFolding': 'false',
'EnableUAC': 'false',
'EntryPointSymbol': 'f5',
'FixedBaseAddress': 'false',
'ForceSymbolReferences': 'd3',
'FunctionOrder': 'fssdfsd',
'GenerateDebugInformation': 'true',
'GenerateMapFile': 'true',
'HeapCommitSize': '13',
'HeapReserveSize': '12',
'IgnoreAllDefaultLibraries': 'true',
'IgnoreEmbeddedIDL': 'true',
'IgnoreSpecificDefaultLibraries': 'flob;flok',
'ImportLibrary': 'f4',
'KeyContainer': 'f7',
'KeyFile': 'f6',
'LargeAddressAware': 'true',
'LinkErrorReporting': 'QueueForNextLogin',
'LinkTimeCodeGeneration': 'UseLinkTimeCodeGeneration',
'ManifestFile': '$(IntDir)$(TargetFileName).2intermediate.manifest',
'MapExports': 'true',
'MapFileName': 'd5',
'MergedIDLBaseFileName': 'f2',
'MergeSections': 'f5',
'MidlCommandFile': 'f1',
'ModuleDefinitionFile': 'sdsd',
'NoEntryPoint': 'true',
'OptimizeReferences': 'true',
'OutputFile': '$(OutDir)$(ProjectName)2.exe',
'PerUserRedirection': 'true',
'Profile': 'true',
'ProfileGuidedDatabase': '$(TargetDir)$(TargetName).pgdd',
'ProgramDatabaseFile': 'Flob.pdb',
'RandomizedBaseAddress': 'false',
'RegisterOutput': 'true',
'SetChecksum': 'false',
'ShowProgress': 'LinkVerbose',
'StackCommitSize': '15',
'StackReserveSize': '14',
'StripPrivateSymbols': 'd3',
'SubSystem': 'Console',
'SupportUnloadOfDelayLoadedDLL': 'true',
'SuppressStartupBanner': 'false',
'SwapRunFromCD': 'true',
'SwapRunFromNET': 'true',
'TargetMachine': 'MachineX86',
'TerminalServerAware': 'false',
'TurnOffAssemblyGeneration': 'true',
'TypeLibraryFile': 'f3',
'TypeLibraryResourceID': '12',
'UACExecutionLevel': 'RequireAdministrator',
'UACUIAccess': 'true',
'Version': '333'},
'ResourceCompile': {
'AdditionalIncludeDirectories': 'f3',
'AdditionalOptions': '/more3',
'Culture': '0x0c0c',
'IgnoreStandardIncludePath': 'true',
'PreprocessorDefinitions': '_UNICODE;UNICODE2',
'ResourceOutputFileName': '$(IntDir)%(Filename)3.res',
'ShowProgress': 'true'},
'Manifest': {
'AdditionalManifestFiles': 'sfsdfsd',
'AdditionalOptions': 'afdsdafsd',
'AssemblyIdentity': 'sddfdsadfsa',
'ComponentFileName': 'fsdfds',
'GenerateCatalogFiles': 'true',
'InputResourceManifests': 'asfsfdafs',
'OutputManifestFile': '$(TargetPath).manifestdfs',
'RegistrarScriptFile': 'sdfsfd',
'ReplacementsFile': 'sdffsd',
'SuppressStartupBanner': 'false',
'TypeLibraryFile': 'sfsd',
'UpdateFileHashes': 'true',
'UpdateFileHashesSearchPath': 'sfsd',
'VerboseOutput': 'true'},
'ProjectReference': {
'LinkLibraryDependencies': 'false',
'UseLibraryDependencyInputs': 'true'},
'': {
'EmbedManifest': 'false',
'GenerateManifest': 'false',
'IgnoreImportLibrary': 'true',
'LinkIncremental': ''
},
'ManifestResourceCompile': {
'ResourceOutputFileName':
'$(IntDir)$(TargetFileName).embed.manifest.resfdsf'}
}
actual_msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(
msvs_settings,
self.stderr)
self.assertEqual(expected_msbuild_settings, actual_msbuild_settings)
self._ExpectedWarnings([])
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5072,
2295,
367,
314,
13828,
5268,
14,
647,
570,
1041,
199,
199,
646,
5228,
199,
646,
2882,
199,
646,
4902,
14,
14206,
5268,
465,
13828,
5268,
421,
199,
533,
1379,
5826,
13967,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
3083,
275,
5228,
14,
6424,
342,
819,
347,
485,
6964,
15921,
8,
277,
12,
1420,
304,
272,
408,
2404,
11044,
18894,
2385,
370,
1420,
3598,
1041,
272,
291,
14,
3083,
14,
5507,
8,
16,
9,
272,
3503,
275,
291,
14,
3083,
14,
739,
1252,
1294,
2258,
78,
358,
272,
3503,
275,
359,
604,
367,
1004,
315,
3503,
340,
1004,
61,
272,
291,
14,
629,
8,
5917,
8,
2062,
395,
3355,
8,
6514,
430,
819,
347,
511,
12584,
14206,
5268,
63,
3557,
63,
1247,
8,
277,
304,
272,
408,
2925,
626,
1454,
13828,
4744,
1561,
787,
4370,
1041,
272,
13828,
5268,
14,
12584,
14206,
5268,
8,
267,
791,
9454,
27053,
356,
5479,
268,
283,
28101,
356,
5479,
268,
283,
54,
9249,
11505,
5157,
356,
5479,
268,
283,
1421,
356,
5479,
268,
283,
9454,
4031,
22993,
356,
5479,
268,
283,
24177,
1892,
82,
15289,
5157,
356,
5479,
268,
283,
9454,
11038,
5157,
356,
5479,
268,
283,
1968,
12626,
356,
20715,
267,
291,
14,
3083,
9,
272,
291,
423,
6964,
15921,
779,
267,
283,
3849,
26,
24718,
4744,
3925,
297,
267,
283,
3849,
26,
24718,
4744,
8465,
12626,
1105,
819,
347,
511,
12584,
14206,
5268,
63,
1751,
8,
277,
304,
272,
408,
2925,
626,
367,
3866,
13828,
2202,
1041,
272,
13828,
5268,
14,
12584,
14206,
5268,
8,
267,
791,
9454,
27053,
356,
469,
288,
283,
25336,
356,
283,
3741,
17,
27,
3741,
18,
297,
288,
283,
18862,
356,
788,
875,
17,
297,
283,
875,
18,
995,
288,
283,
8824,
10369,
13752,
356,
283,
3741,
17,
27,
3741,
18,
297,
288,
283,
31054,
82,
26138,
6592,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
31054,
82,
2959,
356,
283,
16,
297,
288,
283,
6845,
14357,
11834,
356,
283,
21,
297,
288,
283,
24149,
4935,
356,
283,
2592,
75,
2482,
74,
297,
288,
283,
24149,
4935,
1173,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
3299,
7676,
1799,
356,
283,
2052,
297,
288,
283,
23796,
714,
18803,
356,
2475,
17,
297,
288,
283,
12626,
2822,
356,
283,
17,
297,
288,
283,
7084,
4935,
3484,
356,
283,
18,
297,
288,
283,
2698,
1610,
1831,
25269,
356,
283,
2052,
297,
288,
283,
20064,
772,
4734,
4313,
3616,
919,
7561,
356,
283,
2052,
297,
288,
283,
13707,
8493,
10597,
356,
283,
2052,
297,
288,
283,
13707,
16786,
15921,
356,
283,
875,
17,
27,
875,
18,
297,
288,
283,
6476,
1327,
24384,
17700,
1084,
356,
283,
17,
297,
288,
283,
6476,
29721,
11090,
9867,
12270,
356,
283,
2052,
297,
288,
283,
6476,
3481,
4670,
3834,
316,
356,
283,
2052,
297,
288,
283,
6476,
3241,
24667,
9916,
13967,
356,
283,
2052,
297,
288,
283,
6476,
4225,
7015,
356,
283,
2052,
297,
288,
283,
6476,
657,
7015,
356,
283,
18665,
297,
288,
283,
547,
28457,
356,
283,
17,
297,
288,
283,
1726,
26443,
356,
283,
17,
297,
288,
283,
12839,
1271,
24855,
2980,
356,
283,
2052,
297,
288,
283,
24335,
2320,
2844,
15146,
356,
283,
17,
297,
288,
283,
17895,
3428,
16836,
356,
283,
2052,
297,
288,
283,
17895,
3428,
1685,
356,
283,
17,
297,
288,
283,
13606,
714,
11478,
607,
1858,
7382,
7812,
356,
283,
2052,
297,
288,
283,
30548,
7826,
5535,
356,
283,
493,
17,
27,
493,
18,
297,
288,
283,
30548,
10369,
5535,
356,
283,
493,
17,
27,
493,
18,
297,
288,
283,
6864,
2398,
7292,
1173,
356,
283,
17,
297,
288,
283,
6864,
4317,
17763,
5535,
356,
283,
2052,
297,
288,
283,
9495,
9232,
7826,
2042,
356,
283,
2052,
297,
288,
283,
10307,
3481,
26048,
356,
283,
17,
297,
288,
283,
18567,
18929,
356,
283,
2052,
297,
288,
283,
4649,
7265,
497,
1506,
356,
283,
2052,
297,
288,
283,
1692,
1173,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
47,
1147,
2698,
4728,
985,
356,
283,
2052,
297,
288,
283,
47,
1147,
3160,
1575,
11005,
356,
283,
2052,
297,
288,
283,
4299,
1658,
356,
283,
2052,
297,
288,
283,
30661,
356,
283,
17,
297,
288,
283,
25612,
1173,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
25612,
26732,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
20058,
356,
283,
875,
17,
27,
875,
18,
297,
288,
283,
9184,
1451,
1563,
7733,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
14357,
7424,
356,
283,
17,
297,
288,
283,
14357,
29136,
356,
283,
2052,
297,
288,
283,
6824,
22792,
356,
283,
2052,
297,
288,
283,
51,
2174,
1435,
804,
1799,
356,
283,
2052,
297,
288,
283,
1558,
22349,
356,
283,
2052,
297,
288,
283,
4836,
7021,
16613,
356,
283,
17,
297,
288,
283,
25511,
356,
283,
2052,
297,
288,
283,
29442,
55,
1610,
63,
84,
2822,
32406,
607,
804,
356,
283,
2052,
297,
288,
283,
31341,
2422,
20058,
356,
283,
2052,
297,
288,
283,
31341,
20058,
356,
283,
875,
17,
27,
875,
18,
297,
288,
283,
6119,
9042,
11804,
356,
283,
2052,
297,
288,
283,
6119,
25612,
356,
283,
17,
297,
288,
283,
6119,
7087,
2364,
5535,
356,
283,
2052,
297,
288,
283,
22673,
2822,
547,
356,
283,
2052,
297,
288,
283,
3849,
4670,
356,
283,
17,
297,
288,
283,
55,
16668,
9184,
30661,
356,
283,
2052,
297,
288,
283,
4317,
17763,
7733,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
9909,
16694,
356,
283,
18665,
2267,
268,
283,
28101,
356,
469,
1467,
283,
31780,
356,
283,
493,
17,
27,
493,
18,
297,
1467,
283,
31780,
63,
12144,
356,
283,
493,
19,
297,
1467,
283,
8824,
31636,
356,
283,
3741,
17,
27,
3741,
18,
297,
1467,
283,
8824,
11038,
11927,
356,
283,
493,
17,
27,
493,
18,
297,
1467,
283,
18862,
356
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5072,
2295,
367,
314,
13828,
5268,
14,
647,
570,
1041,
199,
199,
646,
5228,
199,
646,
2882,
199,
646,
4902,
14,
14206,
5268,
465,
13828,
5268,
421,
199,
533,
1379,
5826,
13967,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
3083,
275,
5228,
14,
6424,
342,
819,
347,
485,
6964,
15921,
8,
277,
12,
1420,
304,
272,
408,
2404,
11044,
18894,
2385,
370,
1420,
3598,
1041,
272,
291,
14,
3083,
14,
5507,
8,
16,
9,
272,
3503,
275,
291,
14,
3083,
14,
739,
1252,
1294,
2258,
78,
358,
272,
3503,
275,
359,
604,
367,
1004,
315,
3503,
340,
1004,
61,
272,
291,
14,
629,
8,
5917,
8,
2062,
395,
3355,
8,
6514,
430,
819,
347,
511,
12584,
14206,
5268,
63,
3557,
63,
1247,
8,
277,
304,
272,
408,
2925,
626,
1454,
13828,
4744,
1561,
787,
4370,
1041,
272,
13828,
5268,
14,
12584,
14206,
5268,
8,
267,
791,
9454,
27053,
356,
5479,
268,
283,
28101,
356,
5479,
268,
283,
54,
9249,
11505,
5157,
356,
5479,
268,
283,
1421,
356,
5479,
268,
283,
9454,
4031,
22993,
356,
5479,
268,
283,
24177,
1892,
82,
15289,
5157,
356,
5479,
268,
283,
9454,
11038,
5157,
356,
5479,
268,
283,
1968,
12626,
356,
20715,
267,
291,
14,
3083,
9,
272,
291,
423,
6964,
15921,
779,
267,
283,
3849,
26,
24718,
4744,
3925,
297,
267,
283,
3849,
26,
24718,
4744,
8465,
12626,
1105,
819,
347,
511,
12584,
14206,
5268,
63,
1751,
8,
277,
304,
272,
408,
2925,
626,
367,
3866,
13828,
2202,
1041,
272,
13828,
5268,
14,
12584,
14206,
5268,
8,
267,
791,
9454,
27053,
356,
469,
288,
283,
25336,
356,
283,
3741,
17,
27,
3741,
18,
297,
288,
283,
18862,
356,
788,
875,
17,
297,
283,
875,
18,
995,
288,
283,
8824,
10369,
13752,
356,
283,
3741,
17,
27,
3741,
18,
297,
288,
283,
31054,
82,
26138,
6592,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
31054,
82,
2959,
356,
283,
16,
297,
288,
283,
6845,
14357,
11834,
356,
283,
21,
297,
288,
283,
24149,
4935,
356,
283,
2592,
75,
2482,
74,
297,
288,
283,
24149,
4935,
1173,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
3299,
7676,
1799,
356,
283,
2052,
297,
288,
283,
23796,
714,
18803,
356,
2475,
17,
297,
288,
283,
12626,
2822,
356,
283,
17,
297,
288,
283,
7084,
4935,
3484,
356,
283,
18,
297,
288,
283,
2698,
1610,
1831,
25269,
356,
283,
2052,
297,
288,
283,
20064,
772,
4734,
4313,
3616,
919,
7561,
356,
283,
2052,
297,
288,
283,
13707,
8493,
10597,
356,
283,
2052,
297,
288,
283,
13707,
16786,
15921,
356,
283,
875,
17,
27,
875,
18,
297,
288,
283,
6476,
1327,
24384,
17700,
1084,
356,
283,
17,
297,
288,
283,
6476,
29721,
11090,
9867,
12270,
356,
283,
2052,
297,
288,
283,
6476,
3481,
4670,
3834,
316,
356,
283,
2052,
297,
288,
283,
6476,
3241,
24667,
9916,
13967,
356,
283,
2052,
297,
288,
283,
6476,
4225,
7015,
356,
283,
2052,
297,
288,
283,
6476,
657,
7015,
356,
283,
18665,
297,
288,
283,
547,
28457,
356,
283,
17,
297,
288,
283,
1726,
26443,
356,
283,
17,
297,
288,
283,
12839,
1271,
24855,
2980,
356,
283,
2052,
297,
288,
283,
24335,
2320,
2844,
15146,
356,
283,
17,
297,
288,
283,
17895,
3428,
16836,
356,
283,
2052,
297,
288,
283,
17895,
3428,
1685,
356,
283,
17,
297,
288,
283,
13606,
714,
11478,
607,
1858,
7382,
7812,
356,
283,
2052,
297,
288,
283,
30548,
7826,
5535,
356,
283,
493,
17,
27,
493,
18,
297,
288,
283,
30548,
10369,
5535,
356,
283,
493,
17,
27,
493,
18,
297,
288,
283,
6864,
2398,
7292,
1173,
356,
283,
17,
297,
288,
283,
6864,
4317,
17763,
5535,
356,
283,
2052,
297,
288,
283,
9495,
9232,
7826,
2042,
356,
283,
2052,
297,
288,
283,
10307,
3481,
26048,
356,
283,
17,
297,
288,
283,
18567,
18929,
356,
283,
2052,
297,
288,
283,
4649,
7265,
497,
1506,
356,
283,
2052,
297,
288,
283,
1692,
1173,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
47,
1147,
2698,
4728,
985,
356,
283,
2052,
297,
288,
283,
47,
1147,
3160,
1575,
11005,
356,
283,
2052,
297,
288,
283,
4299,
1658,
356,
283,
2052,
297,
288,
283,
30661,
356,
283,
17,
297,
288,
283,
25612,
1173,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
25612,
26732,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
20058,
356,
283,
875,
17,
27,
875,
18,
297,
288,
283,
9184,
1451,
1563,
7733,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
14357,
7424,
356,
283,
17,
297,
288,
283,
14357,
29136,
356,
283,
2052,
297,
288,
283,
6824,
22792,
356,
283,
2052,
297,
288,
283,
51,
2174,
1435,
804,
1799,
356,
283,
2052,
297,
288,
283,
1558,
22349,
356,
283,
2052,
297,
288,
283,
4836,
7021,
16613,
356,
283,
17,
297,
288,
283,
25511,
356,
283,
2052,
297,
288,
283,
29442,
55,
1610,
63,
84,
2822,
32406,
607,
804,
356,
283,
2052,
297,
288,
283,
31341,
2422,
20058,
356,
283,
2052,
297,
288,
283,
31341,
20058,
356,
283,
875,
17,
27,
875,
18,
297,
288,
283,
6119,
9042,
11804,
356,
283,
2052,
297,
288,
283,
6119,
25612,
356,
283,
17,
297,
288,
283,
6119,
7087,
2364,
5535,
356,
283,
2052,
297,
288,
283,
22673,
2822,
547,
356,
283,
2052,
297,
288,
283,
3849,
4670,
356,
283,
17,
297,
288,
283,
55,
16668,
9184,
30661,
356,
283,
2052,
297,
288,
283,
4317,
17763,
7733,
356,
283,
65,
63,
493,
63,
354,
297,
288,
283,
9909,
16694,
356,
283,
18665,
2267,
268,
283,
28101,
356,
469,
1467,
283,
31780,
356,
283,
493,
17,
27,
493,
18,
297,
1467,
283,
31780,
63,
12144,
356,
283,
493,
19,
297,
1467,
283,
8824,
31636,
356,
283,
3741,
17,
27,
3741,
18,
297,
1467,
283,
8824,
11038,
11927,
356,
283,
493,
17,
27,
493,
18,
297,
1467,
283,
18862,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
prefetchnta/questlab
|
bin/x64bin/python/37/Lib/ctypes/util.py
|
1
|
13437
|
import os
import shutil
import subprocess
import sys
# find_library(name) returns the pathname of a library, or None.
if os.name == "nt":
def _get_build_version():
"""Return the version of MSVC that was used to build Python.
For Python 2.3 and up, the version number is included in
sys.version. For earlier versions, assume the compiler is MSVC 6.
"""
# This function was copied from Lib/distutils/msvccompiler.py
prefix = "MSC v."
i = sys.version.find(prefix)
if i == -1:
return 6
i = i + len(prefix)
s, rest = sys.version[i:].split(" ", 1)
majorVersion = int(s[:-2]) - 6
if majorVersion >= 13:
majorVersion += 1
minorVersion = int(s[2:3]) / 10.0
# I don't think paths are affected by minor version in version 6
if majorVersion == 6:
minorVersion = 0
if majorVersion >= 6:
return majorVersion + minorVersion
# else we don't know what version of the compiler this is
return None
def find_msvcrt():
"""Return the name of the VC runtime dll"""
version = _get_build_version()
if version is None:
# better be safe than sorry
return None
if version <= 6:
clibname = 'msvcrt'
elif version <= 13:
clibname = 'msvcr%d' % (version * 10)
else:
# CRT is no longer directly loadable. See issue23606 for the
# discussion about alternative approaches.
return None
# If python was built with in debug mode
import importlib.machinery
if '_d.pyd' in importlib.machinery.EXTENSION_SUFFIXES:
clibname += 'd'
return clibname+'.dll'
def find_library(name):
if name in ('c', 'm'):
return find_msvcrt()
# See MSDN for the REAL search order.
for directory in os.environ['PATH'].split(os.pathsep):
fname = os.path.join(directory, name)
if os.path.isfile(fname):
return fname
if fname.lower().endswith(".dll"):
continue
fname = fname + ".dll"
if os.path.isfile(fname):
return fname
return None
elif os.name == "posix" and sys.platform == "darwin":
from ctypes.macholib.dyld import dyld_find as _dyld_find
def find_library(name):
possible = ['lib%s.dylib' % name,
'%s.dylib' % name,
'%s.framework/%s' % (name, name)]
for name in possible:
try:
return _dyld_find(name)
except ValueError:
continue
return None
elif sys.platform.startswith("aix"):
# AIX has two styles of storing shared libraries
# GNU auto_tools refer to these as svr4 and aix
# svr4 (System V Release 4) is a regular file, often with .so as suffix
# AIX style uses an archive (suffix .a) with members (e.g., shr.o, libssl.so)
# see issue#26439 and _aix.py for more details
from ctypes._aix import find_library
elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile
def _findLib_gcc(name):
# Run GCC's linker with the -t (aka --trace) option and examine the
# library name it prints out. The GCC command will fail because we
# haven't supplied a proper program with main(), but that does not
# matter.
expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
c_compiler = shutil.which('gcc')
if not c_compiler:
c_compiler = shutil.which('cc')
if not c_compiler:
# No C compiler available, give up
return None
temp = tempfile.NamedTemporaryFile()
try:
args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
env = dict(os.environ)
env['LC_ALL'] = 'C'
env['LANG'] = 'C'
try:
proc = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=env)
except OSError: # E.g. bad executable
return None
with proc:
trace = proc.stdout.read()
finally:
try:
temp.close()
except FileNotFoundError:
# Raised if the file was already removed, which is the normal
# behaviour of GCC if linking fails
pass
res = re.search(expr, trace)
if not res:
return None
return os.fsdecode(res.group(0))
if sys.platform == "sunos5":
# use /usr/ccs/bin/dump on solaris
def _get_soname(f):
if not f:
return None
try:
proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
except OSError: # E.g. command not found
return None
with proc:
data = proc.stdout.read()
res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
if not res:
return None
return os.fsdecode(res.group(1))
else:
def _get_soname(f):
# assuming GNU binutils / ELF
if not f:
return None
objdump = shutil.which('objdump')
if not objdump:
# objdump is not available, give up
return None
try:
proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
except OSError: # E.g. bad executable
return None
with proc:
dump = proc.stdout.read()
res = re.search(br'\sSONAME\s+([^\s]+)', dump)
if not res:
return None
return os.fsdecode(res.group(1))
if sys.platform.startswith(("freebsd", "openbsd", "dragonfly")):
def _num_version(libname):
# "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
parts = libname.split(b".")
nums = []
try:
while parts:
nums.insert(0, int(parts.pop()))
except ValueError:
pass
return nums or [sys.maxsize]
def find_library(name):
ename = re.escape(name)
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
expr = os.fsencode(expr)
try:
proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
except OSError: # E.g. command not found
data = b''
else:
with proc:
data = proc.stdout.read()
res = re.findall(expr, data)
if not res:
return _get_soname(_findLib_gcc(name))
res.sort(key=_num_version)
return os.fsdecode(res[-1])
elif sys.platform == "sunos5":
def _findLib_crle(name, is64):
if not os.path.exists('/usr/bin/crle'):
return None
env = dict(os.environ)
env['LC_ALL'] = 'C'
if is64:
args = ('/usr/bin/crle', '-64')
else:
args = ('/usr/bin/crle',)
paths = None
try:
proc = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
env=env)
except OSError: # E.g. bad executable
return None
with proc:
for line in proc.stdout:
line = line.strip()
if line.startswith(b'Default Library Path (ELF):'):
paths = os.fsdecode(line).split()[4]
if not paths:
return None
for dir in paths.split(":"):
libfile = os.path.join(dir, "lib%s.so" % name)
if os.path.exists(libfile):
return libfile
return None
def find_library(name, is64 = False):
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
else:
def _findSoname_ldconfig(name):
import struct
if struct.calcsize('l') == 4:
machine = os.uname().machine + '-32'
else:
machine = os.uname().machine + '-64'
mach_map = {
'x86_64-64': 'libc6,x86-64',
'ppc64-64': 'libc6,64bit',
'sparc64-64': 'libc6,64bit',
's390x-64': 'libc6,64bit',
'ia64-64': 'libc6,IA-64',
}
abi_type = mach_map.get(machine, 'libc6')
# XXX assuming GLIBC's ldconfig (with option -p)
regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
regex = os.fsencode(regex % (re.escape(name), abi_type))
try:
with subprocess.Popen(['/sbin/ldconfig', '-p'],
stdin=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdout=subprocess.PIPE,
env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
res = re.search(regex, p.stdout.read())
if res:
return os.fsdecode(res.group(1))
except OSError:
pass
def _findLib_ld(name):
# See issue #9998 for why this is needed
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
cmd = ['ld', '-t']
libpath = os.environ.get('LD_LIBRARY_PATH')
if libpath:
for d in libpath.split(':'):
cmd.extend(['-L', d])
cmd.extend(['-o', os.devnull, '-l%s' % name])
result = None
try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
out, _ = p.communicate()
res = re.search(expr, os.fsdecode(out))
if res:
result = res.group(0)
except Exception as e:
pass # result will be None
return result
def find_library(name):
# See issue #9998
return _findSoname_ldconfig(name) or \
_get_soname(_findLib_gcc(name) or _findLib_ld(name))
################################################################
# test code
def test():
from ctypes import cdll
if os.name == "nt":
print(cdll.msvcrt)
print(cdll.load("msvcrt"))
print(find_library("msvcrt"))
if os.name == "posix":
# find and load_version
print(find_library("m"))
print(find_library("c"))
print(find_library("bz2"))
# load
if sys.platform == "darwin":
print(cdll.LoadLibrary("libm.dylib"))
print(cdll.LoadLibrary("libcrypto.dylib"))
print(cdll.LoadLibrary("libSystem.dylib"))
print(cdll.LoadLibrary("System.framework/System"))
# issue-26439 - fix broken test call for AIX
elif sys.platform.startswith("aix"):
from ctypes import CDLL
if sys.maxsize < 2**32:
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}")
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}")
# librpm.so is only available as 32-bit shared library
print(find_library("rpm"))
print(cdll.LoadLibrary("librpm.so"))
else:
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}")
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}")
print(f"crypt\t:: {find_library('crypt')}")
print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}")
print(f"crypto\t:: {find_library('crypto')}")
print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}")
else:
print(cdll.LoadLibrary("libm.so"))
print(cdll.LoadLibrary("libcrypt.so"))
print(find_library("crypt"))
if __name__ == "__main__":
test()
|
lgpl-2.1
|
[
646,
747,
202,
199,
646,
5145,
202,
199,
646,
3873,
202,
199,
646,
984,
2999,
199,
3,
2342,
63,
4342,
8,
354,
9,
2529,
314,
11776,
402,
282,
3555,
12,
503,
488,
14,
202,
199,
692,
747,
14,
354,
508,
298,
343,
582,
2958,
347,
485,
362,
63,
1506,
63,
1023,
837,
1039,
408,
1767,
314,
1015,
402,
11694,
35,
626,
1990,
1202,
370,
1900,
2018,
14,
4341,
2104,
2018,
499,
14,
19,
436,
1536,
12,
314,
1015,
1329,
365,
5120,
315,
1039,
984,
14,
1023,
14,
221,
2104,
14119,
5459,
12,
5534,
314,
6365,
365,
11694,
35,
1227,
14,
1039,
408,
1039,
327,
961,
805,
1990,
8876,
687,
8003,
15,
13350,
15,
19875,
5772,
14,
647,
1039,
2403,
275,
298,
3053,
35,
373,
2122,
1039,
284,
275,
984,
14,
1023,
14,
1623,
8,
1861,
9,
1039,
340,
284,
508,
446,
17,
26,
1675,
372,
1227,
1039,
284,
275,
284,
435,
822,
8,
1861,
9,
1039,
308,
12,
4618,
275,
984,
14,
1023,
59,
73,
11455,
1294,
480,
3872,
413,
9,
1039,
12160,
3353,
275,
1109,
8,
83,
4439,
18,
566,
446,
1227,
1039,
340,
12160,
3353,
2356,
4944,
26,
1675,
12160,
3353,
847,
413,
1039,
12612,
3353,
275,
1109,
8,
83,
59,
18,
26,
19,
566,
1182,
1616,
14,
16,
1039,
327,
473,
2793,
1133,
13516,
3792,
787,
16955,
701,
12612,
1015,
315,
1015,
1227,
1039,
340,
12160,
3353,
508,
1227,
26,
1675,
12612,
3353,
275,
378,
1039,
340,
12160,
3353,
2356,
1227,
26,
1675,
372,
12160,
3353,
435,
12612,
3353,
1039,
327,
587,
781,
2793,
1133,
5715,
4052,
1015,
402,
314,
6365,
642,
365,
1039,
372,
488,
2958,
347,
2342,
63,
706,
86,
16617,
837,
1039,
408,
1767,
314,
536,
402,
314,
24955,
8836,
17112,
624,
1039,
1015,
275,
485,
362,
63,
1506,
63,
1023,
342,
1039,
340,
1015,
365,
488,
26,
1675,
327,
8034,
506,
5048,
2419,
308,
21342,
1675,
372,
488,
1039,
340,
1015,
2695,
1227,
26,
1675,
286,
773,
354,
275,
283,
706,
86,
16617,
7,
1039,
916,
1015,
2695,
4944,
26,
1675,
286,
773,
354,
275,
283,
706,
86,
1556,
5,
68,
7,
450,
334,
1023,
627,
1616,
9,
1039,
587,
26,
1675,
327,
445,
11876,
365,
949,
8088,
5370,
32519,
14,
1666,
4976,
10008,
1690,
367,
314,
1675,
327,
16582,
3595,
13943,
18140,
397,
14,
1675,
372,
488,
4341,
327,
982,
2366,
1990,
6137,
543,
315,
3105,
818,
1039,
492,
14802,
14,
14121,
20067,
1039,
340,
2513,
68,
14,
647,
68,
7,
315,
14802,
14,
14121,
20067,
14,
15498,
63,
12273,
654,
26,
1675,
286,
773,
354,
847,
283,
68,
7,
1039,
372,
286,
773,
354,
18098,
9259,
7,
2958,
347,
2342,
63,
4342,
8,
354,
304,
1039,
340,
536,
315,
661,
67,
297,
283,
77,
735,
1675,
372,
2342,
63,
706,
86,
16617,
342,
1039,
327,
1666,
603,
3693,
46,
367,
314,
5363,
748,
2754,
1865,
14,
1039,
367,
2082,
315,
747,
14,
2314,
459,
3243,
2278,
1294,
8,
736,
14,
17843,
304,
1675,
6748,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
536,
9,
1675,
340,
747,
14,
515,
14,
6292,
8,
5252,
304,
2628,
372,
6748,
1675,
340,
6748,
14,
2325,
1252,
4130,
9520,
9259,
2349,
2628,
1980,
1675,
6748,
275,
6748,
435,
3680,
9259,
2,
1675,
340,
747,
14,
515,
14,
6292,
8,
5252,
304,
2628,
372,
6748,
1039,
372,
488,
2999,
199,
4164,
747,
14,
354,
508,
298,
9228,
2,
436,
984,
14,
3246,
508,
298,
13245,
582,
1128,
687,
5577,
14,
391,
2239,
773,
14,
8161,
1447,
492,
13119,
1447,
63,
1623,
465,
485,
8161,
1447,
63,
1623,
1128,
347,
2342,
63,
4342,
8,
354,
304,
1039,
3962,
275,
788,
773,
5,
83,
14,
22305,
7,
450,
536,
12,
4906,
1543,
83,
14,
22305,
7,
450,
536,
12,
4906,
1543,
83,
14,
4857,
3149,
83,
7,
450,
334,
354,
12,
536,
1874,
1039,
367,
536,
315,
3962,
26,
1675,
862,
26,
2628,
372,
485,
8161,
1447,
63,
1623,
8,
354,
9,
1675,
871,
1722,
26,
2628,
1980,
1039,
372,
488,
2999,
199,
4164,
984,
14,
3246,
14,
2460,
480,
65,
1148,
2349,
1128,
327,
437,
3867,
965,
2877,
15725,
402,
16915,
5709,
8363,
1128,
327,
1664,
2599,
63,
2537,
10618,
370,
3520,
465,
308,
10922,
20,
436,
282,
1148,
1128,
327,
308,
10922,
20,
334,
3989,
812,
17646,
841,
9,
365,
282,
5578,
570,
12,
14115,
543,
1275,
1152,
465,
4739,
1128,
327,
437,
3867,
3449,
4440,
376,
6359,
334,
4511,
1275,
65,
9,
543,
7556,
334,
69,
14,
71,
2020,
1033,
82,
14,
79,
12,
1973,
4266,
14,
1152,
9,
1128,
327,
1937,
4976,
3,
9408,
1355,
436,
485,
65,
1148,
14,
647,
367,
1655,
2436,
2958,
687,
5577,
423,
65,
1148,
492,
2342,
63,
4342,
2999,
199,
4164,
747,
14,
354,
508,
298,
9228,
582,
1128,
327,
6061,
264,
305,
1487,
836,
84,
1159,
2342,
3423,
12,
1808,
19443,
12,
1182,
21457,
15,
1447,
888,
12,
1559,
2724,
1128,
492,
295,
12,
5549,
2958,
347,
485,
1623,
4728,
63,
13112,
8,
354,
304,
1039,
327,
3378,
598,
2571,
1159,
17261,
543,
314,
446,
84,
334,
24685,
1553,
3446,
9,
945,
436,
31758,
314,
1039,
327,
3555,
536,
652,
14767,
734,
14,
710,
598,
2571,
1414,
911,
2449,
2952,
781,
1039,
327,
19051,
1133,
6841,
282,
5576,
2240,
543,
2446,
1062,
1325,
626,
1630,
440,
1039,
327,
17247,
14,
1039,
5348,
275,
747,
14,
70,
2464,
600,
8,
82,
29538,
2961,
2862,
83,
3672,
773,
5,
83,
4537,
16045,
2961,
2862,
83,
3672,
7,
450,
295,
14,
3765,
8,
354,
430,
4341,
286,
63,
5772,
275,
5145,
14,
6777,
360,
13112,
358,
1039,
340,
440,
286,
63,
5772,
26,
1675,
286,
63,
5772,
275,
5145,
14,
6777,
360,
2055,
358,
1039,
340,
440,
286,
63,
5772,
26,
1675,
327,
3091,
445,
6365,
2808,
12,
8120,
1536,
1675,
372,
488,
4341,
2388,
275,
5549,
14,
19320,
342,
1039,
862,
26,
1675,
1249,
275,
359,
67,
63,
5772,
12,
2475,
16239,
3057,
84,
297,
2475,
79,
297,
2388,
14,
354,
12,
2475,
76,
7,
435,
536,
61,
11556,
2589,
275,
1211,
8,
736,
14,
2314,
9,
1675,
2589,
459,
7027,
63,
1761,
418,
275,
283,
35,
7,
1675,
2589,
459,
7442
] |
[
747,
202,
199,
646,
5145,
202,
199,
646,
3873,
202,
199,
646,
984,
2999,
199,
3,
2342,
63,
4342,
8,
354,
9,
2529,
314,
11776,
402,
282,
3555,
12,
503,
488,
14,
202,
199,
692,
747,
14,
354,
508,
298,
343,
582,
2958,
347,
485,
362,
63,
1506,
63,
1023,
837,
1039,
408,
1767,
314,
1015,
402,
11694,
35,
626,
1990,
1202,
370,
1900,
2018,
14,
4341,
2104,
2018,
499,
14,
19,
436,
1536,
12,
314,
1015,
1329,
365,
5120,
315,
1039,
984,
14,
1023,
14,
221,
2104,
14119,
5459,
12,
5534,
314,
6365,
365,
11694,
35,
1227,
14,
1039,
408,
1039,
327,
961,
805,
1990,
8876,
687,
8003,
15,
13350,
15,
19875,
5772,
14,
647,
1039,
2403,
275,
298,
3053,
35,
373,
2122,
1039,
284,
275,
984,
14,
1023,
14,
1623,
8,
1861,
9,
1039,
340,
284,
508,
446,
17,
26,
1675,
372,
1227,
1039,
284,
275,
284,
435,
822,
8,
1861,
9,
1039,
308,
12,
4618,
275,
984,
14,
1023,
59,
73,
11455,
1294,
480,
3872,
413,
9,
1039,
12160,
3353,
275,
1109,
8,
83,
4439,
18,
566,
446,
1227,
1039,
340,
12160,
3353,
2356,
4944,
26,
1675,
12160,
3353,
847,
413,
1039,
12612,
3353,
275,
1109,
8,
83,
59,
18,
26,
19,
566,
1182,
1616,
14,
16,
1039,
327,
473,
2793,
1133,
13516,
3792,
787,
16955,
701,
12612,
1015,
315,
1015,
1227,
1039,
340,
12160,
3353,
508,
1227,
26,
1675,
12612,
3353,
275,
378,
1039,
340,
12160,
3353,
2356,
1227,
26,
1675,
372,
12160,
3353,
435,
12612,
3353,
1039,
327,
587,
781,
2793,
1133,
5715,
4052,
1015,
402,
314,
6365,
642,
365,
1039,
372,
488,
2958,
347,
2342,
63,
706,
86,
16617,
837,
1039,
408,
1767,
314,
536,
402,
314,
24955,
8836,
17112,
624,
1039,
1015,
275,
485,
362,
63,
1506,
63,
1023,
342,
1039,
340,
1015,
365,
488,
26,
1675,
327,
8034,
506,
5048,
2419,
308,
21342,
1675,
372,
488,
1039,
340,
1015,
2695,
1227,
26,
1675,
286,
773,
354,
275,
283,
706,
86,
16617,
7,
1039,
916,
1015,
2695,
4944,
26,
1675,
286,
773,
354,
275,
283,
706,
86,
1556,
5,
68,
7,
450,
334,
1023,
627,
1616,
9,
1039,
587,
26,
1675,
327,
445,
11876,
365,
949,
8088,
5370,
32519,
14,
1666,
4976,
10008,
1690,
367,
314,
1675,
327,
16582,
3595,
13943,
18140,
397,
14,
1675,
372,
488,
4341,
327,
982,
2366,
1990,
6137,
543,
315,
3105,
818,
1039,
492,
14802,
14,
14121,
20067,
1039,
340,
2513,
68,
14,
647,
68,
7,
315,
14802,
14,
14121,
20067,
14,
15498,
63,
12273,
654,
26,
1675,
286,
773,
354,
847,
283,
68,
7,
1039,
372,
286,
773,
354,
18098,
9259,
7,
2958,
347,
2342,
63,
4342,
8,
354,
304,
1039,
340,
536,
315,
661,
67,
297,
283,
77,
735,
1675,
372,
2342,
63,
706,
86,
16617,
342,
1039,
327,
1666,
603,
3693,
46,
367,
314,
5363,
748,
2754,
1865,
14,
1039,
367,
2082,
315,
747,
14,
2314,
459,
3243,
2278,
1294,
8,
736,
14,
17843,
304,
1675,
6748,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
536,
9,
1675,
340,
747,
14,
515,
14,
6292,
8,
5252,
304,
2628,
372,
6748,
1675,
340,
6748,
14,
2325,
1252,
4130,
9520,
9259,
2349,
2628,
1980,
1675,
6748,
275,
6748,
435,
3680,
9259,
2,
1675,
340,
747,
14,
515,
14,
6292,
8,
5252,
304,
2628,
372,
6748,
1039,
372,
488,
2999,
199,
4164,
747,
14,
354,
508,
298,
9228,
2,
436,
984,
14,
3246,
508,
298,
13245,
582,
1128,
687,
5577,
14,
391,
2239,
773,
14,
8161,
1447,
492,
13119,
1447,
63,
1623,
465,
485,
8161,
1447,
63,
1623,
1128,
347,
2342,
63,
4342,
8,
354,
304,
1039,
3962,
275,
788,
773,
5,
83,
14,
22305,
7,
450,
536,
12,
4906,
1543,
83,
14,
22305,
7,
450,
536,
12,
4906,
1543,
83,
14,
4857,
3149,
83,
7,
450,
334,
354,
12,
536,
1874,
1039,
367,
536,
315,
3962,
26,
1675,
862,
26,
2628,
372,
485,
8161,
1447,
63,
1623,
8,
354,
9,
1675,
871,
1722,
26,
2628,
1980,
1039,
372,
488,
2999,
199,
4164,
984,
14,
3246,
14,
2460,
480,
65,
1148,
2349,
1128,
327,
437,
3867,
965,
2877,
15725,
402,
16915,
5709,
8363,
1128,
327,
1664,
2599,
63,
2537,
10618,
370,
3520,
465,
308,
10922,
20,
436,
282,
1148,
1128,
327,
308,
10922,
20,
334,
3989,
812,
17646,
841,
9,
365,
282,
5578,
570,
12,
14115,
543,
1275,
1152,
465,
4739,
1128,
327,
437,
3867,
3449,
4440,
376,
6359,
334,
4511,
1275,
65,
9,
543,
7556,
334,
69,
14,
71,
2020,
1033,
82,
14,
79,
12,
1973,
4266,
14,
1152,
9,
1128,
327,
1937,
4976,
3,
9408,
1355,
436,
485,
65,
1148,
14,
647,
367,
1655,
2436,
2958,
687,
5577,
423,
65,
1148,
492,
2342,
63,
4342,
2999,
199,
4164,
747,
14,
354,
508,
298,
9228,
582,
1128,
327,
6061,
264,
305,
1487,
836,
84,
1159,
2342,
3423,
12,
1808,
19443,
12,
1182,
21457,
15,
1447,
888,
12,
1559,
2724,
1128,
492,
295,
12,
5549,
2958,
347,
485,
1623,
4728,
63,
13112,
8,
354,
304,
1039,
327,
3378,
598,
2571,
1159,
17261,
543,
314,
446,
84,
334,
24685,
1553,
3446,
9,
945,
436,
31758,
314,
1039,
327,
3555,
536,
652,
14767,
734,
14,
710,
598,
2571,
1414,
911,
2449,
2952,
781,
1039,
327,
19051,
1133,
6841,
282,
5576,
2240,
543,
2446,
1062,
1325,
626,
1630,
440,
1039,
327,
17247,
14,
1039,
5348,
275,
747,
14,
70,
2464,
600,
8,
82,
29538,
2961,
2862,
83,
3672,
773,
5,
83,
4537,
16045,
2961,
2862,
83,
3672,
7,
450,
295,
14,
3765,
8,
354,
430,
4341,
286,
63,
5772,
275,
5145,
14,
6777,
360,
13112,
358,
1039,
340,
440,
286,
63,
5772,
26,
1675,
286,
63,
5772,
275,
5145,
14,
6777,
360,
2055,
358,
1039,
340,
440,
286,
63,
5772,
26,
1675,
327,
3091,
445,
6365,
2808,
12,
8120,
1536,
1675,
372,
488,
4341,
2388,
275,
5549,
14,
19320,
342,
1039,
862,
26,
1675,
1249,
275,
359,
67,
63,
5772,
12,
2475,
16239,
3057,
84,
297,
2475,
79,
297,
2388,
14,
354,
12,
2475,
76,
7,
435,
536,
61,
11556,
2589,
275,
1211,
8,
736,
14,
2314,
9,
1675,
2589,
459,
7027,
63,
1761,
418,
275,
283,
35,
7,
1675,
2589,
459,
7442,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maftieu/CouchPotatoServer
|
libs/dateutil/relativedelta.py
|
216
|
17224
|
"""
Copyright (c) 2003-2010 Gustavo Niemeyer <gustavo@niemeyer.net>
This module offers extensions to the standard Python
datetime module.
"""
__license__ = "Simplified BSD"
import datetime
import calendar
from six import integer_types
__all__ = ["relativedelta", "MO", "TU", "WE", "TH", "FR", "SA", "SU"]
class weekday(object):
__slots__ = ["weekday", "n"]
def __init__(self, weekday, n=None):
self.weekday = weekday
self.n = n
def __call__(self, n):
if n == self.n:
return self
else:
return self.__class__(self.weekday, n)
def __eq__(self, other):
try:
if self.weekday != other.weekday or self.n != other.n:
return False
except AttributeError:
return False
return True
def __repr__(self):
s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
if not self.n:
return s
else:
return "%s(%+d)" % (s, self.n)
MO, TU, WE, TH, FR, SA, SU = weekdays = tuple([weekday(x) for x in range(7)])
class relativedelta(object):
"""
The relativedelta type is based on the specification of the excelent
work done by M.-A. Lemburg in his mx.DateTime extension. However,
notice that this type does *NOT* implement the same algorithm as
his work. Do *NOT* expect it to behave like mx.DateTime's counterpart.
There's two different ways to build a relativedelta instance. The
first one is passing it two date/datetime classes:
relativedelta(datetime1, datetime2)
And the other way is to use the following keyword arguments:
year, month, day, hour, minute, second, microsecond:
Absolute information.
years, months, weeks, days, hours, minutes, seconds, microseconds:
Relative information, may be negative.
weekday:
One of the weekday instances (MO, TU, etc). These instances may
receive a parameter N, specifying the Nth weekday, which could
be positive or negative (like MO(+1) or MO(-2). Not specifying
it is the same as specifying +1. You can also use an integer,
where 0=MO.
leapdays:
Will add given days to the date found, if year is a leap
year, and the date found is post 28 of february.
yearday, nlyearday:
Set the yearday or the non-leap year day (jump leap days).
These are converted to day/month/leapdays information.
Here is the behavior of operations with relativedelta:
1) Calculate the absolute year, using the 'year' argument, or the
original datetime year, if the argument is not present.
2) Add the relative 'years' argument to the absolute year.
3) Do steps 1 and 2 for month/months.
4) Calculate the absolute day, using the 'day' argument, or the
original datetime day, if the argument is not present. Then,
subtract from the day until it fits in the year and month
found after their operations.
5) Add the relative 'days' argument to the absolute day. Notice
that the 'weeks' argument is multiplied by 7 and added to
'days'.
6) Do steps 1 and 2 for hour/hours, minute/minutes, second/seconds,
microsecond/microseconds.
7) If the 'weekday' argument is present, calculate the weekday,
with the given (wday, nth) tuple. wday is the index of the
weekday (0-6, 0=Mon), and nth is the number of weeks to add
forward or backward, depending on its signal. Notice that if
the calculated date is already Monday, for example, using
(0, 1) or (0, -1) won't change the day.
"""
def __init__(self, dt1=None, dt2=None,
years=0, months=0, days=0, leapdays=0, weeks=0,
hours=0, minutes=0, seconds=0, microseconds=0,
year=None, month=None, day=None, weekday=None,
yearday=None, nlyearday=None,
hour=None, minute=None, second=None, microsecond=None):
if dt1 and dt2:
if (not isinstance(dt1, datetime.date)) or (not isinstance(dt2, datetime.date)):
raise TypeError("relativedelta only diffs datetime/date")
if not type(dt1) == type(dt2): #isinstance(dt1, type(dt2)):
if not isinstance(dt1, datetime.datetime):
dt1 = datetime.datetime.fromordinal(dt1.toordinal())
elif not isinstance(dt2, datetime.datetime):
dt2 = datetime.datetime.fromordinal(dt2.toordinal())
self.years = 0
self.months = 0
self.days = 0
self.leapdays = 0
self.hours = 0
self.minutes = 0
self.seconds = 0
self.microseconds = 0
self.year = None
self.month = None
self.day = None
self.weekday = None
self.hour = None
self.minute = None
self.second = None
self.microsecond = None
self._has_time = 0
months = (dt1.year*12+dt1.month)-(dt2.year*12+dt2.month)
self._set_months(months)
dtm = self.__radd__(dt2)
if dt1 < dt2:
while dt1 > dtm:
months += 1
self._set_months(months)
dtm = self.__radd__(dt2)
else:
while dt1 < dtm:
months -= 1
self._set_months(months)
dtm = self.__radd__(dt2)
delta = dt1 - dtm
self.seconds = delta.seconds+delta.days*86400
self.microseconds = delta.microseconds
else:
self.years = years
self.months = months
self.days = days+weeks*7
self.leapdays = leapdays
self.hours = hours
self.minutes = minutes
self.seconds = seconds
self.microseconds = microseconds
self.year = year
self.month = month
self.day = day
self.hour = hour
self.minute = minute
self.second = second
self.microsecond = microsecond
if isinstance(weekday, integer_types):
self.weekday = weekdays[weekday]
else:
self.weekday = weekday
yday = 0
if nlyearday:
yday = nlyearday
elif yearday:
yday = yearday
if yearday > 59:
self.leapdays = -1
if yday:
ydayidx = [31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 366]
for idx, ydays in enumerate(ydayidx):
if yday <= ydays:
self.month = idx+1
if idx == 0:
self.day = yday
else:
self.day = yday-ydayidx[idx-1]
break
else:
raise ValueError("invalid year day (%d)" % yday)
self._fix()
def _fix(self):
if abs(self.microseconds) > 999999:
s = self.microseconds//abs(self.microseconds)
div, mod = divmod(self.microseconds*s, 1000000)
self.microseconds = mod*s
self.seconds += div*s
if abs(self.seconds) > 59:
s = self.seconds//abs(self.seconds)
div, mod = divmod(self.seconds*s, 60)
self.seconds = mod*s
self.minutes += div*s
if abs(self.minutes) > 59:
s = self.minutes//abs(self.minutes)
div, mod = divmod(self.minutes*s, 60)
self.minutes = mod*s
self.hours += div*s
if abs(self.hours) > 23:
s = self.hours//abs(self.hours)
div, mod = divmod(self.hours*s, 24)
self.hours = mod*s
self.days += div*s
if abs(self.months) > 11:
s = self.months//abs(self.months)
div, mod = divmod(self.months*s, 12)
self.months = mod*s
self.years += div*s
if (self.hours or self.minutes or self.seconds or self.microseconds or
self.hour is not None or self.minute is not None or
self.second is not None or self.microsecond is not None):
self._has_time = 1
else:
self._has_time = 0
def _set_months(self, months):
self.months = months
if abs(self.months) > 11:
s = self.months//abs(self.months)
div, mod = divmod(self.months*s, 12)
self.months = mod*s
self.years = div*s
else:
self.years = 0
def __add__(self, other):
if isinstance(other, relativedelta):
return relativedelta(years=other.years+self.years,
months=other.months+self.months,
days=other.days+self.days,
hours=other.hours+self.hours,
minutes=other.minutes+self.minutes,
seconds=other.seconds+self.seconds,
microseconds=other.microseconds+self.microseconds,
leapdays=other.leapdays or self.leapdays,
year=other.year or self.year,
month=other.month or self.month,
day=other.day or self.day,
weekday=other.weekday or self.weekday,
hour=other.hour or self.hour,
minute=other.minute or self.minute,
second=other.second or self.second,
microsecond=other.microsecond or self.microsecond)
if not isinstance(other, datetime.date):
raise TypeError("unsupported type for add operation")
elif self._has_time and not isinstance(other, datetime.datetime):
other = datetime.datetime.fromordinal(other.toordinal())
year = (self.year or other.year)+self.years
month = self.month or other.month
if self.months:
assert 1 <= abs(self.months) <= 12
month += self.months
if month > 12:
year += 1
month -= 12
elif month < 1:
year -= 1
month += 12
day = min(calendar.monthrange(year, month)[1],
self.day or other.day)
repl = {"year": year, "month": month, "day": day}
for attr in ["hour", "minute", "second", "microsecond"]:
value = getattr(self, attr)
if value is not None:
repl[attr] = value
days = self.days
if self.leapdays and month > 2 and calendar.isleap(year):
days += self.leapdays
ret = (other.replace(**repl)
+ datetime.timedelta(days=days,
hours=self.hours,
minutes=self.minutes,
seconds=self.seconds,
microseconds=self.microseconds))
if self.weekday:
weekday, nth = self.weekday.weekday, self.weekday.n or 1
jumpdays = (abs(nth)-1)*7
if nth > 0:
jumpdays += (7-ret.weekday()+weekday)%7
else:
jumpdays += (ret.weekday()-weekday)%7
jumpdays *= -1
ret += datetime.timedelta(days=jumpdays)
return ret
def __radd__(self, other):
return self.__add__(other)
def __rsub__(self, other):
return self.__neg__().__radd__(other)
def __sub__(self, other):
if not isinstance(other, relativedelta):
raise TypeError("unsupported type for sub operation")
return relativedelta(years=self.years-other.years,
months=self.months-other.months,
days=self.days-other.days,
hours=self.hours-other.hours,
minutes=self.minutes-other.minutes,
seconds=self.seconds-other.seconds,
microseconds=self.microseconds-other.microseconds,
leapdays=self.leapdays or other.leapdays,
year=self.year or other.year,
month=self.month or other.month,
day=self.day or other.day,
weekday=self.weekday or other.weekday,
hour=self.hour or other.hour,
minute=self.minute or other.minute,
second=self.second or other.second,
microsecond=self.microsecond or other.microsecond)
def __neg__(self):
return relativedelta(years=-self.years,
months=-self.months,
days=-self.days,
hours=-self.hours,
minutes=-self.minutes,
seconds=-self.seconds,
microseconds=-self.microseconds,
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
def __bool__(self):
return not (not self.years and
not self.months and
not self.days and
not self.hours and
not self.minutes and
not self.seconds and
not self.microseconds and
not self.leapdays and
self.year is None and
self.month is None and
self.day is None and
self.weekday is None and
self.hour is None and
self.minute is None and
self.second is None and
self.microsecond is None)
def __mul__(self, other):
f = float(other)
return relativedelta(years=int(self.years*f),
months=int(self.months*f),
days=int(self.days*f),
hours=int(self.hours*f),
minutes=int(self.minutes*f),
seconds=int(self.seconds*f),
microseconds=int(self.microseconds*f),
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
__rmul__ = __mul__
def __eq__(self, other):
if not isinstance(other, relativedelta):
return False
if self.weekday or other.weekday:
if not self.weekday or not other.weekday:
return False
if self.weekday.weekday != other.weekday.weekday:
return False
n1, n2 = self.weekday.n, other.weekday.n
if n1 != n2 and not ((not n1 or n1 == 1) and (not n2 or n2 == 1)):
return False
return (self.years == other.years and
self.months == other.months and
self.days == other.days and
self.hours == other.hours and
self.minutes == other.minutes and
self.seconds == other.seconds and
self.leapdays == other.leapdays and
self.year == other.year and
self.month == other.month and
self.day == other.day and
self.hour == other.hour and
self.minute == other.minute and
self.second == other.second and
self.microsecond == other.microsecond)
def __ne__(self, other):
return not self.__eq__(other)
def __div__(self, other):
return self.__mul__(1/float(other))
__truediv__ = __div__
def __repr__(self):
l = []
for attr in ["years", "months", "days", "leapdays",
"hours", "minutes", "seconds", "microseconds"]:
value = getattr(self, attr)
if value:
l.append("%s=%+d" % (attr, value))
for attr in ["year", "month", "day", "weekday",
"hour", "minute", "second", "microsecond"]:
value = getattr(self, attr)
if value is not None:
l.append("%s=%s" % (attr, repr(value)))
return "%s(%s)" % (self.__class__.__name__, ", ".join(l))
# vim:ts=4:sw=4:et
|
gpl-3.0
|
[
624,
199,
7384,
334,
67,
9,
13004,
13,
6542,
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,
363,
1682,
363,
275,
298,
51,
3236,
30200,
6289,
2,
199,
199,
646,
2197,
199,
646,
11234,
199,
199,
504,
3816,
492,
3000,
63,
1313,
199,
199,
363,
452,
363,
275,
2097,
32300,
401,
298,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
937,
199,
199,
533,
20947,
8,
785,
304,
272,
636,
7257,
363,
275,
2097,
12451,
401,
298,
78,
937,
339,
347,
636,
826,
721,
277,
12,
20947,
12,
302,
29,
403,
304,
267,
291,
14,
12451,
275,
20947,
267,
291,
14,
78,
275,
302,
339,
347,
636,
1250,
721,
277,
12,
302,
304,
267,
340,
302,
508,
291,
14,
78,
26,
288,
372,
291,
267,
587,
26,
288,
372,
291,
855,
533,
721,
277,
14,
12451,
12,
302,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
862,
26,
288,
340,
291,
14,
12451,
1137,
1163,
14,
12451,
503,
291,
14,
78,
1137,
1163,
14,
78,
26,
355,
372,
756,
267,
871,
4281,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
1689,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
9981,
277,
14,
12451,
61,
267,
340,
440,
291,
14,
78,
26,
288,
372,
308,
267,
587,
26,
288,
372,
2071,
83,
4042,
11,
68,
2924,
450,
334,
83,
12,
291,
14,
78,
9,
199,
199,
2679,
12,
377,
53,
12,
644,
37,
12,
4221,
12,
28671,
12,
13950,
12,
5698,
275,
8620,
4899,
275,
2008,
779,
12451,
8,
88,
9,
367,
671,
315,
1425,
8,
23,
3948,
199,
199,
533,
20599,
8,
785,
304,
272,
408,
199,
1918,
20599,
730,
365,
4079,
641,
314,
8929,
402,
314,
11553,
12518,
199,
800,
4224,
701,
603,
23683,
33,
14,
7005,
32649,
315,
17049,
8728,
14,
3926,
3329,
14,
9738,
12,
199,
20556,
626,
642,
730,
1630,
627,
4609,
10,
5669,
314,
2011,
5563,
465,
199,
866,
1736,
14,
4226,
627,
4609,
10,
4282,
652,
370,
24062,
2839,
8728,
14,
3926,
1159,
7055,
2064,
14,
199,
199,
10924,
1159,
2877,
3365,
15217,
370,
1900,
282,
20599,
1256,
14,
710,
199,
2246,
1373,
365,
9476,
652,
2877,
1434,
15,
2083,
3992,
26,
339,
20599,
8,
2083,
17,
12,
2197,
18,
9,
199,
199,
3325,
314,
1163,
4340,
365,
370,
675,
314,
2569,
4252,
2368,
26,
339,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
12,
25824,
26,
267,
24964,
2556,
14,
339,
17399,
12,
20096,
12,
29540,
12,
7609,
12,
10857,
12,
9395,
12,
4696,
12,
21574,
26,
267,
22419,
2556,
12,
1443,
506,
6946,
14,
339,
20947,
26,
267,
7309,
402,
314,
20947,
4454,
334,
2679,
12,
377,
53,
12,
5423,
680,
5723,
4454,
1443,
267,
9128,
282,
2725,
653,
12,
9176,
314,
653,
273,
20947,
12,
1314,
4293,
267,
506,
7317,
503,
6946,
334,
2930,
10362,
24303,
17,
9,
503,
10362,
2801,
18,
680,
2832,
9176,
267,
652,
365,
314,
2011,
465,
9176,
435,
17,
14,
2047,
883,
2597,
675,
376,
3000,
12,
267,
2382,
378,
29,
2679,
14,
339,
29487,
4899,
26,
267,
12823,
1050,
1627,
7609,
370,
314,
1434,
1911,
12,
340,
5361,
365,
282,
29487,
267,
5361,
12,
436,
314,
1434,
1911,
365,
2963,
7294,
402,
1964,
3289,
20527,
14,
339,
5361,
2977,
12,
302,
590,
2210,
2977,
26,
267,
2494,
314,
5361,
2977,
503,
314,
2222,
13,
28764,
5361,
5382,
334,
11126,
29487,
7609,
680,
267,
5723,
787,
6702,
370,
5382,
15,
4482,
15,
28764,
4899,
2556,
14,
199,
199,
21741,
365,
314,
5953,
402,
5331,
543,
20599,
26,
199,
199,
17,
9,
12707,
314,
3679,
5361,
12,
1808,
314,
283,
3403,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5361,
12,
340,
314,
1423,
365,
440,
3451,
14,
199,
199,
18,
9,
2654,
314,
3847,
283,
18431,
7,
1423,
370,
314,
3679,
5361,
14,
199,
199,
19,
9,
4226,
7124,
413,
436,
499,
367,
5794,
15,
16745,
14,
199,
199,
20,
9,
12707,
314,
3679,
5382,
12,
1808,
314,
283,
2977,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5382,
12,
340,
314,
1423,
365,
440,
3451,
14,
9442,
12,
2043,
24129,
687,
314,
5382,
5133,
652,
20147,
315,
314,
5361,
436,
5794,
2043,
1911,
2410,
3932,
5331,
14,
199,
199,
21,
9,
2654,
314,
3847,
283,
4899,
7,
1423,
370,
314,
3679,
5382,
14,
3091,
3548,
2043,
626,
314,
283,
25287,
7,
1423,
365,
29597,
701,
1520,
436,
3483,
370,
2043,
283,
4899,
1370,
199,
199,
22,
9,
4226,
7124,
413,
436,
499,
367,
6925,
15,
8419,
12,
12709,
15,
10430,
12,
3499,
15,
4515,
12,
2043,
25824,
15,
18144,
14,
199,
199,
23,
9,
982,
314,
283,
12451,
7,
1423,
365,
3451,
12,
8671,
314,
20947,
12,
2043,
543,
314,
1627,
334,
87,
2977,
12,
30564,
9,
2008,
14,
336,
2977,
365,
314,
1478,
402,
314,
2043,
20947,
334,
16,
13,
22,
12,
378,
29,
6671,
395,
436,
30564,
365,
314,
1329,
402,
29540,
370,
1050,
2043,
7568,
503,
13388,
12,
10298,
641,
2399,
4673,
14,
3091,
3548,
626,
340,
2043,
314,
12950,
1434,
365,
2575,
32740,
12,
367,
2893,
12,
1808,
2043,
334,
16,
12,
413,
9,
503,
334,
16,
12,
446,
17,
9,
7859,
1133,
1570,
314,
5382,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4487,
17,
29,
403,
12,
4487,
18,
29,
403,
12,
326,
17399,
29,
16,
12,
20096,
29,
16,
12,
7609,
29,
16,
12,
29487,
4899,
29,
16,
12,
29540,
29,
16,
12,
326,
10857,
29,
16,
12,
9395,
29,
16,
12,
4696,
29,
16,
12,
21574,
29,
16,
12,
326,
5361,
29,
403,
12,
5794,
29,
403,
12,
5382,
29,
403,
12,
20947,
29,
403,
12,
326,
5361,
2977,
29,
403,
12,
302,
590,
2210,
2977,
29,
403,
12,
326,
6925,
29,
403,
12,
12709,
29,
403,
12,
3499,
29,
403
] |
[
199,
7384,
334,
67,
9,
13004,
13,
6542,
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,
363,
1682,
363,
275,
298,
51,
3236,
30200,
6289,
2,
199,
199,
646,
2197,
199,
646,
11234,
199,
199,
504,
3816,
492,
3000,
63,
1313,
199,
199,
363,
452,
363,
275,
2097,
32300,
401,
298,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
937,
199,
199,
533,
20947,
8,
785,
304,
272,
636,
7257,
363,
275,
2097,
12451,
401,
298,
78,
937,
339,
347,
636,
826,
721,
277,
12,
20947,
12,
302,
29,
403,
304,
267,
291,
14,
12451,
275,
20947,
267,
291,
14,
78,
275,
302,
339,
347,
636,
1250,
721,
277,
12,
302,
304,
267,
340,
302,
508,
291,
14,
78,
26,
288,
372,
291,
267,
587,
26,
288,
372,
291,
855,
533,
721,
277,
14,
12451,
12,
302,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
862,
26,
288,
340,
291,
14,
12451,
1137,
1163,
14,
12451,
503,
291,
14,
78,
1137,
1163,
14,
78,
26,
355,
372,
756,
267,
871,
4281,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
1689,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
9981,
277,
14,
12451,
61,
267,
340,
440,
291,
14,
78,
26,
288,
372,
308,
267,
587,
26,
288,
372,
2071,
83,
4042,
11,
68,
2924,
450,
334,
83,
12,
291,
14,
78,
9,
199,
199,
2679,
12,
377,
53,
12,
644,
37,
12,
4221,
12,
28671,
12,
13950,
12,
5698,
275,
8620,
4899,
275,
2008,
779,
12451,
8,
88,
9,
367,
671,
315,
1425,
8,
23,
3948,
199,
199,
533,
20599,
8,
785,
304,
272,
408,
199,
1918,
20599,
730,
365,
4079,
641,
314,
8929,
402,
314,
11553,
12518,
199,
800,
4224,
701,
603,
23683,
33,
14,
7005,
32649,
315,
17049,
8728,
14,
3926,
3329,
14,
9738,
12,
199,
20556,
626,
642,
730,
1630,
627,
4609,
10,
5669,
314,
2011,
5563,
465,
199,
866,
1736,
14,
4226,
627,
4609,
10,
4282,
652,
370,
24062,
2839,
8728,
14,
3926,
1159,
7055,
2064,
14,
199,
199,
10924,
1159,
2877,
3365,
15217,
370,
1900,
282,
20599,
1256,
14,
710,
199,
2246,
1373,
365,
9476,
652,
2877,
1434,
15,
2083,
3992,
26,
339,
20599,
8,
2083,
17,
12,
2197,
18,
9,
199,
199,
3325,
314,
1163,
4340,
365,
370,
675,
314,
2569,
4252,
2368,
26,
339,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
12,
25824,
26,
267,
24964,
2556,
14,
339,
17399,
12,
20096,
12,
29540,
12,
7609,
12,
10857,
12,
9395,
12,
4696,
12,
21574,
26,
267,
22419,
2556,
12,
1443,
506,
6946,
14,
339,
20947,
26,
267,
7309,
402,
314,
20947,
4454,
334,
2679,
12,
377,
53,
12,
5423,
680,
5723,
4454,
1443,
267,
9128,
282,
2725,
653,
12,
9176,
314,
653,
273,
20947,
12,
1314,
4293,
267,
506,
7317,
503,
6946,
334,
2930,
10362,
24303,
17,
9,
503,
10362,
2801,
18,
680,
2832,
9176,
267,
652,
365,
314,
2011,
465,
9176,
435,
17,
14,
2047,
883,
2597,
675,
376,
3000,
12,
267,
2382,
378,
29,
2679,
14,
339,
29487,
4899,
26,
267,
12823,
1050,
1627,
7609,
370,
314,
1434,
1911,
12,
340,
5361,
365,
282,
29487,
267,
5361,
12,
436,
314,
1434,
1911,
365,
2963,
7294,
402,
1964,
3289,
20527,
14,
339,
5361,
2977,
12,
302,
590,
2210,
2977,
26,
267,
2494,
314,
5361,
2977,
503,
314,
2222,
13,
28764,
5361,
5382,
334,
11126,
29487,
7609,
680,
267,
5723,
787,
6702,
370,
5382,
15,
4482,
15,
28764,
4899,
2556,
14,
199,
199,
21741,
365,
314,
5953,
402,
5331,
543,
20599,
26,
199,
199,
17,
9,
12707,
314,
3679,
5361,
12,
1808,
314,
283,
3403,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5361,
12,
340,
314,
1423,
365,
440,
3451,
14,
199,
199,
18,
9,
2654,
314,
3847,
283,
18431,
7,
1423,
370,
314,
3679,
5361,
14,
199,
199,
19,
9,
4226,
7124,
413,
436,
499,
367,
5794,
15,
16745,
14,
199,
199,
20,
9,
12707,
314,
3679,
5382,
12,
1808,
314,
283,
2977,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5382,
12,
340,
314,
1423,
365,
440,
3451,
14,
9442,
12,
2043,
24129,
687,
314,
5382,
5133,
652,
20147,
315,
314,
5361,
436,
5794,
2043,
1911,
2410,
3932,
5331,
14,
199,
199,
21,
9,
2654,
314,
3847,
283,
4899,
7,
1423,
370,
314,
3679,
5382,
14,
3091,
3548,
2043,
626,
314,
283,
25287,
7,
1423,
365,
29597,
701,
1520,
436,
3483,
370,
2043,
283,
4899,
1370,
199,
199,
22,
9,
4226,
7124,
413,
436,
499,
367,
6925,
15,
8419,
12,
12709,
15,
10430,
12,
3499,
15,
4515,
12,
2043,
25824,
15,
18144,
14,
199,
199,
23,
9,
982,
314,
283,
12451,
7,
1423,
365,
3451,
12,
8671,
314,
20947,
12,
2043,
543,
314,
1627,
334,
87,
2977,
12,
30564,
9,
2008,
14,
336,
2977,
365,
314,
1478,
402,
314,
2043,
20947,
334,
16,
13,
22,
12,
378,
29,
6671,
395,
436,
30564,
365,
314,
1329,
402,
29540,
370,
1050,
2043,
7568,
503,
13388,
12,
10298,
641,
2399,
4673,
14,
3091,
3548,
626,
340,
2043,
314,
12950,
1434,
365,
2575,
32740,
12,
367,
2893,
12,
1808,
2043,
334,
16,
12,
413,
9,
503,
334,
16,
12,
446,
17,
9,
7859,
1133,
1570,
314,
5382,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4487,
17,
29,
403,
12,
4487,
18,
29,
403,
12,
326,
17399,
29,
16,
12,
20096,
29,
16,
12,
7609,
29,
16,
12,
29487,
4899,
29,
16,
12,
29540,
29,
16,
12,
326,
10857,
29,
16,
12,
9395,
29,
16,
12,
4696,
29,
16,
12,
21574,
29,
16,
12,
326,
5361,
29,
403,
12,
5794,
29,
403,
12,
5382,
29,
403,
12,
20947,
29,
403,
12,
326,
5361,
2977,
29,
403,
12,
302,
590,
2210,
2977,
29,
403,
12,
326,
6925,
29,
403,
12,
12709,
29,
403,
12,
3499,
29,
403,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Gamecredits-Universe/Gamecredits-electrum-client
|
lib/msqr.py
|
59
|
2368
|
# from http://eli.thegreenplace.net/2009/03/07/computing-modular-square-roots-in-python/
def modular_sqrt(a, p):
""" Find a quadratic residue (mod p) of 'a'. p
must be an odd prime.
Solve the congruence of the form:
x^2 = a (mod p)
And returns x. Note that p - x is also a root.
0 is returned is no square root exists for
these a and p.
The Tonelli-Shanks algorithm is used (except
for some simple cases in which the solution
is known from an identity). This algorithm
runs in polynomial time (unless the
generalized Riemann hypothesis is false).
"""
# Simple cases
#
if legendre_symbol(a, p) != 1:
return 0
elif a == 0:
return 0
elif p == 2:
return p
elif p % 4 == 3:
return pow(a, (p + 1) / 4, p)
# Partition p-1 to s * 2^e for an odd s (i.e.
# reduce all the powers of 2 from p-1)
#
s = p - 1
e = 0
while s % 2 == 0:
s /= 2
e += 1
# Find some 'n' with a legendre symbol n|p = -1.
# Shouldn't take long.
#
n = 2
while legendre_symbol(n, p) != -1:
n += 1
# Here be dragons!
# Read the paper "Square roots from 1; 24, 51,
# 10 to Dan Shanks" by Ezra Brown for more
# information
#
# x is a guess of the square root that gets better
# with each iteration.
# b is the "fudge factor" - by how much we're off
# with the guess. The invariant x^2 = ab (mod p)
# is maintained throughout the loop.
# g is used for successive powers of n to update
# both a and b
# r is the exponent - decreases with each update
#
x = pow(a, (s + 1) / 2, p)
b = pow(a, s, p)
g = pow(n, s, p)
r = e
while True:
t = b
m = 0
for m in xrange(r):
if t == 1:
break
t = pow(t, 2, p)
if m == 0:
return x
gs = pow(g, 2 ** (r - m - 1), p)
g = (gs * gs) % p
x = (x * gs) % p
b = (b * g) % p
r = m
def legendre_symbol(a, p):
""" Compute the Legendre symbol a|p using
Euler's criterion. p is a prime, a is
relatively prime to p (if p divides
a, then a|p = 0)
Returns 1 if a has a square root modulo
p, -1 otherwise.
"""
ls = pow(a, (p - 1) / 2, p)
return -1 if ls == p - 1 else ls
|
gpl-3.0
|
[
3,
687,
1455,
921,
18865,
14,
1589,
7731,
2778,
14,
846,
15,
8664,
15,
1644,
15,
1780,
15,
863,
4655,
13,
1494,
2238,
13,
9646,
13,
12065,
13,
262,
13,
1548,
15,
199,
199,
318,
3413,
2238,
63,
5079,
8,
65,
12,
299,
304,
272,
408,
6668,
282,
16744,
19826,
23185,
310,
334,
1494,
299,
9,
402,
283,
65,
1370,
299,
272,
1471,
506,
376,
16699,
21619,
14,
339,
428,
3344,
314,
406,
2587,
85,
4894,
402,
314,
1824,
26,
272,
671,
62,
18,
275,
282,
334,
1494,
299,
9,
272,
6061,
2529,
671,
14,
3390,
626,
299,
446,
671,
365,
2597,
282,
1738,
14,
339,
378,
365,
2138,
365,
949,
12386,
1738,
3495,
367,
272,
3520,
282,
436,
299,
14,
339,
710,
377,
265,
352,
317,
13,
2662,
25088,
5563,
365,
1202,
334,
2590,
272,
367,
2005,
3486,
5560,
315,
1314,
314,
8744,
272,
365,
6040,
687,
376,
8503,
680,
961,
5563,
272,
7858,
315,
11849,
900,
334,
18447,
314,
272,
8605,
1759,
820,
1873,
20059,
29268,
365,
3055,
680,
272,
408,
272,
327,
5870,
5560,
272,
327,
272,
340,
15906,
264,
63,
5155,
8,
65,
12,
299,
9,
1137,
413,
26,
267,
372,
378,
272,
916,
282,
508,
378,
26,
267,
372,
378,
272,
916,
299,
508,
499,
26,
267,
372,
299,
272,
916,
299,
450,
841,
508,
650,
26,
267,
372,
13131,
8,
65,
12,
334,
80,
435,
413,
9,
1182,
841,
12,
299,
9,
339,
327,
27353,
299,
13,
17,
370,
308,
627,
499,
62,
69,
367,
376,
16699,
308,
334,
73,
14,
69,
14,
272,
327,
7114,
1006,
314,
13131,
1192,
402,
499,
687,
299,
13,
17,
9,
272,
327,
272,
308,
275,
299,
446,
413,
272,
325,
275,
378,
272,
1830,
308,
450,
499,
508,
378,
26,
267,
308,
12257,
499,
267,
325,
847,
413,
339,
327,
6668,
2005,
283,
78,
7,
543,
282,
15906,
264,
5272,
302,
92,
80,
275,
446,
17,
14,
272,
327,
7719,
78,
1133,
5452,
1846,
14,
272,
327,
272,
302,
275,
499,
272,
1830,
15906,
264,
63,
5155,
8,
78,
12,
299,
9,
1137,
446,
17,
26,
267,
302,
847,
413,
339,
327,
11842,
506,
18981,
4654,
1,
272,
327,
5574,
314,
15220,
298,
23373,
14361,
687,
413,
27,
5504,
12,
8026,
12,
272,
327,
1616,
370,
24747,
5244,
25088,
2,
701,
662,
90,
345,
699,
18406,
367,
1655,
272,
327,
2556,
272,
327,
339,
327,
671,
365,
282,
9519,
402,
314,
12386,
1738,
626,
7545,
8034,
272,
327,
543,
1924,
8494,
14,
272,
327,
330,
365,
314,
298,
70,
16603,
6535,
2,
446,
701,
4212,
8298,
781,
3984,
2331,
272,
327,
543,
314,
9519,
14,
710,
30326,
671,
62,
18,
275,
2236,
334,
1494,
299,
9,
272,
327,
365,
26391,
23088,
314,
4438,
14,
272,
327,
486,
365,
1202,
367,
27028,
3398,
13131,
1192,
402,
302,
370,
1678,
272,
327,
3865,
282,
436,
330,
272,
327,
519,
365,
314,
16588,
446,
477,
1353,
3274,
543,
1924,
1678,
272,
327,
272,
671,
275,
13131,
8,
65,
12,
334,
83,
435,
413,
9,
1182,
499,
12,
299,
9,
272,
330,
275,
13131,
8,
65,
12,
308,
12,
299,
9,
272,
486,
275,
13131,
8,
78,
12,
308,
12,
299,
9,
272,
519,
275,
325,
339,
1830,
715,
26,
267,
307,
275,
330,
267,
333,
275,
378,
267,
367,
333,
315,
4945,
8,
82,
304,
288,
340,
307,
508,
413,
26,
355,
2059,
288,
307,
275,
13131,
8,
84,
12,
499,
12,
299,
9,
398,
340,
333,
508,
378,
26,
288,
372,
671,
398,
8763,
275,
13131,
8,
71,
12,
499,
1011,
334,
82,
446,
333,
446,
413,
395,
299,
9,
267,
486,
275,
334,
458,
627,
8763,
9,
450,
299,
267,
671,
275,
334,
88,
627,
8763,
9,
450,
299,
267,
330,
275,
334,
66,
627,
486,
9,
450,
299,
267,
519,
275,
333,
199,
199,
318,
15906,
264,
63,
5155,
8,
65,
12,
299,
304,
272,
408,
8354,
314,
29420,
5272,
282,
92,
80,
1808,
272,
662,
19345,
1159,
17392,
14,
299,
365,
282,
21619,
12,
282,
365,
272,
13773,
9462,
21619,
370,
299,
334,
692,
299,
487,
9652,
272,
282,
12,
2066,
282,
92,
80,
275,
378,
9,
339,
1803,
413,
340,
282,
965,
282,
12386,
1738,
27656,
272,
299,
12,
446,
17,
4257,
14,
272,
408,
272,
9100,
275,
13131,
8,
65,
12,
334,
80,
446,
413,
9,
1182,
499,
12,
299,
9,
272,
372,
446,
17,
340,
9100,
508,
299,
446,
413,
587,
9100,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
687,
1455,
921,
18865,
14,
1589,
7731,
2778,
14,
846,
15,
8664,
15,
1644,
15,
1780,
15,
863,
4655,
13,
1494,
2238,
13,
9646,
13,
12065,
13,
262,
13,
1548,
15,
199,
199,
318,
3413,
2238,
63,
5079,
8,
65,
12,
299,
304,
272,
408,
6668,
282,
16744,
19826,
23185,
310,
334,
1494,
299,
9,
402,
283,
65,
1370,
299,
272,
1471,
506,
376,
16699,
21619,
14,
339,
428,
3344,
314,
406,
2587,
85,
4894,
402,
314,
1824,
26,
272,
671,
62,
18,
275,
282,
334,
1494,
299,
9,
272,
6061,
2529,
671,
14,
3390,
626,
299,
446,
671,
365,
2597,
282,
1738,
14,
339,
378,
365,
2138,
365,
949,
12386,
1738,
3495,
367,
272,
3520,
282,
436,
299,
14,
339,
710,
377,
265,
352,
317,
13,
2662,
25088,
5563,
365,
1202,
334,
2590,
272,
367,
2005,
3486,
5560,
315,
1314,
314,
8744,
272,
365,
6040,
687,
376,
8503,
680,
961,
5563,
272,
7858,
315,
11849,
900,
334,
18447,
314,
272,
8605,
1759,
820,
1873,
20059,
29268,
365,
3055,
680,
272,
408,
272,
327,
5870,
5560,
272,
327,
272,
340,
15906,
264,
63,
5155,
8,
65,
12,
299,
9,
1137,
413,
26,
267,
372,
378,
272,
916,
282,
508,
378,
26,
267,
372,
378,
272,
916,
299,
508,
499,
26,
267,
372,
299,
272,
916,
299,
450,
841,
508,
650,
26,
267,
372,
13131,
8,
65,
12,
334,
80,
435,
413,
9,
1182,
841,
12,
299,
9,
339,
327,
27353,
299,
13,
17,
370,
308,
627,
499,
62,
69,
367,
376,
16699,
308,
334,
73,
14,
69,
14,
272,
327,
7114,
1006,
314,
13131,
1192,
402,
499,
687,
299,
13,
17,
9,
272,
327,
272,
308,
275,
299,
446,
413,
272,
325,
275,
378,
272,
1830,
308,
450,
499,
508,
378,
26,
267,
308,
12257,
499,
267,
325,
847,
413,
339,
327,
6668,
2005,
283,
78,
7,
543,
282,
15906,
264,
5272,
302,
92,
80,
275,
446,
17,
14,
272,
327,
7719,
78,
1133,
5452,
1846,
14,
272,
327,
272,
302,
275,
499,
272,
1830,
15906,
264,
63,
5155,
8,
78,
12,
299,
9,
1137,
446,
17,
26,
267,
302,
847,
413,
339,
327,
11842,
506,
18981,
4654,
1,
272,
327,
5574,
314,
15220,
298,
23373,
14361,
687,
413,
27,
5504,
12,
8026,
12,
272,
327,
1616,
370,
24747,
5244,
25088,
2,
701,
662,
90,
345,
699,
18406,
367,
1655,
272,
327,
2556,
272,
327,
339,
327,
671,
365,
282,
9519,
402,
314,
12386,
1738,
626,
7545,
8034,
272,
327,
543,
1924,
8494,
14,
272,
327,
330,
365,
314,
298,
70,
16603,
6535,
2,
446,
701,
4212,
8298,
781,
3984,
2331,
272,
327,
543,
314,
9519,
14,
710,
30326,
671,
62,
18,
275,
2236,
334,
1494,
299,
9,
272,
327,
365,
26391,
23088,
314,
4438,
14,
272,
327,
486,
365,
1202,
367,
27028,
3398,
13131,
1192,
402,
302,
370,
1678,
272,
327,
3865,
282,
436,
330,
272,
327,
519,
365,
314,
16588,
446,
477,
1353,
3274,
543,
1924,
1678,
272,
327,
272,
671,
275,
13131,
8,
65,
12,
334,
83,
435,
413,
9,
1182,
499,
12,
299,
9,
272,
330,
275,
13131,
8,
65,
12,
308,
12,
299,
9,
272,
486,
275,
13131,
8,
78,
12,
308,
12,
299,
9,
272,
519,
275,
325,
339,
1830,
715,
26,
267,
307,
275,
330,
267,
333,
275,
378,
267,
367,
333,
315,
4945,
8,
82,
304,
288,
340,
307,
508,
413,
26,
355,
2059,
288,
307,
275,
13131,
8,
84,
12,
499,
12,
299,
9,
398,
340,
333,
508,
378,
26,
288,
372,
671,
398,
8763,
275,
13131,
8,
71,
12,
499,
1011,
334,
82,
446,
333,
446,
413,
395,
299,
9,
267,
486,
275,
334,
458,
627,
8763,
9,
450,
299,
267,
671,
275,
334,
88,
627,
8763,
9,
450,
299,
267,
330,
275,
334,
66,
627,
486,
9,
450,
299,
267,
519,
275,
333,
199,
199,
318,
15906,
264,
63,
5155,
8,
65,
12,
299,
304,
272,
408,
8354,
314,
29420,
5272,
282,
92,
80,
1808,
272,
662,
19345,
1159,
17392,
14,
299,
365,
282,
21619,
12,
282,
365,
272,
13773,
9462,
21619,
370,
299,
334,
692,
299,
487,
9652,
272,
282,
12,
2066,
282,
92,
80,
275,
378,
9,
339,
1803,
413,
340,
282,
965,
282,
12386,
1738,
27656,
272,
299,
12,
446,
17,
4257,
14,
272,
408,
272,
9100,
275,
13131,
8,
65,
12,
334,
80,
446,
413,
9,
1182,
499,
12,
299,
9,
272,
372,
446,
17,
340,
9100,
508,
299,
446,
413,
587,
9100,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
AloneRoad/Inforlearn
|
django/core/serializers/xml_serializer.py
|
16
|
8737
|
"""
XML serializer.
"""
from django.conf import settings
from django.core.serializers import base
from django.db import models
from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import smart_unicode
from xml.dom import pulldom
class Serializer(base.Serializer):
"""
Serializes a QuerySet to XML.
"""
def indent(self, level):
if self.options.get('indent', None) is not None:
self.xml.ignorableWhitespace('\n' + ' ' * self.options.get('indent', None) * level)
def start_serialization(self):
"""
Start serialization -- open the XML document and the root element.
"""
self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
self.xml.startDocument()
self.xml.startElement("django-objects", {"version" : "1.0"})
def end_serialization(self):
"""
End serialization -- end the document.
"""
self.indent(0)
self.xml.endElement("django-objects")
self.xml.endDocument()
def start_object(self, obj):
"""
Called as each object is handled.
"""
if not hasattr(obj, "_meta"):
raise base.SerializationError("Non-model object (%s) encountered during serialization" % type(obj))
self.indent(1)
self.xml.startElement("object", {
"pk" : smart_unicode(obj._get_pk_val()),
"model" : smart_unicode(obj._meta),
})
def end_object(self, obj):
"""
Called after handling all fields for an object.
"""
self.indent(1)
self.xml.endElement("object")
def handle_field(self, obj, field):
"""
Called to handle each field on an object (except for ForeignKeys and
ManyToManyFields)
"""
self.indent(2)
self.xml.startElement("field", {
"name" : field.name,
"type" : field.get_internal_type()
})
# Get a "string version" of the object's data (this is handled by the
# serializer base class).
if getattr(obj, field.name) is not None:
value = self.get_string_value(obj, field)
self.xml.characters(smart_unicode(value))
else:
self.xml.addQuickElement("None")
self.xml.endElement("field")
def handle_fk_field(self, obj, field):
"""
Called to handle a ForeignKey (we need to treat them slightly
differently from regular fields).
"""
self._start_relational_field(field)
related = getattr(obj, field.name)
if related is not None:
if field.rel.field_name == related._meta.pk.name:
# Related to remote object via primary key
related = related._get_pk_val()
else:
# Related to remote object via other field
related = getattr(related, field.rel.field_name)
self.xml.characters(smart_unicode(related))
else:
self.xml.addQuickElement("None")
self.xml.endElement("field")
def handle_m2m_field(self, obj, field):
"""
Called to handle a ManyToManyField. Related objects are only
serialized as references to the object's PK (i.e. the related *data*
is not dumped, just the relation).
"""
if field.creates_table:
self._start_relational_field(field)
for relobj in getattr(obj, field.name).iterator():
self.xml.addQuickElement("object", attrs={"pk" : smart_unicode(relobj._get_pk_val())})
self.xml.endElement("field")
def _start_relational_field(self, field):
"""
Helper to output the <field> element for relational fields
"""
self.indent(2)
self.xml.startElement("field", {
"name" : field.name,
"rel" : field.rel.__class__.__name__,
"to" : smart_unicode(field.rel.to._meta),
})
class Deserializer(base.Deserializer):
"""
Deserialize XML.
"""
def __init__(self, stream_or_string, **options):
super(Deserializer, self).__init__(stream_or_string, **options)
self.event_stream = pulldom.parse(self.stream)
def next(self):
for event, node in self.event_stream:
if event == "START_ELEMENT" and node.nodeName == "object":
self.event_stream.expandNode(node)
return self._handle_object(node)
raise StopIteration
def _handle_object(self, node):
"""
Convert an <object> node to a DeserializedObject.
"""
# Look up the model using the model loading mechanism. If this fails,
# bail.
Model = self._get_model_from_node(node, "model")
# Start building a data dictionary from the object. If the node is
# missing the pk attribute, bail.
pk = node.getAttribute("pk")
if not pk:
raise base.DeserializationError("<object> node is missing the 'pk' attribute")
data = {Model._meta.pk.attname : Model._meta.pk.to_python(pk)}
# Also start building a dict of m2m data (this is saved as
# {m2m_accessor_attribute : [list_of_related_objects]})
m2m_data = {}
# Deseralize each field.
for field_node in node.getElementsByTagName("field"):
# If the field is missing the name attribute, bail (are you
# sensing a pattern here?)
field_name = field_node.getAttribute("name")
if not field_name:
raise base.DeserializationError("<field> node is missing the 'name' attribute")
# Get the field from the Model. This will raise a
# FieldDoesNotExist if, well, the field doesn't exist, which will
# be propagated correctly.
field = Model._meta.get_field(field_name)
# As is usually the case, relation fields get the special treatment.
if field.rel and isinstance(field.rel, models.ManyToManyRel):
m2m_data[field.name] = self._handle_m2m_field_node(field_node, field)
elif field.rel and isinstance(field.rel, models.ManyToOneRel):
data[field.attname] = self._handle_fk_field_node(field_node, field)
else:
if field_node.getElementsByTagName('None'):
value = None
else:
value = field.to_python(getInnerText(field_node).strip())
data[field.name] = value
# Return a DeserializedObject so that the m2m data has a place to live.
return base.DeserializedObject(Model(**data), m2m_data)
def _handle_fk_field_node(self, node, field):
"""
Handle a <field> node for a ForeignKey
"""
# Check if there is a child node named 'None', returning None if so.
if node.getElementsByTagName('None'):
return None
else:
return field.rel.to._meta.get_field(field.rel.field_name).to_python(
getInnerText(node).strip())
def _handle_m2m_field_node(self, node, field):
"""
Handle a <field> node for a ManyToManyField.
"""
return [field.rel.to._meta.pk.to_python(
c.getAttribute("pk"))
for c in node.getElementsByTagName("object")]
def _get_model_from_node(self, node, attr):
"""
Helper to look up a model from a <object model=...> or a <field
rel=... to=...> node.
"""
model_identifier = node.getAttribute(attr)
if not model_identifier:
raise base.DeserializationError(
"<%s> node is missing the required '%s' attribute" \
% (node.nodeName, attr))
try:
Model = models.get_model(*model_identifier.split("."))
except TypeError:
Model = None
if Model is None:
raise base.DeserializationError(
"<%s> node has invalid model identifier: '%s'" % \
(node.nodeName, model_identifier))
return Model
def getInnerText(node):
"""
Get all the inner text of a DOM node (recursively).
"""
# inspired by http://mail.python.org/pipermail/xml-sig/2005-March/011022.html
inner_text = []
for child in node.childNodes:
if child.nodeType == child.TEXT_NODE or child.nodeType == child.CDATA_SECTION_NODE:
inner_text.append(child.data)
elif child.nodeType == child.ELEMENT_NODE:
inner_text.extend(getInnerText(child))
else:
pass
return u"".join(inner_text)
|
apache-2.0
|
[
624,
199,
4317,
9146,
14,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
12844,
492,
1300,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
1652,
1208,
492,
5870,
82,
4317,
7599,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
199,
504,
2748,
14,
4556,
492,
10299,
4556,
199,
199,
533,
25555,
8,
1095,
14,
7299,
304,
272,
408,
272,
11973,
6491,
282,
18397,
370,
4692,
14,
272,
408,
339,
347,
4363,
8,
277,
12,
2166,
304,
267,
340,
291,
14,
1419,
14,
362,
360,
3724,
297,
488,
9,
365,
440,
488,
26,
288,
291,
14,
1652,
14,
1030,
30932,
16552,
2258,
78,
7,
435,
283,
283,
627,
291,
14,
1419,
14,
362,
360,
3724,
297,
488,
9,
627,
2166,
9,
339,
347,
1343,
63,
12161,
8,
277,
304,
267,
408,
267,
7707,
16953,
1553,
1551,
314,
4692,
2213,
436,
314,
1738,
1819,
14,
267,
408,
267,
291,
14,
1652,
275,
5870,
82,
4317,
7599,
8,
277,
14,
1745,
12,
291,
14,
1419,
14,
362,
480,
2991,
401,
2202,
14,
3472,
63,
23969,
430,
267,
291,
14,
1652,
14,
928,
5564,
342,
267,
291,
14,
1652,
14,
30398,
480,
1176,
13,
1462,
401,
2420,
1023,
2,
520,
298,
17,
14,
16,
5984,
339,
347,
1284,
63,
12161,
8,
277,
304,
267,
408,
267,
9599,
16953,
1553,
1284,
314,
2213,
14,
267,
408,
267,
291,
14,
3724,
8,
16,
9,
267,
291,
14,
1652,
14,
31290,
480,
1176,
13,
1462,
531,
267,
291,
14,
1652,
14,
500,
5564,
342,
339,
347,
1343,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
465,
1924,
909,
365,
8860,
14,
267,
408,
267,
340,
440,
2688,
8,
1113,
12,
2668,
2024,
2349,
288,
746,
1300,
14,
3571,
2072,
547,
480,
6932,
13,
1238,
909,
4366,
83,
9,
14556,
5309,
16953,
2,
450,
730,
8,
1113,
430,
398,
291,
14,
3724,
8,
17,
9,
267,
291,
14,
1652,
14,
30398,
480,
785,
401,
469,
288,
298,
2051,
2,
259,
520,
11179,
63,
2975,
8,
1113,
423,
362,
63,
2051,
63,
637,
4000,
288,
298,
1238,
2,
520,
11179,
63,
2975,
8,
1113,
423,
2024,
395,
267,
3828,
339,
347,
1284,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
2410,
7252,
1006,
1504,
367,
376,
909,
14,
267,
408,
267,
291,
14,
3724,
8,
17,
9,
267,
291,
14,
1652,
14,
31290,
480,
785,
531,
339,
347,
2429,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
1924,
901,
641,
376,
909,
334,
2590,
367,
481,
2692,
6340,
436,
267,
28409,
83,
9,
267,
408,
267,
291,
14,
3724,
8,
18,
9,
267,
291,
14,
1652,
14,
30398,
480,
698,
401,
469,
288,
298,
354,
2,
520,
901,
14,
354,
12,
288,
298,
466,
2,
520,
901,
14,
362,
63,
4672,
63,
466,
342,
267,
3828,
398,
327,
2372,
282,
298,
875,
1015,
2,
402,
314,
909,
1159,
666,
334,
3749,
365,
8860,
701,
314,
267,
327,
9146,
1300,
1021,
680,
267,
340,
2519,
8,
1113,
12,
901,
14,
354,
9,
365,
440,
488,
26,
288,
574,
275,
291,
14,
362,
63,
875,
63,
585,
8,
1113,
12,
901,
9,
288,
291,
14,
1652,
14,
16516,
8,
7853,
63,
2975,
8,
585,
430,
267,
587,
26,
288,
291,
14,
1652,
14,
525,
19684,
2162,
480,
403,
531,
398,
291,
14,
1652,
14,
31290,
480,
698,
531,
339,
347,
2429,
63,
9010,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
12718,
334,
1129,
1929,
370,
14312,
3062,
18023,
267,
23142,
687,
5578,
1504,
680,
267,
408,
267,
291,
423,
928,
63,
5690,
279,
63,
698,
8,
698,
9,
267,
4048,
275,
2519,
8,
1113,
12,
901,
14,
354,
9,
267,
340,
4048,
365,
440,
488,
26,
288,
340,
901,
14,
3369,
14,
698,
63,
354,
508,
4048,
423,
2024,
14,
2051,
14,
354,
26,
355,
327,
20116,
370,
3982,
909,
4799,
5062,
790,
355,
4048,
275,
4048,
423,
362,
63,
2051,
63,
637,
342,
288,
587,
26,
355,
327,
20116,
370,
3982,
909,
4799,
1163,
901,
355,
4048,
275,
2519,
8,
2407,
12,
901,
14,
3369,
14,
698,
63,
354,
9,
288,
291,
14,
1652,
14,
16516,
8,
7853,
63,
2975,
8,
2407,
430,
267,
587,
26,
288,
291,
14,
1652,
14,
525,
19684,
2162,
480,
403,
531,
267,
291,
14,
1652,
14,
31290,
480,
698,
531,
339,
347,
2429,
63,
77,
18,
77,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
28409,
14,
20116,
2251,
787,
1454,
267,
6380,
465,
6941,
370,
314,
909,
1159,
18368,
334,
73,
14,
69,
14,
314,
4048,
627,
576,
10,
267,
365,
440,
31374,
12,
2951,
314,
5850,
680,
267,
408,
267,
340,
901,
14,
28219,
63,
1224,
26,
288,
291,
423,
928,
63,
5690,
279,
63,
698,
8,
698,
9,
288,
367,
295,
25678,
315,
2519,
8,
1113,
12,
901,
14,
354,
680,
5778,
837,
355,
291,
14,
1652,
14,
525,
19684,
2162,
480,
785,
401,
3290,
8871,
2051,
2,
520,
11179,
63,
2975,
8,
264,
25678,
423,
362,
63,
2051,
63,
637,
1012,
1552,
288,
291,
14,
1652,
14,
31290,
480,
698,
531,
339,
347,
485,
928,
63,
5690,
279,
63,
698,
8,
277,
12,
901,
304,
267,
408,
267,
11642,
370,
1072,
314,
665,
698,
30,
1819,
367,
5850,
279,
1504,
267,
408,
267,
291,
14,
3724,
8,
18,
9,
267,
291,
14,
1652,
14,
30398,
480,
698,
401,
469,
288,
298,
354,
2,
520,
901,
14,
354,
12,
288,
298,
3369,
2,
221,
520,
901,
14,
3369,
855,
533,
4914,
354,
3108,
288,
298,
475,
2,
257,
520,
11179,
63,
2975,
8,
698,
14,
3369,
14,
475,
423,
2024,
395,
267,
3828,
199,
199,
533,
1487,
8349,
8,
1095,
14,
872,
8349,
304,
272,
408,
272,
1487,
3549,
4692,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2547,
63,
269,
63,
875,
12,
1011,
1419,
304,
267,
1613,
8,
872,
8349,
12,
291,
2843,
826,
721,
1745,
63,
269,
63,
875,
12,
1011,
1419,
9,
267
] |
[
199,
4317,
9146,
14,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
12844,
492,
1300,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
1652,
1208,
492,
5870,
82,
4317,
7599,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
199,
504,
2748,
14,
4556,
492,
10299,
4556,
199,
199,
533,
25555,
8,
1095,
14,
7299,
304,
272,
408,
272,
11973,
6491,
282,
18397,
370,
4692,
14,
272,
408,
339,
347,
4363,
8,
277,
12,
2166,
304,
267,
340,
291,
14,
1419,
14,
362,
360,
3724,
297,
488,
9,
365,
440,
488,
26,
288,
291,
14,
1652,
14,
1030,
30932,
16552,
2258,
78,
7,
435,
283,
283,
627,
291,
14,
1419,
14,
362,
360,
3724,
297,
488,
9,
627,
2166,
9,
339,
347,
1343,
63,
12161,
8,
277,
304,
267,
408,
267,
7707,
16953,
1553,
1551,
314,
4692,
2213,
436,
314,
1738,
1819,
14,
267,
408,
267,
291,
14,
1652,
275,
5870,
82,
4317,
7599,
8,
277,
14,
1745,
12,
291,
14,
1419,
14,
362,
480,
2991,
401,
2202,
14,
3472,
63,
23969,
430,
267,
291,
14,
1652,
14,
928,
5564,
342,
267,
291,
14,
1652,
14,
30398,
480,
1176,
13,
1462,
401,
2420,
1023,
2,
520,
298,
17,
14,
16,
5984,
339,
347,
1284,
63,
12161,
8,
277,
304,
267,
408,
267,
9599,
16953,
1553,
1284,
314,
2213,
14,
267,
408,
267,
291,
14,
3724,
8,
16,
9,
267,
291,
14,
1652,
14,
31290,
480,
1176,
13,
1462,
531,
267,
291,
14,
1652,
14,
500,
5564,
342,
339,
347,
1343,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
465,
1924,
909,
365,
8860,
14,
267,
408,
267,
340,
440,
2688,
8,
1113,
12,
2668,
2024,
2349,
288,
746,
1300,
14,
3571,
2072,
547,
480,
6932,
13,
1238,
909,
4366,
83,
9,
14556,
5309,
16953,
2,
450,
730,
8,
1113,
430,
398,
291,
14,
3724,
8,
17,
9,
267,
291,
14,
1652,
14,
30398,
480,
785,
401,
469,
288,
298,
2051,
2,
259,
520,
11179,
63,
2975,
8,
1113,
423,
362,
63,
2051,
63,
637,
4000,
288,
298,
1238,
2,
520,
11179,
63,
2975,
8,
1113,
423,
2024,
395,
267,
3828,
339,
347,
1284,
63,
785,
8,
277,
12,
1559,
304,
267,
408,
267,
12295,
2410,
7252,
1006,
1504,
367,
376,
909,
14,
267,
408,
267,
291,
14,
3724,
8,
17,
9,
267,
291,
14,
1652,
14,
31290,
480,
785,
531,
339,
347,
2429,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
1924,
901,
641,
376,
909,
334,
2590,
367,
481,
2692,
6340,
436,
267,
28409,
83,
9,
267,
408,
267,
291,
14,
3724,
8,
18,
9,
267,
291,
14,
1652,
14,
30398,
480,
698,
401,
469,
288,
298,
354,
2,
520,
901,
14,
354,
12,
288,
298,
466,
2,
520,
901,
14,
362,
63,
4672,
63,
466,
342,
267,
3828,
398,
327,
2372,
282,
298,
875,
1015,
2,
402,
314,
909,
1159,
666,
334,
3749,
365,
8860,
701,
314,
267,
327,
9146,
1300,
1021,
680,
267,
340,
2519,
8,
1113,
12,
901,
14,
354,
9,
365,
440,
488,
26,
288,
574,
275,
291,
14,
362,
63,
875,
63,
585,
8,
1113,
12,
901,
9,
288,
291,
14,
1652,
14,
16516,
8,
7853,
63,
2975,
8,
585,
430,
267,
587,
26,
288,
291,
14,
1652,
14,
525,
19684,
2162,
480,
403,
531,
398,
291,
14,
1652,
14,
31290,
480,
698,
531,
339,
347,
2429,
63,
9010,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
12718,
334,
1129,
1929,
370,
14312,
3062,
18023,
267,
23142,
687,
5578,
1504,
680,
267,
408,
267,
291,
423,
928,
63,
5690,
279,
63,
698,
8,
698,
9,
267,
4048,
275,
2519,
8,
1113,
12,
901,
14,
354,
9,
267,
340,
4048,
365,
440,
488,
26,
288,
340,
901,
14,
3369,
14,
698,
63,
354,
508,
4048,
423,
2024,
14,
2051,
14,
354,
26,
355,
327,
20116,
370,
3982,
909,
4799,
5062,
790,
355,
4048,
275,
4048,
423,
362,
63,
2051,
63,
637,
342,
288,
587,
26,
355,
327,
20116,
370,
3982,
909,
4799,
1163,
901,
355,
4048,
275,
2519,
8,
2407,
12,
901,
14,
3369,
14,
698,
63,
354,
9,
288,
291,
14,
1652,
14,
16516,
8,
7853,
63,
2975,
8,
2407,
430,
267,
587,
26,
288,
291,
14,
1652,
14,
525,
19684,
2162,
480,
403,
531,
267,
291,
14,
1652,
14,
31290,
480,
698,
531,
339,
347,
2429,
63,
77,
18,
77,
63,
698,
8,
277,
12,
1559,
12,
901,
304,
267,
408,
267,
12295,
370,
2429,
282,
28409,
14,
20116,
2251,
787,
1454,
267,
6380,
465,
6941,
370,
314,
909,
1159,
18368,
334,
73,
14,
69,
14,
314,
4048,
627,
576,
10,
267,
365,
440,
31374,
12,
2951,
314,
5850,
680,
267,
408,
267,
340,
901,
14,
28219,
63,
1224,
26,
288,
291,
423,
928,
63,
5690,
279,
63,
698,
8,
698,
9,
288,
367,
295,
25678,
315,
2519,
8,
1113,
12,
901,
14,
354,
680,
5778,
837,
355,
291,
14,
1652,
14,
525,
19684,
2162,
480,
785,
401,
3290,
8871,
2051,
2,
520,
11179,
63,
2975,
8,
264,
25678,
423,
362,
63,
2051,
63,
637,
1012,
1552,
288,
291,
14,
1652,
14,
31290,
480,
698,
531,
339,
347,
485,
928,
63,
5690,
279,
63,
698,
8,
277,
12,
901,
304,
267,
408,
267,
11642,
370,
1072,
314,
665,
698,
30,
1819,
367,
5850,
279,
1504,
267,
408,
267,
291,
14,
3724,
8,
18,
9,
267,
291,
14,
1652,
14,
30398,
480,
698,
401,
469,
288,
298,
354,
2,
520,
901,
14,
354,
12,
288,
298,
3369,
2,
221,
520,
901,
14,
3369,
855,
533,
4914,
354,
3108,
288,
298,
475,
2,
257,
520,
11179,
63,
2975,
8,
698,
14,
3369,
14,
475,
423,
2024,
395,
267,
3828,
199,
199,
533,
1487,
8349,
8,
1095,
14,
872,
8349,
304,
272,
408,
272,
1487,
3549,
4692,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2547,
63,
269,
63,
875,
12,
1011,
1419,
304,
267,
1613,
8,
872,
8349,
12,
291,
2843,
826,
721,
1745,
63,
269,
63,
875,
12,
1011,
1419,
9,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
malkavi/Flexget
|
flexget/tests/test_plugin_interfaces.py
|
3
|
1272
|
from flexget import plugin
class TestInterfaces:
"""Test that any plugins declaring certain interfaces at least superficially comply with those interfaces."""
@staticmethod
def get_plugins(interface):
plugins = list(plugin.get_plugins(interface=interface))
assert plugins, 'No plugins for this interface found.'
return plugins
def test_task_interface(self):
for p in self.get_plugins('task'):
assert isinstance(p.schema, dict), 'Task interface requires a schema to be defined.'
assert (
p.phase_handlers
), 'Task plugins should have at least on phase handler (on_task_X) method.'
def test_list_interface(self):
for p in self.get_plugins('list'):
assert isinstance(p.schema, dict), 'List interface requires a schema to be defined.'
assert hasattr(
p.instance, 'get_list'
), 'List plugins must implement a get_list method.'
def test_search_interface(self):
for p in self.get_plugins('search'):
assert isinstance(p.schema, dict), 'Search interface requires a schema to be defined.'
assert hasattr(p.instance, 'search'), 'Search plugins must implement a search method.'
|
mit
|
[
504,
20758,
362,
492,
3589,
421,
199,
533,
1379,
18680,
26,
272,
408,
774,
626,
1263,
8963,
13507,
316,
9842,
8386,
737,
5210,
1613,
4294,
1183,
1013,
590,
543,
5204,
8386,
1041,
339,
768,
4639,
272,
347,
664,
63,
5265,
8,
3266,
304,
267,
8963,
275,
769,
8,
2718,
14,
362,
63,
5265,
8,
3266,
29,
3266,
430,
267,
702,
8963,
12,
283,
1944,
8963,
367,
642,
3217,
1911,
3530,
267,
372,
8963,
339,
347,
511,
63,
1765,
63,
3266,
8,
277,
304,
267,
367,
299,
315,
291,
14,
362,
63,
5265,
360,
1765,
735,
288,
702,
1228,
8,
80,
14,
3629,
12,
1211,
395,
283,
4476,
3217,
5074,
282,
4177,
370,
506,
3247,
3530,
288,
702,
334,
355,
299,
14,
6971,
63,
5586,
288,
2318,
283,
4476,
8963,
1077,
1172,
737,
5210,
641,
7669,
3016,
334,
265,
63,
1765,
63,
56,
9,
1083,
3530,
339,
347,
511,
63,
513,
63,
3266,
8,
277,
304,
267,
367,
299,
315,
291,
14,
362,
63,
5265,
360,
513,
735,
288,
702,
1228,
8,
80,
14,
3629,
12,
1211,
395,
283,
1296,
3217,
5074,
282,
4177,
370,
506,
3247,
3530,
288,
702,
2688,
8,
355,
299,
14,
842,
12,
283,
362,
63,
513,
7,
288,
2318,
283,
1296,
8963,
1471,
5669,
282,
664,
63,
513,
1083,
3530,
339,
347,
511,
63,
1733,
63,
3266,
8,
277,
304,
267,
367,
299,
315,
291,
14,
362,
63,
5265,
360,
1733,
735,
288,
702,
1228,
8,
80,
14,
3629,
12,
1211,
395,
283,
5278,
3217,
5074,
282,
4177,
370,
506,
3247,
3530,
288,
702,
2688,
8,
80,
14,
842,
12,
283,
1733,
659,
283,
5278,
8963,
1471,
5669,
282,
2754,
1083,
3530,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
20758,
362,
492,
3589,
421,
199,
533,
1379,
18680,
26,
272,
408,
774,
626,
1263,
8963,
13507,
316,
9842,
8386,
737,
5210,
1613,
4294,
1183,
1013,
590,
543,
5204,
8386,
1041,
339,
768,
4639,
272,
347,
664,
63,
5265,
8,
3266,
304,
267,
8963,
275,
769,
8,
2718,
14,
362,
63,
5265,
8,
3266,
29,
3266,
430,
267,
702,
8963,
12,
283,
1944,
8963,
367,
642,
3217,
1911,
3530,
267,
372,
8963,
339,
347,
511,
63,
1765,
63,
3266,
8,
277,
304,
267,
367,
299,
315,
291,
14,
362,
63,
5265,
360,
1765,
735,
288,
702,
1228,
8,
80,
14,
3629,
12,
1211,
395,
283,
4476,
3217,
5074,
282,
4177,
370,
506,
3247,
3530,
288,
702,
334,
355,
299,
14,
6971,
63,
5586,
288,
2318,
283,
4476,
8963,
1077,
1172,
737,
5210,
641,
7669,
3016,
334,
265,
63,
1765,
63,
56,
9,
1083,
3530,
339,
347,
511,
63,
513,
63,
3266,
8,
277,
304,
267,
367,
299,
315,
291,
14,
362,
63,
5265,
360,
513,
735,
288,
702,
1228,
8,
80,
14,
3629,
12,
1211,
395,
283,
1296,
3217,
5074,
282,
4177,
370,
506,
3247,
3530,
288,
702,
2688,
8,
355,
299,
14,
842,
12,
283,
362,
63,
513,
7,
288,
2318,
283,
1296,
8963,
1471,
5669,
282,
664,
63,
513,
1083,
3530,
339,
347,
511,
63,
1733,
63,
3266,
8,
277,
304,
267,
367,
299,
315,
291,
14,
362,
63,
5265,
360,
1733,
735,
288,
702,
1228,
8,
80,
14,
3629,
12,
1211,
395,
283,
5278,
3217,
5074,
282,
4177,
370,
506,
3247,
3530,
288,
702,
2688,
8,
80,
14,
842,
12,
283,
1733,
659,
283,
5278,
8963,
1471,
5669,
282,
2754,
1083,
3530,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
print(x)
exit(1)
def PrintMsg(x):
print(x)
def Output(x):
global result
result += str(x) + ' '
def GetRandomInt(interval):
if isinstance(interval, str):
PrintError('Error: ' + interval)
if isinstance(interval, int):
return interval
if interval[0] > interval[1]:
print('!!! Invaild Interval ')
exit(1)
rt = random.randint(interval[0], interval[1])
return rt
def AddPermutation(interval):
n = GetRandomInt(interval)
p = [i for i in range(1, n + 1)]
random.shuffle(p)
global result
for i in p:
result += str(i) + ' '
return None
def Add(a, b):
return GetRandomInt(a) + GetRandomInt(b)
def Mul(a, b):
return GetRandomInt(a) + GetRandomInt(b)
def Sub(a, b):
return GetRandomInt(a) + GetRandomInt(b)
def AddWeight(n, interval):
n = GetRandomInt(n)
for i in range(0, n):
Output(GetRandomInt(interval))
def RepeatOutput(node):
times = TranslateNode(node.params[0], node)
for i in range(0, times):
TranslateArray(node)
AddNewLine()
def HandleFunction(node):
print('handling function: ' + node.type)
print(node.params)
cases = {
'print': lambda x: Output(GetRandomInt(TranslateNode(node.params[0], x))),
'add': lambda x: Add(TranslateNode(x.params[0], x), TranslateNode(x.params[1], x)),
'sub': lambda x: Sub(TranslateNode(x.params[0], x), TranslateNode(x.params[1], x)),
'mul': lambda x: Mul(TranslateNode(x.params[0], x), TranslateNode(x.params[1], x)),
'permutation': lambda x: AddPermutation(TranslateNode(x.params[0], x)),
'weight': lambda x: AddWeight(TranslateNode(x.params[0], x), TranslateNode(x.params[1], x)),
'repeat': lambda x: RepeatOutput(x),
'set': lambda x: SetVariableValue(x.params[0].name, TranslateNode(x.params[1], x))
}
return cases.get(node.type, lambda x: None)(node)
def AddNewLine():
global cnt
cnt += 1
if cnt <= 0:
return
cnt -= 1
global result
result += '\n'
def CleanLine():
print("Clean")
global cnt
cnt -= 1
def HandleFormat(node):
print("Handling Format: " + node.value)
cases = {
'newline': lambda x: AddNewLine(),
'clearline': lambda x: CleanLine(),
}
return cases.get(node.value, lambda x: None)(node)
def GetVariableValue(name):
return symbol.get(name, name)
def SetVariableValue(name, value):
value = GetRandomInt(value)
symbol[name] = value
print('Set variable: ' + str(name) + ' = ' + str(symbol[name]))
return symbol[name]
def TranslateArray(node):
for x in node.params:
TranslateNode(x, node)
def TranslateNode(node, parent):
cases = {
parser.Function: lambda x: HandleFunction(x),
parser.Number: lambda x: x.value,
parser.Interval:
lambda x: [TranslateNode(x.left, x) + x.leftoffset, TranslateNode(x.right, x) + x.rightoffset],
parser.String: lambda x: GetVariableValue(x.name),
parser.Setvar: lambda x: SetVariableValue(x),
parser.Program: lambda x: TranslateArray(x),
parser.Format: lambda x: HandleFormat(x),
}
return cases.get(node.__class__, lambda x: None)(node)
TranslateArray(ast)
return result
|
mit
|
[
646,
1798,
199,
646,
2196,
199,
199,
1099,
275,
2125,
199,
5155,
275,
1052,
199,
6507,
275,
378,
199,
199,
318,
6266,
13693,
8,
1810,
304,
272,
347,
9101,
547,
8,
88,
304,
267,
870,
8,
88,
9,
267,
4458,
8,
17,
9,
339,
347,
9101,
6173,
8,
88,
304,
267,
870,
8,
88,
9,
339,
347,
7242,
8,
88,
304,
267,
2288,
754,
267,
754,
847,
620,
8,
88,
9,
435,
283,
283,
339,
347,
2372,
3883,
3241,
8,
4284,
304,
267,
340,
1228,
8,
4284,
12,
620,
304,
288,
9101,
547,
360,
547,
26,
283,
435,
6252,
9,
267,
340,
1228,
8,
4284,
12,
1109,
304,
288,
372,
6252,
267,
340,
6252,
59,
16,
61,
690,
6252,
59,
17,
2189,
288,
870,
360,
21512,
1010,
3042,
668,
18766,
5320,
288,
4458,
8,
17,
9,
267,
14059,
275,
2196,
14,
8393,
8,
4284,
59,
16,
467,
6252,
59,
17,
566,
267,
372,
14059,
2286,
347,
2654,
2623,
11627,
8,
4284,
304,
267,
302,
275,
2372,
3883,
3241,
8,
4284,
9,
267,
299,
275,
359,
73,
367,
284,
315,
1425,
8,
17,
12,
302,
435,
413,
1874,
267,
2196,
14,
11777,
8,
80,
9,
267,
2288,
754,
267,
367,
284,
315,
299,
26,
288,
754,
847,
620,
8,
73,
9,
435,
283,
283,
267,
372,
488,
339,
347,
2654,
8,
65,
12,
330,
304,
267,
372,
2372,
3883,
3241,
8,
65,
9,
435,
2372,
3883,
3241,
8,
66,
9,
2286,
347,
22578,
8,
65,
12,
330,
304,
267,
372,
2372,
3883,
3241,
8,
65,
9,
435,
2372,
3883,
3241,
8,
66,
9,
2286,
347,
4804,
8,
65,
12,
330,
304,
267,
372,
2372,
3883,
3241,
8,
65,
9,
435,
2372,
3883,
3241,
8,
66,
9,
339,
347,
2654,
16359,
8,
78,
12,
6252,
304,
267,
302,
275,
2372,
3883,
3241,
8,
78,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
302,
304,
288,
7242,
8,
1002,
3883,
3241,
8,
4284,
430,
258,
339,
347,
21973,
292,
2959,
8,
932,
304,
267,
5431,
275,
25540,
1716,
8,
932,
14,
1162,
59,
16,
467,
1031,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
5431,
304,
288,
25540,
3836,
8,
932,
9,
288,
2654,
4665,
3049,
342,
339,
347,
8690,
3481,
8,
932,
304,
267,
870,
360,
22273,
805,
26,
283,
435,
1031,
14,
466,
9,
267,
870,
8,
932,
14,
1162,
9,
267,
5560,
275,
469,
288,
283,
1361,
356,
2400,
671,
26,
7242,
8,
1002,
3883,
3241,
8,
18355,
1716,
8,
932,
14,
1162,
59,
16,
467,
671,
11508,
288,
283,
525,
356,
2400,
671,
26,
2654,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
288,
283,
954,
356,
2400,
671,
26,
4804,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
7205,
283,
3703,
356,
2400,
671,
26,
22578,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
288,
283,
23832,
356,
2400,
671,
26,
2654,
2623,
11627,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
1826,
288,
283,
3463,
356,
2400,
671,
26,
2654,
16359,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
288,
283,
8755,
356,
2400,
671,
26,
21973,
292,
2959,
8,
88,
395,
288,
283,
409,
356,
2400,
671,
26,
2494,
2773,
1110,
8,
88,
14,
1162,
59,
16,
1055,
354,
12,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
430,
267,
789,
267,
372,
5560,
14,
362,
8,
932,
14,
466,
12,
2400,
671,
26,
488,
5130,
932,
9,
339,
347,
2654,
4665,
3049,
837,
267,
2288,
12703,
267,
12703,
847,
413,
267,
340,
12703,
2695,
378,
26,
7205,
372,
4960,
12703,
4862,
413,
267,
2288,
754,
267,
754,
847,
1557,
78,
7,
339,
347,
12762,
3049,
837,
267,
870,
480,
6580,
531,
267,
2288,
12703,
267,
12703,
4862,
413,
339,
347,
8690,
3484,
8,
932,
304,
267,
870,
480,
26443,
9701,
26,
298,
435,
1031,
14,
585,
9,
267,
5560,
275,
469,
288,
283,
12210,
356,
2400,
671,
26,
2654,
4665,
3049,
1062,
288,
283,
3584,
604,
356,
2400,
671,
26,
12762,
3049,
1062,
267,
789,
267,
372,
5560,
14,
362,
8,
932,
14,
585,
12,
2400,
671,
26,
488,
5130,
932,
9,
339,
347,
2372,
2773,
1110,
8,
354,
304,
267,
372,
5272,
14,
362,
8,
354,
12,
536,
9,
339,
347,
2494,
2773,
1110,
8,
354,
12,
574,
304,
267,
574,
275,
2372,
3883,
3241,
8,
585,
9,
267,
5272,
59,
354,
61,
275,
574,
267,
870,
360,
1084,
1750,
26,
283,
435,
620,
8,
354,
9,
435,
283,
275,
283,
435,
620,
8,
5155,
59,
354,
2459,
267,
372,
5272,
59,
354,
61,
339,
347,
25540,
3836,
8,
932,
304,
267,
367,
671,
315,
1031,
14,
1162,
26,
288,
25540,
1716,
8,
88,
12,
1031,
9,
339,
347,
25540,
1716,
8,
932,
12,
1676,
304,
267,
5560,
275,
469,
288,
1798,
14,
3481,
26,
2400,
671,
26,
8690,
3481,
8,
88,
395,
288,
1798,
14,
3259,
26,
2400,
671,
26,
671,
14,
585,
12,
288,
1798,
14,
8227,
26,
8892,
2400,
671,
26,
359,
18355,
1716,
8,
88,
14,
3039,
12,
671,
9,
435,
671,
14,
21491,
475,
12449,
12,
25540,
1716,
8,
88,
14,
1019,
12,
671,
9,
435,
671,
14,
31816,
475,
12449,
467,
288,
1798,
14,
1558,
26,
2400,
671,
26,
2372,
2773,
1110,
8,
88,
14,
354,
395,
288,
1798,
14,
1084,
1391,
26,
2400,
671,
26,
2494,
2773,
1110,
8,
88,
395,
288,
1798,
14,
9184,
26,
2400,
671,
26,
25540,
3836,
8,
88,
395,
288,
1798,
14,
3484,
26,
2400,
671,
26,
8690,
3484,
8,
88,
395,
267,
789,
267,
372,
5560,
14,
362,
8,
932,
855,
533,
3108,
2400,
671,
26,
488,
5130,
932,
9,
2286,
25540,
3836,
8,
1810,
9,
272,
372,
754,
9948,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1798,
199,
646,
2196,
199,
199,
1099,
275,
2125,
199,
5155,
275,
1052,
199,
6507,
275,
378,
199,
199,
318,
6266,
13693,
8,
1810,
304,
272,
347,
9101,
547,
8,
88,
304,
267,
870,
8,
88,
9,
267,
4458,
8,
17,
9,
339,
347,
9101,
6173,
8,
88,
304,
267,
870,
8,
88,
9,
339,
347,
7242,
8,
88,
304,
267,
2288,
754,
267,
754,
847,
620,
8,
88,
9,
435,
283,
283,
339,
347,
2372,
3883,
3241,
8,
4284,
304,
267,
340,
1228,
8,
4284,
12,
620,
304,
288,
9101,
547,
360,
547,
26,
283,
435,
6252,
9,
267,
340,
1228,
8,
4284,
12,
1109,
304,
288,
372,
6252,
267,
340,
6252,
59,
16,
61,
690,
6252,
59,
17,
2189,
288,
870,
360,
21512,
1010,
3042,
668,
18766,
5320,
288,
4458,
8,
17,
9,
267,
14059,
275,
2196,
14,
8393,
8,
4284,
59,
16,
467,
6252,
59,
17,
566,
267,
372,
14059,
2286,
347,
2654,
2623,
11627,
8,
4284,
304,
267,
302,
275,
2372,
3883,
3241,
8,
4284,
9,
267,
299,
275,
359,
73,
367,
284,
315,
1425,
8,
17,
12,
302,
435,
413,
1874,
267,
2196,
14,
11777,
8,
80,
9,
267,
2288,
754,
267,
367,
284,
315,
299,
26,
288,
754,
847,
620,
8,
73,
9,
435,
283,
283,
267,
372,
488,
339,
347,
2654,
8,
65,
12,
330,
304,
267,
372,
2372,
3883,
3241,
8,
65,
9,
435,
2372,
3883,
3241,
8,
66,
9,
2286,
347,
22578,
8,
65,
12,
330,
304,
267,
372,
2372,
3883,
3241,
8,
65,
9,
435,
2372,
3883,
3241,
8,
66,
9,
2286,
347,
4804,
8,
65,
12,
330,
304,
267,
372,
2372,
3883,
3241,
8,
65,
9,
435,
2372,
3883,
3241,
8,
66,
9,
339,
347,
2654,
16359,
8,
78,
12,
6252,
304,
267,
302,
275,
2372,
3883,
3241,
8,
78,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
302,
304,
288,
7242,
8,
1002,
3883,
3241,
8,
4284,
430,
258,
339,
347,
21973,
292,
2959,
8,
932,
304,
267,
5431,
275,
25540,
1716,
8,
932,
14,
1162,
59,
16,
467,
1031,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
5431,
304,
288,
25540,
3836,
8,
932,
9,
288,
2654,
4665,
3049,
342,
339,
347,
8690,
3481,
8,
932,
304,
267,
870,
360,
22273,
805,
26,
283,
435,
1031,
14,
466,
9,
267,
870,
8,
932,
14,
1162,
9,
267,
5560,
275,
469,
288,
283,
1361,
356,
2400,
671,
26,
7242,
8,
1002,
3883,
3241,
8,
18355,
1716,
8,
932,
14,
1162,
59,
16,
467,
671,
11508,
288,
283,
525,
356,
2400,
671,
26,
2654,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
288,
283,
954,
356,
2400,
671,
26,
4804,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
7205,
283,
3703,
356,
2400,
671,
26,
22578,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
288,
283,
23832,
356,
2400,
671,
26,
2654,
2623,
11627,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
1826,
288,
283,
3463,
356,
2400,
671,
26,
2654,
16359,
8,
18355,
1716,
8,
88,
14,
1162,
59,
16,
467,
671,
395,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
1826,
288,
283,
8755,
356,
2400,
671,
26,
21973,
292,
2959,
8,
88,
395,
288,
283,
409,
356,
2400,
671,
26,
2494,
2773,
1110,
8,
88,
14,
1162,
59,
16,
1055,
354,
12,
25540,
1716,
8,
88,
14,
1162,
59,
17,
467,
671,
430,
267,
789,
267,
372,
5560,
14,
362,
8,
932,
14,
466,
12,
2400,
671,
26,
488,
5130,
932,
9,
339,
347,
2654,
4665,
3049,
837,
267,
2288,
12703,
267,
12703,
847,
413,
267,
340,
12703,
2695,
378,
26,
7205,
372,
4960,
12703,
4862,
413,
267,
2288,
754,
267,
754,
847,
1557,
78,
7,
339,
347,
12762,
3049,
837,
267,
870,
480,
6580,
531,
267,
2288,
12703,
267,
12703,
4862,
413,
339,
347,
8690,
3484,
8,
932,
304,
267,
870,
480,
26443,
9701,
26,
298,
435,
1031,
14,
585,
9,
267,
5560,
275,
469,
288,
283,
12210,
356,
2400,
671,
26,
2654,
4665,
3049,
1062,
288,
283,
3584,
604,
356,
2400,
671,
26,
12762,
3049,
1062,
267,
789,
267,
372,
5560,
14,
362,
8,
932,
14,
585,
12,
2400,
671,
26,
488,
5130,
932,
9,
339,
347,
2372,
2773,
1110,
8,
354,
304,
267,
372,
5272,
14,
362,
8,
354,
12,
536,
9,
339,
347,
2494,
2773,
1110,
8,
354,
12,
574,
304,
267,
574,
275,
2372,
3883,
3241,
8,
585,
9,
267,
5272,
59,
354,
61,
275,
574,
267,
870,
360,
1084,
1750,
26,
283,
435,
620,
8,
354,
9,
435,
283,
275,
283,
435,
620,
8,
5155,
59,
354,
2459,
267,
372,
5272,
59,
354,
61,
339,
347,
25540,
3836,
8,
932,
304,
267,
367,
671,
315,
1031,
14,
1162,
26,
288,
25540,
1716,
8,
88,
12,
1031,
9,
339,
347,
25540,
1716,
8,
932,
12,
1676,
304,
267,
5560,
275,
469,
288,
1798,
14,
3481,
26,
2400,
671,
26,
8690,
3481,
8,
88,
395,
288,
1798,
14,
3259,
26,
2400,
671,
26,
671,
14,
585,
12,
288,
1798,
14,
8227,
26,
8892,
2400,
671,
26,
359,
18355,
1716,
8,
88,
14,
3039,
12,
671,
9,
435,
671,
14,
21491,
475,
12449,
12,
25540,
1716,
8,
88,
14,
1019,
12,
671,
9,
435,
671,
14,
31816,
475,
12449,
467,
288,
1798,
14,
1558,
26,
2400,
671,
26,
2372,
2773,
1110,
8,
88,
14,
354,
395,
288,
1798,
14,
1084,
1391,
26,
2400,
671,
26,
2494,
2773,
1110,
8,
88,
395,
288,
1798,
14,
9184,
26,
2400,
671,
26,
25540,
3836,
8,
88,
395,
288,
1798,
14,
3484,
26,
2400,
671,
26,
8690,
3484,
8,
88,
395,
267,
789,
267,
372,
5560,
14,
362,
8,
932,
855,
533,
3108,
2400,
671,
26,
488,
5130,
932,
9,
2286,
25540,
3836,
8,
1810,
9,
272,
372,
754,
9948,
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,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applications/sublime-text-3/Packages/Anaconda/anaconda_lib/linting/pep257.py
|
3
|
59998
|
#! /usr/bin/env python
"""Static analysis tool for checking docstring conventions and style.
Implemented checks cover PEP257:
http://www.python.org/dev/peps/pep-0257/
Other checks can be added, e.g. NumPy docstring conventions:
https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
The repository is located at:
http://github.com/GreenSteam/pep257
"""
from __future__ import with_statement
import os
import sys
import copy
import logging
import tokenize as tk
from itertools import takewhile, dropwhile, chain
from re import compile as re
import itertools
from collections import defaultdict, namedtuple, Set
try: # Python 3.x
from ConfigParser import RawConfigParser
except ImportError: # Python 2.x
from configparser import RawConfigParser
log = logging.getLogger(__name__)
try:
from StringIO import StringIO
except ImportError: # Python 3.0 and later
from io import StringIO
try:
next
except NameError: # Python 2.5 and earlier
nothing = object()
def next(obj, default=nothing):
if default == nothing:
return obj.next()
else:
try:
return obj.next()
except StopIteration:
return default
# If possible (python >= 3.2) use tokenize.open to open files, so PEP 263
# encoding markers are interpreted.
try:
tokenize_open = tk.open
except AttributeError:
tokenize_open = open
__version__ = '0.7.0'
__all__ = ('check', 'collect')
NO_VIOLATIONS_RETURN_CODE = 0
VIOLATIONS_RETURN_CODE = 1
INVALID_OPTIONS_RETURN_CODE = 2
VARIADIC_MAGIC_METHODS = ('__init__', '__call__', '__new__')
def humanize(string):
return re(r'(.)([A-Z]+)').sub(r'\1 \2', string).lower()
def is_magic(name):
return (name.startswith('__') and
name.endswith('__') and
name not in VARIADIC_MAGIC_METHODS)
def is_ascii(string):
return all(ord(char) < 128 for char in string)
def is_blank(string):
return not string.strip()
def leading_space(string):
return re('\s*').match(string).group()
class Value(object):
def __init__(self, *args):
vars(self).update(zip(self._fields, args))
def __hash__(self):
return hash(repr(self))
def __eq__(self, other):
return other and vars(self) == vars(other)
def __repr__(self):
kwargs = ', '.join('{0}={1!r}'.format(field, getattr(self, field))
for field in self._fields)
return '{0}({1})'.format(self.__class__.__name__, kwargs)
class Definition(Value):
_fields = ('name', '_source', 'start', 'end', 'decorators', 'docstring',
'children', 'parent')
_human = property(lambda self: humanize(type(self).__name__))
kind = property(lambda self: self._human.split()[-1])
module = property(lambda self: self.parent.module)
all = property(lambda self: self.module.all)
_slice = property(lambda self: slice(self.start - 1, self.end))
source = property(lambda self: ''.join(self._source[self._slice]))
def __iter__(self):
return chain([self], *self.children)
@property
def _publicity(self):
return {True: 'public', False: 'private'}[self.is_public]
def __str__(self):
return 'in %s %s `%s`' % (self._publicity, self._human, self.name)
class Module(Definition):
_fields = ('name', '_source', 'start', 'end', 'decorators', 'docstring',
'children', 'parent', '_all', 'future_imports')
is_public = True
_nest = staticmethod(lambda s: {'def': Function, 'class': Class}[s])
module = property(lambda self: self)
all = property(lambda self: self._all)
def __str__(self):
return 'at module level'
class Package(Module):
"""A package is a __init__.py module."""
class Function(Definition):
_nest = staticmethod(lambda s: {'def': NestedFunction,
'class': NestedClass}[s])
@property
def is_public(self):
if self.all is not None:
return self.name in self.all
else:
return not self.name.startswith('_')
class NestedFunction(Function):
is_public = False
class Method(Function):
@property
def is_public(self):
# Check if we are a setter/deleter method, and mark as private if so.
for decorator in self.decorators:
# Given 'foo', match 'foo.bar' but not 'foobar' or 'sfoo'
if re(r"^{0}\.".format(self.name)).match(decorator.name):
return False
name_is_public = (not self.name.startswith('_') or
self.name in VARIADIC_MAGIC_METHODS or
is_magic(self.name))
return self.parent.is_public and name_is_public
class Class(Definition):
_nest = staticmethod(lambda s: {'def': Method, 'class': NestedClass}[s])
is_public = Function.is_public
class NestedClass(Class):
is_public = False
class Decorator(Value):
"""A decorator for function, method or class."""
_fields = 'name arguments'.split()
class TokenKind(int):
def __repr__(self):
return "tk.{0}".format(tk.tok_name[self])
class Token(Value):
_fields = 'kind value start end source'.split()
def __init__(self, *args):
super(Token, self).__init__(*args)
self.kind = TokenKind(self.kind)
class TokenStream(object):
def __init__(self, filelike):
self._generator = tk.generate_tokens(filelike.readline)
self.current = Token(*next(self._generator, None))
self.line = self.current.start[0]
def move(self):
previous = self.current
current = next(self._generator, None)
self.current = None if current is None else Token(*current)
self.line = self.current.start[0] if self.current else self.line
return previous
def __iter__(self):
while True:
if self.current is not None:
yield self.current
else:
return
self.move()
class AllError(Exception):
def __init__(self, message):
Exception.__init__(
self, message +
'That means pep257 cannot decide which definitions are public. '
'Variable __all__ should be present at most once in each file, '
"in form `__all__ = ('a_public_function', 'APublicClass', ...)`. "
'More info on __all__: http://stackoverflow.com/q/44834/. ')
class Parser(object):
def __call__(self, filelike, filename):
self.source = filelike.readlines()
src = ''.join(self.source)
self.stream = TokenStream(StringIO(src))
self.filename = filename
self.all = None
self.future_imports = defaultdict(lambda: False)
self._accumulated_decorators = []
return self.parse_module()
current = property(lambda self: self.stream.current)
line = property(lambda self: self.stream.line)
def consume(self, kind):
assert self.stream.move().kind == kind
def leapfrog(self, kind, value=None):
"""Skip tokens in the stream until a certain token kind is reached.
If `value` is specified, tokens whose values are different will also
be skipped.
"""
while self.current is not None:
if (self.current.kind == kind and
(value is None or self.current.value == value)):
self.consume(kind)
return
self.stream.move()
def parse_docstring(self):
"""Parse a single docstring and return its value."""
log.debug("parsing docstring, token is %r (%s)",
self.current.kind, self.current.value)
while self.current.kind in (tk.COMMENT, tk.NEWLINE, tk.NL):
self.stream.move()
log.debug("parsing docstring, token is %r (%s)",
self.current.kind, self.current.value)
if self.current.kind == tk.STRING:
docstring = self.current.value
self.stream.move()
return docstring
return None
def parse_decorators(self):
"""Called after first @ is found.
Parse decorators into self._accumulated_decorators.
Continue to do so until encountering the 'def' or 'class' start token.
"""
name = []
arguments = []
at_arguments = False
while self.current is not None:
if (self.current.kind == tk.NAME and
self.current.value in ['def', 'class']):
# Done with decorators - found function or class proper
break
elif self.current.kind == tk.OP and self.current.value == '@':
# New decorator found. Store the decorator accumulated so far:
self._accumulated_decorators.append(
Decorator(''.join(name), ''.join(arguments)))
# Now reset to begin accumulating the new decorator:
name = []
arguments = []
at_arguments = False
elif self.current.kind == tk.OP and self.current.value == '(':
at_arguments = True
elif self.current.kind == tk.OP and self.current.value == ')':
# Ignore close parenthesis
pass
elif self.current.kind == tk.NEWLINE or self.current.kind == tk.NL:
# Ignore newlines
pass
else:
# Keep accumulating current decorator's name or argument.
if not at_arguments:
name.append(self.current.value)
else:
arguments.append(self.current.value)
self.stream.move()
# Add decorator accumulated so far
self._accumulated_decorators.append(
Decorator(''.join(name), ''.join(arguments)))
def parse_definitions(self, class_, all=False):
"""Parse multiple defintions and yield them."""
while self.current is not None:
log.debug("parsing defintion list, current token is %r (%s)",
self.current.kind, self.current.value)
if all and self.current.value == '__all__':
self.parse_all()
elif self.current.kind == tk.OP and self.current.value == '@':
self.consume(tk.OP)
self.parse_decorators()
elif self.current.value in ['def', 'class']:
yield self.parse_definition(class_._nest(self.current.value))
elif self.current.kind == tk.INDENT:
self.consume(tk.INDENT)
for definition in self.parse_definitions(class_):
yield definition
elif self.current.kind == tk.DEDENT:
self.consume(tk.DEDENT)
return
elif self.current.value == 'from':
self.parse_from_import_statement()
else:
self.stream.move()
def parse_all(self):
"""Parse the __all__ definition in a module."""
assert self.current.value == '__all__'
self.consume(tk.NAME)
if self.current.value != '=':
raise AllError('Could not evaluate contents of __all__. ')
self.consume(tk.OP)
if self.current.value not in '([':
raise AllError('Could not evaluate contents of __all__. ')
if self.current.value == '[':
msg = ("%s WARNING: __all__ is defined as a list, this means "
"pep257 cannot reliably detect contents of the __all__ "
"variable, because it can be mutated. Change __all__ to be "
"an (immutable) tuple, to remove this warning. Note, "
"pep257 uses __all__ to detect which definitions are "
"public, to warn if public definitions are missing "
"docstrings. If __all__ is a (mutable) list, pep257 cannot "
"reliably assume its contents. pep257 will proceed "
"assuming __all__ is not mutated.\n" % self.filename)
sys.stderr.write(msg)
self.consume(tk.OP)
self.all = []
all_content = "("
while self.current.kind != tk.OP or self.current.value not in ")]":
if self.current.kind in (tk.NL, tk.COMMENT):
pass
elif (self.current.kind == tk.STRING or
self.current.value == ','):
all_content += self.current.value
else:
kind = token.tok_name[self.current.kind]
raise AllError('Unexpected token kind in __all__: %s' % kind)
self.stream.move()
self.consume(tk.OP)
all_content += ")"
try:
self.all = eval(all_content, {})
except BaseException as e:
raise AllError('Could not evaluate contents of __all__.'
'\bThe value was %s. The exception was:\n%s'
% (all_content, e))
def parse_module(self):
"""Parse a module (and its children) and return a Module object."""
log.debug("parsing module.")
start = self.line
docstring = self.parse_docstring()
children = list(self.parse_definitions(Module, all=True))
assert self.current is None, self.current
end = self.line
cls = Module
if self.filename.endswith('__init__.py'):
cls = Package
module = cls(self.filename, self.source, start, end,
[], docstring, children, None, self.all)
for child in module.children:
child.parent = module
module.future_imports = self.future_imports
log.debug("finished parsing module.")
return module
def parse_definition(self, class_):
"""Parse a defintion and return its value in a `class_` object."""
start = self.line
self.consume(tk.NAME)
name = self.current.value
log.debug("parsing %s '%s'", class_.__name__, name)
self.stream.move()
if self.current.kind == tk.OP and self.current.value == '(':
parenthesis_level = 0
while True:
if self.current.kind == tk.OP:
if self.current.value == '(':
parenthesis_level += 1
elif self.current.value == ')':
parenthesis_level -= 1
if parenthesis_level == 0:
break
self.stream.move()
if self.current.kind != tk.OP or self.current.value != ':':
self.leapfrog(tk.OP, value=":")
else:
self.consume(tk.OP)
if self.current.kind in (tk.NEWLINE, tk.COMMENT):
self.leapfrog(tk.INDENT)
assert self.current.kind != tk.INDENT
docstring = self.parse_docstring()
decorators = self._accumulated_decorators
self._accumulated_decorators = []
log.debug("parsing nested defintions.")
children = list(self.parse_definitions(class_))
log.debug("finished parsing nested defintions for '%s'", name)
end = self.line - 1
else: # one-liner definition
docstring = self.parse_docstring()
decorators = [] # TODO
children = []
end = self.line
self.leapfrog(tk.NEWLINE)
definition = class_(name, self.source, start, end,
decorators, docstring, children, None)
for child in definition.children:
child.parent = definition
log.debug("finished parsing %s '%s'. Next token is %r (%s)",
class_.__name__, name, self.current.kind,
self.current.value)
return definition
def parse_from_import_statement(self):
"""Parse a 'from x import y' statement.
The purpose is to find __future__ statements.
"""
log.debug('parsing from/import statement.')
assert self.current.value == 'from', self.current.value
self.stream.move()
if self.current.value != '__future__':
return
self.stream.move()
assert self.current.value == 'import', self.current.value
self.stream.move()
if self.current.value == '(':
self.consume(tk.OP)
expected_end_kind = tk.OP
else:
expected_end_kind = tk.NEWLINE
while self.current.kind != expected_end_kind:
if self.current.kind != tk.NAME:
self.stream.move()
continue
log.debug("parsing import, token is %r (%s)",
self.current.kind, self.current.value)
log.debug('found future import: %s', self.current.value)
self.future_imports[self.current.value] = True
self.consume(tk.NAME)
log.debug("parsing import, token is %r (%s)",
self.current.kind, self.current.value)
if self.current.kind == tk.NAME:
self.consume(tk.NAME) # as
self.consume(tk.NAME) # new name, irrelevant
if self.current.value == ',':
self.consume(tk.OP)
log.debug("parsing import, token is %r (%s)",
self.current.kind, self.current.value)
class Error(object):
"""Error in docstring style."""
# should be overridden by inheriting classes
code = None
short_desc = None
context = None
# Options that define how errors are printed:
explain = False
source = False
def __init__(self, *parameters):
self.parameters = parameters
self.definition = None
self.explanation = None
def set_context(self, definition, explanation):
self.definition = definition
self.explanation = explanation
filename = property(lambda self: self.definition.module.name)
line = property(lambda self: self.definition.start)
@property
def message(self):
ret = '%s: %s' % (self.code, self.short_desc)
if self.context is not None:
ret += ' (' + self.context % self.parameters + ')'
return ret
@property
def lines(self):
source = ''
lines = self.definition._source[self.definition._slice]
offset = self.definition.start
lines_stripped = list(reversed(list(dropwhile(is_blank,
reversed(lines)))))
numbers_width = 0
for n, line in enumerate(lines_stripped):
numbers_width = max(numbers_width, n + offset)
numbers_width = len(str(numbers_width))
numbers_width = 6
for n, line in enumerate(lines_stripped):
source += '%*d: %s' % (numbers_width, n + offset, line)
if n > 5:
source += ' ...\n'
break
return source
def __str__(self):
self.explanation = '\n'.join(l for l in self.explanation.split('\n')
if not is_blank(l))
template = '%(filename)s:%(line)s %(definition)s:\n %(message)s'
if self.source and self.explain:
template += '\n\n%(explanation)s\n\n%(lines)s\n'
elif self.source and not self.explain:
template += '\n\n%(lines)s\n'
elif self.explain and not self.source:
template += '\n\n%(explanation)s\n\n'
return template % dict((name, getattr(self, name)) for name in
['filename', 'line', 'definition', 'message',
'explanation', 'lines'])
__repr__ = __str__
def __lt__(self, other):
return (self.filename, self.line) < (other.filename, other.line)
class ErrorRegistry(object):
groups = []
class ErrorGroup(object):
def __init__(self, prefix, name):
self.prefix = prefix
self.name = name
self.errors = []
def create_error(self, error_code, error_desc, error_context=None):
# TODO: check prefix
class _Error(Error):
code = error_code
short_desc = error_desc
context = error_context
self.errors.append(_Error)
return _Error
@classmethod
def create_group(cls, prefix, name):
group = cls.ErrorGroup(prefix, name)
cls.groups.append(group)
return group
@classmethod
def get_error_codes(cls):
for group in cls.groups:
for error in group.errors:
yield error.code
@classmethod
def to_rst(cls):
sep_line = '+' + 6 * '-' + '+' + '-' * 71 + '+\n'
blank_line = '|' + 78 * ' ' + '|\n'
table = ''
for group in cls.groups:
table += sep_line
table += blank_line
table += '|' + ('**%s**' % group.name).center(78) + '|\n'
table += blank_line
for error in group.errors:
table += sep_line
table += ('|' + error.code.center(6) + '| ' +
error.short_desc.ljust(70) + '|\n')
table += sep_line
return table
D1xx = ErrorRegistry.create_group('D1', 'Missing Docstrings')
D100 = D1xx.create_error('D100', 'Missing docstring in public module')
D101 = D1xx.create_error('D101', 'Missing docstring in public class')
D102 = D1xx.create_error('D102', 'Missing docstring in public method')
D103 = D1xx.create_error('D103', 'Missing docstring in public function')
D104 = D1xx.create_error('D104', 'Missing docstring in public package')
D105 = D1xx.create_error('D105', 'Missing docstring in magic method')
D2xx = ErrorRegistry.create_group('D2', 'Whitespace Issues')
D200 = D2xx.create_error('D200', 'One-line docstring should fit on one line '
'with quotes', 'found %s')
D201 = D2xx.create_error('D201', 'No blank lines allowed before function '
'docstring', 'found %s')
D202 = D2xx.create_error('D202', 'No blank lines allowed after function '
'docstring', 'found %s')
D203 = D2xx.create_error('D203', '1 blank line required before class '
'docstring', 'found %s')
D204 = D2xx.create_error('D204', '1 blank line required after class '
'docstring', 'found %s')
D205 = D2xx.create_error('D205', '1 blank line required between summary line '
'and description', 'found %s')
D206 = D2xx.create_error('D206', 'Docstring should be indented with spaces, '
'not tabs')
D207 = D2xx.create_error('D207', 'Docstring is under-indented')
D208 = D2xx.create_error('D208', 'Docstring is over-indented')
D209 = D2xx.create_error('D209', 'Multi-line docstring closing quotes should '
'be on a separate line')
D210 = D2xx.create_error('D210', 'No whitespaces allowed surrounding '
'docstring text')
D211 = D2xx.create_error('D211', 'No blank lines allowed before class '
'docstring', 'found %s')
D3xx = ErrorRegistry.create_group('D3', 'Quotes Issues')
D300 = D3xx.create_error('D300', 'Use """triple double quotes"""',
'found %s-quotes')
D301 = D3xx.create_error('D301', 'Use r""" if any backslashes in a docstring')
D302 = D3xx.create_error('D302', 'Use u""" for Unicode docstrings')
D4xx = ErrorRegistry.create_group('D4', 'Docstring Content Issues')
D400 = D4xx.create_error('D400', 'First line should end with a period',
'not %r')
D401 = D4xx.create_error('D401', 'First line should be in imperative mood',
'%r, not %r')
D402 = D4xx.create_error('D402', 'First line should not be the function\'s '
'"signature"')
class AttrDict(dict):
def __getattr__(self, item):
return self[item]
conventions = AttrDict({
'pep257': set(ErrorRegistry.get_error_codes()) - set(['D203']),
})
# General configurations for pep257 run.
RunConfiguration = namedtuple('RunConfiguration',
('explain', 'source', 'debug',
'verbose', 'count'))
class IllegalConfiguration(Exception):
"""An exception for illegal configurations."""
pass
# Check configuration - used by the ConfigurationParser class.
CheckConfiguration = namedtuple('CheckConfiguration',
('checked_codes', 'match', 'match_dir'))
def check_initialized(method):
"""Check that the configuration object was initialized."""
def _decorator(self, *args, **kwargs):
if self._arguments is None or self._options is None:
raise RuntimeError('using an uninitialized configuration')
return method(self, *args, **kwargs)
return _decorator
class ConfigurationParser(object):
"""Responsible for parsing configuration from files and CLI.
There are 2 types of configurations: Run configurations and Check
configurations.
Run Configurations:
------------------
Responsible for deciding things that are related to the user interface,
e.g. verbosity, debug options, etc.
All run configurations default to `False` and are decided only by CLI.
Check Configurations:
--------------------
Configurations that are related to which files and errors will be checked.
These are configurable in 2 ways: using the CLI, and using configuration
files.
Configuration files are nested within the file system, meaning that the
closer a configuration file is to a checked file, the more relevant it will
be. For instance, imagine this directory structure:
A
+-- tox.ini: sets `select=D100`
+-- B
+-- foo.py
+-- tox.ini: sets `add-ignore=D100`
Then `foo.py` will not be checked for `D100`.
The configuration build algorithm is described in `self._get_config`.
Note: If any of `BASE_ERROR_SELECTION_OPTIONS` was selected in the CLI, all
configuration files will be ignored and each file will be checked for
the error codes supplied in the CLI.
"""
CONFIG_FILE_OPTIONS = ('convention', 'select', 'ignore', 'add-select',
'add-ignore', 'match', 'match-dir')
BASE_ERROR_SELECTION_OPTIONS = ('ignore', 'select', 'convention')
DEFAULT_MATCH_RE = '(?!test_).*\.py'
DEFAULT_MATCH_DIR_RE = '[^\.].*'
DEFAULT_CONVENTION = conventions.pep257
PROJECT_CONFIG_FILES = ('setup.cfg', 'tox.ini', '.pep257')
def __init__(self):
"""Create a configuration parser."""
self._cache = {}
self._override_by_cli = None
self._options = self._arguments = self._run_conf = None
self._parser = self._create_option_parser()
# ---------------------------- Public Methods -----------------------------
def get_default_run_configuration(self):
"""Return a `RunConfiguration` object set with default values."""
options, _ = self._parse_args([])
return self._create_run_config(options)
def parse(self):
"""Parse the configuration.
If one of `BASE_ERROR_SELECTION_OPTIONS` was selected, overrides all
error codes to check and disregards any error code related
configurations from the configuration files.
"""
self._options, self._arguments = self._parse_args()
self._arguments = self._arguments or ['.']
if not self._validate_options(self._options):
raise IllegalConfiguration()
self._run_conf = self._create_run_config(self._options)
config = self._create_check_config(self._options, use_dafaults=False)
self._override_by_cli = config
@check_initialized
def get_user_run_configuration(self):
"""Return the run configuration for pep257."""
return self._run_conf
@check_initialized
def get_files_to_check(self):
"""Generate files and error codes to check on each one.
Walk dir trees under `self._arguments` and generate yield filnames
that `match` under each directory that `match_dir`.
The method locates the configuration for each file name and yields a
tuple of (filename, [error_codes]).
With every discovery of a new configuration file `IllegalConfiguration`
might be raised.
"""
def _get_matches(config):
"""Return the `match` and `match_dir` functions for `config`."""
match_func = re(config.match + '$').match
match_dir_func = re(config.match_dir + '$').match
return match_func, match_dir_func
for name in self._arguments:
if os.path.isdir(name):
for root, dirs, filenames in os.walk(name):
config = self._get_config(root)
match, match_dir = _get_matches(config)
# Skip any dirs that do not match match_dir
dirs[:] = [dir for dir in dirs if match_dir(dir)]
for filename in filenames:
if match(filename):
full_path = os.path.join(root, filename)
yield full_path, list(config.checked_codes)
else:
config = self._get_config(name)
match, _ = _get_matches(config)
if match(name):
yield name, list(config.checked_codes)
# --------------------------- Private Methods -----------------------------
def _get_config(self, node):
"""Get and cache the run configuration for `node`.
If no configuration exists (not local and not for the parend node),
returns and caches a default configuration.
The algorithm:
-------------
* If the current directory's configuration exists in
`self._cache` - return it.
* If a configuration file does not exist in this directory:
* If the directory is not a root directory:
* Cache its configuration as this directory's and return it.
* Else:
* Cache a default configuration and return it.
* Else:
* Read the configuration file.
* If a parent directory exists AND the configuration file
allows inheritance:
* Read the parent configuration by calling this function with the
parent directory as `node`.
* Merge the parent configuration with the current one and
cache it.
* If the user has specified one of `BASE_ERROR_SELECTION_OPTIONS` in
the CLI - return the CLI configuration with the configuration match
clauses
* Set the `--add-select` and `--add-ignore` CLI configurations.
"""
path = os.path.abspath(node)
path = path if os.path.isdir(path) else os.path.dirname(path)
if path in self._cache:
return self._cache[path]
config_file = self._get_config_file_in_folder(path)
if config_file is None:
parent_dir, tail = os.path.split(path)
if tail:
# No configuration file, simply take the parent's.
config = self._get_config(parent_dir)
else:
# There's no configuration file and no parent directory.
# Use the default configuration or the one given in the CLI.
config = self._create_check_config(self._options)
else:
# There's a config file! Read it and merge if necessary.
options, inherit = self._read_configuration_file(config_file)
parent_dir, tail = os.path.split(path)
if tail and inherit:
# There is a parent dir and we should try to merge.
parent_config = self._get_config(parent_dir)
config = self._merge_configuration(parent_config, options)
else:
# No need to merge or parent dir does not exist.
config = self._create_check_config(options)
# Make the CLI always win
final_config = {}
for attr in CheckConfiguration._fields:
cli_val = getattr(self._override_by_cli, attr)
conf_val = getattr(config, attr)
final_config[attr] = cli_val if cli_val is not None else conf_val
config = CheckConfiguration(**final_config)
self._set_add_options(config.checked_codes, self._options)
self._cache[path] = config
return self._cache[path]
def _read_configuration_file(self, path):
"""Try to read and parse `path` as a pep257 configuration file.
If the configurations were illegal (checked with
`self._validate_options`), raises `IllegalConfiguration`.
Returns (options, should_inherit).
"""
parser = RawConfigParser()
options = None
should_inherit = True
if parser.read(path) and parser.has_section('pep257'):
option_list = dict([(o.dest, o.type or o.action)
for o in self._parser.option_list])
# First, read the default values
new_options, _ = self._parse_args([])
# Second, parse the configuration
pep257_section = 'pep257'
for opt in parser.options(pep257_section):
if opt == 'inherit':
should_inherit = parser.getboolean(pep257_section, opt)
continue
if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS:
log.warning("Unknown option '{0}' ignored".format(opt))
continue
normalized_opt = opt.replace('-', '_')
opt_type = option_list[normalized_opt]
if opt_type in ('int', 'count'):
value = parser.getint(pep257_section, opt)
elif opt_type == 'string':
value = parser.get(pep257_section, opt)
else:
assert opt_type in ('store_true', 'store_false')
value = parser.getboolean(pep257_section, opt)
setattr(new_options, normalized_opt, value)
# Third, fix the set-options
options = self._fix_set_options(new_options)
if options is not None:
if not self._validate_options(options):
raise IllegalConfiguration('in file: {0}'.format(path))
return options, should_inherit
def _merge_configuration(self, parent_config, child_options):
"""Merge parent config into the child options.
The migration process requires an `options` object for the child in
order to distinguish between mutually exclusive codes, add-select and
add-ignore error codes.
"""
# Copy the parent error codes so we won't override them
error_codes = copy.deepcopy(parent_config.checked_codes)
if self._has_exclusive_option(child_options):
error_codes = self._get_exclusive_error_codes(child_options)
self._set_add_options(error_codes, child_options)
match = child_options.match \
if child_options.match is not None else parent_config.match
match_dir = child_options.match_dir \
if child_options.match_dir is not None else parent_config.match_dir
return CheckConfiguration(checked_codes=error_codes,
match=match,
match_dir=match_dir)
def _parse_args(self, args=None, values=None):
"""Parse the options using `self._parser` and reformat the options."""
options, arguments = self._parser.parse_args(args, values)
return self._fix_set_options(options), arguments
@staticmethod
def _create_run_config(options):
"""Create a `RunConfiguration` object from `options`."""
values = dict([(opt, getattr(options, opt)) for opt in
RunConfiguration._fields])
return RunConfiguration(**values)
@classmethod
def _create_check_config(cls, options, use_dafaults=True):
"""Create a `CheckConfiguration` object from `options`.
If `use_dafaults`, any of the match options that are `None` will
be replaced with their default value and the default convention will be
set for the checked codes.
"""
match = cls.DEFAULT_MATCH_RE \
if options.match is None and use_dafaults \
else options.match
match_dir = cls.DEFAULT_MATCH_DIR_RE \
if options.match_dir is None and use_dafaults \
else options.match_dir
checked_codes = None
if cls._has_exclusive_option(options) or use_dafaults:
checked_codes = cls._get_checked_errors(options)
return CheckConfiguration(checked_codes=checked_codes,
match=match, match_dir=match_dir)
@classmethod
def _get_config_file_in_folder(cls, path):
"""Look for a configuration file in `path`.
If exists return it's full path, otherwise None.
"""
if os.path.isfile(path):
path = os.path.dirname(path)
for fn in cls.PROJECT_CONFIG_FILES:
config = RawConfigParser()
full_path = os.path.join(path, fn)
if config.read(full_path) and config.has_section('pep257'):
return full_path
@staticmethod
def _get_exclusive_error_codes(options):
"""Extract the error codes from the selected exclusive option."""
codes = set(ErrorRegistry.get_error_codes())
checked_codes = None
if options.ignore is not None:
checked_codes = codes - options.ignore
elif options.select is not None:
checked_codes = options.select
elif options.convention is not None:
checked_codes = getattr(conventions, options.convention)
# To not override the conventions nor the options - copy them.
return copy.deepcopy(checked_codes)
@staticmethod
def _set_add_options(checked_codes, options):
"""Set `checked_codes` by the `add_ignore` or `add_select` options."""
checked_codes |= options.add_select
checked_codes -= options.add_ignore
@classmethod
def _get_checked_errors(cls, options):
"""Extract the codes needed to be checked from `options`."""
checked_codes = cls._get_exclusive_error_codes(options)
if checked_codes is None:
checked_codes = cls.DEFAULT_CONVENTION
cls._set_add_options(checked_codes, options)
return checked_codes
@classmethod
def _validate_options(cls, options):
"""Validate the mutually exclusive options.
Return `True` iff only zero or one of `BASE_ERROR_SELECTION_OPTIONS`
was selected.
"""
for opt1, opt2 in \
itertools.permutations(cls.BASE_ERROR_SELECTION_OPTIONS, 2):
if getattr(options, opt1) and getattr(options, opt2):
log.error('Cannot pass both {0} and {1}. They are '
'mutually exclusive.'.format(opt1, opt2))
return False
if options.convention and options.convention not in conventions:
log.error("Illegal convention '{0}'. Possible conventions: {1}"
.format(options.convention,
', '.join(conventions.keys())))
return False
return True
@classmethod
def _has_exclusive_option(cls, options):
"""Return `True` iff one or more exclusive options were selected."""
return any([getattr(options, opt) is not None for opt in
cls.BASE_ERROR_SELECTION_OPTIONS])
@staticmethod
def _fix_set_options(options):
"""Alter the set options from None/strings to sets in place."""
optional_set_options = ('ignore', 'select')
mandatory_set_options = ('add_ignore', 'add_select')
def _get_set(value_str):
"""Split `value_str` by the delimiter `,` and return a set.
Removes any occurrences of '' in the set.
"""
return set(value_str.split(',')) - set([''])
for opt in optional_set_options:
value = getattr(options, opt)
if value is not None:
setattr(options, opt, _get_set(value))
for opt in mandatory_set_options:
value = getattr(options, opt)
if value is None:
value = ''
if not isinstance(value, Set):
value = _get_set(value)
setattr(options, opt, value)
return options
@classmethod
def _create_option_parser(cls):
"""Return an option parser to parse the command line arguments."""
from optparse import OptionParser
parser = OptionParser(version=__version__,
usage='Usage: pep257 [options] [<file|dir>...]')
option = parser.add_option
# Run configuration options
option('-e', '--explain', action='store_true', default=False,
help='show explanation of each error')
option('-s', '--source', action='store_true', default=False,
help='show source for each error')
option('-d', '--debug', action='store_true', default=False,
help='print debug information')
option('-v', '--verbose', action='store_true', default=False,
help='print status information')
option('--count', action='store_true', default=False,
help='print total number of errors to stdout')
# Error check options
option('--select', metavar='<codes>', default=None,
help='choose the basic list of checked errors by '
'specifying which errors to check for (with a list of '
'comma-separated error codes). '
'for example: --select=D101,D202')
option('--ignore', metavar='<codes>', default=None,
help='choose the basic list of checked errors by '
'specifying which errors to ignore (with a list of '
'comma-separated error codes). '
'for example: --ignore=D101,D202')
option('--convention', metavar='<name>', default=None,
help='choose the basic list of checked errors by specifying an '
'existing convention. Possible conventions: {0}'
.format(', '.join(conventions)))
option('--add-select', metavar='<codes>', default=None,
help='amend the list of errors to check for by specifying '
'more error codes to check.')
option('--add-ignore', metavar='<codes>', default=None,
help='amend the list of errors to check for by specifying '
'more error codes to ignore.')
# Match clauses
option('--match', metavar='<pattern>', default=None,
help=("check only files that exactly match <pattern> regular "
"expression; default is --match='{0}' which matches "
"files that don't start with 'test_' but end with "
"'.py'").format(cls.DEFAULT_MATCH_RE))
option('--match-dir', metavar='<pattern>', default=None,
help=("search only dirs that exactly match <pattern> regular "
"expression; default is --match-dir='{0}', which "
"matches all dirs that don't start with "
"a dot").format(cls.DEFAULT_MATCH_DIR_RE))
return parser
def check(filenames, select=None, ignore=None):
"""Generate PEP 257 errors that exist in `filenames` iterable.
Only returns errors with error-codes defined in `checked_codes` iterable.
Example
-------
>>> check(['pep257.py'], checked_codes=['D100'])
<generator object check at 0x...>
"""
if select is not None and ignore is not None:
raise IllegalConfiguration('Cannot pass both select and ignore. '
'They are mutually exclusive.')
elif select is not None:
checked_codes = select
elif ignore is not None:
checked_codes = list(set(ErrorRegistry.get_error_codes()) -
set(ignore))
else:
checked_codes = conventions.pep257
for filename in filenames:
log.info('Checking file %s.', filename)
try:
with tokenize_open(filename) as file:
source = file.read()
for error in PEP257Checker().check_source(source, filename):
code = getattr(error, 'code', None)
if code in checked_codes:
yield error
except (EnvironmentError, AllError):
yield sys.exc_info()[1]
except tk.TokenError:
yield SyntaxError('invalid syntax in file %s' % filename)
def setup_stream_handlers(conf):
"""Setup logging stream handlers according to the options."""
class StdoutFilter(logging.Filter):
def filter(self, record):
return record.levelno in (logging.DEBUG, logging.INFO)
if log.handlers:
for handler in log.handlers:
log.removeHandler(handler)
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.WARNING)
stdout_handler.addFilter(StdoutFilter())
if conf.debug:
stdout_handler.setLevel(logging.DEBUG)
elif conf.verbose:
stdout_handler.setLevel(logging.INFO)
else:
stdout_handler.setLevel(logging.WARNING)
log.addHandler(stdout_handler)
stderr_handler = logging.StreamHandler(sys.stderr)
stderr_handler.setLevel(logging.WARNING)
log.addHandler(stderr_handler)
def run_pep257():
log.setLevel(logging.DEBUG)
conf = ConfigurationParser()
setup_stream_handlers(conf.get_default_run_configuration())
try:
conf.parse()
except IllegalConfiguration:
return INVALID_OPTIONS_RETURN_CODE
run_conf = conf.get_user_run_configuration()
# Reset the logger according to the command line arguments
setup_stream_handlers(run_conf)
log.debug("starting pep257 in debug mode.")
Error.explain = run_conf.explain
Error.source = run_conf.source
errors = []
try:
for filename, checked_codes in conf.get_files_to_check():
errors.extend(check((filename,), select=checked_codes))
except IllegalConfiguration:
# An illegal configuration file was found during file generation.
return INVALID_OPTIONS_RETURN_CODE
code = NO_VIOLATIONS_RETURN_CODE
count = 0
for error in errors:
sys.stderr.write('%s\n' % error)
code = VIOLATIONS_RETURN_CODE
count += 1
if run_conf.count:
print(count)
return code
parse = Parser()
def check_for(kind, terminal=False):
def decorator(f):
f._check_for = kind
f._terminal = terminal
return f
return decorator
class PEP257Checker(object):
"""Checker for PEP 257.
D10x: Missing docstrings
D20x: Whitespace issues
D30x: Docstring formatting
D40x: Docstring content issues
"""
def check_source(self, source, filename):
module = parse(StringIO(source), filename)
for definition in module:
for check in self.checks:
terminate = False
if isinstance(definition, check._check_for):
error = check(None, definition, definition.docstring)
errors = error if hasattr(error, '__iter__') else [error]
for error in errors:
if error is not None:
partition = check.__doc__.partition('.\n')
message, _, explanation = partition
error.set_context(explanation=explanation,
definition=definition)
yield error
if check._terminal:
terminate = True
break
if terminate:
break
@property
def checks(self):
all = [check for check in vars(type(self)).values()
if hasattr(check, '_check_for')]
return sorted(all, key=lambda check: not check._terminal)
@check_for(Definition, terminal=True)
def check_docstring_missing(self, definition, docstring):
"""D10{0,1,2,3}: Public definitions should have docstrings.
All modules should normally have docstrings. [...] all functions and
classes exported by a module should also have docstrings. Public
methods (including the __init__ constructor) should also have
docstrings.
Note: Public (exported) definitions are either those with names listed
in __all__ variable (if present), or those that do not start
with a single underscore.
"""
if (not docstring and definition.is_public or
docstring and is_blank(eval(docstring))):
codes = {Module: D100, Class: D101, NestedClass: D101,
Method: (lambda: D105() if is_magic(definition.name)
else D102()),
Function: D103, NestedFunction: D103, Package: D104}
return codes[type(definition)]()
@check_for(Definition)
def check_one_liners(self, definition, docstring):
"""D200: One-liner docstrings should fit on one line with quotes.
The closing quotes are on the same line as the opening quotes.
This looks better for one-liners.
"""
if docstring:
lines = eval(docstring).split('\n')
if len(lines) > 1:
non_empty_lines = sum(1 for l in lines if not is_blank(l))
if non_empty_lines == 1:
return D200(len(lines))
@check_for(Function)
def check_no_blank_before(self, function, docstring): # def
"""D20{1,2}: No blank lines allowed around function/method docstring.
There's no blank line either before or after the docstring.
"""
# NOTE: This does not take comments into account.
# NOTE: This does not take into account functions with groups of code.
if docstring:
before, _, after = function.source.partition(docstring)
blanks_before = list(map(is_blank, before.split('\n')[:-1]))
blanks_after = list(map(is_blank, after.split('\n')[1:]))
blanks_before_count = sum(takewhile(bool, reversed(blanks_before)))
blanks_after_count = sum(takewhile(bool, blanks_after))
if blanks_before_count != 0:
yield D201(blanks_before_count)
if not all(blanks_after) and blanks_after_count != 0:
yield D202(blanks_after_count)
@check_for(Class)
def check_blank_before_after_class(slef, class_, docstring):
"""D20{3,4}: Class docstring should have 1 blank line around them.
Insert a blank line before and after all docstrings (one-line or
multi-line) that document a class -- generally speaking, the class's
methods are separated from each other by a single blank line, and the
docstring needs to be offset from the first method by a blank line;
for symmetry, put a blank line between the class header and the
docstring.
"""
# NOTE: this gives false-positive in this case
# class Foo:
#
# """Docstring."""
#
#
# # comment here
# def foo(): pass
if docstring:
before, _, after = class_.source.partition(docstring)
blanks_before = list(map(is_blank, before.split('\n')[:-1]))
blanks_after = list(map(is_blank, after.split('\n')[1:]))
blanks_before_count = sum(takewhile(bool, reversed(blanks_before)))
blanks_after_count = sum(takewhile(bool, blanks_after))
if blanks_before_count != 0:
yield D211(blanks_before_count)
if blanks_before_count != 1:
yield D203(blanks_before_count)
if not all(blanks_after) and blanks_after_count != 1:
yield D204(blanks_after_count)
@check_for(Definition)
def check_blank_after_summary(self, definition, docstring):
"""D205: Put one blank line between summary line and description.
Multi-line docstrings consist of a summary line just like a one-line
docstring, followed by a blank line, followed by a more elaborate
description. The summary line may be used by automatic indexing tools;
it is important that it fits on one line and is separated from the
rest of the docstring by a blank line.
"""
if docstring:
lines = eval(docstring).strip().split('\n')
if len(lines) > 1:
post_summary_blanks = list(map(is_blank, lines[1:]))
blanks_count = sum(takewhile(bool, post_summary_blanks))
if blanks_count != 1:
return D205(blanks_count)
@check_for(Definition)
def check_indent(self, definition, docstring):
"""D20{6,7,8}: The entire docstring should be indented same as code.
The entire docstring is indented the same as the quotes at its
first line.
"""
if docstring:
before_docstring, _, _ = definition.source.partition(docstring)
_, _, indent = before_docstring.rpartition('\n')
lines = docstring.split('\n')
if len(lines) > 1:
lines = lines[1:] # First line does not need indent.
indents = [leading_space(l) for l in lines if not is_blank(l)]
if set(' \t') == set(''.join(indents) + indent):
yield D206()
if (len(indents) > 1 and min(indents[:-1]) > indent or
indents[-1] > indent):
yield D208()
if min(indents) < indent:
yield D207()
@check_for(Definition)
def check_newline_after_last_paragraph(self, definition, docstring):
"""D209: Put multi-line docstring closing quotes on separate line.
Unless the entire docstring fits on a line, place the closing
quotes on a line by themselves.
"""
if docstring:
lines = [l for l in eval(docstring).split('\n') if not is_blank(l)]
if len(lines) > 1:
if docstring.split("\n")[-1].strip() not in ['"""', "'''"]:
return D209()
@check_for(Definition)
def check_surrounding_whitespaces(self, definition, docstring):
"""D210: No whitespaces allowed surrounding docstring text."""
if docstring:
lines = eval(docstring).split('\n')
if lines[0].startswith(' ') or \
len(lines) == 1 and lines[0].endswith(' '):
return D210()
@check_for(Definition)
def check_triple_double_quotes(self, definition, docstring):
r'''D300: Use """triple double quotes""".
For consistency, always use """triple double quotes""" around
docstrings. Use r"""raw triple double quotes""" if you use any
backslashes in your docstrings. For Unicode docstrings, use
u"""Unicode triple-quoted strings""".
Note: Exception to this is made if the docstring contains
""" quotes in its body.
'''
if docstring and '"""' in eval(docstring) and docstring.startswith(
("'''", "r'''", "u'''", "ur'''")):
# Allow ''' quotes if docstring contains """, because otherwise """
# quotes could not be expressed inside docstring. Not in PEP 257.
return
if docstring and not docstring.startswith(
('"""', 'r"""', 'u"""', 'ur"""')):
quotes = "'''" if "'''" in docstring[:4] else "'"
return D300(quotes)
@check_for(Definition)
def check_backslashes(self, definition, docstring):
r'''D301: Use r""" if any backslashes in a docstring.
Use r"""raw triple double quotes""" if you use any backslashes
(\) in your docstrings.
'''
# Just check that docstring is raw, check_triple_double_quotes
# ensures the correct quotes.
if docstring and '\\' in docstring and not docstring.startswith(
('r', 'ur')):
return D301()
@check_for(Definition)
def check_unicode_docstring(self, definition, docstring):
r'''D302: Use u""" for docstrings with Unicode.
For Unicode docstrings, use u"""Unicode triple-quoted strings""".
'''
if definition.module.future_imports['unicode_literals']:
return
# Just check that docstring is unicode, check_triple_double_quotes
# ensures the correct quotes.
if docstring and sys.version_info[0] <= 2:
if not is_ascii(docstring) and not docstring.startswith(
('u', 'ur')):
return D302()
@check_for(Definition)
def check_ends_with_period(self, definition, docstring):
"""D400: First line should end with a period.
The [first line of a] docstring is a phrase ending in a period.
"""
if docstring:
summary_line = eval(docstring).strip().split('\n')[0]
if not summary_line.endswith('.'):
return D400(summary_line[-1])
@check_for(Function)
def check_imperative_mood(self, function, docstring): # def context
"""D401: First line should be in imperative mood: 'Do', not 'Does'.
[Docstring] prescribes the function or method's effect as a command:
("Do this", "Return that"), not as a description; e.g. don't write
"Returns the pathname ...".
"""
if docstring:
stripped = eval(docstring).strip()
if stripped:
first_word = stripped.split()[0]
if first_word.endswith('s') and not first_word.endswith('ss'):
return D401(first_word[:-1], first_word)
@check_for(Function)
def check_no_signature(self, function, docstring): # def context
"""D402: First line should not be function's or method's "signature".
The one-line docstring should NOT be a "signature" reiterating the
function/method parameters (which can be obtained by introspection).
"""
if docstring:
first_line = eval(docstring).strip().split('\n')[0]
if function.name + '(' in first_line.replace(' ', ''):
return D402()
# Somewhat hard to determine if return value is mentioned.
# @check(Function)
def SKIP_check_return_type(self, function, docstring):
"""D40x: Return value type should be mentioned.
[T]he nature of the return value cannot be determined by
introspection, so it should be mentioned.
"""
if docstring and function.returns_value:
if 'return' not in docstring.lower():
return Error()
def main():
try:
sys.exit(run_pep257())
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()
|
mit
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
9278,
11284,
4744,
367,
7907,
9214,
8758,
852,
436,
3449,
14,
199,
199,
3500,
5920,
8486,
13663,
11551,
26,
199,
1014,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
15,
12636,
13,
16,
11551,
15,
199,
199,
8632,
5920,
883,
506,
3483,
12,
325,
14,
71,
14,
20602,
9214,
8758,
852,
26,
199,
2859,
921,
5031,
14,
957,
15,
4714,
15,
4714,
15,
6582,
15,
4133,
15,
1301,
15,
16210,
2566,
63,
7884,
14,
8332,
14,
2424,
199,
199,
1918,
7611,
365,
16180,
737,
26,
199,
1014,
921,
5031,
14,
957,
15,
19456,
51,
5969,
15,
12636,
11551,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
984,
199,
646,
1331,
199,
646,
2050,
199,
646,
13343,
465,
10157,
199,
504,
7975,
492,
5452,
6710,
12,
5978,
6710,
12,
6036,
199,
504,
295,
492,
6555,
465,
295,
199,
646,
7975,
199,
504,
5055,
492,
10018,
12,
12863,
12,
2494,
199,
199,
893,
26,
221,
327,
2018,
650,
14,
88,
272,
687,
14196,
492,
13480,
15218,
199,
2590,
3545,
26,
221,
327,
2018,
499,
14,
88,
272,
687,
21230,
492,
13480,
15218,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
893,
26,
272,
687,
5228,
492,
5228,
199,
2590,
3545,
26,
221,
327,
2018,
650,
14,
16,
436,
2945,
272,
687,
5890,
492,
5228,
421,
199,
893,
26,
272,
2163,
199,
2590,
12746,
26,
221,
327,
2018,
499,
14,
21,
436,
14119,
272,
6548,
275,
909,
342,
339,
347,
2163,
8,
1113,
12,
849,
29,
16323,
304,
267,
340,
849,
508,
6548,
26,
288,
372,
1559,
14,
2184,
342,
267,
587,
26,
288,
862,
26,
355,
372,
1559,
14,
2184,
342,
288,
871,
10852,
26,
355,
372,
849,
421,
199,
3,
982,
3962,
334,
1548,
2356,
650,
14,
18,
9,
675,
13343,
14,
1490,
370,
1551,
1584,
12,
880,
13663,
499,
2766,
199,
3,
2644,
14327,
787,
11922,
14,
199,
893,
26,
272,
13343,
63,
1490,
275,
10157,
14,
1490,
199,
2590,
4281,
26,
272,
13343,
63,
1490,
275,
1551,
421,
199,
363,
1023,
363,
275,
283,
16,
14,
23,
14,
16,
7,
199,
363,
452,
363,
275,
661,
1074,
297,
283,
7112,
358,
199,
199,
2826,
63,
54,
2090,
44,
12969,
63,
9677,
63,
6012,
275,
378,
199,
54,
2090,
44,
12969,
63,
9677,
63,
6012,
275,
413,
199,
9692,
63,
8808,
63,
9677,
63,
6012,
275,
499,
199,
12349,
1554,
948,
63,
19973,
63,
18383,
275,
25038,
826,
7500,
2560,
1250,
7500,
2560,
1222,
13766,
421,
199,
318,
11779,
794,
8,
875,
304,
272,
372,
295,
8,
82,
6774,
4959,
779,
33,
13,
58,
11896,
1959,
954,
8,
82,
1154,
17,
971,
18,
297,
1059,
680,
2325,
342,
421,
199,
318,
365,
63,
11523,
8,
354,
304,
272,
372,
334,
354,
14,
2460,
10714,
358,
436,
288,
536,
14,
4130,
10714,
358,
436,
288,
536,
440,
315,
30098,
1554,
948,
63,
19973,
63,
18383,
9,
421,
199,
318,
365,
63,
4371,
8,
875,
304,
272,
372,
1006,
8,
2181,
8,
1560,
9,
665,
7960,
367,
1495,
315,
1059,
9,
421,
199,
318,
365,
63,
2500,
8,
875,
304,
272,
372,
440,
1059,
14,
1913,
342,
421,
199,
318,
9186,
63,
2638,
8,
875,
304,
272,
372,
295,
2258,
83,
10,
1959,
1431,
8,
875,
680,
923,
342,
421,
199,
533,
1594,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
6802,
8,
277,
680,
873,
8,
3065,
8,
277,
423,
955,
12,
1249,
430,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1163,
436,
6802,
8,
277,
9,
508,
6802,
8,
1848,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
2074,
275,
1656,
1987,
904,
11117,
16,
93,
3126,
17,
1,
82,
5285,
908,
8,
698,
12,
2519,
8,
277,
12,
901,
430,
2574,
367,
901,
315,
291,
423,
955,
9,
267,
372,
5041,
16,
93,
2561,
17,
25885,
908,
8,
277,
855,
533,
4914,
354,
3108,
2074,
9,
421,
199,
533,
29398,
8,
1110,
304,
339,
485,
955,
275,
661,
354,
297,
2513,
1365,
297,
283,
928,
297,
283,
500,
297,
283,
11582,
297,
283,
12485,
297,
2049,
283,
3223,
297,
283,
1708,
358,
339,
485,
14864,
275,
3324,
8,
2734,
291,
26,
11779,
794,
8,
466,
8,
277,
2843,
354,
8964,
272,
4928,
275,
3324,
8,
2734,
291,
26,
291,
423,
14864,
14,
1294,
19105,
17,
566,
272,
859,
275,
3324,
8,
2734,
291,
26,
291,
14,
1708,
14,
578,
9,
272,
1006,
275,
3324,
8,
2734,
291,
26,
291,
14,
578,
14,
452,
9,
272,
485,
5224,
275,
3324,
8,
2734,
291,
26,
6014,
8,
277,
14,
928,
446,
413,
12,
291,
14,
500,
430,
272,
1350,
275,
3324,
8,
2734,
291,
26,
6522,
904,
8,
277,
423,
1365,
59,
277,
423,
5224,
2459,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
6036,
779,
277,
467,
627,
277,
14,
3223,
9,
339,
768,
1829,
272,
347,
485,
5645,
20976,
8,
277,
304,
267,
372,
469,
549,
26,
283,
3455,
297,
756,
26,
283,
4239,
936,
59,
277,
14,
374,
63,
3455,
61,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
262,
450,
83,
450,
83,
18633,
83,
19097,
450,
334,
277,
423,
5645,
20976,
12,
291,
423,
14864,
12,
291,
14,
354,
9,
421,
199,
533,
5673,
8,
10701,
304,
339,
485,
955,
275,
661,
354,
297,
2513,
1365,
297,
283,
928,
297,
283,
500,
297,
283,
11582,
297,
283,
12485,
297,
2049,
283,
3223,
297,
283,
1708,
297,
2513,
452,
297,
283,
2443,
63,
12775,
358,
272,
365,
63,
3455,
275,
715,
272,
485,
15272,
275,
12822,
8,
2734,
308,
26,
791,
318,
356,
6801,
12,
283,
533,
356,
8089,
22857,
83,
566,
272,
859,
275,
3324,
8,
2734,
291,
26,
291,
9,
272,
1006,
275,
3324,
8,
2734,
291,
26,
291,
423,
452,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
292,
859,
2166,
7,
421,
199,
533,
15665,
8,
2377,
304
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
9278,
11284,
4744,
367,
7907,
9214,
8758,
852,
436,
3449,
14,
199,
199,
3500,
5920,
8486,
13663,
11551,
26,
199,
1014,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
15,
12636,
13,
16,
11551,
15,
199,
199,
8632,
5920,
883,
506,
3483,
12,
325,
14,
71,
14,
20602,
9214,
8758,
852,
26,
199,
2859,
921,
5031,
14,
957,
15,
4714,
15,
4714,
15,
6582,
15,
4133,
15,
1301,
15,
16210,
2566,
63,
7884,
14,
8332,
14,
2424,
199,
199,
1918,
7611,
365,
16180,
737,
26,
199,
1014,
921,
5031,
14,
957,
15,
19456,
51,
5969,
15,
12636,
11551,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
984,
199,
646,
1331,
199,
646,
2050,
199,
646,
13343,
465,
10157,
199,
504,
7975,
492,
5452,
6710,
12,
5978,
6710,
12,
6036,
199,
504,
295,
492,
6555,
465,
295,
199,
646,
7975,
199,
504,
5055,
492,
10018,
12,
12863,
12,
2494,
199,
199,
893,
26,
221,
327,
2018,
650,
14,
88,
272,
687,
14196,
492,
13480,
15218,
199,
2590,
3545,
26,
221,
327,
2018,
499,
14,
88,
272,
687,
21230,
492,
13480,
15218,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
893,
26,
272,
687,
5228,
492,
5228,
199,
2590,
3545,
26,
221,
327,
2018,
650,
14,
16,
436,
2945,
272,
687,
5890,
492,
5228,
421,
199,
893,
26,
272,
2163,
199,
2590,
12746,
26,
221,
327,
2018,
499,
14,
21,
436,
14119,
272,
6548,
275,
909,
342,
339,
347,
2163,
8,
1113,
12,
849,
29,
16323,
304,
267,
340,
849,
508,
6548,
26,
288,
372,
1559,
14,
2184,
342,
267,
587,
26,
288,
862,
26,
355,
372,
1559,
14,
2184,
342,
288,
871,
10852,
26,
355,
372,
849,
421,
199,
3,
982,
3962,
334,
1548,
2356,
650,
14,
18,
9,
675,
13343,
14,
1490,
370,
1551,
1584,
12,
880,
13663,
499,
2766,
199,
3,
2644,
14327,
787,
11922,
14,
199,
893,
26,
272,
13343,
63,
1490,
275,
10157,
14,
1490,
199,
2590,
4281,
26,
272,
13343,
63,
1490,
275,
1551,
421,
199,
363,
1023,
363,
275,
283,
16,
14,
23,
14,
16,
7,
199,
363,
452,
363,
275,
661,
1074,
297,
283,
7112,
358,
199,
199,
2826,
63,
54,
2090,
44,
12969,
63,
9677,
63,
6012,
275,
378,
199,
54,
2090,
44,
12969,
63,
9677,
63,
6012,
275,
413,
199,
9692,
63,
8808,
63,
9677,
63,
6012,
275,
499,
199,
12349,
1554,
948,
63,
19973,
63,
18383,
275,
25038,
826,
7500,
2560,
1250,
7500,
2560,
1222,
13766,
421,
199,
318,
11779,
794,
8,
875,
304,
272,
372,
295,
8,
82,
6774,
4959,
779,
33,
13,
58,
11896,
1959,
954,
8,
82,
1154,
17,
971,
18,
297,
1059,
680,
2325,
342,
421,
199,
318,
365,
63,
11523,
8,
354,
304,
272,
372,
334,
354,
14,
2460,
10714,
358,
436,
288,
536,
14,
4130,
10714,
358,
436,
288,
536,
440,
315,
30098,
1554,
948,
63,
19973,
63,
18383,
9,
421,
199,
318,
365,
63,
4371,
8,
875,
304,
272,
372,
1006,
8,
2181,
8,
1560,
9,
665,
7960,
367,
1495,
315,
1059,
9,
421,
199,
318,
365,
63,
2500,
8,
875,
304,
272,
372,
440,
1059,
14,
1913,
342,
421,
199,
318,
9186,
63,
2638,
8,
875,
304,
272,
372,
295,
2258,
83,
10,
1959,
1431,
8,
875,
680,
923,
342,
421,
199,
533,
1594,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
6802,
8,
277,
680,
873,
8,
3065,
8,
277,
423,
955,
12,
1249,
430,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1163,
436,
6802,
8,
277,
9,
508,
6802,
8,
1848,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
2074,
275,
1656,
1987,
904,
11117,
16,
93,
3126,
17,
1,
82,
5285,
908,
8,
698,
12,
2519,
8,
277,
12,
901,
430,
2574,
367,
901,
315,
291,
423,
955,
9,
267,
372,
5041,
16,
93,
2561,
17,
25885,
908,
8,
277,
855,
533,
4914,
354,
3108,
2074,
9,
421,
199,
533,
29398,
8,
1110,
304,
339,
485,
955,
275,
661,
354,
297,
2513,
1365,
297,
283,
928,
297,
283,
500,
297,
283,
11582,
297,
283,
12485,
297,
2049,
283,
3223,
297,
283,
1708,
358,
339,
485,
14864,
275,
3324,
8,
2734,
291,
26,
11779,
794,
8,
466,
8,
277,
2843,
354,
8964,
272,
4928,
275,
3324,
8,
2734,
291,
26,
291,
423,
14864,
14,
1294,
19105,
17,
566,
272,
859,
275,
3324,
8,
2734,
291,
26,
291,
14,
1708,
14,
578,
9,
272,
1006,
275,
3324,
8,
2734,
291,
26,
291,
14,
578,
14,
452,
9,
272,
485,
5224,
275,
3324,
8,
2734,
291,
26,
6014,
8,
277,
14,
928,
446,
413,
12,
291,
14,
500,
430,
272,
1350,
275,
3324,
8,
2734,
291,
26,
6522,
904,
8,
277,
423,
1365,
59,
277,
423,
5224,
2459,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
6036,
779,
277,
467,
627,
277,
14,
3223,
9,
339,
768,
1829,
272,
347,
485,
5645,
20976,
8,
277,
304,
267,
372,
469,
549,
26,
283,
3455,
297,
756,
26,
283,
4239,
936,
59,
277,
14,
374,
63,
3455,
61,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
262,
450,
83,
450,
83,
18633,
83,
19097,
450,
334,
277,
423,
5645,
20976,
12,
291,
423,
14864,
12,
291,
14,
354,
9,
421,
199,
533,
5673,
8,
10701,
304,
339,
485,
955,
275,
661,
354,
297,
2513,
1365,
297,
283,
928,
297,
283,
500,
297,
283,
11582,
297,
283,
12485,
297,
2049,
283,
3223,
297,
283,
1708,
297,
2513,
452,
297,
283,
2443,
63,
12775,
358,
272,
365,
63,
3455,
275,
715,
272,
485,
15272,
275,
12822,
8,
2734,
308,
26,
791,
318,
356,
6801,
12,
283,
533,
356,
8089,
22857,
83,
566,
272,
859,
275,
3324,
8,
2734,
291,
26,
291,
9,
272,
1006,
275,
3324,
8,
2734,
291,
26,
291,
423,
452,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
292,
859,
2166,
7,
421,
199,
533,
15665,
8,
2377,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bdh1011/wau
|
venv/lib/python2.7/site-packages/requests/packages/urllib3/connection.py
|
483
|
9011
|
import datetime
import sys
import socket
from socket import timeout as SocketTimeout
import warnings
from .packages import six
try: # Python 3
from http.client import HTTPConnection as _HTTPConnection, HTTPException
except ImportError:
from httplib import HTTPConnection as _HTTPConnection, HTTPException
class DummyConnection(object):
"Used to detect a failed ConnectionCls import."
pass
try: # Compiled with SSL?
HTTPSConnection = DummyConnection
import ssl
BaseSSLError = ssl.SSLError
except (ImportError, AttributeError): # Platform-specific: No SSL.
ssl = None
class BaseSSLError(BaseException):
pass
try: # Python 3:
# Not a no-op, we're adding this to the namespace so it can be imported.
ConnectionError = ConnectionError
except NameError: # Python 2:
class ConnectionError(Exception):
pass
from .exceptions import (
ConnectTimeoutError,
SystemTimeWarning,
SecurityWarning,
)
from .packages.ssl_match_hostname import match_hostname
from .util.ssl_ import (
resolve_cert_reqs,
resolve_ssl_version,
ssl_wrap_socket,
assert_fingerprint,
)
from .util import connection
port_by_scheme = {
'http': 80,
'https': 443,
}
RECENT_DATE = datetime.date(2014, 1, 1)
class HTTPConnection(_HTTPConnection, object):
"""
Based on httplib.HTTPConnection but provides an extra constructor
backwards-compatibility layer between older and newer Pythons.
Additional keyword parameters are used to configure attributes of the connection.
Accepted parameters include:
- ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
- ``source_address``: Set the source address for the current connection.
.. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x
- ``socket_options``: Set specific options on the underlying socket. If not specified, then
defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.
For example, if you wish to enable TCP Keep Alive in addition to the defaults,
you might pass::
HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
]
Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
"""
default_port = port_by_scheme['http']
#: Disable Nagle's algorithm by default.
#: ``[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]``
default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]
#: Whether this connection verifies the host's certificate.
is_verified = False
def __init__(self, *args, **kw):
if six.PY3: # Python 3
kw.pop('strict', None)
# Pre-set source_address in case we have an older Python like 2.6.
self.source_address = kw.get('source_address')
if sys.version_info < (2, 7): # Python 2.6
# _HTTPConnection on Python 2.6 will balk at this keyword arg, but
# not newer versions. We can still use it when creating a
# connection though, so we pop it *after* we have saved it as
# self.source_address.
kw.pop('source_address', None)
#: The socket options provided by the user. If no options are
#: provided, we use the default options.
self.socket_options = kw.pop('socket_options', self.default_socket_options)
# Superclass also sets self.source_address in Python 2.7+.
_HTTPConnection.__init__(self, *args, **kw)
def _new_conn(self):
""" Establish a socket connection and set nodelay settings on it.
:return: New socket connection.
"""
extra_kw = {}
if self.source_address:
extra_kw['source_address'] = self.source_address
if self.socket_options:
extra_kw['socket_options'] = self.socket_options
try:
conn = connection.create_connection(
(self.host, self.port), self.timeout, **extra_kw)
except SocketTimeout:
raise ConnectTimeoutError(
self, "Connection to %s timed out. (connect timeout=%s)" %
(self.host, self.timeout))
return conn
def _prepare_conn(self, conn):
self.sock = conn
# the _tunnel_host attribute was added in python 2.6.3 (via
# http://hg.python.org/cpython/rev/0f57b30a152f) so pythons 2.6(0-2) do
# not have them.
if getattr(self, '_tunnel_host', None):
# TODO: Fix tunnel so it doesn't depend on self.sock state.
self._tunnel()
# Mark this connection as not reusable
self.auto_open = 0
def connect(self):
conn = self._new_conn()
self._prepare_conn(conn)
class HTTPSConnection(HTTPConnection):
default_port = port_by_scheme['https']
def __init__(self, host, port=None, key_file=None, cert_file=None,
strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, **kw):
HTTPConnection.__init__(self, host, port, strict=strict,
timeout=timeout, **kw)
self.key_file = key_file
self.cert_file = cert_file
# Required property for Google AppEngine 1.9.0 which otherwise causes
# HTTPS requests to go out as HTTP. (See Issue #356)
self._protocol = 'https'
def connect(self):
conn = self._new_conn()
self._prepare_conn(conn)
self.sock = ssl.wrap_socket(conn, self.key_file, self.cert_file)
class VerifiedHTTPSConnection(HTTPSConnection):
"""
Based on httplib.HTTPSConnection but wraps the socket with
SSL certification.
"""
cert_reqs = None
ca_certs = None
ssl_version = None
assert_fingerprint = None
def set_cert(self, key_file=None, cert_file=None,
cert_reqs=None, ca_certs=None,
assert_hostname=None, assert_fingerprint=None):
self.key_file = key_file
self.cert_file = cert_file
self.cert_reqs = cert_reqs
self.ca_certs = ca_certs
self.assert_hostname = assert_hostname
self.assert_fingerprint = assert_fingerprint
def connect(self):
# Add certificate verification
conn = self._new_conn()
resolved_cert_reqs = resolve_cert_reqs(self.cert_reqs)
resolved_ssl_version = resolve_ssl_version(self.ssl_version)
hostname = self.host
if getattr(self, '_tunnel_host', None):
# _tunnel_host was added in Python 2.6.3
# (See: http://hg.python.org/cpython/rev/0f57b30a152f)
self.sock = conn
# Calls self._set_hostport(), so self.host is
# self._tunnel_host below.
self._tunnel()
# Mark this connection as not reusable
self.auto_open = 0
# Override the host with the one we're requesting data from.
hostname = self._tunnel_host
is_time_off = datetime.date.today() < RECENT_DATE
if is_time_off:
warnings.warn((
'System time is way off (before {0}). This will probably '
'lead to SSL verification errors').format(RECENT_DATE),
SystemTimeWarning
)
# Wrap socket using verification with the root certs in
# trusted_root_certs
self.sock = ssl_wrap_socket(conn, self.key_file, self.cert_file,
cert_reqs=resolved_cert_reqs,
ca_certs=self.ca_certs,
server_hostname=hostname,
ssl_version=resolved_ssl_version)
if self.assert_fingerprint:
assert_fingerprint(self.sock.getpeercert(binary_form=True),
self.assert_fingerprint)
elif resolved_cert_reqs != ssl.CERT_NONE \
and self.assert_hostname is not False:
cert = self.sock.getpeercert()
if not cert.get('subjectAltName', ()):
warnings.warn((
'Certificate has no `subjectAltName`, falling back to check for a `commonName` for now. '
'This feature is being removed by major browsers and deprecated by RFC 2818. '
'(See https://github.com/shazow/urllib3/issues/497 for details.)'),
SecurityWarning
)
match_hostname(cert, self.assert_hostname or hostname)
self.is_verified = (resolved_cert_reqs == ssl.CERT_REQUIRED
or self.assert_fingerprint is not None)
if ssl:
# Make a copy for testing.
UnverifiedHTTPSConnection = HTTPSConnection
HTTPSConnection = VerifiedHTTPSConnection
else:
HTTPSConnection = DummyConnection
|
mit
|
[
646,
2197,
199,
646,
984,
199,
646,
2838,
199,
504,
2838,
492,
2653,
465,
17766,
6372,
199,
646,
3598,
199,
504,
1275,
5154,
492,
3816,
199,
199,
893,
26,
221,
327,
2018,
650,
272,
687,
1455,
14,
1258,
492,
3101,
3225,
465,
485,
19114,
12,
28185,
199,
2590,
3545,
26,
272,
687,
8809,
492,
3101,
3225,
465,
485,
19114,
12,
28185,
421,
199,
533,
9762,
3225,
8,
785,
304,
272,
298,
9167,
370,
9696,
282,
3405,
8113,
24342,
492,
2122,
272,
986,
421,
199,
893,
26,
221,
327,
3599,
1672,
543,
7799,
31,
272,
14147,
3225,
275,
9762,
3225,
272,
492,
6149,
272,
3523,
27102,
275,
6149,
14,
27102,
199,
2590,
334,
17825,
12,
4281,
304,
221,
327,
16078,
13,
6100,
26,
3091,
7799,
14,
272,
6149,
275,
488,
339,
1021,
3523,
27102,
8,
29900,
304,
267,
986,
421,
199,
893,
26,
221,
327,
2018,
650,
26,
272,
327,
2832,
282,
949,
13,
411,
12,
781,
3984,
7791,
642,
370,
314,
3231,
880,
652,
883,
506,
8439,
14,
272,
25417,
275,
25417,
199,
2590,
12746,
26,
221,
327,
2018,
499,
26,
272,
1021,
25417,
8,
1726,
304,
267,
986,
421,
199,
504,
1275,
3924,
492,
334,
272,
15175,
19382,
12,
272,
6187,
1366,
3849,
12,
272,
13863,
3849,
12,
199,
9,
199,
504,
1275,
5154,
14,
4266,
63,
1431,
63,
4269,
492,
1336,
63,
4269,
199,
199,
504,
1275,
1974,
14,
4266,
63,
492,
334,
272,
7512,
63,
4736,
63,
12720,
12,
272,
7512,
63,
4266,
63,
1023,
12,
272,
6149,
63,
3823,
63,
3450,
12,
272,
702,
63,
15077,
12,
199,
9,
421,
199,
504,
1275,
1974,
492,
1950,
199,
199,
719,
63,
991,
63,
5512,
275,
469,
272,
283,
1014,
356,
5939,
12,
272,
283,
2859,
356,
23865,
12,
199,
93,
199,
199,
9481,
1309,
63,
5390,
275,
2197,
14,
602,
8,
7280,
12,
413,
12,
413,
9,
421,
199,
533,
3101,
3225,
1547,
19114,
12,
909,
304,
272,
408,
272,
21311,
641,
8809,
14,
19114,
1325,
6571,
376,
2402,
3787,
272,
8552,
13,
15390,
4045,
3382,
12731,
436,
15666,
2018,
83,
14,
339,
10961,
4252,
2633,
787,
1202,
370,
7908,
3004,
402,
314,
1950,
14,
272,
4473,
7203,
2633,
2387,
26,
2541,
446,
1124,
4768,
18983,
1666,
314,
3794,
641,
520,
533,
1705,
4078,
19,
14,
2105,
2293,
14,
19114,
5453,
64,
489,
446,
1124,
1365,
63,
1562,
18983,
2494,
314,
1350,
2287,
367,
314,
1453,
1950,
14,
398,
2508,
5317,
447,
961,
365,
5525,
367,
2018,
499,
14,
22,
14,
2779,
365,
1454,
6781,
367,
499,
14,
23,
436,
650,
14,
88,
2541,
446,
1124,
3450,
63,
1419,
18983,
2494,
2488,
1511,
641,
314,
8793,
2838,
14,
982,
440,
2013,
12,
2066,
267,
4243,
787,
6511,
687,
1124,
19114,
14,
885,
63,
3450,
63,
1419,
1040,
1314,
6952,
30723,
267,
653,
643,
274,
1159,
5563,
334,
2193,
13488,
63,
2826,
18616,
370,
413,
9,
7444,
314,
1950,
365,
22172,
282,
4566,
14,
398,
2104,
2893,
12,
340,
1265,
13809,
370,
4756,
13488,
14797,
437,
6442,
315,
10234,
370,
314,
4243,
12,
267,
1265,
5594,
986,
447,
953,
3101,
3225,
14,
885,
63,
3450,
63,
1419,
435,
359,
355,
334,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
32162,
748,
5399,
12,
413,
395,
288,
1622,
398,
4236,
1265,
1443,
2934,
370,
3507,
314,
4243,
701,
9476,
376,
2701,
769,
334,
69,
14,
71,
2020,
1124,
8607,
20008,
272,
408,
339,
849,
63,
719,
275,
1844,
63,
991,
63,
5512,
459,
1014,
418,
339,
6079,
17534,
653,
643,
274,
1159,
5563,
701,
849,
14,
272,
6079,
1124,
7528,
3450,
14,
20130,
63,
9735,
12,
2838,
14,
9735,
63,
2826,
18616,
12,
413,
1874,
1040,
272,
849,
63,
3450,
63,
1419,
275,
3842,
3450,
14,
20130,
63,
9735,
12,
2838,
14,
9735,
63,
2826,
18616,
12,
413,
1874,
339,
6079,
7480,
642,
1950,
22694,
314,
1591,
1159,
5897,
14,
272,
365,
63,
12949,
275,
756,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
340,
3816,
14,
4521,
19,
26,
221,
327,
2018,
650,
288,
4775,
14,
1935,
360,
4768,
297,
488,
9,
398,
327,
5543,
13,
409,
1350,
63,
1562,
315,
1930,
781,
1172,
376,
12731,
2018,
2839,
499,
14,
22,
14,
267,
291,
14,
1365,
63,
1562,
275,
4775,
14,
362,
360,
1365,
63,
1562,
358,
398,
340,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
221,
327,
2018,
499,
14,
22,
288,
327,
485,
19114,
641,
2018,
499,
14,
22,
911,
330,
4878,
737,
642,
4252,
1680,
12,
1325,
288,
327,
440,
15666,
5459,
14,
2136,
883,
5139,
675,
652,
1380,
6425,
282,
288,
327,
1950,
10617,
12,
880,
781,
4560,
652,
627,
4399,
10,
781,
1172,
6290,
652,
465,
288,
327,
291,
14,
1365,
63,
1562,
14,
288,
4775,
14,
1935,
360,
1365,
63,
1562,
297,
488,
9,
398,
6079,
710,
2838,
1511,
2741,
701,
314,
922,
14,
982,
949,
1511,
787,
267,
6079,
2741,
12,
781,
675,
314,
849,
1511,
14,
267,
291,
14,
3450,
63,
1419,
275,
4775,
14,
1935,
360,
3450,
63,
1419,
297,
291,
14,
885,
63,
3450,
63,
1419,
9,
398,
327,
17897,
533,
2597,
5951,
291,
14,
1365,
63,
1562,
315,
2018,
499,
14,
23,
26240,
267,
485,
19114,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
408,
15896,
13306,
282,
2838,
1950,
436,
663,
1031,
817,
2202,
641,
652,
14,
398,
520,
1107,
26,
7053,
2838,
1950,
14,
267,
408,
267,
2402,
63,
829,
275,
1052,
267,
340,
291,
14,
1365,
63,
1562,
26,
288,
2402,
63,
829,
459,
1365,
63,
1562,
418,
275,
291,
14,
1365,
63,
1562,
398,
340,
291,
14,
3450,
63,
1419,
26,
288,
2402,
63,
829,
459,
3450,
63,
1419,
418,
275,
291,
14,
3450,
63,
1419,
398,
862,
26,
288,
2557,
275,
1950,
14,
981,
63,
2105,
8,
355,
334,
277,
14,
1102,
12,
291,
14,
719,
395,
291,
14,
2593,
12,
1011,
2911,
63,
829,
9,
398,
871,
17766,
6372,
26,
288,
746,
15175,
19382,
8,
355,
291,
12,
298,
3225,
370,
450,
83,
18590,
734,
14,
334,
2242,
2653,
2458
] |
[
2197,
199,
646,
984,
199,
646,
2838,
199,
504,
2838,
492,
2653,
465,
17766,
6372,
199,
646,
3598,
199,
504,
1275,
5154,
492,
3816,
199,
199,
893,
26,
221,
327,
2018,
650,
272,
687,
1455,
14,
1258,
492,
3101,
3225,
465,
485,
19114,
12,
28185,
199,
2590,
3545,
26,
272,
687,
8809,
492,
3101,
3225,
465,
485,
19114,
12,
28185,
421,
199,
533,
9762,
3225,
8,
785,
304,
272,
298,
9167,
370,
9696,
282,
3405,
8113,
24342,
492,
2122,
272,
986,
421,
199,
893,
26,
221,
327,
3599,
1672,
543,
7799,
31,
272,
14147,
3225,
275,
9762,
3225,
272,
492,
6149,
272,
3523,
27102,
275,
6149,
14,
27102,
199,
2590,
334,
17825,
12,
4281,
304,
221,
327,
16078,
13,
6100,
26,
3091,
7799,
14,
272,
6149,
275,
488,
339,
1021,
3523,
27102,
8,
29900,
304,
267,
986,
421,
199,
893,
26,
221,
327,
2018,
650,
26,
272,
327,
2832,
282,
949,
13,
411,
12,
781,
3984,
7791,
642,
370,
314,
3231,
880,
652,
883,
506,
8439,
14,
272,
25417,
275,
25417,
199,
2590,
12746,
26,
221,
327,
2018,
499,
26,
272,
1021,
25417,
8,
1726,
304,
267,
986,
421,
199,
504,
1275,
3924,
492,
334,
272,
15175,
19382,
12,
272,
6187,
1366,
3849,
12,
272,
13863,
3849,
12,
199,
9,
199,
504,
1275,
5154,
14,
4266,
63,
1431,
63,
4269,
492,
1336,
63,
4269,
199,
199,
504,
1275,
1974,
14,
4266,
63,
492,
334,
272,
7512,
63,
4736,
63,
12720,
12,
272,
7512,
63,
4266,
63,
1023,
12,
272,
6149,
63,
3823,
63,
3450,
12,
272,
702,
63,
15077,
12,
199,
9,
421,
199,
504,
1275,
1974,
492,
1950,
199,
199,
719,
63,
991,
63,
5512,
275,
469,
272,
283,
1014,
356,
5939,
12,
272,
283,
2859,
356,
23865,
12,
199,
93,
199,
199,
9481,
1309,
63,
5390,
275,
2197,
14,
602,
8,
7280,
12,
413,
12,
413,
9,
421,
199,
533,
3101,
3225,
1547,
19114,
12,
909,
304,
272,
408,
272,
21311,
641,
8809,
14,
19114,
1325,
6571,
376,
2402,
3787,
272,
8552,
13,
15390,
4045,
3382,
12731,
436,
15666,
2018,
83,
14,
339,
10961,
4252,
2633,
787,
1202,
370,
7908,
3004,
402,
314,
1950,
14,
272,
4473,
7203,
2633,
2387,
26,
2541,
446,
1124,
4768,
18983,
1666,
314,
3794,
641,
520,
533,
1705,
4078,
19,
14,
2105,
2293,
14,
19114,
5453,
64,
489,
446,
1124,
1365,
63,
1562,
18983,
2494,
314,
1350,
2287,
367,
314,
1453,
1950,
14,
398,
2508,
5317,
447,
961,
365,
5525,
367,
2018,
499,
14,
22,
14,
2779,
365,
1454,
6781,
367,
499,
14,
23,
436,
650,
14,
88,
2541,
446,
1124,
3450,
63,
1419,
18983,
2494,
2488,
1511,
641,
314,
8793,
2838,
14,
982,
440,
2013,
12,
2066,
267,
4243,
787,
6511,
687,
1124,
19114,
14,
885,
63,
3450,
63,
1419,
1040,
1314,
6952,
30723,
267,
653,
643,
274,
1159,
5563,
334,
2193,
13488,
63,
2826,
18616,
370,
413,
9,
7444,
314,
1950,
365,
22172,
282,
4566,
14,
398,
2104,
2893,
12,
340,
1265,
13809,
370,
4756,
13488,
14797,
437,
6442,
315,
10234,
370,
314,
4243,
12,
267,
1265,
5594,
986,
447,
953,
3101,
3225,
14,
885,
63,
3450,
63,
1419,
435,
359,
355,
334,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
32162,
748,
5399,
12,
413,
395,
288,
1622,
398,
4236,
1265,
1443,
2934,
370,
3507,
314,
4243,
701,
9476,
376,
2701,
769,
334,
69,
14,
71,
2020,
1124,
8607,
20008,
272,
408,
339,
849,
63,
719,
275,
1844,
63,
991,
63,
5512,
459,
1014,
418,
339,
6079,
17534,
653,
643,
274,
1159,
5563,
701,
849,
14,
272,
6079,
1124,
7528,
3450,
14,
20130,
63,
9735,
12,
2838,
14,
9735,
63,
2826,
18616,
12,
413,
1874,
1040,
272,
849,
63,
3450,
63,
1419,
275,
3842,
3450,
14,
20130,
63,
9735,
12,
2838,
14,
9735,
63,
2826,
18616,
12,
413,
1874,
339,
6079,
7480,
642,
1950,
22694,
314,
1591,
1159,
5897,
14,
272,
365,
63,
12949,
275,
756,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
340,
3816,
14,
4521,
19,
26,
221,
327,
2018,
650,
288,
4775,
14,
1935,
360,
4768,
297,
488,
9,
398,
327,
5543,
13,
409,
1350,
63,
1562,
315,
1930,
781,
1172,
376,
12731,
2018,
2839,
499,
14,
22,
14,
267,
291,
14,
1365,
63,
1562,
275,
4775,
14,
362,
360,
1365,
63,
1562,
358,
398,
340,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
221,
327,
2018,
499,
14,
22,
288,
327,
485,
19114,
641,
2018,
499,
14,
22,
911,
330,
4878,
737,
642,
4252,
1680,
12,
1325,
288,
327,
440,
15666,
5459,
14,
2136,
883,
5139,
675,
652,
1380,
6425,
282,
288,
327,
1950,
10617,
12,
880,
781,
4560,
652,
627,
4399,
10,
781,
1172,
6290,
652,
465,
288,
327,
291,
14,
1365,
63,
1562,
14,
288,
4775,
14,
1935,
360,
1365,
63,
1562,
297,
488,
9,
398,
6079,
710,
2838,
1511,
2741,
701,
314,
922,
14,
982,
949,
1511,
787,
267,
6079,
2741,
12,
781,
675,
314,
849,
1511,
14,
267,
291,
14,
3450,
63,
1419,
275,
4775,
14,
1935,
360,
3450,
63,
1419,
297,
291,
14,
885,
63,
3450,
63,
1419,
9,
398,
327,
17897,
533,
2597,
5951,
291,
14,
1365,
63,
1562,
315,
2018,
499,
14,
23,
26240,
267,
485,
19114,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
408,
15896,
13306,
282,
2838,
1950,
436,
663,
1031,
817,
2202,
641,
652,
14,
398,
520,
1107,
26,
7053,
2838,
1950,
14,
267,
408,
267,
2402,
63,
829,
275,
1052,
267,
340,
291,
14,
1365,
63,
1562,
26,
288,
2402,
63,
829,
459,
1365,
63,
1562,
418,
275,
291,
14,
1365,
63,
1562,
398,
340,
291,
14,
3450,
63,
1419,
26,
288,
2402,
63,
829,
459,
3450,
63,
1419,
418,
275,
291,
14,
3450,
63,
1419,
398,
862,
26,
288,
2557,
275,
1950,
14,
981,
63,
2105,
8,
355,
334,
277,
14,
1102,
12,
291,
14,
719,
395,
291,
14,
2593,
12,
1011,
2911,
63,
829,
9,
398,
871,
17766,
6372,
26,
288,
746,
15175,
19382,
8,
355,
291,
12,
298,
3225,
370,
450,
83,
18590,
734,
14,
334,
2242,
2653,
2458,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dstockwell/catapult
|
tracing/third_party/tvcm/third_party/rjsmin/_setup/py2/util.py
|
37
|
2011
|
# -*- coding: ascii -*-
#
# Copyright 2007, 2008, 2009, 2010, 2011
# Andr\xe9 Malo or his licensors, as applicable
#
# 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.
"""
=================
Setup utilities
=================
Setup utilities.
"""
__author__ = u"Andr\xe9 Malo"
__docformat__ = "restructuredtext en"
try:
from distutils import log
except ImportError:
class log(object):
def info(self, value):
print value
def debug(self, value):
pass
log = log()
from distutils import util as _util
try:
from ConfigParser import SafeConfigParser
except ImportError:
import ConfigParser as _config_parser
class SafeConfigParser(_config_parser.ConfigParser):
""" Safe config parser """
def _interpolate(self, section, option, rawval, vars):
return rawval
def items(self, section):
return [(key, self.get(section, key))
for key in self.options(section)
]
def humanbool(name, value):
"""
Determine human boolean value
:Parameters:
`name` : ``str``
The config key (used for error message)
`value` : ``str``
The config value
:Return: The boolean value
:Rtype: ``bool``
:Exceptions:
- `ValueError` : The value could not be recognized
"""
try:
return _util.strtobool(str(value).strip().lower() or 'no')
except ValueError:
raise ValueError("Unrecognized config value: %s = %s" % (name, value))
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
13294,
1882,
199,
3,
199,
3,
1898,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
199,
3,
6061,
82,
60,
1845,
25,
603,
12201,
503,
17049,
23854,
17564,
12,
465,
3964,
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,
624,
199,
1280,
29,
199,
12439,
15841,
199,
1280,
29,
199,
199,
8555,
15841,
14,
199,
624,
199,
363,
2502,
363,
275,
399,
2,
3325,
82,
60,
1845,
25,
603,
12201,
2,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
893,
26,
272,
687,
7065,
492,
943,
199,
2590,
3545,
26,
272,
1021,
943,
8,
785,
304,
267,
347,
2256,
8,
277,
12,
574,
304,
288,
870,
574,
267,
347,
3105,
8,
277,
12,
574,
304,
288,
986,
272,
943,
275,
943,
342,
199,
199,
504,
7065,
492,
4884,
465,
485,
1974,
199,
893,
26,
272,
687,
14196,
492,
14969,
15218,
199,
2590,
3545,
26,
272,
492,
14196,
465,
485,
888,
63,
2087,
272,
1021,
14969,
15218,
1547,
888,
63,
2087,
14,
15218,
304,
267,
408,
14969,
1101,
1798,
408,
267,
347,
485,
21294,
8,
277,
12,
3420,
12,
945,
12,
3066,
637,
12,
6802,
304,
288,
372,
3066,
637,
398,
347,
2974,
8,
277,
12,
3420,
304,
288,
372,
3842,
498,
12,
291,
14,
362,
8,
2792,
12,
790,
430,
355,
367,
790,
315,
291,
14,
1419,
8,
2792,
9,
288,
1622,
421,
199,
318,
11779,
2245,
8,
354,
12,
574,
304,
272,
408,
272,
14703,
11779,
5046,
574,
339,
520,
5976,
26,
489,
658,
354,
64,
520,
1124,
495,
1040,
267,
710,
1101,
790,
334,
2972,
367,
1125,
1245,
9,
2541,
658,
585,
64,
520,
1124,
495,
1040,
267,
710,
1101,
574,
339,
520,
1767,
26,
710,
5046,
574,
272,
520,
50,
466,
26,
1124,
2245,
1040,
339,
520,
16836,
26,
489,
446,
658,
3393,
64,
520,
710,
574,
4293,
440,
506,
18054,
272,
408,
272,
862,
26,
267,
372,
485,
1974,
14,
495,
475,
2245,
8,
495,
8,
585,
680,
1913,
1252,
2325,
342,
503,
283,
889,
358,
272,
871,
1722,
26,
267,
746,
1722,
480,
22517,
1101,
574,
26,
450,
83,
275,
450,
83,
2,
450,
334,
354,
12,
574,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
13294,
1882,
199,
3,
199,
3,
1898,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
199,
3,
6061,
82,
60,
1845,
25,
603,
12201,
503,
17049,
23854,
17564,
12,
465,
3964,
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,
624,
199,
1280,
29,
199,
12439,
15841,
199,
1280,
29,
199,
199,
8555,
15841,
14,
199,
624,
199,
363,
2502,
363,
275,
399,
2,
3325,
82,
60,
1845,
25,
603,
12201,
2,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
893,
26,
272,
687,
7065,
492,
943,
199,
2590,
3545,
26,
272,
1021,
943,
8,
785,
304,
267,
347,
2256,
8,
277,
12,
574,
304,
288,
870,
574,
267,
347,
3105,
8,
277,
12,
574,
304,
288,
986,
272,
943,
275,
943,
342,
199,
199,
504,
7065,
492,
4884,
465,
485,
1974,
199,
893,
26,
272,
687,
14196,
492,
14969,
15218,
199,
2590,
3545,
26,
272,
492,
14196,
465,
485,
888,
63,
2087,
272,
1021,
14969,
15218,
1547,
888,
63,
2087,
14,
15218,
304,
267,
408,
14969,
1101,
1798,
408,
267,
347,
485,
21294,
8,
277,
12,
3420,
12,
945,
12,
3066,
637,
12,
6802,
304,
288,
372,
3066,
637,
398,
347,
2974,
8,
277,
12,
3420,
304,
288,
372,
3842,
498,
12,
291,
14,
362,
8,
2792,
12,
790,
430,
355,
367,
790,
315,
291,
14,
1419,
8,
2792,
9,
288,
1622,
421,
199,
318,
11779,
2245,
8,
354,
12,
574,
304,
272,
408,
272,
14703,
11779,
5046,
574,
339,
520,
5976,
26,
489,
658,
354,
64,
520,
1124,
495,
1040,
267,
710,
1101,
790,
334,
2972,
367,
1125,
1245,
9,
2541,
658,
585,
64,
520,
1124,
495,
1040,
267,
710,
1101,
574,
339,
520,
1767,
26,
710,
5046,
574,
272,
520,
50,
466,
26,
1124,
2245,
1040,
339,
520,
16836,
26,
489,
446,
658,
3393,
64,
520,
710,
574,
4293,
440,
506,
18054,
272,
408,
272,
862,
26,
267,
372,
485,
1974,
14,
495,
475,
2245,
8,
495,
8,
585,
680,
1913,
1252,
2325,
342,
503,
283,
889,
358,
272,
871,
1722,
26,
267,
746,
1722,
480,
22517,
1101,
574,
26,
450,
83,
275,
450,
83,
2,
450,
334,
354,
12,
574,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ARNING: I haven't thought much about the best way of doing
# this. it may get lots of extra caches, or take a long
# time if your path goes thru a city.
# there's probably a better algorithm.
# in meters.
maxdist = 2500.0
# get geocaches, circles of "radius", then go ahead advance_dist in the track and do it again.
#radius = maxdist * 2 * 0.707106 # sqrt(2)
radius = maxdist * 2
advance_dist = maxdist * 2
# TODO: shell escape in case mkdtemp has unsafe chars in (unlikely)
class Coord:
def __init__(self, lat=0.0, lon=0.0):
self.lat = lat
self.lon = lon
# diff between two coords in meters.
def diff(c1,c2):
from math import acos, sin, cos
PIOVER180 = 3.14159265358979 / 180.0
EquatorialRadius = 6378137 # WGS-84
lat1 = c1.lat * PIOVER180
lon1 = c1.lon * PIOVER180
lat2 = c2.lat * PIOVER180
lon2 = c2.lon * PIOVER180
return EquatorialRadius * acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));
def load_track ( file ):
import re
latlonre = re.compile("lat=['\"]([0-9\\-\\.]*?)['\"].*lon=['\"]([0-9\\-\\.]*?)['\"]")
track = []
for line in file:
match = latlonre.search(line)
if match:
lat = float(match.group(1))
lon = float(match.group(2))
track.append ( Coord(lat,lon) )
return track
# position inside of a track = index of trackpoint + meters past this trackpoint
class TPos:
def __init__(self, track):
self.track = track
self.n_tps = len(self.track)
self.i_lasttp = 0 # index of tp before current position
self.dist_past = 0 # meters past this tp
self.coord = Coord()
if self.n_tps > 0:
self.coord.lat = track[0].lat
self.coord.lon = track[0].lon
if self.n_tps > 1:
self.finished = False
else:
self.finished = True # no tps in track, nothing to do
def recalculate_coord(self):
if self.i_lasttp >= self.n_tps - 1:
self.coord = self.track[self.n_tps - 1] # return last tp
return
c1 = self.track[self.i_lasttp]
c2 = self.track[self.i_lasttp+1]
# APPROXIMATE
percentage_past = self.dist_past / Coord.diff ( c1, c2 )
self.coord.lat = c1.lat + percentage_past * (c2.lat - c1.lat)
self.coord.lon = c1.lon + percentage_past * (c2.lon - c1.lon)
def advance(self, distance):
if self.i_lasttp >= (self.n_tps - 1):
self.finished = True
if self.finished:
return
# possibility one: we don't pass a TP
dist_to_next_tp = Coord.diff ( self.track[self.i_lasttp], self.track[self.i_lasttp+1] ) - self.dist_past
if dist_to_next_tp > distance:
self.dist_past += distance
self.recalculate_coord()
else:
# goto beginning of next tp and try again.
self.i_lasttp += 1
self.dist_past = 0
if self.i_lasttp >= (self.n_tps - 1):
self.recalculate_coord()
else:
self.advance ( distance - dist_to_next_tp )
# dist_after_pos = dist_after_i
# if self.track[i_lasttp
# TODO!
def end(self):
return self.finished
def get_geocaches_for(coord,radius,tmpdir,i):
import os, sys
MAXGCS = 100
radiusinmiles = radius * 100 / 2.54 / 12 / 5280 # meters to miles
gcgetstr = "gcget %f,%f %d %f > %s/%d.loc" % (coord.lat, coord.lon, MAXGCS, radius, tmpdir, i)
sys.stderr.write("%s\n" % gcgetstr)
os.system(gcgetstr)
#print "type=\"trackpoint\" latitude=\"%f\" longitude=\"%f\"" % (coord.lat, coord.lon)
#------------
import sys, os
tr = load_track ( sys.stdin )
tpos = TPos(tr)
import tempfile
tmpdir = tempfile.mkdtemp()
i = 0
while not tpos.end():
get_geocaches_for ( tpos.coord, radius, tmpdir, i )
tpos.advance ( advance_dist )
i += 1
get_geocaches_for ( tpos.coord, radius, tmpdir, i )
####### condense all #######
gb_input_args = ["-i geo -f %s/%d.loc" % (tmpdir,j) for j in range(i)]
gb_string = "gpsbabel %s -x duplicate,location -o gpx -F -" % (" ".join(gb_input_args))
sys.stderr.write("\n%s\n" % gb_string)
os.system(gb_string)
####### delete temp files #######
for j in range(i):
os.sys.remove("%s/%d.loc" % (tmpdir,j))
os.sys.rmdir(tmpdir)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
14750,
26,
473,
19051,
1133,
32463,
8298,
3595,
314,
5526,
4340,
402,
9689,
199,
3,
198,
257,
642,
14,
652,
1443,
664,
24213,
402,
2402,
18014,
12,
503,
5452,
282,
1846,
199,
3,
198,
257,
900,
340,
2195,
931,
13538,
294,
6558,
282,
14492,
14,
199,
3,
2337,
1159,
8646,
282,
8034,
5563,
14,
199,
199,
3,
315,
24808,
14,
199,
988,
2686,
275,
5661,
383,
14,
16,
199,
199,
3,
664,
2312,
679,
1225,
397,
12,
17990,
83,
402,
298,
8017,
401,
2066,
2621,
23417,
18695,
63,
2686,
315,
314,
4426,
436,
886,
652,
4020,
14,
199,
3,
8017,
275,
1390,
2686,
627,
499,
627,
378,
14,
15378,
7357,
327,
7452,
8,
18,
9,
199,
8017,
275,
1390,
2686,
627,
499,
199,
21195,
63,
2686,
275,
1390,
2686,
627,
499,
421,
199,
3,
3254,
26,
5218,
4772,
315,
1930,
31781,
965,
19293,
8365,
315,
334,
324,
24227,
9,
199,
199,
533,
1849,
2181,
26,
523,
347,
636,
826,
721,
277,
12,
8396,
29,
16,
14,
16,
12,
6132,
29,
16,
14,
16,
304,
272,
291,
14,
4452,
275,
8396,
272,
291,
14,
5298,
275,
6132,
819,
327,
3915,
3382,
2877,
13259,
315,
24808,
14,
523,
347,
3915,
8,
67,
17,
12,
67,
18,
304,
272,
687,
3473,
492,
282,
5197,
12,
9829,
12,
9794,
272,
510,
2090,
2111,
7663,
275,
650,
14,
1079,
9327,
1479,
7920,
1407,
1965,
1182,
13576,
14,
16,
272,
662,
392,
707,
2380,
19800,
275,
1227,
12046,
7498,
327,
644,
8021,
13,
1349,
272,
8396,
17,
275,
286,
17,
14,
4452,
627,
510,
2090,
2111,
7663,
272,
6132,
17,
275,
286,
17,
14,
5298,
627,
510,
2090,
2111,
7663,
272,
8396,
18,
275,
286,
18,
14,
4452,
627,
510,
2090,
2111,
7663,
272,
6132,
18,
275,
286,
18,
14,
5298,
627,
510,
2090,
2111,
7663,
272,
372,
662,
392,
707,
2380,
19800,
627,
282,
5197,
8,
5911,
8,
4452,
17,
3342,
5911,
8,
4452,
18,
6393,
5197,
8,
4452,
17,
3342,
5197,
8,
4452,
18,
3342,
5197,
8,
5298,
17,
13,
5298,
18,
16674,
199,
199,
318,
2248,
63,
3885,
334,
570,
3461,
523,
492,
295,
523,
8396,
5298,
264,
275,
295,
14,
2014,
480,
4452,
2968,
60,
937,
779,
16,
13,
25,
1103,
13,
20942,
3672,
31,
11820,
60,
937,
2795,
5298,
2968,
60,
937,
779,
16,
13,
25,
1103,
13,
20942,
3672,
31,
11820,
60,
937,
531,
523,
4426,
275,
942,
523,
367,
1004,
315,
570,
26,
272,
1336,
275,
8396,
5298,
264,
14,
1733,
8,
604,
9,
272,
340,
1336,
26,
489,
8396,
275,
2069,
8,
1431,
14,
923,
8,
17,
430,
489,
6132,
275,
2069,
8,
1431,
14,
923,
8,
18,
430,
489,
4426,
14,
740,
334,
1849,
2181,
8,
4452,
12,
5298,
9,
776,
523,
372,
4426,
199,
199,
3,
3421,
6272,
402,
282,
4426,
275,
1478,
402,
4426,
1403,
435,
24808,
13541,
642,
4426,
1403,
199,
533,
377,
6981,
26,
523,
347,
636,
826,
721,
277,
12,
4426,
304,
272,
291,
14,
3885,
275,
4426,
272,
291,
14,
78,
63,
30543,
275,
822,
8,
277,
14,
3885,
9,
272,
291,
14,
73,
63,
2019,
683,
275,
378,
327,
1478,
402,
9253,
2544,
1453,
3421,
272,
291,
14,
2686,
63,
18597,
275,
378,
327,
24808,
13541,
642,
9253,
339,
291,
14,
7988,
275,
1849,
2181,
342,
339,
340,
291,
14,
78,
63,
30543,
690,
378,
26,
489,
291,
14,
7988,
14,
4452,
275,
4426,
59,
16,
1055,
4452,
489,
291,
14,
7988,
14,
5298,
275,
4426,
59,
16,
1055,
5298,
339,
340,
291,
14,
78,
63,
30543,
690,
413,
26,
489,
291,
14,
8669,
275,
756,
272,
587,
26,
489,
291,
14,
8669,
275,
715,
327,
949,
307,
1190,
315,
4426,
12,
6548,
370,
886,
819,
347,
295,
12063,
63,
7988,
8,
277,
304,
272,
340,
291,
14,
73,
63,
2019,
683,
2356,
291,
14,
78,
63,
30543,
446,
413,
26,
489,
291,
14,
7988,
275,
291,
14,
3885,
59,
277,
14,
78,
63,
30543,
446,
413,
61,
327,
372,
2061,
9253,
489,
372,
339,
286,
17,
275,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
61,
272,
286,
18,
275,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
11,
17,
61,
339,
327,
10319,
2514,
56,
1469,
1951,
272,
16327,
63,
18597,
275,
291,
14,
2686,
63,
18597,
1182,
1849,
2181,
14,
3028,
334,
286,
17,
12,
286,
18,
776,
272,
291,
14,
7988,
14,
4452,
275,
286,
17,
14,
4452,
435,
16327,
63,
18597,
627,
334,
67,
18,
14,
4452,
446,
286,
17,
14,
4452,
9,
272,
291,
14,
7988,
14,
5298,
275,
286,
17,
14,
5298,
435,
16327,
63,
18597,
627,
334,
67,
18,
14,
5298,
446,
286,
17,
14,
5298,
9,
819,
347,
18695,
8,
277,
12,
6033,
304,
272,
340,
291,
14,
73,
63,
2019,
683,
2356,
334,
277,
14,
78,
63,
30543,
446,
413,
304,
489,
291,
14,
8669,
275,
715,
272,
340,
291,
14,
8669,
26,
489,
372,
339,
327,
31077,
1373,
26,
781,
2793,
1133,
986,
282,
24328,
272,
2917,
63,
475,
63,
2184,
63,
683,
275,
1849,
2181,
14,
3028,
334,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
467,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
11,
17,
61,
776,
446,
291,
14,
2686,
63,
18597,
272,
340,
2917,
63,
475,
63,
2184,
63,
683,
690,
6033,
26,
489,
291,
14,
2686,
63,
18597,
847,
6033,
489,
291,
14,
264,
12063,
63,
7988,
342,
272,
587,
26,
489,
327,
18878,
9608,
402,
2163,
9253,
436,
862,
4020,
14,
489,
291,
14,
73,
63,
2019,
683,
847,
413,
489,
291,
14,
2686,
63,
18597,
275,
378,
2541,
340,
291,
14,
73,
63,
2019,
683,
2356,
334,
277,
14,
78,
63,
30543,
446,
413,
304,
267,
291,
14,
264,
12063,
63,
7988,
342,
489,
587,
26,
267,
291,
14,
21195,
334,
6033,
446,
2917,
63,
475,
63,
2184,
63,
683,
776,
199,
199,
3,
259,
2917,
63,
4399,
63,
1712,
275,
2917,
63,
4399,
63,
73,
199,
3,
259,
340,
291,
14,
3885,
59,
73,
63,
2019,
683,
199,
3,
3254,
1,
819,
347,
1284,
8,
277
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
14750,
26,
473,
19051,
1133,
32463,
8298,
3595,
314,
5526,
4340,
402,
9689,
199,
3,
198,
257,
642,
14,
652,
1443,
664,
24213,
402,
2402,
18014,
12,
503,
5452,
282,
1846,
199,
3,
198,
257,
900,
340,
2195,
931,
13538,
294,
6558,
282,
14492,
14,
199,
3,
2337,
1159,
8646,
282,
8034,
5563,
14,
199,
199,
3,
315,
24808,
14,
199,
988,
2686,
275,
5661,
383,
14,
16,
199,
199,
3,
664,
2312,
679,
1225,
397,
12,
17990,
83,
402,
298,
8017,
401,
2066,
2621,
23417,
18695,
63,
2686,
315,
314,
4426,
436,
886,
652,
4020,
14,
199,
3,
8017,
275,
1390,
2686,
627,
499,
627,
378,
14,
15378,
7357,
327,
7452,
8,
18,
9,
199,
8017,
275,
1390,
2686,
627,
499,
199,
21195,
63,
2686,
275,
1390,
2686,
627,
499,
421,
199,
3,
3254,
26,
5218,
4772,
315,
1930,
31781,
965,
19293,
8365,
315,
334,
324,
24227,
9,
199,
199,
533,
1849,
2181,
26,
523,
347,
636,
826,
721,
277,
12,
8396,
29,
16,
14,
16,
12,
6132,
29,
16,
14,
16,
304,
272,
291,
14,
4452,
275,
8396,
272,
291,
14,
5298,
275,
6132,
819,
327,
3915,
3382,
2877,
13259,
315,
24808,
14,
523,
347,
3915,
8,
67,
17,
12,
67,
18,
304,
272,
687,
3473,
492,
282,
5197,
12,
9829,
12,
9794,
272,
510,
2090,
2111,
7663,
275,
650,
14,
1079,
9327,
1479,
7920,
1407,
1965,
1182,
13576,
14,
16,
272,
662,
392,
707,
2380,
19800,
275,
1227,
12046,
7498,
327,
644,
8021,
13,
1349,
272,
8396,
17,
275,
286,
17,
14,
4452,
627,
510,
2090,
2111,
7663,
272,
6132,
17,
275,
286,
17,
14,
5298,
627,
510,
2090,
2111,
7663,
272,
8396,
18,
275,
286,
18,
14,
4452,
627,
510,
2090,
2111,
7663,
272,
6132,
18,
275,
286,
18,
14,
5298,
627,
510,
2090,
2111,
7663,
272,
372,
662,
392,
707,
2380,
19800,
627,
282,
5197,
8,
5911,
8,
4452,
17,
3342,
5911,
8,
4452,
18,
6393,
5197,
8,
4452,
17,
3342,
5197,
8,
4452,
18,
3342,
5197,
8,
5298,
17,
13,
5298,
18,
16674,
199,
199,
318,
2248,
63,
3885,
334,
570,
3461,
523,
492,
295,
523,
8396,
5298,
264,
275,
295,
14,
2014,
480,
4452,
2968,
60,
937,
779,
16,
13,
25,
1103,
13,
20942,
3672,
31,
11820,
60,
937,
2795,
5298,
2968,
60,
937,
779,
16,
13,
25,
1103,
13,
20942,
3672,
31,
11820,
60,
937,
531,
523,
4426,
275,
942,
523,
367,
1004,
315,
570,
26,
272,
1336,
275,
8396,
5298,
264,
14,
1733,
8,
604,
9,
272,
340,
1336,
26,
489,
8396,
275,
2069,
8,
1431,
14,
923,
8,
17,
430,
489,
6132,
275,
2069,
8,
1431,
14,
923,
8,
18,
430,
489,
4426,
14,
740,
334,
1849,
2181,
8,
4452,
12,
5298,
9,
776,
523,
372,
4426,
199,
199,
3,
3421,
6272,
402,
282,
4426,
275,
1478,
402,
4426,
1403,
435,
24808,
13541,
642,
4426,
1403,
199,
533,
377,
6981,
26,
523,
347,
636,
826,
721,
277,
12,
4426,
304,
272,
291,
14,
3885,
275,
4426,
272,
291,
14,
78,
63,
30543,
275,
822,
8,
277,
14,
3885,
9,
272,
291,
14,
73,
63,
2019,
683,
275,
378,
327,
1478,
402,
9253,
2544,
1453,
3421,
272,
291,
14,
2686,
63,
18597,
275,
378,
327,
24808,
13541,
642,
9253,
339,
291,
14,
7988,
275,
1849,
2181,
342,
339,
340,
291,
14,
78,
63,
30543,
690,
378,
26,
489,
291,
14,
7988,
14,
4452,
275,
4426,
59,
16,
1055,
4452,
489,
291,
14,
7988,
14,
5298,
275,
4426,
59,
16,
1055,
5298,
339,
340,
291,
14,
78,
63,
30543,
690,
413,
26,
489,
291,
14,
8669,
275,
756,
272,
587,
26,
489,
291,
14,
8669,
275,
715,
327,
949,
307,
1190,
315,
4426,
12,
6548,
370,
886,
819,
347,
295,
12063,
63,
7988,
8,
277,
304,
272,
340,
291,
14,
73,
63,
2019,
683,
2356,
291,
14,
78,
63,
30543,
446,
413,
26,
489,
291,
14,
7988,
275,
291,
14,
3885,
59,
277,
14,
78,
63,
30543,
446,
413,
61,
327,
372,
2061,
9253,
489,
372,
339,
286,
17,
275,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
61,
272,
286,
18,
275,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
11,
17,
61,
339,
327,
10319,
2514,
56,
1469,
1951,
272,
16327,
63,
18597,
275,
291,
14,
2686,
63,
18597,
1182,
1849,
2181,
14,
3028,
334,
286,
17,
12,
286,
18,
776,
272,
291,
14,
7988,
14,
4452,
275,
286,
17,
14,
4452,
435,
16327,
63,
18597,
627,
334,
67,
18,
14,
4452,
446,
286,
17,
14,
4452,
9,
272,
291,
14,
7988,
14,
5298,
275,
286,
17,
14,
5298,
435,
16327,
63,
18597,
627,
334,
67,
18,
14,
5298,
446,
286,
17,
14,
5298,
9,
819,
347,
18695,
8,
277,
12,
6033,
304,
272,
340,
291,
14,
73,
63,
2019,
683,
2356,
334,
277,
14,
78,
63,
30543,
446,
413,
304,
489,
291,
14,
8669,
275,
715,
272,
340,
291,
14,
8669,
26,
489,
372,
339,
327,
31077,
1373,
26,
781,
2793,
1133,
986,
282,
24328,
272,
2917,
63,
475,
63,
2184,
63,
683,
275,
1849,
2181,
14,
3028,
334,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
467,
291,
14,
3885,
59,
277,
14,
73,
63,
2019,
683,
11,
17,
61,
776,
446,
291,
14,
2686,
63,
18597,
272,
340,
2917,
63,
475,
63,
2184,
63,
683,
690,
6033,
26,
489,
291,
14,
2686,
63,
18597,
847,
6033,
489,
291,
14,
264,
12063,
63,
7988,
342,
272,
587,
26,
489,
327,
18878,
9608,
402,
2163,
9253,
436,
862,
4020,
14,
489,
291,
14,
73,
63,
2019,
683,
847,
413,
489,
291,
14,
2686,
63,
18597,
275,
378,
2541,
340,
291,
14,
73,
63,
2019,
683,
2356,
334,
277,
14,
78,
63,
30543,
446,
413,
304,
267,
291,
14,
264,
12063,
63,
7988,
342,
489,
587,
26,
267,
291,
14,
21195,
334,
6033,
446,
2917,
63,
475,
63,
2184,
63,
683,
776,
199,
199,
3,
259,
2917,
63,
4399,
63,
1712,
275,
2917,
63,
4399,
63,
73,
199,
3,
259,
340,
291,
14,
3885,
59,
73,
63,
2019,
683,
199,
3,
3254,
1,
819,
347,
1284,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sesh/djver
|
djver/djver.py
|
1
|
6137
|
#!/usr/bin/env python
"""
djver.
Usage:
djver.py [<url>] [--static-path=<static-path>] [--find-diffs] [--verbose]
Options:
--static-path=<static-path> URL path to the site's static files [default: /static/].
--find-diffs Attempt to find differences between the known versions of Django
--verbose Turn on verbose logging
"""
import os
import sys
import subprocess
import shutil
import difflib
import requests
from docopt import docopt
try:
from urlparse import urljoin
except ImportError:
from urllib.parse import urljoin
try:
from packaging.version import parse
except:
def parse(version):
return None
RESPONSE_CACHE = {}
THIRD_PARTY_CSS = [
# Third party apps, might disguise version numbers
('django-flat-theme, or Django 1.9', 'fonts.css', 'Roboto'),
('django-suit', 'forms.css', 'Django Suit'),
]
ADMIN_CHANGES = [
('2.1.2-2.1', 'css/base.css', 'background: url(../img/icon-viewlink.svg) 0 1px no-repeat;'),
('2.0.9-2.0', 'css/base.css', 'textarea:focus, select:focus, .vTextField:focus {'),
('1.11.16-1.11', 'css/base.css', 'background-position: right 7px center;'),
('1.10.8-1.10', 'css/base.css', 'color: #000;'),
('1.9.13-1.9', 'css/widgets.css', 'margin-left: 7px;'),
('1.8.19-1.8.2', 'css/forms.css', 'clear: left;'),
('1.8.1', 'css/widgets.css', '.related-widget-wrapper {'),
('1.8', 'css/widgets.css', 'opacity: 1;'),
('1.7.11-1.7', 'css/base.css', '#branding a:hover {'),
('1.6.11-1.6', 'css/widgets.css', 'width: 360px;'),
('1.5.12-1.5', 'css/widgets.css', '.url a {'),
('1.4.22-1.4.1', 'css/widgets.css', '.inline-group .aligned .selector .selector-filter label {'),
]
def check_str(url, search_str, verbose=False):
if url in RESPONSE_CACHE.keys():
content = RESPONSE_CACHE[url]
status_code = 200
else:
response = requests.get(url)
content = response.content.decode().replace(' ', '')
status_code = response.status_code
if verbose:
print('[{}] {}'.format(status_code, url))
if status_code == 200:
RESPONSE_CACHE[url] = content
return search_str.replace(' ', '') in content
def check_version(base_url, static_path, verbose=False):
if not base_url.startswith('http'):
base_url = 'http://{}'.format(base_url)
for version, path, string in ADMIN_CHANGES:
url = '{}{}admin/{}'.format(base_url, static_path, path)
if check_str(url, string, verbose):
return version
def find_diffs():
response = requests.get('https://pypi.org/pypi/Django/json')
versions = [parse(v) for v in response.json()['releases'].keys()]
versions = sorted(versions, reverse=True)
print(versions)
versions = [str(v) for v in versions if v.is_prerelease == False and v > parse("1.3.99")]
# we only care about 1.4 and above
# favour files _not_ found in django-flat-theme
files = [
# admin js
# "js/SelectBox.js",
# "js/actions.js",
# "js/actions.min.js",
# "js/calendar.js",
# "js/collapse.js",
# "js/collapse.min.js",
# "js/core.js",
# "js/inlines.js",
# "js/inlines.min.js",
# "js/jquery.init.js",
# "js/prepopulate.js",
# "js/prepopulate.min.js",
# "js/timeparse.js",
# "js/urlify.js",
# admin css
'css/widgets.css', 'css/base.css', 'css/forms.css', 'css/login.css', 'css/dashboard.css',
# 'css/ie.css', # removed in 1.9.x
]
for v in versions:
os.makedirs('files/{}/css/'.format(v), exist_ok=True)
os.makedirs('files/{}/js/'.format(v), exist_ok=True)
for fn in files:
full_path = 'files/{}/{}'.format(v, fn)
if not os.path.exists(full_path):
repo = 'https://raw.githubusercontent.com/django/django/'
url = '{}{}/django/contrib/admin/static/admin/{}'.format(repo, v, fn)
if v.startswith('1.3'):
url = '{}{}/django/contrib/admin/media/{}'.format(repo, v, fn)
response = requests.get(url)
print('[{}] {}'.format(response.status_code, url))
with open(full_path, 'wb') as f:
f.write(response.content)
matched_versions = []
for i, v1 in enumerate(versions[:-1]):
matched_versions.append(v1)
v2 = versions[i + 1]
new_line = None
for f in files:
f1 = open('files/{}/{}'.format(v1, f)).read()
f2 = open('files/{}/{}'.format(v2, f)).read()
# compare f2 to f1 so that we see _added_ lines
diff = difflib.ndiff(f2.splitlines(), f1.splitlines())
for line in diff:
if line.startswith('+ ') and '/*' not in line:
line = line[2:]
# ensure this line is unique within the file
if f1.count(line) == 1:
# we also want to make sure that it doesn't appear in any _older_ versions
for v in versions[i + 1:]:
f3 = open('files/{}/{}'.format(v, f)).read()
if line in f3:
break
new_line = line
if new_line:
if len(matched_versions) > 1:
print("('{}', '{}', '{}'),".format('-'.join([matched_versions[0], matched_versions[-1]]), f, new_line.strip()))
else:
print("('{}', '{}', '{}'),".format(matched_versions[0], f, new_line.strip()))
matched_versions = []
break
def djver():
arguments = docopt(__doc__, version='djver 2.0.0')
if arguments['--find-diffs']:
find_diffs()
elif arguments['<url>']:
version = check_version(arguments['<url>'], arguments['--static-path'], arguments['--verbose'])
if version:
print(version)
else:
print('Unable to detect version.')
if __name__ == '__main__':
djver()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
18256,
422,
14,
199,
199,
7692,
26,
272,
366,
74,
422,
14,
647,
24936,
633,
19109,
19344,
1986,
13,
515,
18987,
1986,
13,
515,
19109,
19344,
1623,
13,
17418,
61,
19344,
3832,
61,
199,
199,
4558,
26,
272,
1553,
1986,
13,
515,
18987,
1986,
13,
515,
30,
221,
2851,
931,
370,
314,
4770,
1159,
2955,
1584,
359,
885,
26,
1182,
1986,
15,
1055,
272,
1553,
1623,
13,
17418,
463,
23115,
370,
2342,
15109,
3382,
314,
6040,
5459,
402,
5634,
272,
1553,
3832,
8540,
16147,
641,
3376,
2050,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
5145,
199,
199,
646,
27070,
199,
646,
4145,
199,
199,
504,
886,
32626,
492,
886,
32626,
199,
199,
893,
26,
272,
687,
7097,
492,
20818,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
20818,
199,
199,
893,
26,
272,
687,
27369,
14,
1023,
492,
2198,
199,
2590,
26,
272,
347,
2198,
8,
1023,
304,
267,
372,
488,
421,
199,
12801,
63,
8677,
275,
1052,
199,
199,
2080,
3927,
36,
63,
4014,
2099,
63,
14391,
275,
359,
272,
327,
31079,
17135,
8686,
12,
5594,
487,
1226,
85,
572,
1015,
5579,
272,
661,
1176,
13,
7088,
13,
7915,
12,
503,
5634,
413,
14,
25,
297,
283,
19864,
14,
3919,
297,
283,
50,
2873,
3459,
659,
272,
661,
1176,
13,
83,
4993,
297,
283,
3351,
14,
3919,
297,
283,
9323,
428,
4993,
659,
199,
61,
199,
199,
14288,
63,
17858,
654,
275,
359,
272,
661,
18,
14,
17,
14,
18,
13,
18,
14,
17,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
7451,
26,
1166,
8,
5093,
4060,
15,
4677,
13,
1345,
1073,
14,
10273,
9,
378,
413,
5326,
949,
13,
8755,
27,
659,
272,
661,
18,
14,
16,
14,
25,
13,
18,
14,
16,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
20895,
26,
12283,
12,
3504,
26,
12283,
12,
1275,
86,
6254,
26,
12283,
469,
659,
272,
661,
17,
14,
845,
14,
975,
13,
17,
14,
845,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
7451,
13,
3124,
26,
2451,
1520,
5326,
8126,
27,
659,
272,
661,
17,
14,
709,
14,
24,
13,
17,
14,
709,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
2326,
26,
327,
1493,
27,
659,
272,
661,
17,
14,
25,
14,
969,
13,
17,
14,
25,
297,
283,
3919,
15,
8583,
14,
3919,
297,
283,
9650,
13,
3039,
26,
1520,
5326,
27,
659,
272,
661,
17,
14,
24,
14,
1167,
13,
17,
14,
24,
14,
18,
297,
283,
3919,
15,
3351,
14,
3919,
297,
283,
3584,
26,
3602,
27,
659,
272,
661,
17,
14,
24,
14,
17,
297,
283,
3919,
15,
8583,
14,
3919,
297,
1987,
2407,
13,
3440,
13,
5029,
469,
659,
272,
661,
17,
14,
24,
297,
283,
3919,
15,
8583,
14,
3919,
297,
283,
21861,
26,
413,
27,
659,
272,
661,
17,
14,
23,
14,
845,
13,
17,
14,
23,
297,
283,
3919,
15,
1095,
14,
3919,
297,
3943,
19026,
316,
282,
26,
22797,
469,
659,
272,
661,
17,
14,
22,
14,
845,
13,
17,
14,
22,
297,
283,
3919,
15,
8583,
14,
3919,
297,
283,
2063,
26,
19434,
5326,
27,
659,
272,
661,
17,
14,
21,
14,
713,
13,
17,
14,
21,
297,
283,
3919,
15,
8583,
14,
3919,
297,
1987,
633,
282,
469,
659,
272,
661,
17,
14,
20,
14,
1081,
13,
17,
14,
20,
14,
17,
297,
283,
3919,
15,
8583,
14,
3919,
297,
1987,
6460,
13,
923,
1275,
19175,
1275,
6662,
1275,
6662,
13,
1541,
1768,
469,
659,
199,
61,
421,
199,
318,
1104,
63,
495,
8,
633,
12,
2754,
63,
495,
12,
3376,
29,
797,
304,
272,
340,
1166,
315,
820,
7613,
11827,
63,
8677,
14,
1612,
837,
267,
1564,
275,
820,
7613,
11827,
63,
8677,
59,
633,
61,
267,
2004,
63,
600,
275,
1926,
272,
587,
26,
267,
1177,
275,
4145,
14,
362,
8,
633,
9,
267,
1564,
275,
1177,
14,
1317,
14,
2708,
1252,
1814,
360,
1656,
4074,
267,
2004,
63,
600,
275,
1177,
14,
1205,
63,
600,
339,
340,
3376,
26,
267,
870,
11894,
27922,
9499,
908,
8,
1205,
63,
600,
12,
1166,
430,
339,
340,
2004,
63,
600,
508,
1926,
26,
267,
820,
7613,
11827,
63,
8677,
59,
633,
61,
275,
1564,
267,
372,
2754,
63,
495,
14,
1814,
360,
1656,
4074,
315,
1564,
421,
199,
318,
1104,
63,
1023,
8,
1095,
63,
633,
12,
2955,
63,
515,
12,
3376,
29,
797,
304,
272,
340,
440,
1300,
63,
633,
14,
2460,
360,
1014,
735,
267,
1300,
63,
633,
275,
283,
1014,
921,
11123,
908,
8,
1095,
63,
633,
9,
339,
367,
1015,
12,
931,
12,
1059,
315,
29948,
63,
17858,
654,
26,
267,
1166,
275,
9005,
2440,
2113,
30837,
908,
8,
1095,
63,
633,
12,
2955,
63,
515,
12,
931,
9,
267,
340,
1104,
63,
495,
8,
633,
12,
1059,
12,
3376,
304,
288,
372,
1015,
421,
199,
318,
2342,
63,
17418,
837,
272,
1177,
275,
4145,
14,
362,
360,
2859,
921,
17343,
14,
1308,
15,
17343,
15,
9323,
15,
1001,
358,
272,
5459,
275,
359,
1122,
8,
86,
9,
367,
373,
315,
1177,
14,
1001,
12047,
11840,
2278,
1612,
5106,
272,
5459,
275,
3355,
8,
6234,
12,
3837,
29,
549,
9,
339,
870,
8,
6234,
9,
272,
5459,
275,
359,
495,
8,
86,
9,
367,
373,
315,
5459,
340,
373,
14,
374,
63,
657,
3221,
508,
756,
436,
373,
690,
2198,
480,
17,
14,
19,
14,
1020,
11323,
339,
327,
781,
1454,
10296,
3595,
413,
14,
20,
436,
3432,
339,
327,
289,
1214,
567,
1584,
485,
1397,
63,
1911,
315,
1639,
13,
7088,
13,
7915,
272,
1584,
275,
359,
267,
327,
4628,
8586,
267,
327,
298,
3596,
15,
5446,
3532,
14,
3596,
401,
267,
327,
298,
3596,
15,
3723,
14,
3596,
401,
267,
327,
298,
3596,
15,
3723,
14,
827,
14,
3596,
401,
267,
327,
298,
3596,
15,
8183,
14,
3596,
401,
267,
327,
298,
3596,
15,
20681,
14,
3596,
401,
267,
327,
298,
3596,
15,
20681,
14,
827,
14,
3596,
401,
267,
327,
298,
3596,
15,
1018,
14,
3596,
401,
267,
327,
298,
3596,
15,
26739,
14,
3596
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
18256,
422,
14,
199,
199,
7692,
26,
272,
366,
74,
422,
14,
647,
24936,
633,
19109,
19344,
1986,
13,
515,
18987,
1986,
13,
515,
19109,
19344,
1623,
13,
17418,
61,
19344,
3832,
61,
199,
199,
4558,
26,
272,
1553,
1986,
13,
515,
18987,
1986,
13,
515,
30,
221,
2851,
931,
370,
314,
4770,
1159,
2955,
1584,
359,
885,
26,
1182,
1986,
15,
1055,
272,
1553,
1623,
13,
17418,
463,
23115,
370,
2342,
15109,
3382,
314,
6040,
5459,
402,
5634,
272,
1553,
3832,
8540,
16147,
641,
3376,
2050,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
5145,
199,
199,
646,
27070,
199,
646,
4145,
199,
199,
504,
886,
32626,
492,
886,
32626,
199,
199,
893,
26,
272,
687,
7097,
492,
20818,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
20818,
199,
199,
893,
26,
272,
687,
27369,
14,
1023,
492,
2198,
199,
2590,
26,
272,
347,
2198,
8,
1023,
304,
267,
372,
488,
421,
199,
12801,
63,
8677,
275,
1052,
199,
199,
2080,
3927,
36,
63,
4014,
2099,
63,
14391,
275,
359,
272,
327,
31079,
17135,
8686,
12,
5594,
487,
1226,
85,
572,
1015,
5579,
272,
661,
1176,
13,
7088,
13,
7915,
12,
503,
5634,
413,
14,
25,
297,
283,
19864,
14,
3919,
297,
283,
50,
2873,
3459,
659,
272,
661,
1176,
13,
83,
4993,
297,
283,
3351,
14,
3919,
297,
283,
9323,
428,
4993,
659,
199,
61,
199,
199,
14288,
63,
17858,
654,
275,
359,
272,
661,
18,
14,
17,
14,
18,
13,
18,
14,
17,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
7451,
26,
1166,
8,
5093,
4060,
15,
4677,
13,
1345,
1073,
14,
10273,
9,
378,
413,
5326,
949,
13,
8755,
27,
659,
272,
661,
18,
14,
16,
14,
25,
13,
18,
14,
16,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
20895,
26,
12283,
12,
3504,
26,
12283,
12,
1275,
86,
6254,
26,
12283,
469,
659,
272,
661,
17,
14,
845,
14,
975,
13,
17,
14,
845,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
7451,
13,
3124,
26,
2451,
1520,
5326,
8126,
27,
659,
272,
661,
17,
14,
709,
14,
24,
13,
17,
14,
709,
297,
283,
3919,
15,
1095,
14,
3919,
297,
283,
2326,
26,
327,
1493,
27,
659,
272,
661,
17,
14,
25,
14,
969,
13,
17,
14,
25,
297,
283,
3919,
15,
8583,
14,
3919,
297,
283,
9650,
13,
3039,
26,
1520,
5326,
27,
659,
272,
661,
17,
14,
24,
14,
1167,
13,
17,
14,
24,
14,
18,
297,
283,
3919,
15,
3351,
14,
3919,
297,
283,
3584,
26,
3602,
27,
659,
272,
661,
17,
14,
24,
14,
17,
297,
283,
3919,
15,
8583,
14,
3919,
297,
1987,
2407,
13,
3440,
13,
5029,
469,
659,
272,
661,
17,
14,
24,
297,
283,
3919,
15,
8583,
14,
3919,
297,
283,
21861,
26,
413,
27,
659,
272,
661,
17,
14,
23,
14,
845,
13,
17,
14,
23,
297,
283,
3919,
15,
1095,
14,
3919,
297,
3943,
19026,
316,
282,
26,
22797,
469,
659,
272,
661,
17,
14,
22,
14,
845,
13,
17,
14,
22,
297,
283,
3919,
15,
8583,
14,
3919,
297,
283,
2063,
26,
19434,
5326,
27,
659,
272,
661,
17,
14,
21,
14,
713,
13,
17,
14,
21,
297,
283,
3919,
15,
8583,
14,
3919,
297,
1987,
633,
282,
469,
659,
272,
661,
17,
14,
20,
14,
1081,
13,
17,
14,
20,
14,
17,
297,
283,
3919,
15,
8583,
14,
3919,
297,
1987,
6460,
13,
923,
1275,
19175,
1275,
6662,
1275,
6662,
13,
1541,
1768,
469,
659,
199,
61,
421,
199,
318,
1104,
63,
495,
8,
633,
12,
2754,
63,
495,
12,
3376,
29,
797,
304,
272,
340,
1166,
315,
820,
7613,
11827,
63,
8677,
14,
1612,
837,
267,
1564,
275,
820,
7613,
11827,
63,
8677,
59,
633,
61,
267,
2004,
63,
600,
275,
1926,
272,
587,
26,
267,
1177,
275,
4145,
14,
362,
8,
633,
9,
267,
1564,
275,
1177,
14,
1317,
14,
2708,
1252,
1814,
360,
1656,
4074,
267,
2004,
63,
600,
275,
1177,
14,
1205,
63,
600,
339,
340,
3376,
26,
267,
870,
11894,
27922,
9499,
908,
8,
1205,
63,
600,
12,
1166,
430,
339,
340,
2004,
63,
600,
508,
1926,
26,
267,
820,
7613,
11827,
63,
8677,
59,
633,
61,
275,
1564,
267,
372,
2754,
63,
495,
14,
1814,
360,
1656,
4074,
315,
1564,
421,
199,
318,
1104,
63,
1023,
8,
1095,
63,
633,
12,
2955,
63,
515,
12,
3376,
29,
797,
304,
272,
340,
440,
1300,
63,
633,
14,
2460,
360,
1014,
735,
267,
1300,
63,
633,
275,
283,
1014,
921,
11123,
908,
8,
1095,
63,
633,
9,
339,
367,
1015,
12,
931,
12,
1059,
315,
29948,
63,
17858,
654,
26,
267,
1166,
275,
9005,
2440,
2113,
30837,
908,
8,
1095,
63,
633,
12,
2955,
63,
515,
12,
931,
9,
267,
340,
1104,
63,
495,
8,
633,
12,
1059,
12,
3376,
304,
288,
372,
1015,
421,
199,
318,
2342,
63,
17418,
837,
272,
1177,
275,
4145,
14,
362,
360,
2859,
921,
17343,
14,
1308,
15,
17343,
15,
9323,
15,
1001,
358,
272,
5459,
275,
359,
1122,
8,
86,
9,
367,
373,
315,
1177,
14,
1001,
12047,
11840,
2278,
1612,
5106,
272,
5459,
275,
3355,
8,
6234,
12,
3837,
29,
549,
9,
339,
870,
8,
6234,
9,
272,
5459,
275,
359,
495,
8,
86,
9,
367,
373,
315,
5459,
340,
373,
14,
374,
63,
657,
3221,
508,
756,
436,
373,
690,
2198,
480,
17,
14,
19,
14,
1020,
11323,
339,
327,
781,
1454,
10296,
3595,
413,
14,
20,
436,
3432,
339,
327,
289,
1214,
567,
1584,
485,
1397,
63,
1911,
315,
1639,
13,
7088,
13,
7915,
272,
1584,
275,
359,
267,
327,
4628,
8586,
267,
327,
298,
3596,
15,
5446,
3532,
14,
3596,
401,
267,
327,
298,
3596,
15,
3723,
14,
3596,
401,
267,
327,
298,
3596,
15,
3723,
14,
827,
14,
3596,
401,
267,
327,
298,
3596,
15,
8183,
14,
3596,
401,
267,
327,
298,
3596,
15,
20681,
14,
3596,
401,
267,
327,
298,
3596,
15,
20681,
14,
827,
14,
3596,
401,
267,
327,
298,
3596,
15,
1018,
14,
3596,
401,
267,
327,
298,
3596,
15,
26739,
14,
3596,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wdv4758h/ZipPy
|
lib-python/3/test/test_kqueue.py
|
59
|
7048
|
"""
Tests for kqueue wrapper.
"""
import errno
import os
import select
import socket
import sys
import time
import unittest
from test import support
if not hasattr(select, "kqueue"):
raise unittest.SkipTest("test works only on BSD")
class TestKQueue(unittest.TestCase):
def test_create_queue(self):
kq = select.kqueue()
self.assertTrue(kq.fileno() > 0, kq.fileno())
self.assertTrue(not kq.closed)
kq.close()
self.assertTrue(kq.closed)
self.assertRaises(ValueError, kq.fileno)
def test_create_event(self):
from operator import lt, le, gt, ge
fd = os.open(os.devnull, os.O_WRONLY)
self.addCleanup(os.close, fd)
ev = select.kevent(fd)
other = select.kevent(1000)
self.assertEqual(ev.ident, fd)
self.assertEqual(ev.filter, select.KQ_FILTER_READ)
self.assertEqual(ev.flags, select.KQ_EV_ADD)
self.assertEqual(ev.fflags, 0)
self.assertEqual(ev.data, 0)
self.assertEqual(ev.udata, 0)
self.assertEqual(ev, ev)
self.assertNotEqual(ev, other)
self.assertTrue(ev < other)
self.assertTrue(other >= ev)
for op in lt, le, gt, ge:
self.assertRaises(TypeError, op, ev, None)
self.assertRaises(TypeError, op, ev, 1)
self.assertRaises(TypeError, op, ev, "ev")
ev = select.kevent(fd, select.KQ_FILTER_WRITE)
self.assertEqual(ev.ident, fd)
self.assertEqual(ev.filter, select.KQ_FILTER_WRITE)
self.assertEqual(ev.flags, select.KQ_EV_ADD)
self.assertEqual(ev.fflags, 0)
self.assertEqual(ev.data, 0)
self.assertEqual(ev.udata, 0)
self.assertEqual(ev, ev)
self.assertNotEqual(ev, other)
ev = select.kevent(fd, select.KQ_FILTER_WRITE, select.KQ_EV_ONESHOT)
self.assertEqual(ev.ident, fd)
self.assertEqual(ev.filter, select.KQ_FILTER_WRITE)
self.assertEqual(ev.flags, select.KQ_EV_ONESHOT)
self.assertEqual(ev.fflags, 0)
self.assertEqual(ev.data, 0)
self.assertEqual(ev.udata, 0)
self.assertEqual(ev, ev)
self.assertNotEqual(ev, other)
ev = select.kevent(1, 2, 3, 4, 5, 6)
self.assertEqual(ev.ident, 1)
self.assertEqual(ev.filter, 2)
self.assertEqual(ev.flags, 3)
self.assertEqual(ev.fflags, 4)
self.assertEqual(ev.data, 5)
self.assertEqual(ev.udata, 6)
self.assertEqual(ev, ev)
self.assertNotEqual(ev, other)
bignum = sys.maxsize * 2 + 1
ev = select.kevent(bignum, 1, 2, 3, sys.maxsize, bignum)
self.assertEqual(ev.ident, bignum)
self.assertEqual(ev.filter, 1)
self.assertEqual(ev.flags, 2)
self.assertEqual(ev.fflags, 3)
self.assertEqual(ev.data, sys.maxsize)
self.assertEqual(ev.udata, bignum)
self.assertEqual(ev, ev)
self.assertNotEqual(ev, other)
def test_queue_event(self):
serverSocket = socket.socket()
serverSocket.bind(('127.0.0.1', 0))
serverSocket.listen(1)
client = socket.socket()
client.setblocking(False)
try:
client.connect(('127.0.0.1', serverSocket.getsockname()[1]))
except socket.error as e:
self.assertEqual(e.args[0], errno.EINPROGRESS)
else:
#raise AssertionError("Connect should have raised EINPROGRESS")
pass # FreeBSD doesn't raise an exception here
server, addr = serverSocket.accept()
if sys.platform.startswith("darwin"):
flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE
else:
flags = 0
kq = select.kqueue()
kq2 = select.kqueue.fromfd(kq.fileno())
ev = select.kevent(server.fileno(),
select.KQ_FILTER_WRITE,
select.KQ_EV_ADD | select.KQ_EV_ENABLE)
kq.control([ev], 0)
ev = select.kevent(server.fileno(),
select.KQ_FILTER_READ,
select.KQ_EV_ADD | select.KQ_EV_ENABLE)
kq.control([ev], 0)
ev = select.kevent(client.fileno(),
select.KQ_FILTER_WRITE,
select.KQ_EV_ADD | select.KQ_EV_ENABLE)
kq2.control([ev], 0)
ev = select.kevent(client.fileno(),
select.KQ_FILTER_READ,
select.KQ_EV_ADD | select.KQ_EV_ENABLE)
kq2.control([ev], 0)
events = kq.control(None, 4, 1)
events = [(e.ident, e.filter, e.flags) for e in events]
events.sort()
self.assertEqual(events, [
(client.fileno(), select.KQ_FILTER_WRITE, flags),
(server.fileno(), select.KQ_FILTER_WRITE, flags)])
client.send(b"Hello!")
server.send(b"world!!!")
# We may need to call it several times
for i in range(10):
events = kq.control(None, 4, 1)
if len(events) == 4:
break
time.sleep(1.0)
else:
self.fail('timeout waiting for event notifications')
events = [(e.ident, e.filter, e.flags) for e in events]
events.sort()
self.assertEqual(events, [
(client.fileno(), select.KQ_FILTER_WRITE, flags),
(client.fileno(), select.KQ_FILTER_READ, flags),
(server.fileno(), select.KQ_FILTER_WRITE, flags),
(server.fileno(), select.KQ_FILTER_READ, flags)])
# Remove completely client, and server read part
ev = select.kevent(client.fileno(),
select.KQ_FILTER_WRITE,
select.KQ_EV_DELETE)
kq.control([ev], 0)
ev = select.kevent(client.fileno(),
select.KQ_FILTER_READ,
select.KQ_EV_DELETE)
kq.control([ev], 0)
ev = select.kevent(server.fileno(),
select.KQ_FILTER_READ,
select.KQ_EV_DELETE)
kq.control([ev], 0, 0)
events = kq.control([], 4, 0.99)
events = [(e.ident, e.filter, e.flags) for e in events]
events.sort()
self.assertEqual(events, [
(server.fileno(), select.KQ_FILTER_WRITE, flags)])
client.close()
server.close()
serverSocket.close()
def testPair(self):
kq = select.kqueue()
a, b = socket.socketpair()
a.send(b'foo')
event1 = select.kevent(a, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
event2 = select.kevent(b, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
r = kq.control([event1, event2], 1, 1)
self.assertTrue(r)
self.assertFalse(r[0].flags & select.KQ_EV_ERROR)
self.assertEqual(b.recv(r[0].data), b'foo')
a.close()
b.close()
kq.close()
def test_main():
support.run_unittest(TestKQueue)
if __name__ == "__main__":
test_main()
|
bsd-3-clause
|
[
624,
199,
2925,
367,
1022,
1825,
4975,
14,
199,
624,
199,
646,
7554,
199,
646,
747,
199,
646,
3504,
199,
646,
2838,
199,
646,
984,
199,
646,
900,
199,
646,
2882,
199,
199,
504,
511,
492,
2291,
199,
692,
440,
2688,
8,
2416,
12,
298,
75,
1825,
2349,
272,
746,
2882,
14,
25755,
480,
396,
5419,
1454,
641,
6289,
531,
199,
199,
533,
1379,
43,
3737,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
981,
63,
1825,
8,
277,
304,
267,
1022,
81,
275,
3504,
14,
75,
1825,
342,
267,
291,
14,
1815,
8,
75,
81,
14,
9843,
342,
690,
378,
12,
1022,
81,
14,
9843,
1012,
267,
291,
14,
1815,
8,
1397,
1022,
81,
14,
5938,
9,
267,
1022,
81,
14,
1600,
342,
267,
291,
14,
1815,
8,
75,
81,
14,
5938,
9,
267,
291,
14,
1855,
8,
3393,
12,
1022,
81,
14,
9843,
9,
339,
347,
511,
63,
981,
63,
1430,
8,
277,
304,
267,
687,
4182,
492,
22146,
12,
1026,
12,
16484,
12,
2312,
398,
6111,
275,
747,
14,
1490,
8,
736,
14,
19778,
12,
747,
14,
47,
63,
6524,
10452,
9,
267,
291,
14,
12808,
8,
736,
14,
1600,
12,
6111,
9,
398,
8145,
275,
3504,
14,
415,
782,
8,
2592,
9,
267,
1163,
275,
3504,
14,
415,
782,
8,
5279,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
6111,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
3504,
14,
24817,
63,
9905,
63,
5670,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
3504,
14,
24817,
63,
18015,
63,
9732,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
267,
291,
14,
1815,
8,
6857,
665,
1163,
9,
267,
291,
14,
1815,
8,
1848,
2356,
8145,
9,
267,
367,
1687,
315,
22146,
12,
1026,
12,
16484,
12,
2312,
26,
288,
291,
14,
1855,
8,
4333,
12,
1687,
12,
8145,
12,
488,
9,
288,
291,
14,
1855,
8,
4333,
12,
1687,
12,
8145,
12,
413,
9,
288,
291,
14,
1855,
8,
4333,
12,
1687,
12,
8145,
12,
298,
6857,
531,
398,
8145,
275,
3504,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
6111,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
3504,
14,
24817,
63,
18015,
63,
9732,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
398,
8145,
275,
3504,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
12,
3504,
14,
24817,
63,
18015,
63,
615,
654,
40,
1387,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
6111,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
3504,
14,
24817,
63,
18015,
63,
615,
654,
40,
1387,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
398,
8145,
275,
3504,
14,
415,
782,
8,
17,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
413,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
499,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
650,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
841,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
959,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
1227,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
398,
330,
1030,
453,
275,
984,
14,
13634,
627,
499,
435,
413,
267,
8145,
275,
3504,
14,
415,
782,
8,
66,
1030,
453,
12,
413,
12,
499,
12,
650,
12,
984,
14,
13634,
12,
330,
1030,
453,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
330,
1030,
453,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
413,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
499,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
650,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
984,
14,
13634,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
330,
1030,
453,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
339,
347,
511,
63,
1825,
63,
1430,
8,
277,
304,
267,
1654,
3869,
275,
2838,
14,
3450,
342,
267,
1654,
3869,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
378,
430,
267,
1654,
3869,
14,
5859,
8,
17,
9,
267,
1890,
275,
2838,
14,
3450,
342,
267,
1890,
14,
409,
13091,
8,
797,
9,
267,
862,
26,
288,
1890,
14,
2242,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1654,
3869,
14,
27886,
3430,
17,
2459,
267,
871,
2838,
14,
705,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
589,
59,
16,
467,
7554,
14,
25652,
24547,
9,
267,
587,
26,
288,
327,
3730,
9070,
480,
8631,
1077,
1172,
4915,
662,
568,
24547,
531,
288,
986,
327,
2868,
15400,
3181,
1133,
746,
376,
1919,
2348,
267,
1654,
12,
5552,
275,
1654,
3869,
14,
5694,
342,
398,
340,
984,
14,
3246,
14,
2460,
480,
13245,
2349,
288,
3285,
275,
3504,
14,
24817
] |
[
199,
2925,
367,
1022,
1825,
4975,
14,
199,
624,
199,
646,
7554,
199,
646,
747,
199,
646,
3504,
199,
646,
2838,
199,
646,
984,
199,
646,
900,
199,
646,
2882,
199,
199,
504,
511,
492,
2291,
199,
692,
440,
2688,
8,
2416,
12,
298,
75,
1825,
2349,
272,
746,
2882,
14,
25755,
480,
396,
5419,
1454,
641,
6289,
531,
199,
199,
533,
1379,
43,
3737,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
981,
63,
1825,
8,
277,
304,
267,
1022,
81,
275,
3504,
14,
75,
1825,
342,
267,
291,
14,
1815,
8,
75,
81,
14,
9843,
342,
690,
378,
12,
1022,
81,
14,
9843,
1012,
267,
291,
14,
1815,
8,
1397,
1022,
81,
14,
5938,
9,
267,
1022,
81,
14,
1600,
342,
267,
291,
14,
1815,
8,
75,
81,
14,
5938,
9,
267,
291,
14,
1855,
8,
3393,
12,
1022,
81,
14,
9843,
9,
339,
347,
511,
63,
981,
63,
1430,
8,
277,
304,
267,
687,
4182,
492,
22146,
12,
1026,
12,
16484,
12,
2312,
398,
6111,
275,
747,
14,
1490,
8,
736,
14,
19778,
12,
747,
14,
47,
63,
6524,
10452,
9,
267,
291,
14,
12808,
8,
736,
14,
1600,
12,
6111,
9,
398,
8145,
275,
3504,
14,
415,
782,
8,
2592,
9,
267,
1163,
275,
3504,
14,
415,
782,
8,
5279,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
6111,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
3504,
14,
24817,
63,
9905,
63,
5670,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
3504,
14,
24817,
63,
18015,
63,
9732,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
267,
291,
14,
1815,
8,
6857,
665,
1163,
9,
267,
291,
14,
1815,
8,
1848,
2356,
8145,
9,
267,
367,
1687,
315,
22146,
12,
1026,
12,
16484,
12,
2312,
26,
288,
291,
14,
1855,
8,
4333,
12,
1687,
12,
8145,
12,
488,
9,
288,
291,
14,
1855,
8,
4333,
12,
1687,
12,
8145,
12,
413,
9,
288,
291,
14,
1855,
8,
4333,
12,
1687,
12,
8145,
12,
298,
6857,
531,
398,
8145,
275,
3504,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
6111,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
3504,
14,
24817,
63,
18015,
63,
9732,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
398,
8145,
275,
3504,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
12,
3504,
14,
24817,
63,
18015,
63,
615,
654,
40,
1387,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
6111,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
3504,
14,
24817,
63,
18015,
63,
615,
654,
40,
1387,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
378,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
398,
8145,
275,
3504,
14,
415,
782,
8,
17,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
413,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
499,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
650,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
841,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
959,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
1227,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
398,
330,
1030,
453,
275,
984,
14,
13634,
627,
499,
435,
413,
267,
8145,
275,
3504,
14,
415,
782,
8,
66,
1030,
453,
12,
413,
12,
499,
12,
650,
12,
984,
14,
13634,
12,
330,
1030,
453,
9,
267,
291,
14,
629,
8,
6857,
14,
5425,
12,
330,
1030,
453,
9,
267,
291,
14,
629,
8,
6857,
14,
1541,
12,
413,
9,
267,
291,
14,
629,
8,
6857,
14,
2469,
12,
499,
9,
267,
291,
14,
629,
8,
6857,
14,
556,
1550,
12,
650,
9,
267,
291,
14,
629,
8,
6857,
14,
576,
12,
984,
14,
13634,
9,
267,
291,
14,
629,
8,
6857,
14,
85,
576,
12,
330,
1030,
453,
9,
267,
291,
14,
629,
8,
6857,
12,
8145,
9,
267,
291,
14,
7418,
8,
6857,
12,
1163,
9,
339,
347,
511,
63,
1825,
63,
1430,
8,
277,
304,
267,
1654,
3869,
275,
2838,
14,
3450,
342,
267,
1654,
3869,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
378,
430,
267,
1654,
3869,
14,
5859,
8,
17,
9,
267,
1890,
275,
2838,
14,
3450,
342,
267,
1890,
14,
409,
13091,
8,
797,
9,
267,
862,
26,
288,
1890,
14,
2242,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1654,
3869,
14,
27886,
3430,
17,
2459,
267,
871,
2838,
14,
705,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
589,
59,
16,
467,
7554,
14,
25652,
24547,
9,
267,
587,
26,
288,
327,
3730,
9070,
480,
8631,
1077,
1172,
4915,
662,
568,
24547,
531,
288,
986,
327,
2868,
15400,
3181,
1133,
746,
376,
1919,
2348,
267,
1654,
12,
5552,
275,
1654,
3869,
14,
5694,
342,
398,
340,
984,
14,
3246,
14,
2460,
480,
13245,
2349,
288,
3285,
275,
3504,
14,
24817,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eevee/urwid
|
urwid/widget.py
|
8
|
60739
|
#!/usr/bin/python
#
# Urwid basic widget classes
# Copyright (C) 2004-2012 Ian Ward
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Urwid web site: http://excess.org/urwid/
from operator import attrgetter
from urwid.util import (MetaSuper, decompose_tagmarkup, calc_width,
is_wide_char, move_prev_char, move_next_char)
from urwid.text_layout import calc_pos, calc_coords, shift_line
from urwid import signals
from urwid import text_layout
from urwid.canvas import (CanvasCache, CompositeCanvas, SolidCanvas,
apply_text_layout)
from urwid.command_map import (command_map, CURSOR_LEFT, CURSOR_RIGHT,
CURSOR_UP, CURSOR_DOWN, CURSOR_MAX_LEFT, CURSOR_MAX_RIGHT)
from urwid.split_repr import split_repr, remove_defaults, python3_repr
# define some names for these constants to avoid misspellings in the source
# and to document the constant strings we are using
# Widget sizing methods
FLOW = 'flow'
BOX = 'box'
FIXED = 'fixed'
# Text alignment modes
LEFT = 'left'
RIGHT = 'right'
CENTER = 'center'
# Filler alignment
TOP = 'top'
MIDDLE = 'middle'
BOTTOM = 'bottom'
# Text wrapping modes
SPACE = 'space'
ANY = 'any'
CLIP = 'clip'
# Width and Height settings
PACK = 'pack'
GIVEN = 'given'
RELATIVE = 'relative'
RELATIVE_100 = (RELATIVE, 100)
WEIGHT = 'weight'
class WidgetMeta(MetaSuper, signals.MetaSignals):
"""
Bases: :class:`MetaSuper`, :class:`MetaSignals`
Automatic caching of render and rows methods.
Class variable *no_cache* is a list of names of methods to not cache
automatically. Valid method names for *no_cache* are ``'render'`` and
``'rows'``.
Class variable *ignore_focus* if defined and set to ``True`` indicates
that the canvas this widget renders is not affected by the focus
parameter, so it may be ignored when caching.
"""
def __init__(cls, name, bases, d):
no_cache = d.get("no_cache", [])
super(WidgetMeta, cls).__init__(name, bases, d)
if "render" in d:
if "render" not in no_cache:
render_fn = cache_widget_render(cls)
else:
render_fn = nocache_widget_render(cls)
cls.render = render_fn
if "rows" in d and "rows" not in no_cache:
cls.rows = cache_widget_rows(cls)
if "no_cache" in d:
del cls.no_cache
if "ignore_focus" in d:
del cls.ignore_focus
class WidgetError(Exception):
pass
def validate_size(widget, size, canv):
"""
Raise a WidgetError if a canv does not match size size.
"""
if (size and size[1:] != (0,) and size[0] != canv.cols()) or \
(len(size)>1 and size[1] != canv.rows()):
raise WidgetError("Widget %r rendered (%d x %d) canvas"
" when passed size %r!" % (widget, canv.cols(),
canv.rows(), size))
def update_wrapper(new_fn, fn):
"""
Copy as much of the function detail from fn to new_fn
as we can.
"""
try:
new_fn.__name__ = fn.__name__
new_fn.__dict__.update(fn.__dict__)
new_fn.__doc__ = fn.__doc__
new_fn.__module__ = fn.__module__
except TypeError:
pass # python2.3 ignore read-only attributes
def cache_widget_render(cls):
"""
Return a function that wraps the cls.render() method
and fetches and stores canvases with CanvasCache.
"""
ignore_focus = bool(getattr(cls, "ignore_focus", False))
fn = cls.render
def cached_render(self, size, focus=False):
focus = focus and not ignore_focus
canv = CanvasCache.fetch(self, cls, size, focus)
if canv:
return canv
canv = fn(self, size, focus=focus)
validate_size(self, size, canv)
if canv.widget_info:
canv = CompositeCanvas(canv)
canv.finalize(self, size, focus)
CanvasCache.store(cls, canv)
return canv
cached_render.original_fn = fn
update_wrapper(cached_render, fn)
return cached_render
def nocache_widget_render(cls):
"""
Return a function that wraps the cls.render() method
and finalizes the canvas that it returns.
"""
fn = cls.render
if hasattr(fn, "original_fn"):
fn = fn.original_fn
def finalize_render(self, size, focus=False):
canv = fn(self, size, focus=focus)
if canv.widget_info:
canv = CompositeCanvas(canv)
validate_size(self, size, canv)
canv.finalize(self, size, focus)
return canv
finalize_render.original_fn = fn
update_wrapper(finalize_render, fn)
return finalize_render
def nocache_widget_render_instance(self):
"""
Return a function that wraps the cls.render() method
and finalizes the canvas that it returns, but does not
cache the canvas.
"""
fn = self.render.original_fn
def finalize_render(size, focus=False):
canv = fn(self, size, focus=focus)
if canv.widget_info:
canv = CompositeCanvas(canv)
canv.finalize(self, size, focus)
return canv
finalize_render.original_fn = fn
update_wrapper(finalize_render, fn)
return finalize_render
def cache_widget_rows(cls):
"""
Return a function that wraps the cls.rows() method
and returns rows from the CanvasCache if available.
"""
ignore_focus = bool(getattr(cls, "ignore_focus", False))
fn = cls.rows
def cached_rows(self, size, focus=False):
focus = focus and not ignore_focus
canv = CanvasCache.fetch(self, cls, size, focus)
if canv:
return canv.rows()
return fn(self, size, focus)
update_wrapper(cached_rows, fn)
return cached_rows
class Widget(object):
"""
Widget base class
.. attribute:: __metaclass__
:annotation: = urwid.WidgetMeta
See :class:`urwid.WidgetMeta` definition
.. attribute:: _selectable
:annotation: = False
The default :meth:`.selectable` method returns this
value.
.. attribute:: _sizing
:annotation: = frozenset(['flow', 'box', 'fixed'])
The default :meth:`.sizing` method returns this value.
.. attribute:: _command_map
:annotation: = urwid.command_map
A shared :class:`CommandMap` instance. May be redefined
in subclasses or widget instances.
.. method:: render(size, focus=False)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any concrete subclass
:param size: One of the following,
*maxcol* and *maxrow* are integers > 0:
(*maxcol*, *maxrow*)
for box sizing -- the parent chooses the exact
size of this widget
(*maxcol*,)
for flow sizing -- the parent chooses only the
number of columns for this widget
()
for fixed sizing -- this widget is a fixed size
which can't be adjusted by the parent
:type size: widget size
:param focus: set to ``True`` if this widget or one of its children
is in focus
:type focus: bool
:returns: A :class:`Canvas` subclass instance containing the
rendered content of this widget
:class:`Text` widgets return a :class:`TextCanvas` (arbitrary text and
display attributes), :class:`SolidFill` widgets return a
:class:`SolidCanvas` (a single character repeated across
the whole surface) and container widgets return a
:class:`CompositeCanvas` (one or more other canvases
arranged arbitrarily).
If *focus* is ``False``, the returned canvas may not have a cursor
position set.
There is some metaclass magic defined in the :class:`Widget`
metaclass :class:`WidgetMeta` that causes the
result of this method to be cached by :class:`CanvasCache`.
Later calls will automatically look up the value in the cache first.
As a small optimization the class variable :attr:`ignore_focus`
may be defined and set to ``True`` if this widget renders the same
canvas regardless of the value of the *focus* parameter.
Any time the content of a widget changes it should call
:meth:`_invalidate` to remove any cached canvases, or the widget
may render the cached canvas instead of creating a new one.
.. method:: rows(size, focus=False)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any flow widget. See :meth:`.sizing`.
See :meth:`Widget.render` for parameter details.
:returns: The number of rows required for this widget given a number
of columns in *size*
This is the method flow widgets use to communicate their size to other
widgets without having to render a canvas. This should be a quick
calculation as this function may be called a number of times in normal
operation. If your implementation may take a long time you should add
your own caching here.
There is some metaclass magic defined in the :class:`Widget`
metaclass :class:`WidgetMeta` that causes the
result of this function to be retrieved from any
canvas cached by :class:`CanvasCache`, so if your widget
has been rendered you may not receive calls to this function. The class
variable :attr:`ignore_focus` may be defined and set to ``True`` if this
widget renders the same size regardless of the value of the *focus*
parameter.
.. method:: keypress(size, key)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any selectable widget.
See :meth:`.selectable`.
:param size: See :meth:`Widget.render` for details
:type size: widget size
:param key: a single keystroke value; see :ref:`keyboard-input`
:type key: bytes or unicode
:returns: ``None`` if *key* was handled by this widget or
*key* (the same value passed) if *key* was not handled
by this widget
Container widgets will typically call the :meth:`keypress` method on
whichever of their children is set as the focus.
The standard widgets use :attr:`_command_map` to
determine what action should be performed for a given *key*. You may
modify these values to your liking globally, at some level in the
widget hierarchy or on individual widgets. See :class:`CommandMap`
for the defaults.
In your own widgets you may use whatever logic you like: filtering or
translating keys, selectively passing along events etc.
.. method:: mouse_event(size, event, button, col, row, focus)
.. note::
This method is not implemented in :class:`.Widget` but
may be implemented by a subclass. Not implementing this
method is equivalent to having a method that always returns
``False``.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:param event: Values such as ``'mouse press'``, ``'ctrl mouse press'``,
``'mouse release'``, ``'meta mouse release'``,
``'mouse drag'``; see :ref:`mouse-input`
:type event: mouse event
:param button: 1 through 5 for press events, often 0 for release events
(which button was released is often not known)
:type button: int
:param col: Column of the event, 0 is the left edge of this widget
:type col: int
:param row: Row of the event, 0 it the top row of this widget
:type row: int
:param focus: Set to ``True`` if this widget or one of its children
is in focus
:type focus: bool
:returns: ``True`` if the event was handled by this widget, ``False``
otherwise
Container widgets will typically call the :meth:`mouse_event` method on
whichever of their children is at the position (*col*, *row*).
.. method:: get_cursor_coords(size)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any widget that may return cursor
coordinates as part of the canvas that :meth:`render` returns.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:returns: (*col*, *row*) if this widget has a cursor, ``None`` otherwise
Return the cursor coordinates (*col*, *row*) of a cursor that will appear
as part of the canvas rendered by this widget when in focus, or ``None``
if no cursor is displayed.
The :class:`ListBox` widget
uses this method to make sure a cursor in the focus widget is not
scrolled out of view. It is a separate method to avoid having to render
the whole widget while calculating layout.
Container widgets will typically call the :meth:`.get_cursor_coords`
method on their focus widget.
.. method:: get_pref_col(size)
.. note::
This method is not implemented in :class:`.Widget` but
may be implemented by a subclass.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:returns: a column number or ``'left'`` for the leftmost available
column or ``'right'`` for the rightmost available column
Return the preferred column for the cursor to be displayed in this
widget. This value might not be the same as the column returned from
:meth:`get_cursor_coords`.
The :class:`ListBox` and :class:`Pile`
widgets call this method on a widget losing focus and use the value
returned to call :meth:`.move_cursor_to_coords` on the widget becoming
the focus. This allows the focus to move up and down through widgets
while keeping the cursor in approximately the same column on screen.
.. method:: move_cursor_to_coords(size, col, row)
.. note::
This method is not implemented in :class:`.Widget` but
may be implemented by a subclass. Not implementing this
method is equivalent to having a method that always returns
``False``.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:param col: new column for the cursor, 0 is the left edge of this widget
:type col: int
:param row: new row for the cursor, 0 it the top row of this widget
:type row: int
:returns: ``True`` if the position was set successfully anywhere on
*row*, ``False`` otherwise
"""
__metaclass__ = WidgetMeta
_selectable = False
_sizing = frozenset([FLOW, BOX, FIXED])
_command_map = command_map
def _invalidate(self):
"""
Mark cached canvases rendered by this widget as dirty so that
they will not be used again.
"""
CanvasCache.invalidate(self)
def _emit(self, name, *args):
"""
Convenience function to emit signals with self as first
argument.
"""
signals.emit_signal(self, name, self, *args)
def selectable(self):
"""
:returns: ``True`` if this is a widget that is designed to take the
focus, i.e. it contains something the user might want to
interact with, ``False`` otherwise,
This default implementation returns :attr:`._selectable`.
Subclasses may leave these is if the are not selectable,
or if they are always selectable they may
set the :attr:`_selectable` class variable to ``True``.
If this method returns ``True`` then the :meth:`.keypress` method
must be implemented.
Returning ``False`` does not guarantee that this widget will never be in
focus, only that this widget will usually be skipped over when changing
focus. It is still possible for non selectable widgets to have the focus
(typically when there are no other selectable widgets visible).
"""
return self._selectable
def sizing(self):
"""
:returns: A frozenset including one or more of ``'box'``, ``'flow'`` and
``'fixed'``. Default implementation returns the value of
:attr:`._sizing`, which for this class includes all three.
The sizing modes returned indicate the modes that may be
supported by this widget, but is not sufficient to know
that using that sizing mode will work. Subclasses should
make an effort to remove sizing modes they know will not
work given the state of the widget, but many do not yet
do this.
If a sizing mode is missing from the set then the widget
should fail when used in that mode.
If ``'flow'`` is among the values returned then the other
methods in this widget must be able to accept a
single-element tuple (*maxcol*,) to their ``size``
parameter, and the :meth:`rows` method must be defined.
If ``'box'`` is among the values returned then the other
methods must be able to accept a two-element tuple
(*maxcol*, *maxrow*) to their size paramter.
If ``'fixed'`` is among the values returned then the other
methods must be able to accept an empty tuple () to
their size parameter, and the :meth:`pack` method must
be defined.
"""
return self._sizing
def pack(self, size, focus=False):
"""
See :meth:`Widget.render` for parameter details.
:returns: A "packed" size (*maxcol*, *maxrow*) for this widget
Calculate and return a minimum
size where all content could still be displayed. Fixed widgets must
implement this method and return their size when ``()`` is passed as the
*size* parameter.
This default implementation returns the *size* passed, or the *maxcol*
passed and the value of :meth:`rows` as the *maxrow* when (*maxcol*,)
is passed as the *size* parameter.
.. note::
This is a new method that hasn't been fully implemented across the
standard widget types. In particular it has not yet been
implemented for container widgets.
:class:`Text` widgets have implemented this method.
You can use :meth:`Text.pack` to calculate the minumum
columns and rows required to display a text widget without wrapping,
or call it iteratively to calculate the minimum number of columns
required to display the text wrapped into a target number of rows.
"""
if not size:
if FIXED in self.sizing():
raise NotImplementedError('Fixed widgets must override'
' Widget.pack()')
raise WidgetError('Cannot pack () size, this is not a fixed'
' widget: %s' % repr(self))
elif len(size) == 1:
if FLOW in self.sizing():
return size + (self.rows(size, focus),)
raise WidgetError('Cannot pack (maxcol,) size, this is not a'
' flow widget: %s' % repr(self))
return size
base_widget = property(lambda self:self, doc="""
Read-only property that steps through decoration widgets
and returns the one at the base. This default implementation
returns self.
""")
focus = property(lambda self:None, doc="""
Read-only property returning the child widget in focus for
container widgets. This default implementation
always returns ``None``, indicating that this widget has no children.
""")
def _not_a_container(self, val=None):
raise IndexError(
"No focus_position, %r is not a container widget" % self)
focus_position = property(_not_a_container, _not_a_container, doc="""
Property for reading and setting the focus position for
container widgets. This default implementation raises
:exc:`IndexError`, making normal widgets fail the same way
accessing :attr:`.focus_position` on an empty container widget would.
""")
def __repr__(self):
"""
A friendly __repr__ for widgets, designed to be extended
by subclasses with _repr_words and _repr_attr methods.
"""
return split_repr(self)
def _repr_words(self):
words = []
if self.selectable():
words = ["selectable"] + words
if self.sizing() and self.sizing() != frozenset([FLOW, BOX, FIXED]):
sizing_modes = list(self.sizing())
sizing_modes.sort()
words.append("/".join(sizing_modes))
return words + ["widget"]
def _repr_attrs(self):
return {}
class FlowWidget(Widget):
"""
Deprecated. Inherit from Widget and add:
_sizing = frozenset(['flow'])
at the top of your class definition instead.
Base class of widgets that determine their rows from the number of
columns available.
"""
_sizing = frozenset([FLOW])
def rows(self, size, focus=False):
"""
All flow widgets must implement this function.
"""
raise NotImplementedError()
def render(self, size, focus=False):
"""
All widgets must implement this function.
"""
raise NotImplementedError()
class BoxWidget(Widget):
"""
Deprecated. Inherit from Widget and add:
_sizing = frozenset(['box'])
_selectable = True
at the top of your class definition instead.
Base class of width and height constrained widgets such as
the top level widget attached to the display object
"""
_selectable = True
_sizing = frozenset([BOX])
def render(self, size, focus=False):
"""
All widgets must implement this function.
"""
raise NotImplementedError()
def fixed_size(size):
"""
raise ValueError if size != ().
Used by FixedWidgets to test size parameter.
"""
if size != ():
raise ValueError("FixedWidget takes only () for size." \
"passed: %r" % (size,))
class FixedWidget(Widget):
"""
Deprecated. Inherit from Widget and add:
_sizing = frozenset(['fixed'])
at the top of your class definition instead.
Base class of widgets that know their width and height and
cannot be resized
"""
_sizing = frozenset([FIXED])
def render(self, size, focus=False):
"""
All widgets must implement this function.
"""
raise NotImplementedError()
def pack(self, size=None, focus=False):
"""
All fixed widgets must implement this function.
"""
raise NotImplementedError()
class Divider(Widget):
"""
Horizontal divider widget
"""
_sizing = frozenset([FLOW])
ignore_focus = True
def __init__(self,div_char=u" ",top=0,bottom=0):
"""
:param div_char: character to repeat across line
:type div_char: bytes or unicode
:param top: number of blank lines above
:type top: int
:param bottom: number of blank lines below
:type bottom: int
>>> Divider()
<Divider flow widget>
>>> Divider(u'-')
<Divider flow widget '-'>
>>> Divider(u'x', 1, 2)
<Divider flow widget 'x' bottom=2 top=1>
"""
self.__super.__init__()
self.div_char = div_char
self.top = top
self.bottom = bottom
def _repr_words(self):
return self.__super._repr_words() + [
python3_repr(self.div_char)] * (self.div_char != u" ")
def _repr_attrs(self):
attrs = dict(self.__super._repr_attrs())
if self.top: attrs['top'] = self.top
if self.bottom: attrs['bottom'] = self.bottom
return attrs
def rows(self, size, focus=False):
"""
Return the number of lines that will be rendered.
>>> Divider().rows((10,))
1
>>> Divider(u'x', 1, 2).rows((10,))
4
"""
(maxcol,) = size
return self.top + 1 + self.bottom
def render(self, size, focus=False):
"""
Render the divider as a canvas and return it.
>>> Divider().render((10,)).text # ... = b in Python 3
[...' ']
>>> Divider(u'-', top=1).render((10,)).text
[...' ', ...'----------']
>>> Divider(u'x', bottom=2).render((5,)).text
[...'xxxxx', ...' ', ...' ']
"""
(maxcol,) = size
canv = SolidCanvas(self.div_char, maxcol, 1)
canv = CompositeCanvas(canv)
if self.top or self.bottom:
canv.pad_trim_top_bottom(self.top, self.bottom)
return canv
class SolidFill(BoxWidget):
"""
A box widget that fills an area with a single character
"""
_selectable = False
ignore_focus = True
def __init__(self, fill_char=" "):
"""
:param fill_char: character to fill area with
:type fill_char: bytes or unicode
>>> SolidFill(u'8')
<SolidFill box widget '8'>
"""
self.__super.__init__()
self.fill_char = fill_char
def _repr_words(self):
return self.__super._repr_words() + [python3_repr(self.fill_char)]
def render(self, size, focus=False ):
"""
Render the Fill as a canvas and return it.
>>> SolidFill().render((4,2)).text # ... = b in Python 3
[...' ', ...' ']
>>> SolidFill('#').render((5,3)).text
[...'#####', ...'#####', ...'#####']
"""
maxcol, maxrow = size
return SolidCanvas(self.fill_char, maxcol, maxrow)
class TextError(Exception):
pass
class Text(Widget):
"""
a horizontally resizeable text widget
"""
_sizing = frozenset([FLOW])
ignore_focus = True
_repr_content_length_max = 140
def __init__(self, markup, align=LEFT, wrap=SPACE, layout=None):
"""
:param markup: content of text widget, one of:
bytes or unicode
text to be displayed
(*display attribute*, *text markup*)
*text markup* with *display attribute* applied to all parts
of *text markup* with no display attribute already applied
[*text markup*, *text markup*, ... ]
all *text markup* in the list joined together
:type markup: :ref:`text-markup`
:param align: typically ``'left'``, ``'center'`` or ``'right'``
:type align: text alignment mode
:param wrap: typically ``'space'``, ``'any'`` or ``'clip'``
:type wrap: text wrapping mode
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
>>> Text(u"Hello")
<Text flow widget 'Hello'>
>>> t = Text(('bold', u"stuff"), 'right', 'any')
>>> t
<Text flow widget 'stuff' align='right' wrap='any'>
>>> print t.text
stuff
>>> t.attrib
[('bold', 5)]
"""
self.__super.__init__()
self._cache_maxcol = None
self.set_text(markup)
self.set_layout(align, wrap, layout)
def _repr_words(self):
"""
Show the text in the repr in python3 format (b prefix for byte
strings) and truncate if it's too long
"""
first = self.__super._repr_words()
text = self.get_text()[0]
rest = python3_repr(text)
if len(rest) > self._repr_content_length_max:
rest = (rest[:self._repr_content_length_max * 2 // 3 - 3] +
'...' + rest[-self._repr_content_length_max // 3:])
return first + [rest]
def _repr_attrs(self):
attrs = dict(self.__super._repr_attrs(),
align=self._align_mode,
wrap=self._wrap_mode)
return remove_defaults(attrs, Text.__init__)
def _invalidate(self):
self._cache_maxcol = None
self.__super._invalidate()
def set_text(self,markup):
"""
Set content of text widget.
:param markup: see :class:`Text` for description.
:type markup: text markup
>>> t = Text(u"foo")
>>> print t.text
foo
>>> t.set_text(u"bar")
>>> print t.text
bar
>>> t.text = u"baz" # not supported because text stores text but set_text() takes markup
Traceback (most recent call last):
AttributeError: can't set attribute
"""
self._text, self._attrib = decompose_tagmarkup(markup)
self._invalidate()
def get_text(self):
"""
:returns: (*text*, *display attributes*)
*text*
complete bytes/unicode content of text widget
*display attributes*
run length encoded display attributes for *text*, eg.
``[('attr1', 10), ('attr2', 5)]``
>>> Text(u"Hello").get_text() # ... = u in Python 2
(...'Hello', [])
>>> Text(('bright', u"Headline")).get_text()
(...'Headline', [('bright', 8)])
>>> Text([('a', u"one"), u"two", ('b', u"three")]).get_text()
(...'onetwothree', [('a', 3), (None, 3), ('b', 5)])
"""
return self._text, self._attrib
text = property(lambda self:self.get_text()[0], doc="""
Read-only property returning the complete bytes/unicode content
of this widget
""")
attrib = property(lambda self:self.get_text()[1], doc="""
Read-only property returning the run-length encoded display
attributes of this widget
""")
def set_align_mode(self, mode):
"""
Set text alignment mode. Supported modes depend on text layout
object in use but defaults to a :class:`StandardTextLayout` instance
:param mode: typically ``'left'``, ``'center'`` or ``'right'``
:type mode: text alignment mode
>>> t = Text(u"word")
>>> t.set_align_mode('right')
>>> t.align
'right'
>>> t.render((10,)).text # ... = b in Python 3
[...' word']
>>> t.align = 'center'
>>> t.render((10,)).text
[...' word ']
>>> t.align = 'somewhere'
Traceback (most recent call last):
TextError: Alignment mode 'somewhere' not supported.
"""
if not self.layout.supports_align_mode(mode):
raise TextError("Alignment mode %r not supported."%
(mode,))
self._align_mode = mode
self._invalidate()
def set_wrap_mode(self, mode):
"""
Set text wrapping mode. Supported modes depend on text layout
object in use but defaults to a :class:`StandardTextLayout` instance
:param mode: typically ``'space'``, ``'any'`` or ``'clip'``
:type mode: text wrapping mode
>>> t = Text(u"some words")
>>> t.render((6,)).text # ... = b in Python 3
[...'some ', ...'words ']
>>> t.set_wrap_mode('clip')
>>> t.wrap
'clip'
>>> t.render((6,)).text
[...'some w']
>>> t.wrap = 'any' # Urwid 0.9.9 or later
>>> t.render((6,)).text
[...'some w', ...'ords ']
>>> t.wrap = 'somehow'
Traceback (most recent call last):
TextError: Wrap mode 'somehow' not supported.
"""
if not self.layout.supports_wrap_mode(mode):
raise TextError("Wrap mode %r not supported."%(mode,))
self._wrap_mode = mode
self._invalidate()
def set_layout(self, align, wrap, layout=None):
"""
Set the text layout object, alignment and wrapping modes at
the same time.
:type align: text alignment mode
:param wrap: typically 'space', 'any' or 'clip'
:type wrap: text wrapping mode
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
>>> t = Text(u"hi")
>>> t.set_layout('right', 'clip')
>>> t
<Text flow widget 'hi' align='right' wrap='clip'>
"""
if layout is None:
layout = text_layout.default_layout
self._layout = layout
self.set_align_mode(align)
self.set_wrap_mode(wrap)
align = property(lambda self:self._align_mode, set_align_mode)
wrap = property(lambda self:self._wrap_mode, set_wrap_mode)
layout = property(lambda self:self._layout)
def render(self, size, focus=False):
"""
Render contents with wrapping and alignment. Return canvas.
See :meth:`Widget.render` for parameter details.
>>> Text(u"important things").render((18,)).text # ... = b in Python 3
[...'important things ']
>>> Text(u"important things").render((11,)).text
[...'important ', ...'things ']
"""
(maxcol,) = size
text, attr = self.get_text()
#assert isinstance(text, unicode)
trans = self.get_line_translation( maxcol, (text,attr) )
return apply_text_layout(text, attr, trans, maxcol)
def rows(self, size, focus=False):
"""
Return the number of rows the rendered text requires.
See :meth:`Widget.rows` for parameter details.
>>> Text(u"important things").rows((18,))
1
>>> Text(u"important things").rows((11,))
2
"""
(maxcol,) = size
return len(self.get_line_translation(maxcol))
def get_line_translation(self, maxcol, ta=None):
"""
Return layout structure used to map self.text to a canvas.
This method is used internally, but may be useful for
debugging custom layout classes.
:param maxcol: columns available for display
:type maxcol: int
:param ta: ``None`` or the (*text*, *display attributes*) tuple
returned from :meth:`.get_text`
:type ta: text and display attributes
"""
if not self._cache_maxcol or self._cache_maxcol != maxcol:
self._update_cache_translation(maxcol, ta)
return self._cache_translation
def _update_cache_translation(self,maxcol, ta):
if ta:
text, attr = ta
else:
text, attr = self.get_text()
self._cache_maxcol = maxcol
self._cache_translation = self._calc_line_translation(
text, maxcol )
def _calc_line_translation(self, text, maxcol ):
return self.layout.layout(
text, self._cache_maxcol,
self._align_mode, self._wrap_mode )
def pack(self, size=None, focus=False):
"""
Return the number of screen columns and rows required for
this Text widget to be displayed without wrapping or
clipping, as a single element tuple.
:param size: ``None`` for unlimited screen columns or (*maxcol*,) to
specify a maximum column size
:type size: widget size
>>> Text(u"important things").pack()
(16, 1)
>>> Text(u"important things").pack((15,))
(9, 2)
>>> Text(u"important things").pack((8,))
(8, 2)
"""
text, attr = self.get_text()
if size is not None:
(maxcol,) = size
if not hasattr(self.layout, "pack"):
return size
trans = self.get_line_translation( maxcol, (text,attr))
cols = self.layout.pack( maxcol, trans )
return (cols, len(trans))
i = 0
cols = 0
while i < len(text):
j = text.find('\n', i)
if j == -1:
j = len(text)
c = calc_width(text, i, j)
if c>cols:
cols = c
i = j+1
return (cols, text.count('\n') + 1)
class EditError(TextError):
pass
class Edit(Text):
"""
Text editing widget implements cursor movement, text insertion and
deletion. A caption may prefix the editing area. Uses text class
for text layout.
Users of this class to listen for ``"change"`` events
sent when the value of edit_text changes. See :func:``connect_signal``.
"""
# (this variable is picked up by the MetaSignals metaclass)
signals = ["change"]
def valid_char(self, ch):
"""
Filter for text that may be entered into this widget by the user
:param ch: character to be inserted
:type ch: bytes or unicode
This implementation returns True for all printable characters.
"""
return is_wide_char(ch,0) or (len(ch)==1 and ord(ch) >= 32)
def selectable(self): return True
def __init__(self, caption=u"", edit_text=u"", multiline=False,
align=LEFT, wrap=SPACE, allow_tab=False,
edit_pos=None, layout=None, mask=None):
"""
:param caption: markup for caption preceeding edit_text, see
:class:`Text` for description of text markup.
:type caption: text markup
:param edit_text: initial text for editing, type (bytes or unicode)
must match the text in the caption
:type edit_text: bytes or unicode
:param multiline: True: 'enter' inserts newline False: return it
:type multiline: bool
:param align: typically 'left', 'center' or 'right'
:type align: text alignment mode
:param wrap: typically 'space', 'any' or 'clip'
:type wrap: text wrapping mode
:param allow_tab: True: 'tab' inserts 1-8 spaces False: return it
:type allow_tab: bool
:param edit_pos: initial position for cursor, None:end of edit_text
:type edit_pos: int
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
:param mask: hide text entered with this character, None:disable mask
:type mask: bytes or unicode
>>> Edit()
<Edit selectable flow widget '' edit_pos=0>
>>> Edit(u"Y/n? ", u"yes")
<Edit selectable flow widget 'yes' caption='Y/n? ' edit_pos=3>
>>> Edit(u"Name ", u"Smith", edit_pos=1)
<Edit selectable flow widget 'Smith' caption='Name ' edit_pos=1>
>>> Edit(u"", u"3.14", align='right')
<Edit selectable flow widget '3.14' align='right' edit_pos=4>
"""
self.__super.__init__("", align, wrap, layout)
self.multiline = multiline
self.allow_tab = allow_tab
self._edit_pos = 0
self.set_caption(caption)
self.set_edit_text(edit_text)
if edit_pos is None:
edit_pos = len(edit_text)
self.set_edit_pos(edit_pos)
self.set_mask(mask)
self._shift_view_to_cursor = False
def _repr_words(self):
return self.__super._repr_words()[:-1] + [
python3_repr(self._edit_text)] + [
'caption=' + python3_repr(self._caption)] * bool(self._caption) + [
'multiline'] * (self.multiline is True)
def _repr_attrs(self):
attrs = dict(self.__super._repr_attrs(),
edit_pos=self._edit_pos)
return remove_defaults(attrs, Edit.__init__)
def get_text(self):
"""
Returns ``(text, display attributes)``. See :meth:`Text.get_text`
for details.
Text returned includes the caption and edit_text, possibly masked.
>>> Edit(u"What? ","oh, nothing.").get_text() # ... = u in Python 2
(...'What? oh, nothing.', [])
>>> Edit(('bright',u"user@host:~$ "),"ls").get_text()
(...'user@host:~$ ls', [('bright', 13)])
>>> Edit(u"password:", u"seekrit", mask=u"*").get_text()
(...'password:*******', [])
"""
if self._mask is None:
return self._caption + self._edit_text, self._attrib
else:
return self._caption + (self._mask * len(self._edit_text)), self._attrib
def set_text(self, markup):
"""
Not supported by Edit widget.
>>> Edit().set_text("test")
Traceback (most recent call last):
EditError: set_text() not supported. Use set_caption() or set_edit_text() instead.
"""
# FIXME: this smells. reimplement Edit as a WidgetWrap subclass to
# clean this up
# hack to let Text.__init__() work
if not hasattr(self, '_text') and markup == "":
self._text = None
return
raise EditError("set_text() not supported. Use set_caption()"
" or set_edit_text() instead.")
def get_pref_col(self, size):
"""
Return the preferred column for the cursor, or the
current cursor x value. May also return ``'left'`` or ``'right'``
to indicate the leftmost or rightmost column available.
This method is used internally and by other widgets when
moving the cursor up or down between widgets so that the
column selected is one that the user would expect.
>>> size = (10,)
>>> Edit().get_pref_col(size)
0
>>> e = Edit(u"", u"word")
>>> e.get_pref_col(size)
4
>>> e.keypress(size, 'left')
>>> e.get_pref_col(size)
3
>>> e.keypress(size, 'end')
>>> e.get_pref_col(size)
'right'
>>> e = Edit(u"", u"2\\nwords")
>>> e.keypress(size, 'left')
>>> e.keypress(size, 'up')
>>> e.get_pref_col(size)
4
>>> e.keypress(size, 'left')
>>> e.get_pref_col(size)
0
"""
(maxcol,) = size
pref_col, then_maxcol = self.pref_col_maxcol
if then_maxcol != maxcol:
return self.get_cursor_coords((maxcol,))[0]
else:
return pref_col
def update_text(self):
"""
No longer supported.
>>> Edit().update_text()
Traceback (most recent call last):
EditError: update_text() has been removed. Use set_caption() or set_edit_text() instead.
"""
raise EditError("update_text() has been removed. Use "
"set_caption() or set_edit_text() instead.")
def set_caption(self, caption):
"""
Set the caption markup for this widget.
:param caption: markup for caption preceeding edit_text, see
:meth:`Text.__init__` for description of text markup.
>>> e = Edit("")
>>> e.set_caption("cap1")
>>> print e.caption
cap1
>>> e.set_caption(('bold', "cap2"))
>>> print e.caption
cap2
>>> e.attrib
[('bold', 4)]
>>> e.caption = "cap3" # not supported because caption stores text but set_caption() takes markup
Traceback (most recent call last):
AttributeError: can't set attribute
"""
self._caption, self._attrib = decompose_tagmarkup(caption)
self._invalidate()
caption = property(lambda self:self._caption)
def set_edit_pos(self, pos):
"""
Set the cursor position with a self.edit_text offset.
Clips pos to [0, len(edit_text)].
:param pos: cursor position
:type pos: int
>>> e = Edit(u"", u"word")
>>> e.edit_pos
4
>>> e.set_edit_pos(2)
>>> e.edit_pos
2
>>> e.edit_pos = -1 # Urwid 0.9.9 or later
>>> e.edit_pos
0
>>> e.edit_pos = 20
>>> e.edit_pos
4
"""
if pos < 0:
pos = 0
if pos > len(self._edit_text):
pos = len(self._edit_text)
self.highlight = None
self.pref_col_maxcol = None, None
self._edit_pos = pos
self._invalidate()
edit_pos = property(lambda self:self._edit_pos, set_edit_pos)
def set_mask(self, mask):
"""
Set the character for masking text away.
:param mask: hide text entered with this character, None:disable mask
:type mask: bytes or unicode
"""
self._mask = mask
self._invalidate()
def set_edit_text(self, text):
"""
Set the edit text for this widget.
:param text: text for editing, type (bytes or unicode)
must match the text in the caption
:type text: bytes or unicode
>>> e = Edit()
>>> e.set_edit_text(u"yes")
>>> print e.edit_text
yes
>>> e
<Edit selectable flow widget 'yes' edit_pos=0>
>>> e.edit_text = u"no" # Urwid 0.9.9 or later
>>> print e.edit_text
no
"""
text = self._normalize_to_caption(text)
self.highlight = None
self._emit("change", text)
self._edit_text = text
if self.edit_pos > len(text):
self.edit_pos = len(text)
self._invalidate()
def get_edit_text(self):
"""
Return the edit text for this widget.
>>> e = Edit(u"What? ", u"oh, nothing.")
>>> print e.get_edit_text()
oh, nothing.
>>> print e.edit_text
oh, nothing.
"""
return self._edit_text
edit_text = property(get_edit_text, set_edit_text, doc="""
Read-only property returning the edit text for this widget.
""")
def insert_text(self, text):
"""
Insert text at the cursor position and update cursor.
This method is used by the keypress() method when inserting
one or more characters into edit_text.
:param text: text for inserting, type (bytes or unicode)
must match the text in the caption
:type text: bytes or unicode
>>> e = Edit(u"", u"42")
>>> e.insert_text(u".5")
>>> e
<Edit selectable flow widget '42.5' edit_pos=4>
>>> e.set_edit_pos(2)
>>> e.insert_text(u"a")
>>> print e.edit_text
42a.5
"""
text = self._normalize_to_caption(text)
result_text, result_pos = self.insert_text_result(text)
self.set_edit_text(result_text)
self.set_edit_pos(result_pos)
self.highlight = None
def _normalize_to_caption(self, text):
"""
Return text converted to the same type as self.caption
(bytes or unicode)
"""
tu = isinstance(text, unicode)
cu = isinstance(self._caption, unicode)
if tu == cu:
return text
if tu:
return text.encode('ascii') # follow python2's implicit conversion
return text.decode('ascii')
def insert_text_result(self, text):
"""
Return result of insert_text(text) without actually performing the
insertion. Handy for pre-validation.
:param text: text for inserting, type (bytes or unicode)
must match the text in the caption
:type text: bytes or unicode
"""
# if there's highlighted text, it'll get replaced by the new text
text = self._normalize_to_caption(text)
if self.highlight:
start, stop = self.highlight
btext, etext = self.edit_text[:start], self.edit_text[stop:]
result_text = btext + etext
result_pos = start
else:
result_text = self.edit_text
result_pos = self.edit_pos
try:
result_text = (result_text[:result_pos] + text +
result_text[result_pos:])
except:
assert 0, repr((self.edit_text, result_text, text))
result_pos += len(text)
return (result_text, result_pos)
def keypress(self, size, key):
"""
Handle editing keystrokes, return others.
>>> e, size = Edit(), (20,)
>>> e.keypress(size, 'x')
>>> e.keypress(size, 'left')
>>> e.keypress(size, '1')
>>> print e.edit_text
1x
>>> e.keypress(size, 'backspace')
>>> e.keypress(size, 'end')
>>> e.keypress(size, '2')
>>> print e.edit_text
x2
>>> e.keypress(size, 'shift f1')
'shift f1'
"""
(maxcol,) = size
p = self.edit_pos
if self.valid_char(key):
if (isinstance(key, unicode) and not
isinstance(self._caption, unicode)):
# screen is sending us unicode input, must be using utf-8
# encoding because that's all we support, so convert it
# to bytes to match our caption's type
key = key.encode('utf-8')
self.insert_text(key)
elif key=="tab" and self.allow_tab:
key = " "*(8-(self.edit_pos%8))
self.insert_text(key)
elif key=="enter" and self.multiline:
key = "\n"
self.insert_text(key)
elif self._command_map[key] == CURSOR_LEFT:
if p==0: return key
p = move_prev_char(self.edit_text,0,p)
self.set_edit_pos(p)
elif self._command_map[key] == CURSOR_RIGHT:
if p >= len(self.edit_text): return key
p = move_next_char(self.edit_text,p,len(self.edit_text))
self.set_edit_pos(p)
elif self._command_map[key] in (CURSOR_UP, CURSOR_DOWN):
self.highlight = None
x,y = self.get_cursor_coords((maxcol,))
pref_col = self.get_pref_col((maxcol,))
assert pref_col is not None
#if pref_col is None:
# pref_col = x
if self._command_map[key] == CURSOR_UP: y -= 1
else: y += 1
if not self.move_cursor_to_coords((maxcol,),pref_col,y):
return key
elif key=="backspace":
self.pref_col_maxcol = None, None
if not self._delete_highlighted():
if p == 0: return key
p = move_prev_char(self.edit_text,0,p)
self.set_edit_text( self.edit_text[:p] +
self.edit_text[self.edit_pos:] )
self.set_edit_pos( p )
elif key=="delete":
self.pref_col_maxcol = None, None
if not self._delete_highlighted():
if p >= len(self.edit_text):
return key
p = move_next_char(self.edit_text,p,len(self.edit_text))
self.set_edit_text( self.edit_text[:self.edit_pos] +
self.edit_text[p:] )
elif self._command_map[key] in (CURSOR_MAX_LEFT, CURSOR_MAX_RIGHT):
self.highlight = None
self.pref_col_maxcol = None, None
x,y = self.get_cursor_coords((maxcol,))
if self._command_map[key] == CURSOR_MAX_LEFT:
self.move_cursor_to_coords((maxcol,), LEFT, y)
else:
self.move_cursor_to_coords((maxcol,), RIGHT, y)
return
else:
# key wasn't handled
return key
def move_cursor_to_coords(self, size, x, y):
"""
Set the cursor position with (x,y) coordinates.
Returns True if move succeeded, False otherwise.
>>> size = (10,)
>>> e = Edit("","edit\\ntext")
>>> e.move_cursor_to_coords(size, 5, 0)
True
>>> e.edit_pos
4
>>> e.move_cursor_to_coords(size, 5, 3)
False
>>> e.move_cursor_to_coords(size, 0, 1)
True
>>> e.edit_pos
5
"""
(maxcol,) = size
trans = self.get_line_translation(maxcol)
top_x, top_y = self.position_coords(maxcol, 0)
if y < top_y or y >= len(trans):
return False
pos = calc_pos( self.get_text()[0], trans, x, y )
e_pos = pos - len(self.caption)
if e_pos < 0: e_pos = 0
if e_pos > len(self.edit_text): e_pos = len(self.edit_text)
self.edit_pos = e_pos
self.pref_col_maxcol = x, maxcol
self._invalidate()
return True
def mouse_event(self, size, event, button, x, y, focus):
"""
Move the cursor to the location clicked for button 1.
>>> size = (20,)
>>> e = Edit("","words here")
>>> e.mouse_event(size, 'mouse press', 1, 2, 0, True)
True
>>> e.edit_pos
2
"""
(maxcol,) = size
if button==1:
return self.move_cursor_to_coords( (maxcol,), x, y )
def _delete_highlighted(self):
"""
Delete all highlighted text and update cursor position, if any
text is highlighted.
"""
if not self.highlight: return
start, stop = self.highlight
btext, etext = self.edit_text[:start], self.edit_text[stop:]
self.set_edit_text( btext + etext )
self.edit_pos = start
self.highlight = None
return True
def render(self, size, focus=False):
"""
Render edit widget and return canvas. Include cursor when in
focus.
>>> c = Edit("? ","yes").render((10,), focus=True)
>>> c.text # ... = b in Python 3
[...'? yes ']
>>> c.cursor
(5, 0)
"""
(maxcol,) = size
self._shift_view_to_cursor = bool(focus)
canv = Text.render(self,(maxcol,))
if focus:
canv = CompositeCanvas(canv)
canv.cursor = self.get_cursor_coords((maxcol,))
# .. will need to FIXME if I want highlight to work again
#if self.highlight:
# hstart, hstop = self.highlight_coords()
# d.coords['highlight'] = [ hstart, hstop ]
return canv
def get_line_translation(self, maxcol, ta=None ):
trans = Text.get_line_translation(self, maxcol, ta)
if not self._shift_view_to_cursor:
return trans
text, ignore = self.get_text()
x,y = calc_coords( text, trans,
self.edit_pos + len(self.caption) )
if x < 0:
return ( trans[:y]
+ [shift_line(trans[y],-x)]
+ trans[y+1:] )
elif x >= maxcol:
return ( trans[:y]
+ [shift_line(trans[y],-(x-maxcol+1))]
+ trans[y+1:] )
return trans
def get_cursor_coords(self, size):
"""
Return the (*x*, *y*) coordinates of cursor within widget.
>>> Edit("? ","yes").get_cursor_coords((10,))
(5, 0)
"""
(maxcol,) = size
self._shift_view_to_cursor = True
return self.position_coords(maxcol,self.edit_pos)
def position_coords(self,maxcol,pos):
"""
Return (*x*, *y*) coordinates for an offset into self.edit_text.
"""
p = pos + len(self.caption)
trans = self.get_line_translation(maxcol)
x,y = calc_coords(self.get_text()[0], trans,p)
return x,y
class IntEdit(Edit):
"""Edit widget for integer values"""
def valid_char(self, ch):
"""
Return true for decimal digits.
"""
return len(ch)==1 and ch in "0123456789"
def __init__(self,caption="",default=None):
"""
caption -- caption markup
default -- default edit value
>>> IntEdit(u"", 42)
<IntEdit selectable flow widget '42' edit_pos=2>
"""
if default is not None: val = str(default)
else: val = ""
self.__super.__init__(caption,val)
def keypress(self, size, key):
"""
Handle editing keystrokes. Remove leading zeros.
>>> e, size = IntEdit(u"", 5002), (10,)
>>> e.keypress(size, 'home')
>>> e.keypress(size, 'delete')
>>> print e.edit_text
002
>>> e.keypress(size, 'end')
>>> print e.edit_text
2
"""
(maxcol,) = size
unhandled = Edit.keypress(self,(maxcol,),key)
if not unhandled:
# trim leading zeros
while self.edit_pos > 0 and self.edit_text[:1] == "0":
self.set_edit_pos( self.edit_pos - 1)
self.set_edit_text(self.edit_text[1:])
return unhandled
def value(self):
"""
Return the numeric value of self.edit_text.
>>> e, size = IntEdit(), (10,)
>>> e.keypress(size, '5')
>>> e.keypress(size, '1')
>>> e.value() == 51
True
"""
if self.edit_text:
return long(self.edit_text)
else:
return 0
def delegate_to_widget_mixin(attribute_name):
"""
Return a mixin class that delegates all standard widget methods
to an attribute given by attribute_name.
This mixin is designed to be used as a superclass of another widget.
"""
# FIXME: this is so common, let's add proper support for it
# when layout and rendering are separated
get_delegate = attrgetter(attribute_name)
class DelegateToWidgetMixin(Widget):
no_cache = ["rows"] # crufty metaclass work-around
def render(self, size, focus=False):
canv = get_delegate(self).render(size, focus=focus)
return CompositeCanvas(canv)
selectable = property(lambda self:get_delegate(self).selectable)
get_cursor_coords = property(
lambda self:get_delegate(self).get_cursor_coords)
get_pref_col = property(lambda self:get_delegate(self).get_pref_col)
keypress = property(lambda self:get_delegate(self).keypress)
move_cursor_to_coords = property(
lambda self:get_delegate(self).move_cursor_to_coords)
rows = property(lambda self:get_delegate(self).rows)
mouse_event = property(lambda self:get_delegate(self).mouse_event)
sizing = property(lambda self:get_delegate(self).sizing)
pack = property(lambda self:get_delegate(self).pack)
return DelegateToWidgetMixin
class WidgetWrapError(Exception):
pass
class WidgetWrap(delegate_to_widget_mixin('_wrapped_widget'), Widget):
def __init__(self, w):
"""
w -- widget to wrap, stored as self._w
This object will pass the functions defined in Widget interface
definition to self._w.
The purpose of this widget is to provide a base class for
widgets that compose other widgets for their display and
behaviour. The details of that composition should not affect
users of the subclass. The subclass may decide to expose some
of the wrapped widgets by behaving like a ContainerWidget or
WidgetDecoration, or it may hide them from outside access.
"""
self._wrapped_widget = w
def _set_w(self, w):
"""
Change the wrapped widget. This is meant to be called
only by subclasses.
>>> size = (10,)
>>> ww = WidgetWrap(Edit("hello? ","hi"))
>>> ww.render(size).text # ... = b in Python 3
[...'hello? hi ']
>>> ww.selectable()
True
>>> ww._w = Text("goodbye") # calls _set_w()
>>> ww.render(size).text
[...'goodbye ']
>>> ww.selectable()
False
"""
self._wrapped_widget = w
self._invalidate()
_w = property(lambda self:self._wrapped_widget, _set_w)
def _raise_old_name_error(self, val=None):
raise WidgetWrapError("The WidgetWrap.w member variable has "
"been renamed to WidgetWrap._w (not intended for use "
"outside the class and its subclasses). "
"Please update your code to use self._w "
"instead of self.w.")
w = property(_raise_old_name_error, _raise_old_name_error)
def _test():
import doctest
doctest.testmod()
if __name__=='__main__':
_test()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
738,
13057,
344,
5678,
3938,
3992,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
221,
473,
290,
644,
1005,
199,
3,
199,
3,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
259,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
3555,
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,
1664,
199,
3,
259,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
3,
738,
13057,
344,
3330,
4770,
26,
1455,
921,
476,
670,
14,
1308,
15,
300,
19686,
15,
199,
199,
504,
4182,
492,
21829,
199,
199,
504,
7629,
19686,
14,
1974,
492,
334,
3396,
11823,
12,
477,
12607,
63,
1450,
10131,
12,
12831,
63,
2063,
12,
272,
365,
63,
13062,
63,
1560,
12,
4057,
63,
5701,
63,
1560,
12,
4057,
63,
2184,
63,
1560,
9,
199,
504,
7629,
19686,
14,
505,
63,
4209,
492,
12831,
63,
1712,
12,
12831,
63,
8032,
12,
7706,
63,
604,
199,
504,
7629,
19686,
492,
10166,
199,
504,
7629,
19686,
492,
1318,
63,
4209,
199,
504,
7629,
19686,
14,
7682,
492,
334,
15174,
4437,
12,
27506,
2124,
15174,
12,
2002,
7401,
15174,
12,
272,
4838,
63,
505,
63,
4209,
9,
199,
504,
7629,
19686,
14,
1531,
63,
1130,
492,
334,
1531,
63,
1130,
12,
18715,
26508,
63,
9894,
12,
18715,
26508,
63,
12811,
12,
272,
18715,
26508,
63,
2160,
12,
18715,
26508,
63,
8819,
12,
18715,
26508,
63,
4283,
63,
9894,
12,
18715,
26508,
63,
4283,
63,
12811,
9,
199,
504,
7629,
19686,
14,
1294,
63,
2722,
492,
3715,
63,
2722,
12,
2813,
63,
4322,
12,
2366,
19,
63,
2722,
421,
199,
3,
5627,
2005,
1561,
367,
3520,
5262,
370,
5126,
3201,
32252,
780,
315,
314,
1350,
199,
3,
436,
370,
2213,
314,
4413,
3326,
781,
787,
1808,
199,
199,
3,
16905,
308,
9147,
3102,
199,
199,
17114,
275,
283,
1659,
7,
199,
15694,
275,
283,
1977,
7,
199,
23837,
275,
283,
5964,
7,
199,
199,
3,
4516,
13177,
12404,
199,
9894,
275,
283,
3039,
7,
199,
12811,
275,
283,
1019,
7,
199,
17611,
275,
283,
4218,
7,
199,
199,
3,
17887,
1435,
13177,
199,
11422,
275,
283,
2119,
7,
199,
45,
13016,
275,
283,
14885,
7,
199,
27838,
275,
283,
8305,
7,
199,
199,
3,
4516,
19696,
12404,
199,
11658,
275,
283,
2638,
7,
199,
8974,
275,
283,
1629,
7,
199,
1981,
1772,
275,
283,
7548,
7,
199,
199,
3,
644,
1466,
436,
5311,
1070,
2202,
199,
6961,
275,
283,
1389,
7,
199,
39,
6882,
742,
275,
283,
11809,
7,
199,
13604,
14277,
275,
283,
6188,
7,
199,
13604,
14277,
63,
1960,
275,
334,
13604,
14277,
12,
2948,
9,
199,
25100,
275,
283,
3463,
7,
421,
199,
533,
16905,
3396,
8,
3396,
11823,
12,
10166,
14,
3396,
28536,
304,
272,
408,
272,
699,
3274,
26,
520,
533,
1705,
3396,
11823,
3559,
520,
533,
1705,
3396,
28536,
64,
339,
9195,
3889,
13627,
402,
3795,
436,
4730,
3102,
14,
339,
8089,
1750,
627,
889,
63,
1637,
10,
365,
282,
769,
402,
1561,
402,
3102,
370,
440,
2581,
272,
5847,
14,
221,
4821,
1083,
1561,
367,
627,
889,
63,
1637,
10,
787,
12692,
3352,
14700,
436,
272,
12692,
3838,
26809,
339,
8089,
1750,
627,
4247,
63,
12283,
10,
340,
3247,
436,
663,
370,
1124,
549,
1040,
9126,
272,
626,
314,
10218,
642,
3938,
3795,
83,
365,
440,
16955,
701,
314,
16470,
272,
2725,
12,
880,
652,
1443,
506,
5525,
1380,
13627,
14,
272,
408,
272,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
366,
304,
267,
949,
63,
1637,
275,
366,
14,
362,
480,
889,
63,
1637,
401,
3073,
398,
1613,
8,
3339,
3396,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
366,
9,
398,
340,
298,
3352,
2,
315,
366,
26,
288,
340,
298,
3352,
2,
440,
315,
949,
63,
1637,
26,
355,
3795,
63,
2324,
275,
2581,
63,
3440,
63,
3352,
8,
1886,
9,
288,
587,
26,
355,
3795,
63,
2324,
275,
302,
679,
21481,
63,
3440,
63,
3352,
8,
1886,
9,
288,
843,
14,
3352,
275,
3795,
63,
2324,
398,
340,
298,
3838,
2,
315,
366,
436,
298,
3838,
2,
440,
315,
949,
63,
1637,
26,
288,
843,
14,
3838,
275,
2581,
63,
3440,
63,
3838,
8,
1886,
9,
267,
340,
298,
889,
63,
1637,
2,
315,
366,
26,
288,
2150,
843,
14,
889,
63,
1637,
267,
340,
298,
4247,
63,
12283,
2,
315,
366,
26,
288,
2150,
843,
14,
4247,
63,
12283,
199,
199,
533,
16905,
547,
8,
1726,
304,
272,
986,
199,
199,
318,
4107,
63,
890,
8,
3440,
12,
1568,
12,
883,
86,
304,
272,
408,
272,
14771,
282,
16905,
547,
340,
282,
883,
86,
1630,
440,
1336,
1568,
1568,
14,
272,
408,
272,
340,
334,
890,
436,
1568,
59,
17,
2938,
1137,
334,
16,
4258,
436,
1568,
59,
16,
61,
1137,
883,
86,
14,
4574,
1012,
503,
971,
267,
334,
552,
8,
890,
13032,
17,
436,
1568,
59,
17,
61,
1137,
883,
86,
14,
3838,
5109,
267,
746,
16905,
547,
480,
3339,
450,
82,
8018,
4366,
68,
671,
450,
68,
9,
10218,
2,
288,
298,
1380,
3032,
1568,
450,
82,
9539,
450,
334,
3440,
12,
883,
86,
14,
4574,
1062,
288,
883,
86,
14,
3838,
1062,
1568,
430,
199,
199,
318,
1678,
63,
5029,
8,
1222,
63,
2324,
12,
4325,
304,
272,
408,
272,
11247,
465,
8298
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
738,
13057,
344,
5678,
3938,
3992,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
221,
473,
290,
644,
1005,
199,
3,
199,
3,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
259,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
3555,
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,
1664,
199,
3,
259,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
3,
738,
13057,
344,
3330,
4770,
26,
1455,
921,
476,
670,
14,
1308,
15,
300,
19686,
15,
199,
199,
504,
4182,
492,
21829,
199,
199,
504,
7629,
19686,
14,
1974,
492,
334,
3396,
11823,
12,
477,
12607,
63,
1450,
10131,
12,
12831,
63,
2063,
12,
272,
365,
63,
13062,
63,
1560,
12,
4057,
63,
5701,
63,
1560,
12,
4057,
63,
2184,
63,
1560,
9,
199,
504,
7629,
19686,
14,
505,
63,
4209,
492,
12831,
63,
1712,
12,
12831,
63,
8032,
12,
7706,
63,
604,
199,
504,
7629,
19686,
492,
10166,
199,
504,
7629,
19686,
492,
1318,
63,
4209,
199,
504,
7629,
19686,
14,
7682,
492,
334,
15174,
4437,
12,
27506,
2124,
15174,
12,
2002,
7401,
15174,
12,
272,
4838,
63,
505,
63,
4209,
9,
199,
504,
7629,
19686,
14,
1531,
63,
1130,
492,
334,
1531,
63,
1130,
12,
18715,
26508,
63,
9894,
12,
18715,
26508,
63,
12811,
12,
272,
18715,
26508,
63,
2160,
12,
18715,
26508,
63,
8819,
12,
18715,
26508,
63,
4283,
63,
9894,
12,
18715,
26508,
63,
4283,
63,
12811,
9,
199,
504,
7629,
19686,
14,
1294,
63,
2722,
492,
3715,
63,
2722,
12,
2813,
63,
4322,
12,
2366,
19,
63,
2722,
421,
199,
3,
5627,
2005,
1561,
367,
3520,
5262,
370,
5126,
3201,
32252,
780,
315,
314,
1350,
199,
3,
436,
370,
2213,
314,
4413,
3326,
781,
787,
1808,
199,
199,
3,
16905,
308,
9147,
3102,
199,
199,
17114,
275,
283,
1659,
7,
199,
15694,
275,
283,
1977,
7,
199,
23837,
275,
283,
5964,
7,
199,
199,
3,
4516,
13177,
12404,
199,
9894,
275,
283,
3039,
7,
199,
12811,
275,
283,
1019,
7,
199,
17611,
275,
283,
4218,
7,
199,
199,
3,
17887,
1435,
13177,
199,
11422,
275,
283,
2119,
7,
199,
45,
13016,
275,
283,
14885,
7,
199,
27838,
275,
283,
8305,
7,
199,
199,
3,
4516,
19696,
12404,
199,
11658,
275,
283,
2638,
7,
199,
8974,
275,
283,
1629,
7,
199,
1981,
1772,
275,
283,
7548,
7,
199,
199,
3,
644,
1466,
436,
5311,
1070,
2202,
199,
6961,
275,
283,
1389,
7,
199,
39,
6882,
742,
275,
283,
11809,
7,
199,
13604,
14277,
275,
283,
6188,
7,
199,
13604,
14277,
63,
1960,
275,
334,
13604,
14277,
12,
2948,
9,
199,
25100,
275,
283,
3463,
7,
421,
199,
533,
16905,
3396,
8,
3396,
11823,
12,
10166,
14,
3396,
28536,
304,
272,
408,
272,
699,
3274,
26,
520,
533,
1705,
3396,
11823,
3559,
520,
533,
1705,
3396,
28536,
64,
339,
9195,
3889,
13627,
402,
3795,
436,
4730,
3102,
14,
339,
8089,
1750,
627,
889,
63,
1637,
10,
365,
282,
769,
402,
1561,
402,
3102,
370,
440,
2581,
272,
5847,
14,
221,
4821,
1083,
1561,
367,
627,
889,
63,
1637,
10,
787,
12692,
3352,
14700,
436,
272,
12692,
3838,
26809,
339,
8089,
1750,
627,
4247,
63,
12283,
10,
340,
3247,
436,
663,
370,
1124,
549,
1040,
9126,
272,
626,
314,
10218,
642,
3938,
3795,
83,
365,
440,
16955,
701,
314,
16470,
272,
2725,
12,
880,
652,
1443,
506,
5525,
1380,
13627,
14,
272,
408,
272,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
366,
304,
267,
949,
63,
1637,
275,
366,
14,
362,
480,
889,
63,
1637,
401,
3073,
398,
1613,
8,
3339,
3396,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
366,
9,
398,
340,
298,
3352,
2,
315,
366,
26,
288,
340,
298,
3352,
2,
440,
315,
949,
63,
1637,
26,
355,
3795,
63,
2324,
275,
2581,
63,
3440,
63,
3352,
8,
1886,
9,
288,
587,
26,
355,
3795,
63,
2324,
275,
302,
679,
21481,
63,
3440,
63,
3352,
8,
1886,
9,
288,
843,
14,
3352,
275,
3795,
63,
2324,
398,
340,
298,
3838,
2,
315,
366,
436,
298,
3838,
2,
440,
315,
949,
63,
1637,
26,
288,
843,
14,
3838,
275,
2581,
63,
3440,
63,
3838,
8,
1886,
9,
267,
340,
298,
889,
63,
1637,
2,
315,
366,
26,
288,
2150,
843,
14,
889,
63,
1637,
267,
340,
298,
4247,
63,
12283,
2,
315,
366,
26,
288,
2150,
843,
14,
4247,
63,
12283,
199,
199,
533,
16905,
547,
8,
1726,
304,
272,
986,
199,
199,
318,
4107,
63,
890,
8,
3440,
12,
1568,
12,
883,
86,
304,
272,
408,
272,
14771,
282,
16905,
547,
340,
282,
883,
86,
1630,
440,
1336,
1568,
1568,
14,
272,
408,
272,
340,
334,
890,
436,
1568,
59,
17,
2938,
1137,
334,
16,
4258,
436,
1568,
59,
16,
61,
1137,
883,
86,
14,
4574,
1012,
503,
971,
267,
334,
552,
8,
890,
13032,
17,
436,
1568,
59,
17,
61,
1137,
883,
86,
14,
3838,
5109,
267,
746,
16905,
547,
480,
3339,
450,
82,
8018,
4366,
68,
671,
450,
68,
9,
10218,
2,
288,
298,
1380,
3032,
1568,
450,
82,
9539,
450,
334,
3440,
12,
883,
86,
14,
4574,
1062,
288,
883,
86,
14,
3838,
1062,
1568,
430,
199,
199,
318,
1678,
63,
5029,
8,
1222,
63,
2324,
12,
4325,
304,
272,
408,
272,
11247,
465,
8298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jfpla/odoo
|
addons/project_timesheet/__openerp__.py
|
260
|
2151
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Bill Time on Tasks',
'version': '1.0',
'category': 'Project Management',
'description': """
Synchronization of project task work entries with timesheet entries.
====================================================================
This module lets you transfer the entries under tasks defined for Project
Management to the Timesheet line entries for particular date and particular user
with the effect of creating, editing and deleting either ways.
""",
'author': 'OpenERP SA',
'website': 'https://www.odoo.com/page/project-management',
'depends': ['resource', 'project', 'hr_timesheet_sheet', 'hr_timesheet_invoice', 'account_analytic_analysis', 'procurement'],
'data': [
'security/ir.model.access.csv',
'security/project_timesheet_security.xml',
'report/task_report_view.xml',
'project_timesheet_view.xml',
],
'demo': ['project_timesheet_demo.xml'],
'test': [
'test/worktask_entry_to_timesheetline_entry.yml',
'test/work_timesheet.yml',
],
'installable': True,
'auto_install': True,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
356,
283,
34,
778,
4703,
641,
8495,
83,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
4761,
8259,
297,
272,
283,
1802,
356,
408,
199,
21814,
2072,
402,
2199,
2120,
1736,
4811,
543,
900,
5069,
4811,
14,
199,
5695,
532,
199,
199,
2765,
859,
19083,
1265,
9307,
314,
4811,
1334,
6527,
3247,
367,
7290,
199,
14552,
370,
314,
4703,
5069,
1004,
4811,
367,
6770,
1434,
436,
6770,
922,
199,
1045,
314,
7763,
402,
6425,
12,
20401,
436,
13794,
1902,
15217,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
1715,
13,
8110,
297,
272,
283,
8912,
356,
788,
1927,
297,
283,
1715,
297,
283,
6271,
63,
17739,
63,
5069,
297,
283,
6271,
63,
17739,
63,
5404,
297,
283,
2048,
63,
9782,
63,
10466,
297,
283,
18546,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
4416,
15,
1715,
63,
17739,
63,
4416,
14,
1652,
297,
267,
283,
3070,
15,
1765,
63,
3070,
63,
1345,
14,
1652,
297,
267,
283,
1715,
63,
17739,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
788,
1715,
63,
17739,
63,
8768,
14,
1652,
995,
272,
283,
396,
356,
359,
267,
283,
396,
15,
800,
1765,
63,
2373,
63,
475,
63,
17739,
604,
63,
2373,
14,
11714,
297,
267,
283,
396,
15,
800,
63,
17739,
14,
11714,
297,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
715,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
356,
283,
34,
778,
4703,
641,
8495,
83,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
4761,
8259,
297,
272,
283,
1802,
356,
408,
199,
21814,
2072,
402,
2199,
2120,
1736,
4811,
543,
900,
5069,
4811,
14,
199,
5695,
532,
199,
199,
2765,
859,
19083,
1265,
9307,
314,
4811,
1334,
6527,
3247,
367,
7290,
199,
14552,
370,
314,
4703,
5069,
1004,
4811,
367,
6770,
1434,
436,
6770,
922,
199,
1045,
314,
7763,
402,
6425,
12,
20401,
436,
13794,
1902,
15217,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
1715,
13,
8110,
297,
272,
283,
8912,
356,
788,
1927,
297,
283,
1715,
297,
283,
6271,
63,
17739,
63,
5069,
297,
283,
6271,
63,
17739,
63,
5404,
297,
283,
2048,
63,
9782,
63,
10466,
297,
283,
18546,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
4416,
15,
1715,
63,
17739,
63,
4416,
14,
1652,
297,
267,
283,
3070,
15,
1765,
63,
3070,
63,
1345,
14,
1652,
297,
267,
283,
1715,
63,
17739,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
788,
1715,
63,
17739,
63,
8768,
14,
1652,
995,
272,
283,
396,
356,
359,
267,
283,
396,
15,
800,
1765,
63,
2373,
63,
475,
63,
17739,
604,
63,
2373,
14,
11714,
297,
267,
283,
396,
15,
800,
63,
17739,
14,
11714,
297,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
715,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
"""
Benchmark for approximate nearest neighbor search using
locality sensitive hashing forest.
There are two types of benchmarks.
First, accuracy of LSHForest queries are measured for various
hyper-parameters and index sizes.
Second, speed up of LSHForest queries compared to brute force
method in exact nearest neighbors is measures for the
aforementioned settings. In general, speed up is increasing as
the index size grows.
"""
from __future__ import division
import numpy as np
from tempfile import gettempdir
from time import time
from sklearn.neighbors import NearestNeighbors
from sklearn.neighbors.approximate import LSHForest
from sklearn.datasets import make_blobs
from sklearn.externals.joblib import Memory
m = Memory(cachedir=gettempdir())
@m.cache()
def make_data(n_samples, n_features, n_queries, random_state=0):
"""Create index and query data."""
print('Generating random blob-ish data')
X, _ = make_blobs(n_samples=n_samples + n_queries,
n_features=n_features, centers=100,
shuffle=True, random_state=random_state)
# Keep the last samples as held out query vectors: note since we used
# shuffle=True we have ensured that index and query vectors are
# samples from the same distribution (a mixture of 100 gaussians in this
# case)
return X[:n_samples], X[n_samples:]
def calc_exact_neighbors(X, queries, n_queries, n_neighbors):
"""Measures average times for exact neighbor queries."""
print ('Building NearestNeighbors for %d samples in %d dimensions' %
(X.shape[0], X.shape[1]))
nbrs = NearestNeighbors(algorithm='brute', metric='cosine').fit(X)
average_time = 0
t0 = time()
neighbors = nbrs.kneighbors(queries, n_neighbors=n_neighbors,
return_distance=False)
average_time = (time() - t0) / n_queries
return neighbors, average_time
def calc_accuracy(X, queries, n_queries, n_neighbors, exact_neighbors,
average_time_exact, **lshf_params):
"""Calculates accuracy and the speed up of LSHForest."""
print('Building LSHForest for %d samples in %d dimensions' %
(X.shape[0], X.shape[1]))
lshf = LSHForest(**lshf_params)
t0 = time()
lshf.fit(X)
lshf_build_time = time() - t0
print('Done in %0.3fs' % lshf_build_time)
accuracy = 0
t0 = time()
approx_neighbors = lshf.kneighbors(queries, n_neighbors=n_neighbors,
return_distance=False)
average_time_approx = (time() - t0) / n_queries
for i in range(len(queries)):
accuracy += np.in1d(approx_neighbors[i], exact_neighbors[i]).mean()
accuracy /= n_queries
speed_up = average_time_exact / average_time_approx
print('Average time for lshf neighbor queries: %0.3fs' %
average_time_approx)
print ('Average time for exact neighbor queries: %0.3fs' %
average_time_exact)
print ('Average Accuracy : %0.2f' % accuracy)
print ('Speed up: %0.1fx' % speed_up)
return speed_up, accuracy
if __name__ == '__main__':
import matplotlib.pyplot as plt
# Initialize index sizes
n_samples = [int(1e3), int(1e4), int(1e5), int(1e6)]
n_features = int(1e2)
n_queries = 100
n_neighbors = 10
X_index, X_query = make_data(np.max(n_samples), n_features, n_queries,
random_state=0)
params_list = [{'n_estimators': 3, 'n_candidates': 50},
{'n_estimators': 5, 'n_candidates': 70},
{'n_estimators': 10, 'n_candidates': 100}]
accuracies = np.zeros((len(n_samples), len(params_list)), dtype=float)
speed_ups = np.zeros((len(n_samples), len(params_list)), dtype=float)
for i, sample_size in enumerate(n_samples):
print ('==========================================================')
print ('Sample size: %i' % sample_size)
print ('------------------------')
exact_neighbors, average_time_exact = calc_exact_neighbors(
X_index[:sample_size], X_query, n_queries, n_neighbors)
for j, params in enumerate(params_list):
print ('LSHF parameters: n_estimators = %i, n_candidates = %i' %
(params['n_estimators'], params['n_candidates']))
speed_ups[i, j], accuracies[i, j] = calc_accuracy(
X_index[:sample_size], X_query, n_queries, n_neighbors,
exact_neighbors, average_time_exact, random_state=0, **params)
print ('')
print ('==========================================================')
# Set labels for LSHForest parameters
colors = ['c', 'm', 'y']
legend_rects = [plt.Rectangle((0, 0), 0.1, 0.1, fc=color)
for color in colors]
legend_labels = ['n_estimators={n_estimators}, '
'n_candidates={n_candidates}'.format(**p)
for p in params_list]
# Plot precision
plt.figure()
plt.legend(legend_rects, legend_labels,
loc='upper left')
for i in range(len(params_list)):
plt.scatter(n_samples, accuracies[:, i], c=colors[i])
plt.plot(n_samples, accuracies[:, i], c=colors[i])
plt.ylim([0, 1.3])
plt.xlim(np.min(n_samples), np.max(n_samples))
plt.semilogx()
plt.ylabel("Precision@10")
plt.xlabel("Index size")
plt.grid(which='both')
plt.title("Precision of first 10 neighbors with index size")
# Plot speed up
plt.figure()
plt.legend(legend_rects, legend_labels,
loc='upper left')
for i in range(len(params_list)):
plt.scatter(n_samples, speed_ups[:, i], c=colors[i])
plt.plot(n_samples, speed_ups[:, i], c=colors[i])
plt.ylim(0, np.max(speed_ups))
plt.xlim(np.min(n_samples), np.max(n_samples))
plt.semilogx()
plt.ylabel("Speed up")
plt.xlabel("Index size")
plt.grid(which='both')
plt.title("Relationship between Speed up and index size")
plt.show()
|
bsd-3-clause
|
[
624,
199,
18644,
367,
19917,
17173,
15503,
2754,
1808,
199,
1832,
1209,
18423,
25223,
27882,
14,
199,
199,
10924,
787,
2877,
2943,
402,
12338,
83,
14,
199,
199,
7147,
12,
12862,
402,
491,
3234,
21668,
9212,
787,
27396,
367,
7750,
199,
9547,
13,
3214,
436,
1478,
10627,
14,
199,
199,
11906,
12,
8112,
1536,
402,
491,
3234,
21668,
9212,
13524,
370,
11665,
938,
3542,
199,
765,
315,
5835,
17173,
15845,
365,
17616,
1482,
367,
314,
199,
65,
1707,
32016,
379,
2202,
14,
1010,
8605,
12,
8112,
1536,
365,
22255,
465,
199,
1589,
1478,
1568,
486,
3838,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
504,
5549,
492,
664,
11567,
199,
504,
900,
492,
900,
199,
199,
504,
6357,
14,
11113,
492,
5612,
9540,
20011,
199,
504,
6357,
14,
11113,
14,
16815,
6897,
492,
491,
3234,
21668,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
24688,
14,
2423,
773,
492,
15825,
199,
199,
77,
275,
15825,
8,
1637,
694,
29,
31572,
1012,
421,
199,
32,
77,
14,
1637,
342,
199,
318,
1852,
63,
576,
8,
78,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
10590,
12,
2196,
63,
929,
29,
16,
304,
272,
408,
2499,
1478,
436,
1827,
666,
1041,
272,
870,
360,
29244,
2196,
9182,
13,
2453,
666,
358,
272,
1323,
12,
485,
275,
1852,
63,
21893,
8,
78,
63,
3356,
29,
78,
63,
3356,
435,
302,
63,
10590,
12,
1993,
302,
63,
3179,
29,
78,
63,
3179,
12,
19190,
29,
1960,
12,
1993,
13031,
29,
549,
12,
2196,
63,
929,
29,
2355,
63,
929,
9,
339,
327,
14797,
314,
2061,
5845,
465,
23608,
734,
1827,
11102,
26,
5317,
3967,
781,
1202,
272,
327,
13031,
29,
549,
781,
1172,
12889,
3297,
626,
1478,
436,
1827,
11102,
787,
272,
327,
5845,
687,
314,
2011,
4084,
334,
65,
31885,
402,
2948,
16072,
17759,
796,
315,
642,
272,
327,
1930,
9,
272,
372,
1323,
1491,
78,
63,
3356,
467,
1323,
59,
78,
63,
3356,
2938,
421,
199,
318,
12831,
63,
7327,
63,
11113,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
304,
272,
408,
1352,
305,
1482,
8095,
5431,
367,
5835,
15503,
9212,
1041,
272,
870,
661,
16461,
5612,
9540,
20011,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
1779,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
8526,
2393,
275,
5612,
9540,
20011,
8,
8833,
534,
3289,
938,
297,
6370,
534,
28485,
1959,
3269,
8,
56,
9,
272,
8095,
63,
521,
275,
378,
339,
307,
16,
275,
900,
342,
272,
15845,
275,
8526,
2393,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
1816,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
272,
372,
15845,
12,
8095,
63,
521,
421,
199,
318,
12831,
63,
13374,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
12,
5835,
63,
11113,
12,
2116,
8095,
63,
521,
63,
7327,
12,
1011,
478,
9188,
63,
1162,
304,
272,
408,
13862,
2335,
12862,
436,
314,
8112,
1536,
402,
491,
3234,
21668,
1041,
272,
870,
360,
16461,
491,
3234,
21668,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
881,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
9100,
9188,
275,
491,
3234,
21668,
3682,
478,
9188,
63,
1162,
9,
272,
307,
16,
275,
900,
342,
272,
9100,
9188,
14,
3269,
8,
56,
9,
272,
9100,
9188,
63,
1506,
63,
521,
275,
900,
342,
446,
307,
16,
272,
870,
360,
10759,
315,
450,
16,
14,
19,
2319,
7,
450,
9100,
9188,
63,
1506,
63,
521,
9,
339,
12862,
275,
378,
339,
307,
16,
275,
900,
342,
272,
14106,
63,
11113,
275,
9100,
9188,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
4318,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
63,
16815,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
339,
367,
284,
315,
1425,
8,
552,
8,
10590,
2298,
267,
12862,
847,
980,
14,
262,
17,
68,
8,
16815,
63,
11113,
59,
73,
467,
5835,
63,
11113,
59,
73,
6575,
3670,
342,
339,
12862,
12257,
302,
63,
10590,
272,
8112,
63,
384,
275,
8095,
63,
521,
63,
7327,
1182,
8095,
63,
521,
63,
16815,
339,
870,
360,
17400,
900,
367,
9100,
9188,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
881,
8095,
63,
521,
63,
16815,
9,
272,
870,
661,
17400,
900,
367,
5835,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
1779,
8095,
63,
521,
63,
7327,
9,
272,
870,
661,
17400,
4473,
7933,
520,
450,
16,
14,
18,
70,
7,
450,
12862,
9,
272,
870,
661,
15146,
1536,
26,
450,
16,
14,
17,
12220,
7,
450,
8112,
63,
384,
9,
339,
372,
8112,
63,
384,
12,
12862,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
8027,
14,
13563,
465,
4488,
272,
327,
11578,
1478,
10627,
272,
302,
63,
3356,
275,
359,
442,
8,
17,
69,
19,
395,
1109,
8,
17,
69,
20,
395,
1109,
8,
17,
69,
21,
395,
1109,
8,
17,
69,
22,
1874,
272,
302,
63,
3179,
275,
1109,
8,
17,
69,
18,
9,
272,
302,
63,
10590,
275,
2948,
272,
302,
63,
11113,
275,
1616,
339,
1323,
63,
1080,
12,
1323,
63,
1131,
275,
1852,
63,
576,
8,
1590,
14,
988,
8,
78,
63,
3356,
395,
302,
63,
3179,
12,
302,
63,
10590,
12,
639,
2196,
63,
929,
29,
16,
9,
339,
1862,
63,
513,
275,
9016,
78,
63,
10646,
356,
650,
12,
283,
78,
63,
16389,
356,
5238,
1386,
673,
791,
78,
63,
10646,
356,
959,
12,
283,
78,
63,
16389,
356,
10045,
1386,
673,
791,
78,
63,
10646,
356,
1616,
12,
283,
78,
63,
16389,
356,
2948,
11049,
339,
1066,
895,
65,
2578,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356,
395,
822,
8,
1162,
63,
513,
1826,
2152,
29,
1609,
9,
272,
8112,
63,
15203,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356
] |
[
199,
18644,
367,
19917,
17173,
15503,
2754,
1808,
199,
1832,
1209,
18423,
25223,
27882,
14,
199,
199,
10924,
787,
2877,
2943,
402,
12338,
83,
14,
199,
199,
7147,
12,
12862,
402,
491,
3234,
21668,
9212,
787,
27396,
367,
7750,
199,
9547,
13,
3214,
436,
1478,
10627,
14,
199,
199,
11906,
12,
8112,
1536,
402,
491,
3234,
21668,
9212,
13524,
370,
11665,
938,
3542,
199,
765,
315,
5835,
17173,
15845,
365,
17616,
1482,
367,
314,
199,
65,
1707,
32016,
379,
2202,
14,
1010,
8605,
12,
8112,
1536,
365,
22255,
465,
199,
1589,
1478,
1568,
486,
3838,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
504,
5549,
492,
664,
11567,
199,
504,
900,
492,
900,
199,
199,
504,
6357,
14,
11113,
492,
5612,
9540,
20011,
199,
504,
6357,
14,
11113,
14,
16815,
6897,
492,
491,
3234,
21668,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
24688,
14,
2423,
773,
492,
15825,
199,
199,
77,
275,
15825,
8,
1637,
694,
29,
31572,
1012,
421,
199,
32,
77,
14,
1637,
342,
199,
318,
1852,
63,
576,
8,
78,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
10590,
12,
2196,
63,
929,
29,
16,
304,
272,
408,
2499,
1478,
436,
1827,
666,
1041,
272,
870,
360,
29244,
2196,
9182,
13,
2453,
666,
358,
272,
1323,
12,
485,
275,
1852,
63,
21893,
8,
78,
63,
3356,
29,
78,
63,
3356,
435,
302,
63,
10590,
12,
1993,
302,
63,
3179,
29,
78,
63,
3179,
12,
19190,
29,
1960,
12,
1993,
13031,
29,
549,
12,
2196,
63,
929,
29,
2355,
63,
929,
9,
339,
327,
14797,
314,
2061,
5845,
465,
23608,
734,
1827,
11102,
26,
5317,
3967,
781,
1202,
272,
327,
13031,
29,
549,
781,
1172,
12889,
3297,
626,
1478,
436,
1827,
11102,
787,
272,
327,
5845,
687,
314,
2011,
4084,
334,
65,
31885,
402,
2948,
16072,
17759,
796,
315,
642,
272,
327,
1930,
9,
272,
372,
1323,
1491,
78,
63,
3356,
467,
1323,
59,
78,
63,
3356,
2938,
421,
199,
318,
12831,
63,
7327,
63,
11113,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
304,
272,
408,
1352,
305,
1482,
8095,
5431,
367,
5835,
15503,
9212,
1041,
272,
870,
661,
16461,
5612,
9540,
20011,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
1779,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
8526,
2393,
275,
5612,
9540,
20011,
8,
8833,
534,
3289,
938,
297,
6370,
534,
28485,
1959,
3269,
8,
56,
9,
272,
8095,
63,
521,
275,
378,
339,
307,
16,
275,
900,
342,
272,
15845,
275,
8526,
2393,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
1816,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
272,
372,
15845,
12,
8095,
63,
521,
421,
199,
318,
12831,
63,
13374,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
12,
5835,
63,
11113,
12,
2116,
8095,
63,
521,
63,
7327,
12,
1011,
478,
9188,
63,
1162,
304,
272,
408,
13862,
2335,
12862,
436,
314,
8112,
1536,
402,
491,
3234,
21668,
1041,
272,
870,
360,
16461,
491,
3234,
21668,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
881,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
9100,
9188,
275,
491,
3234,
21668,
3682,
478,
9188,
63,
1162,
9,
272,
307,
16,
275,
900,
342,
272,
9100,
9188,
14,
3269,
8,
56,
9,
272,
9100,
9188,
63,
1506,
63,
521,
275,
900,
342,
446,
307,
16,
272,
870,
360,
10759,
315,
450,
16,
14,
19,
2319,
7,
450,
9100,
9188,
63,
1506,
63,
521,
9,
339,
12862,
275,
378,
339,
307,
16,
275,
900,
342,
272,
14106,
63,
11113,
275,
9100,
9188,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
4318,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
63,
16815,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
339,
367,
284,
315,
1425,
8,
552,
8,
10590,
2298,
267,
12862,
847,
980,
14,
262,
17,
68,
8,
16815,
63,
11113,
59,
73,
467,
5835,
63,
11113,
59,
73,
6575,
3670,
342,
339,
12862,
12257,
302,
63,
10590,
272,
8112,
63,
384,
275,
8095,
63,
521,
63,
7327,
1182,
8095,
63,
521,
63,
16815,
339,
870,
360,
17400,
900,
367,
9100,
9188,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
881,
8095,
63,
521,
63,
16815,
9,
272,
870,
661,
17400,
900,
367,
5835,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
1779,
8095,
63,
521,
63,
7327,
9,
272,
870,
661,
17400,
4473,
7933,
520,
450,
16,
14,
18,
70,
7,
450,
12862,
9,
272,
870,
661,
15146,
1536,
26,
450,
16,
14,
17,
12220,
7,
450,
8112,
63,
384,
9,
339,
372,
8112,
63,
384,
12,
12862,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
8027,
14,
13563,
465,
4488,
272,
327,
11578,
1478,
10627,
272,
302,
63,
3356,
275,
359,
442,
8,
17,
69,
19,
395,
1109,
8,
17,
69,
20,
395,
1109,
8,
17,
69,
21,
395,
1109,
8,
17,
69,
22,
1874,
272,
302,
63,
3179,
275,
1109,
8,
17,
69,
18,
9,
272,
302,
63,
10590,
275,
2948,
272,
302,
63,
11113,
275,
1616,
339,
1323,
63,
1080,
12,
1323,
63,
1131,
275,
1852,
63,
576,
8,
1590,
14,
988,
8,
78,
63,
3356,
395,
302,
63,
3179,
12,
302,
63,
10590,
12,
639,
2196,
63,
929,
29,
16,
9,
339,
1862,
63,
513,
275,
9016,
78,
63,
10646,
356,
650,
12,
283,
78,
63,
16389,
356,
5238,
1386,
673,
791,
78,
63,
10646,
356,
959,
12,
283,
78,
63,
16389,
356,
10045,
1386,
673,
791,
78,
63,
10646,
356,
1616,
12,
283,
78,
63,
16389,
356,
2948,
11049,
339,
1066,
895,
65,
2578,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356,
395,
822,
8,
1162,
63,
513,
1826,
2152,
29,
1609,
9,
272,
8112,
63,
15203,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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_tv.py
|
30
|
7086
|
# -*- coding: utf-8 -*-
'''
Specto Add-on
Copyright (C) 2015 lambda
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import os,re,urllib,urlparse,json,zipfile,StringIO,datetime,base64
try:
from sqlite3 import dbapi2 as database
except:
from pysqlite2 import dbapi2 as database
from resources.lib.libraries import control
from resources.lib.libraries import cleantitle
from resources.lib.libraries import client
class source:
def __init__(self):
self.base_link = 'http://movietv.to'
self.data_link = 'aHR0cHM6Ly9vZmZzaG9yZWdpdC5jb20vbGFtYmRhODEvZGF0YWJhc2VzL21vdmlldHYyLnppcA=='
self.extra_link = 'aHR0cDovL2p1c3RwYXN0ZS5pdC9vYzVj'
def get_movie(self, imdb, title, year):
try:
data = os.path.join(control.dataPath, 'movietv.db')
try: control.deleteFile(data)
except: pass
data = os.path.join(control.dataPath, 'movietv2.db')
download = True
try: download = abs(datetime.datetime.fromtimestamp(os.path.getmtime(data)) - (datetime.datetime.now())) > datetime.timedelta(days=7)
except: pass
if download == True:
result = client.source(base64.b64decode(self.data_link))
zip = zipfile.ZipFile(StringIO.StringIO(result))
zip.extractall(control.dataPath)
zip.close()
dbcon = database.connect(data)
dbcur = dbcon.cursor()
dbcur.execute("SELECT * FROM movies WHERE year = '%s'" % year)
result = dbcur.fetchone()
result = eval(result[1].encode('utf-8'))
title = cleantitle.movie(title)
years = ['%s' % str(year), '%s' % str(int(year)+1), '%s' % str(int(year)-1)]
result = [i for i in result if title == cleantitle.movie(i[2])]
result = [i[0] for i in result if any(x in i[3] for x in years)][0]
try: url = re.compile('//.+?(/.+)').findall(result)[0]
except: url = result
url = client.replaceHTMLCodes(url)
url = url.encode('utf-8')
return url
except:
return
def get_show(self, imdb, tvdb, tvshowtitle, year):
try:
data = os.path.join(control.dataPath, 'movietv.db')
try: control.deleteFile(data)
except: pass
data = os.path.join(control.dataPath, 'movietv2.db')
download = True
try: download = abs(datetime.datetime.fromtimestamp(os.path.getmtime(data)) - (datetime.datetime.now())) > datetime.timedelta(days=7)
except: pass
if download == True:
result = client.source(base64.b64decode(self.data_link))
zip = zipfile.ZipFile(StringIO.StringIO(result))
zip.extractall(control.dataPath)
zip.close()
dbcon = database.connect(data)
dbcur = dbcon.cursor()
dbcur.execute("SELECT * FROM tvshows WHERE year = '%s'" % year)
result = dbcur.fetchone()
result = eval(result[1].encode('utf-8'))
tvshowtitle = cleantitle.tv(tvshowtitle)
years = ['%s' % str(year), '%s' % str(int(year)+1), '%s' % str(int(year)-1)]
result = [i for i in result if tvshowtitle == cleantitle.tv(i[2])]
result = [i[0] for i in result if any(x in i[3] for x in years)][0]
try: url = re.compile('//.+?(/.+)').findall(result)[0]
except: url = result
url = client.replaceHTMLCodes(url)
url = url.encode('utf-8')
return url
except:
return
def get_episode(self, url, imdb, tvdb, title, date, season, episode):
try:
if url == None: return
if not '%01d' % int(season) == '1': return
if '%01d' % int(episode) > '3': return
url += '?S%02dE%02d' % (int(season), int(episode))
url = client.replaceHTMLCodes(url)
url = url.encode('utf-8')
return url
except:
return
def get_sources(self, url, hosthdDict, hostDict, locDict):
try:
sources = []
if url == None: return sources
data = os.path.join(control.dataPath, 'movietv.db')
try: control.deleteFile(data)
except: pass
data = os.path.join(control.dataPath, 'movietv2.db')
download = True
try: download = abs(datetime.datetime.fromtimestamp(os.path.getmtime(data)) - (datetime.datetime.now())) > datetime.timedelta(days=7)
except: pass
if download == True:
result = client.source(base64.b64decode(self.data_link))
zip = zipfile.ZipFile(StringIO.StringIO(result))
zip.extractall(control.dataPath)
zip.close()
dbcon = database.connect(data)
dbcur = dbcon.cursor()
content = re.compile('(.+?)\?S\d*E\d*$').findall(url)
try: url, handler = re.compile('(.+?)\?(S\d*E\d*)$').findall(url)[0]
except: pass
if len(content) == 0:
dbcur.execute("SELECT * FROM movies")
result = dbcur.fetchall()
result = [eval(i[1].encode('utf-8')) for i in result]
result = sum(result, [])
result = [i for i in result if i[0] == url][0]
else:
dbcur.execute("SELECT * FROM tvshows")
result = dbcur.fetchall()
result = [eval(i[1].encode('utf-8')) for i in result]
result = sum(result, [])
result = [i for i in result if i[0] == url]
result = [i for i in result if i[4] == handler][0]
url = '%s|Referer=%s' % (result[1], urllib.quote_plus(urlparse.urljoin(self.base_link, result[0])))
sources.append({'source': 'MovieTV', 'quality': 'HD', 'provider': 'MovieTV', 'url': url})
return sources
except:
return sources
def resolve(self, url):
try:
result = client.source(base64.b64decode(self.extra_link))
extra = client.parseDOM(result, 'p')
extra = [i for i in extra if 'User-Agent=' in i][0]
extra = client.replaceHTMLCodes(extra)
url += extra
return url
except:
return
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
428,
1764,
79,
2654,
13,
265,
272,
1898,
334,
35,
9,
6900,
2400,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
747,
12,
264,
12,
4078,
12,
10290,
12,
1001,
12,
18717,
12,
6424,
12,
2083,
12,
1095,
772,
199,
199,
893,
26,
272,
687,
11723,
19,
492,
29333,
18,
465,
3050,
199,
2590,
26,
272,
687,
10382,
29498,
18,
492,
29333,
18,
465,
3050,
199,
199,
504,
5944,
14,
773,
14,
10159,
492,
3304,
199,
504,
5944,
14,
773,
14,
10159,
492,
3633,
1213,
199,
504,
5944,
14,
773,
14,
10159,
492,
1890,
421,
199,
533,
1350,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1095,
63,
1073,
275,
283,
1014,
921,
573,
433,
386,
86,
14,
475,
7,
267,
291,
14,
576,
63,
1073,
275,
283,
65,
14784,
16,
67,
27699,
22,
27480,
25,
86,
26467,
58,
8076,
39,
25,
89,
14324,
5780,
68,
35,
21,
26257,
1165,
18708,
17395,
84,
57,
77,
50,
72,
9125,
86,
58,
17395,
16,
20207,
42,
15907,
18,
54,
90,
44,
2025,
11549,
757,
1447,
16255,
89,
8940,
20638,
33,
6803,
267,
291,
14,
2911,
63,
1073,
275,
283,
65,
14784,
16,
67,
2585,
86,
44,
18,
80,
17,
67,
19,
50,
87,
16936,
46,
16,
26697,
21,
8961,
35,
25,
86,
30879,
54,
74,
7,
2378,
347,
664,
63,
10888,
8,
277,
12,
18232,
12,
2538,
12,
5361,
304,
267,
862,
26,
288,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
14,
697,
358,
288,
862,
26,
3304,
14,
1807,
1173,
8,
576,
9,
288,
871,
26,
986,
953,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
18,
14,
697,
358,
953,
5235,
275,
715,
953,
862,
26,
5235,
275,
2853,
8,
2083,
14,
2083,
14,
18531,
8,
736,
14,
515,
14,
26628,
8,
576,
430,
446,
334,
2083,
14,
2083,
14,
2131,
4059,
690,
2197,
14,
7473,
8,
4899,
29,
23,
9,
288,
871,
26,
986,
953,
340,
5235,
508,
715,
26,
355,
754,
275,
1890,
14,
1365,
8,
1095,
772,
14,
66,
772,
2708,
8,
277,
14,
576,
63,
1073,
430,
355,
3482,
275,
10392,
14,
15016,
8,
6424,
14,
6424,
8,
1099,
430,
355,
3482,
14,
5005,
452,
8,
2785,
14,
576,
2042,
9,
355,
3482,
14,
1600,
342,
953,
1592,
388,
275,
3050,
14,
2242,
8,
576,
9,
288,
1592,
895,
275,
1592,
388,
14,
3937,
342,
953,
1592,
895,
14,
2526,
480,
4859,
627,
4442,
1303,
14484,
6038,
5361,
275,
1543,
83,
4065,
450,
5361,
9,
288,
754,
275,
1592,
895,
14,
11591,
342,
288,
754,
275,
3468,
8,
1099,
59,
17,
1055,
2143,
360,
1624,
13,
24,
1333,
953,
2538,
275,
3633,
1213,
14,
10888,
8,
1213,
9,
288,
17399,
275,
15926,
83,
7,
450,
620,
8,
3403,
395,
1543,
83,
7,
450,
620,
8,
442,
8,
3403,
6393,
17,
395,
1543,
83,
7,
450,
620,
8,
442,
8,
3403,
7216,
17,
1874,
953,
754,
275,
359,
73,
367,
284,
315,
754,
340,
2538,
508,
3633,
1213,
14,
10888,
8,
73,
59,
18,
12457,
288,
754,
275,
359,
73,
59,
16,
61,
367,
284,
315,
754,
340,
1263,
8,
88,
315,
284,
59,
19,
61,
367,
671,
315,
17399,
30372,
16,
61,
953,
862,
26,
1166,
275,
295,
14,
2014,
15079,
11198,
29478,
6977,
9,
1959,
6452,
8,
1099,
2788,
16,
61,
288,
871,
26,
1166,
275,
754,
288,
1166,
275,
1890,
14,
1814,
4943,
14060,
8,
633,
9,
288,
1166,
275,
1166,
14,
2143,
360,
1624,
13,
24,
358,
288,
372,
1166,
267,
871,
26,
288,
372,
2378,
347,
664,
63,
2384,
8,
277,
12,
18232,
12,
26905,
12,
13466,
2384,
1213,
12,
5361,
304,
267,
862,
26,
288,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
14,
697,
358,
288,
862,
26,
3304,
14,
1807,
1173,
8,
576,
9,
288,
871,
26,
986,
953,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
18,
14,
697,
358,
953,
5235,
275,
715,
953,
862,
26,
5235,
275,
2853,
8,
2083,
14,
2083,
14,
18531,
8,
736,
14,
515,
14,
26628,
8,
576,
430,
446,
334,
2083,
14,
2083,
14,
2131,
4059,
690,
2197,
14,
7473,
8,
4899,
29,
23,
9,
288,
871,
26,
986,
953,
340,
5235,
508,
715,
26,
355,
754,
275,
1890,
14,
1365,
8,
1095,
772,
14,
66,
772,
2708,
8,
277,
14,
576,
63,
1073,
430,
355,
3482,
275,
10392,
14,
15016,
8,
6424,
14,
6424,
8,
1099,
430,
355,
3482,
14,
5005,
452,
8,
2785,
14,
576,
2042,
9,
355,
3482,
14,
1600,
342,
953,
1592,
388,
275,
3050,
14,
2242,
8,
576,
9,
288,
1592,
895,
275,
1592,
388,
14,
3937,
342,
953,
1592,
895,
14,
2526,
480,
4859,
627,
4442,
13466,
23866,
6038,
5361,
275,
1543,
83,
4065,
450,
5361,
9,
288,
754,
275,
1592,
895,
14,
11591,
342,
288,
754,
275,
3468,
8,
1099,
59,
17,
1055,
2143,
360,
1624,
13,
24,
1333,
953,
13466,
2384,
1213,
275,
3633,
1213,
14,
6993,
8,
6993,
2384,
1213,
9,
288,
17399,
275,
15926,
83,
7,
450,
620,
8,
3403,
395,
1543,
83,
7,
450,
620,
8
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
428,
1764,
79,
2654,
13,
265,
272,
1898,
334,
35,
9,
6900,
2400,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
747,
12,
264,
12,
4078,
12,
10290,
12,
1001,
12,
18717,
12,
6424,
12,
2083,
12,
1095,
772,
199,
199,
893,
26,
272,
687,
11723,
19,
492,
29333,
18,
465,
3050,
199,
2590,
26,
272,
687,
10382,
29498,
18,
492,
29333,
18,
465,
3050,
199,
199,
504,
5944,
14,
773,
14,
10159,
492,
3304,
199,
504,
5944,
14,
773,
14,
10159,
492,
3633,
1213,
199,
504,
5944,
14,
773,
14,
10159,
492,
1890,
421,
199,
533,
1350,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1095,
63,
1073,
275,
283,
1014,
921,
573,
433,
386,
86,
14,
475,
7,
267,
291,
14,
576,
63,
1073,
275,
283,
65,
14784,
16,
67,
27699,
22,
27480,
25,
86,
26467,
58,
8076,
39,
25,
89,
14324,
5780,
68,
35,
21,
26257,
1165,
18708,
17395,
84,
57,
77,
50,
72,
9125,
86,
58,
17395,
16,
20207,
42,
15907,
18,
54,
90,
44,
2025,
11549,
757,
1447,
16255,
89,
8940,
20638,
33,
6803,
267,
291,
14,
2911,
63,
1073,
275,
283,
65,
14784,
16,
67,
2585,
86,
44,
18,
80,
17,
67,
19,
50,
87,
16936,
46,
16,
26697,
21,
8961,
35,
25,
86,
30879,
54,
74,
7,
2378,
347,
664,
63,
10888,
8,
277,
12,
18232,
12,
2538,
12,
5361,
304,
267,
862,
26,
288,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
14,
697,
358,
288,
862,
26,
3304,
14,
1807,
1173,
8,
576,
9,
288,
871,
26,
986,
953,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
18,
14,
697,
358,
953,
5235,
275,
715,
953,
862,
26,
5235,
275,
2853,
8,
2083,
14,
2083,
14,
18531,
8,
736,
14,
515,
14,
26628,
8,
576,
430,
446,
334,
2083,
14,
2083,
14,
2131,
4059,
690,
2197,
14,
7473,
8,
4899,
29,
23,
9,
288,
871,
26,
986,
953,
340,
5235,
508,
715,
26,
355,
754,
275,
1890,
14,
1365,
8,
1095,
772,
14,
66,
772,
2708,
8,
277,
14,
576,
63,
1073,
430,
355,
3482,
275,
10392,
14,
15016,
8,
6424,
14,
6424,
8,
1099,
430,
355,
3482,
14,
5005,
452,
8,
2785,
14,
576,
2042,
9,
355,
3482,
14,
1600,
342,
953,
1592,
388,
275,
3050,
14,
2242,
8,
576,
9,
288,
1592,
895,
275,
1592,
388,
14,
3937,
342,
953,
1592,
895,
14,
2526,
480,
4859,
627,
4442,
1303,
14484,
6038,
5361,
275,
1543,
83,
4065,
450,
5361,
9,
288,
754,
275,
1592,
895,
14,
11591,
342,
288,
754,
275,
3468,
8,
1099,
59,
17,
1055,
2143,
360,
1624,
13,
24,
1333,
953,
2538,
275,
3633,
1213,
14,
10888,
8,
1213,
9,
288,
17399,
275,
15926,
83,
7,
450,
620,
8,
3403,
395,
1543,
83,
7,
450,
620,
8,
442,
8,
3403,
6393,
17,
395,
1543,
83,
7,
450,
620,
8,
442,
8,
3403,
7216,
17,
1874,
953,
754,
275,
359,
73,
367,
284,
315,
754,
340,
2538,
508,
3633,
1213,
14,
10888,
8,
73,
59,
18,
12457,
288,
754,
275,
359,
73,
59,
16,
61,
367,
284,
315,
754,
340,
1263,
8,
88,
315,
284,
59,
19,
61,
367,
671,
315,
17399,
30372,
16,
61,
953,
862,
26,
1166,
275,
295,
14,
2014,
15079,
11198,
29478,
6977,
9,
1959,
6452,
8,
1099,
2788,
16,
61,
288,
871,
26,
1166,
275,
754,
288,
1166,
275,
1890,
14,
1814,
4943,
14060,
8,
633,
9,
288,
1166,
275,
1166,
14,
2143,
360,
1624,
13,
24,
358,
288,
372,
1166,
267,
871,
26,
288,
372,
2378,
347,
664,
63,
2384,
8,
277,
12,
18232,
12,
26905,
12,
13466,
2384,
1213,
12,
5361,
304,
267,
862,
26,
288,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
14,
697,
358,
288,
862,
26,
3304,
14,
1807,
1173,
8,
576,
9,
288,
871,
26,
986,
953,
666,
275,
747,
14,
515,
14,
904,
8,
2785,
14,
576,
2042,
12,
283,
573,
433,
386,
86,
18,
14,
697,
358,
953,
5235,
275,
715,
953,
862,
26,
5235,
275,
2853,
8,
2083,
14,
2083,
14,
18531,
8,
736,
14,
515,
14,
26628,
8,
576,
430,
446,
334,
2083,
14,
2083,
14,
2131,
4059,
690,
2197,
14,
7473,
8,
4899,
29,
23,
9,
288,
871,
26,
986,
953,
340,
5235,
508,
715,
26,
355,
754,
275,
1890,
14,
1365,
8,
1095,
772,
14,
66,
772,
2708,
8,
277,
14,
576,
63,
1073,
430,
355,
3482,
275,
10392,
14,
15016,
8,
6424,
14,
6424,
8,
1099,
430,
355,
3482,
14,
5005,
452,
8,
2785,
14,
576,
2042,
9,
355,
3482,
14,
1600,
342,
953,
1592,
388,
275,
3050,
14,
2242,
8,
576,
9,
288,
1592,
895,
275,
1592,
388,
14,
3937,
342,
953,
1592,
895,
14,
2526,
480,
4859,
627,
4442,
13466,
23866,
6038,
5361,
275,
1543,
83,
4065,
450,
5361,
9,
288,
754,
275,
1592,
895,
14,
11591,
342,
288,
754,
275,
3468,
8,
1099,
59,
17,
1055,
2143,
360,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
chandranaik/Aligning-of-PIE-with-rfc8033-in-ns3
|
src/lte/doc/source/conf.py
|
28
|
7622
|
# -*- coding: utf-8 -*-
#
# ns-3 documentation build configuration file, created by
# sphinx-quickstart on Tue Dec 14 09:00:39 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.pngmath']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'lte'
# General information about the project.
project = u'LENA'
copyright = u'CTTC'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = 'v10'
# The full version, including alpha/beta/rc tags.
release = 'v10'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
#htmlhelp_basename = 'ns-3doc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
# ('lte-testing', 'lte-doc-testing.tex', u'LTE Simulator Testing Documentation', u'Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)', 'manual'),
# ('lte-design', 'lte-doc-design.tex', u'LTE Simulator Design Documentation', u'Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)', 'manual'),
# ('lte-user', 'lte-doc-user.tex', u'LTE Simulator User Documentation', u'Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)', 'manual'),
('lte', 'lena-lte-module-doc.tex', u'The LENA ns-3 LTE Module Documentation', u'Centre Tecnològic de Telecomunicacions de Catalunya (CTTC)', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# add page breaks in the pdf. Level 1 is for top-level sections, level 2 for subsections, and so on.
pdf_break_level = 4
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'ns-3-model-library', u'ns-3 Model Library',
[u'ns-3 project'], 1)
]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
700,
13,
19,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
13966,
4329,
21798,
26,
383,
26,
1355,
7129,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
4524,
3442,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
20740,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
5304,
33,
7,
199,
7307,
275,
399,
7,
1028,
5708,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
86,
709,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
86,
709,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63,
22229,
275,
488,
199,
199,
3
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
700,
13,
19,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
13966,
4329,
21798,
26,
383,
26,
1355,
7129,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
4524,
3442,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
20740,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
5304,
33,
7,
199,
7307,
275,
399,
7,
1028,
5708,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
86,
709,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
86,
709,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63,
22229,
275,
488,
199,
199,
3,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andrius-preimantas/odoo
|
addons/account_voucher/invoice.py
|
382
|
2496
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import osv
from openerp.tools.translate import _
class invoice(osv.osv):
_inherit = 'account.invoice'
def invoice_pay_customer(self, cr, uid, ids, context=None):
if not ids: return []
dummy, view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_voucher', 'view_vendor_receipt_dialog_form')
inv = self.browse(cr, uid, ids[0], context=context)
return {
'name':_("Pay Invoice"),
'view_mode': 'form',
'view_id': view_id,
'view_type': 'form',
'res_model': 'account.voucher',
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'new',
'domain': '[]',
'context': {
'payment_expected_currency': inv.currency_id.id,
'default_partner_id': self.pool.get('res.partner')._find_accounting_partner(inv.partner_id).id,
'default_amount': inv.type in ('out_refund', 'in_refund') and -inv.residual or inv.residual,
'default_reference': inv.name,
'close_after_process': True,
'invoice_type': inv.type,
'invoice_id': inv.id,
'default_type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment',
'type': inv.type in ('out_invoice','out_refund') and 'receipt' or 'payment'
}
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
8485,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
2048,
14,
5404,
7,
339,
347,
8485,
63,
5989,
63,
10178,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
440,
2762,
26,
372,
942,
267,
7283,
12,
2455,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
1556,
12,
1747,
12,
283,
2048,
63,
16637,
297,
283,
1345,
63,
9884,
63,
18905,
63,
7196,
63,
964,
358,
398,
4572,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
59,
16,
467,
1067,
29,
1100,
9,
267,
372,
469,
288,
283,
354,
356,
14332,
10517,
19868,
1288,
288,
283,
1345,
63,
632,
356,
283,
964,
297,
288,
283,
1345,
63,
344,
356,
2455,
63,
344,
12,
288,
283,
1345,
63,
466,
356,
283,
964,
297,
288,
283,
470,
63,
1238,
356,
283,
2048,
14,
16637,
297,
288,
283,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
288,
283,
932,
270,
4813,
356,
715,
12,
288,
283,
1375,
356,
283,
1222,
297,
288,
283,
2261,
356,
6730,
4300,
288,
283,
1100,
356,
469,
355,
283,
7948,
63,
2062,
63,
4968,
356,
4572,
14,
4968,
63,
344,
14,
344,
12,
355,
283,
885,
63,
3899,
63,
344,
356,
291,
14,
2293,
14,
362,
360,
470,
14,
3899,
31238,
1623,
63,
21609,
63,
3899,
8,
5350,
14,
3899,
63,
344,
680,
344,
12,
355,
283,
885,
63,
4606,
356,
4572,
14,
466,
315,
661,
548,
63,
18440,
297,
283,
262,
63,
18440,
358,
436,
446,
5350,
14,
20161,
503,
4572,
14,
20161,
12,
355,
283,
885,
63,
4443,
356,
4572,
14,
354,
12,
355,
283,
1600,
63,
4399,
63,
1412,
356,
715,
12,
355,
283,
5404,
63,
466,
356,
4572,
14,
466,
12,
355,
283,
5404,
63,
344,
356,
4572,
14,
344,
12,
355,
283,
885,
63,
466,
356,
4572,
14,
466,
315,
661,
548,
63,
5404,
1673,
548,
63,
18440,
358,
436,
283,
18905,
7,
503,
283,
7948,
297,
355,
283,
466,
356,
4572,
14,
466,
315,
661,
548,
63,
5404,
1673,
548,
63,
18440,
358,
436,
283,
18905,
7,
503,
283,
7948,
7,
288,
789,
267,
789,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
8485,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
2048,
14,
5404,
7,
339,
347,
8485,
63,
5989,
63,
10178,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
440,
2762,
26,
372,
942,
267,
7283,
12,
2455,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
1556,
12,
1747,
12,
283,
2048,
63,
16637,
297,
283,
1345,
63,
9884,
63,
18905,
63,
7196,
63,
964,
358,
398,
4572,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
59,
16,
467,
1067,
29,
1100,
9,
267,
372,
469,
288,
283,
354,
356,
14332,
10517,
19868,
1288,
288,
283,
1345,
63,
632,
356,
283,
964,
297,
288,
283,
1345,
63,
344,
356,
2455,
63,
344,
12,
288,
283,
1345,
63,
466,
356,
283,
964,
297,
288,
283,
470,
63,
1238,
356,
283,
2048,
14,
16637,
297,
288,
283,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
288,
283,
932,
270,
4813,
356,
715,
12,
288,
283,
1375,
356,
283,
1222,
297,
288,
283,
2261,
356,
6730,
4300,
288,
283,
1100,
356,
469,
355,
283,
7948,
63,
2062,
63,
4968,
356,
4572,
14,
4968,
63,
344,
14,
344,
12,
355,
283,
885,
63,
3899,
63,
344,
356,
291,
14,
2293,
14,
362,
360,
470,
14,
3899,
31238,
1623,
63,
21609,
63,
3899,
8,
5350,
14,
3899,
63,
344,
680,
344,
12,
355,
283,
885,
63,
4606,
356,
4572,
14,
466,
315,
661,
548,
63,
18440,
297,
283,
262,
63,
18440,
358,
436,
446,
5350,
14,
20161,
503,
4572,
14,
20161,
12,
355,
283,
885,
63,
4443,
356,
4572,
14,
354,
12,
355,
283,
1600,
63,
4399,
63,
1412,
356,
715,
12,
355,
283,
5404,
63,
466,
356,
4572,
14,
466,
12,
355,
283,
5404,
63,
344,
356,
4572,
14,
344,
12,
355,
283,
885,
63,
466,
356,
4572,
14,
466,
315,
661,
548,
63,
5404,
1673,
548,
63,
18440,
358,
436,
283,
18905,
7,
503,
283,
7948,
297,
355,
283,
466,
356,
4572,
14,
466,
315,
661,
548,
63,
5404,
1673,
548,
63,
18440,
358,
436,
283,
18905,
7,
503,
283,
7948,
7,
288,
789,
267,
789,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
luther07/dak
|
dak/rm.py
|
2
|
32615
|
#!/usr/bin/env python
""" General purpose package removal tool for ftpmaster """
# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
# Copyright (C) 2010 Alexander Reichle-Schmehl <tolimar@debian.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
################################################################################
# o OpenBSD team wants to get changes incorporated into IPF. Darren no
# respond.
# o Ask again -> No respond. Darren coder supreme.
# o OpenBSD decide to make changes, but only in OpenBSD source
# tree. Darren hears, gets angry! Decides: "LICENSE NO ALLOW!"
# o Insert Flame War.
# o OpenBSD team decide to switch to different packet filter under BSD
# license. Because Project Goal: Every user should be able to make
# changes to source tree. IPF license bad!!
# o Darren try get back: says, NetBSD, FreeBSD allowed! MUAHAHAHAH!!!
# o Theo say: no care, pf much better than ipf!
# o Darren changes mind: changes license. But OpenBSD will not change
# back to ipf. Darren even much more bitter.
# o Darren so bitterbitter. Decides: I'LL GET BACK BY FORKING OPENBSD AND
# RELEASING MY OWN VERSION. HEHEHEHEHE.
# http://slashdot.org/comments.pl?sid=26697&cid=2883271
################################################################################
import commands
import os
import sys
import apt_pkg
import apt_inst
from re import sub
from daklib.config import Config
from daklib.dbconn import *
from daklib import utils
from daklib.dak_exceptions import *
from daklib.regexes import re_strip_source_version, re_build_dep_arch, re_bin_only_nmu
import debianbts as bts
################################################################################
Options = None
################################################################################
def usage (exit_code=0):
print """Usage: dak rm [OPTIONS] PACKAGE[...]
Remove PACKAGE(s) from suite(s).
-a, --architecture=ARCH only act on this architecture
-b, --binary remove binaries only
-c, --component=COMPONENT act on this component
-C, --carbon-copy=EMAIL send a CC of removal message to EMAIL
-d, --done=BUG# send removal message as closure to bug#
-D, --do-close also close all bugs associated to that package
-h, --help show this help and exit
-m, --reason=MSG reason for removal
-n, --no-action don't do anything
-p, --partial don't affect override files
-R, --rdep-check check reverse dependencies
-s, --suite=SUITE act on this suite
-S, --source-only remove source only
ARCH, BUG#, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
--architecture=amd64,i386"""
sys.exit(exit_code)
################################################################################
# "Hudson: What that's great, that's just fucking great man, now what
# the fuck are we supposed to do? We're in some real pretty shit now
# man...That's it man, game over man, game over, man! Game over! What
# the fuck are we gonna do now? What are we gonna do?"
def game_over():
answer = utils.our_raw_input("Continue (y/N)? ").lower()
if answer != "y":
print "Aborted."
sys.exit(1)
################################################################################
def reverse_depends_check(removals, suite, arches=None, session=None):
dbsuite = get_suite(suite, session)
cnf = Config()
print "Checking reverse dependencies..."
dep_problem = 0
p2c = {}
all_broken = {}
if arches:
all_arches = set(arches)
else:
all_arches = set([x.arch_string for x in get_suite_architectures(suite)])
all_arches -= set(["source", "all"])
metakey_d = get_or_set_metadatakey("Depends", session)
metakey_p = get_or_set_metadatakey("Provides", session)
params = {
'suite_id': dbsuite.suite_id,
'metakey_d_id': metakey_d.key_id,
'metakey_p_id': metakey_p.key_id,
}
for architecture in all_arches | set(['all']):
deps = {}
sources = {}
virtual_packages = {}
params['arch_id'] = get_architecture(architecture, session).arch_id
statement = '''
SELECT b.id, b.package, s.source, c.name as component,
(SELECT bmd.value FROM binaries_metadata bmd WHERE bmd.bin_id = b.id AND bmd.key_id = :metakey_d_id) AS depends,
(SELECT bmp.value FROM binaries_metadata bmp WHERE bmp.bin_id = b.id AND bmp.key_id = :metakey_p_id) AS provides
FROM binaries b
JOIN bin_associations ba ON b.id = ba.bin AND ba.suite = :suite_id
JOIN source s ON b.source = s.id
JOIN files f ON b.file = f.id
JOIN location l ON f.location = l.id
JOIN component c ON l.component = c.id
WHERE b.architecture = :arch_id'''
query = session.query('id', 'package', 'source', 'component', 'depends', 'provides'). \
from_statement(statement).params(params)
for binary_id, package, source, component, depends, provides in query:
sources[package] = source
p2c[package] = component
if depends is not None:
deps[package] = depends
# Maintain a counter for each virtual package. If a
# Provides: exists, set the counter to 0 and count all
# provides by a package not in the list for removal.
# If the counter stays 0 at the end, we know that only
# the to-be-removed packages provided this virtual
# package.
if provides is not None:
for virtual_pkg in provides.split(","):
virtual_pkg = virtual_pkg.strip()
if virtual_pkg == package: continue
if not virtual_packages.has_key(virtual_pkg):
virtual_packages[virtual_pkg] = 0
if package not in removals:
virtual_packages[virtual_pkg] += 1
# If a virtual package is only provided by the to-be-removed
# packages, treat the virtual package as to-be-removed too.
for virtual_pkg in virtual_packages.keys():
if virtual_packages[virtual_pkg] == 0:
removals.append(virtual_pkg)
# Check binary dependencies (Depends)
for package in deps.keys():
if package in removals: continue
parsed_dep = []
try:
parsed_dep += apt_pkg.ParseDepends(deps[package])
except ValueError as e:
print "Error for package %s: %s" % (package, e)
for dep in parsed_dep:
# Check for partial breakage. If a package has a ORed
# dependency, there is only a dependency problem if all
# packages in the ORed depends will be removed.
unsat = 0
for dep_package, _, _ in dep:
if dep_package in removals:
unsat += 1
if unsat == len(dep):
component = p2c[package]
source = sources[package]
if component != "main":
source = "%s/%s" % (source, component)
all_broken.setdefault(source, {}).setdefault(package, set()).add(architecture)
dep_problem = 1
if all_broken:
print "# Broken Depends:"
for source, bindict in sorted(all_broken.items()):
lines = []
for binary, arches in sorted(bindict.items()):
if arches == all_arches or 'all' in arches:
lines.append(binary)
else:
lines.append('%s [%s]' % (binary, ' '.join(sorted(arches))))
print '%s: %s' % (source, lines[0])
for line in lines[1:]:
print ' ' * (len(source) + 2) + line
print
# Check source dependencies (Build-Depends and Build-Depends-Indep)
all_broken.clear()
metakey_bd = get_or_set_metadatakey("Build-Depends", session)
metakey_bdi = get_or_set_metadatakey("Build-Depends-Indep", session)
params = {
'suite_id': dbsuite.suite_id,
'metakey_ids': (metakey_bd.key_id, metakey_bdi.key_id),
}
statement = '''
SELECT s.id, s.source, string_agg(sm.value, ', ') as build_dep
FROM source s
JOIN source_metadata sm ON s.id = sm.src_id
WHERE s.id in
(SELECT source FROM src_associations
WHERE suite = :suite_id)
AND sm.key_id in :metakey_ids
GROUP BY s.id, s.source'''
query = session.query('id', 'source', 'build_dep').from_statement(statement). \
params(params)
for source_id, source, build_dep in query:
if source in removals: continue
parsed_dep = []
if build_dep is not None:
# Remove [arch] information since we want to see breakage on all arches
build_dep = re_build_dep_arch.sub("", build_dep)
try:
parsed_dep += apt_pkg.ParseDepends(build_dep)
except ValueError as e:
print "Error for source %s: %s" % (source, e)
for dep in parsed_dep:
unsat = 0
for dep_package, _, _ in dep:
if dep_package in removals:
unsat += 1
if unsat == len(dep):
component = DBSource.get(source_id, session).get_component_name()
if component != "main":
source = "%s/%s" % (source, component)
all_broken.setdefault(source, set()).add(utils.pp_deps(dep))
dep_problem = 1
if all_broken:
print "# Broken Build-Depends:"
for source, bdeps in sorted(all_broken.items()):
bdeps = sorted(bdeps)
print '%s: %s' % (source, bdeps[0])
for bdep in bdeps[1:]:
print ' ' * (len(source) + 2) + bdep
print
if dep_problem:
print "Dependency problem found."
if not Options["No-Action"]:
game_over()
else:
print "No dependency problem found."
print
################################################################################
def main ():
global Options
cnf = Config()
Arguments = [('h',"help","Rm::Options::Help"),
('a',"architecture","Rm::Options::Architecture", "HasArg"),
('b',"binary", "Rm::Options::Binary-Only"),
('c',"component", "Rm::Options::Component", "HasArg"),
('C',"carbon-copy", "Rm::Options::Carbon-Copy", "HasArg"), # Bugs to Cc
('d',"done","Rm::Options::Done", "HasArg"), # Bugs fixed
('D',"do-close","Rm::Options::Do-Close"),
('R',"rdep-check", "Rm::Options::Rdep-Check"),
('m',"reason", "Rm::Options::Reason", "HasArg"), # Hysterical raisins; -m is old-dinstall option for rejection reason
('n',"no-action","Rm::Options::No-Action"),
('p',"partial", "Rm::Options::Partial"),
('s',"suite","Rm::Options::Suite", "HasArg"),
('S',"source-only", "Rm::Options::Source-Only"),
]
for i in [ "architecture", "binary-only", "carbon-copy", "component",
"done", "help", "no-action", "partial", "rdep-check", "reason",
"source-only", "Do-Close" ]:
if not cnf.has_key("Rm::Options::%s" % (i)):
cnf["Rm::Options::%s" % (i)] = ""
if not cnf.has_key("Rm::Options::Suite"):
cnf["Rm::Options::Suite"] = "unstable"
arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
Options = cnf.subtree("Rm::Options")
if Options["Help"]:
usage()
session = DBConn().session()
# Sanity check options
if not arguments:
utils.fubar("need at least one package name as an argument.")
if Options["Architecture"] and Options["Source-Only"]:
utils.fubar("can't use -a/--architecture and -S/--source-only options simultaneously.")
if Options["Binary-Only"] and Options["Source-Only"]:
utils.fubar("can't use -b/--binary-only and -S/--source-only options simultaneously.")
if Options.has_key("Carbon-Copy") and not Options.has_key("Done"):
utils.fubar("can't use -C/--carbon-copy without also using -d/--done option.")
if Options["Architecture"] and not Options["Partial"]:
utils.warn("-a/--architecture implies -p/--partial.")
Options["Partial"] = "true"
if Options["Do-Close"] and not Options["Done"]:
utils.fubar("No.")
if Options["Do-Close"] and Options["Binary-Only"]:
utils.fubar("No.")
if Options["Do-Close"] and Options["Source-Only"]:
utils.fubar("No.")
if Options["Do-Close"] and Options["Suite"] != 'unstable':
utils.fubar("No.")
# Force the admin to tell someone if we're not doing a 'dak
# cruft-report' inspired removal (or closing a bug, which counts
# as telling someone).
if not Options["No-Action"] and not Options["Carbon-Copy"] \
and not Options["Done"] and Options["Reason"].find("[auto-cruft]") == -1:
utils.fubar("Need a -C/--carbon-copy if not closing a bug and not doing a cruft removal.")
# Process -C/--carbon-copy
#
# Accept 3 types of arguments (space separated):
# 1) a number - assumed to be a bug number, i.e. nnnnn@bugs.debian.org
# 2) the keyword 'package' - cc's $package@packages.debian.org for every argument
# 3) contains a '@' - assumed to be an email address, used unmofidied
#
carbon_copy = []
for copy_to in utils.split_args(Options.get("Carbon-Copy")):
if copy_to.isdigit():
if cnf.has_key("Dinstall::BugServer"):
carbon_copy.append(copy_to + "@" + cnf["Dinstall::BugServer"])
else:
utils.fubar("Asked to send mail to #%s in BTS but Dinstall::BugServer is not configured" % copy_to)
elif copy_to == 'package':
for package in arguments:
if cnf.has_key("Dinstall::PackagesServer"):
carbon_copy.append(package + "@" + cnf["Dinstall::PackagesServer"])
if cnf.has_key("Dinstall::TrackingServer"):
carbon_copy.append(package + "@" + cnf["Dinstall::TrackingServer"])
elif '@' in copy_to:
carbon_copy.append(copy_to)
else:
utils.fubar("Invalid -C/--carbon-copy argument '%s'; not a bug number, 'package' or email address." % (copy_to))
if Options["Binary-Only"]:
field = "b.package"
else:
field = "s.source"
con_packages = "AND %s IN (%s)" % (field, ", ".join([ repr(i) for i in arguments ]))
(con_suites, con_architectures, con_components, check_source) = \
utils.parse_args(Options)
# Additional suite checks
suite_ids_list = []
suites = utils.split_args(Options["Suite"])
suites_list = utils.join_with_commas_and(suites)
if not Options["No-Action"]:
for suite in suites:
s = get_suite(suite, session=session)
if s is not None:
suite_ids_list.append(s.suite_id)
if suite in ("oldstable", "stable"):
print "**WARNING** About to remove from the (old)stable suite!"
print "This should only be done just prior to a (point) release and not at"
print "any other time."
game_over()
elif suite == "testing":
print "**WARNING About to remove from the testing suite!"
print "There's no need to do this normally as removals from unstable will"
print "propogate to testing automagically."
game_over()
# Additional architecture checks
if Options["Architecture"] and check_source:
utils.warn("'source' in -a/--argument makes no sense and is ignored.")
# Additional component processing
over_con_components = con_components.replace("c.id", "component")
# Don't do dependency checks on multiple suites
if Options["Rdep-Check"] and len(suites) > 1:
utils.fubar("Reverse dependency check on multiple suites is not implemented.")
print "Working...",
sys.stdout.flush()
to_remove = []
maintainers = {}
# We have 3 modes of package selection: binary-only, source-only
# and source+binary. The first two are trivial and obvious; the
# latter is a nasty mess, but very nice from a UI perspective so
# we try to support it.
# XXX: TODO: This all needs converting to use placeholders or the object
# API. It's an SQL injection dream at the moment
if Options["Binary-Only"]:
# Binary-only
q = session.execute("SELECT b.package, b.version, a.arch_string, b.id, b.maintainer FROM binaries b, bin_associations ba, architecture a, suite su, files f, location l, component c WHERE ba.bin = b.id AND ba.suite = su.id AND b.architecture = a.id AND b.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s %s" % (con_packages, con_suites, con_components, con_architectures))
for i in q.fetchall():
to_remove.append(i)
else:
# Source-only
source_packages = {}
q = session.execute("SELECT l.path, f.filename, s.source, s.version, 'source', s.id, s.maintainer FROM source s, src_associations sa, suite su, files f, location l, component c WHERE sa.source = s.id AND sa.suite = su.id AND s.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s" % (con_packages, con_suites, con_components))
for i in q.fetchall():
source_packages[i[2]] = i[:2]
to_remove.append(i[2:])
if not Options["Source-Only"]:
# Source + Binary
binary_packages = {}
# First get a list of binary package names we suspect are linked to the source
q = session.execute("SELECT DISTINCT b.package FROM binaries b, source s, src_associations sa, suite su, files f, location l, component c WHERE b.source = s.id AND sa.source = s.id AND sa.suite = su.id AND s.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s" % (con_packages, con_suites, con_components))
for i in q.fetchall():
binary_packages[i[0]] = ""
# Then parse each .dsc that we found earlier to see what binary packages it thinks it produces
for i in source_packages.keys():
filename = "/".join(source_packages[i])
try:
dsc = utils.parse_changes(filename, dsc_file=1)
except CantOpenError:
utils.warn("couldn't open '%s'." % (filename))
continue
for package in dsc.get("binary").split(','):
package = package.strip()
binary_packages[package] = ""
# Then for each binary package: find any version in
# unstable, check the Source: field in the deb matches our
# source package and if so add it to the list of packages
# to be removed.
for package in binary_packages.keys():
q = session.execute("SELECT l.path, f.filename, b.package, b.version, a.arch_string, b.id, b.maintainer FROM binaries b, bin_associations ba, architecture a, suite su, files f, location l, component c WHERE ba.bin = b.id AND ba.suite = su.id AND b.architecture = a.id AND b.file = f.id AND f.location = l.id AND l.component = c.id %s %s %s AND b.package = '%s'" % (con_suites, con_components, con_architectures, package))
for i in q.fetchall():
filename = "/".join(i[:2])
control = apt_pkg.TagSection(utils.deb_extract_control(utils.open_file(filename)))
source = control.find("Source", control.find("Package"))
source = re_strip_source_version.sub('', source)
if source_packages.has_key(source):
to_remove.append(i[2:])
print "done."
if not to_remove:
print "Nothing to do."
sys.exit(0)
# If we don't have a reason; spawn an editor so the user can add one
# Write the rejection email out as the <foo>.reason file
if not Options["Reason"] and not Options["No-Action"]:
(fd, temp_filename) = utils.temp_filename()
editor = os.environ.get("EDITOR","vi")
result = os.system("%s %s" % (editor, temp_filename))
if result != 0:
utils.fubar ("vi invocation failed for `%s'!" % (temp_filename), result)
temp_file = utils.open_file(temp_filename)
for line in temp_file.readlines():
Options["Reason"] += line
temp_file.close()
os.unlink(temp_filename)
# Generate the summary of what's to be removed
d = {}
for i in to_remove:
package = i[0]
version = i[1]
architecture = i[2]
maintainer = i[4]
maintainers[maintainer] = ""
if not d.has_key(package):
d[package] = {}
if not d[package].has_key(version):
d[package][version] = []
if architecture not in d[package][version]:
d[package][version].append(architecture)
maintainer_list = []
for maintainer_id in maintainers.keys():
maintainer_list.append(get_maintainer(maintainer_id).name)
summary = ""
removals = d.keys()
removals.sort()
versions = []
for package in removals:
versions = d[package].keys()
versions.sort(apt_pkg.version_compare)
for version in versions:
d[package][version].sort(utils.arch_compare_sw)
summary += "%10s | %10s | %s\n" % (package, version, ", ".join(d[package][version]))
print "Will remove the following packages from %s:" % (suites_list)
print
print summary
print "Maintainer: %s" % ", ".join(maintainer_list)
if Options["Done"]:
print "Will also close bugs: "+Options["Done"]
if carbon_copy:
print "Will also send CCs to: " + ", ".join(carbon_copy)
if Options["Do-Close"]:
print "Will also close associated bug reports."
print
print "------------------- Reason -------------------"
print Options["Reason"]
print "----------------------------------------------"
print
if Options["Rdep-Check"]:
arches = utils.split_args(Options["Architecture"])
reverse_depends_check(removals, suites[0], arches, session)
# If -n/--no-action, drop out here
if Options["No-Action"]:
sys.exit(0)
print "Going to remove the packages now."
game_over()
whoami = utils.whoami()
date = commands.getoutput('date -R')
# Log first; if it all falls apart I want a record that we at least tried.
logfile = utils.open_file(cnf["Rm::LogFile"], 'a')
logfile.write("=========================================================================\n")
logfile.write("[Date: %s] [ftpmaster: %s]\n" % (date, whoami))
logfile.write("Removed the following packages from %s:\n\n%s" % (suites_list, summary))
if Options["Done"]:
logfile.write("Closed bugs: %s\n" % (Options["Done"]))
logfile.write("\n------------------- Reason -------------------\n%s\n" % (Options["Reason"]))
logfile.write("----------------------------------------------\n")
# Do the same in rfc822 format
logfile822 = utils.open_file(cnf["Rm::LogFile822"], 'a')
logfile822.write("Date: %s\n" % date)
logfile822.write("Ftpmaster: %s\n" % whoami)
logfile822.write("Suite: %s\n" % suites_list)
sources = []
binaries = []
for package in summary.split("\n"):
for row in package.split("\n"):
element = row.split("|")
if len(element) == 3:
if element[2].find("source") > 0:
sources.append("%s_%s" % tuple(elem.strip(" ") for elem in element[:2]))
element[2] = sub("source\s?,?", "", element[2]).strip(" ")
if element[2]:
binaries.append("%s_%s [%s]" % tuple(elem.strip(" ") for elem in element))
if sources:
logfile822.write("Sources:\n")
for source in sources:
logfile822.write(" %s\n" % source)
if binaries:
logfile822.write("Binaries:\n")
for binary in binaries:
logfile822.write(" %s\n" % binary)
logfile822.write("Reason: %s\n" % Options["Reason"].replace('\n', '\n '))
if Options["Done"]:
logfile822.write("Bug: %s\n" % Options["Done"])
dsc_type_id = get_override_type('dsc', session).overridetype_id
deb_type_id = get_override_type('deb', session).overridetype_id
# Do the actual deletion
print "Deleting...",
sys.stdout.flush()
for i in to_remove:
package = i[0]
architecture = i[2]
package_id = i[3]
for suite_id in suite_ids_list:
if architecture == "source":
session.execute("DELETE FROM src_associations WHERE source = :packageid AND suite = :suiteid",
{'packageid': package_id, 'suiteid': suite_id})
#print "DELETE FROM src_associations WHERE source = %s AND suite = %s" % (package_id, suite_id)
else:
session.execute("DELETE FROM bin_associations WHERE bin = :packageid AND suite = :suiteid",
{'packageid': package_id, 'suiteid': suite_id})
#print "DELETE FROM bin_associations WHERE bin = %s AND suite = %s" % (package_id, suite_id)
# Delete from the override file
if not Options["Partial"]:
if architecture == "source":
type_id = dsc_type_id
else:
type_id = deb_type_id
# TODO: Again, fix this properly to remove the remaining non-bind argument
session.execute("DELETE FROM override WHERE package = :package AND type = :typeid AND suite = :suiteid %s" % (over_con_components), {'package': package, 'typeid': type_id, 'suiteid': suite_id})
session.commit()
print "done."
# If we don't have a Bug server configured, we're done
if not cnf.has_key("Dinstall::BugServer"):
if Options["Done"] or Options["Do-Close"]:
print "Cannot send mail to BugServer as Dinstall::BugServer is not configured"
logfile.write("=========================================================================\n")
logfile.close()
logfile822.write("\n")
logfile822.close()
return
# read common subst variables for all bug closure mails
Subst_common = {}
Subst_common["__RM_ADDRESS__"] = cnf["Dinstall::MyEmailAddress"]
Subst_common["__BUG_SERVER__"] = cnf["Dinstall::BugServer"]
Subst_common["__CC__"] = "X-DAK: dak rm"
if carbon_copy:
Subst_common["__CC__"] += "\nCc: " + ", ".join(carbon_copy)
Subst_common["__SUITE_LIST__"] = suites_list
Subst_common["__SUBJECT__"] = "Removed package(s) from %s" % (suites_list)
Subst_common["__ADMIN_ADDRESS__"] = cnf["Dinstall::MyAdminAddress"]
Subst_common["__DISTRO__"] = cnf["Dinstall::MyDistribution"]
Subst_common["__WHOAMI__"] = whoami
# Send the bug closing messages
if Options["Done"]:
Subst_close_rm = Subst_common
bcc = []
if cnf.find("Dinstall::Bcc") != "":
bcc.append(cnf["Dinstall::Bcc"])
if cnf.find("Rm::Bcc") != "":
bcc.append(cnf["Rm::Bcc"])
if bcc:
Subst_close_rm["__BCC__"] = "Bcc: " + ", ".join(bcc)
else:
Subst_close_rm["__BCC__"] = "X-Filler: 42"
summarymail = "%s\n------------------- Reason -------------------\n%s\n" % (summary, Options["Reason"])
summarymail += "----------------------------------------------\n"
Subst_close_rm["__SUMMARY__"] = summarymail
whereami = utils.where_am_i()
Archive = get_archive(whereami, session)
if Archive is None:
utils.warn("Cannot find archive %s. Setting blank values for origin" % whereami)
Subst_close_rm["__MASTER_ARCHIVE__"] = ""
Subst_close_rm["__PRIMARY_MIRROR__"] = ""
else:
Subst_close_rm["__MASTER_ARCHIVE__"] = Archive.origin_server
Subst_close_rm["__PRIMARY_MIRROR__"] = Archive.primary_mirror
for bug in utils.split_args(Options["Done"]):
Subst_close_rm["__BUG_NUMBER__"] = bug
if Options["Do-Close"]:
mail_message = utils.TemplateSubst(Subst_close_rm,cnf["Dir::Templates"]+"/rm.bug-close-with-related")
else:
mail_message = utils.TemplateSubst(Subst_close_rm,cnf["Dir::Templates"]+"/rm.bug-close")
utils.send_mail(mail_message)
# close associated bug reports
if Options["Do-Close"]:
Subst_close_other = Subst_common
bcc = []
wnpp = utils.parse_wnpp_bug_file()
versions = list(set([re_bin_only_nmu.sub('', v) for v in versions]))
if len(versions) == 1:
Subst_close_other["__VERSION__"] = versions[0]
else:
utils.fubar("Closing bugs with multiple package versions is not supported. Do it yourself.")
if bcc:
Subst_close_other["__BCC__"] = "Bcc: " + ", ".join(bcc)
else:
Subst_close_other["__BCC__"] = "X-Filler: 42"
# at this point, I just assume, that the first closed bug gives
# some useful information on why the package got removed
Subst_close_other["__BUG_NUMBER__"] = utils.split_args(Options["Done"])[0]
if len(sources) == 1:
source_pkg = source.split("_", 1)[0]
else:
utils.fubar("Closing bugs for multiple source pakcages is not supported. Do it yourself.")
Subst_close_other["__BUG_NUMBER_ALSO__"] = ""
Subst_close_other["__SOURCE__"] = source_pkg
other_bugs = bts.get_bugs('src', source_pkg, 'status', 'open')
if other_bugs:
logfile.write("Also closing bug(s):")
logfile822.write("Also-Bugs:")
for bug in other_bugs:
Subst_close_other["__BUG_NUMBER_ALSO__"] += str(bug) + "-done@" + cnf["Dinstall::BugServer"] + ","
logfile.write(" " + str(bug))
logfile822.write(" " + str(bug))
logfile.write("\n")
logfile822.write("\n")
if source_pkg in wnpp.keys():
logfile.write("Also closing WNPP bug(s):")
logfile822.write("Also-WNPP:")
for bug in wnpp[source_pkg]:
# the wnpp-rm file we parse also contains our removal
# bugs, filtering that out
if bug != Subst_close_other["__BUG_NUMBER__"]:
Subst_close_other["__BUG_NUMBER_ALSO__"] += str(bug) + "-done@" + cnf["Dinstall::BugServer"] + ","
logfile.write(" " + str(bug))
logfile822.write(" " + str(bug))
logfile.write("\n")
logfile822.write("\n")
mail_message = utils.TemplateSubst(Subst_close_other,cnf["Dir::Templates"]+"/rm.bug-close-related")
if Subst_close_other["__BUG_NUMBER_ALSO__"]:
utils.send_mail(mail_message)
logfile.write("=========================================================================\n")
logfile.close()
logfile822.write("\n")
logfile822.close()
#######################################################################################
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
1696,
12016,
2559,
20055,
4744,
367,
14904,
4133,
408,
199,
3,
1898,
334,
35,
9,
12293,
12,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
8315,
221,
1603,
14015,
377,
684,
665,
74,
14015,
32,
23507,
5257,
14,
1308,
30,
199,
3,
1898,
334,
35,
9,
7129,
22986,
11438,
799,
1158,
274,
13,
31936,
278,
15544,
665,
475,
4175,
285,
32,
23204,
14,
1308,
30,
199,
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,
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,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
199,
13289,
199,
199,
3,
312,
3232,
15400,
8099,
15061,
370,
664,
4493,
30147,
972,
1901,
3531,
38,
14,
577,
285,
828,
949,
199,
3,
259,
22722,
14,
199,
3,
312,
30481,
4020,
1035,
3091,
22722,
14,
577,
285,
828,
1233,
82,
1029,
17817,
14,
199,
3,
312,
3232,
15400,
19822,
370,
1852,
4493,
12,
1325,
1454,
315,
3232,
15400,
1350,
199,
3,
259,
3123,
14,
577,
285,
828,
946,
4291,
12,
7545,
14550,
651,
1,
1487,
559,
3424,
26,
298,
3961,
4825,
27805,
9539,
199,
3,
312,
15496,
11040,
313,
644,
285,
14,
199,
3,
312,
3232,
15400,
8099,
19822,
370,
6258,
370,
3365,
3644,
2457,
1334,
6289,
199,
3,
259,
4190,
14,
13821,
7290,
3971,
279,
26,
18414,
922,
1077,
506,
7688,
370,
1852,
199,
3,
259,
4493,
370,
1350,
3123,
14,
3531,
38,
4190,
4875,
3480,
199,
3,
312,
577,
285,
828,
862,
664,
1771,
26,
20065,
12,
5365,
15400,
12,
2868,
15400,
4370,
1,
603,
21659,
6294,
6294,
6294,
40,
21512,
199,
3,
312,
710,
79,
14722,
26,
949,
10296,
12,
18258,
8298,
8034,
2419,
3384,
70,
1,
199,
3,
312,
577,
285,
828,
4493,
25169,
26,
4493,
4190,
14,
11017,
3232,
15400,
911,
440,
1570,
199,
3,
259,
1771,
370,
3384,
70,
14,
577,
285,
828,
2755,
8298,
1655,
4546,
351,
14,
199,
3,
312,
577,
285,
828,
880,
4546,
351,
2075,
351,
14,
1487,
559,
3424,
26,
473,
7,
4464,
9576,
22658,
6515,
2381,
43,
1206,
24164,
15400,
2401,
199,
3,
259,
5363,
906,
1179,
1206,
603,
57,
593,
3705,
15945,
14,
8378,
1645,
1645,
1645,
1645,
14,
199,
199,
3,
12788,
1455,
921,
7001,
3287,
14,
1308,
15,
6223,
14,
1168,
31,
4148,
29,
9969,
2576,
6,
7504,
29,
10740,
708,
3172,
199,
199,
13289,
199,
199,
646,
3718,
199,
646,
747,
199,
646,
984,
199,
646,
20932,
63,
4600,
199,
646,
20932,
63,
3615,
199,
504,
295,
492,
1007,
199,
199,
504,
366,
1151,
773,
14,
888,
492,
4094,
199,
504,
366,
1151,
773,
14,
697,
1631,
492,
627,
199,
504,
366,
1151,
773,
492,
3778,
199,
504,
366,
1151,
773,
14,
983,
75,
63,
3924,
492,
627,
199,
504,
366,
1151,
773,
14,
29283,
492,
295,
63,
1913,
63,
1365,
63,
1023,
12,
295,
63,
1506,
63,
2601,
63,
1047,
12,
295,
63,
1393,
63,
2118,
63,
78,
6553,
199,
646,
477,
9662,
66,
1086,
465,
330,
1086,
199,
199,
13289,
199,
199,
4558,
275,
488,
199,
199,
13289,
199,
199,
318,
4503,
334,
2224,
63,
600,
29,
16,
304,
272,
870,
408,
7692,
26,
366,
1151,
14267,
359,
8808,
61,
510,
3099,
2962,
59,
18737,
199,
5587,
510,
3099,
2962,
8,
83,
9,
687,
5241,
8,
83,
680,
819,
446,
65,
12,
1553,
19134,
29,
7762,
259,
1454,
2454,
641,
642,
15931,
523,
446,
66,
12,
1553,
3008,
5185,
2813,
21984,
1454,
523,
446,
67,
12,
1553,
3173,
29,
20360,
221,
2454,
641,
642,
3931,
523,
446,
35,
12,
1553,
7007,
13520,
13,
1574,
29,
10089,
259,
3222,
282,
17586,
402,
20055,
1245,
370,
32320,
523,
446,
68,
12,
1553,
4456,
29,
4381,
3,
3322,
3222,
20055,
1245,
465,
17903,
370,
6519,
3,
523,
446,
36,
12,
1553,
1117,
13,
1600,
3777,
2597,
4002,
1006,
18227,
4568,
370,
626,
2559,
523,
446,
72,
12,
1553,
3437,
463,
2498,
642,
1720,
436,
4458,
523,
446,
77,
12,
1553,
5764,
29,
9740,
3698,
4499,
367,
20055,
523,
446,
78,
12,
1553,
889,
13,
1287,
3322,
2793,
1133,
886,
7003,
523,
446,
80,
12,
1553,
6672,
4519,
2793,
1133,
12787,
4278,
1584,
523,
446,
50,
12,
1553,
82,
2601,
13,
1074,
3698,
1104,
3837,
5124,
523,
446,
83,
12,
1553,
5768,
29,
6195,
4427,
3515,
2454,
641,
642,
5241,
523,
446,
51,
12,
1553,
1365,
13,
2118,
3515,
2813,
1350,
1454,
199,
199,
7762,
12,
699,
10134,
3,
12,
16503,
17877,
436,
5698,
4427,
883,
506,
10029,
334,
269,
4601,
9,
11673,
5548,
12,
325,
14,
71,
14,
272,
1553,
19134,
29,
21778,
772,
12,
73,
8040,
624,
339,
984,
14,
2224,
8,
2224,
63,
600,
9,
199,
199,
13289,
199,
199,
3,
298,
40,
14577,
265,
26,
14791,
626,
1159,
27254,
12,
626,
1159,
2951,
289,
10112,
316,
27254,
2169,
12,
3063,
4052,
199,
3,
221,
314,
289,
10112,
787,
781,
20042,
370,
886,
31,
2136,
3984,
315,
2005,
3363,
7268,
1033,
390,
3063,
199,
3,
221,
2169,
1396,
17231,
1159,
652,
2169,
12,
9219,
1806,
2169,
12,
9219,
1806,
12,
2169,
1,
25132,
1806,
1,
14791,
199,
3,
221,
314,
289,
10112,
787,
781,
486,
265,
3540,
886,
3063,
31,
14791,
787,
781,
486,
265,
3540,
886,
13472,
199,
199,
318,
9219,
63,
1883,
837,
272,
6385,
275,
3778,
14,
567,
63,
1773,
63,
1210,
480,
24055
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
1696,
12016,
2559,
20055,
4744,
367,
14904,
4133,
408,
199,
3,
1898,
334,
35,
9,
12293,
12,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
8315,
221,
1603,
14015,
377,
684,
665,
74,
14015,
32,
23507,
5257,
14,
1308,
30,
199,
3,
1898,
334,
35,
9,
7129,
22986,
11438,
799,
1158,
274,
13,
31936,
278,
15544,
665,
475,
4175,
285,
32,
23204,
14,
1308,
30,
199,
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,
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,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
199,
13289,
199,
199,
3,
312,
3232,
15400,
8099,
15061,
370,
664,
4493,
30147,
972,
1901,
3531,
38,
14,
577,
285,
828,
949,
199,
3,
259,
22722,
14,
199,
3,
312,
30481,
4020,
1035,
3091,
22722,
14,
577,
285,
828,
1233,
82,
1029,
17817,
14,
199,
3,
312,
3232,
15400,
19822,
370,
1852,
4493,
12,
1325,
1454,
315,
3232,
15400,
1350,
199,
3,
259,
3123,
14,
577,
285,
828,
946,
4291,
12,
7545,
14550,
651,
1,
1487,
559,
3424,
26,
298,
3961,
4825,
27805,
9539,
199,
3,
312,
15496,
11040,
313,
644,
285,
14,
199,
3,
312,
3232,
15400,
8099,
19822,
370,
6258,
370,
3365,
3644,
2457,
1334,
6289,
199,
3,
259,
4190,
14,
13821,
7290,
3971,
279,
26,
18414,
922,
1077,
506,
7688,
370,
1852,
199,
3,
259,
4493,
370,
1350,
3123,
14,
3531,
38,
4190,
4875,
3480,
199,
3,
312,
577,
285,
828,
862,
664,
1771,
26,
20065,
12,
5365,
15400,
12,
2868,
15400,
4370,
1,
603,
21659,
6294,
6294,
6294,
40,
21512,
199,
3,
312,
710,
79,
14722,
26,
949,
10296,
12,
18258,
8298,
8034,
2419,
3384,
70,
1,
199,
3,
312,
577,
285,
828,
4493,
25169,
26,
4493,
4190,
14,
11017,
3232,
15400,
911,
440,
1570,
199,
3,
259,
1771,
370,
3384,
70,
14,
577,
285,
828,
2755,
8298,
1655,
4546,
351,
14,
199,
3,
312,
577,
285,
828,
880,
4546,
351,
2075,
351,
14,
1487,
559,
3424,
26,
473,
7,
4464,
9576,
22658,
6515,
2381,
43,
1206,
24164,
15400,
2401,
199,
3,
259,
5363,
906,
1179,
1206,
603,
57,
593,
3705,
15945,
14,
8378,
1645,
1645,
1645,
1645,
14,
199,
199,
3,
12788,
1455,
921,
7001,
3287,
14,
1308,
15,
6223,
14,
1168,
31,
4148,
29,
9969,
2576,
6,
7504,
29,
10740,
708,
3172,
199,
199,
13289,
199,
199,
646,
3718,
199,
646,
747,
199,
646,
984,
199,
646,
20932,
63,
4600,
199,
646,
20932,
63,
3615,
199,
504,
295,
492,
1007,
199,
199,
504,
366,
1151,
773,
14,
888,
492,
4094,
199,
504,
366,
1151,
773,
14,
697,
1631,
492,
627,
199,
504,
366,
1151,
773,
492,
3778,
199,
504,
366,
1151,
773,
14,
983,
75,
63,
3924,
492,
627,
199,
504,
366,
1151,
773,
14,
29283,
492,
295,
63,
1913,
63,
1365,
63,
1023,
12,
295,
63,
1506,
63,
2601,
63,
1047,
12,
295,
63,
1393,
63,
2118,
63,
78,
6553,
199,
646,
477,
9662,
66,
1086,
465,
330,
1086,
199,
199,
13289,
199,
199,
4558,
275,
488,
199,
199,
13289,
199,
199,
318,
4503,
334,
2224,
63,
600,
29,
16,
304,
272,
870,
408,
7692,
26,
366,
1151,
14267,
359,
8808,
61,
510,
3099,
2962,
59,
18737,
199,
5587,
510,
3099,
2962,
8,
83,
9,
687,
5241,
8,
83,
680,
819,
446,
65,
12,
1553,
19134,
29,
7762,
259,
1454,
2454,
641,
642,
15931,
523,
446,
66,
12,
1553,
3008,
5185,
2813,
21984,
1454,
523,
446,
67,
12,
1553,
3173,
29,
20360,
221,
2454,
641,
642,
3931,
523,
446,
35,
12,
1553,
7007,
13520,
13,
1574,
29,
10089,
259,
3222,
282,
17586,
402,
20055,
1245,
370,
32320,
523,
446,
68,
12,
1553,
4456,
29,
4381,
3,
3322,
3222,
20055,
1245,
465,
17903,
370,
6519,
3,
523,
446,
36,
12,
1553,
1117,
13,
1600,
3777,
2597,
4002,
1006,
18227,
4568,
370,
626,
2559,
523,
446,
72,
12,
1553,
3437,
463,
2498,
642,
1720,
436,
4458,
523,
446,
77,
12,
1553,
5764,
29,
9740,
3698,
4499,
367,
20055,
523,
446,
78,
12,
1553,
889,
13,
1287,
3322,
2793,
1133,
886,
7003,
523,
446,
80,
12,
1553,
6672,
4519,
2793,
1133,
12787,
4278,
1584,
523,
446,
50,
12,
1553,
82,
2601,
13,
1074,
3698,
1104,
3837,
5124,
523,
446,
83,
12,
1553,
5768,
29,
6195,
4427,
3515,
2454,
641,
642,
5241,
523,
446,
51,
12,
1553,
1365,
13,
2118,
3515,
2813,
1350,
1454,
199,
199,
7762,
12,
699,
10134,
3,
12,
16503,
17877,
436,
5698,
4427,
883,
506,
10029,
334,
269,
4601,
9,
11673,
5548,
12,
325,
14,
71,
14,
272,
1553,
19134,
29,
21778,
772,
12,
73,
8040,
624,
339,
984,
14,
2224,
8,
2224,
63,
600,
9,
199,
199,
13289,
199,
199,
3,
298,
40,
14577,
265,
26,
14791,
626,
1159,
27254,
12,
626,
1159,
2951,
289,
10112,
316,
27254,
2169,
12,
3063,
4052,
199,
3,
221,
314,
289,
10112,
787,
781,
20042,
370,
886,
31,
2136,
3984,
315,
2005,
3363,
7268,
1033,
390,
3063,
199,
3,
221,
2169,
1396,
17231,
1159,
652,
2169,
12,
9219,
1806,
2169,
12,
9219,
1806,
12,
2169,
1,
25132,
1806,
1,
14791,
199,
3,
221,
314,
289,
10112,
787,
781,
486,
265,
3540,
886,
3063,
31,
14791,
787,
781,
486,
265,
3540,
886,
13472,
199,
199,
318,
9219,
63,
1883,
837,
272,
6385,
275,
3778,
14,
567,
63,
1773,
63,
1210,
480,
24055,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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from marrow.mongo import Field, Index
from marrow.mongo.trait import Collection
@pytest.fixture
def db(request, connection):
return connection.test
@pytest.fixture
def coll(request, db):
return db.collection
@pytest.fixture
def Sample(request):
class Sample(Collection):
__collection__ = 'collection'
__engine__ = {'mmapv1': {}}
id = None # Remove the default identifier.
field = Field()
other = Field()
_field = Index('field', background=False)
return Sample
class TestDocumentBinding(object):
def test_bind_fail(self, Sample):
with pytest.raises(TypeError):
Sample.bind()
def test_bind_specific_collection(self, coll, Sample):
assert not Sample.__bound__
Sample.bind(coll)
assert Sample.__bound__
def test_bind_specific_collection_twice(self, coll, Sample):
assert not Sample.__bound__
Sample.bind(coll)
assert Sample.__bound__
first = Sample.__bound__
Sample.bind(coll)
assert Sample.__bound__ is first
assert Sample.get_collection() is first
def test_bind_database(self, db, Sample):
assert not Sample.__bound__
Sample.bind(db)
assert Sample.__bound__
def test_create_collection(self, db, Sample):
assert Sample.create_collection(db, drop=True, indexes=False).name == 'collection'
def test_create_bound_collection(self, db, Sample):
assert Sample.bind(db).create_collection(drop=True, indexes=False).name == 'collection'
def test_create_collection_failure(self, Sample):
with pytest.raises(TypeError):
Sample.create_collection()
with pytest.raises(TypeError):
Sample.create_collection("Hoi.")
def test_create_collection_collection(self, db, Sample):
assert Sample.create_collection(db.foo, True).name == 'foo'
def test_get_collection_failure(self, Sample):
with pytest.raises(TypeError):
Sample.get_collection(None)
with pytest.raises(TypeError):
Sample.get_collection("Hoi.")
def test_validation(self, db, Sample):
if tuple((int(i) for i in db.client.server_info()['version'].split('.')[:3])) < (3, 2):
pytest.xfail("Test expected to fail on MongoDB versions prior to 3.2.")
Sample.__validate__ = 'strict'
Sample.__validator__ = {'field': {'$gt': 27}}
c = Sample.create_collection(db, True, indexes=False)
c.insert_one(Sample(42))
with pytest.raises(WriteError):
c.insert_one(Sample(12))
def test_index_construction(self, db, Sample):
c = Sample.create_collection(db, True, indexes=False)
Sample.create_indexes(c, True)
indexes = c.index_information()
assert '_field' in indexes
del indexes['_field']['v']
assert indexes['_field'] == {
'background': False,
'key': [('field', 1)],
'ns': 'test.collection',
'sparse': False
}
def test_update_empty(self, db, Sample):
Sample.bind(db).create_collection(drop=True)
with pytest.raises(TypeError):
Sample().update_one()
|
mit
|
[
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
4613,
199,
504,
21878,
14,
2550,
492,
6990,
547,
199,
199,
504,
7557,
1143,
14,
9217,
492,
5024,
12,
5499,
199,
504,
7557,
1143,
14,
9217,
14,
22687,
492,
18003,
421,
199,
32,
4462,
14,
5997,
199,
318,
1592,
8,
1069,
12,
1950,
304,
199,
198,
1107,
1950,
14,
396,
421,
199,
32,
4462,
14,
5997,
199,
318,
23721,
8,
1069,
12,
1592,
304,
199,
198,
1107,
1592,
14,
3627,
421,
199,
32,
4462,
14,
5997,
199,
318,
15227,
8,
1069,
304,
199,
198,
533,
15227,
8,
7768,
304,
507,
198,
363,
3627,
363,
275,
283,
3627,
7,
507,
198,
363,
3908,
363,
275,
791,
20671,
86,
17,
356,
24312,
9068,
198,
344,
275,
488,
221,
327,
5852,
314,
849,
5148,
14,
507,
198,
698,
275,
5024,
342,
507,
198,
1848,
275,
5024,
342,
9068,
198,
63,
698,
275,
5499,
360,
698,
297,
8020,
29,
797,
9,
8299,
198,
1107,
15227,
421,
199,
533,
1379,
5564,
17490,
8,
785,
304,
199,
198,
318,
511,
63,
3409,
63,
1633,
8,
277,
12,
15227,
304,
507,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
3409,
342,
8299,
198,
318,
511,
63,
3409,
63,
6100,
63,
3627,
8,
277,
12,
23721,
12,
15227,
304,
507,
198,
479,
440,
15227,
855,
3556,
363,
9068,
198,
8176,
14,
3409,
8,
15772,
9,
9068,
198,
479,
15227,
855,
3556,
363,
8299,
198,
318,
511,
63,
3409,
63,
6100,
63,
3627,
63,
8122,
1885,
8,
277,
12,
23721,
12,
15227,
304,
507,
198,
479,
440,
15227,
855,
3556,
363,
9068,
198,
8176,
14,
3409,
8,
15772,
9,
9068,
198,
479,
15227,
855,
3556,
363,
9068,
198,
2246,
275,
15227,
855,
3556,
363,
507,
198,
8176,
14,
3409,
8,
15772,
9,
9068,
198,
479,
15227,
855,
3556,
363,
365,
1642,
9068,
198,
479,
15227,
14,
362,
63,
3627,
342,
365,
1642,
8299,
198,
318,
511,
63,
3409,
63,
4659,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
440,
15227,
855,
3556,
363,
9068,
198,
8176,
14,
3409,
8,
697,
9,
9068,
198,
479,
15227,
855,
3556,
363,
8299,
198,
318,
511,
63,
981,
63,
3627,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
15227,
14,
981,
63,
3627,
8,
697,
12,
5978,
29,
549,
12,
10507,
29,
797,
680,
354,
508,
283,
3627,
7,
8299,
198,
318,
511,
63,
981,
63,
3556,
63,
3627,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
15227,
14,
3409,
8,
697,
680,
981,
63,
3627,
8,
4824,
29,
549,
12,
10507,
29,
797,
680,
354,
508,
283,
3627,
7,
8299,
198,
318,
511,
63,
981,
63,
3627,
63,
5328,
8,
277,
12,
15227,
304,
507,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
981,
63,
3627,
342,
9068,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
981,
63,
3627,
480,
40,
16142,
2685,
8299,
198,
318,
511,
63,
981,
63,
3627,
63,
3627,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
15227,
14,
981,
63,
3627,
8,
697,
14,
1421,
12,
715,
680,
354,
508,
283,
1421,
7,
8299,
198,
318,
511,
63,
362,
63,
3627,
63,
5328,
8,
277,
12,
15227,
304,
507,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
362,
63,
3627,
8,
403,
9,
9068,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
362,
63,
3627,
480,
40,
16142,
2685,
8299,
198,
318,
511,
63,
6136,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
692,
2008,
1332,
442,
8,
73,
9,
367,
284,
315,
1592,
14,
1258,
14,
1000,
63,
815,
12047,
1023,
2278,
1294,
7563,
1491,
19,
2459,
665,
334,
19,
12,
499,
304,
686,
198,
4462,
14,
22557,
480,
774,
1420,
370,
2449,
641,
28458,
5459,
6791,
370,
650,
14,
18,
2685,
9068,
198,
8176,
855,
3502,
363,
275,
283,
4768,
7,
507,
198,
8176,
855,
11034,
363,
275,
791,
698,
356,
30108,
3308,
356,
8087,
4863,
507,
198,
67,
275,
15227,
14,
981,
63,
3627,
8,
697,
12,
715,
12,
10507,
29,
797,
9,
9068,
198,
67,
14,
3176,
63,
368,
8,
8176,
8,
2260,
430,
9068,
198,
1045,
4613,
14,
3536,
8,
3534,
547,
304,
686,
198,
67,
14,
3176,
63,
368,
8,
8176,
8,
713,
430,
8299,
198,
318,
511,
63,
1080,
63,
12708,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
67,
275,
15227,
14,
981,
63,
3627,
8,
697,
12,
715,
12,
10507,
29,
797,
9,
507,
198,
8176,
14,
981,
63,
10116,
8,
67,
12,
715,
9,
9068,
198,
10116,
275,
286,
14,
1080,
63,
11697,
342,
507,
198,
479,
2513,
698,
7,
315,
10507,
507,
198,
2264,
10507,
8680,
698,
2545,
86,
418,
507,
198,
479,
10507,
8680,
698,
418,
508,
469,
1585,
198,
7,
7451,
356,
756,
12,
1585,
198,
7,
498,
356,
4274,
698,
297,
413,
4360,
1585,
198,
7,
561,
356,
283,
396,
14,
3627,
297,
1585,
198,
1159,
1122,
356,
756,
686,
198,
93,
8299,
198,
318,
511,
63,
873,
63,
1667,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
8176,
14,
3409,
8,
697,
680,
981,
63,
3627,
8,
4824,
29,
549,
9,
9068,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
1252,
873,
63,
368,
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
] |
[
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
4613,
199,
504,
21878,
14,
2550,
492,
6990,
547,
199,
199,
504,
7557,
1143,
14,
9217,
492,
5024,
12,
5499,
199,
504,
7557,
1143,
14,
9217,
14,
22687,
492,
18003,
421,
199,
32,
4462,
14,
5997,
199,
318,
1592,
8,
1069,
12,
1950,
304,
199,
198,
1107,
1950,
14,
396,
421,
199,
32,
4462,
14,
5997,
199,
318,
23721,
8,
1069,
12,
1592,
304,
199,
198,
1107,
1592,
14,
3627,
421,
199,
32,
4462,
14,
5997,
199,
318,
15227,
8,
1069,
304,
199,
198,
533,
15227,
8,
7768,
304,
507,
198,
363,
3627,
363,
275,
283,
3627,
7,
507,
198,
363,
3908,
363,
275,
791,
20671,
86,
17,
356,
24312,
9068,
198,
344,
275,
488,
221,
327,
5852,
314,
849,
5148,
14,
507,
198,
698,
275,
5024,
342,
507,
198,
1848,
275,
5024,
342,
9068,
198,
63,
698,
275,
5499,
360,
698,
297,
8020,
29,
797,
9,
8299,
198,
1107,
15227,
421,
199,
533,
1379,
5564,
17490,
8,
785,
304,
199,
198,
318,
511,
63,
3409,
63,
1633,
8,
277,
12,
15227,
304,
507,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
3409,
342,
8299,
198,
318,
511,
63,
3409,
63,
6100,
63,
3627,
8,
277,
12,
23721,
12,
15227,
304,
507,
198,
479,
440,
15227,
855,
3556,
363,
9068,
198,
8176,
14,
3409,
8,
15772,
9,
9068,
198,
479,
15227,
855,
3556,
363,
8299,
198,
318,
511,
63,
3409,
63,
6100,
63,
3627,
63,
8122,
1885,
8,
277,
12,
23721,
12,
15227,
304,
507,
198,
479,
440,
15227,
855,
3556,
363,
9068,
198,
8176,
14,
3409,
8,
15772,
9,
9068,
198,
479,
15227,
855,
3556,
363,
9068,
198,
2246,
275,
15227,
855,
3556,
363,
507,
198,
8176,
14,
3409,
8,
15772,
9,
9068,
198,
479,
15227,
855,
3556,
363,
365,
1642,
9068,
198,
479,
15227,
14,
362,
63,
3627,
342,
365,
1642,
8299,
198,
318,
511,
63,
3409,
63,
4659,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
440,
15227,
855,
3556,
363,
9068,
198,
8176,
14,
3409,
8,
697,
9,
9068,
198,
479,
15227,
855,
3556,
363,
8299,
198,
318,
511,
63,
981,
63,
3627,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
15227,
14,
981,
63,
3627,
8,
697,
12,
5978,
29,
549,
12,
10507,
29,
797,
680,
354,
508,
283,
3627,
7,
8299,
198,
318,
511,
63,
981,
63,
3556,
63,
3627,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
15227,
14,
3409,
8,
697,
680,
981,
63,
3627,
8,
4824,
29,
549,
12,
10507,
29,
797,
680,
354,
508,
283,
3627,
7,
8299,
198,
318,
511,
63,
981,
63,
3627,
63,
5328,
8,
277,
12,
15227,
304,
507,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
981,
63,
3627,
342,
9068,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
981,
63,
3627,
480,
40,
16142,
2685,
8299,
198,
318,
511,
63,
981,
63,
3627,
63,
3627,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
479,
15227,
14,
981,
63,
3627,
8,
697,
14,
1421,
12,
715,
680,
354,
508,
283,
1421,
7,
8299,
198,
318,
511,
63,
362,
63,
3627,
63,
5328,
8,
277,
12,
15227,
304,
507,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
362,
63,
3627,
8,
403,
9,
9068,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
14,
362,
63,
3627,
480,
40,
16142,
2685,
8299,
198,
318,
511,
63,
6136,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
692,
2008,
1332,
442,
8,
73,
9,
367,
284,
315,
1592,
14,
1258,
14,
1000,
63,
815,
12047,
1023,
2278,
1294,
7563,
1491,
19,
2459,
665,
334,
19,
12,
499,
304,
686,
198,
4462,
14,
22557,
480,
774,
1420,
370,
2449,
641,
28458,
5459,
6791,
370,
650,
14,
18,
2685,
9068,
198,
8176,
855,
3502,
363,
275,
283,
4768,
7,
507,
198,
8176,
855,
11034,
363,
275,
791,
698,
356,
30108,
3308,
356,
8087,
4863,
507,
198,
67,
275,
15227,
14,
981,
63,
3627,
8,
697,
12,
715,
12,
10507,
29,
797,
9,
9068,
198,
67,
14,
3176,
63,
368,
8,
8176,
8,
2260,
430,
9068,
198,
1045,
4613,
14,
3536,
8,
3534,
547,
304,
686,
198,
67,
14,
3176,
63,
368,
8,
8176,
8,
713,
430,
8299,
198,
318,
511,
63,
1080,
63,
12708,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
67,
275,
15227,
14,
981,
63,
3627,
8,
697,
12,
715,
12,
10507,
29,
797,
9,
507,
198,
8176,
14,
981,
63,
10116,
8,
67,
12,
715,
9,
9068,
198,
10116,
275,
286,
14,
1080,
63,
11697,
342,
507,
198,
479,
2513,
698,
7,
315,
10507,
507,
198,
2264,
10507,
8680,
698,
2545,
86,
418,
507,
198,
479,
10507,
8680,
698,
418,
508,
469,
1585,
198,
7,
7451,
356,
756,
12,
1585,
198,
7,
498,
356,
4274,
698,
297,
413,
4360,
1585,
198,
7,
561,
356,
283,
396,
14,
3627,
297,
1585,
198,
1159,
1122,
356,
756,
686,
198,
93,
8299,
198,
318,
511,
63,
873,
63,
1667,
8,
277,
12,
1592,
12,
15227,
304,
507,
198,
8176,
14,
3409,
8,
697,
680,
981,
63,
3627,
8,
4824,
29,
549,
9,
9068,
198,
1045,
4613,
14,
3536,
8,
4333,
304,
686,
198,
8176,
1252,
873,
63,
368,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
import numpy as np
from vispy import glsl
from . collection import Collection
from ..transforms import NullTransform
class RawPathCollection(Collection):
"""
"""
def __init__(self, user_dtype=None, transform=None,
vertex=None, fragment=None, **kwargs):
"""
Initialize the collection.
Parameters
----------
user_dtype: list
The base dtype can be completed (appended) by the used_dtype. It
only make sense if user also provide vertex and/or fragment shaders
transform : Transform instance
Used to define the transform(vec4) function
vertex: string
Vertex shader code
fragment: string
Fragment shader code
color : string
'local', 'shared' or 'global'
"""
base_dtype = [('position', (np.float32, 3), '!local', (0, 0, 0)),
('id', (np.float32, 1), '!local', 0),
('color', (np.float32, 4), 'local', (0, 0, 0, 1)),
("linewidth", (np.float32, 1), 'global', 1),
("viewport", (np.float32, 4), 'global', (0, 0, 512, 512))
]
dtype = base_dtype
if user_dtype:
dtype.extend(user_dtype)
if vertex is None:
vertex = glsl.get('collections/raw-path.vert')
if transform is None:
transform = NullTransform()
self.transform = transform
if fragment is None:
fragment = glsl.get('collections/raw-path.frag')
vertex = transform + vertex
Collection.__init__(self, dtype=dtype, itype=None, mode='line_strip',
vertex=vertex, fragment=fragment, **kwargs)
self._programs[0].vert['transform'] = self.transform
def append(self, P, closed=False, itemsize=None, **kwargs):
"""
Append a new set of vertices to the collection.
For kwargs argument, n is the number of vertices (local) or the number
of item (shared)
Parameters
----------
P : np.array
Vertices positions of the path(s) to be added
closed: bool
Whether path(s) is/are closed
itemsize: int or None
Size of an individual path
color : list, array or 4-tuple
Path color
"""
itemsize = itemsize or len(P)
itemcount = len(P) / itemsize
P = P.reshape(itemcount, itemsize, 3)
if closed:
V = np.empty((itemcount, itemsize + 3), dtype=self.vtype)
# Apply default values on vertices
for name in self.vtype.names:
if name not in ['collection_index', 'position']:
V[name][1:-2] = kwargs.get(name, self._defaults[name])
V["position"][:, 1:-2] = P
V["position"][:, -2] = V["position"][:, 1]
else:
V = np.empty((itemcount, itemsize + 2), dtype=self.vtype)
# Apply default values on vertices
for name in self.vtype.names:
if name not in ['collection_index', 'position']:
V[name][1:-1] = kwargs.get(name, self._defaults[name])
V["position"][:, 1:-1] = P
V["id"] = 1
V[:, 0] = V[:, 1]
V[:, -1] = V[:, -2]
V["id"][:, 0] = 0
V["id"][:, -1] = 0
# Uniforms
if self.utype:
U = np.zeros(itemcount, dtype=self.utype)
for name in self.utype.names:
if name not in ["__unused__"]:
U[name] = kwargs.get(name, self._defaults[name])
else:
U = None
Collection.append(self, vertices=V, uniforms=U,
itemsize=itemsize + 2 + closed)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
13722,
199,
3,
1898,
334,
67,
9,
6927,
12,
30650,
761,
305,
510,
14,
19776,
71,
4446,
199,
3,
17484,
1334,
314,
334,
1222,
9,
6289,
844,
14,
1666,
5113,
14,
2424,
367,
1655,
2256,
14,
199,
3,
13722,
199,
646,
2680,
465,
980,
199,
504,
21370,
647,
492,
486,
478,
76,
199,
504,
1275,
3245,
492,
18003,
199,
504,
2508,
15133,
492,
12119,
6939,
421,
199,
533,
13480,
2042,
7768,
8,
7768,
304,
339,
408,
272,
408,
339,
347,
636,
826,
721,
277,
12,
922,
63,
2271,
29,
403,
12,
5793,
29,
403,
12,
326,
12759,
29,
403,
12,
7956,
29,
403,
12,
1011,
958,
304,
267,
408,
267,
11578,
314,
3245,
14,
398,
3897,
267,
4143,
398,
922,
63,
2271,
26,
769,
288,
710,
1300,
2152,
883,
506,
9709,
334,
5435,
770,
9,
701,
314,
1202,
63,
2271,
14,
2779,
288,
1454,
1852,
12249,
340,
922,
2597,
5647,
12759,
436,
15,
269,
7956,
25958,
83,
398,
5793,
520,
19463,
1256,
288,
8051,
370,
5627,
314,
5793,
8,
6046,
20,
9,
805,
398,
12759,
26,
1059,
288,
5444,
3858,
25958,
1233,
398,
7956,
26,
1059,
288,
481,
4338,
221,
25958,
1233,
398,
3164,
520,
1059,
288,
283,
1832,
297,
283,
5555,
7,
503,
283,
2966,
7,
267,
408,
398,
1300,
63,
2271,
275,
4274,
3124,
297,
334,
1590,
14,
1609,
708,
12,
650,
395,
14597,
1832,
297,
334,
16,
12,
378,
12,
378,
1826,
1993,
661,
344,
297,
755,
334,
1590,
14,
1609,
708,
12,
413,
395,
14597,
1832,
297,
378,
395,
1993,
661,
2326,
297,
259,
334,
1590,
14,
1609,
708,
12,
841,
395,
283,
1832,
297,
334,
16,
12,
378,
12,
378,
12,
413,
1826,
1993,
1689,
24643,
401,
334,
1590,
14,
1609,
708,
12,
413,
395,
283,
2966,
297,
413,
395,
1993,
1689,
25484,
401,
334,
1590,
14,
1609,
708,
12,
841,
395,
283,
2966,
297,
334,
16,
12,
378,
12,
10574,
12,
10574,
430,
1993,
1622,
398,
2152,
275,
1300,
63,
2271,
267,
340,
922,
63,
2271,
26,
288,
2152,
14,
2880,
8,
751,
63,
2271,
9,
398,
340,
12759,
365,
488,
26,
288,
12759,
275,
486,
478,
76,
14,
362,
360,
7882,
15,
1773,
13,
515,
14,
1884,
358,
267,
340,
5793,
365,
488,
26,
288,
5793,
275,
12119,
6939,
342,
267,
291,
14,
4711,
275,
5793,
18418,
340,
7956,
365,
488,
26,
288,
7956,
275,
486,
478,
76,
14,
362,
360,
7882,
15,
1773,
13,
515,
14,
11255,
358,
398,
12759,
275,
5793,
435,
12759,
267,
18003,
855,
826,
721,
277,
12,
2152,
29,
2271,
12,
284,
466,
29,
403,
12,
818,
534,
604,
63,
1913,
297,
1169,
12759,
29,
11417,
12,
7956,
29,
7677,
12,
1011,
958,
9,
267,
291,
423,
28464,
59,
16,
1055,
1884,
459,
4711,
418,
275,
291,
14,
4711,
339,
347,
5666,
8,
277,
12,
510,
12,
6876,
29,
797,
12,
1242,
890,
29,
403,
12,
1011,
958,
304,
267,
408,
267,
18726,
282,
892,
663,
402,
14971,
370,
314,
3245,
14,
398,
2104,
2074,
1423,
12,
302,
365,
314,
1329,
402,
14971,
334,
1832,
9,
503,
314,
1329,
267,
402,
1242,
334,
5555,
9,
398,
3897,
267,
4143,
398,
510,
520,
980,
14,
1144,
288,
5444,
7724,
12266,
402,
314,
931,
8,
83,
9,
370,
506,
3483,
398,
6876,
26,
2155,
288,
7480,
931,
8,
83,
9,
365,
15,
1530,
6876,
398,
1242,
890,
26,
1109,
503,
488,
288,
14579,
402,
376,
8212,
931,
398,
3164,
520,
769,
12,
1625,
503,
841,
13,
2960,
1779,
6912,
3164,
267,
408,
398,
1242,
890,
275,
1242,
890,
503,
822,
8,
48,
9,
267,
1242,
835,
275,
822,
8,
48,
9,
1182,
1242,
890,
267,
510,
275,
510,
14,
5217,
8,
1053,
835,
12,
1242,
890,
12,
650,
9,
267,
340,
6876,
26,
288,
812,
275,
980,
14,
1667,
1332,
1053,
835,
12,
1242,
890,
435,
650,
395,
2152,
29,
277,
14,
86,
466,
9,
288,
327,
14618,
849,
1338,
641,
14971,
288,
367,
536,
315,
291,
14,
86,
466,
14,
1247,
26,
355,
340,
536,
440,
315,
788,
3627,
63,
1080,
297,
283,
3124,
2565,
490,
812,
59,
354,
1527,
17,
6809,
18,
61,
275,
2074,
14,
362,
8,
354,
12,
291,
423,
4322,
59,
354,
566,
288,
812,
905,
3124,
937,
3981,
413,
6809,
18,
61,
275,
510,
288,
812,
905,
3124,
937,
3981,
221,
446,
18,
61,
275,
812,
905,
3124,
937,
3981,
413,
61,
267,
587,
26,
288,
812,
275,
980,
14,
1667,
1332,
1053,
835,
12,
1242,
890,
435,
499,
395,
2152,
29,
277,
14,
86,
466,
9,
288,
327,
14618,
849,
1338,
641,
14971,
288,
367,
536,
315,
291,
14,
86,
466,
14,
1247,
26,
355,
340,
536,
440,
315,
788,
3627,
63,
1080,
297,
283,
3124,
2565,
490,
812,
59,
354,
1527,
17,
6809,
17,
61,
275,
2074,
14,
362,
8,
354,
12,
291,
423,
4322,
59,
354,
566,
288,
812,
905,
3124,
937,
3981,
413,
6809,
17,
61,
275,
510,
267,
812,
905,
344,
937,
275,
413,
267,
812,
3981,
378,
61,
275,
812,
3981,
413,
61,
267,
812,
3981,
446,
17,
61,
275,
812,
3981,
446,
18,
61,
267,
812,
905,
344,
937,
3981,
378,
61,
275,
378,
267,
812,
905,
344,
937,
3981,
446,
17,
61,
275,
378,
398,
327,
1910,
73,
3351,
267,
340,
291,
14,
337,
514,
26,
288,
738,
275,
980,
14,
4250,
8,
1053,
835,
12,
2152,
29,
277,
14,
337,
514,
9,
288,
367,
536,
315,
291,
14,
337,
514,
14,
1247,
26,
355,
340,
536,
440,
315,
2097,
363,
8618,
363,
6229,
490,
738,
59,
354,
61,
275,
2074,
14,
362,
8,
354,
12,
291,
423,
4322,
59,
354,
566,
267,
587,
26,
288,
738,
275,
488,
398,
18003,
14,
740,
8,
277,
12,
14971,
29,
54,
12,
15439,
3351,
29,
53,
12,
2079,
1242,
890,
29,
21210,
435,
499,
435,
6876,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
13722,
199,
3,
1898,
334,
67,
9,
6927,
12,
30650,
761,
305,
510,
14,
19776,
71,
4446,
199,
3,
17484,
1334,
314,
334,
1222,
9,
6289,
844,
14,
1666,
5113,
14,
2424,
367,
1655,
2256,
14,
199,
3,
13722,
199,
646,
2680,
465,
980,
199,
504,
21370,
647,
492,
486,
478,
76,
199,
504,
1275,
3245,
492,
18003,
199,
504,
2508,
15133,
492,
12119,
6939,
421,
199,
533,
13480,
2042,
7768,
8,
7768,
304,
339,
408,
272,
408,
339,
347,
636,
826,
721,
277,
12,
922,
63,
2271,
29,
403,
12,
5793,
29,
403,
12,
326,
12759,
29,
403,
12,
7956,
29,
403,
12,
1011,
958,
304,
267,
408,
267,
11578,
314,
3245,
14,
398,
3897,
267,
4143,
398,
922,
63,
2271,
26,
769,
288,
710,
1300,
2152,
883,
506,
9709,
334,
5435,
770,
9,
701,
314,
1202,
63,
2271,
14,
2779,
288,
1454,
1852,
12249,
340,
922,
2597,
5647,
12759,
436,
15,
269,
7956,
25958,
83,
398,
5793,
520,
19463,
1256,
288,
8051,
370,
5627,
314,
5793,
8,
6046,
20,
9,
805,
398,
12759,
26,
1059,
288,
5444,
3858,
25958,
1233,
398,
7956,
26,
1059,
288,
481,
4338,
221,
25958,
1233,
398,
3164,
520,
1059,
288,
283,
1832,
297,
283,
5555,
7,
503,
283,
2966,
7,
267,
408,
398,
1300,
63,
2271,
275,
4274,
3124,
297,
334,
1590,
14,
1609,
708,
12,
650,
395,
14597,
1832,
297,
334,
16,
12,
378,
12,
378,
1826,
1993,
661,
344,
297,
755,
334,
1590,
14,
1609,
708,
12,
413,
395,
14597,
1832,
297,
378,
395,
1993,
661,
2326,
297,
259,
334,
1590,
14,
1609,
708,
12,
841,
395,
283,
1832,
297,
334,
16,
12,
378,
12,
378,
12,
413,
1826,
1993,
1689,
24643,
401,
334,
1590,
14,
1609,
708,
12,
413,
395,
283,
2966,
297,
413,
395,
1993,
1689,
25484,
401,
334,
1590,
14,
1609,
708,
12,
841,
395,
283,
2966,
297,
334,
16,
12,
378,
12,
10574,
12,
10574,
430,
1993,
1622,
398,
2152,
275,
1300,
63,
2271,
267,
340,
922,
63,
2271,
26,
288,
2152,
14,
2880,
8,
751,
63,
2271,
9,
398,
340,
12759,
365,
488,
26,
288,
12759,
275,
486,
478,
76,
14,
362,
360,
7882,
15,
1773,
13,
515,
14,
1884,
358,
267,
340,
5793,
365,
488,
26,
288,
5793,
275,
12119,
6939,
342,
267,
291,
14,
4711,
275,
5793,
18418,
340,
7956,
365,
488,
26,
288,
7956,
275,
486,
478,
76,
14,
362,
360,
7882,
15,
1773,
13,
515,
14,
11255,
358,
398,
12759,
275,
5793,
435,
12759,
267,
18003,
855,
826,
721,
277,
12,
2152,
29,
2271,
12,
284,
466,
29,
403,
12,
818,
534,
604,
63,
1913,
297,
1169,
12759,
29,
11417,
12,
7956,
29,
7677,
12,
1011,
958,
9,
267,
291,
423,
28464,
59,
16,
1055,
1884,
459,
4711,
418,
275,
291,
14,
4711,
339,
347,
5666,
8,
277,
12,
510,
12,
6876,
29,
797,
12,
1242,
890,
29,
403,
12,
1011,
958,
304,
267,
408,
267,
18726,
282,
892,
663,
402,
14971,
370,
314,
3245,
14,
398,
2104,
2074,
1423,
12,
302,
365,
314,
1329,
402,
14971,
334,
1832,
9,
503,
314,
1329,
267,
402,
1242,
334,
5555,
9,
398,
3897,
267,
4143,
398,
510,
520,
980,
14,
1144,
288,
5444,
7724,
12266,
402,
314,
931,
8,
83,
9,
370,
506,
3483,
398,
6876,
26,
2155,
288,
7480,
931,
8,
83,
9,
365,
15,
1530,
6876,
398,
1242,
890,
26,
1109,
503,
488,
288,
14579,
402,
376,
8212,
931,
398,
3164,
520,
769,
12,
1625,
503,
841,
13,
2960,
1779,
6912,
3164,
267,
408,
398,
1242,
890,
275,
1242,
890,
503,
822,
8,
48,
9,
267,
1242,
835,
275,
822,
8,
48,
9,
1182,
1242,
890,
267,
510,
275,
510,
14,
5217,
8,
1053,
835,
12,
1242,
890,
12,
650,
9,
267,
340,
6876,
26,
288,
812,
275,
980,
14,
1667,
1332,
1053,
835,
12,
1242,
890,
435,
650,
395,
2152,
29,
277,
14,
86,
466,
9,
288,
327,
14618,
849,
1338,
641,
14971,
288,
367,
536,
315,
291,
14,
86,
466,
14,
1247,
26,
355,
340,
536,
440,
315,
788,
3627,
63,
1080,
297,
283,
3124,
2565,
490,
812,
59,
354,
1527,
17,
6809,
18,
61,
275,
2074,
14,
362,
8,
354,
12,
291,
423,
4322,
59,
354,
566,
288,
812,
905,
3124,
937,
3981,
413,
6809,
18,
61,
275,
510,
288,
812,
905,
3124,
937,
3981,
221,
446,
18,
61,
275,
812,
905,
3124,
937,
3981,
413,
61,
267,
587,
26,
288,
812,
275,
980,
14,
1667,
1332,
1053,
835,
12,
1242,
890,
435,
499,
395,
2152,
29,
277,
14,
86,
466,
9,
288,
327,
14618,
849,
1338,
641,
14971,
288,
367,
536,
315,
291,
14,
86,
466,
14,
1247,
26,
355,
340,
536,
440,
315,
788,
3627,
63,
1080,
297,
283,
3124,
2565,
490,
812,
59,
354,
1527,
17,
6809,
17,
61,
275,
2074,
14,
362,
8,
354,
12,
291,
423,
4322,
59,
354,
566,
288,
812,
905,
3124,
937,
3981,
413,
6809,
17,
61,
275,
510,
267,
812,
905,
344,
937,
275,
413,
267,
812,
3981,
378,
61,
275,
812,
3981,
413,
61,
267,
812,
3981,
446,
17,
61,
275,
812,
3981,
446,
18,
61,
267,
812,
905,
344,
937,
3981,
378,
61,
275,
378,
267,
812,
905,
344,
937,
3981,
446,
17,
61,
275,
378,
398,
327,
1910,
73,
3351,
267,
340,
291,
14,
337,
514,
26,
288,
738,
275,
980,
14,
4250,
8,
1053,
835,
12,
2152,
29,
277,
14,
337,
514,
9,
288,
367,
536,
315,
291,
14,
337,
514,
14,
1247,
26,
355,
340,
536,
440,
315,
2097,
363,
8618,
363,
6229,
490,
738,
59,
354,
61,
275,
2074,
14,
362,
8,
354,
12,
291,
423,
4322,
59,
354,
566,
267,
587,
26,
288,
738,
275,
488,
398,
18003,
14,
740,
8,
277,
12,
14971,
29,
54,
12,
15439,
3351,
29,
53,
12,
2079,
1242,
890,
29,
21210,
435,
499,
435,
6876,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
5731
|
# -*- coding: utf-8 -*-
#
import sys
import os
# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
sys.path.insert(0, "../")
import ghettoq
from django.conf import settings
if not settings.configured:
settings.configure()
# General configuration
# ---------------------
# Add any Sphinx extension module names here, as strings.
# They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['.templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'ghettoq'
copyright = u'2009, Opera Softare (WebTeam)'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = ".".join(map(str, ghettoq.VERSION[0:2]))
# The full version, including alpha/beta/rc tags.
release = ghettoq.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['.build']
# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'trac'
#html_translator_class = "djangodocs.DjangoHTMLTranslator"
# Options for HTML output
# -----------------------
# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
#html_style = 'agogo.css'
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['.static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
html_use_modindex = True
# If false, no index is generated.
html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, the reST sources are included in the HTML build as _sources/<name>.
#html_copy_source = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'ghettoqdoc'
# Options for LaTeX output
# ------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class
# [howto/manual]).
latex_documents = [
('index', 'ghettoq.tex', ur'ghettoq Documentation',
ur'Ask Solem', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True
html_theme = "nature"
html_theme_path = ["_theme"]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
646,
984,
199,
646,
747,
199,
199,
3,
982,
2195,
5478,
787,
315,
4573,
2082,
12,
1050,
652,
2348,
14,
982,
314,
2082,
199,
3,
365,
3847,
370,
314,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
199,
3,
3679,
12,
2839,
9164,
2348,
14,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
29024,
531,
199,
646,
23310,
386,
475,
81,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
692,
440,
2202,
14,
11786,
26,
272,
2202,
14,
6472,
342,
199,
199,
3,
1696,
2897,
199,
3,
10652,
9858,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
199,
3,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
18953,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
3561,
386,
475,
81,
7,
199,
7307,
275,
399,
7,
8664,
12,
6654,
65,
428,
1618,
502,
264,
334,
5926,
13126,
3171,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
32443,
904,
8,
1130,
8,
495,
12,
23310,
386,
475,
81,
14,
4612,
59,
16,
26,
18,
2459,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
23310,
386,
475,
81,
855,
1023,
363,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
8247,
626,
9296,
1133,
506,
5120,
315,
314,
1900,
14,
199,
3,
8618,
63,
4757,
275,
942,
199,
199,
3,
3820,
402,
6602,
12,
3847,
370,
1350,
2082,
12,
626,
9296,
1133,
506,
17543,
199,
3,
367,
1350,
1584,
14,
199,
5473,
63,
14635,
275,
18953,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
199,
3,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
23047,
7,
199,
199,
3,
1360,
63,
29346,
63,
533,
275,
298,
12816,
364,
14851,
14,
9323,
4943,
26059,
2,
421,
199,
3,
8394,
367,
4163,
1072,
199,
3,
10652,
12797,
199,
199,
3,
710,
3449,
12083,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
437,
570,
402,
626,
536,
199,
3,
1471,
2187,
1902,
315,
10229,
7,
2955,
15,
931,
12,
503,
315,
1373,
402,
314,
3537,
3792,
199,
3,
1627,
315,
3517,
63,
1986,
63,
515,
14,
199,
3,
1360,
63,
2487,
275,
283,
643,
974,
79,
14,
3919,
7,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63,
22229,
275,
488,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
2955,
1584,
334,
10180,
465,
3449,
24405,
9,
2348,
12,
199,
3,
3847,
370,
642,
2082,
14,
9322,
787,
8876,
2410,
314,
6762,
2955,
1584,
12,
199,
3,
880,
282,
570,
4310,
298,
885,
14,
3919,
2,
911,
8970,
314,
6762,
298,
885,
14,
3919,
1674,
199,
1360,
63,
1986,
63,
515,
275,
18953,
1986,
418,
199,
199,
3,
982,
440,
3260,
282,
283,
6090,
4588,
641,
4881,
4913,
365,
11788,
737,
4036,
2034,
9048,
12,
199,
3,
1808,
314,
1627,
14053,
1475,
14,
199,
3,
1360,
63,
2019,
63,
5334,
63,
5045,
275,
1543,
66,
450,
68,
12,
450,
57,
7,
199,
199,
3,
982
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
646,
984,
199,
646,
747,
199,
199,
3,
982,
2195,
5478,
787,
315,
4573,
2082,
12,
1050,
652,
2348,
14,
982,
314,
2082,
199,
3,
365,
3847,
370,
314,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
199,
3,
3679,
12,
2839,
9164,
2348,
14,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
29024,
531,
199,
646,
23310,
386,
475,
81,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
692,
440,
2202,
14,
11786,
26,
272,
2202,
14,
6472,
342,
199,
199,
3,
1696,
2897,
199,
3,
10652,
9858,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
199,
3,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
18953,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
3561,
386,
475,
81,
7,
199,
7307,
275,
399,
7,
8664,
12,
6654,
65,
428,
1618,
502,
264,
334,
5926,
13126,
3171,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
32443,
904,
8,
1130,
8,
495,
12,
23310,
386,
475,
81,
14,
4612,
59,
16,
26,
18,
2459,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
23310,
386,
475,
81,
855,
1023,
363,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
8247,
626,
9296,
1133,
506,
5120,
315,
314,
1900,
14,
199,
3,
8618,
63,
4757,
275,
942,
199,
199,
3,
3820,
402,
6602,
12,
3847,
370,
1350,
2082,
12,
626,
9296,
1133,
506,
17543,
199,
3,
367,
1350,
1584,
14,
199,
5473,
63,
14635,
275,
18953,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
199,
3,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
23047,
7,
199,
199,
3,
1360,
63,
29346,
63,
533,
275,
298,
12816,
364,
14851,
14,
9323,
4943,
26059,
2,
421,
199,
3,
8394,
367,
4163,
1072,
199,
3,
10652,
12797,
199,
199,
3,
710,
3449,
12083,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
437,
570,
402,
626,
536,
199,
3,
1471,
2187,
1902,
315,
10229,
7,
2955,
15,
931,
12,
503,
315,
1373,
402,
314,
3537,
3792,
199,
3,
1627,
315,
3517,
63,
1986,
63,
515,
14,
199,
3,
1360,
63,
2487,
275,
283,
643,
974,
79,
14,
3919,
7,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63,
22229,
275,
488,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
2955,
1584,
334,
10180,
465,
3449,
24405,
9,
2348,
12,
199,
3,
3847,
370,
642,
2082,
14,
9322,
787,
8876,
2410,
314,
6762,
2955,
1584,
12,
199,
3,
880,
282,
570,
4310,
298,
885,
14,
3919,
2,
911,
8970,
314,
6762,
298,
885,
14,
3919,
1674,
199,
1360,
63,
1986,
63,
515,
275,
18953,
1986,
418,
199,
199,
3,
982,
440,
3260,
282,
283,
6090,
4588,
641,
4881,
4913,
365,
11788,
737,
4036,
2034,
9048,
12,
199,
3,
1808,
314,
1627,
14053,
1475,
14,
199,
3,
1360,
63,
2019,
63,
5334,
63,
5045,
275,
1543,
66,
450,
68,
12,
450,
57,
7,
199,
199,
3,
982,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
git001/openshift-ansible
|
utils/test/openshift_ansible_tests.py
|
14
|
2542
|
import os
import unittest
import tempfile
import shutil
from six.moves import configparser
from ooinstall import openshift_ansible
from ooinstall.oo_config import Host, OOConfig
BASE_CONFIG = """
---
variant: openshift-enterprise
variant_version: 3.3
version: v2
deployment:
ansible_ssh_user: cloud-user
hosts: []
roles:
master:
node:
"""
class TestOpenShiftAnsible(unittest.TestCase):
def setUp(self):
self.tempfiles = []
self.work_dir = tempfile.mkdtemp(prefix='openshift_ansible_tests')
self.configfile = os.path.join(self.work_dir, 'ooinstall.config')
with open(self.configfile, 'w') as config_file:
config_file.write(BASE_CONFIG)
self.inventory = os.path.join(self.work_dir, 'hosts')
config = OOConfig(self.configfile)
config.settings['ansible_inventory_path'] = self.inventory
openshift_ansible.set_config(config)
def tearDown(self):
shutil.rmtree(self.work_dir)
def test_generate_inventory_new_nodes(self):
hosts = generate_hosts(1, 'master', roles=(['master', 'etcd']))
hosts.extend(generate_hosts(1, 'node', roles=['node']))
hosts.extend(generate_hosts(1, 'new_node', roles=['node'], new_host=True))
openshift_ansible.generate_inventory(hosts)
inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(self.inventory)
self.assertTrue(inventory.has_section('new_nodes'))
self.assertTrue(inventory.has_option('new_nodes', 'new_node1'))
def test_write_inventory_vars_role_vars(self):
with open(self.inventory, 'w') as inv:
openshift_ansible.CFG.deployment.roles['master'].variables = {'color': 'blue'}
openshift_ansible.CFG.deployment.roles['node'].variables = {'color': 'green'}
openshift_ansible.write_inventory_vars(inv, None)
inventory = configparser.ConfigParser(allow_no_value=True)
inventory.read(self.inventory)
self.assertTrue(inventory.has_section('masters:vars'))
self.assertEquals('blue', inventory.get('masters:vars', 'color'))
self.assertTrue(inventory.has_section('nodes:vars'))
self.assertEquals('green', inventory.get('nodes:vars', 'color'))
def generate_hosts(num_hosts, name_prefix, roles=None, new_host=False):
hosts = []
for num in range(1, num_hosts + 1):
hosts.append(Host(connect_to=name_prefix + str(num),
roles=roles, new_host=new_host))
return hosts
|
apache-2.0
|
[
646,
747,
199,
646,
2882,
199,
646,
5549,
199,
646,
5145,
199,
199,
504,
3816,
14,
4912,
492,
21230,
199,
199,
504,
16390,
3174,
492,
1551,
4723,
63,
4853,
199,
504,
16390,
3174,
14,
1534,
63,
888,
492,
10891,
12,
593,
47,
2028,
421,
199,
5825,
63,
5569,
275,
408,
199,
2595,
199,
8759,
26,
1551,
4723,
13,
24375,
199,
8759,
63,
1023,
26,
650,
14,
19,
199,
1023,
26,
373,
18,
199,
13605,
26,
272,
3242,
63,
5510,
63,
751,
26,
8002,
13,
751,
272,
7057,
26,
942,
272,
11689,
26,
267,
5288,
26,
267,
1031,
26,
199,
624,
421,
199,
533,
1379,
4299,
14379,
10047,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
808,
1725,
275,
942,
267,
291,
14,
800,
63,
694,
275,
5549,
14,
11983,
8,
1861,
534,
22858,
63,
4853,
63,
2219,
358,
267,
291,
14,
29217,
275,
747,
14,
515,
14,
904,
8,
277,
14,
800,
63,
694,
12,
283,
1534,
3174,
14,
888,
358,
267,
543,
1551,
8,
277,
14,
29217,
12,
283,
87,
358,
465,
1101,
63,
493,
26,
288,
1101,
63,
493,
14,
952,
8,
5825,
63,
5569,
9,
267,
291,
14,
7212,
275,
747,
14,
515,
14,
904,
8,
277,
14,
800,
63,
694,
12,
283,
5146,
358,
267,
1101,
275,
593,
47,
2028,
8,
277,
14,
29217,
9,
267,
1101,
14,
1751,
459,
4853,
63,
7212,
63,
515,
418,
275,
291,
14,
7212,
267,
1551,
4723,
63,
4853,
14,
409,
63,
888,
8,
888,
9,
339,
347,
6766,
8,
277,
304,
267,
5145,
14,
9242,
8,
277,
14,
800,
63,
694,
9,
339,
347,
511,
63,
4208,
63,
7212,
63,
1222,
63,
2415,
8,
277,
304,
267,
7057,
275,
3550,
63,
5146,
8,
17,
12,
283,
4133,
297,
11689,
2687,
459,
4133,
297,
283,
29604,
5156,
267,
7057,
14,
2880,
8,
4208,
63,
5146,
8,
17,
12,
283,
932,
297,
11689,
2968,
932,
5156,
267,
7057,
14,
2880,
8,
4208,
63,
5146,
8,
17,
12,
283,
1222,
63,
932,
297,
11689,
2968,
932,
995,
892,
63,
1102,
29,
549,
430,
267,
1551,
4723,
63,
4853,
14,
4208,
63,
7212,
8,
5146,
9,
267,
8200,
275,
21230,
14,
15218,
8,
3306,
63,
889,
63,
585,
29,
549,
9,
267,
8200,
14,
739,
8,
277,
14,
7212,
9,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
2792,
360,
1222,
63,
2415,
1333,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
1422,
360,
1222,
63,
2415,
297,
283,
1222,
63,
932,
17,
1333,
339,
347,
511,
63,
952,
63,
7212,
63,
2936,
63,
3756,
63,
2936,
8,
277,
304,
267,
543,
1551,
8,
277,
14,
7212,
12,
283,
87,
358,
465,
4572,
26,
288,
1551,
4723,
63,
4853,
14,
10118,
14,
13605,
14,
8050,
459,
4133,
2278,
3669,
275,
791,
2326,
356,
283,
6304,
936,
288,
1551,
4723,
63,
4853,
14,
10118,
14,
13605,
14,
8050,
459,
932,
2278,
3669,
275,
791,
2326,
356,
283,
7731,
936,
288,
1551,
4723,
63,
4853,
14,
952,
63,
7212,
63,
2936,
8,
5350,
12,
488,
9,
398,
8200,
275,
21230,
14,
15218,
8,
3306,
63,
889,
63,
585,
29,
549,
9,
267,
8200,
14,
739,
8,
277,
14,
7212,
9,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
2792,
360,
5892,
878,
26,
2936,
1333,
267,
291,
14,
2947,
360,
6304,
297,
8200,
14,
362,
360,
5892,
878,
26,
2936,
297,
283,
2326,
1333,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
2792,
360,
2415,
26,
2936,
1333,
267,
291,
14,
2947,
360,
7731,
297,
8200,
14,
362,
360,
2415,
26,
2936,
297,
283,
2326,
1333,
421,
199,
318,
3550,
63,
5146,
8,
1507,
63,
5146,
12,
536,
63,
1861,
12,
11689,
29,
403,
12,
892,
63,
1102,
29,
797,
304,
272,
7057,
275,
942,
272,
367,
1967,
315,
1425,
8,
17,
12,
1967,
63,
5146,
435,
413,
304,
267,
7057,
14,
740,
8,
4965,
8,
2242,
63,
475,
29,
354,
63,
1861,
435,
620,
8,
1507,
395,
2079,
11689,
29,
8050,
12,
892,
63,
1102,
29,
1222,
63,
1102,
430,
272,
372,
7057,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2882,
199,
646,
5549,
199,
646,
5145,
199,
199,
504,
3816,
14,
4912,
492,
21230,
199,
199,
504,
16390,
3174,
492,
1551,
4723,
63,
4853,
199,
504,
16390,
3174,
14,
1534,
63,
888,
492,
10891,
12,
593,
47,
2028,
421,
199,
5825,
63,
5569,
275,
408,
199,
2595,
199,
8759,
26,
1551,
4723,
13,
24375,
199,
8759,
63,
1023,
26,
650,
14,
19,
199,
1023,
26,
373,
18,
199,
13605,
26,
272,
3242,
63,
5510,
63,
751,
26,
8002,
13,
751,
272,
7057,
26,
942,
272,
11689,
26,
267,
5288,
26,
267,
1031,
26,
199,
624,
421,
199,
533,
1379,
4299,
14379,
10047,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
808,
1725,
275,
942,
267,
291,
14,
800,
63,
694,
275,
5549,
14,
11983,
8,
1861,
534,
22858,
63,
4853,
63,
2219,
358,
267,
291,
14,
29217,
275,
747,
14,
515,
14,
904,
8,
277,
14,
800,
63,
694,
12,
283,
1534,
3174,
14,
888,
358,
267,
543,
1551,
8,
277,
14,
29217,
12,
283,
87,
358,
465,
1101,
63,
493,
26,
288,
1101,
63,
493,
14,
952,
8,
5825,
63,
5569,
9,
267,
291,
14,
7212,
275,
747,
14,
515,
14,
904,
8,
277,
14,
800,
63,
694,
12,
283,
5146,
358,
267,
1101,
275,
593,
47,
2028,
8,
277,
14,
29217,
9,
267,
1101,
14,
1751,
459,
4853,
63,
7212,
63,
515,
418,
275,
291,
14,
7212,
267,
1551,
4723,
63,
4853,
14,
409,
63,
888,
8,
888,
9,
339,
347,
6766,
8,
277,
304,
267,
5145,
14,
9242,
8,
277,
14,
800,
63,
694,
9,
339,
347,
511,
63,
4208,
63,
7212,
63,
1222,
63,
2415,
8,
277,
304,
267,
7057,
275,
3550,
63,
5146,
8,
17,
12,
283,
4133,
297,
11689,
2687,
459,
4133,
297,
283,
29604,
5156,
267,
7057,
14,
2880,
8,
4208,
63,
5146,
8,
17,
12,
283,
932,
297,
11689,
2968,
932,
5156,
267,
7057,
14,
2880,
8,
4208,
63,
5146,
8,
17,
12,
283,
1222,
63,
932,
297,
11689,
2968,
932,
995,
892,
63,
1102,
29,
549,
430,
267,
1551,
4723,
63,
4853,
14,
4208,
63,
7212,
8,
5146,
9,
267,
8200,
275,
21230,
14,
15218,
8,
3306,
63,
889,
63,
585,
29,
549,
9,
267,
8200,
14,
739,
8,
277,
14,
7212,
9,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
2792,
360,
1222,
63,
2415,
1333,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
1422,
360,
1222,
63,
2415,
297,
283,
1222,
63,
932,
17,
1333,
339,
347,
511,
63,
952,
63,
7212,
63,
2936,
63,
3756,
63,
2936,
8,
277,
304,
267,
543,
1551,
8,
277,
14,
7212,
12,
283,
87,
358,
465,
4572,
26,
288,
1551,
4723,
63,
4853,
14,
10118,
14,
13605,
14,
8050,
459,
4133,
2278,
3669,
275,
791,
2326,
356,
283,
6304,
936,
288,
1551,
4723,
63,
4853,
14,
10118,
14,
13605,
14,
8050,
459,
932,
2278,
3669,
275,
791,
2326,
356,
283,
7731,
936,
288,
1551,
4723,
63,
4853,
14,
952,
63,
7212,
63,
2936,
8,
5350,
12,
488,
9,
398,
8200,
275,
21230,
14,
15218,
8,
3306,
63,
889,
63,
585,
29,
549,
9,
267,
8200,
14,
739,
8,
277,
14,
7212,
9,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
2792,
360,
5892,
878,
26,
2936,
1333,
267,
291,
14,
2947,
360,
6304,
297,
8200,
14,
362,
360,
5892,
878,
26,
2936,
297,
283,
2326,
1333,
267,
291,
14,
1815,
8,
7212,
14,
1989,
63,
2792,
360,
2415,
26,
2936,
1333,
267,
291,
14,
2947,
360,
7731,
297,
8200,
14,
362,
360,
2415,
26,
2936,
297,
283,
2326,
1333,
421,
199,
318,
3550,
63,
5146,
8,
1507,
63,
5146,
12,
536,
63,
1861,
12,
11689,
29,
403,
12,
892,
63,
1102,
29,
797,
304,
272,
7057,
275,
942,
272,
367,
1967,
315,
1425,
8,
17,
12,
1967,
63,
5146,
435,
413,
304,
267,
7057,
14,
740,
8,
4965,
8,
2242,
63,
475,
29,
354,
63,
1861,
435,
620,
8,
1507,
395,
2079,
11689,
29,
8050,
12,
892,
63,
1102,
29,
1222,
63,
1102,
430,
272,
372,
7057,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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served.
#
# 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.
# ==============================================================================
"""Slim is an interface to contrib functions, examples and models.
TODO(nsilberman): flesh out documentation.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# pylint: disable=unused-import,line-too-long,g-importing-member,wildcard-import
# TODO(jart): Delete non-slim imports
from tensorflow.contrib import losses
from tensorflow.contrib import metrics
from tensorflow.contrib.framework.python.ops.arg_scope import *
from tensorflow.contrib.framework.python.ops.variables import *
from tensorflow.contrib.layers.python.layers import *
from tensorflow.contrib.layers.python.layers.initializers import *
from tensorflow.contrib.layers.python.layers.regularizers import *
from tensorflow.contrib.slim.python.slim import evaluation
from tensorflow.contrib.slim.python.slim import learning
from tensorflow.contrib.slim.python.slim import model_analyzer
from tensorflow.contrib.slim.python.slim import queues
from tensorflow.contrib.slim.python.slim.data import data_decoder
from tensorflow.contrib.slim.python.slim.data import data_provider
from tensorflow.contrib.slim.python.slim.data import dataset
from tensorflow.contrib.slim.python.slim.data import dataset_data_provider
from tensorflow.contrib.slim.python.slim.data import parallel_reader
from tensorflow.contrib.slim.python.slim.data import prefetch_queue
from tensorflow.contrib.slim.python.slim.data import tfexample_decoder
from tensorflow.python.util.all_util import make_all
# pylint: enable=unused-import,line-too-long,g-importing-member,wildcard-import
__all__ = make_all(__name__)
|
gpl-3.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,
51,
4175,
365,
376,
3217,
370,
5914,
3423,
12,
7251,
436,
1709,
14,
199,
199,
11768,
8,
78,
20329,
605,
1237,
304,
289,
274,
609,
734,
3794,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
12,
16692,
13,
646,
199,
3,
3254,
8,
74,
580,
304,
8496,
2222,
13,
30393,
8925,
199,
504,
3228,
14,
2828,
492,
21289,
199,
504,
3228,
14,
2828,
492,
7186,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
14,
1273,
63,
2645,
492,
627,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
14,
3669,
492,
627,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
492,
627,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
14,
2747,
6315,
492,
627,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
14,
7898,
6315,
492,
627,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
11735,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
9328,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
1402,
63,
17965,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
21366,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
666,
63,
8813,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
666,
63,
3780,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
4789,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
4789,
63,
576,
63,
3780,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
9861,
63,
5503,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
21544,
63,
1825,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
2833,
2694,
63,
8813,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
1852,
63,
452,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
12,
16692,
13,
646,
199,
199,
363,
452,
363,
275,
1852,
63,
452,
3460,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
51,
4175,
365,
376,
3217,
370,
5914,
3423,
12,
7251,
436,
1709,
14,
199,
199,
11768,
8,
78,
20329,
605,
1237,
304,
289,
274,
609,
734,
3794,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
12,
16692,
13,
646,
199,
3,
3254,
8,
74,
580,
304,
8496,
2222,
13,
30393,
8925,
199,
504,
3228,
14,
2828,
492,
21289,
199,
504,
3228,
14,
2828,
492,
7186,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
14,
1273,
63,
2645,
492,
627,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
14,
3669,
492,
627,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
492,
627,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
14,
2747,
6315,
492,
627,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
14,
7898,
6315,
492,
627,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
11735,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
9328,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
1402,
63,
17965,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
492,
21366,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
666,
63,
8813,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
666,
63,
3780,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
4789,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
4789,
63,
576,
63,
3780,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
9861,
63,
5503,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
21544,
63,
1825,
199,
504,
3228,
14,
2828,
14,
30393,
14,
1548,
14,
30393,
14,
576,
492,
2833,
2694,
63,
8813,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
1852,
63,
452,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
12,
604,
13,
7354,
13,
2809,
12,
71,
13,
646,
316,
13,
1114,
12,
16692,
13,
646,
199,
199,
363,
452,
363,
275,
1852,
63,
452,
3460,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
sbuss/voteswap
|
lib/setuptools/command/install_egg_info.py
|
112
|
4035
|
from distutils import log, dir_util
import os
from setuptools.extern.six.moves import map
from setuptools import Command
from setuptools.archive_util import unpack_archive
import pkg_resources
class install_egg_info(Command):
"""Install an .egg-info directory for the package"""
description = "Install an .egg-info directory for the package"
user_options = [
('install-dir=', 'd', "directory to install to"),
]
def initialize_options(self):
self.install_dir = None
def finalize_options(self):
self.set_undefined_options('install_lib',
('install_dir', 'install_dir'))
ei_cmd = self.get_finalized_command("egg_info")
basename = pkg_resources.Distribution(
None, None, ei_cmd.egg_name, ei_cmd.egg_version
).egg_name() + '.egg-info'
self.source = ei_cmd.egg_info
self.target = os.path.join(self.install_dir, basename)
self.outputs = []
def run(self):
self.run_command('egg_info')
if os.path.isdir(self.target) and not os.path.islink(self.target):
dir_util.remove_tree(self.target, dry_run=self.dry_run)
elif os.path.exists(self.target):
self.execute(os.unlink, (self.target,), "Removing " + self.target)
if not self.dry_run:
pkg_resources.ensure_directory(self.target)
self.execute(
self.copytree, (), "Copying %s to %s" % (self.source, self.target)
)
self.install_namespaces()
def get_outputs(self):
return self.outputs
def copytree(self):
# Copy the .egg-info tree to site-packages
def skimmer(src, dst):
# filter out source-control directories; note that 'src' is always
# a '/'-separated path, regardless of platform. 'dst' is a
# platform-specific path.
for skip in '.svn/', 'CVS/':
if src.startswith(skip) or '/' + skip in src:
return None
self.outputs.append(dst)
log.debug("Copying %s to %s", src, dst)
return dst
unpack_archive(self.source, self.target, skimmer)
def install_namespaces(self):
nsp = self._get_all_ns_packages()
if not nsp:
return
filename, ext = os.path.splitext(self.target)
filename += '-nspkg.pth'
self.outputs.append(filename)
log.info("Installing %s", filename)
lines = map(self._gen_nspkg_line, nsp)
if self.dry_run:
# always generate the lines, even in dry run
list(lines)
return
with open(filename, 'wt') as f:
f.writelines(lines)
_nspkg_tmpl = (
"import sys, types, os",
"p = os.path.join(sys._getframe(1).f_locals['sitedir'], *%(pth)r)",
"ie = os.path.exists(os.path.join(p,'__init__.py'))",
"m = not ie and "
"sys.modules.setdefault(%(pkg)r, types.ModuleType(%(pkg)r))",
"mp = (m or []) and m.__dict__.setdefault('__path__',[])",
"(p not in mp) and mp.append(p)",
)
"lines for the namespace installer"
_nspkg_tmpl_multi = (
'm and setattr(sys.modules[%(parent)r], %(child)r, m)',
)
"additional line(s) when a parent package is indicated"
@classmethod
def _gen_nspkg_line(cls, pkg):
# ensure pkg is not a unicode string under Python 2.7
pkg = str(pkg)
pth = tuple(pkg.split('.'))
tmpl_lines = cls._nspkg_tmpl
parent, sep, child = pkg.rpartition('.')
if parent:
tmpl_lines += cls._nspkg_tmpl_multi
return ';'.join(tmpl_lines) % locals() + '\n'
def _get_all_ns_packages(self):
"""Return sorted list of all package namespaces"""
nsp = set()
for pkg in self.distribution.namespace_packages or []:
pkg = pkg.split('.')
while pkg:
nsp.add('.'.join(pkg))
pkg.pop()
return sorted(nsp)
|
mit
|
[
504,
7065,
492,
943,
12,
2935,
63,
1974,
199,
646,
747,
199,
199,
504,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
2341,
199,
199,
504,
9116,
492,
5817,
199,
504,
9116,
14,
6404,
63,
1974,
492,
7787,
63,
6404,
199,
646,
5496,
63,
4435,
421,
199,
533,
3907,
63,
5799,
63,
815,
8,
3110,
304,
272,
408,
8154,
376,
1275,
5799,
13,
815,
2082,
367,
314,
2559,
624,
339,
1369,
275,
298,
8154,
376,
1275,
5799,
13,
815,
2082,
367,
314,
2559,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
3174,
13,
694,
4009,
283,
68,
297,
298,
3619,
370,
3907,
370,
1288,
272,
1622,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
291,
14,
3174,
63,
694,
275,
488,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
291,
14,
409,
63,
10705,
63,
1419,
360,
3174,
63,
773,
297,
3521,
661,
3174,
63,
694,
297,
283,
3174,
63,
694,
1333,
267,
20654,
63,
1760,
275,
291,
14,
362,
63,
19231,
63,
1531,
480,
5799,
63,
815,
531,
267,
9593,
275,
5496,
63,
4435,
14,
8580,
8,
288,
488,
12,
488,
12,
20654,
63,
1760,
14,
5799,
63,
354,
12,
20654,
63,
1760,
14,
5799,
63,
1023,
267,
7092,
5799,
63,
354,
342,
435,
1987,
5799,
13,
815,
7,
267,
291,
14,
1365,
275,
20654,
63,
1760,
14,
5799,
63,
815,
267,
291,
14,
1375,
275,
747,
14,
515,
14,
904,
8,
277,
14,
3174,
63,
694,
12,
9593,
9,
267,
291,
14,
4467,
275,
942,
339,
347,
1255,
8,
277,
304,
267,
291,
14,
1065,
63,
1531,
360,
5799,
63,
815,
358,
267,
340,
747,
14,
515,
14,
6027,
8,
277,
14,
1375,
9,
436,
440,
747,
14,
515,
14,
20719,
8,
277,
14,
1375,
304,
288,
2935,
63,
1974,
14,
2168,
63,
2350,
8,
277,
14,
1375,
12,
9951,
63,
1065,
29,
277,
14,
10481,
63,
1065,
9,
267,
916,
747,
14,
515,
14,
2444,
8,
277,
14,
1375,
304,
288,
291,
14,
2526,
8,
736,
14,
7162,
12,
334,
277,
14,
1375,
4706,
298,
23420,
298,
435,
291,
14,
1375,
9,
267,
340,
440,
291,
14,
10481,
63,
1065,
26,
288,
5496,
63,
4435,
14,
7505,
63,
3619,
8,
277,
14,
1375,
9,
267,
291,
14,
2526,
8,
288,
291,
14,
29296,
12,
11969,
298,
32596,
450,
83,
370,
450,
83,
2,
450,
334,
277,
14,
1365,
12,
291,
14,
1375,
9,
267,
776,
267,
291,
14,
3174,
63,
9247,
342,
339,
347,
664,
63,
4467,
8,
277,
304,
267,
372,
291,
14,
4467,
339,
347,
1331,
2350,
8,
277,
304,
267,
327,
11247,
314,
1275,
5799,
13,
815,
3123,
370,
4770,
13,
5154,
267,
347,
2386,
1017,
2626,
8,
2164,
12,
5042,
304,
288,
327,
2457,
734,
1350,
13,
2785,
6602,
27,
5317,
626,
283,
2164,
7,
365,
3544,
288,
327,
282,
7324,
13,
12794,
931,
12,
15270,
402,
4298,
14,
221,
283,
5119,
7,
365,
282,
288,
327,
4298,
13,
6100,
931,
14,
288,
367,
3372,
315,
1987,
6836,
3678,
283,
35,
7428,
25772,
355,
340,
2928,
14,
2460,
8,
2759,
9,
503,
7324,
435,
3372,
315,
2928,
26,
490,
372,
488,
288,
291,
14,
4467,
14,
740,
8,
5119,
9,
288,
943,
14,
1757,
480,
32596,
450,
83,
370,
450,
83,
401,
2928,
12,
5042,
9,
288,
372,
5042,
398,
7787,
63,
6404,
8,
277,
14,
1365,
12,
291,
14,
1375,
12,
2386,
1017,
2626,
9,
339,
347,
3907,
63,
9247,
8,
277,
304,
267,
302,
681,
275,
291,
423,
362,
63,
452,
63,
561,
63,
5154,
342,
267,
340,
440,
302,
681,
26,
288,
372,
267,
1788,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
277,
14,
1375,
9,
267,
1788,
847,
2475,
561,
4600,
14,
13316,
7,
267,
291,
14,
4467,
14,
740,
8,
1501,
9,
267,
943,
14,
815,
480,
31376,
450,
83,
401,
1788,
9,
267,
2385,
275,
2341,
8,
277,
423,
2268,
63,
561,
4600,
63,
604,
12,
302,
681,
9,
398,
340,
291,
14,
10481,
63,
1065,
26,
288,
327,
3544,
3550,
314,
2385,
12,
2755,
315,
9951,
1255,
288,
769,
8,
1278,
9,
288,
372,
398,
543,
1551,
8,
1501,
12,
283,
9115,
358,
465,
289,
26,
288,
289,
14,
23277,
8,
1278,
9,
339,
485,
561,
4600,
63,
11510,
275,
334,
267,
298,
646,
984,
12,
2943,
12,
747,
401,
267,
298,
80,
275,
747,
14,
515,
14,
904,
8,
1274,
423,
20912,
8,
17,
680,
70,
63,
9350,
459,
2124,
694,
995,
627,
2840,
13316,
9,
82,
4186,
267,
298,
1873,
275,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
80,
2584,
363,
826,
4343,
647,
1333,
401,
267,
298,
77,
275,
440,
13446,
436,
298,
288,
298,
1274,
14,
3112,
14,
5486,
12473,
4600,
9,
82,
12,
2943,
14,
21820,
12473,
4600,
9,
82,
430,
401,
267,
298,
311,
275,
334,
77,
503,
3073,
436,
333,
855,
807,
4343,
5486,
10714,
515,
7500,
59,
566,
401,
267,
7340,
80,
440,
315,
6118,
9,
436,
6118,
14,
740,
8,
80,
4186,
272,
776,
272,
298,
1278,
367,
314,
3231,
18535,
2,
339,
485,
561,
4600,
63,
11510,
63,
3029,
275,
334,
267,
283,
77,
436,
5371,
8,
1274,
14,
3112,
59,
2840,
1708,
9,
82,
467,
2818,
1739,
9,
82,
12,
333,
3196,
272,
776,
272,
298,
8460,
1004,
8,
83,
9,
1380,
282,
1676,
2559,
365,
22141,
2,
339,
768,
3744,
272,
347,
485,
2268,
63,
561,
4600,
63,
604,
8,
1886,
12,
5496,
304,
267,
327,
4868,
5496,
365,
440,
282,
2649,
1059,
1334,
2018,
499,
14,
23,
267,
5496,
275,
620,
8,
4600,
9,
267,
25504,
275,
2008,
8,
4600,
14,
1294,
24535,
267,
9675,
63,
1278,
275,
843,
423,
561,
4600,
63,
11510,
267,
1676,
12,
7375,
12,
1982,
275,
5496,
14,
25817,
7563,
267,
340,
1676,
26,
288,
9675,
63,
1278,
847,
843,
423,
561,
4600,
63,
11510,
63,
3029,
267,
372,
30955,
904,
8,
11510,
63,
1278,
9,
450,
9480,
342,
435,
1557,
78,
7,
339,
347,
485,
362,
63,
452,
63,
561,
63,
5154,
8,
277,
304,
267,
408,
1767,
3355,
769,
402,
1006,
2559,
10747,
624,
267,
302,
681,
275,
663,
342
] |
[
7065,
492,
943,
12,
2935,
63,
1974,
199,
646,
747,
199,
199,
504,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
2341,
199,
199,
504,
9116,
492,
5817,
199,
504,
9116,
14,
6404,
63,
1974,
492,
7787,
63,
6404,
199,
646,
5496,
63,
4435,
421,
199,
533,
3907,
63,
5799,
63,
815,
8,
3110,
304,
272,
408,
8154,
376,
1275,
5799,
13,
815,
2082,
367,
314,
2559,
624,
339,
1369,
275,
298,
8154,
376,
1275,
5799,
13,
815,
2082,
367,
314,
2559,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
3174,
13,
694,
4009,
283,
68,
297,
298,
3619,
370,
3907,
370,
1288,
272,
1622,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
291,
14,
3174,
63,
694,
275,
488,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
291,
14,
409,
63,
10705,
63,
1419,
360,
3174,
63,
773,
297,
3521,
661,
3174,
63,
694,
297,
283,
3174,
63,
694,
1333,
267,
20654,
63,
1760,
275,
291,
14,
362,
63,
19231,
63,
1531,
480,
5799,
63,
815,
531,
267,
9593,
275,
5496,
63,
4435,
14,
8580,
8,
288,
488,
12,
488,
12,
20654,
63,
1760,
14,
5799,
63,
354,
12,
20654,
63,
1760,
14,
5799,
63,
1023,
267,
7092,
5799,
63,
354,
342,
435,
1987,
5799,
13,
815,
7,
267,
291,
14,
1365,
275,
20654,
63,
1760,
14,
5799,
63,
815,
267,
291,
14,
1375,
275,
747,
14,
515,
14,
904,
8,
277,
14,
3174,
63,
694,
12,
9593,
9,
267,
291,
14,
4467,
275,
942,
339,
347,
1255,
8,
277,
304,
267,
291,
14,
1065,
63,
1531,
360,
5799,
63,
815,
358,
267,
340,
747,
14,
515,
14,
6027,
8,
277,
14,
1375,
9,
436,
440,
747,
14,
515,
14,
20719,
8,
277,
14,
1375,
304,
288,
2935,
63,
1974,
14,
2168,
63,
2350,
8,
277,
14,
1375,
12,
9951,
63,
1065,
29,
277,
14,
10481,
63,
1065,
9,
267,
916,
747,
14,
515,
14,
2444,
8,
277,
14,
1375,
304,
288,
291,
14,
2526,
8,
736,
14,
7162,
12,
334,
277,
14,
1375,
4706,
298,
23420,
298,
435,
291,
14,
1375,
9,
267,
340,
440,
291,
14,
10481,
63,
1065,
26,
288,
5496,
63,
4435,
14,
7505,
63,
3619,
8,
277,
14,
1375,
9,
267,
291,
14,
2526,
8,
288,
291,
14,
29296,
12,
11969,
298,
32596,
450,
83,
370,
450,
83,
2,
450,
334,
277,
14,
1365,
12,
291,
14,
1375,
9,
267,
776,
267,
291,
14,
3174,
63,
9247,
342,
339,
347,
664,
63,
4467,
8,
277,
304,
267,
372,
291,
14,
4467,
339,
347,
1331,
2350,
8,
277,
304,
267,
327,
11247,
314,
1275,
5799,
13,
815,
3123,
370,
4770,
13,
5154,
267,
347,
2386,
1017,
2626,
8,
2164,
12,
5042,
304,
288,
327,
2457,
734,
1350,
13,
2785,
6602,
27,
5317,
626,
283,
2164,
7,
365,
3544,
288,
327,
282,
7324,
13,
12794,
931,
12,
15270,
402,
4298,
14,
221,
283,
5119,
7,
365,
282,
288,
327,
4298,
13,
6100,
931,
14,
288,
367,
3372,
315,
1987,
6836,
3678,
283,
35,
7428,
25772,
355,
340,
2928,
14,
2460,
8,
2759,
9,
503,
7324,
435,
3372,
315,
2928,
26,
490,
372,
488,
288,
291,
14,
4467,
14,
740,
8,
5119,
9,
288,
943,
14,
1757,
480,
32596,
450,
83,
370,
450,
83,
401,
2928,
12,
5042,
9,
288,
372,
5042,
398,
7787,
63,
6404,
8,
277,
14,
1365,
12,
291,
14,
1375,
12,
2386,
1017,
2626,
9,
339,
347,
3907,
63,
9247,
8,
277,
304,
267,
302,
681,
275,
291,
423,
362,
63,
452,
63,
561,
63,
5154,
342,
267,
340,
440,
302,
681,
26,
288,
372,
267,
1788,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
277,
14,
1375,
9,
267,
1788,
847,
2475,
561,
4600,
14,
13316,
7,
267,
291,
14,
4467,
14,
740,
8,
1501,
9,
267,
943,
14,
815,
480,
31376,
450,
83,
401,
1788,
9,
267,
2385,
275,
2341,
8,
277,
423,
2268,
63,
561,
4600,
63,
604,
12,
302,
681,
9,
398,
340,
291,
14,
10481,
63,
1065,
26,
288,
327,
3544,
3550,
314,
2385,
12,
2755,
315,
9951,
1255,
288,
769,
8,
1278,
9,
288,
372,
398,
543,
1551,
8,
1501,
12,
283,
9115,
358,
465,
289,
26,
288,
289,
14,
23277,
8,
1278,
9,
339,
485,
561,
4600,
63,
11510,
275,
334,
267,
298,
646,
984,
12,
2943,
12,
747,
401,
267,
298,
80,
275,
747,
14,
515,
14,
904,
8,
1274,
423,
20912,
8,
17,
680,
70,
63,
9350,
459,
2124,
694,
995,
627,
2840,
13316,
9,
82,
4186,
267,
298,
1873,
275,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
80,
2584,
363,
826,
4343,
647,
1333,
401,
267,
298,
77,
275,
440,
13446,
436,
298,
288,
298,
1274,
14,
3112,
14,
5486,
12473,
4600,
9,
82,
12,
2943,
14,
21820,
12473,
4600,
9,
82,
430,
401,
267,
298,
311,
275,
334,
77,
503,
3073,
436,
333,
855,
807,
4343,
5486,
10714,
515,
7500,
59,
566,
401,
267,
7340,
80,
440,
315,
6118,
9,
436,
6118,
14,
740,
8,
80,
4186,
272,
776,
272,
298,
1278,
367,
314,
3231,
18535,
2,
339,
485,
561,
4600,
63,
11510,
63,
3029,
275,
334,
267,
283,
77,
436,
5371,
8,
1274,
14,
3112,
59,
2840,
1708,
9,
82,
467,
2818,
1739,
9,
82,
12,
333,
3196,
272,
776,
272,
298,
8460,
1004,
8,
83,
9,
1380,
282,
1676,
2559,
365,
22141,
2,
339,
768,
3744,
272,
347,
485,
2268,
63,
561,
4600,
63,
604,
8,
1886,
12,
5496,
304,
267,
327,
4868,
5496,
365,
440,
282,
2649,
1059,
1334,
2018,
499,
14,
23,
267,
5496,
275,
620,
8,
4600,
9,
267,
25504,
275,
2008,
8,
4600,
14,
1294,
24535,
267,
9675,
63,
1278,
275,
843,
423,
561,
4600,
63,
11510,
267,
1676,
12,
7375,
12,
1982,
275,
5496,
14,
25817,
7563,
267,
340,
1676,
26,
288,
9675,
63,
1278,
847,
843,
423,
561,
4600,
63,
11510,
63,
3029,
267,
372,
30955,
904,
8,
11510,
63,
1278,
9,
450,
9480,
342,
435,
1557,
78,
7,
339,
347,
485,
362,
63,
452,
63,
561,
63,
5154,
8,
277,
304,
267,
408,
1767,
3355,
769,
402,
1006,
2559,
10747,
624,
267,
302,
681,
275,
663,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kant/videonotes
|
lib/thrift/Thrift.py
|
62
|
4077
|
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import sys
class TType:
STOP = 0
VOID = 1
BOOL = 2
BYTE = 3
I08 = 3
DOUBLE = 4
I16 = 6
I32 = 8
I64 = 10
STRING = 11
UTF7 = 11
STRUCT = 12
MAP = 13
SET = 14
LIST = 15
UTF8 = 16
UTF16 = 17
_VALUES_TO_NAMES = ( 'STOP',
'VOID',
'BOOL',
'BYTE',
'DOUBLE',
None,
'I16',
None,
'I32',
None,
'I64',
'STRING',
'STRUCT',
'MAP',
'SET',
'LIST',
'UTF8',
'UTF16' )
class TMessageType:
CALL = 1
REPLY = 2
EXCEPTION = 3
ONEWAY = 4
class TProcessor:
"""Base class for procsessor, which works on two streams."""
def process(iprot, oprot):
pass
class TException(Exception):
"""Base class for all thrift exceptions."""
# BaseException.message is deprecated in Python v[2.6,3.0)
if (2,6,0) <= sys.version_info < (3,0):
def _get_message(self):
return self._message
def _set_message(self, message):
self._message = message
message = property(_get_message, _set_message)
def __init__(self, message=None):
Exception.__init__(self, message)
self.message = message
class TApplicationException(TException):
"""Application level thrift exceptions."""
UNKNOWN = 0
UNKNOWN_METHOD = 1
INVALID_MESSAGE_TYPE = 2
WRONG_METHOD_NAME = 3
BAD_SEQUENCE_ID = 4
MISSING_RESULT = 5
INTERNAL_ERROR = 6
PROTOCOL_ERROR = 7
def __init__(self, type=UNKNOWN, message=None):
TException.__init__(self, message)
self.type = type
def __str__(self):
if self.message:
return self.message
elif self.type == self.UNKNOWN_METHOD:
return 'Unknown method'
elif self.type == self.INVALID_MESSAGE_TYPE:
return 'Invalid message type'
elif self.type == self.WRONG_METHOD_NAME:
return 'Wrong method name'
elif self.type == self.BAD_SEQUENCE_ID:
return 'Bad sequence ID'
elif self.type == self.MISSING_RESULT:
return 'Missing result'
else:
return 'Default (unknown) TApplicationException'
def read(self, iprot):
iprot.readStructBegin()
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.STRING:
self.message = iprot.readString();
else:
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.I32:
self.type = iprot.readI32();
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
def write(self, oprot):
oprot.writeStructBegin('TApplicationException')
if self.message != None:
oprot.writeFieldBegin('message', TType.STRING, 1)
oprot.writeString(self.message)
oprot.writeFieldEnd()
if self.type != None:
oprot.writeFieldBegin('type', TType.I32, 2)
oprot.writeI32(self.type)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
|
mit
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
984,
199,
199,
533,
6547,
26,
523,
22348,
257,
275,
378,
523,
812,
16337,
257,
275,
413,
523,
25849,
257,
275,
499,
523,
6515,
3727,
257,
275,
650,
523,
473,
2036,
259,
275,
650,
523,
5681,
275,
841,
523,
473,
975,
259,
275,
1227,
523,
473,
708,
259,
275,
1695,
523,
473,
772,
259,
275,
1616,
523,
18661,
275,
4119,
523,
9094,
23,
257,
275,
4119,
523,
7553,
7996,
275,
3144,
523,
603,
1282,
259,
275,
4944,
523,
11543,
259,
275,
4329,
523,
21716,
257,
275,
4114,
523,
9094,
24,
257,
275,
3193,
523,
9094,
975,
221,
275,
5557,
819,
485,
15514,
63,
2566,
63,
14546,
275,
334,
283,
11632,
297,
1993,
283,
17510,
297,
1993,
283,
16026,
297,
1993,
283,
19714,
297,
1993,
283,
14989,
297,
1993,
488,
12,
1993,
283,
41,
975,
297,
1993,
488,
12,
1993,
283,
41,
708,
297,
1993,
488,
12,
2432,
283,
41,
772,
297,
2432,
283,
5353,
297,
2432,
283,
8893,
297,
2432,
283,
5443,
297,
2432,
283,
3597,
297,
2432,
283,
4924,
297,
2432,
283,
6610,
24,
297,
2432,
283,
6610,
975,
7,
776,
199,
199,
533,
20998,
26,
523,
24251,
221,
275,
413,
523,
5363,
31370,
275,
499,
523,
3651,
7177,
1075,
275,
650,
523,
13051,
17488,
275,
841,
199,
199,
533,
377,
10438,
26,
819,
408,
1563,
1021,
367,
6499,
5480,
269,
12,
1314,
5419,
641,
2877,
13788,
1041,
819,
347,
2112,
8,
10141,
12,
4833,
304,
272,
986,
199,
199,
533,
377,
1726,
8,
1726,
304,
819,
408,
1563,
1021,
367,
1006,
17199,
4967,
1041,
819,
327,
25416,
14,
1188,
365,
5906,
315,
2018,
373,
59,
18,
14,
22,
12,
19,
14,
16,
9,
523,
340,
334,
18,
12,
22,
12,
16,
9,
2695,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
16,
304,
272,
347,
485,
362,
63,
1188,
8,
277,
304,
6722,
372,
291,
423,
1188,
272,
347,
485,
409,
63,
1188,
8,
277,
12,
1245,
304,
6722,
291,
423,
1188,
275,
1245,
272,
1245,
275,
3324,
1547,
362,
63,
1188,
12,
485,
409,
63,
1188,
9,
819,
347,
636,
826,
721,
277,
12,
1245,
29,
403,
304,
272,
2186,
855,
826,
721,
277,
12,
1245,
9,
272,
291,
14,
1188,
275,
1245,
199,
199,
533,
27790,
8,
52,
1726,
304,
819,
408,
5039,
2166,
17199,
4967,
1041,
819,
24740,
275,
378,
523,
24740,
63,
9977,
275,
413,
523,
29901,
63,
8272,
63,
2711,
275,
499,
523,
16573,
7770,
63,
9977,
63,
2339,
275,
650,
523,
699,
1554,
63,
16585,
63,
998,
275,
841,
523,
603,
1311,
12567,
63,
9517,
275,
959,
523,
1621,
17071,
63,
3170,
275,
1227,
523,
3611,
2566,
3978,
63,
3170,
275,
1520,
819,
347,
636,
826,
721,
277,
12,
730,
29,
11588,
12,
1245,
29,
403,
304,
272,
377,
1726,
855,
826,
721,
277,
12,
1245,
9,
272,
291,
14,
466,
275,
730,
819,
347,
636,
495,
721,
277,
304,
272,
340,
291,
14,
1188,
26,
489,
372,
291,
14,
1188,
272,
916,
291,
14,
466,
508,
291,
14,
11588,
63,
9977,
26,
489,
372,
283,
5912,
1083,
7,
272,
916,
291,
14,
466,
508,
291,
14,
9692,
63,
8272,
63,
2711,
26,
489,
372,
283,
3364,
1245,
730,
7,
272,
916,
291,
14,
466,
508,
291,
14,
6524,
7770,
63,
9977,
63,
2339,
26,
489,
372,
283,
14858,
1083,
536,
7,
272,
916,
291,
14,
466,
508,
291,
14,
9439,
63,
16585,
63,
998,
26,
489,
372,
283,
5725,
3414,
2870,
7,
272,
916,
291,
14,
466,
508,
291,
14,
18701,
63,
9517,
26,
489,
372,
283,
7718,
754,
7,
272,
587,
26,
489,
372,
283,
2698,
334,
5187,
9,
27790,
7,
819,
347,
1586,
8,
277,
12,
5052,
304,
272,
5052,
14,
23962,
342,
272,
1830,
715,
26,
489,
334,
5252,
12,
8570,
12,
8289,
9,
275,
5052,
14,
23971,
342,
489,
340,
8570,
508,
6547,
14,
11632,
26,
267,
2059,
489,
340,
8289,
508,
413,
26,
267,
340,
8570,
508,
6547,
14,
5353,
26,
881,
291,
14,
1188,
275,
5052,
14,
22765,
7303,
267,
587,
26,
881,
5052,
14,
2759,
8,
10386,
9,
489,
916,
8289,
508,
499,
26,
267,
340,
8570,
508,
6547,
14,
41,
708,
26,
881,
291,
14,
466,
275,
5052,
14,
739,
41,
708,
7303,
267,
587,
26,
881,
5052,
14,
2759,
8,
10386,
9,
489,
587,
26,
267,
5052,
14,
2759,
8,
10386,
9,
489,
5052,
14,
23970,
342,
272,
5052,
14,
23961,
342,
819,
347,
2218,
8,
277,
12,
4833,
304,
272,
4833,
14,
24019,
360,
52,
22573,
358,
272,
340,
291,
14,
1188,
1137,
488,
26,
489,
4833,
14,
14048,
360,
1188,
297,
6547,
14,
5353,
12,
413,
9,
489,
4833,
14,
23187,
8,
277,
14,
1188,
9,
489,
4833,
14,
14047,
342,
272,
340,
291,
14,
466,
1137,
488,
26,
489,
4833,
14,
14048,
360,
466,
297,
6547,
14,
41,
708,
12,
499,
9,
489,
4833,
14,
952,
41,
708,
8,
277,
14,
466,
9,
489,
4833,
14,
14047,
342,
272,
4833,
14,
24033,
342,
272,
4833,
14,
24018,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
984,
199,
199,
533,
6547,
26,
523,
22348,
257,
275,
378,
523,
812,
16337,
257,
275,
413,
523,
25849,
257,
275,
499,
523,
6515,
3727,
257,
275,
650,
523,
473,
2036,
259,
275,
650,
523,
5681,
275,
841,
523,
473,
975,
259,
275,
1227,
523,
473,
708,
259,
275,
1695,
523,
473,
772,
259,
275,
1616,
523,
18661,
275,
4119,
523,
9094,
23,
257,
275,
4119,
523,
7553,
7996,
275,
3144,
523,
603,
1282,
259,
275,
4944,
523,
11543,
259,
275,
4329,
523,
21716,
257,
275,
4114,
523,
9094,
24,
257,
275,
3193,
523,
9094,
975,
221,
275,
5557,
819,
485,
15514,
63,
2566,
63,
14546,
275,
334,
283,
11632,
297,
1993,
283,
17510,
297,
1993,
283,
16026,
297,
1993,
283,
19714,
297,
1993,
283,
14989,
297,
1993,
488,
12,
1993,
283,
41,
975,
297,
1993,
488,
12,
1993,
283,
41,
708,
297,
1993,
488,
12,
2432,
283,
41,
772,
297,
2432,
283,
5353,
297,
2432,
283,
8893,
297,
2432,
283,
5443,
297,
2432,
283,
3597,
297,
2432,
283,
4924,
297,
2432,
283,
6610,
24,
297,
2432,
283,
6610,
975,
7,
776,
199,
199,
533,
20998,
26,
523,
24251,
221,
275,
413,
523,
5363,
31370,
275,
499,
523,
3651,
7177,
1075,
275,
650,
523,
13051,
17488,
275,
841,
199,
199,
533,
377,
10438,
26,
819,
408,
1563,
1021,
367,
6499,
5480,
269,
12,
1314,
5419,
641,
2877,
13788,
1041,
819,
347,
2112,
8,
10141,
12,
4833,
304,
272,
986,
199,
199,
533,
377,
1726,
8,
1726,
304,
819,
408,
1563,
1021,
367,
1006,
17199,
4967,
1041,
819,
327,
25416,
14,
1188,
365,
5906,
315,
2018,
373,
59,
18,
14,
22,
12,
19,
14,
16,
9,
523,
340,
334,
18,
12,
22,
12,
16,
9,
2695,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
16,
304,
272,
347,
485,
362,
63,
1188,
8,
277,
304,
6722,
372,
291,
423,
1188,
272,
347,
485,
409,
63,
1188,
8,
277,
12,
1245,
304,
6722,
291,
423,
1188,
275,
1245,
272,
1245,
275,
3324,
1547,
362,
63,
1188,
12,
485,
409,
63,
1188,
9,
819,
347,
636,
826,
721,
277,
12,
1245,
29,
403,
304,
272,
2186,
855,
826,
721,
277,
12,
1245,
9,
272,
291,
14,
1188,
275,
1245,
199,
199,
533,
27790,
8,
52,
1726,
304,
819,
408,
5039,
2166,
17199,
4967,
1041,
819,
24740,
275,
378,
523,
24740,
63,
9977,
275,
413,
523,
29901,
63,
8272,
63,
2711,
275,
499,
523,
16573,
7770,
63,
9977,
63,
2339,
275,
650,
523,
699,
1554,
63,
16585,
63,
998,
275,
841,
523,
603,
1311,
12567,
63,
9517,
275,
959,
523,
1621,
17071,
63,
3170,
275,
1227,
523,
3611,
2566,
3978,
63,
3170,
275,
1520,
819,
347,
636,
826,
721,
277,
12,
730,
29,
11588,
12,
1245,
29,
403,
304,
272,
377,
1726,
855,
826,
721,
277,
12,
1245,
9,
272,
291,
14,
466,
275,
730,
819,
347,
636,
495,
721,
277,
304,
272,
340,
291,
14,
1188,
26,
489,
372,
291,
14,
1188,
272,
916,
291,
14,
466,
508,
291,
14,
11588,
63,
9977,
26,
489,
372,
283,
5912,
1083,
7,
272,
916,
291,
14,
466,
508,
291,
14,
9692,
63,
8272,
63,
2711,
26,
489,
372,
283,
3364,
1245,
730,
7,
272,
916,
291,
14,
466,
508,
291,
14,
6524,
7770,
63,
9977,
63,
2339,
26,
489,
372,
283,
14858,
1083,
536,
7,
272,
916,
291,
14,
466,
508,
291,
14,
9439,
63,
16585,
63,
998,
26,
489,
372,
283,
5725,
3414,
2870,
7,
272,
916,
291,
14,
466,
508,
291,
14,
18701,
63,
9517,
26,
489,
372,
283,
7718,
754,
7,
272,
587,
26,
489,
372,
283,
2698,
334,
5187,
9,
27790,
7,
819,
347,
1586,
8,
277,
12,
5052,
304,
272,
5052,
14,
23962,
342,
272,
1830,
715,
26,
489,
334,
5252,
12,
8570,
12,
8289,
9,
275,
5052,
14,
23971,
342,
489,
340,
8570,
508,
6547,
14,
11632,
26,
267,
2059,
489,
340,
8289,
508,
413,
26,
267,
340,
8570,
508,
6547,
14,
5353,
26,
881,
291,
14,
1188,
275,
5052,
14,
22765,
7303,
267,
587,
26,
881,
5052,
14,
2759,
8,
10386,
9,
489,
916,
8289,
508,
499,
26,
267,
340,
8570,
508,
6547,
14,
41,
708,
26,
881,
291,
14,
466,
275,
5052,
14,
739,
41,
708,
7303,
267,
587,
26,
881,
5052,
14,
2759,
8,
10386,
9,
489,
587,
26,
267,
5052,
14,
2759,
8,
10386,
9,
489,
5052,
14,
23970,
342,
272,
5052,
14,
23961,
342,
819,
347,
2218,
8,
277,
12,
4833,
304,
272,
4833,
14,
24019,
360,
52,
22573,
358,
272,
340,
291,
14,
1188,
1137,
488,
26,
489,
4833,
14,
14048,
360,
1188,
297,
6547,
14,
5353,
12,
413,
9,
489,
4833,
14,
23187,
8,
277,
14,
1188,
9,
489,
4833,
14,
14047,
342,
272,
340,
291,
14,
466,
1137,
488,
26,
489,
4833,
14,
14048,
360,
466,
297,
6547,
14,
41,
708,
12,
499,
9,
489,
4833,
14,
952,
41,
708,
8,
277,
14,
466,
9,
489,
4833,
14,
14047,
342,
272,
4833,
14,
24033,
342,
272,
4833,
14,
24018,
342,
199,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ICTU/quality-time
|
components/server/src/initialization/report.py
|
1
|
2301
|
"""Report loaders."""
import json
import logging
import pathlib
from pymongo.database import Database
from database.reports import insert_new_report, insert_new_reports_overview, latest_reports_overview, report_exists
def initialize_reports_overview(database: Database) -> None:
"""Initialize the reports overview if not present in the database."""
# The coverage measurement of the behave feature tests is unstable. Most of the time it reports the last two lines
# as covered, sometimes not. It's unclear why. To prevent needless checking of the coverage report coverage
# measurement of the last two lines and the if-statement has been turned off.
if latest_reports_overview(database): # pragma: no cover-behave
logging.info("Skipping initializing reports overview; it already exists")
else:
logging.info("Initializing reports overview") # pragma: no cover-behave
insert_new_reports_overview(
database, "{{user}} initialized the reports overview", dict(title="Reports", subtitle="")
) # pragma: no cover-behave
def import_report(database: Database, filename: pathlib.Path) -> None:
"""Read the report and store it in the database."""
# The coverage measurement of the behave feature tests is unstable. Most of the time it reports the last two lines
# as covered, sometimes not. It's unclear why. To prevent needless checking of the coverage report coverage
# measurement of the last two lines and the if-statement has been turned off.
with filename.open() as json_report:
imported_report = json.load(json_report)
if report_exists(database, imported_report["report_uuid"]): # pragma: no cover-behave
logging.info("Skipping import of %s; it already exists", filename)
else: # pragma: no cover-behave
insert_new_report(database, "{{user}} imported a new report", (imported_report, imported_report["report_uuid"]))
logging.info("Report %s imported", filename)
def import_example_reports(database: Database) -> None:
"""Import the example reports."""
example_reports_path = pathlib.Path(__file__).resolve().parent.parent / "example-reports"
for filename in example_reports_path.glob("example-report*.json"):
import_report(database, filename)
|
apache-2.0
|
[
624,
7457,
25520,
1041,
199,
199,
646,
2022,
199,
646,
2050,
199,
646,
32212,
199,
199,
504,
21878,
14,
4659,
492,
8692,
199,
199,
504,
3050,
14,
15629,
492,
5518,
63,
1222,
63,
3070,
12,
5518,
63,
1222,
63,
15629,
63,
21753,
12,
8839,
63,
15629,
63,
21753,
12,
3622,
63,
2444,
421,
199,
318,
8265,
63,
15629,
63,
21753,
8,
4659,
26,
8692,
9,
1035,
488,
26,
272,
408,
9345,
314,
13924,
23503,
340,
440,
3451,
315,
314,
3050,
1041,
272,
327,
710,
11745,
18216,
402,
314,
24062,
3878,
2295,
365,
625,
11989,
14,
17536,
402,
314,
900,
652,
13924,
314,
2061,
2877,
2385,
272,
327,
465,
24295,
12,
15026,
440,
14,
2779,
1159,
625,
3584,
10842,
14,
4005,
7981,
1929,
2003,
7907,
402,
314,
11745,
3622,
11745,
272,
327,
18216,
402,
314,
2061,
2877,
2385,
436,
314,
340,
13,
6242,
965,
2757,
19136,
2331,
14,
272,
340,
8839,
63,
15629,
63,
21753,
8,
4659,
304,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
2050,
14,
815,
480,
18297,
29141,
13924,
23503,
27,
652,
2575,
3495,
531,
272,
587,
26,
267,
2050,
14,
815,
480,
5733,
9147,
13924,
23503,
531,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
5518,
63,
1222,
63,
15629,
63,
21753,
8,
288,
3050,
12,
7370,
751,
4863,
10038,
314,
13924,
23503,
401,
1211,
8,
1213,
628,
497,
5203,
401,
18197,
18413,
267,
776,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
421,
199,
318,
492,
63,
3070,
8,
4659,
26,
8692,
12,
1788,
26,
32212,
14,
2042,
9,
1035,
488,
26,
272,
408,
3284,
314,
3622,
436,
3877,
652,
315,
314,
3050,
1041,
272,
327,
710,
11745,
18216,
402,
314,
24062,
3878,
2295,
365,
625,
11989,
14,
17536,
402,
314,
900,
652,
13924,
314,
2061,
2877,
2385,
272,
327,
465,
24295,
12,
15026,
440,
14,
2779,
1159,
625,
3584,
10842,
14,
4005,
7981,
1929,
2003,
7907,
402,
314,
11745,
3622,
11745,
272,
327,
18216,
402,
314,
2061,
2877,
2385,
436,
314,
340,
13,
6242,
965,
2757,
19136,
2331,
14,
272,
543,
1788,
14,
1490,
342,
465,
2022,
63,
3070,
26,
267,
8439,
63,
3070,
275,
2022,
14,
912,
8,
1001,
63,
3070,
9,
272,
340,
3622,
63,
2444,
8,
4659,
12,
8439,
63,
3070,
905,
3070,
63,
2580,
21473,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
2050,
14,
815,
480,
18297,
492,
402,
450,
83,
27,
652,
2575,
3495,
401,
1788,
9,
272,
587,
26,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
5518,
63,
1222,
63,
3070,
8,
4659,
12,
7370,
751,
4863,
8439,
282,
892,
3622,
401,
334,
17932,
63,
3070,
12,
8439,
63,
3070,
905,
3070,
63,
2580,
13045,
267,
2050,
14,
815,
480,
7457,
450,
83,
8439,
401,
1788,
9,
421,
199,
318,
492,
63,
2694,
63,
15629,
8,
4659,
26,
8692,
9,
1035,
488,
26,
272,
408,
6295,
314,
2893,
13924,
1041,
272,
2893,
63,
15629,
63,
515,
275,
32212,
14,
2042,
3460,
493,
28634,
6983,
1252,
1708,
14,
1708,
1182,
298,
2694,
13,
15629,
2,
272,
367,
1788,
315,
2893,
63,
15629,
63,
515,
14,
6463,
480,
2694,
13,
3070,
4856,
1001,
2349,
267,
492,
63,
3070,
8,
4659,
12,
1788,
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
] |
[
7457,
25520,
1041,
199,
199,
646,
2022,
199,
646,
2050,
199,
646,
32212,
199,
199,
504,
21878,
14,
4659,
492,
8692,
199,
199,
504,
3050,
14,
15629,
492,
5518,
63,
1222,
63,
3070,
12,
5518,
63,
1222,
63,
15629,
63,
21753,
12,
8839,
63,
15629,
63,
21753,
12,
3622,
63,
2444,
421,
199,
318,
8265,
63,
15629,
63,
21753,
8,
4659,
26,
8692,
9,
1035,
488,
26,
272,
408,
9345,
314,
13924,
23503,
340,
440,
3451,
315,
314,
3050,
1041,
272,
327,
710,
11745,
18216,
402,
314,
24062,
3878,
2295,
365,
625,
11989,
14,
17536,
402,
314,
900,
652,
13924,
314,
2061,
2877,
2385,
272,
327,
465,
24295,
12,
15026,
440,
14,
2779,
1159,
625,
3584,
10842,
14,
4005,
7981,
1929,
2003,
7907,
402,
314,
11745,
3622,
11745,
272,
327,
18216,
402,
314,
2061,
2877,
2385,
436,
314,
340,
13,
6242,
965,
2757,
19136,
2331,
14,
272,
340,
8839,
63,
15629,
63,
21753,
8,
4659,
304,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
2050,
14,
815,
480,
18297,
29141,
13924,
23503,
27,
652,
2575,
3495,
531,
272,
587,
26,
267,
2050,
14,
815,
480,
5733,
9147,
13924,
23503,
531,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
5518,
63,
1222,
63,
15629,
63,
21753,
8,
288,
3050,
12,
7370,
751,
4863,
10038,
314,
13924,
23503,
401,
1211,
8,
1213,
628,
497,
5203,
401,
18197,
18413,
267,
776,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
421,
199,
318,
492,
63,
3070,
8,
4659,
26,
8692,
12,
1788,
26,
32212,
14,
2042,
9,
1035,
488,
26,
272,
408,
3284,
314,
3622,
436,
3877,
652,
315,
314,
3050,
1041,
272,
327,
710,
11745,
18216,
402,
314,
24062,
3878,
2295,
365,
625,
11989,
14,
17536,
402,
314,
900,
652,
13924,
314,
2061,
2877,
2385,
272,
327,
465,
24295,
12,
15026,
440,
14,
2779,
1159,
625,
3584,
10842,
14,
4005,
7981,
1929,
2003,
7907,
402,
314,
11745,
3622,
11745,
272,
327,
18216,
402,
314,
2061,
2877,
2385,
436,
314,
340,
13,
6242,
965,
2757,
19136,
2331,
14,
272,
543,
1788,
14,
1490,
342,
465,
2022,
63,
3070,
26,
267,
8439,
63,
3070,
275,
2022,
14,
912,
8,
1001,
63,
3070,
9,
272,
340,
3622,
63,
2444,
8,
4659,
12,
8439,
63,
3070,
905,
3070,
63,
2580,
21473,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
2050,
14,
815,
480,
18297,
492,
402,
450,
83,
27,
652,
2575,
3495,
401,
1788,
9,
272,
587,
26,
221,
327,
11942,
26,
949,
8486,
13,
1235,
7804,
267,
5518,
63,
1222,
63,
3070,
8,
4659,
12,
7370,
751,
4863,
8439,
282,
892,
3622,
401,
334,
17932,
63,
3070,
12,
8439,
63,
3070,
905,
3070,
63,
2580,
13045,
267,
2050,
14,
815,
480,
7457,
450,
83,
8439,
401,
1788,
9,
421,
199,
318,
492,
63,
2694,
63,
15629,
8,
4659,
26,
8692,
9,
1035,
488,
26,
272,
408,
6295,
314,
2893,
13924,
1041,
272,
2893,
63,
15629,
63,
515,
275,
32212,
14,
2042,
3460,
493,
28634,
6983,
1252,
1708,
14,
1708,
1182,
298,
2694,
13,
15629,
2,
272,
367,
1788,
315,
2893,
63,
15629,
63,
515,
14,
6463,
480,
2694,
13,
3070,
4856,
1001,
2349,
267,
492,
63,
3070,
8,
4659,
12,
1788,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
matthew-tucker/mne-python
|
mne/datasets/utils.py
|
6
|
10755
|
# Authors: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
# Martin Luessi <mluessi@nmr.mgh.harvard.edu>
# Eric Larson <larson.eric.d@gmail.com>
# Denis Egnemann <denis.engemann@gmail.com>
# License: BSD Style.
import os
import os.path as op
import shutil
import tarfile
from warnings import warn
import stat
from .. import __version__ as mne_version
from ..utils import get_config, set_config, _fetch_file, logger
from ..externals.six import string_types
from ..externals.six.moves import input
_data_path_doc = """Get path to local copy of {name} dataset
Parameters
----------
path : None | str
Location of where to look for the {name} dataset.
If None, the environment variable or config parameter
{conf} is used. If it doesn't exist, the
"mne-python/examples" directory is used. If the {name} dataset
is not found under the given path (e.g., as
"mne-python/examples/MNE-{name}-data"), the data
will be automatically downloaded to the specified folder.
force_update : bool
Force update of the {name} dataset even if a local copy exists.
update_path : bool | None
If True, set the {conf} in mne-python
config to the given path. If None, the user is prompted.
download : bool
If False and the {name} dataset has not been downloaded yet,
it will not be downloaded and the path will be returned as
'' (empty string). This is mostly used for debugging purposes
and can be safely ignored by most users.
verbose : bool, str, int, or None
If not None, override default verbose level (see mne.verbose).
Returns
-------
path : str
Path to {name} dataset directory.
"""
_version_doc = """Get version of the local {name} dataset
Returns
-------
version : str | None
Version of the {name} local dataset, or None if the dataset
does not exist locally.
"""
def _dataset_version(path, name):
"""Get the version of the dataset"""
ver_fname = op.join(path, 'version.txt')
if op.exists(ver_fname):
with open(ver_fname, 'r') as fid:
version = fid.readline().strip() # version is on first line
else:
# Sample dataset versioning was introduced after 0.3
# SPM dataset was introduced with 0.7
version = '0.3' if name == 'sample' else '0.7'
return version
def _get_path(path, key, name):
"""Helper to get a dataset path"""
if path is None:
# use an intelligent guess if it's not defined
def_path = op.realpath(op.join(op.dirname(__file__), '..', '..',
'..', 'examples'))
if get_config(key) is None:
key = 'MNE_DATA'
path = get_config(key, def_path)
# use the same for all datasets
if not op.exists(path) or not os.access(path, os.W_OK):
try:
os.mkdir(path)
except OSError:
try:
logger.info('Checking for %s data in '
'"~/mne_data"...' % name)
path = op.join(op.expanduser("~"), "mne_data")
if not op.exists(path):
logger.info("Trying to create "
"'~/mne_data' in home directory")
os.mkdir(path)
except OSError:
raise OSError("User does not have write permissions "
"at '%s', try giving the path as an "
"argument to data_path() where user has "
"write permissions, for ex:data_path"
"('/home/xyz/me2/')" % (path))
if not isinstance(path, string_types):
raise ValueError('path must be a string or None')
return path
def _do_path_update(path, update_path, key, name):
"""Helper to update path"""
path = op.abspath(path)
if update_path is None:
if get_config(key, '') != path:
update_path = True
msg = ('Do you want to set the path:\n %s\nas the default '
'%s dataset path in the mne-python config [y]/n? '
% (path, name))
answer = input(msg)
if answer.lower() == 'n':
update_path = False
else:
update_path = False
if update_path is True:
set_config(key, path)
return path
def _data_path(path=None, force_update=False, update_path=True, download=True,
name=None, check_version=False, return_version=False):
"""Aux function
"""
key = {'sample': 'MNE_DATASETS_SAMPLE_PATH',
'spm': 'MNE_DATASETS_SPM_FACE_PATH',
'somato': 'MNE_DATASETS_SOMATO_PATH',
'testing': 'MNE_DATASETS_TESTING_PATH',
'fake': 'MNE_DATASETS_FAKE_PATH',
}[name]
path = _get_path(path, key, name)
archive_names = dict(
sample='MNE-sample-data-processed.tar.gz',
spm='MNE-spm-face.tar.bz2',
somato='MNE-somato-data.tar.gz',
testing='mne-testing-data-master.tar.gz',
fake='foo.tgz',
)
folder_names = dict(
sample='MNE-sample-data',
spm='MNE-spm-face',
somato='MNE-somato-data',
testing='MNE-testing-data',
fake='foo',
)
urls = dict(
sample="https://s3.amazonaws.com/mne-python/datasets/%s",
spm='https://s3.amazonaws.com/mne-python/datasets/%s',
somato='https://s3.amazonaws.com/mne-python/datasets/%s',
testing='https://github.com/mne-tools/mne-testing-data/archive/'
'master.tar.gz',
fake='https://github.com/mne-tools/mne-testing-data/raw/master/'
'datasets/%s',
)
hashes = dict(
sample='f73186795af820428e5e8e779ce5bfcf',
spm='3e9e83c642136e5b720e2ecc5dcc3244',
somato='f3e3a8441477bb5bacae1d0c6e0964fb',
testing=None,
fake='3194e9f7b46039bb050a74f3e1ae9908',
)
folder_origs = dict( # not listed means None
testing='mne-testing-data-master',
)
folder_name = folder_names[name]
archive_name = archive_names[name]
hash_ = hashes[name]
url = urls[name]
folder_orig = folder_origs.get(name, None)
if '%s' in url:
url = url % archive_name
folder_path = op.join(path, folder_name)
rm_archive = False
martinos_path = '/cluster/fusion/sample_data/' + archive_name
neurospin_path = '/neurospin/tmp/gramfort/' + archive_name
if not op.exists(folder_path) and not download:
return ''
if not op.exists(folder_path) or force_update:
logger.info('Downloading or reinstalling '
'data archive %s at location %s' % (archive_name, path))
if op.exists(martinos_path):
archive_name = martinos_path
elif op.exists(neurospin_path):
archive_name = neurospin_path
else:
archive_name = op.join(path, archive_name)
rm_archive = True
fetch_archive = True
if op.exists(archive_name):
msg = ('Archive already exists. Overwrite it (y/[n])? ')
answer = input(msg)
if answer.lower() == 'y':
os.remove(archive_name)
else:
fetch_archive = False
if fetch_archive:
_fetch_file(url, archive_name, print_destination=False,
hash_=hash_)
if op.exists(folder_path):
def onerror(func, path, exc_info):
"""Deal with access errors (e.g. testing dataset read-only)"""
# Is the error an access error ?
do = False
if not os.access(path, os.W_OK):
perm = os.stat(path).st_mode | stat.S_IWUSR
os.chmod(path, perm)
do = True
if not os.access(op.dirname(path), os.W_OK):
dir_perm = (os.stat(op.dirname(path)).st_mode |
stat.S_IWUSR)
os.chmod(op.dirname(path), dir_perm)
do = True
if do:
func(path)
else:
raise
shutil.rmtree(folder_path, onerror=onerror)
logger.info('Decompressing the archive: %s' % archive_name)
logger.info('(please be patient, this can take some time)')
for ext in ['gz', 'bz2']: # informed guess (and the only 2 options).
try:
tarfile.open(archive_name, 'r:%s' % ext).extractall(path=path)
break
except tarfile.ReadError as err:
logger.info('%s is %s trying "bz2"' % (archive_name, err))
if folder_orig is not None:
shutil.move(op.join(path, folder_orig), folder_path)
if rm_archive:
os.remove(archive_name)
path = _do_path_update(path, update_path, key, name)
path = op.join(path, folder_name)
# compare the version of the dataset and mne
data_version = _dataset_version(path, name)
try:
from distutils.version import LooseVersion as LV
except:
warn('Could not determine %s dataset version; dataset could\n'
'be out of date. Please install the "distutils" package.'
% name)
else: # 0.7 < 0.7.git shoud be False, therefore strip
if check_version and LV(data_version) < LV(mne_version.strip('.git')):
warn('The {name} dataset (version {current}) is older than '
'mne-python (version {newest}). If the examples fail, '
'you may need to update the {name} dataset by using '
'mne.datasets.{name}.data_path(force_update=True)'.format(
name=name, current=data_version, newest=mne_version))
return (path, data_version) if return_version else path
def _get_version(name):
"""Helper to get a dataset version"""
if not has_dataset(name):
return None
return _data_path(name=name, return_version=True)[1]
def has_dataset(name):
"""Helper for dataset presence"""
endswith = {'sample': 'MNE-sample-data',
'spm': 'MNE-spm-face',
'somato': 'MNE-somato-data',
'testing': 'MNE-testing-data',
'fake': 'foo',
}[name]
dp = _data_path(download=False, name=name, check_version=False)
return dp.endswith(endswith)
|
bsd-3-clause
|
[
3,
6642,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
15253,
957,
13,
462,
374,
15970,
14,
4391,
30,
199,
3,
3515,
603,
26788,
491,
10138,
338,
665,
757,
10138,
338,
32,
10756,
82,
14,
77,
3561,
14,
8210,
86,
1005,
14,
8654,
30,
199,
3,
3515,
662,
1567,
491,
285,
834,
665,
9828,
834,
14,
281,
530,
14,
68,
32,
6799,
14,
957,
30,
199,
3,
3515,
25187,
374,
662,
71,
685,
20059,
665,
848,
374,
14,
287,
303,
20059,
32,
6799,
14,
957,
30,
199,
3,
844,
26,
6289,
19442,
14,
199,
199,
646,
747,
199,
646,
747,
14,
515,
465,
1687,
199,
646,
5145,
199,
646,
13608,
199,
504,
3598,
492,
7987,
199,
646,
5672,
199,
199,
504,
2508,
492,
636,
1023,
363,
465,
18250,
63,
1023,
199,
504,
2508,
1208,
492,
664,
63,
888,
12,
663,
63,
888,
12,
485,
3535,
63,
493,
12,
2512,
199,
504,
2508,
24688,
14,
4174,
492,
1059,
63,
1313,
199,
504,
2508,
24688,
14,
4174,
14,
4912,
492,
1324,
421,
199,
63,
576,
63,
515,
63,
1301,
275,
408,
1002,
931,
370,
2257,
1331,
402,
469,
354,
93,
4789,
339,
3897,
272,
4143,
272,
931,
520,
488,
1204,
620,
267,
12625,
402,
2382,
370,
3648,
367,
314,
469,
354,
93,
4789,
14,
267,
982,
488,
12,
314,
3734,
1750,
503,
1101,
2725,
267,
469,
2190,
93,
365,
1202,
14,
982,
652,
3181,
1133,
2187,
12,
314,
267,
298,
22599,
13,
1548,
15,
8589,
2,
2082,
365,
1202,
14,
982,
314,
469,
354,
93,
4789,
267,
365,
440,
1911,
1334,
314,
1627,
931,
334,
69,
14,
71,
2020,
465,
267,
298,
22599,
13,
1548,
15,
8589,
15,
45,
6388,
24185,
354,
17063,
576,
1288,
314,
666,
267,
911,
506,
5847,
13557,
370,
314,
2013,
4922,
14,
272,
3542,
63,
873,
520,
2155,
267,
18771,
1678,
402,
314,
469,
354,
93,
4789,
2755,
340,
282,
2257,
1331,
3495,
14,
272,
1678,
63,
515,
520,
2155,
1204,
488,
267,
982,
715,
12,
663,
314,
469,
2190,
93,
315,
18250,
13,
1548,
267,
1101,
370,
314,
1627,
931,
14,
982,
488,
12,
314,
922,
365,
21652,
471,
14,
272,
5235,
520,
2155,
267,
982,
756,
436,
314,
469,
354,
93,
4789,
965,
440,
2757,
13557,
5966,
12,
267,
652,
911,
440,
506,
13557,
436,
314,
931,
911,
506,
2138,
465,
267,
2125,
334,
1667,
1059,
680,
961,
365,
19762,
1202,
367,
10201,
12901,
267,
436,
883,
506,
19353,
5525,
701,
4750,
4390,
14,
272,
3376,
520,
2155,
12,
620,
12,
1109,
12,
503,
488,
267,
982,
440,
488,
12,
4278,
849,
3376,
2166,
334,
3239,
18250,
14,
3832,
680,
339,
1803,
272,
5514,
272,
931,
520,
620,
267,
6912,
370,
469,
354,
93,
4789,
2082,
14,
199,
624,
421,
199,
63,
1023,
63,
1301,
275,
408,
1002,
1015,
402,
314,
2257,
469,
354,
93,
4789,
339,
1803,
272,
5514,
272,
1015,
520,
620,
1204,
488,
267,
3394,
402,
314,
469,
354,
93,
2257,
4789,
12,
503,
488,
340,
314,
4789,
267,
1630,
440,
2187,
17738,
14,
199,
624,
421,
199,
318,
485,
5214,
63,
1023,
8,
515,
12,
536,
304,
272,
408,
1002,
314,
1015,
402,
314,
4789,
624,
272,
809,
63,
5252,
275,
1687,
14,
904,
8,
515,
12,
283,
1023,
14,
2424,
358,
272,
340,
1687,
14,
2444,
8,
422,
63,
5252,
304,
267,
543,
1551,
8,
422,
63,
5252,
12,
283,
82,
358,
465,
8289,
26,
288,
1015,
275,
8289,
14,
6407,
1252,
1913,
342,
221,
327,
1015,
365,
641,
1642,
1004,
272,
587,
26,
267,
327,
15227,
4789,
1015,
316,
1990,
21399,
2410,
378,
14,
19,
267,
327,
6988,
45,
4789,
1990,
21399,
543,
378,
14,
23,
267,
1015,
275,
283,
16,
14,
19,
7,
340,
536,
508,
283,
3271,
7,
587,
283,
16,
14,
23,
7,
339,
372,
1015,
421,
199,
318,
485,
362,
63,
515,
8,
515,
12,
790,
12,
536,
304,
272,
408,
4433,
370,
664,
282,
4789,
931,
624,
272,
340,
931,
365,
488,
26,
288,
327,
675,
376,
4661,
24024,
9519,
340,
652,
1159,
440,
3247,
288,
347,
63,
515,
275,
1687,
14,
11091,
8,
411,
14,
904,
8,
411,
14,
3475,
3460,
493,
10139,
19155,
19155,
5644,
19155,
283,
8589,
1333,
288,
340,
664,
63,
888,
8,
498,
9,
365,
488,
26,
355,
790,
275,
283,
45,
6388,
63,
3998,
7,
288,
931,
275,
664,
63,
888,
8,
498,
12,
347,
63,
515,
9,
953,
327,
675,
314,
2011,
367,
1006,
13148,
288,
340,
440,
1687,
14,
2444,
8,
515,
9,
503,
440,
747,
14,
2732,
8,
515,
12,
747,
14,
55,
63,
3593,
304,
355,
862,
26,
490,
747,
14,
8215,
8,
515,
9,
355,
871,
6440,
26,
490,
862,
26,
717,
2512,
14,
815,
360,
14740,
367,
450,
83,
666,
315,
283,
2511,
5522,
94,
15,
22599,
63,
576,
2,
13698,
450,
536,
9,
717,
931,
275,
1687,
14,
904,
8,
411,
14,
12131,
20793,
1288,
298,
22599,
63,
576,
531,
717,
340,
440,
1687,
14,
2444,
8,
515,
304,
1169,
2512,
14,
815,
480,
27693,
370,
1218,
298,
3147,
3546,
94,
15,
22599,
63,
576,
7,
315,
5629,
2082,
531,
1169,
747,
14,
8215,
8,
515,
9,
490,
871,
6440,
26,
717,
746,
6440,
480,
1899,
1630,
440,
1172,
2218,
3443,
298,
4228,
298,
292,
1543,
83,
297,
862,
15131,
314,
931,
465,
376,
298,
4228,
298,
2094,
370,
666,
63,
515,
342,
2382,
922,
965,
298,
4228,
298,
952,
3443,
12,
367,
444,
26,
576,
63,
515,
2,
4228,
298,
2336,
4219,
15,
8568,
15,
278,
18,
6217,
2,
450,
334,
515,
430,
272,
340,
440,
1228,
8,
515,
12,
1059,
63,
1313,
304,
267,
746,
1722,
360,
515,
1471,
506,
282,
1059,
503,
488,
358,
272,
372,
931,
421,
199,
318,
485,
1117,
63,
515,
63,
873,
8,
515,
12,
1678,
63,
515,
12,
790,
12,
536,
304,
272,
408,
4433,
370,
1678,
931,
624,
272,
931,
275,
1687,
14,
4832,
8,
515,
9,
272,
340,
1678,
63,
515,
365,
488,
26,
267,
340,
664,
63,
888,
8,
498,
12,
4074,
1137,
931,
26,
288,
1678,
63,
515,
275,
715,
288,
1499,
275,
661,
2585,
1265,
2934,
370,
663
] |
[
6642,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
15253,
957,
13,
462,
374,
15970,
14,
4391,
30,
199,
3,
3515,
603,
26788,
491,
10138,
338,
665,
757,
10138,
338,
32,
10756,
82,
14,
77,
3561,
14,
8210,
86,
1005,
14,
8654,
30,
199,
3,
3515,
662,
1567,
491,
285,
834,
665,
9828,
834,
14,
281,
530,
14,
68,
32,
6799,
14,
957,
30,
199,
3,
3515,
25187,
374,
662,
71,
685,
20059,
665,
848,
374,
14,
287,
303,
20059,
32,
6799,
14,
957,
30,
199,
3,
844,
26,
6289,
19442,
14,
199,
199,
646,
747,
199,
646,
747,
14,
515,
465,
1687,
199,
646,
5145,
199,
646,
13608,
199,
504,
3598,
492,
7987,
199,
646,
5672,
199,
199,
504,
2508,
492,
636,
1023,
363,
465,
18250,
63,
1023,
199,
504,
2508,
1208,
492,
664,
63,
888,
12,
663,
63,
888,
12,
485,
3535,
63,
493,
12,
2512,
199,
504,
2508,
24688,
14,
4174,
492,
1059,
63,
1313,
199,
504,
2508,
24688,
14,
4174,
14,
4912,
492,
1324,
421,
199,
63,
576,
63,
515,
63,
1301,
275,
408,
1002,
931,
370,
2257,
1331,
402,
469,
354,
93,
4789,
339,
3897,
272,
4143,
272,
931,
520,
488,
1204,
620,
267,
12625,
402,
2382,
370,
3648,
367,
314,
469,
354,
93,
4789,
14,
267,
982,
488,
12,
314,
3734,
1750,
503,
1101,
2725,
267,
469,
2190,
93,
365,
1202,
14,
982,
652,
3181,
1133,
2187,
12,
314,
267,
298,
22599,
13,
1548,
15,
8589,
2,
2082,
365,
1202,
14,
982,
314,
469,
354,
93,
4789,
267,
365,
440,
1911,
1334,
314,
1627,
931,
334,
69,
14,
71,
2020,
465,
267,
298,
22599,
13,
1548,
15,
8589,
15,
45,
6388,
24185,
354,
17063,
576,
1288,
314,
666,
267,
911,
506,
5847,
13557,
370,
314,
2013,
4922,
14,
272,
3542,
63,
873,
520,
2155,
267,
18771,
1678,
402,
314,
469,
354,
93,
4789,
2755,
340,
282,
2257,
1331,
3495,
14,
272,
1678,
63,
515,
520,
2155,
1204,
488,
267,
982,
715,
12,
663,
314,
469,
2190,
93,
315,
18250,
13,
1548,
267,
1101,
370,
314,
1627,
931,
14,
982,
488,
12,
314,
922,
365,
21652,
471,
14,
272,
5235,
520,
2155,
267,
982,
756,
436,
314,
469,
354,
93,
4789,
965,
440,
2757,
13557,
5966,
12,
267,
652,
911,
440,
506,
13557,
436,
314,
931,
911,
506,
2138,
465,
267,
2125,
334,
1667,
1059,
680,
961,
365,
19762,
1202,
367,
10201,
12901,
267,
436,
883,
506,
19353,
5525,
701,
4750,
4390,
14,
272,
3376,
520,
2155,
12,
620,
12,
1109,
12,
503,
488,
267,
982,
440,
488,
12,
4278,
849,
3376,
2166,
334,
3239,
18250,
14,
3832,
680,
339,
1803,
272,
5514,
272,
931,
520,
620,
267,
6912,
370,
469,
354,
93,
4789,
2082,
14,
199,
624,
421,
199,
63,
1023,
63,
1301,
275,
408,
1002,
1015,
402,
314,
2257,
469,
354,
93,
4789,
339,
1803,
272,
5514,
272,
1015,
520,
620,
1204,
488,
267,
3394,
402,
314,
469,
354,
93,
2257,
4789,
12,
503,
488,
340,
314,
4789,
267,
1630,
440,
2187,
17738,
14,
199,
624,
421,
199,
318,
485,
5214,
63,
1023,
8,
515,
12,
536,
304,
272,
408,
1002,
314,
1015,
402,
314,
4789,
624,
272,
809,
63,
5252,
275,
1687,
14,
904,
8,
515,
12,
283,
1023,
14,
2424,
358,
272,
340,
1687,
14,
2444,
8,
422,
63,
5252,
304,
267,
543,
1551,
8,
422,
63,
5252,
12,
283,
82,
358,
465,
8289,
26,
288,
1015,
275,
8289,
14,
6407,
1252,
1913,
342,
221,
327,
1015,
365,
641,
1642,
1004,
272,
587,
26,
267,
327,
15227,
4789,
1015,
316,
1990,
21399,
2410,
378,
14,
19,
267,
327,
6988,
45,
4789,
1990,
21399,
543,
378,
14,
23,
267,
1015,
275,
283,
16,
14,
19,
7,
340,
536,
508,
283,
3271,
7,
587,
283,
16,
14,
23,
7,
339,
372,
1015,
421,
199,
318,
485,
362,
63,
515,
8,
515,
12,
790,
12,
536,
304,
272,
408,
4433,
370,
664,
282,
4789,
931,
624,
272,
340,
931,
365,
488,
26,
288,
327,
675,
376,
4661,
24024,
9519,
340,
652,
1159,
440,
3247,
288,
347,
63,
515,
275,
1687,
14,
11091,
8,
411,
14,
904,
8,
411,
14,
3475,
3460,
493,
10139,
19155,
19155,
5644,
19155,
283,
8589,
1333,
288,
340,
664,
63,
888,
8,
498,
9,
365,
488,
26,
355,
790,
275,
283,
45,
6388,
63,
3998,
7,
288,
931,
275,
664,
63,
888,
8,
498,
12,
347,
63,
515,
9,
953,
327,
675,
314,
2011,
367,
1006,
13148,
288,
340,
440,
1687,
14,
2444,
8,
515,
9,
503,
440,
747,
14,
2732,
8,
515,
12,
747,
14,
55,
63,
3593,
304,
355,
862,
26,
490,
747,
14,
8215,
8,
515,
9,
355,
871,
6440,
26,
490,
862,
26,
717,
2512,
14,
815,
360,
14740,
367,
450,
83,
666,
315,
283,
2511,
5522,
94,
15,
22599,
63,
576,
2,
13698,
450,
536,
9,
717,
931,
275,
1687,
14,
904,
8,
411,
14,
12131,
20793,
1288,
298,
22599,
63,
576,
531,
717,
340,
440,
1687,
14,
2444,
8,
515,
304,
1169,
2512,
14,
815,
480,
27693,
370,
1218,
298,
3147,
3546,
94,
15,
22599,
63,
576,
7,
315,
5629,
2082,
531,
1169,
747,
14,
8215,
8,
515,
9,
490,
871,
6440,
26,
717,
746,
6440,
480,
1899,
1630,
440,
1172,
2218,
3443,
298,
4228,
298,
292,
1543,
83,
297,
862,
15131,
314,
931,
465,
376,
298,
4228,
298,
2094,
370,
666,
63,
515,
342,
2382,
922,
965,
298,
4228,
298,
952,
3443,
12,
367,
444,
26,
576,
63,
515,
2,
4228,
298,
2336,
4219,
15,
8568,
15,
278,
18,
6217,
2,
450,
334,
515,
430,
272,
340,
440,
1228,
8,
515,
12,
1059,
63,
1313,
304,
267,
746,
1722,
360,
515,
1471,
506,
282,
1059,
503,
488,
358,
272,
372,
931,
421,
199,
318,
485,
1117,
63,
515,
63,
873,
8,
515,
12,
1678,
63,
515,
12,
790,
12,
536,
304,
272,
408,
4433,
370,
1678,
931,
624,
272,
931,
275,
1687,
14,
4832,
8,
515,
9,
272,
340,
1678,
63,
515,
365,
488,
26,
267,
340,
664,
63,
888,
8,
498,
12,
4074,
1137,
931,
26,
288,
1678,
63,
515,
275,
715,
288,
1499,
275,
661,
2585,
1265,
2934,
370,
663,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
TheJJ100100/bedrock
|
bedrock/tabzilla/urls.py
|
8
|
1127
|
# 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/.
from django.conf import settings
from django.conf.urls import url
from pipeline.collector import default_collector
from pipeline.packager import Packager
from bedrock.base.helpers import static
from bedrock.redirects.util import redirect
import views
def tabzilla_css_redirect(r):
packer = Packager()
tabzilla_package = packer.package_for('css', 'tabzilla')
if not settings.DEBUG:
file_path = tabzilla_package.output_filename
else:
default_collector.collect()
paths = packer.compile(tabzilla_package.paths)
file_path = paths[0]
return static(file_path)
urlpatterns = (
url(r'^tabzilla\.js$', views.tabzilla_js, name='tabzilla'),
url(r'^transbar\.jsonp$', views.transbar_jsonp, name='transbar'),
redirect(r'media/js/tabzilla\.js$', 'tabzilla', locale_prefix=False),
redirect(r'media/css/tabzilla\.css$', tabzilla_css_redirect, locale_prefix=False),
)
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
199,
504,
7679,
14,
10946,
492,
849,
63,
10946,
199,
504,
7679,
14,
1389,
1456,
492,
9954,
1456,
199,
199,
504,
30739,
24892,
14,
1095,
14,
7546,
492,
2955,
199,
504,
30739,
24892,
14,
13607,
14,
1974,
492,
4660,
199,
199,
646,
6858,
421,
199,
318,
5174,
6956,
63,
3919,
63,
4876,
8,
82,
304,
272,
1706,
281,
275,
9954,
1456,
342,
272,
5174,
6956,
63,
2491,
275,
1706,
281,
14,
2491,
63,
509,
360,
3919,
297,
283,
2902,
6956,
358,
272,
340,
440,
2202,
14,
5287,
26,
267,
570,
63,
515,
275,
5174,
6956,
63,
2491,
14,
1199,
63,
1501,
272,
587,
26,
267,
849,
63,
10946,
14,
7112,
342,
267,
3792,
275,
1706,
281,
14,
2014,
8,
2902,
6956,
63,
2491,
14,
3771,
9,
267,
570,
63,
515,
275,
3792,
59,
16,
61,
339,
372,
2955,
8,
493,
63,
515,
9,
421,
199,
20050,
275,
334,
272,
1166,
8,
82,
4289,
2902,
6956,
4537,
3596,
4268,
6858,
14,
2902,
6956,
63,
3596,
12,
536,
534,
2902,
6956,
659,
272,
1166,
8,
82,
4289,
1515,
1700,
4537,
1001,
80,
4268,
6858,
14,
1515,
1700,
63,
1001,
80,
12,
536,
534,
1515,
1700,
659,
339,
4660,
8,
82,
6704,
69,
2391,
15,
3596,
15,
2902,
6956,
4537,
3596,
4268,
283,
2902,
6956,
297,
5867,
63,
1861,
29,
797,
395,
272,
4660,
8,
82,
6704,
69,
2391,
15,
3919,
15,
2902,
6956,
4537,
3919,
4268,
5174,
6956,
63,
3919,
63,
4876,
12,
5867,
63,
1861,
29,
797,
395,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
199,
504,
7679,
14,
10946,
492,
849,
63,
10946,
199,
504,
7679,
14,
1389,
1456,
492,
9954,
1456,
199,
199,
504,
30739,
24892,
14,
1095,
14,
7546,
492,
2955,
199,
504,
30739,
24892,
14,
13607,
14,
1974,
492,
4660,
199,
199,
646,
6858,
421,
199,
318,
5174,
6956,
63,
3919,
63,
4876,
8,
82,
304,
272,
1706,
281,
275,
9954,
1456,
342,
272,
5174,
6956,
63,
2491,
275,
1706,
281,
14,
2491,
63,
509,
360,
3919,
297,
283,
2902,
6956,
358,
272,
340,
440,
2202,
14,
5287,
26,
267,
570,
63,
515,
275,
5174,
6956,
63,
2491,
14,
1199,
63,
1501,
272,
587,
26,
267,
849,
63,
10946,
14,
7112,
342,
267,
3792,
275,
1706,
281,
14,
2014,
8,
2902,
6956,
63,
2491,
14,
3771,
9,
267,
570,
63,
515,
275,
3792,
59,
16,
61,
339,
372,
2955,
8,
493,
63,
515,
9,
421,
199,
20050,
275,
334,
272,
1166,
8,
82,
4289,
2902,
6956,
4537,
3596,
4268,
6858,
14,
2902,
6956,
63,
3596,
12,
536,
534,
2902,
6956,
659,
272,
1166,
8,
82,
4289,
1515,
1700,
4537,
1001,
80,
4268,
6858,
14,
1515,
1700,
63,
1001,
80,
12,
536,
534,
1515,
1700,
659,
339,
4660,
8,
82,
6704,
69,
2391,
15,
3596,
15,
2902,
6956,
4537,
3596,
4268,
283,
2902,
6956,
297,
5867,
63,
1861,
29,
797,
395,
272,
4660,
8,
82,
6704,
69,
2391,
15,
3919,
15,
2902,
6956,
4537,
3919,
4268,
5174,
6956,
63,
3919,
63,
4876,
12,
5867,
63,
1861,
29,
797,
395,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
minhphung171093/OpenERP_V8
|
openerp/addons/web/controllers/main.py
|
40
|
65803
|
# -*- coding: utf-8 -*-
import ast
import base64
import csv
import functools
import glob
import itertools
import jinja2
import logging
import operator
import datetime
import hashlib
import os
import re
import simplejson
import sys
import time
import urllib2
import zlib
from xml.etree import ElementTree
from cStringIO import StringIO
import babel.messages.pofile
import werkzeug.utils
import werkzeug.wrappers
try:
import xlwt
except ImportError:
xlwt = None
import openerp
import openerp.modules.registry
from openerp.addons.base.ir.ir_qweb import AssetsBundle, QWebTemplateNotFound
from openerp.modules import get_module_resource
from openerp.tools import topological_sort
from openerp.tools.translate import _
from openerp.tools import ustr
from openerp import http
from openerp.http import request, serialize_exception as _serialize_exception
_logger = logging.getLogger(__name__)
if hasattr(sys, 'frozen'):
# When running on compiled windows binary, we don't have access to package loader.
path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'views'))
loader = jinja2.FileSystemLoader(path)
else:
loader = jinja2.PackageLoader('openerp.addons.web', "views")
env = jinja2.Environment(loader=loader, autoescape=True)
env.filters["json"] = simplejson.dumps
# 1 week cache for asset bundles as advised by Google Page Speed
BUNDLE_MAXAGE = 60 * 60 * 24 * 7
#----------------------------------------------------------
# OpenERP Web helpers
#----------------------------------------------------------
db_list = http.db_list
db_monodb = http.db_monodb
def serialize_exception(f):
@functools.wraps(f)
def wrap(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception, e:
_logger.exception("An exception occured during an http request")
se = _serialize_exception(e)
error = {
'code': 200,
'message': "Odoo Server Error",
'data': se
}
return werkzeug.exceptions.InternalServerError(simplejson.dumps(error))
return wrap
def redirect_with_hash(*args, **kw):
"""
.. deprecated:: 8.0
Use the ``http.redirect_with_hash()`` function instead.
"""
return http.redirect_with_hash(*args, **kw)
def abort_and_redirect(url):
r = request.httprequest
response = werkzeug.utils.redirect(url, 302)
response = r.app.get_response(r, response, explicit_session=False)
werkzeug.exceptions.abort(response)
def ensure_db(redirect='/web/database/selector'):
# This helper should be used in web client auth="none" routes
# if those routes needs a db to work with.
# If the heuristics does not find any database, then the users will be
# redirected to db selector or any url specified by `redirect` argument.
# If the db is taken out of a query parameter, it will be checked against
# `http.db_filter()` in order to ensure it's legit and thus avoid db
# forgering that could lead to xss attacks.
db = request.params.get('db')
# Ensure db is legit
if db and db not in http.db_filter([db]):
db = None
if db and not request.session.db:
# User asked a specific database on a new session.
# That mean the nodb router has been used to find the route
# Depending on installed module in the database, the rendering of the page
# may depend on data injected by the database route dispatcher.
# Thus, we redirect the user to the same page but with the session cookie set.
# This will force using the database route dispatcher...
r = request.httprequest
url_redirect = r.base_url
if r.query_string:
# Can't use werkzeug.wrappers.BaseRequest.url with encoded hashes:
# https://github.com/amigrave/werkzeug/commit/b4a62433f2f7678c234cdcac6247a869f90a7eb7
url_redirect += '?' + r.query_string
response = werkzeug.utils.redirect(url_redirect, 302)
request.session.db = db
abort_and_redirect(url_redirect)
# if db not provided, use the session one
if not db and request.session.db and http.db_filter([request.session.db]):
db = request.session.db
# if no database provided and no database in session, use monodb
if not db:
db = db_monodb(request.httprequest)
# if no db can be found til here, send to the database selector
# the database selector will redirect to database manager if needed
if not db:
werkzeug.exceptions.abort(werkzeug.utils.redirect(redirect, 303))
# always switch the session to the computed db
if db != request.session.db:
request.session.logout()
abort_and_redirect(request.httprequest.url)
request.session.db = db
def module_installed():
# Candidates module the current heuristic is the /static dir
loadable = http.addons_manifest.keys()
modules = {}
# Retrieve database installed modules
# TODO The following code should move to ir.module.module.list_installed_modules()
Modules = request.session.model('ir.module.module')
domain = [('state','=','installed'), ('name','in', loadable)]
for module in Modules.search_read(domain, ['name', 'dependencies_id']):
modules[module['name']] = []
deps = module.get('dependencies_id')
if deps:
deps_read = request.session.model('ir.module.module.dependency').read(deps, ['name'])
dependencies = [i['name'] for i in deps_read]
modules[module['name']] = dependencies
sorted_modules = topological_sort(modules)
return sorted_modules
def module_installed_bypass_session(dbname):
loadable = http.addons_manifest.keys()
modules = {}
try:
registry = openerp.modules.registry.RegistryManager.get(dbname)
with registry.cursor() as cr:
m = registry.get('ir.module.module')
# TODO The following code should move to ir.module.module.list_installed_modules()
domain = [('state','=','installed'), ('name','in', loadable)]
ids = m.search(cr, 1, [('state','=','installed'), ('name','in', loadable)])
for module in m.read(cr, 1, ids, ['name', 'dependencies_id']):
modules[module['name']] = []
deps = module.get('dependencies_id')
if deps:
deps_read = registry.get('ir.module.module.dependency').read(cr, 1, deps, ['name'])
dependencies = [i['name'] for i in deps_read]
modules[module['name']] = dependencies
except Exception,e:
pass
sorted_modules = topological_sort(modules)
return sorted_modules
def module_boot(db=None):
server_wide_modules = openerp.conf.server_wide_modules or ['web']
serverside = []
dbside = []
for i in server_wide_modules:
if i in http.addons_manifest:
serverside.append(i)
monodb = db or db_monodb()
if monodb:
dbside = module_installed_bypass_session(monodb)
dbside = [i for i in dbside if i not in serverside]
addons = serverside + dbside
return addons
def concat_xml(file_list):
"""Concatenate xml files
:param list(str) file_list: list of files to check
:returns: (concatenation_result, checksum)
:rtype: (str, str)
"""
checksum = hashlib.new('sha1')
if not file_list:
return '', checksum.hexdigest()
root = None
for fname in file_list:
with open(fname, 'rb') as fp:
contents = fp.read()
checksum.update(contents)
fp.seek(0)
xml = ElementTree.parse(fp).getroot()
if root is None:
root = ElementTree.Element(xml.tag)
#elif root.tag != xml.tag:
# raise ValueError("Root tags missmatch: %r != %r" % (root.tag, xml.tag))
for child in xml.getchildren():
root.append(child)
return ElementTree.tostring(root, 'utf-8'), checksum.hexdigest()
def fs2web(path):
"""convert FS path into web path"""
return '/'.join(path.split(os.path.sep))
def manifest_glob(extension, addons=None, db=None, include_remotes=False):
if addons is None:
addons = module_boot(db=db)
else:
addons = addons.split(',')
r = []
for addon in addons:
manifest = http.addons_manifest.get(addon, None)
if not manifest:
continue
# ensure does not ends with /
addons_path = os.path.join(manifest['addons_path'], '')[:-1]
globlist = manifest.get(extension, [])
for pattern in globlist:
if pattern.startswith(('http://', 'https://', '//')):
if include_remotes:
r.append((None, pattern))
else:
for path in glob.glob(os.path.normpath(os.path.join(addons_path, addon, pattern))):
r.append((path, fs2web(path[len(addons_path):])))
return r
def manifest_list(extension, mods=None, db=None, debug=None):
""" list ressources to load specifying either:
mods: a comma separated string listing modules
db: a database name (return all installed modules in that database)
"""
if debug is not None:
_logger.warning("openerp.addons.web.main.manifest_list(): debug parameter is deprecated")
files = manifest_glob(extension, addons=mods, db=db, include_remotes=True)
return [wp for _fp, wp in files]
def get_last_modified(files):
""" Returns the modification time of the most recently modified
file provided
:param list(str) files: names of files to check
:return: most recent modification time amongst the fileset
:rtype: datetime.datetime
"""
files = list(files)
if files:
return max(datetime.datetime.fromtimestamp(os.path.getmtime(f))
for f in files)
return datetime.datetime(1970, 1, 1)
def make_conditional(response, last_modified=None, etag=None, max_age=0):
""" Makes the provided response conditional based upon the request,
and mandates revalidation from clients
Uses Werkzeug's own :meth:`ETagResponseMixin.make_conditional`, after
setting ``last_modified`` and ``etag`` correctly on the response object
:param response: Werkzeug response
:type response: werkzeug.wrappers.Response
:param datetime.datetime last_modified: last modification date of the response content
:param str etag: some sort of checksum of the content (deep etag)
:return: the response object provided
:rtype: werkzeug.wrappers.Response
"""
response.cache_control.must_revalidate = True
response.cache_control.max_age = max_age
if last_modified:
response.last_modified = last_modified
if etag:
response.set_etag(etag)
return response.make_conditional(request.httprequest)
def login_and_redirect(db, login, key, redirect_url='/web'):
request.session.authenticate(db, login, key)
return set_cookie_and_redirect(redirect_url)
def set_cookie_and_redirect(redirect_url):
redirect = werkzeug.utils.redirect(redirect_url, 303)
redirect.autocorrect_location_header = False
return redirect
def login_redirect():
url = '/web/login?'
# built the redirect url, keeping all the query parameters of the url
redirect_url = '%s?%s' % (request.httprequest.base_url, werkzeug.urls.url_encode(request.params))
return """<html><head><script>
window.location = '%sredirect=' + encodeURIComponent("%s");
</script></head></html>
""" % (url, redirect_url)
def load_actions_from_ir_values(key, key2, models, meta):
Values = request.session.model('ir.values')
actions = Values.get(key, key2, models, meta, request.context)
return [(id, name, clean_action(action))
for id, name, action in actions]
def clean_action(action):
action.setdefault('flags', {})
action_type = action.setdefault('type', 'ir.actions.act_window_close')
if action_type == 'ir.actions.act_window':
return fix_view_modes(action)
return action
# I think generate_views,fix_view_modes should go into js ActionManager
def generate_views(action):
"""
While the server generates a sequence called "views" computing dependencies
between a bunch of stuff for views coming directly from the database
(the ``ir.actions.act_window model``), it's also possible for e.g. buttons
to return custom view dictionaries generated on the fly.
In that case, there is no ``views`` key available on the action.
Since the web client relies on ``action['views']``, generate it here from
``view_mode`` and ``view_id``.
Currently handles two different cases:
* no view_id, multiple view_mode
* single view_id, single view_mode
:param dict action: action descriptor dictionary to generate a views key for
"""
view_id = action.get('view_id') or False
if isinstance(view_id, (list, tuple)):
view_id = view_id[0]
# providing at least one view mode is a requirement, not an option
view_modes = action['view_mode'].split(',')
if len(view_modes) > 1:
if view_id:
raise ValueError('Non-db action dictionaries should provide '
'either multiple view modes or a single view '
'mode and an optional view id.\n\n Got view '
'modes %r and view id %r for action %r' % (
view_modes, view_id, action))
action['views'] = [(False, mode) for mode in view_modes]
return
action['views'] = [(view_id, view_modes[0])]
def fix_view_modes(action):
""" For historical reasons, OpenERP has weird dealings in relation to
view_mode and the view_type attribute (on window actions):
* one of the view modes is ``tree``, which stands for both list views
and tree views
* the choice is made by checking ``view_type``, which is either
``form`` for a list view or ``tree`` for an actual tree view
This methods simply folds the view_type into view_mode by adding a
new view mode ``list`` which is the result of the ``tree`` view_mode
in conjunction with the ``form`` view_type.
TODO: this should go into the doc, some kind of "peculiarities" section
:param dict action: an action descriptor
:returns: nothing, the action is modified in place
"""
if not action.get('views'):
generate_views(action)
if action.pop('view_type', 'form') != 'form':
return action
if 'view_mode' in action:
action['view_mode'] = ','.join(
mode if mode != 'tree' else 'list'
for mode in action['view_mode'].split(','))
action['views'] = [
[id, mode if mode != 'tree' else 'list']
for id, mode in action['views']
]
return action
def _local_web_translations(trans_file):
messages = []
try:
with open(trans_file) as t_file:
po = babel.messages.pofile.read_po(t_file)
except Exception:
return
for x in po:
if x.id and x.string and "openerp-web" in x.auto_comments:
messages.append({'id': x.id, 'string': x.string})
return messages
def xml2json_from_elementtree(el, preserve_whitespaces=False):
""" xml2json-direct
Simple and straightforward XML-to-JSON converter in Python
New BSD Licensed
http://code.google.com/p/xml2json-direct/
"""
res = {}
if el.tag[0] == "{":
ns, name = el.tag.rsplit("}", 1)
res["tag"] = name
res["namespace"] = ns[1:]
else:
res["tag"] = el.tag
res["attrs"] = {}
for k, v in el.items():
res["attrs"][k] = v
kids = []
if el.text and (preserve_whitespaces or el.text.strip() != ''):
kids.append(el.text)
for kid in el:
kids.append(xml2json_from_elementtree(kid, preserve_whitespaces))
if kid.tail and (preserve_whitespaces or kid.tail.strip() != ''):
kids.append(kid.tail)
res["children"] = kids
return res
def content_disposition(filename):
filename = ustr(filename)
escaped = urllib2.quote(filename.encode('utf8'))
browser = request.httprequest.user_agent.browser
version = int((request.httprequest.user_agent.version or '0').split('.')[0])
if browser == 'msie' and version < 9:
return "attachment; filename=%s" % escaped
elif browser == 'safari':
return u"attachment; filename=%s" % filename
else:
return "attachment; filename*=UTF-8''%s" % escaped
#----------------------------------------------------------
# OpenERP Web web Controllers
#----------------------------------------------------------
class Home(http.Controller):
@http.route('/', type='http', auth="none")
def index(self, s_action=None, db=None, **kw):
return http.local_redirect('/web', query=request.params, keep_hash=True)
@http.route('/web', type='http', auth="none")
def web_client(self, s_action=None, **kw):
ensure_db()
if request.session.uid:
if kw.get('redirect'):
return werkzeug.utils.redirect(kw.get('redirect'), 303)
if not request.uid:
request.uid = request.session.uid
menu_data = request.registry['ir.ui.menu'].load_menus(request.cr, request.uid, context=request.context)
return request.render('web.webclient_bootstrap', qcontext={'menu_data': menu_data})
else:
return login_redirect()
@http.route('/web/dbredirect', type='http', auth="none")
def web_db_redirect(self, redirect='/', **kw):
ensure_db()
return werkzeug.utils.redirect(redirect, 303)
@http.route('/web/login', type='http', auth="none")
def web_login(self, redirect=None, **kw):
ensure_db()
if request.httprequest.method == 'GET' and redirect and request.session.uid:
return http.redirect_with_hash(redirect)
if not request.uid:
request.uid = openerp.SUPERUSER_ID
values = request.params.copy()
if not redirect:
redirect = '/web?' + request.httprequest.query_string
values['redirect'] = redirect
try:
values['databases'] = http.db_list()
except openerp.exceptions.AccessDenied:
values['databases'] = None
if request.httprequest.method == 'POST':
old_uid = request.uid
uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])
if uid is not False:
return http.redirect_with_hash(redirect)
request.uid = old_uid
values['error'] = "Wrong login/password"
if request.env.ref('web.login', False):
return request.render('web.login', values)
else:
# probably not an odoo compatible database
error = 'Unable to login on database %s' % request.session.db
return werkzeug.utils.redirect('/web/database/selector?error=%s' % error, 303)
@http.route('/login', type='http', auth="none")
def login(self, db, login, key, redirect="/web", **kw):
if not http.db_filter([db]):
return werkzeug.utils.redirect('/', 303)
return login_and_redirect(db, login, key, redirect_url=redirect)
@http.route([
'/web/js/<xmlid>',
'/web/js/<xmlid>/<version>',
], type='http', auth='public')
def js_bundle(self, xmlid, version=None, **kw):
try:
bundle = AssetsBundle(xmlid)
except QWebTemplateNotFound:
return request.not_found()
response = request.make_response(bundle.js(), [('Content-Type', 'application/javascript')])
return make_conditional(response, bundle.last_modified, max_age=BUNDLE_MAXAGE)
@http.route([
'/web/css/<xmlid>',
'/web/css/<xmlid>/<version>',
'/web/css.<int:page>/<xmlid>/<version>',
], type='http', auth='public')
def css_bundle(self, xmlid, version=None, page=None, **kw):
try:
bundle = AssetsBundle(xmlid)
except QWebTemplateNotFound:
return request.not_found()
response = request.make_response(bundle.css(page), [('Content-Type', 'text/css')])
return make_conditional(response, bundle.last_modified, max_age=BUNDLE_MAXAGE)
class WebClient(http.Controller):
@http.route('/web/webclient/csslist', type='json', auth="none")
def csslist(self, mods=None):
return manifest_list('css', mods=mods)
@http.route('/web/webclient/jslist', type='json', auth="none")
def jslist(self, mods=None):
return manifest_list('js', mods=mods)
@http.route('/web/webclient/qweb', type='http', auth="none")
def qweb(self, mods=None, db=None):
files = [f[0] for f in manifest_glob('qweb', addons=mods, db=db)]
last_modified = get_last_modified(files)
if request.httprequest.if_modified_since and request.httprequest.if_modified_since >= last_modified:
return werkzeug.wrappers.Response(status=304)
content, checksum = concat_xml(files)
return make_conditional(
request.make_response(content, [('Content-Type', 'text/xml')]),
last_modified, checksum)
@http.route('/web/webclient/bootstrap_translations', type='json', auth="none")
def bootstrap_translations(self, mods):
""" Load local translations from *.po files, as a temporary solution
until we have established a valid session. This is meant only
for translating the login page and db management chrome, using
the browser's language. """
# For performance reasons we only load a single translation, so for
# sub-languages (that should only be partially translated) we load the
# main language PO instead - that should be enough for the login screen.
lang = request.lang.split('_')[0]
translations_per_module = {}
for addon_name in mods:
if http.addons_manifest[addon_name].get('bootstrap'):
addons_path = http.addons_manifest[addon_name]['addons_path']
f_name = os.path.join(addons_path, addon_name, "i18n", lang + ".po")
if not os.path.exists(f_name):
continue
translations_per_module[addon_name] = {'messages': _local_web_translations(f_name)}
return {"modules": translations_per_module,
"lang_parameters": None}
@http.route('/web/webclient/translations', type='json', auth="none")
def translations(self, mods=None, lang=None):
request.disable_db = False
uid = openerp.SUPERUSER_ID
if mods is None:
m = request.registry.get('ir.module.module')
mods = [x['name'] for x in m.search_read(request.cr, uid,
[('state','=','installed')], ['name'])]
if lang is None:
lang = request.context["lang"]
res_lang = request.registry.get('res.lang')
ids = res_lang.search(request.cr, uid, [("code", "=", lang)])
lang_params = None
if ids:
lang_params = res_lang.read(request.cr, uid, ids[0], ["direction", "date_format", "time_format",
"grouping", "decimal_point", "thousands_sep"])
# Regional languages (ll_CC) must inherit/override their parent lang (ll), but this is
# done server-side when the language is loaded, so we only need to load the user's lang.
ir_translation = request.registry.get('ir.translation')
translations_per_module = {}
messages = ir_translation.search_read(request.cr, uid, [('module','in',mods),('lang','=',lang),
('comments','like','openerp-web'),('value','!=',False),
('value','!=','')],
['module','src','value','lang'], order='module')
for mod, msg_group in itertools.groupby(messages, key=operator.itemgetter('module')):
translations_per_module.setdefault(mod,{'messages':[]})
translations_per_module[mod]['messages'].extend({'id': m['src'],
'string': m['value']} \
for m in msg_group)
return {"modules": translations_per_module,
"lang_parameters": lang_params}
@http.route('/web/webclient/version_info', type='json', auth="none")
def version_info(self):
return openerp.service.common.exp_version()
@http.route('/web/tests', type='http', auth="none")
def index(self, mod=None, **kwargs):
return request.render('web.qunit_suite')
class Proxy(http.Controller):
@http.route('/web/proxy/load', type='json', auth="none")
def load(self, path):
""" Proxies an HTTP request through a JSON request.
It is strongly recommended to not request binary files through this,
as the result will be a binary data blob as well.
:param path: actual request path
:return: file content
"""
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
base_url = request.httprequest.base_url
return Client(request.httprequest.app, BaseResponse).get(path, base_url=base_url).data
class Database(http.Controller):
@http.route('/web/database/selector', type='http', auth="none")
def selector(self, **kw):
try:
dbs = http.db_list()
if not dbs:
return http.local_redirect('/web/database/manager')
except openerp.exceptions.AccessDenied:
dbs = False
return env.get_template("database_selector.html").render({
'databases': dbs,
'debug': request.debug,
'error': kw.get('error')
})
@http.route('/web/database/manager', type='http', auth="none")
def manager(self, **kw):
# TODO: migrate the webclient's database manager to server side views
request.session.logout()
return env.get_template("database_manager.html").render({
'modules': simplejson.dumps(module_boot()),
})
@http.route('/web/database/get_list', type='json', auth="none")
def get_list(self):
# TODO change js to avoid calling this method if in monodb mode
try:
return http.db_list()
except openerp.exceptions.AccessDenied:
monodb = db_monodb()
if monodb:
return [monodb]
raise
@http.route('/web/database/create', type='json', auth="none")
def create(self, fields):
params = dict(map(operator.itemgetter('name', 'value'), fields))
db_created = request.session.proxy("db").create_database(
params['super_admin_pwd'],
params['db_name'],
bool(params.get('demo_data')),
params['db_lang'],
params['create_admin_pwd'])
if db_created:
request.session.authenticate(params['db_name'], 'admin', params['create_admin_pwd'])
return db_created
@http.route('/web/database/duplicate', type='json', auth="none")
def duplicate(self, fields):
params = dict(map(operator.itemgetter('name', 'value'), fields))
duplicate_attrs = (
params['super_admin_pwd'],
params['db_original_name'],
params['db_name'],
)
return request.session.proxy("db").duplicate_database(*duplicate_attrs)
@http.route('/web/database/drop', type='json', auth="none")
def drop(self, fields):
password, db = operator.itemgetter(
'drop_pwd', 'drop_db')(
dict(map(operator.itemgetter('name', 'value'), fields)))
try:
if request.session.proxy("db").drop(password, db):
return True
else:
return False
except openerp.exceptions.AccessDenied:
return {'error': 'AccessDenied', 'title': 'Drop Database'}
except Exception:
return {'error': _('Could not drop database !'), 'title': _('Drop Database')}
@http.route('/web/database/backup', type='http', auth="none")
def backup(self, backup_db, backup_pwd, token, backup_format='zip'):
try:
openerp.service.security.check_super(backup_pwd)
ts = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S")
filename = "%s_%s.%s" % (backup_db, ts, backup_format)
headers = [
('Content-Type', 'application/octet-stream; charset=binary'),
('Content-Disposition', content_disposition(filename)),
]
dump_stream = openerp.service.db.dump_db(backup_db, None, backup_format)
response = werkzeug.wrappers.Response(dump_stream, headers=headers, direct_passthrough=True)
response.set_cookie('fileToken', token)
return response
except Exception, e:
_logger.exception('Database.backup')
return simplejson.dumps([[],[{'error': openerp.tools.ustr(e), 'title': _('Backup Database')}]])
@http.route('/web/database/restore', type='http', auth="none")
def restore(self, db_file, restore_pwd, new_db, mode):
try:
copy = mode == 'copy'
data = base64.b64encode(db_file.read())
request.session.proxy("db").restore(restore_pwd, new_db, data, copy)
return ''
except openerp.exceptions.AccessDenied, e:
raise Exception("AccessDenied")
@http.route('/web/database/change_password', type='json', auth="none")
def change_password(self, fields):
old_password, new_password = operator.itemgetter(
'old_pwd', 'new_pwd')(
dict(map(operator.itemgetter('name', 'value'), fields)))
try:
return request.session.proxy("db").change_admin_password(old_password, new_password)
except openerp.exceptions.AccessDenied:
return {'error': 'AccessDenied', 'title': _('Change Password')}
except Exception:
return {'error': _('Error, password not changed !'), 'title': _('Change Password')}
class Session(http.Controller):
def session_info(self):
request.session.ensure_valid()
return {
"session_id": request.session_id,
"uid": request.session.uid,
"user_context": request.session.get_context() if request.session.uid else {},
"db": request.session.db,
"username": request.session.login,
"company_id": request.env.user.company_id.id if request.session.uid else None,
}
@http.route('/web/session/get_session_info', type='json', auth="none")
def get_session_info(self):
request.uid = request.session.uid
request.disable_db = False
return self.session_info()
@http.route('/web/session/authenticate', type='json', auth="none")
def authenticate(self, db, login, password, base_location=None):
request.session.authenticate(db, login, password)
return self.session_info()
@http.route('/web/session/change_password', type='json', auth="user")
def change_password(self, fields):
old_password, new_password,confirm_password = operator.itemgetter('old_pwd', 'new_password','confirm_pwd')(
dict(map(operator.itemgetter('name', 'value'), fields)))
if not (old_password.strip() and new_password.strip() and confirm_password.strip()):
return {'error':_('You cannot leave any password empty.'),'title': _('Change Password')}
if new_password != confirm_password:
return {'error': _('The new password and its confirmation must be identical.'),'title': _('Change Password')}
try:
if request.session.model('res.users').change_password(
old_password, new_password):
return {'new_password':new_password}
except Exception:
return {'error': _('The old password you provided is incorrect, your password was not changed.'), 'title': _('Change Password')}
return {'error': _('Error, password not changed !'), 'title': _('Change Password')}
@http.route('/web/session/get_lang_list', type='json', auth="none")
def get_lang_list(self):
try:
return request.session.proxy("db").list_lang() or []
except Exception, e:
return {"error": e, "title": _("Languages")}
@http.route('/web/session/modules', type='json', auth="user")
def modules(self):
# return all installed modules. Web client is smart enough to not load a module twice
return module_installed()
@http.route('/web/session/save_session_action', type='json', auth="user")
def save_session_action(self, the_action):
"""
This method store an action object in the session object and returns an integer
identifying that action. The method get_session_action() can be used to get
back the action.
:param the_action: The action to save in the session.
:type the_action: anything
:return: A key identifying the saved action.
:rtype: integer
"""
return request.httpsession.save_action(the_action)
@http.route('/web/session/get_session_action', type='json', auth="user")
def get_session_action(self, key):
"""
Gets back a previously saved action. This method can return None if the action
was saved since too much time (this case should be handled in a smart way).
:param key: The key given by save_session_action()
:type key: integer
:return: The saved action or None.
:rtype: anything
"""
return request.httpsession.get_action(key)
@http.route('/web/session/check', type='json', auth="user")
def check(self):
request.session.assert_valid()
return None
@http.route('/web/session/destroy', type='json', auth="user")
def destroy(self):
request.session.logout()
@http.route('/web/session/logout', type='http', auth="none")
def logout(self, redirect='/web'):
request.session.logout(keep_db=True)
return werkzeug.utils.redirect(redirect, 303)
class Menu(http.Controller):
@http.route('/web/menu/load_needaction', type='json', auth="user")
def load_needaction(self, menu_ids):
""" Loads needaction counters for specific menu ids.
:return: needaction data
:rtype: dict(menu_id: {'needaction_enabled': boolean, 'needaction_counter': int})
"""
return request.session.model('ir.ui.menu').get_needaction_data(menu_ids, request.context)
class DataSet(http.Controller):
@http.route('/web/dataset/search_read', type='json', auth="user")
def search_read(self, model, fields=False, offset=0, limit=False, domain=None, sort=None):
return self.do_search_read(model, fields, offset, limit, domain, sort)
def do_search_read(self, model, fields=False, offset=0, limit=False, domain=None
, sort=None):
""" Performs a search() followed by a read() (if needed) using the
provided search criteria
:param str model: the name of the model to search on
:param fields: a list of the fields to return in the result records
:type fields: [str]
:param int offset: from which index should the results start being returned
:param int limit: the maximum number of records to return
:param list domain: the search domain for the query
:param list sort: sorting directives
:returns: A structure (dict) with two keys: ids (all the ids matching
the (domain, context) pair) and records (paginated records
matching fields selection set)
:rtype: list
"""
Model = request.session.model(model)
records = Model.search_read(domain, fields, offset or 0, limit or False, sort or False,
request.context)
if not records:
return {
'length': 0,
'records': []
}
if limit and len(records) == limit:
length = Model.search_count(domain, request.context)
else:
length = len(records) + (offset or 0)
return {
'length': length,
'records': records
}
@http.route('/web/dataset/load', type='json', auth="user")
def load(self, model, id, fields):
m = request.session.model(model)
value = {}
r = m.read([id], False, request.context)
if r:
value = r[0]
return {'value': value}
def call_common(self, model, method, args, domain_id=None, context_id=None):
return self._call_kw(model, method, args, {})
def _call_kw(self, model, method, args, kwargs):
if method.startswith('_'):
raise Exception("Access Denied: Underscore prefixed methods cannot be remotely called")
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
@http.route('/web/dataset/call', type='json', auth="user")
def call(self, model, method, args, domain_id=None, context_id=None):
return self._call_kw(model, method, args, {})
@http.route(['/web/dataset/call_kw', '/web/dataset/call_kw/<path:path>'], type='json', auth="user")
def call_kw(self, model, method, args, kwargs, path=None):
return self._call_kw(model, method, args, kwargs)
@http.route('/web/dataset/call_button', type='json', auth="user")
def call_button(self, model, method, args, domain_id=None, context_id=None):
action = self._call_kw(model, method, args, {})
if isinstance(action, dict) and action.get('type') != '':
return clean_action(action)
return False
@http.route('/web/dataset/exec_workflow', type='json', auth="user")
def exec_workflow(self, model, id, signal):
return request.session.exec_workflow(model, id, signal)
@http.route('/web/dataset/resequence', type='json', auth="user")
def resequence(self, model, ids, field='sequence', offset=0):
""" Re-sequences a number of records in the model, by their ids
The re-sequencing starts at the first model of ``ids``, the sequence
number is incremented by one after each record and starts at ``offset``
:param ids: identifiers of the records to resequence, in the new sequence order
:type ids: list(id)
:param str field: field used for sequence specification, defaults to
"sequence"
:param int offset: sequence number for first record in ``ids``, allows
starting the resequencing from an arbitrary number,
defaults to ``0``
"""
m = request.session.model(model)
if not m.fields_get([field]):
return False
# python 2.6 has no start parameter
for i, id in enumerate(ids):
m.write(id, { field: i + offset })
return True
class View(http.Controller):
@http.route('/web/view/add_custom', type='json', auth="user")
def add_custom(self, view_id, arch):
CustomView = request.session.model('ir.ui.view.custom')
CustomView.create({
'user_id': request.session.uid,
'ref_id': view_id,
'arch': arch
}, request.context)
return {'result': True}
@http.route('/web/view/undo_custom', type='json', auth="user")
def undo_custom(self, view_id, reset=False):
CustomView = request.session.model('ir.ui.view.custom')
vcustom = CustomView.search([('user_id', '=', request.session.uid), ('ref_id' ,'=', view_id)],
0, False, False, request.context)
if vcustom:
if reset:
CustomView.unlink(vcustom, request.context)
else:
CustomView.unlink([vcustom[0]], request.context)
return {'result': True}
return {'result': False}
class TreeView(View):
@http.route('/web/treeview/action', type='json', auth="user")
def action(self, model, id):
return load_actions_from_ir_values(
'action', 'tree_but_open',[(model, id)],
False)
class Binary(http.Controller):
@http.route('/web/binary/image', type='http', auth="public")
def image(self, model, id, field, **kw):
last_update = '__last_update'
Model = request.registry[model]
cr, uid, context = request.cr, request.uid, request.context
headers = [('Content-Type', 'image/png')]
etag = request.httprequest.headers.get('If-None-Match')
hashed_session = hashlib.md5(request.session_id).hexdigest()
retag = hashed_session
id = None if not id else simplejson.loads(id)
if type(id) is list:
id = id[0] # m2o
try:
if etag:
if not id and hashed_session == etag:
return werkzeug.wrappers.Response(status=304)
else:
date = Model.read(cr, uid, [id], [last_update], context)[0].get(last_update)
if hashlib.md5(date).hexdigest() == etag:
return werkzeug.wrappers.Response(status=304)
if not id:
res = Model.default_get(cr, uid, [field], context).get(field)
image_base64 = res
else:
res = Model.read(cr, uid, [id], [last_update, field], context)[0]
retag = hashlib.md5(res.get(last_update)).hexdigest()
image_base64 = res.get(field)
if kw.get('resize'):
resize = kw.get('resize').split(',')
if len(resize) == 2 and int(resize[0]) and int(resize[1]):
width = int(resize[0])
height = int(resize[1])
# resize maximum 500*500
if width > 500: width = 500
if height > 500: height = 500
image_base64 = openerp.tools.image_resize_image(base64_source=image_base64, size=(width, height), encoding='base64', filetype='PNG')
image_data = base64.b64decode(image_base64)
except Exception:
image_data = self.placeholder()
headers.append(('ETag', retag))
headers.append(('Content-Length', len(image_data)))
try:
ncache = int(kw.get('cache'))
headers.append(('Cache-Control', 'no-cache' if ncache == 0 else 'max-age=%s' % (ncache)))
except:
pass
return request.make_response(image_data, headers)
def placeholder(self, image='placeholder.png'):
addons_path = http.addons_manifest['web']['addons_path']
return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', image), 'rb').read()
@http.route('/web/binary/saveas', type='http', auth="public")
@serialize_exception
def saveas(self, model, field, id=None, filename_field=None, **kw):
""" Download link for files stored as binary fields.
If the ``id`` parameter is omitted, fetches the default value for the
binary field (via ``default_get``), otherwise fetches the field for
that precise record.
:param str model: name of the model to fetch the binary from
:param str field: binary field
:param str id: id of the record from which to fetch the binary
:param str filename_field: field holding the file's name, if any
:returns: :class:`werkzeug.wrappers.Response`
"""
Model = request.registry[model]
cr, uid, context = request.cr, request.uid, request.context
fields = [field]
if filename_field:
fields.append(filename_field)
if id:
res = Model.read(cr, uid, [int(id)], fields, context)[0]
else:
res = Model.default_get(cr, uid, fields, context)
filecontent = base64.b64decode(res.get(field) or '')
if not filecontent:
return request.not_found()
else:
filename = '%s_%s' % (model.replace('.', '_'), id)
if filename_field:
filename = res.get(filename_field, '') or filename
return request.make_response(filecontent,
[('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename))])
@http.route('/web/binary/saveas_ajax', type='http', auth="public")
@serialize_exception
def saveas_ajax(self, data, token):
jdata = simplejson.loads(data)
model = jdata['model']
field = jdata['field']
data = jdata['data']
id = jdata.get('id', None)
filename_field = jdata.get('filename_field', None)
context = jdata.get('context', {})
Model = request.session.model(model)
fields = [field]
if filename_field:
fields.append(filename_field)
if data:
res = {field: data, filename_field: jdata.get('filename', None)}
elif id:
res = Model.read([int(id)], fields, context)[0]
else:
res = Model.default_get(fields, context)
filecontent = base64.b64decode(res.get(field) or '')
if not filecontent:
raise ValueError(_("No content found for field '%s' on '%s:%s'") %
(field, model, id))
else:
filename = '%s_%s' % (model.replace('.', '_'), id)
if filename_field:
filename = res.get(filename_field, '') or filename
return request.make_response(filecontent,
headers=[('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename))],
cookies={'fileToken': token})
@http.route('/web/binary/upload', type='http', auth="user")
@serialize_exception
def upload(self, callback, ufile):
# TODO: might be useful to have a configuration flag for max-length file uploads
out = """<script language="javascript" type="text/javascript">
var win = window.top.window;
win.jQuery(win).trigger(%s, %s);
</script>"""
try:
data = ufile.read()
args = [len(data), ufile.filename,
ufile.content_type, base64.b64encode(data)]
except Exception, e:
args = [False, e.message]
return out % (simplejson.dumps(callback), simplejson.dumps(args))
@http.route('/web/binary/upload_attachment', type='http', auth="user")
@serialize_exception
def upload_attachment(self, callback, model, id, ufile):
Model = request.session.model('ir.attachment')
out = """<script language="javascript" type="text/javascript">
var win = window.top.window;
win.jQuery(win).trigger(%s, %s);
</script>"""
try:
attachment_id = Model.create({
'name': ufile.filename,
'datas': base64.encodestring(ufile.read()),
'datas_fname': ufile.filename,
'res_model': model,
'res_id': int(id)
}, request.context)
args = {
'filename': ufile.filename,
'id': attachment_id
}
except Exception:
args = {'error': "Something horrible happened"}
_logger.exception("Fail to upload attachment %s" % ufile.filename)
return out % (simplejson.dumps(callback), simplejson.dumps(args))
@http.route([
'/web/binary/company_logo',
'/logo',
'/logo.png',
], type='http', auth="none", cors="*")
def company_logo(self, dbname=None, **kw):
imgname = 'logo.png'
placeholder = functools.partial(get_module_resource, 'web', 'static', 'src', 'img')
uid = None
if request.session.db:
dbname = request.session.db
uid = request.session.uid
elif dbname is None:
dbname = db_monodb()
if not uid:
uid = openerp.SUPERUSER_ID
if not dbname:
response = http.send_file(placeholder(imgname))
else:
try:
# create an empty registry
registry = openerp.modules.registry.Registry(dbname)
with registry.cursor() as cr:
cr.execute("""SELECT c.logo_web, c.write_date
FROM res_users u
LEFT JOIN res_company c
ON c.id = u.company_id
WHERE u.id = %s
""", (uid,))
row = cr.fetchone()
if row and row[0]:
image_data = StringIO(str(row[0]).decode('base64'))
response = http.send_file(image_data, filename=imgname, mtime=row[1])
else:
response = http.send_file(placeholder('nologo.png'))
except Exception:
response = http.send_file(placeholder(imgname))
return response
class Action(http.Controller):
@http.route('/web/action/load', type='json', auth="user")
def load(self, action_id, do_not_eval=False, additional_context=None):
Actions = request.session.model('ir.actions.actions')
value = False
try:
action_id = int(action_id)
except ValueError:
try:
module, xmlid = action_id.split('.', 1)
model, action_id = request.session.model('ir.model.data').get_object_reference(module, xmlid)
assert model.startswith('ir.actions.')
except Exception:
action_id = 0 # force failed read
base_action = Actions.read([action_id], ['type'], request.context)
if base_action:
ctx = request.context
action_type = base_action[0]['type']
if action_type == 'ir.actions.report.xml':
ctx.update({'bin_size': True})
if additional_context:
ctx.update(additional_context)
action = request.session.model(action_type).read([action_id], False, ctx)
if action:
value = clean_action(action[0])
return value
@http.route('/web/action/run', type='json', auth="user")
def run(self, action_id):
return_action = request.session.model('ir.actions.server').run(
[action_id], request.context)
if return_action:
return clean_action(return_action)
else:
return False
class Export(http.Controller):
@http.route('/web/export/formats', type='json', auth="user")
def formats(self):
""" Returns all valid export formats
:returns: for each export format, a pair of identifier and printable name
:rtype: [(str, str)]
"""
return [
{'tag': 'csv', 'label': 'CSV'},
{'tag': 'xls', 'label': 'Excel', 'error': None if xlwt else "XLWT required"},
]
def fields_get(self, model):
Model = request.session.model(model)
fields = Model.fields_get(False, request.context)
return fields
@http.route('/web/export/get_fields', type='json', auth="user")
def get_fields(self, model, prefix='', parent_name= '',
import_compat=True, parent_field_type=None,
exclude=None):
if import_compat and parent_field_type == "many2one":
fields = {}
else:
fields = self.fields_get(model)
if import_compat:
fields.pop('id', None)
else:
fields['.id'] = fields.pop('id', {'string': 'ID'})
fields_sequence = sorted(fields.iteritems(),
key=lambda field: openerp.tools.ustr(field[1].get('string', '')))
records = []
for field_name, field in fields_sequence:
if import_compat:
if exclude and field_name in exclude:
continue
if field.get('readonly'):
# If none of the field's states unsets readonly, skip the field
if all(dict(attrs).get('readonly', True)
for attrs in field.get('states', {}).values()):
continue
if not field.get('exportable', True):
continue
id = prefix + (prefix and '/'or '') + field_name
name = parent_name + (parent_name and '/' or '') + field['string']
record = {'id': id, 'string': name,
'value': id, 'children': False,
'field_type': field.get('type'),
'required': field.get('required'),
'relation_field': field.get('relation_field')}
records.append(record)
if len(name.split('/')) < 3 and 'relation' in field:
ref = field.pop('relation')
record['value'] += '/id'
record['params'] = {'model': ref, 'prefix': id, 'name': name}
if not import_compat or field['type'] == 'one2many':
# m2m field in import_compat is childless
record['children'] = True
return records
@http.route('/web/export/namelist', type='json', auth="user")
def namelist(self, model, export_id):
# TODO: namelist really has no reason to be in Python (although itertools.groupby helps)
export = request.session.model("ir.exports").read([export_id])[0]
export_fields_list = request.session.model("ir.exports.line").read(
export['export_fields'])
fields_data = self.fields_info(
model, map(operator.itemgetter('name'), export_fields_list))
return [
{'name': field['name'], 'label': fields_data[field['name']]}
for field in export_fields_list
]
def fields_info(self, model, export_fields):
info = {}
fields = self.fields_get(model)
if ".id" in export_fields:
fields['.id'] = fields.pop('id', {'string': 'ID'})
# To make fields retrieval more efficient, fetch all sub-fields of a
# given field at the same time. Because the order in the export list is
# arbitrary, this requires ordering all sub-fields of a given field
# together so they can be fetched at the same time
#
# Works the following way:
# * sort the list of fields to export, the default sorting order will
# put the field itself (if present, for xmlid) and all of its
# sub-fields right after it
# * then, group on: the first field of the path (which is the same for
# a field and for its subfields and the length of splitting on the
# first '/', which basically means grouping the field on one side and
# all of the subfields on the other. This way, we have the field (for
# the xmlid) with length 1, and all of the subfields with the same
# base but a length "flag" of 2
# * if we have a normal field (length 1), just add it to the info
# mapping (with its string) as-is
# * otherwise, recursively call fields_info via graft_subfields.
# all graft_subfields does is take the result of fields_info (on the
# field's model) and prepend the current base (current field), which
# rebuilds the whole sub-tree for the field
#
# result: because we're not fetching the fields_get for half the
# database models, fetching a namelist with a dozen fields (including
# relational data) falls from ~6s to ~300ms (on the leads model).
# export lists with no sub-fields (e.g. import_compatible lists with
# no o2m) are even more efficient (from the same 6s to ~170ms, as
# there's a single fields_get to execute)
for (base, length), subfields in itertools.groupby(
sorted(export_fields),
lambda field: (field.split('/', 1)[0], len(field.split('/', 1)))):
subfields = list(subfields)
if length == 2:
# subfields is a seq of $base/*rest, and not loaded yet
info.update(self.graft_subfields(
fields[base]['relation'], base, fields[base]['string'],
subfields
))
elif base in fields:
info[base] = fields[base]['string']
return info
def graft_subfields(self, model, prefix, prefix_string, fields):
export_fields = [field.split('/', 1)[1] for field in fields]
return (
(prefix + '/' + k, prefix_string + '/' + v)
for k, v in self.fields_info(model, export_fields).iteritems())
class ExportFormat(object):
raw_data = False
@property
def content_type(self):
""" Provides the format's content type """
raise NotImplementedError()
def filename(self, base):
""" Creates a valid filename for the format (with extension) from the
provided base name (exension-less)
"""
raise NotImplementedError()
def from_data(self, fields, rows):
""" Conversion method from OpenERP's export data to whatever the
current export class outputs
:params list fields: a list of fields to export
:params list rows: a list of records to export
:returns:
:rtype: bytes
"""
raise NotImplementedError()
def base(self, data, token):
params = simplejson.loads(data)
model, fields, ids, domain, import_compat = \
operator.itemgetter('model', 'fields', 'ids', 'domain',
'import_compat')(
params)
Model = request.session.model(model)
context = dict(request.context or {}, **params.get('context', {}))
ids = ids or Model.search(domain, 0, False, False, context)
if not request.env[model]._is_an_ordinary_table():
fields = [field for field in fields if field['name'] != 'id']
field_names = map(operator.itemgetter('name'), fields)
import_data = Model.export_data(ids, field_names, self.raw_data, context=context).get('datas',[])
if import_compat:
columns_headers = field_names
else:
columns_headers = [val['label'].strip() for val in fields]
return request.make_response(self.from_data(columns_headers, import_data),
headers=[('Content-Disposition',
content_disposition(self.filename(model))),
('Content-Type', self.content_type)],
cookies={'fileToken': token})
class CSVExport(ExportFormat, http.Controller):
@http.route('/web/export/csv', type='http', auth="user")
@serialize_exception
def index(self, data, token):
return self.base(data, token)
@property
def content_type(self):
return 'text/csv;charset=utf8'
def filename(self, base):
return base + '.csv'
def from_data(self, fields, rows):
fp = StringIO()
writer = csv.writer(fp, quoting=csv.QUOTE_ALL)
writer.writerow([name.encode('utf-8') for name in fields])
for data in rows:
row = []
for d in data:
if isinstance(d, basestring):
d = d.replace('\n',' ').replace('\t',' ')
try:
d = d.encode('utf-8')
except UnicodeError:
pass
if d is False: d = None
row.append(d)
writer.writerow(row)
fp.seek(0)
data = fp.read()
fp.close()
return data
class ExcelExport(ExportFormat, http.Controller):
# Excel needs raw data to correctly handle numbers and date values
raw_data = True
@http.route('/web/export/xls', type='http', auth="user")
@serialize_exception
def index(self, data, token):
return self.base(data, token)
@property
def content_type(self):
return 'application/vnd.ms-excel'
def filename(self, base):
return base + '.xls'
def from_data(self, fields, rows):
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('Sheet 1')
for i, fieldname in enumerate(fields):
worksheet.write(0, i, fieldname)
worksheet.col(i).width = 8000 # around 220 pixels
base_style = xlwt.easyxf('align: wrap yes')
date_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD')
datetime_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD HH:mm:SS')
for row_index, row in enumerate(rows):
for cell_index, cell_value in enumerate(row):
cell_style = base_style
if isinstance(cell_value, basestring):
cell_value = re.sub("\r", " ", cell_value)
elif isinstance(cell_value, datetime.datetime):
cell_style = datetime_style
elif isinstance(cell_value, datetime.date):
cell_style = date_style
worksheet.write(row_index + 1, cell_index, cell_value, cell_style)
fp = StringIO()
workbook.save(fp)
fp.seek(0)
data = fp.read()
fp.close()
return data
class Reports(http.Controller):
POLLING_DELAY = 0.25
TYPES_MAPPING = {
'doc': 'application/vnd.ms-word',
'html': 'text/html',
'odt': 'application/vnd.oasis.opendocument.text',
'pdf': 'application/pdf',
'sxw': 'application/vnd.sun.xml.writer',
'xls': 'application/vnd.ms-excel',
}
@http.route('/web/report', type='http', auth="user")
@serialize_exception
def index(self, action, token):
action = simplejson.loads(action)
report_srv = request.session.proxy("report")
context = dict(request.context)
context.update(action["context"])
report_data = {}
report_ids = context.get("active_ids", None)
if 'report_type' in action:
report_data['report_type'] = action['report_type']
if 'datas' in action:
if 'ids' in action['datas']:
report_ids = action['datas'].pop('ids')
report_data.update(action['datas'])
report_id = report_srv.report(
request.session.db, request.session.uid, request.session.password,
action["report_name"], report_ids,
report_data, context)
report_struct = None
while True:
report_struct = report_srv.report_get(
request.session.db, request.session.uid, request.session.password, report_id)
if report_struct["state"]:
break
time.sleep(self.POLLING_DELAY)
report = base64.b64decode(report_struct['result'])
if report_struct.get('code') == 'zlib':
report = zlib.decompress(report)
report_mimetype = self.TYPES_MAPPING.get(
report_struct['format'], 'octet-stream')
file_name = action.get('name', 'report')
if 'name' not in action:
reports = request.session.model('ir.actions.report.xml')
res_id = reports.search([('report_name', '=', action['report_name']),],
0, False, False, context)
if len(res_id) > 0:
file_name = reports.read(res_id[0], ['name'], context)['name']
else:
file_name = action['report_name']
file_name = '%s.%s' % (file_name, report_struct['format'])
return request.make_response(report,
headers=[
('Content-Disposition', content_disposition(file_name)),
('Content-Type', report_mimetype),
('Content-Length', len(report))],
cookies={'fileToken': token})
class Apps(http.Controller):
@http.route('/apps/<app>', auth='user')
def get_app_url(self, req, app):
act_window_obj = request.session.model('ir.actions.act_window')
ir_model_data = request.session.model('ir.model.data')
try:
action_id = ir_model_data.get_object_reference('base', 'open_module_tree')[1]
action = act_window_obj.read(action_id, ['name', 'type', 'res_model', 'view_mode', 'view_type', 'context', 'views', 'domain'])
action['target'] = 'current'
except ValueError:
action = False
try:
app_id = ir_model_data.get_object_reference('base', 'module_%s' % app)[1]
except ValueError:
app_id = False
if action and app_id:
action['res_id'] = app_id
action['view_mode'] = 'form'
action['views'] = [(False, u'form')]
sakey = Session().save_session_action(action)
debug = '?debug' if req.debug else ''
return werkzeug.utils.redirect('/web{0}#sa={1}'.format(debug, sakey))
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
6073,
199,
646,
1300,
772,
199,
646,
7392,
199,
646,
9143,
199,
646,
5739,
199,
646,
7975,
199,
646,
10321,
18,
199,
646,
2050,
199,
646,
4182,
199,
646,
2197,
199,
646,
8337,
199,
646,
747,
199,
646,
295,
199,
646,
13804,
199,
646,
984,
199,
646,
900,
199,
646,
4011,
18,
199,
646,
12472,
199,
504,
2748,
14,
9464,
492,
13139,
199,
504,
15073,
492,
5228,
199,
199,
646,
29178,
14,
3431,
14,
555,
493,
199,
646,
10380,
14,
1208,
199,
646,
10380,
14,
21148,
199,
893,
26,
272,
492,
25077,
9115,
199,
2590,
3545,
26,
272,
25077,
9115,
275,
488,
199,
199,
646,
5166,
199,
646,
5166,
14,
3112,
14,
5189,
199,
504,
5166,
14,
10788,
14,
1095,
14,
723,
14,
723,
63,
22600,
492,
3709,
2193,
12320,
12,
1413,
5926,
4231,
4667,
199,
504,
5166,
14,
3112,
492,
664,
63,
578,
63,
1927,
199,
504,
5166,
14,
2537,
492,
11111,
7954,
63,
3191,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
2537,
492,
399,
495,
199,
504,
5166,
492,
1455,
199,
199,
504,
5166,
14,
1014,
492,
1056,
12,
8437,
63,
1971,
465,
485,
3549,
63,
1971,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
692,
2688,
8,
1274,
12,
283,
11202,
735,
272,
327,
3979,
3879,
641,
10311,
10061,
3366,
12,
781,
2793,
1133,
1172,
2879,
370,
2559,
5077,
14,
272,
931,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
19155,
283,
4196,
1333,
272,
5077,
275,
10321,
18,
14,
17521,
5455,
8,
515,
9,
199,
2836,
26,
272,
5077,
275,
10321,
18,
14,
8599,
5455,
360,
11267,
14,
10788,
14,
2520,
297,
298,
4196,
531,
199,
199,
1813,
275,
10321,
18,
14,
8263,
8,
3422,
29,
3422,
12,
19102,
29,
549,
9,
199,
1813,
14,
4273,
905,
1001,
937,
275,
13804,
14,
4180,
199,
199,
3,
413,
8620,
2581,
367,
8977,
27206,
465,
1503,
17311,
701,
4475,
10331,
428,
4536,
199,
32044,
906,
63,
4283,
2962,
275,
5212,
627,
5212,
627,
5504,
627,
1520,
199,
199,
30346,
199,
3,
7653,
6001,
10897,
199,
30346,
199,
199,
697,
63,
513,
275,
1455,
14,
697,
63,
513,
199,
199,
697,
63,
2106,
13152,
275,
1455,
14,
697,
63,
2106,
13152,
199,
199,
318,
8437,
63,
1971,
8,
70,
304,
272,
768,
17869,
14,
13582,
8,
70,
9,
272,
347,
4816,
2031,
589,
12,
1011,
958,
304,
267,
862,
26,
288,
372,
289,
2031,
589,
12,
1011,
958,
9,
267,
871,
2186,
12,
325,
26,
288,
485,
2921,
14,
1971,
480,
2493,
1919,
28408,
5309,
376,
1455,
1056,
531,
288,
542,
275,
485,
3549,
63,
1971,
8,
69,
9,
288,
1125,
275,
469,
355,
283,
600,
356,
1926,
12,
355,
283,
1188,
356,
298,
47,
16766,
7146,
4520,
401,
355,
283,
576,
356,
542,
288,
789,
288,
372,
10380,
14,
3924,
14,
8405,
17692,
8,
4129,
1001,
14,
4180,
8,
705,
430,
272,
372,
4816,
199,
199,
318,
4660,
63,
1045,
63,
2227,
2031,
589,
12,
1011,
829,
304,
272,
408,
267,
2508,
5906,
447,
1695,
14,
16,
398,
3645,
314,
1124,
1014,
14,
4876,
63,
1045,
63,
2227,
8497,
805,
3140,
14,
272,
408,
272,
372,
1455,
14,
4876,
63,
1045,
63,
2227,
2031,
589,
12,
1011,
829,
9,
199,
199,
318,
12004,
63,
460,
63,
4876,
8,
633,
304,
272,
519,
275,
1056,
14,
16916,
26762,
272,
1177,
275,
10380,
14,
1208,
14,
4876,
8,
633,
12,
11485,
9,
272,
1177,
275,
519,
14,
571,
14,
362,
63,
1310,
8,
82,
12,
1177,
12,
5027,
63,
1730,
29,
797,
9,
272,
10380,
14,
3924,
14,
13845,
8,
1310,
9,
199,
199,
318,
4868,
63,
697,
8,
4876,
8805,
2520,
15,
4659,
15,
6662,
735,
272,
327,
961,
5922,
1077,
506,
1202,
315,
3330,
1890,
1790,
628,
3592,
2,
15777,
272,
327,
340,
5204,
15777,
4839,
282,
1592,
370,
1736,
543,
14,
272,
327,
982,
314,
946,
300,
631,
2932,
1630,
440,
2342,
1263,
3050,
12,
2066,
314,
4390,
911,
506,
272,
327,
20884,
370,
1592,
9759,
503,
1263,
1166,
2013,
701,
658,
4876,
64,
1423,
14,
272,
327,
982,
314,
1592,
365,
9394,
734,
402,
282,
1827,
2725,
12,
652,
911,
506,
7923,
6169,
272,
327,
658,
1014,
14,
697,
63,
1541,
11995,
315,
1865,
370,
4868,
652,
1159,
1026,
3187,
436,
12850,
5126,
1592,
272,
327,
367,
836,
316,
626,
4293,
12690,
370,
671,
385,
28140,
14,
272,
1592,
275,
1056,
14,
1162,
14,
362,
360,
697,
358,
339,
327,
7523,
1592,
365,
1026,
3187,
272,
340,
1592,
436,
1592,
440,
315,
1455,
14,
697,
63,
1541,
779,
697,
4682,
267,
1592,
275,
488,
339,
340,
1592,
436,
440,
1056,
14,
1730,
14,
697,
26,
267,
327,
2876,
20864,
282,
2488,
3050,
641,
282,
892,
2351,
14,
267,
327,
10314,
4615,
314,
302,
13152,
6197,
965,
2757,
1202,
370,
2342,
314,
7475,
267,
327,
1487,
6455,
641,
4903,
859,
315,
314,
3050,
12,
314,
14066,
402,
314,
2034,
267,
327,
1443,
11687,
641,
666,
26121,
701,
314,
3050,
7475,
17475,
14,
267,
327,
20227,
12,
781,
4660,
314,
922,
370,
314,
2011,
2034,
1325,
543,
314,
2351,
5494,
663,
14,
267,
327,
961,
911,
3542,
1808,
314,
3050,
7475,
17475,
1396,
267,
519,
275,
1056,
14,
16916,
26762,
267,
1166,
63,
4876,
275,
519,
14,
1095,
63,
633,
267,
340,
519,
14,
1131,
63,
875,
26,
288,
327,
6855,
1133,
675,
10380,
14,
21148,
14,
1563,
2017,
14,
633,
543,
5737,
14647,
26,
288,
327,
4178,
921,
5031,
14,
957,
15,
455,
528,
345,
432,
15,
17719,
15,
3543,
15,
66,
20,
65,
28062,
1153,
70,
18,
70,
14787,
24,
67,
5533,
2866,
11055,
22,
11717,
65,
13254,
70,
2710,
65,
23,
2871,
23,
288,
1166,
63,
4876,
847,
15539,
435,
519,
14,
1131,
63,
875,
267,
1177,
275,
10380,
14,
1208,
14,
4876,
8,
633,
63,
4876,
12,
11485,
9,
267,
1056,
14,
1730,
14,
697,
275,
1592,
267,
12004,
63,
460,
63,
4876,
8,
633,
63,
4876,
9,
339,
327,
340,
1592,
440
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
6073,
199,
646,
1300,
772,
199,
646,
7392,
199,
646,
9143,
199,
646,
5739,
199,
646,
7975,
199,
646,
10321,
18,
199,
646,
2050,
199,
646,
4182,
199,
646,
2197,
199,
646,
8337,
199,
646,
747,
199,
646,
295,
199,
646,
13804,
199,
646,
984,
199,
646,
900,
199,
646,
4011,
18,
199,
646,
12472,
199,
504,
2748,
14,
9464,
492,
13139,
199,
504,
15073,
492,
5228,
199,
199,
646,
29178,
14,
3431,
14,
555,
493,
199,
646,
10380,
14,
1208,
199,
646,
10380,
14,
21148,
199,
893,
26,
272,
492,
25077,
9115,
199,
2590,
3545,
26,
272,
25077,
9115,
275,
488,
199,
199,
646,
5166,
199,
646,
5166,
14,
3112,
14,
5189,
199,
504,
5166,
14,
10788,
14,
1095,
14,
723,
14,
723,
63,
22600,
492,
3709,
2193,
12320,
12,
1413,
5926,
4231,
4667,
199,
504,
5166,
14,
3112,
492,
664,
63,
578,
63,
1927,
199,
504,
5166,
14,
2537,
492,
11111,
7954,
63,
3191,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
2537,
492,
399,
495,
199,
504,
5166,
492,
1455,
199,
199,
504,
5166,
14,
1014,
492,
1056,
12,
8437,
63,
1971,
465,
485,
3549,
63,
1971,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
692,
2688,
8,
1274,
12,
283,
11202,
735,
272,
327,
3979,
3879,
641,
10311,
10061,
3366,
12,
781,
2793,
1133,
1172,
2879,
370,
2559,
5077,
14,
272,
931,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
19155,
283,
4196,
1333,
272,
5077,
275,
10321,
18,
14,
17521,
5455,
8,
515,
9,
199,
2836,
26,
272,
5077,
275,
10321,
18,
14,
8599,
5455,
360,
11267,
14,
10788,
14,
2520,
297,
298,
4196,
531,
199,
199,
1813,
275,
10321,
18,
14,
8263,
8,
3422,
29,
3422,
12,
19102,
29,
549,
9,
199,
1813,
14,
4273,
905,
1001,
937,
275,
13804,
14,
4180,
199,
199,
3,
413,
8620,
2581,
367,
8977,
27206,
465,
1503,
17311,
701,
4475,
10331,
428,
4536,
199,
32044,
906,
63,
4283,
2962,
275,
5212,
627,
5212,
627,
5504,
627,
1520,
199,
199,
30346,
199,
3,
7653,
6001,
10897,
199,
30346,
199,
199,
697,
63,
513,
275,
1455,
14,
697,
63,
513,
199,
199,
697,
63,
2106,
13152,
275,
1455,
14,
697,
63,
2106,
13152,
199,
199,
318,
8437,
63,
1971,
8,
70,
304,
272,
768,
17869,
14,
13582,
8,
70,
9,
272,
347,
4816,
2031,
589,
12,
1011,
958,
304,
267,
862,
26,
288,
372,
289,
2031,
589,
12,
1011,
958,
9,
267,
871,
2186,
12,
325,
26,
288,
485,
2921,
14,
1971,
480,
2493,
1919,
28408,
5309,
376,
1455,
1056,
531,
288,
542,
275,
485,
3549,
63,
1971,
8,
69,
9,
288,
1125,
275,
469,
355,
283,
600,
356,
1926,
12,
355,
283,
1188,
356,
298,
47,
16766,
7146,
4520,
401,
355,
283,
576,
356,
542,
288,
789,
288,
372,
10380,
14,
3924,
14,
8405,
17692,
8,
4129,
1001,
14,
4180,
8,
705,
430,
272,
372,
4816,
199,
199,
318,
4660,
63,
1045,
63,
2227,
2031,
589,
12,
1011,
829,
304,
272,
408,
267,
2508,
5906,
447,
1695,
14,
16,
398,
3645,
314,
1124,
1014,
14,
4876,
63,
1045,
63,
2227,
8497,
805,
3140,
14,
272,
408,
272,
372,
1455,
14,
4876,
63,
1045,
63,
2227,
2031,
589,
12,
1011,
829,
9,
199,
199,
318,
12004,
63,
460,
63,
4876,
8,
633,
304,
272,
519,
275,
1056,
14,
16916,
26762,
272,
1177,
275,
10380,
14,
1208,
14,
4876,
8,
633,
12,
11485,
9,
272,
1177,
275,
519,
14,
571,
14,
362,
63,
1310,
8,
82,
12,
1177,
12,
5027,
63,
1730,
29,
797,
9,
272,
10380,
14,
3924,
14,
13845,
8,
1310,
9,
199,
199,
318,
4868,
63,
697,
8,
4876,
8805,
2520,
15,
4659,
15,
6662,
735,
272,
327,
961,
5922,
1077,
506,
1202,
315,
3330,
1890,
1790,
628,
3592,
2,
15777,
272,
327,
340,
5204,
15777,
4839,
282,
1592,
370,
1736,
543,
14,
272,
327,
982,
314,
946,
300,
631,
2932,
1630,
440,
2342,
1263,
3050,
12,
2066,
314,
4390,
911,
506,
272,
327,
20884,
370,
1592,
9759,
503,
1263,
1166,
2013,
701,
658,
4876,
64,
1423,
14,
272,
327,
982,
314,
1592,
365,
9394,
734,
402,
282,
1827,
2725,
12,
652,
911,
506,
7923,
6169,
272,
327,
658,
1014,
14,
697,
63,
1541,
11995,
315,
1865,
370,
4868,
652,
1159,
1026,
3187,
436,
12850,
5126,
1592,
272,
327,
367,
836,
316,
626,
4293,
12690,
370,
671,
385,
28140,
14,
272,
1592,
275,
1056,
14,
1162,
14,
362,
360,
697,
358,
339,
327,
7523,
1592,
365,
1026,
3187,
272,
340,
1592,
436,
1592,
440,
315,
1455,
14,
697,
63,
1541,
779,
697,
4682,
267,
1592,
275,
488,
339,
340,
1592,
436,
440,
1056,
14,
1730,
14,
697,
26,
267,
327,
2876,
20864,
282,
2488,
3050,
641,
282,
892,
2351,
14,
267,
327,
10314,
4615,
314,
302,
13152,
6197,
965,
2757,
1202,
370,
2342,
314,
7475,
267,
327,
1487,
6455,
641,
4903,
859,
315,
314,
3050,
12,
314,
14066,
402,
314,
2034,
267,
327,
1443,
11687,
641,
666,
26121,
701,
314,
3050,
7475,
17475,
14,
267,
327,
20227,
12,
781,
4660,
314,
922,
370,
314,
2011,
2034,
1325,
543,
314,
2351,
5494,
663,
14,
267,
327,
961,
911,
3542,
1808,
314,
3050,
7475,
17475,
1396,
267,
519,
275,
1056,
14,
16916,
26762,
267,
1166,
63,
4876,
275,
519,
14,
1095,
63,
633,
267,
340,
519,
14,
1131,
63,
875,
26,
288,
327,
6855,
1133,
675,
10380,
14,
21148,
14,
1563,
2017,
14,
633,
543,
5737,
14647,
26,
288,
327,
4178,
921,
5031,
14,
957,
15,
455,
528,
345,
432,
15,
17719,
15,
3543,
15,
66,
20,
65,
28062,
1153,
70,
18,
70,
14787,
24,
67,
5533,
2866,
11055,
22,
11717,
65,
13254,
70,
2710,
65,
23,
2871,
23,
288,
1166,
63,
4876,
847,
15539,
435,
519,
14,
1131,
63,
875,
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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
] |
manipopopo/tensorflow
|
tensorflow/contrib/model_pruning/python/pruning_utils.py
|
14
|
11088
|
# Copyright 2017 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.
# ==============================================================================
"""Utility functions for adding pruning related ops to the graph.
"""
# pylint: disable=missing-docstring
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import clip_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import init_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn_ops
from tensorflow.python.ops import state_ops
from tensorflow.python.ops import variable_scope
_NBINS = 256
def weight_mask_variable(var, scope):
"""Create a mask for the weights.
This function adds a variable 'mask' to the graph.
Args:
var: the weight variable that needs to be masked
scope: The variable scope of the variable var
Returns:
the mask variable of the same size and shape as var, initialized to all 1s.
"""
with variable_scope.variable_scope(scope):
mask = variable_scope.get_variable(
'mask',
var.get_shape(),
initializer=init_ops.ones_initializer(),
trainable=False,
dtype=var.dtype)
return mask
def weight_threshold_variable(var, scope):
"""Create a scalar threshold for the weights.
This function adds a variable
'threshold' to the graph.
Args:
var: The weight variable that needs to be masked
scope: The variable scope of the variable var
Returns:
a scalar threshold variable initialized to 0.
"""
with variable_scope.variable_scope(scope):
threshold = variable_scope.get_variable(
'threshold', [],
initializer=init_ops.zeros_initializer(),
trainable=False,
dtype=var.dtype)
return threshold
def kronecker_product(mat1, mat2):
"""Computes the Kronecker product of two matrices mat1 and mat2.
Args:
mat1: A matrix of size m x n
mat2: A matrix of size p x q
Returns:
Kronecker product of matrices mat1 and mat2 of size mp x nq
"""
m1, n1 = mat1.get_shape().as_list()
mat1_rsh = array_ops.reshape(mat1, [m1, 1, n1, 1])
m2, n2 = mat2.get_shape().as_list()
mat2_rsh = array_ops.reshape(mat2, [1, m2, 1, n2])
return array_ops.reshape(mat1_rsh * mat2_rsh, [m1 * m2, n1 * n2])
def _histogram(values, value_range, nbins=100, dtype=dtypes.int32, name=None):
"""Return histogram of values.
Given the tensor `values`, this operation returns a rank 1 histogram counting
the number of entries in `values` that fell into every bin. The bins are
equal width and determined by the arguments `value_range` and `nbins`.
Args:
values: Numeric `Tensor`.
value_range: Shape [2] `Tensor` of same `dtype` as `values`.
values <= value_range[0] will be mapped to hist[0],
values >= value_range[1] will be mapped to hist[-1].
nbins: Scalar `int32 Tensor`. Number of histogram bins.
dtype: dtype for returned histogram.
name: A name for this operation (defaults to 'histogram').
Returns:
A 1-D `Tensor` holding histogram of values.
"""
with ops.name_scope(name, 'histogram', [values, value_range, nbins]) as scope:
values = ops.convert_to_tensor(values, name='values')
values = array_ops.reshape(values, [-1])
value_range = ops.convert_to_tensor(value_range, name='value_range')
nbins_float = np.float32(nbins)
# Map tensor values that fall within value_range to [0, 1].
scaled_values = math_ops.truediv(
values - value_range[0],
value_range[1] - value_range[0],
name='scaled_values')
# map tensor values within the open interval value_range to {0,.., nbins-1},
# values outside the open interval will be zero or less, or nbins or more.
indices = math_ops.floor(nbins_float * scaled_values, name='indices')
# Clip edge cases (e.g. value = value_range[1]) or "outliers."
indices = math_ops.cast(
clip_ops.clip_by_value(indices, 0, nbins_float - 1), dtypes.int32)
return math_ops.unsorted_segment_sum(
array_ops.ones_like(indices, dtype=dtype), indices, nbins, name=scope)
def compute_cdf_from_histogram(values, value_range, **kwargs):
"""Returns the normalized cumulative distribution of the given values tensor.
Computes the histogram and uses tf.cumsum to arrive at cdf
Args:
values: Numeric `Tensor`.
value_range: Shape [2] `Tensor` of same `dtype` as `values`.
**kwargs: keyword arguments: nbins, name
Returns:
A 1-D `Tensor` holding normalized cdf of values.
"""
nbins = kwargs.get('nbins', _NBINS)
name = kwargs.get('name', None)
with ops.name_scope(name, 'cdf', [values, value_range, nbins]):
histogram = _histogram(
values, value_range, dtype=dtypes.float32, nbins=nbins)
cdf = math_ops.cumsum(histogram)
return math_ops.div(cdf, math_ops.reduce_max(cdf))
def compute_cdf(values, value_range, **kwargs):
"""Returns the normalized cumulative distribution of the given values tensor.
Uses tf.while_loop to directly compute the cdf of the values. Number of bins
for histogram is fixed at _NBINS=255
Args:
values: Numeric `Tensor`.
value_range: Shape [2] `Tensor` of same `dtype` as `values`
**kwargs: keyword arguments: name
Returns:
A 1-D `Tensor` holding normalized cdf of values.
"""
nbins = _NBINS
name = kwargs.get('name', None)
with ops.name_scope(name, 'cdf', [values, value_range, nbins]):
values = ops.convert_to_tensor(values, name='values')
value_range = ops.convert_to_tensor(value_range, name='value_range')
nbins_float = np.float32(nbins)
# Map tensor values that fall within value_range to [0, 1].
scaled_values = math_ops.truediv(
values - value_range[0],
value_range[1] - value_range[0],
name='scaled_values')
# map tensor values within the open interval value_range to {0,.., nbins-1},
# values outside the open interval will be zero or less, or nbins or more.
indices = math_ops.floor(nbins_float * scaled_values, name='indices')
# Clip edge cases (e.g. value = value_range[1]) or "outliers."
indices = math_ops.cast(
clip_ops.clip_by_value(indices, 0, nbins_float - 1), dtypes.int32)
cdf = array_ops.zeros(nbins)
i = constant_op.constant(0)
def loop_cond(loop_count, _):
return math_ops.less(loop_count, nbins)
def loop_body(loop_count, cdf):
temp = math_ops.reduce_sum(
math_ops.cast(
math_ops.less_equal(indices, loop_count), dtypes.float32))
cdf = math_ops.add(
cdf,
array_ops.one_hot(
loop_count, depth=_NBINS, on_value=temp, off_value=0.0))
return [loop_count + 1, cdf]
_, cdf = control_flow_ops.while_loop(
loop_cond, loop_body, [i, cdf], maximum_iterations=nbins)
return math_ops.div(cdf, math_ops.reduce_max(cdf))
def factorized_pool(input_tensor,
window_shape,
pooling_type,
strides,
padding,
name=None):
"""Performs m x n pooling through a combination of 1xm and 1xn pooling.
Args:
input_tensor: Input tensor. Must be rank 2
window_shape: Pooling window shape
pooling_type: Either 'MAX' or 'AVG'
strides: The stride of the pooling window
padding: 'SAME' or 'VALID'.
name: Name of the op
Returns:
A rank 2 tensor containing the pooled output
Raises:
ValueError: if the input tensor is not rank 2
"""
if input_tensor.get_shape().ndims != 2:
raise ValueError('factorized_pool() accepts tensors of rank 2 only')
[height, width] = input_tensor.get_shape()
with ops.name_scope(name, 'factorized_pool'):
input_tensor_aligned = array_ops.reshape(
input_tensor, [1, 1, height, width],
name=input_tensor.op.name + '_aligned')
height_pooling = nn_ops.pool(
input_tensor_aligned,
window_shape=[1, window_shape[0]],
pooling_type=pooling_type,
strides=[1, strides[0]],
padding=padding)
swap_height_width = array_ops.transpose(height_pooling, perm=[0, 1, 3, 2])
width_pooling = nn_ops.pool(
swap_height_width,
window_shape=[1, window_shape[1]],
pooling_type=pooling_type,
strides=[1, strides[1]],
padding=padding)
return array_ops.squeeze(
array_ops.transpose(width_pooling, perm=[0, 1, 3, 2]))
def determine_partitioned_axis(partitioned_variable):
partitioned_axis = 0
concatenated_variable_shape = partitioned_variable.get_shape()
for partition in partitioned_variable:
partition_shape = partition.get_shape()
maybe_partitioned_axis = np.less(partition_shape,
concatenated_variable_shape)
# Sanity check: make sure number of partitioned axis == 1
if np.count_nonzero(maybe_partitioned_axis) != 1:
raise ValueError('Number of partitioned axes %s not equal to 1' %
np.count_nonzero(maybe_partitioned_axis))
partitioned_axis = np.where(maybe_partitioned_axis)[0][0]
return partitioned_axis
def variable_assign(var, new_value):
return state_ops.assign(var, new_value, name=var.op.name + '_assign')
def partitioned_variable_assign(partitioned_var, new_value):
"""Assign op for partitioned variables.
Args:
partitioned_var: A partitioned tensorflow variable
new_value: Value to be assigned to the variable var
Returns:
A tensorflow op that groups the assign ops for each of the variable slices
"""
# Determine which axis was used to partition the variable. Currently
# tensorflow allows partitioning variable only along 1 axis.
axis = 0 if len(partitioned_var) == 1 else determine_partitioned_axis(
partitioned_var)
partition_sizes = np.array(
[partition.get_shape()[axis] for partition in partitioned_var])
new_partitioned_values = array_ops.split(
new_value,
ops.convert_to_tensor(partition_sizes, dtype=dtypes.int32),
axis=axis)
op_list = []
for partition in partitioned_var:
op_list.append(
variable_assign(partition, new_partitioned_values[len(op_list)]))
return control_flow_ops.group(
*op_list, name=partitioned_var.name + '_group_assign')
|
apache-2.0
|
[
3,
1898,
9708,
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,
17505,
3423,
367,
7791,
29501,
316,
4048,
4156,
370,
314,
3343,
14,
199,
624,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11353,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4205,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1174,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
199,
63,
46,
9431,
51,
275,
7633,
421,
199,
318,
5401,
63,
2629,
63,
1975,
8,
1391,
12,
4194,
304,
523,
408,
2499,
282,
3656,
367,
314,
4931,
14,
819,
961,
805,
9584,
282,
1750,
283,
2629,
7,
370,
314,
3343,
14,
819,
3033,
26,
272,
2729,
26,
314,
5401,
1750,
626,
4839,
370,
506,
9742,
272,
4194,
26,
710,
1750,
4194,
402,
314,
1750,
2729,
819,
1803,
26,
272,
314,
3656,
1750,
402,
314,
2011,
1568,
436,
2215,
465,
2729,
12,
10038,
370,
1006,
413,
83,
14,
523,
408,
523,
543,
1750,
63,
2645,
14,
1975,
63,
2645,
8,
2645,
304,
272,
3656,
275,
1750,
63,
2645,
14,
362,
63,
1975,
8,
267,
283,
2629,
297,
267,
2729,
14,
362,
63,
1392,
1062,
267,
11130,
29,
826,
63,
1483,
14,
4548,
63,
6498,
1062,
267,
17029,
29,
797,
12,
267,
2152,
29,
1391,
14,
2271,
9,
523,
372,
3656,
421,
199,
318,
5401,
63,
7227,
63,
1975,
8,
1391,
12,
4194,
304,
523,
408,
2499,
282,
6917,
8765,
367,
314,
4931,
14,
819,
961,
805,
9584,
282,
1750,
523,
283,
7227,
7,
370,
314,
3343,
14,
819,
3033,
26,
272,
2729,
26,
710,
5401,
1750,
626,
4839,
370,
506,
9742,
272,
4194,
26,
710,
1750,
4194,
402,
314,
1750,
2729,
819,
1803,
26,
272,
282,
6917,
8765,
1750,
10038,
370,
378,
14,
523,
408,
523,
543,
1750,
63,
2645,
14,
1975,
63,
2645,
8,
2645,
304,
272,
8765,
275,
1750,
63,
2645,
14,
362,
63,
1975,
8,
267,
283,
7227,
297,
990,
267,
11130,
29,
826,
63,
1483,
14,
4250,
63,
6498,
1062,
267,
17029,
29,
797,
12,
267,
2152,
29,
1391,
14,
2271,
9,
272,
372,
8765,
421,
199,
318,
1022,
82,
368,
22043,
63,
2558,
8,
569,
17,
12,
2530,
18,
304,
523,
408,
22594,
314,
1804,
82,
368,
22043,
3336,
402,
2877,
12627,
2530,
17,
436,
2530,
18,
14,
819,
3033,
26,
272,
2530,
17,
26,
437,
3634,
402,
1568,
333,
671,
302,
272,
2530,
18,
26,
437,
3634,
402,
1568,
299,
671,
1894,
523,
1803,
26,
272,
1804,
82,
368,
22043,
3336,
402,
12627,
2530,
17,
436,
2530,
18,
402,
1568,
6118,
671,
302,
81,
523,
408,
819,
333,
17,
12,
302,
17,
275,
2530,
17,
14,
362,
63,
1392,
1252,
305,
63,
513,
342,
523,
2530,
17,
63,
82,
609,
275,
1625,
63,
1483,
14,
5217,
8,
569,
17,
12,
359,
77,
17,
12,
413,
12,
302,
17,
12,
413,
566,
523,
333,
18,
12,
302,
18,
275,
2530,
18,
14,
362,
63,
1392,
1252,
305,
63,
513,
342,
523,
2530,
18,
63,
82,
609,
275,
1625,
63,
1483,
14,
5217,
8,
569,
18,
12,
359,
17,
12,
333,
18,
12,
413,
12,
302,
18,
566,
523,
372,
1625,
63,
1483,
14,
5217,
8,
569,
17,
63,
82,
609,
627,
2530,
18,
63,
82,
609,
12,
359,
77,
17,
627,
333,
18,
12,
302,
17,
627,
302,
18,
566,
421,
199,
318,
485,
14805,
8,
1459,
12,
574,
63,
1842,
12,
302,
11329,
29,
1960,
12,
2152,
29,
5717,
14,
442,
708,
12,
536,
29,
403,
304,
523,
408,
1767,
15379,
402,
1338,
14,
819,
9138,
314,
2345,
658,
1459,
3559,
642,
3439,
2529,
282,
6915,
413,
15379,
23190,
523,
314,
1329,
402,
4811,
315,
658,
1459,
64,
626,
289,
1697,
1901,
4036,
2517,
14,
221,
710,
13341,
787,
523,
4472,
3462,
436,
12037,
701,
314,
2368,
658,
585,
63,
1842,
64,
436,
658,
78,
11329,
2313,
819,
3033,
26,
272,
1338,
26,
221,
19378,
658,
3861,
2313,
272,
574,
63,
1842,
26,
221,
16528,
359,
18,
61,
658,
3861,
64,
402,
2011,
658,
2271,
64,
465,
658,
1459,
2313,
489,
1338,
2695,
574,
63,
1842,
59,
16,
61,
911,
506,
9994,
370,
13612,
59,
16,
467,
489,
1338,
2356,
574,
63,
1842,
59,
17,
61,
911,
506,
9994,
370,
13612,
1988,
17,
1055,
272,
302,
11329,
26,
221,
24289,
658,
442,
708,
5878,
2313,
221,
4860,
402,
15379,
13341,
14,
272,
2152,
26,
221,
2152,
367,
2138,
15379,
14,
272,
536,
26,
221,
437,
536,
367,
642,
3439,
334,
4322,
370,
283,
14805,
1959,
819,
1803,
26,
272,
437,
413,
13,
36,
658,
3861,
64,
17573,
15379,
402,
1338,
14,
819,
408,
523,
543,
4156
] |
[
1898,
9708,
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,
17505,
3423,
367,
7791,
29501,
316,
4048,
4156,
370,
314,
3343,
14,
199,
624,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11353,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4205,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1174,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
199,
63,
46,
9431,
51,
275,
7633,
421,
199,
318,
5401,
63,
2629,
63,
1975,
8,
1391,
12,
4194,
304,
523,
408,
2499,
282,
3656,
367,
314,
4931,
14,
819,
961,
805,
9584,
282,
1750,
283,
2629,
7,
370,
314,
3343,
14,
819,
3033,
26,
272,
2729,
26,
314,
5401,
1750,
626,
4839,
370,
506,
9742,
272,
4194,
26,
710,
1750,
4194,
402,
314,
1750,
2729,
819,
1803,
26,
272,
314,
3656,
1750,
402,
314,
2011,
1568,
436,
2215,
465,
2729,
12,
10038,
370,
1006,
413,
83,
14,
523,
408,
523,
543,
1750,
63,
2645,
14,
1975,
63,
2645,
8,
2645,
304,
272,
3656,
275,
1750,
63,
2645,
14,
362,
63,
1975,
8,
267,
283,
2629,
297,
267,
2729,
14,
362,
63,
1392,
1062,
267,
11130,
29,
826,
63,
1483,
14,
4548,
63,
6498,
1062,
267,
17029,
29,
797,
12,
267,
2152,
29,
1391,
14,
2271,
9,
523,
372,
3656,
421,
199,
318,
5401,
63,
7227,
63,
1975,
8,
1391,
12,
4194,
304,
523,
408,
2499,
282,
6917,
8765,
367,
314,
4931,
14,
819,
961,
805,
9584,
282,
1750,
523,
283,
7227,
7,
370,
314,
3343,
14,
819,
3033,
26,
272,
2729,
26,
710,
5401,
1750,
626,
4839,
370,
506,
9742,
272,
4194,
26,
710,
1750,
4194,
402,
314,
1750,
2729,
819,
1803,
26,
272,
282,
6917,
8765,
1750,
10038,
370,
378,
14,
523,
408,
523,
543,
1750,
63,
2645,
14,
1975,
63,
2645,
8,
2645,
304,
272,
8765,
275,
1750,
63,
2645,
14,
362,
63,
1975,
8,
267,
283,
7227,
297,
990,
267,
11130,
29,
826,
63,
1483,
14,
4250,
63,
6498,
1062,
267,
17029,
29,
797,
12,
267,
2152,
29,
1391,
14,
2271,
9,
272,
372,
8765,
421,
199,
318,
1022,
82,
368,
22043,
63,
2558,
8,
569,
17,
12,
2530,
18,
304,
523,
408,
22594,
314,
1804,
82,
368,
22043,
3336,
402,
2877,
12627,
2530,
17,
436,
2530,
18,
14,
819,
3033,
26,
272,
2530,
17,
26,
437,
3634,
402,
1568,
333,
671,
302,
272,
2530,
18,
26,
437,
3634,
402,
1568,
299,
671,
1894,
523,
1803,
26,
272,
1804,
82,
368,
22043,
3336,
402,
12627,
2530,
17,
436,
2530,
18,
402,
1568,
6118,
671,
302,
81,
523,
408,
819,
333,
17,
12,
302,
17,
275,
2530,
17,
14,
362,
63,
1392,
1252,
305,
63,
513,
342,
523,
2530,
17,
63,
82,
609,
275,
1625,
63,
1483,
14,
5217,
8,
569,
17,
12,
359,
77,
17,
12,
413,
12,
302,
17,
12,
413,
566,
523,
333,
18,
12,
302,
18,
275,
2530,
18,
14,
362,
63,
1392,
1252,
305,
63,
513,
342,
523,
2530,
18,
63,
82,
609,
275,
1625,
63,
1483,
14,
5217,
8,
569,
18,
12,
359,
17,
12,
333,
18,
12,
413,
12,
302,
18,
566,
523,
372,
1625,
63,
1483,
14,
5217,
8,
569,
17,
63,
82,
609,
627,
2530,
18,
63,
82,
609,
12,
359,
77,
17,
627,
333,
18,
12,
302,
17,
627,
302,
18,
566,
421,
199,
318,
485,
14805,
8,
1459,
12,
574,
63,
1842,
12,
302,
11329,
29,
1960,
12,
2152,
29,
5717,
14,
442,
708,
12,
536,
29,
403,
304,
523,
408,
1767,
15379,
402,
1338,
14,
819,
9138,
314,
2345,
658,
1459,
3559,
642,
3439,
2529,
282,
6915,
413,
15379,
23190,
523,
314,
1329,
402,
4811,
315,
658,
1459,
64,
626,
289,
1697,
1901,
4036,
2517,
14,
221,
710,
13341,
787,
523,
4472,
3462,
436,
12037,
701,
314,
2368,
658,
585,
63,
1842,
64,
436,
658,
78,
11329,
2313,
819,
3033,
26,
272,
1338,
26,
221,
19378,
658,
3861,
2313,
272,
574,
63,
1842,
26,
221,
16528,
359,
18,
61,
658,
3861,
64,
402,
2011,
658,
2271,
64,
465,
658,
1459,
2313,
489,
1338,
2695,
574,
63,
1842,
59,
16,
61,
911,
506,
9994,
370,
13612,
59,
16,
467,
489,
1338,
2356,
574,
63,
1842,
59,
17,
61,
911,
506,
9994,
370,
13612,
1988,
17,
1055,
272,
302,
11329,
26,
221,
24289,
658,
442,
708,
5878,
2313,
221,
4860,
402,
15379,
13341,
14,
272,
2152,
26,
221,
2152,
367,
2138,
15379,
14,
272,
536,
26,
221,
437,
536,
367,
642,
3439,
334,
4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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
] |
DmitryADP/diff_qc750
|
vendor/nvidia/tegra/3rdparty/python-support-files/src/Lib/mutex.py
|
60
|
1866
|
"""Mutual exclusion -- for use with module sched
A mutex has two pieces of state -- a 'locked' bit and a queue.
When the mutex is not locked, the queue is empty.
Otherwise, the queue contains 0 or more (function, argument) pairs
representing functions (or methods) waiting to acquire the lock.
When the mutex is unlocked while the queue is not empty,
the first queue entry is removed and its function(argument) pair called,
implying it now has the lock.
Of course, no multi-threading is implied -- hence the funny interface
for lock, where a function is called once the lock is aquired.
"""
from warnings import warnpy3k
warnpy3k("the mutex module has been removed in Python 3.0", stacklevel=2)
del warnpy3k
from collections import deque
class mutex:
def __init__(self):
"""Create a new mutex -- initially unlocked."""
self.locked = 0
self.queue = deque()
def test(self):
"""Test the locked bit of the mutex."""
return self.locked
def testandset(self):
"""Atomic test-and-set -- grab the lock if it is not set,
return True if it succeeded."""
if not self.locked:
self.locked = 1
return True
else:
return False
def lock(self, function, argument):
"""Lock a mutex, call the function with supplied argument
when it is acquired. If the mutex is already locked, place
function and argument in the queue."""
if self.testandset():
function(argument)
else:
self.queue.append((function, argument))
def unlock(self):
"""Unlock a mutex. If the queue is not empty, call the next
function with its argument."""
if self.queue:
function, argument = self.queue.popleft()
function(argument)
else:
self.locked = 0
|
gpl-2.0
|
[
624,
22539,
1061,
27551,
1553,
367,
675,
543,
859,
10286,
199,
199,
33,
333,
18173,
965,
2877,
10338,
402,
1174,
1553,
282,
283,
9325,
7,
4546,
436,
282,
4126,
14,
199,
11423,
314,
333,
18173,
365,
440,
14233,
12,
314,
4126,
365,
2701,
14,
199,
8632,
2605,
12,
314,
4126,
3509,
378,
503,
1655,
334,
1593,
12,
1423,
9,
6342,
199,
13063,
316,
3423,
334,
269,
3102,
9,
10923,
370,
16919,
314,
4650,
14,
199,
11423,
314,
333,
18173,
365,
625,
9325,
1830,
314,
4126,
365,
440,
2701,
12,
199,
1589,
1642,
4126,
2397,
365,
4829,
436,
2399,
805,
8,
2094,
9,
4092,
2797,
12,
199,
3236,
6670,
652,
3063,
965,
314,
4650,
14,
199,
199,
3466,
2518,
12,
949,
3510,
13,
12562,
365,
2478,
1553,
19407,
314,
9627,
9745,
3217,
199,
509,
4650,
12,
2382,
282,
805,
365,
2797,
5403,
314,
4650,
365,
282,
1087,
14,
199,
624,
199,
504,
3598,
492,
7987,
647,
19,
75,
199,
4050,
647,
19,
75,
480,
1589,
333,
18173,
859,
965,
2757,
4829,
315,
2018,
650,
14,
16,
401,
13232,
29,
18,
9,
199,
2264,
7987,
647,
19,
75,
199,
199,
504,
5055,
492,
15782,
199,
199,
533,
333,
18173,
26,
272,
347,
636,
826,
721,
277,
304,
267,
408,
2499,
282,
892,
333,
18173,
1553,
22801,
625,
9325,
1041,
267,
291,
14,
9325,
275,
378,
267,
291,
14,
1825,
275,
15782,
342,
339,
347,
511,
8,
277,
304,
267,
408,
774,
314,
14233,
4546,
402,
314,
333,
18173,
1041,
267,
372,
291,
14,
9325,
339,
347,
511,
460,
409,
8,
277,
304,
267,
408,
31931,
511,
13,
460,
13,
409,
1553,
18200,
314,
4650,
340,
652,
365,
440,
663,
12,
267,
372,
715,
340,
652,
19268,
1041,
267,
340,
440,
291,
14,
9325,
26,
288,
291,
14,
9325,
275,
413,
288,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
4650,
8,
277,
12,
805,
12,
1423,
304,
267,
408,
6432,
282,
333,
18173,
12,
1240,
314,
805,
543,
6841,
1423,
267,
1380,
652,
365,
28320,
14,
221,
982,
314,
333,
18173,
365,
2575,
14233,
12,
4192,
267,
805,
436,
1423,
315,
314,
4126,
1041,
267,
340,
291,
14,
396,
460,
409,
837,
288,
805,
8,
2094,
9,
267,
587,
26,
288,
291,
14,
1825,
14,
740,
1332,
1593,
12,
1423,
430,
339,
347,
28451,
8,
277,
304,
267,
408,
1358,
831,
282,
333,
18173,
14,
221,
982,
314,
4126,
365,
440,
2701,
12,
1240,
314,
2163,
267,
805,
543,
2399,
1423,
1041,
267,
340,
291,
14,
1825,
26,
288,
805,
12,
1423,
275,
291,
14,
1825,
14,
25704,
342,
288,
805,
8,
2094,
9,
267,
587,
26,
288,
291,
14,
9325,
275,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
22539,
1061,
27551,
1553,
367,
675,
543,
859,
10286,
199,
199,
33,
333,
18173,
965,
2877,
10338,
402,
1174,
1553,
282,
283,
9325,
7,
4546,
436,
282,
4126,
14,
199,
11423,
314,
333,
18173,
365,
440,
14233,
12,
314,
4126,
365,
2701,
14,
199,
8632,
2605,
12,
314,
4126,
3509,
378,
503,
1655,
334,
1593,
12,
1423,
9,
6342,
199,
13063,
316,
3423,
334,
269,
3102,
9,
10923,
370,
16919,
314,
4650,
14,
199,
11423,
314,
333,
18173,
365,
625,
9325,
1830,
314,
4126,
365,
440,
2701,
12,
199,
1589,
1642,
4126,
2397,
365,
4829,
436,
2399,
805,
8,
2094,
9,
4092,
2797,
12,
199,
3236,
6670,
652,
3063,
965,
314,
4650,
14,
199,
199,
3466,
2518,
12,
949,
3510,
13,
12562,
365,
2478,
1553,
19407,
314,
9627,
9745,
3217,
199,
509,
4650,
12,
2382,
282,
805,
365,
2797,
5403,
314,
4650,
365,
282,
1087,
14,
199,
624,
199,
504,
3598,
492,
7987,
647,
19,
75,
199,
4050,
647,
19,
75,
480,
1589,
333,
18173,
859,
965,
2757,
4829,
315,
2018,
650,
14,
16,
401,
13232,
29,
18,
9,
199,
2264,
7987,
647,
19,
75,
199,
199,
504,
5055,
492,
15782,
199,
199,
533,
333,
18173,
26,
272,
347,
636,
826,
721,
277,
304,
267,
408,
2499,
282,
892,
333,
18173,
1553,
22801,
625,
9325,
1041,
267,
291,
14,
9325,
275,
378,
267,
291,
14,
1825,
275,
15782,
342,
339,
347,
511,
8,
277,
304,
267,
408,
774,
314,
14233,
4546,
402,
314,
333,
18173,
1041,
267,
372,
291,
14,
9325,
339,
347,
511,
460,
409,
8,
277,
304,
267,
408,
31931,
511,
13,
460,
13,
409,
1553,
18200,
314,
4650,
340,
652,
365,
440,
663,
12,
267,
372,
715,
340,
652,
19268,
1041,
267,
340,
440,
291,
14,
9325,
26,
288,
291,
14,
9325,
275,
413,
288,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
4650,
8,
277,
12,
805,
12,
1423,
304,
267,
408,
6432,
282,
333,
18173,
12,
1240,
314,
805,
543,
6841,
1423,
267,
1380,
652,
365,
28320,
14,
221,
982,
314,
333,
18173,
365,
2575,
14233,
12,
4192,
267,
805,
436,
1423,
315,
314,
4126,
1041,
267,
340,
291,
14,
396,
460,
409,
837,
288,
805,
8,
2094,
9,
267,
587,
26,
288,
291,
14,
1825,
14,
740,
1332,
1593,
12,
1423,
430,
339,
347,
28451,
8,
277,
304,
267,
408,
1358,
831,
282,
333,
18173,
14,
221,
982,
314,
4126,
365,
440,
2701,
12,
1240,
314,
2163,
267,
805,
543,
2399,
1423,
1041,
267,
340,
291,
14,
1825,
26,
288,
805,
12,
1423,
275,
291,
14,
1825,
14,
25704,
342,
288,
805,
8,
2094,
9,
267,
587,
26,
288,
291,
14,
9325,
275,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
patrickcurl/ztruck
|
dj/lib/python2.7/site-packages/django/core/handlers/base.py
|
92
|
12054
|
from __future__ import unicode_literals
import logging
import sys
import types
from django import http
from django.conf import settings
from django.core import signals, urlresolvers
from django.core.exceptions import (
MiddlewareNotUsed, PermissionDenied, SuspiciousOperation,
)
from django.db import connections, transaction
from django.http.multipartparser import MultiPartParserError
from django.utils import six
from django.utils.encoding import force_text
from django.utils.module_loading import import_string
from django.views import debug
logger = logging.getLogger('django.request')
class BaseHandler(object):
# Changes that are always applied to a response (in this order).
response_fixes = [
http.fix_location_header,
http.conditional_content_removal,
]
def __init__(self):
self._request_middleware = None
self._view_middleware = None
self._template_response_middleware = None
self._response_middleware = None
self._exception_middleware = None
def load_middleware(self):
"""
Populate middleware lists from settings.MIDDLEWARE_CLASSES.
Must be called after the environment is fixed (see __call__ in subclasses).
"""
self._view_middleware = []
self._template_response_middleware = []
self._response_middleware = []
self._exception_middleware = []
request_middleware = []
for middleware_path in settings.MIDDLEWARE_CLASSES:
mw_class = import_string(middleware_path)
try:
mw_instance = mw_class()
except MiddlewareNotUsed as exc:
if settings.DEBUG:
if six.text_type(exc):
logger.debug('MiddlewareNotUsed(%r): %s', middleware_path, exc)
else:
logger.debug('MiddlewareNotUsed: %r', middleware_path)
continue
if hasattr(mw_instance, 'process_request'):
request_middleware.append(mw_instance.process_request)
if hasattr(mw_instance, 'process_view'):
self._view_middleware.append(mw_instance.process_view)
if hasattr(mw_instance, 'process_template_response'):
self._template_response_middleware.insert(0, mw_instance.process_template_response)
if hasattr(mw_instance, 'process_response'):
self._response_middleware.insert(0, mw_instance.process_response)
if hasattr(mw_instance, 'process_exception'):
self._exception_middleware.insert(0, mw_instance.process_exception)
# We only assign to this when initialization is complete as it is used
# as a flag for initialization being complete.
self._request_middleware = request_middleware
def make_view_atomic(self, view):
non_atomic_requests = getattr(view, '_non_atomic_requests', set())
for db in connections.all():
if (db.settings_dict['ATOMIC_REQUESTS']
and db.alias not in non_atomic_requests):
view = transaction.atomic(using=db.alias)(view)
return view
def get_exception_response(self, request, resolver, status_code):
try:
callback, param_dict = resolver.resolve_error_handler(status_code)
response = callback(request, **param_dict)
except:
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
return response
def get_response(self, request):
"Returns an HttpResponse object for the given HttpRequest"
# Setup default url resolver for this thread, this code is outside
# the try/except so we don't get a spurious "unbound local
# variable" exception in the event an exception is raised before
# resolver is set
urlconf = settings.ROOT_URLCONF
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
try:
response = None
# Apply request middleware
for middleware_method in self._request_middleware:
response = middleware_method(request)
if response:
break
if response is None:
if hasattr(request, 'urlconf'):
# Reset url resolver with a custom urlconf.
urlconf = request.urlconf
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
resolver_match = resolver.resolve(request.path_info)
callback, callback_args, callback_kwargs = resolver_match
request.resolver_match = resolver_match
# Apply view middleware
for middleware_method in self._view_middleware:
response = middleware_method(request, callback, callback_args, callback_kwargs)
if response:
break
if response is None:
wrapped_callback = self.make_view_atomic(callback)
try:
response = wrapped_callback(request, *callback_args, **callback_kwargs)
except Exception as e:
# If the view raised an exception, run it through exception
# middleware, and if the exception middleware returns a
# response, use that. Otherwise, reraise the exception.
for middleware_method in self._exception_middleware:
response = middleware_method(request, e)
if response:
break
if response is None:
raise
# Complain if the view returned None (a common error).
if response is None:
if isinstance(callback, types.FunctionType): # FBV
view_name = callback.__name__
else: # CBV
view_name = callback.__class__.__name__ + '.__call__'
raise ValueError("The view %s.%s didn't return an HttpResponse object. It returned None instead."
% (callback.__module__, view_name))
# If the response supports deferred rendering, apply template
# response middleware and then render the response
if hasattr(response, 'render') and callable(response.render):
for middleware_method in self._template_response_middleware:
response = middleware_method(request, response)
# Complain if the template response middleware returned None (a common error).
if response is None:
raise ValueError(
"%s.process_template_response didn't return an "
"HttpResponse object. It returned None instead."
% (middleware_method.__self__.__class__.__name__))
response = response.render()
except http.Http404 as e:
logger.warning('Not Found: %s', request.path,
extra={
'status_code': 404,
'request': request
})
if settings.DEBUG:
response = debug.technical_404_response(request, e)
else:
response = self.get_exception_response(request, resolver, 404)
except PermissionDenied:
logger.warning(
'Forbidden (Permission denied): %s', request.path,
extra={
'status_code': 403,
'request': request
})
response = self.get_exception_response(request, resolver, 403)
except MultiPartParserError:
logger.warning(
'Bad request (Unable to parse request body): %s', request.path,
extra={
'status_code': 400,
'request': request
})
response = self.get_exception_response(request, resolver, 400)
except SuspiciousOperation as e:
# The request logger receives events for any problematic request
# The security logger receives events for all SuspiciousOperations
security_logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
security_logger.error(
force_text(e),
extra={
'status_code': 400,
'request': request
})
if settings.DEBUG:
return debug.technical_500_response(request, *sys.exc_info(), status_code=400)
response = self.get_exception_response(request, resolver, 400)
except SystemExit:
# Allow sys.exit() to actually exit. See tickets #1023 and #4701
raise
except: # Handle everything else.
# Get the exception info now, in case another exception is thrown later.
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
try:
# Apply response middleware, regardless of the response
for middleware_method in self._response_middleware:
response = middleware_method(request, response)
# Complain if the response middleware returned None (a common error).
if response is None:
raise ValueError(
"%s.process_response didn't return an "
"HttpResponse object. It returned None instead."
% (middleware_method.__self__.__class__.__name__))
response = self.apply_response_fixes(request, response)
except: # Any exception should be gathered and handled
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
response._closable_objects.append(request)
return response
def handle_uncaught_exception(self, request, resolver, exc_info):
"""
Processing for any otherwise uncaught exceptions (those that will
generate HTTP 500 responses). Can be overridden by subclasses who want
customised 500 handling.
Be *very* careful when overriding this because the error could be
caused by anything, so assuming something like the database is always
available would be an error.
"""
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
raise
logger.error('Internal Server Error: %s', request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request': request
}
)
if settings.DEBUG:
return debug.technical_500_response(request, *exc_info)
# If Http500 handler is not installed, re-raise last exception
if resolver.urlconf_module is None:
six.reraise(*exc_info)
# Return an HttpResponse that displays a friendly error message.
callback, param_dict = resolver.resolve_error_handler(500)
return callback(request, **param_dict)
def apply_response_fixes(self, request, response):
"""
Applies each of the functions in self.response_fixes to the request and
response, modifying the response in the process. Returns the new
response.
"""
for func in self.response_fixes:
response = func(request, response)
return response
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
646,
984,
199,
646,
2943,
199,
199,
504,
1639,
492,
1455,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
492,
10166,
12,
32403,
199,
504,
1639,
14,
1018,
14,
3924,
492,
334,
272,
603,
3551,
1763,
9167,
12,
23724,
12,
428,
28651,
6044,
12,
199,
9,
199,
504,
1639,
14,
697,
492,
6947,
12,
6008,
199,
504,
1639,
14,
1014,
14,
10123,
2087,
492,
6879,
8416,
21811,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
875,
199,
504,
1639,
14,
4196,
492,
3105,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1069,
358,
421,
199,
533,
3523,
2461,
8,
785,
304,
272,
327,
18784,
626,
787,
3544,
6781,
370,
282,
1177,
334,
262,
642,
1865,
680,
272,
1177,
63,
26205,
275,
359,
267,
1455,
14,
970,
63,
1985,
63,
1291,
12,
267,
1455,
14,
14353,
63,
1317,
63,
25818,
12,
272,
1622,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1069,
63,
5754,
275,
488,
267,
291,
423,
1345,
63,
5754,
275,
488,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
488,
267,
291,
423,
1310,
63,
5754,
275,
488,
267,
291,
423,
1971,
63,
5754,
275,
488,
339,
347,
2248,
63,
5754,
8,
277,
304,
267,
408,
267,
31731,
10816,
5548,
687,
2202,
14,
19987,
63,
13748,
14,
398,
9498,
506,
2797,
2410,
314,
3734,
365,
6317,
334,
3239,
636,
1250,
363,
315,
9180,
680,
267,
408,
267,
291,
423,
1345,
63,
5754,
275,
942,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
942,
267,
291,
423,
1310,
63,
5754,
275,
942,
267,
291,
423,
1971,
63,
5754,
275,
942,
398,
1056,
63,
5754,
275,
942,
267,
367,
10816,
63,
515,
315,
2202,
14,
19987,
63,
13748,
26,
288,
23530,
63,
533,
275,
492,
63,
875,
8,
5754,
63,
515,
9,
288,
862,
26,
355,
23530,
63,
842,
275,
23530,
63,
533,
342,
288,
871,
603,
3551,
1763,
9167,
465,
3178,
26,
355,
340,
2202,
14,
5287,
26,
490,
340,
3816,
14,
505,
63,
466,
8,
2804,
304,
717,
2512,
14,
1757,
360,
6608,
1763,
9167,
4042,
82,
304,
450,
83,
297,
10816,
63,
515,
12,
3178,
9,
490,
587,
26,
717,
2512,
14,
1757,
360,
6608,
1763,
9167,
26,
450,
82,
297,
10816,
63,
515,
9,
355,
1980,
953,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1069,
735,
355,
1056,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1069,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1345,
735,
355,
291,
423,
1345,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1345,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1160,
63,
1310,
735,
355,
291,
423,
1160,
63,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1160,
63,
1310,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1310,
735,
355,
291,
423,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1310,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1971,
735,
355,
291,
423,
1971,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1971,
9,
398,
327,
2136,
1454,
5090,
370,
642,
1380,
11097,
365,
4890,
465,
652,
365,
1202,
267,
327,
465,
282,
3305,
367,
11097,
3769,
4890,
14,
267,
291,
423,
1069,
63,
5754,
275,
1056,
63,
5754,
339,
347,
1852,
63,
1345,
63,
10910,
8,
277,
12,
2455,
304,
267,
2222,
63,
10910,
63,
6615,
275,
2519,
8,
1345,
12,
2513,
2865,
63,
10910,
63,
6615,
297,
663,
1012,
267,
367,
1592,
315,
6947,
14,
452,
837,
288,
340,
334,
697,
14,
1751,
63,
807,
459,
22479,
948,
63,
6780,
51,
418,
490,
436,
1592,
14,
3620,
440,
315,
2222,
63,
10910,
63,
6615,
304,
355,
2455,
275,
6008,
14,
10910,
8,
4941,
29,
697,
14,
3620,
5130,
1345,
9,
267,
372,
2455,
339,
347,
664,
63,
1971,
63,
1310,
8,
277,
12,
1056,
12,
15611,
12,
2004,
63,
600,
304,
267,
862,
26,
288,
3233,
12,
1215,
63,
807,
275,
15611,
14,
6983,
63,
705,
63,
2232,
8,
1205,
63,
600,
9,
288,
1177,
275,
3233,
8,
1069,
12,
1011,
635,
63,
807,
9,
267,
871,
26,
288,
10166,
14,
7808,
63,
1069,
63,
1971,
14,
2254,
8,
8114,
29,
277,
855,
533,
3108,
1056,
29,
1069,
9,
288,
1177,
275,
291,
14,
2479,
63,
324,
24872,
63,
1971,
8,
1069,
12,
15611,
12,
984,
14,
2804,
63,
815,
1012,
398,
372,
1177,
339,
347,
664,
63,
1310,
8,
277,
12,
1056,
304,
267,
298,
3407,
376,
6183,
909,
367,
314,
1627,
20730,
2,
398,
327,
12439,
849,
1166,
15611,
367,
642,
2462,
12,
642,
1233,
365,
9682,
267,
327,
314,
862,
15,
2590,
880,
781,
2793,
1133,
664,
282,
2249,
2302,
1785,
298,
18124,
2257,
267,
327,
1750,
2,
1919,
315,
314,
1566,
376,
1919,
365,
4915,
2544,
267,
327,
15611,
365,
663,
267,
30009,
275,
2202,
14,
5441,
63,
18125,
267,
32403,
14,
409,
63,
21801,
8,
21801,
9,
267,
15611,
275,
32403,
14,
5103,
2632,
12407,
8,
82,
4289,
3678,
30009,
9,
267,
862,
26,
288,
1177,
275,
488,
288,
327,
14618,
1056,
10816,
288,
367,
10816,
63,
765,
315,
291,
423,
1069,
63,
5754,
26,
355,
1177,
275,
10816,
63,
765,
8,
1069,
9,
355,
340,
1177,
26,
490,
2059,
953,
340,
1177,
365,
488,
26,
355,
340,
2688,
8,
1069,
12,
283,
21801,
735,
490,
327,
15510,
1166,
15611,
543,
282,
3537,
30009,
14,
490,
30009,
275,
1056,
14,
21801,
490,
32403,
14,
409,
63,
21801,
8,
21801,
9,
490,
15611,
275,
32403,
14,
5103,
2632,
12407,
8,
82,
4289,
3678,
30009,
9,
2234,
15611,
63,
1431,
275,
15611,
14,
6983,
8,
1069,
14,
515,
63,
815,
9,
355,
3233,
12,
3233,
63,
589,
12,
3233,
63,
958,
275,
15611,
63,
1431,
355,
1056,
14
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
646,
984,
199,
646,
2943,
199,
199,
504,
1639,
492,
1455,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
492,
10166,
12,
32403,
199,
504,
1639,
14,
1018,
14,
3924,
492,
334,
272,
603,
3551,
1763,
9167,
12,
23724,
12,
428,
28651,
6044,
12,
199,
9,
199,
504,
1639,
14,
697,
492,
6947,
12,
6008,
199,
504,
1639,
14,
1014,
14,
10123,
2087,
492,
6879,
8416,
21811,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
875,
199,
504,
1639,
14,
4196,
492,
3105,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1069,
358,
421,
199,
533,
3523,
2461,
8,
785,
304,
272,
327,
18784,
626,
787,
3544,
6781,
370,
282,
1177,
334,
262,
642,
1865,
680,
272,
1177,
63,
26205,
275,
359,
267,
1455,
14,
970,
63,
1985,
63,
1291,
12,
267,
1455,
14,
14353,
63,
1317,
63,
25818,
12,
272,
1622,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1069,
63,
5754,
275,
488,
267,
291,
423,
1345,
63,
5754,
275,
488,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
488,
267,
291,
423,
1310,
63,
5754,
275,
488,
267,
291,
423,
1971,
63,
5754,
275,
488,
339,
347,
2248,
63,
5754,
8,
277,
304,
267,
408,
267,
31731,
10816,
5548,
687,
2202,
14,
19987,
63,
13748,
14,
398,
9498,
506,
2797,
2410,
314,
3734,
365,
6317,
334,
3239,
636,
1250,
363,
315,
9180,
680,
267,
408,
267,
291,
423,
1345,
63,
5754,
275,
942,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
942,
267,
291,
423,
1310,
63,
5754,
275,
942,
267,
291,
423,
1971,
63,
5754,
275,
942,
398,
1056,
63,
5754,
275,
942,
267,
367,
10816,
63,
515,
315,
2202,
14,
19987,
63,
13748,
26,
288,
23530,
63,
533,
275,
492,
63,
875,
8,
5754,
63,
515,
9,
288,
862,
26,
355,
23530,
63,
842,
275,
23530,
63,
533,
342,
288,
871,
603,
3551,
1763,
9167,
465,
3178,
26,
355,
340,
2202,
14,
5287,
26,
490,
340,
3816,
14,
505,
63,
466,
8,
2804,
304,
717,
2512,
14,
1757,
360,
6608,
1763,
9167,
4042,
82,
304,
450,
83,
297,
10816,
63,
515,
12,
3178,
9,
490,
587,
26,
717,
2512,
14,
1757,
360,
6608,
1763,
9167,
26,
450,
82,
297,
10816,
63,
515,
9,
355,
1980,
953,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1069,
735,
355,
1056,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1069,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1345,
735,
355,
291,
423,
1345,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1345,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1160,
63,
1310,
735,
355,
291,
423,
1160,
63,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1160,
63,
1310,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1310,
735,
355,
291,
423,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1310,
9,
288,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1971,
735,
355,
291,
423,
1971,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1971,
9,
398,
327,
2136,
1454,
5090,
370,
642,
1380,
11097,
365,
4890,
465,
652,
365,
1202,
267,
327,
465,
282,
3305,
367,
11097,
3769,
4890,
14,
267,
291,
423,
1069,
63,
5754,
275,
1056,
63,
5754,
339,
347,
1852,
63,
1345,
63,
10910,
8,
277,
12,
2455,
304,
267,
2222,
63,
10910,
63,
6615,
275,
2519,
8,
1345,
12,
2513,
2865,
63,
10910,
63,
6615,
297,
663,
1012,
267,
367,
1592,
315,
6947,
14,
452,
837,
288,
340,
334,
697,
14,
1751,
63,
807,
459,
22479,
948,
63,
6780,
51,
418,
490,
436,
1592,
14,
3620,
440,
315,
2222,
63,
10910,
63,
6615,
304,
355,
2455,
275,
6008,
14,
10910,
8,
4941,
29,
697,
14,
3620,
5130,
1345,
9,
267,
372,
2455,
339,
347,
664,
63,
1971,
63,
1310,
8,
277,
12,
1056,
12,
15611,
12,
2004,
63,
600,
304,
267,
862,
26,
288,
3233,
12,
1215,
63,
807,
275,
15611,
14,
6983,
63,
705,
63,
2232,
8,
1205,
63,
600,
9,
288,
1177,
275,
3233,
8,
1069,
12,
1011,
635,
63,
807,
9,
267,
871,
26,
288,
10166,
14,
7808,
63,
1069,
63,
1971,
14,
2254,
8,
8114,
29,
277,
855,
533,
3108,
1056,
29,
1069,
9,
288,
1177,
275,
291,
14,
2479,
63,
324,
24872,
63,
1971,
8,
1069,
12,
15611,
12,
984,
14,
2804,
63,
815,
1012,
398,
372,
1177,
339,
347,
664,
63,
1310,
8,
277,
12,
1056,
304,
267,
298,
3407,
376,
6183,
909,
367,
314,
1627,
20730,
2,
398,
327,
12439,
849,
1166,
15611,
367,
642,
2462,
12,
642,
1233,
365,
9682,
267,
327,
314,
862,
15,
2590,
880,
781,
2793,
1133,
664,
282,
2249,
2302,
1785,
298,
18124,
2257,
267,
327,
1750,
2,
1919,
315,
314,
1566,
376,
1919,
365,
4915,
2544,
267,
327,
15611,
365,
663,
267,
30009,
275,
2202,
14,
5441,
63,
18125,
267,
32403,
14,
409,
63,
21801,
8,
21801,
9,
267,
15611,
275,
32403,
14,
5103,
2632,
12407,
8,
82,
4289,
3678,
30009,
9,
267,
862,
26,
288,
1177,
275,
488,
288,
327,
14618,
1056,
10816,
288,
367,
10816,
63,
765,
315,
291,
423,
1069,
63,
5754,
26,
355,
1177,
275,
10816,
63,
765,
8,
1069,
9,
355,
340,
1177,
26,
490,
2059,
953,
340,
1177,
365,
488,
26,
355,
340,
2688,
8,
1069,
12,
283,
21801,
735,
490,
327,
15510,
1166,
15611,
543,
282,
3537,
30009,
14,
490,
30009,
275,
1056,
14,
21801,
490,
32403,
14,
409,
63,
21801,
8,
21801,
9,
490,
15611,
275,
32403,
14,
5103,
2632,
12407,
8,
82,
4289,
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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
] |
fangxingli/hue
|
desktop/core/ext-py/tablib-0.10.0/tablib/packages/yaml3/dumper.py
|
277
|
2723
|
__all__ = ['BaseDumper', 'SafeDumper', 'Dumper']
from .emitter import *
from .serializer import *
from .representer import *
from .resolver import *
class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
def __init__(self, stream,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
Emitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Serializer.__init__(self, encoding=encoding,
explicit_start=explicit_start, explicit_end=explicit_end,
version=version, tags=tags)
Representer.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver):
def __init__(self, stream,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
Emitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Serializer.__init__(self, encoding=encoding,
explicit_start=explicit_start, explicit_end=explicit_end,
version=version, tags=tags)
SafeRepresenter.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
class Dumper(Emitter, Serializer, Representer, Resolver):
def __init__(self, stream,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
Emitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Serializer.__init__(self, encoding=encoding,
explicit_start=explicit_start, explicit_end=explicit_end,
version=version, tags=tags)
Representer.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
|
apache-2.0
|
[
199,
363,
452,
363,
275,
788,
1563,
28593,
297,
283,
11090,
28593,
297,
283,
28593,
418,
199,
199,
504,
1275,
8159,
351,
492,
627,
199,
504,
1275,
8349,
492,
627,
199,
504,
1275,
264,
22682,
492,
627,
199,
504,
1275,
7717,
492,
627,
199,
199,
533,
3523,
28593,
8,
37,
22541,
12,
25555,
12,
3523,
497,
22682,
12,
3523,
12407,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
14969,
28593,
8,
37,
22541,
12,
25555,
12,
14969,
497,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
14969,
497,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
19460,
281,
8,
37,
22541,
12,
25555,
12,
799,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
363,
452,
363,
275,
788,
1563,
28593,
297,
283,
11090,
28593,
297,
283,
28593,
418,
199,
199,
504,
1275,
8159,
351,
492,
627,
199,
504,
1275,
8349,
492,
627,
199,
504,
1275,
264,
22682,
492,
627,
199,
504,
1275,
7717,
492,
627,
199,
199,
533,
3523,
28593,
8,
37,
22541,
12,
25555,
12,
3523,
497,
22682,
12,
3523,
12407,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
14969,
28593,
8,
37,
22541,
12,
25555,
12,
14969,
497,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
14969,
497,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
19460,
281,
8,
37,
22541,
12,
25555,
12,
799,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
meefik/tinykernel-flo
|
tools/perf/scripts/python/syscall-counts.py
|
11181
|
1522
|
# system call counts
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts.py [comm]\n";
for_comm = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
print "%-40s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
chrsmithdemos/selenium
|
py/test/selenium/webdriver/common/element_attribute_tests.py
|
15
|
12232
|
#!/usr/bin/python
# Copyright 2008-2010 WebDriver committers
# Copyright 2008-2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import pytest
class ElementAttributeTests(unittest.TestCase):
def testShouldReturnNullWhenGettingTheValueOfAnAttributeThatIsNotListed(self):
self._loadSimplePage()
head = self.driver.find_element_by_xpath("/html")
attribute = head.get_attribute("cheese")
self.assertTrue(attribute is None)
def testShouldReturnNullWhenGettingSrcAttributeOfInvalidImgTag(self):
self._loadSimplePage()
img = self.driver.find_element_by_id("invalidImgTag")
img_attr = img.get_attribute("src")
self.assertTrue(img_attr is None)
def testShouldReturnAnAbsoluteUrlWhenGettingSrcAttributeOfAValidImgTag(self):
self._loadSimplePage()
img = self.driver.find_element_by_id("validImgTag")
img_attr = img.get_attribute("src")
self.assertTrue("icon.gif" in img_attr)
def testShouldReturnAnAbsoluteUrlWhenGettingHrefAttributeOfAValidAnchorTag(self):
self._loadSimplePage()
img = self.driver.find_element_by_id("validAnchorTag")
img_attr = img.get_attribute("href")
self.assertTrue("icon.gif" in img_attr)
def testShouldReturnEmptyAttributeValuesWhenPresentAndTheValueIsActuallyEmpty(self):
self._loadSimplePage()
body = self.driver.find_element_by_xpath("//body")
self.assertEqual("", body.get_attribute("style"))
def testShouldReturnTheValueOfTheDisabledAttributeAsFalseIfNotSet(self):
self._loadPage("formPage")
inputElement = self.driver.find_element_by_xpath("//input[@id='working']")
self.assertEqual(None, inputElement.get_attribute("disabled"))
self.assertTrue(inputElement.is_enabled())
pElement = self.driver.find_element_by_id("peas")
self.assertEqual(None, pElement.get_attribute("disabled"))
self.assertTrue(pElement.is_enabled())
def testShouldReturnTheValueOfTheIndexAttrbuteEvenIfItIsMissing(self):
self._loadPage("formPage")
multiSelect = self.driver.find_element_by_id("multi")
options = multiSelect.find_elements_by_tag_name("option")
self.assertEqual("1", options[1].get_attribute("index"))
def testShouldIndicateTheElementsThatAreDisabledAreNotis_enabled(self):
self._loadPage("formPage")
inputElement = self.driver.find_element_by_xpath("//input[@id='notWorking']")
self.assertFalse(inputElement.is_enabled())
inputElement = self.driver.find_element_by_xpath("//input[@id='working']")
self.assertTrue(inputElement.is_enabled())
def testElementsShouldBeDisabledIfTheyAreDisabledUsingRandomDisabledStrings(self):
self._loadPage("formPage")
disabledTextElement1 = self.driver.find_element_by_id("disabledTextElement1")
self.assertFalse(disabledTextElement1.is_enabled())
disabledTextElement2 = self.driver.find_element_by_id("disabledTextElement2")
self.assertFalse(disabledTextElement2.is_enabled())
disabledSubmitElement = self.driver.find_element_by_id("disabledSubmitElement")
self.assertFalse(disabledSubmitElement.is_enabled())
def testShouldIndicateWhenATextAreaIsDisabled(self):
self._loadPage("formPage")
textArea = self.driver.find_element_by_xpath("//textarea[@id='notWorkingArea']")
self.assertFalse(textArea.is_enabled())
def testShouldThrowExceptionIfSendingKeysToElementDisabledUsingRandomDisabledStrings(self):
self._loadPage("formPage")
disabledTextElement1 = self.driver.find_element_by_id("disabledTextElement1")
try:
disabledTextElement1.send_keys("foo")
self.fail("Should have thrown exception")
except:
pass
self.assertEqual("", disabledTextElement1.text)
disabledTextElement2 = self.driver.find_element_by_id("disabledTextElement2")
try:
disabledTextElement2.send_keys("bar")
self.fail("Should have thrown exception")
except:
pass
self.assertEqual("", disabledTextElement2.text)
def testShouldIndicateWhenASelectIsDisabled(self):
self._loadPage("formPage")
enabled = self.driver.find_element_by_name("selectomatic")
disabled = self.driver.find_element_by_name("no-select")
self.assertTrue(enabled.is_enabled())
self.assertFalse(disabled.is_enabled())
def testShouldReturnTheValueOfCheckedForACheckboxEvenIfItLacksThatAttribute(self):
self._loadPage("formPage")
checkbox = self.driver.find_element_by_xpath("//input[@id='checky']")
self.assertTrue(checkbox.get_attribute("checked") is None)
checkbox.click()
self.assertEqual("true", checkbox.get_attribute("checked"))
def testShouldReturnTheValueOfSelectedForRadioButtonsEvenIfTheyLackThatAttribute(self):
self._loadPage("formPage")
neverSelected = self.driver.find_element_by_id("cheese")
initiallyNotSelected = self.driver.find_element_by_id("peas")
initiallySelected = self.driver.find_element_by_id("cheese_and_peas")
self.assertTrue(neverSelected.get_attribute("selected") is None, "false")
self.assertTrue(initiallyNotSelected.get_attribute("selected") is None, "false")
self.assertEqual("true", initiallySelected.get_attribute("selected"), "true")
initiallyNotSelected.click()
self.assertTrue(neverSelected.get_attribute("selected") is None)
self.assertEqual("true", initiallyNotSelected.get_attribute("selected"))
self.assertTrue(initiallySelected.get_attribute("selected") is None)
def testShouldReturnTheValueOfSelectedForOptionsInSelectsEvenIfTheyLackThatAttribute(self):
self._loadPage("formPage")
selectBox = self.driver.find_element_by_xpath("//select[@name='selectomatic']")
options = selectBox.find_elements_by_tag_name("option")
one = options[0]
two = options[1]
self.assertTrue(one.is_selected())
self.assertFalse(two.is_selected())
self.assertEqual("true", one.get_attribute("selected"))
self.assertTrue(two.get_attribute("selected") is None)
def testShouldReturnValueOfClassAttributeOfAnElement(self):
self._loadPage("xhtmlTest")
heading = self.driver.find_element_by_xpath("//h1")
classname = heading.get_attribute("class")
self.assertEqual("header", classname)
# Disabled due to issues with Frames
#def testShouldReturnValueOfClassAttributeOfAnElementAfterSwitchingIFrame(self):
# self._loadPage("iframes")
# self.driver.switch_to.frame("iframe1")
#
# wallace = self.driver.find_element_by_xpath("//div[@id='wallace']")
# classname = wallace.get_attribute("class")
# self.assertEqual("gromit", classname)
def testShouldReturnTheContentsOfATextAreaAsItsValue(self):
self._loadPage("formPage")
value = self.driver.find_element_by_id("withText").get_attribute("value")
self.assertEqual("Example text", value)
def testShouldReturnTheContentsOfATextAreaAsItsValueWhenSetToNonNorminalTrue(self):
self._loadPage("formPage")
e = self.driver.find_element_by_id("withText")
self.driver.execute_script("arguments[0].value = 'tRuE'", e)
value = e.get_attribute("value")
self.assertEqual("tRuE", value)
def testShouldTreatReadonlyAsAValue(self):
self._loadPage("formPage")
element = self.driver.find_element_by_name("readonly")
readOnlyAttribute = element.get_attribute("readonly")
textInput = self.driver.find_element_by_name("x")
notReadOnly = textInput.get_attribute("readonly")
self.assertNotEqual(readOnlyAttribute, notReadOnly)
def testShouldGetNumericAtribute(self):
self._loadPage("formPage")
element = self.driver.find_element_by_id("withText")
self.assertEqual("5", element.get_attribute("rows"))
def testCanReturnATextApproximationOfTheStyleAttribute(self):
self._loadPage("javascriptPage")
style = self.driver.find_element_by_id("red-item").get_attribute("style")
self.assertTrue("background-color" in style.lower())
def testShouldCorrectlyReportValueOfColspan(self):
self._loadPage("tables")
th1 = self.driver.find_element_by_id("th1")
td2 = self.driver.find_element_by_id("td2")
self.assertEqual("th1", th1.get_attribute("id"))
self.assertEqual("3", th1.get_attribute("colspan"))
self.assertEqual("td2", td2.get_attribute("id"));
self.assertEquals("2", td2.get_attribute("colspan"));
def testCanRetrieveTheCurrentValueOfATextFormField_textInput(self):
self._loadPage("formPage")
element = self.driver.find_element_by_id("working")
self.assertEqual("", element.get_attribute("value"))
element.send_keys("hello world")
self.assertEqual("hello world", element.get_attribute("value"))
def testCanRetrieveTheCurrentValueOfATextFormField_emailInput(self):
self._loadPage("formPage")
element = self.driver.find_element_by_id("email")
self.assertEqual("", element.get_attribute("value"))
element.send_keys("hello@example.com")
self.assertEqual("hello@example.com", element.get_attribute("value"))
def testCanRetrieveTheCurrentValueOfATextFormField_textArea(self):
self._loadPage("formPage")
element = self.driver.find_element_by_id("emptyTextArea")
self.assertEqual("", element.get_attribute("value"))
element.send_keys("hello world")
self.assertEqual("hello world", element.get_attribute("value"))
@pytest.mark.ignore_chrome
@pytest.mark.ignore_opera
def testShouldReturnNullForNonPresentBooleanAttributes(self):
self._loadPage("booleanAttributes")
element1 = self.driver.find_element_by_id("working")
self.assertEqual(None, element1.get_attribute("required"))
element2 = self.driver.find_element_by_id("wallace")
self.assertEqual(None, element2.get_attribute("nowrap"))
@pytest.mark.ignore_ie
def testShouldReturnTrueForPresentBooleanAttributes(self):
self._loadPage("booleanAttributes")
element1 = self.driver.find_element_by_id("emailRequired")
self.assertEqual("true", element1.get_attribute("required"))
element2 = self.driver.find_element_by_id("emptyTextAreaRequired")
self.assertEqual("true", element2.get_attribute("required"))
element3 = self.driver.find_element_by_id("inputRequired")
self.assertEqual("true", element3.get_attribute("required"))
element4 = self.driver.find_element_by_id("textAreaRequired")
self.assertEqual("true", element4.get_attribute("required"))
element5 = self.driver.find_element_by_id("unwrappable")
self.assertEqual("true", element5.get_attribute("nowrap"))
def tesShouldGetUnicodeCharsFromAttribute(self):
self._loadPage("formPage")
title = self.driver.find_element_by_id("vsearchGadget").get_attribute("title")
self.assertEqual('Hvad s\xf8ger du?', title)
def _pageURL(self, name):
return self.webserver.where_is(name + '.html')
def _loadSimplePage(self):
self._loadPage("simpleTest")
def _loadPage(self, name):
self.driver.get(self._pageURL(name))
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
9079,
13,
6542,
27104,
5532,
878,
199,
3,
1898,
9079,
13,
6542,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
531,
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,
421,
199,
646,
2882,
199,
646,
4613,
4388,
199,
533,
6566,
1646,
2925,
8,
2796,
14,
1746,
304,
339,
347,
511,
11408,
1767,
8849,
11423,
28277,
1918,
1110,
3466,
2493,
1646,
17231,
1831,
1763,
44,
4957,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
4854,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
4769,
1360,
531,
267,
2225,
275,
4854,
14,
362,
63,
3215,
480,
595,
31209,
531,
267,
291,
14,
1815,
8,
3215,
365,
488,
9,
5493,
347,
511,
11408,
1767,
8849,
11423,
28277,
21261,
1646,
3466,
3364,
27261,
1931,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
6050,
275,
221,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
3197,
27261,
1931,
531,
267,
6050,
63,
962,
275,
6050,
14,
362,
63,
3215,
480,
2164,
531,
267,
291,
14,
1815,
8,
4060,
63,
962,
365,
488,
9,
339,
347,
511,
11408,
1767,
2493,
24677,
6417,
11423,
28277,
21261,
1646,
3466,
33,
3490,
27261,
1931,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
6050,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1078,
27261,
1931,
531,
267,
6050,
63,
962,
275,
6050,
14,
362,
63,
3215,
480,
2164,
531,
267,
291,
14,
1815,
480,
4677,
14,
14513,
2,
315,
6050,
63,
962,
9,
20950,
347,
511,
11408,
1767,
2493,
24677,
6417,
11423,
28277,
40,
1121,
1646,
3466,
33,
3490,
23517,
1931,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
6050,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1078,
23517,
1931,
531,
267,
6050,
63,
962,
275,
6050,
14,
362,
63,
3215,
480,
6399,
531,
267,
291,
14,
1815,
480,
4677,
14,
14513,
2,
315,
6050,
63,
962,
9,
339,
347,
511,
11408,
1767,
12365,
83,
11423,
19794,
3325,
1918,
1110,
14104,
319,
3163,
4699,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
2396,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
2030,
531,
267,
291,
14,
629,
12398,
2396,
14,
362,
63,
3215,
480,
2487,
2237,
5493,
347,
511,
11408,
1767,
1918,
1110,
3466,
1918,
15049,
1646,
2822,
797,
3917,
15953,
8,
277,
304,
27144,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
1324,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
1210,
14251,
344,
534,
9818,
32266,
267,
291,
14,
629,
8,
403,
12,
1324,
2162,
14,
362,
63,
3215,
480,
7011,
2237,
267,
291,
14,
1815,
8,
1210,
2162,
14,
374,
63,
3827,
1012,
398,
299,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
321,
305,
531,
267,
291,
14,
629,
8,
403,
12,
299,
2162,
14,
362,
63,
3215,
480,
7011,
2237,
267,
291,
14,
1815,
8,
80,
2162,
14,
374,
63,
3827,
1012,
5493,
347,
511,
11408,
1767,
1918,
1110,
3466,
1918,
2681,
7144,
26583,
29704,
3917,
7940,
1831,
7718,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
3510,
5446,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
3029,
531,
267,
1511,
275,
3510,
5446,
14,
1623,
63,
5527,
63,
991,
63,
1450,
63,
354,
480,
1422,
531,
267,
291,
14,
629,
480,
17,
401,
1511,
59,
17,
1055,
362,
63,
3215,
480,
1080,
2237,
5493,
347,
511,
11408,
607,
10188,
1918,
6255,
17231,
17683,
15049,
17683,
1944,
16753,
63,
3827,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
1324,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
1210,
14251,
344,
534,
1397,
18356,
32266,
267,
291,
14,
3334,
8,
1210,
2162,
14,
374,
63,
3827,
1012,
398,
1324,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
1210,
14251,
344,
534,
9818,
32266,
267,
291,
14,
1815,
8,
1210,
2162,
14,
374,
63,
3827,
1012,
5493,
347,
511,
6255,
11408,
3655,
15049,
3917,
1918,
89,
17683,
15049,
10369,
3883,
15049,
12672,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
6980,
1872,
2162,
17,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
7011,
1872,
2162,
17,
531,
267,
291,
14,
3334,
8,
7011,
1872,
2162,
17,
14,
374,
63,
3827,
1012,
398,
6980,
1872,
2162,
18,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
7011,
1872,
2162,
18,
531,
267,
291,
14,
3334,
8,
7011,
1872,
2162,
18,
14,
374,
63,
3827,
1012,
398,
6980,
17187,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
7011,
17187,
2162,
531,
267,
291,
14,
3334,
8,
7011,
17187,
2162,
14,
374,
63,
3827,
1012,
5493,
347,
511,
11408,
607,
10188,
11423,
619,
832,
11043,
1831,
15049,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
1318,
11043,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
20895,
14251,
344,
534,
1397,
18356,
11043,
32266,
267,
291,
14,
3334,
8,
505,
11043,
14,
374,
63,
3827,
1012,
5493,
347,
511,
11408,
2719,
1143,
1726,
3917,
27219,
6340,
1378,
2162,
15049,
10369
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
9079,
13,
6542,
27104,
5532,
878,
199,
3,
1898,
9079,
13,
6542,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
531,
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,
421,
199,
646,
2882,
199,
646,
4613,
4388,
199,
533,
6566,
1646,
2925,
8,
2796,
14,
1746,
304,
339,
347,
511,
11408,
1767,
8849,
11423,
28277,
1918,
1110,
3466,
2493,
1646,
17231,
1831,
1763,
44,
4957,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
4854,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
4769,
1360,
531,
267,
2225,
275,
4854,
14,
362,
63,
3215,
480,
595,
31209,
531,
267,
291,
14,
1815,
8,
3215,
365,
488,
9,
5493,
347,
511,
11408,
1767,
8849,
11423,
28277,
21261,
1646,
3466,
3364,
27261,
1931,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
6050,
275,
221,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
3197,
27261,
1931,
531,
267,
6050,
63,
962,
275,
6050,
14,
362,
63,
3215,
480,
2164,
531,
267,
291,
14,
1815,
8,
4060,
63,
962,
365,
488,
9,
339,
347,
511,
11408,
1767,
2493,
24677,
6417,
11423,
28277,
21261,
1646,
3466,
33,
3490,
27261,
1931,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
6050,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1078,
27261,
1931,
531,
267,
6050,
63,
962,
275,
6050,
14,
362,
63,
3215,
480,
2164,
531,
267,
291,
14,
1815,
480,
4677,
14,
14513,
2,
315,
6050,
63,
962,
9,
20950,
347,
511,
11408,
1767,
2493,
24677,
6417,
11423,
28277,
40,
1121,
1646,
3466,
33,
3490,
23517,
1931,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
6050,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1078,
23517,
1931,
531,
267,
6050,
63,
962,
275,
6050,
14,
362,
63,
3215,
480,
6399,
531,
267,
291,
14,
1815,
480,
4677,
14,
14513,
2,
315,
6050,
63,
962,
9,
339,
347,
511,
11408,
1767,
12365,
83,
11423,
19794,
3325,
1918,
1110,
14104,
319,
3163,
4699,
8,
277,
304,
267,
291,
423,
912,
3184,
3276,
342,
267,
2396,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
2030,
531,
267,
291,
14,
629,
12398,
2396,
14,
362,
63,
3215,
480,
2487,
2237,
5493,
347,
511,
11408,
1767,
1918,
1110,
3466,
1918,
15049,
1646,
2822,
797,
3917,
15953,
8,
277,
304,
27144,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
1324,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
1210,
14251,
344,
534,
9818,
32266,
267,
291,
14,
629,
8,
403,
12,
1324,
2162,
14,
362,
63,
3215,
480,
7011,
2237,
267,
291,
14,
1815,
8,
1210,
2162,
14,
374,
63,
3827,
1012,
398,
299,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
321,
305,
531,
267,
291,
14,
629,
8,
403,
12,
299,
2162,
14,
362,
63,
3215,
480,
7011,
2237,
267,
291,
14,
1815,
8,
80,
2162,
14,
374,
63,
3827,
1012,
5493,
347,
511,
11408,
1767,
1918,
1110,
3466,
1918,
2681,
7144,
26583,
29704,
3917,
7940,
1831,
7718,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
3510,
5446,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
3029,
531,
267,
1511,
275,
3510,
5446,
14,
1623,
63,
5527,
63,
991,
63,
1450,
63,
354,
480,
1422,
531,
267,
291,
14,
629,
480,
17,
401,
1511,
59,
17,
1055,
362,
63,
3215,
480,
1080,
2237,
5493,
347,
511,
11408,
607,
10188,
1918,
6255,
17231,
17683,
15049,
17683,
1944,
16753,
63,
3827,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
1324,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
1210,
14251,
344,
534,
1397,
18356,
32266,
267,
291,
14,
3334,
8,
1210,
2162,
14,
374,
63,
3827,
1012,
398,
1324,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
1210,
14251,
344,
534,
9818,
32266,
267,
291,
14,
1815,
8,
1210,
2162,
14,
374,
63,
3827,
1012,
5493,
347,
511,
6255,
11408,
3655,
15049,
3917,
1918,
89,
17683,
15049,
10369,
3883,
15049,
12672,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
6980,
1872,
2162,
17,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
7011,
1872,
2162,
17,
531,
267,
291,
14,
3334,
8,
7011,
1872,
2162,
17,
14,
374,
63,
3827,
1012,
398,
6980,
1872,
2162,
18,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
7011,
1872,
2162,
18,
531,
267,
291,
14,
3334,
8,
7011,
1872,
2162,
18,
14,
374,
63,
3827,
1012,
398,
6980,
17187,
2162,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
7011,
17187,
2162,
531,
267,
291,
14,
3334,
8,
7011,
17187,
2162,
14,
374,
63,
3827,
1012,
5493,
347,
511,
11408,
607,
10188,
11423,
619,
832,
11043,
1831,
15049,
8,
277,
304,
267,
291,
423,
912,
3276,
480,
964,
3276,
531,
267,
1318,
11043,
275,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
21816,
20895,
14251,
344,
534,
1397,
18356,
11043,
32266,
267,
291,
14,
3334,
8,
505,
11043,
14,
374,
63,
3827,
1012,
5493,
347,
511,
11408,
2719,
1143,
1726,
3917,
27219,
6340,
1378,
2162,
15049,
10369,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
apechimp/servo
|
tests/wpt/harness/wptrunner/wptmanifest/tests/test_static.py
|
139
|
2863
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import unittest
from cStringIO import StringIO
from ..backends import static
# There aren't many tests here because it turns out to be way more convenient to
# use test_serializer for the majority of cases
class TestStatic(unittest.TestCase):
def parse(self, input_str):
return self.parser.parse(StringIO(input_str))
def compile(self, input_text, input_data):
return static.compile(input_text, input_data)
def test_get_0(self):
data = """
key: value
[Heading 1]
other_key:
if a == 1: value_1
if a == 2: value_2
value_3
"""
manifest = self.compile(data, {"a": 2})
self.assertEquals(manifest.get("key"), "value")
children = list(item for item in manifest.iterchildren())
self.assertEquals(len(children), 1)
section = children[0]
self.assertEquals(section.name, "Heading 1")
self.assertEquals(section.get("other_key"), "value_2")
self.assertEquals(section.get("key"), "value")
def test_get_1(self):
data = """
key: value
[Heading 1]
other_key:
if a == 1: value_1
if a == 2: value_2
value_3
"""
manifest = self.compile(data, {"a": 3})
children = list(item for item in manifest.iterchildren())
section = children[0]
self.assertEquals(section.get("other_key"), "value_3")
def test_get_3(self):
data = """key:
if a == "1": value_1
if a[0] == "ab"[0]: value_2
"""
manifest = self.compile(data, {"a": "1"})
self.assertEquals(manifest.get("key"), "value_1")
manifest = self.compile(data, {"a": "ac"})
self.assertEquals(manifest.get("key"), "value_2")
def test_get_4(self):
data = """key:
if not a: value_1
value_2
"""
manifest = self.compile(data, {"a": True})
self.assertEquals(manifest.get("key"), "value_2")
manifest = self.compile(data, {"a": False})
self.assertEquals(manifest.get("key"), "value_1")
def test_api(self):
data = """key:
if a == 1.5: value_1
value_2
key_1: other_value
"""
manifest = self.compile(data, {"a": 1.5})
self.assertFalse(manifest.is_empty)
self.assertEquals(manifest.root, manifest)
self.assertTrue(manifest.has_key("key_1"))
self.assertFalse(manifest.has_key("key_2"))
self.assertEquals(set(manifest.iterkeys()), set(["key", "key_1"]))
self.assertEquals(set(manifest.itervalues()), set(["value_1", "other_value"]))
def test_is_empty_1(self):
data = """
[Section]
[Subsection]
"""
manifest = self.compile(data, {})
self.assertTrue(manifest.is_empty)
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
2882,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
2508,
7765,
492,
2955,
199,
199,
3,
6006,
10621,
1133,
5002,
2295,
2348,
2952,
652,
25449,
734,
370,
506,
4340,
1655,
22700,
370,
199,
3,
675,
511,
63,
8349,
367,
314,
610,
74,
3822,
402,
5560,
421,
199,
533,
1379,
9278,
8,
2796,
14,
1746,
304,
272,
347,
2198,
8,
277,
12,
1324,
63,
495,
304,
267,
372,
291,
14,
2087,
14,
1122,
8,
6424,
8,
1210,
63,
495,
430,
339,
347,
6555,
8,
277,
12,
1324,
63,
505,
12,
1324,
63,
576,
304,
267,
372,
2955,
14,
2014,
8,
1210,
63,
505,
12,
1324,
63,
576,
9,
339,
347,
511,
63,
362,
63,
16,
8,
277,
304,
267,
666,
275,
408,
199,
498,
26,
574,
199,
199,
59,
23818,
413,
61,
523,
1163,
63,
498,
26,
272,
340,
282,
508,
413,
26,
574,
63,
17,
272,
340,
282,
508,
499,
26,
574,
63,
18,
272,
574,
63,
19,
199,
624,
398,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
499,
1552,
398,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
531,
267,
4978,
275,
769,
8,
1053,
367,
1242,
315,
7712,
14,
1661,
3223,
1012,
267,
291,
14,
2947,
8,
552,
8,
3223,
395,
413,
9,
267,
3420,
275,
4978,
59,
16,
61,
267,
291,
14,
2947,
8,
2792,
14,
354,
12,
298,
23818,
413,
531,
398,
291,
14,
2947,
8,
2792,
14,
362,
480,
1848,
63,
498,
1288,
298,
585,
63,
18,
531,
267,
291,
14,
2947,
8,
2792,
14,
362,
480,
498,
1288,
298,
585,
531,
339,
347,
511,
63,
362,
63,
17,
8,
277,
304,
267,
666,
275,
408,
199,
498,
26,
574,
199,
199,
59,
23818,
413,
61,
523,
1163,
63,
498,
26,
272,
340,
282,
508,
413,
26,
574,
63,
17,
272,
340,
282,
508,
499,
26,
574,
63,
18,
272,
574,
63,
19,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
650,
1552,
398,
4978,
275,
769,
8,
1053,
367,
1242,
315,
7712,
14,
1661,
3223,
1012,
267,
3420,
275,
4978,
59,
16,
61,
267,
291,
14,
2947,
8,
2792,
14,
362,
480,
1848,
63,
498,
1288,
298,
585,
63,
19,
531,
339,
347,
511,
63,
362,
63,
19,
8,
277,
304,
267,
666,
275,
408,
498,
26,
523,
340,
282,
508,
298,
17,
582,
574,
63,
17,
523,
340,
282,
59,
16,
61,
508,
298,
371,
22774,
16,
2189,
574,
63,
18,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
298,
17,
5984,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
17,
531,
398,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
298,
645,
5984,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
18,
531,
339,
347,
511,
63,
362,
63,
20,
8,
277,
304,
267,
666,
275,
408,
498,
26,
523,
340,
440,
282,
26,
574,
63,
17,
523,
574,
63,
18,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
715,
1552,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
18,
531,
398,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
756,
1552,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
17,
531,
339,
347,
511,
63,
1246,
8,
277,
304,
267,
666,
275,
408,
498,
26,
523,
340,
282,
508,
413,
14,
21,
26,
574,
63,
17,
523,
574,
63,
18,
199,
498,
63,
17,
26,
1163,
63,
585,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
413,
14,
21,
1552,
398,
291,
14,
3334,
8,
6418,
14,
374,
63,
1667,
9,
267,
291,
14,
2947,
8,
6418,
14,
1231,
12,
7712,
9,
267,
291,
14,
1815,
8,
6418,
14,
1989,
63,
498,
480,
498,
63,
17,
2237,
267,
291,
14,
3334,
8,
6418,
14,
1989,
63,
498,
480,
498,
63,
18,
2237,
398,
291,
14,
2947,
8,
409,
8,
6418,
14,
16007,
4000,
663,
5234,
498,
401,
298,
498,
63,
17,
13045,
267,
291,
14,
2947,
8,
409,
8,
6418,
14,
13012,
4000,
663,
5234,
585,
63,
17,
401,
298,
1848,
63,
585,
13045,
339,
347,
511,
63,
374,
63,
1667,
63,
17,
8,
277,
304,
267,
666,
275,
408,
199,
59,
8660,
61,
523,
359,
31839,
61,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
5009,
398,
291,
14,
1815,
8,
6418,
14,
374,
63,
1667,
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
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
2882,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
2508,
7765,
492,
2955,
199,
199,
3,
6006,
10621,
1133,
5002,
2295,
2348,
2952,
652,
25449,
734,
370,
506,
4340,
1655,
22700,
370,
199,
3,
675,
511,
63,
8349,
367,
314,
610,
74,
3822,
402,
5560,
421,
199,
533,
1379,
9278,
8,
2796,
14,
1746,
304,
272,
347,
2198,
8,
277,
12,
1324,
63,
495,
304,
267,
372,
291,
14,
2087,
14,
1122,
8,
6424,
8,
1210,
63,
495,
430,
339,
347,
6555,
8,
277,
12,
1324,
63,
505,
12,
1324,
63,
576,
304,
267,
372,
2955,
14,
2014,
8,
1210,
63,
505,
12,
1324,
63,
576,
9,
339,
347,
511,
63,
362,
63,
16,
8,
277,
304,
267,
666,
275,
408,
199,
498,
26,
574,
199,
199,
59,
23818,
413,
61,
523,
1163,
63,
498,
26,
272,
340,
282,
508,
413,
26,
574,
63,
17,
272,
340,
282,
508,
499,
26,
574,
63,
18,
272,
574,
63,
19,
199,
624,
398,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
499,
1552,
398,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
531,
267,
4978,
275,
769,
8,
1053,
367,
1242,
315,
7712,
14,
1661,
3223,
1012,
267,
291,
14,
2947,
8,
552,
8,
3223,
395,
413,
9,
267,
3420,
275,
4978,
59,
16,
61,
267,
291,
14,
2947,
8,
2792,
14,
354,
12,
298,
23818,
413,
531,
398,
291,
14,
2947,
8,
2792,
14,
362,
480,
1848,
63,
498,
1288,
298,
585,
63,
18,
531,
267,
291,
14,
2947,
8,
2792,
14,
362,
480,
498,
1288,
298,
585,
531,
339,
347,
511,
63,
362,
63,
17,
8,
277,
304,
267,
666,
275,
408,
199,
498,
26,
574,
199,
199,
59,
23818,
413,
61,
523,
1163,
63,
498,
26,
272,
340,
282,
508,
413,
26,
574,
63,
17,
272,
340,
282,
508,
499,
26,
574,
63,
18,
272,
574,
63,
19,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
650,
1552,
398,
4978,
275,
769,
8,
1053,
367,
1242,
315,
7712,
14,
1661,
3223,
1012,
267,
3420,
275,
4978,
59,
16,
61,
267,
291,
14,
2947,
8,
2792,
14,
362,
480,
1848,
63,
498,
1288,
298,
585,
63,
19,
531,
339,
347,
511,
63,
362,
63,
19,
8,
277,
304,
267,
666,
275,
408,
498,
26,
523,
340,
282,
508,
298,
17,
582,
574,
63,
17,
523,
340,
282,
59,
16,
61,
508,
298,
371,
22774,
16,
2189,
574,
63,
18,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
298,
17,
5984,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
17,
531,
398,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
298,
645,
5984,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
18,
531,
339,
347,
511,
63,
362,
63,
20,
8,
277,
304,
267,
666,
275,
408,
498,
26,
523,
340,
440,
282,
26,
574,
63,
17,
523,
574,
63,
18,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
715,
1552,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
18,
531,
398,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
756,
1552,
267,
291,
14,
2947,
8,
6418,
14,
362,
480,
498,
1288,
298,
585,
63,
17,
531,
339,
347,
511,
63,
1246,
8,
277,
304,
267,
666,
275,
408,
498,
26,
523,
340,
282,
508,
413,
14,
21,
26,
574,
63,
17,
523,
574,
63,
18,
199,
498,
63,
17,
26,
1163,
63,
585,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
2420,
65,
582,
413,
14,
21,
1552,
398,
291,
14,
3334,
8,
6418,
14,
374,
63,
1667,
9,
267,
291,
14,
2947,
8,
6418,
14,
1231,
12,
7712,
9,
267,
291,
14,
1815,
8,
6418,
14,
1989,
63,
498,
480,
498,
63,
17,
2237,
267,
291,
14,
3334,
8,
6418,
14,
1989,
63,
498,
480,
498,
63,
18,
2237,
398,
291,
14,
2947,
8,
409,
8,
6418,
14,
16007,
4000,
663,
5234,
498,
401,
298,
498,
63,
17,
13045,
267,
291,
14,
2947,
8,
409,
8,
6418,
14,
13012,
4000,
663,
5234,
585,
63,
17,
401,
298,
1848,
63,
585,
13045,
339,
347,
511,
63,
374,
63,
1667,
63,
17,
8,
277,
304,
267,
666,
275,
408,
199,
59,
8660,
61,
523,
359,
31839,
61,
199,
624,
267,
7712,
275,
291,
14,
2014,
8,
576,
12,
5009,
398,
291,
14,
1815,
8,
6418,
14,
374,
63,
1667,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pythonbyexample/PBE
|
dbe/classviews/edit_custom.py
|
1
|
5732
|
from django.forms import formsets
from django.contrib import messages
from django.db.models import Q
from detail import *
from edit import *
from dbe.shared.utils import *
class SearchFormViewMixin(BaseFormView):
ignore_get_keys = ["page"]
def get_form_kwargs(self):
""" Returns the keyword arguments for instanciating the form. """
r = self.request
kwargs = dict(initial=self.get_initial())
if r.method in ("POST", "PUT"):
kwargs.update(dict(data=r.POST, files=r.FILES))
elif r.GET:
# do get form processing if there's get data that's not in ignore list
if [k for k in r.GET.keys() if k not in self.ignore_get_keys]:
kwargs.update(dict(data=r.GET))
return kwargs
def get(self, request):
form = self.get_form()
if self.request.GET:
if form.is_valid():
self.process_form(form)
else:
return self.form_invalid(form)
return self.render_to_response(self.get_context_data(form=form))
class SearchFormView(FormView, SearchFormViewMixin):
"""FormView for search pages."""
class UpdateView2(UpdateView):
def get_success_url(self):
return self.object.get_absolute_url()
def get_context_data(self, **kwargs):
c = super(UpdateView2, self).get_context_data(**kwargs)
c.update(self.add_context())
return c
def add_context(self):
return {}
class UserUpdateView(UpdateView2):
def get_form_kwargs(self):
d = super(UpdateView2, self).get_form_kwargs()
d.update(dict(user=self.request.user))
return d
class CreateView2(CreateView):
def get_context_data(self, **kwargs):
c = super(CreateView2, self).get_context_data(**kwargs)
if hasattr(self, "add_context"):
c.update(self.add_context())
return c
def get_form_kwargs(self):
d = super(CreateView2, self).get_form_kwargs()
d.update(dict(user=self.request.user))
return d
class OwnObjMixin(SingleObjectMixin):
"""Access object, checking that it belongs to current user."""
item_name = None # used in permissions error message
owner_field = "creator" # object's field to compare to current user to check permission
def perm_error(self):
return HttpResponse("You don't have permissions to access this %s." % self.item_name)
def validate(self, obj):
if getattr(obj, self.owner_field) == self.request.user:
return True
def get_object(self, queryset=None):
obj = super(OwnObjMixin, self).get_object(queryset)
if not self.validate(obj): return None
return obj
class DeleteOwnObjView(OwnObjMixin, DeleteView):
"""Delete object, checking that it belongs to current user."""
class UpdateOwnObjView(OwnObjMixin, UpdateView2):
"""Update object, checking that it belongs to current user."""
class SearchEditFormset(SearchFormView):
"""Search form filtering a formset of items to be updated."""
model = None
formset_class = None
form_class = None
def get_form_class(self):
if self.request.method == "GET": return self.form_class
else: return self.formset_class
def get_queryset(self, form=None):
return self.model.objects.filter(self.get_query(form))
def get_query(self, form):
"""This method should always be overridden, applying search from the `form`."""
return Q()
def form_valid(self, form):
formset = None
if self.request.method == "GET":
formset = self.formset_class(queryset=self.get_queryset(form))
else:
form.save()
messages.success(self.request, "%s(s) were updated successfully" % self.model.__name__.capitalize())
formset = form
form = self.form_class(self.request.GET)
return self.render_to_response(self.get_context_data(form=form, formset=formset))
def form_invalid(self, form):
formset = form
form = self.form_class(self.request.GET)
return self.render_to_response(self.get_context_data(form=form, formset=formset))
def get(self, request, *args, **kwargs):
form = self.get_form()
if form.is_bound:
if form.is_valid(): return self.form_valid(form)
else: return self.form_invalid(form)
return self.render_to_response(self.get_context_data(form=form))
class CreateWithFormset(FormView):
""" Create multiple objects using a formset.
Passes user as an arg to each form init function.
"""
model = None
form_class = None
extra = 5
def get_form(self, form_class=None):
Formset = formsets.formset_factory(self.form_class, extra=self.extra)
Formset.form = staticmethod(curry(self.form_class, user=self.request.user))
return Formset(**self.get_form_kwargs())
def post(self, request, *args, **kwargs):
self.object = None
formset = self.get_form()
if formset.is_valid():
return self.form_valid(formset)
else:
return self.form_invalid(formset)
def form_valid(self, formset):
for form in formset:
if form.has_changed():
form.save()
return HttpResponseRedirect(reverse(self.success_url_name))
def form_invalid(self, form):
return self.render_to_response(self.get_context_data(form=form))
def get_context_data(self, **kwargs):
context = super(CreateWithFormset, self).get_context_data(**kwargs)
return updated( context, dict(formset=self.get_form()) )
|
bsd-3-clause
|
[
504,
1639,
14,
3351,
492,
1824,
2193,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
199,
504,
10093,
492,
627,
199,
504,
5283,
492,
627,
199,
504,
366,
1235,
14,
5555,
14,
1208,
492,
627,
421,
199,
533,
8730,
2821,
2768,
4256,
8,
1563,
2821,
2768,
304,
272,
3686,
63,
362,
63,
1612,
275,
2097,
1606,
937,
339,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
408,
1803,
314,
4252,
2368,
367,
2727,
290,
559,
1958,
314,
1824,
14,
408,
267,
519,
275,
291,
14,
1069,
267,
2074,
275,
1211,
8,
2747,
29,
277,
14,
362,
63,
2747,
1012,
267,
340,
519,
14,
765,
315,
1689,
4030,
401,
298,
4013,
2349,
288,
2074,
14,
873,
8,
807,
8,
576,
29,
82,
14,
4030,
12,
1584,
29,
82,
14,
9472,
430,
267,
916,
519,
14,
2970,
26,
288,
327,
886,
664,
1824,
6661,
340,
2337,
1159,
664,
666,
626,
1159,
440,
315,
3686,
769,
288,
340,
359,
75,
367,
1022,
315,
519,
14,
2970,
14,
1612,
342,
340,
1022,
440,
315,
291,
14,
4247,
63,
362,
63,
1612,
2189,
355,
2074,
14,
873,
8,
807,
8,
576,
29,
82,
14,
2970,
430,
267,
372,
2074,
339,
347,
664,
8,
277,
12,
1056,
304,
267,
1824,
275,
291,
14,
362,
63,
964,
342,
267,
340,
291,
14,
1069,
14,
2970,
26,
288,
340,
1824,
14,
374,
63,
1078,
837,
355,
291,
14,
1412,
63,
964,
8,
964,
9,
288,
587,
26,
355,
372,
291,
14,
964,
63,
3197,
8,
964,
9,
267,
372,
291,
14,
3352,
63,
475,
63,
1310,
8,
277,
14,
362,
63,
1100,
63,
576,
8,
964,
29,
964,
430,
421,
199,
533,
8730,
2821,
2768,
8,
2821,
2768,
12,
8730,
2821,
2768,
4256,
304,
272,
408,
2821,
2768,
367,
2754,
6497,
1041,
421,
199,
533,
6162,
2768,
18,
8,
4152,
2768,
304,
272,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
291,
14,
785,
14,
362,
63,
6116,
63,
633,
342,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
286,
275,
1613,
8,
4152,
2768,
18,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
286,
14,
873,
8,
277,
14,
525,
63,
1100,
1012,
267,
372,
286,
339,
347,
1050,
63,
1100,
8,
277,
304,
267,
372,
1052,
421,
199,
533,
2876,
4152,
2768,
8,
4152,
2768,
18,
304,
272,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
366,
275,
1613,
8,
4152,
2768,
18,
12,
291,
680,
362,
63,
964,
63,
958,
342,
267,
366,
14,
873,
8,
807,
8,
751,
29,
277,
14,
1069,
14,
751,
430,
267,
372,
366,
421,
199,
533,
2790,
2768,
18,
8,
2499,
2768,
304,
272,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
286,
275,
1613,
8,
2499,
2768,
18,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
340,
2688,
8,
277,
12,
298,
525,
63,
1100,
2349,
288,
286,
14,
873,
8,
277,
14,
525,
63,
1100,
1012,
267,
372,
286,
339,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
366,
275,
1613,
8,
2499,
2768,
18,
12,
291,
680,
362,
63,
964,
63,
958,
342,
267,
366,
14,
873,
8,
807,
8,
751,
29,
277,
14,
1069,
14,
751,
430,
267,
372,
366,
421,
199,
533,
593,
3501,
5665,
4256,
8,
7200,
1692,
4256,
304,
272,
408,
3946,
909,
12,
7907,
626,
652,
15006,
370,
1453,
922,
1041,
272,
1242,
63,
354,
263,
275,
488,
420,
327,
1202,
315,
3443,
1125,
1245,
272,
5771,
63,
698,
420,
275,
298,
9986,
2,
327,
909,
1159,
901,
370,
6540,
370,
1453,
922,
370,
1104,
4983,
339,
347,
10869,
63,
705,
8,
277,
304,
267,
372,
6183,
480,
5556,
2793,
1133,
1172,
3443,
370,
2879,
642,
450,
83,
2122,
450,
291,
14,
1053,
63,
354,
9,
339,
347,
4107,
8,
277,
12,
1559,
304,
267,
340,
2519,
8,
1113,
12,
291,
14,
4597,
63,
698,
9,
508,
291,
14,
1069,
14,
751,
26,
288,
372,
715,
339,
347,
664,
63,
785,
8,
277,
12,
7594,
29,
403,
304,
267,
1559,
275,
1613,
8,
28492,
5665,
4256,
12,
291,
680,
362,
63,
785,
8,
7924,
9,
267,
340,
440,
291,
14,
3502,
8,
1113,
304,
372,
488,
267,
372,
1559,
421,
199,
533,
8496,
28492,
5665,
2768,
8,
28492,
5665,
4256,
12,
8496,
2768,
304,
272,
408,
5392,
909,
12,
7907,
626,
652,
15006,
370,
1453,
922,
1041,
421,
199,
533,
6162,
28492,
5665,
2768,
8,
28492,
5665,
4256,
12,
6162,
2768,
18,
304,
272,
408,
4152,
909,
12,
7907,
626,
652,
15006,
370,
1453,
922,
1041,
421,
199,
533,
8730,
4685,
2821,
409,
8,
5278,
2821,
2768,
304,
272,
408,
5278,
1824,
14545,
282,
11068,
402,
2974,
370,
506,
4588,
1041,
272,
1402,
260,
275,
488,
272,
11068,
63,
533,
275,
488,
272,
1824,
63,
533,
259,
275,
488,
339,
347,
664,
63,
964,
63,
533,
8,
277,
304,
267,
340,
291,
14,
1069,
14,
765,
508,
298,
2970,
582,
372,
291,
14,
964,
63,
533,
267,
587,
26,
372,
291,
14,
10724,
63,
533,
339,
347,
664,
63,
7924,
8,
277,
12,
1824,
29,
403,
304,
267,
372,
291,
14,
1238,
14,
1462,
14,
1541,
8,
277,
14,
362,
63,
1131,
8,
964,
430,
339,
347,
664,
63,
1131,
8,
277,
12,
1824,
304,
267,
408,
2765,
1083,
1077,
3544,
506,
10087,
12,
18876,
2754,
687,
314,
658,
964,
17105,
267,
372,
1413,
342,
339,
347,
1824,
63,
1078,
8,
277,
12,
1824,
304,
267,
11068,
275,
488,
267,
340,
291,
14,
1069,
14,
765,
508,
298,
2970,
582,
288,
11068,
275,
291,
14,
10724,
63,
533,
8,
7924,
29,
277,
14,
362,
63,
7924,
8,
964,
430,
267,
587,
26,
288,
1824,
14,
2117,
342,
288,
3788,
14,
3742,
8,
277,
14,
1069,
12,
2071,
83,
8,
83,
9,
4898,
4588,
8792,
2,
450,
291,
14,
1238,
855,
354,
4343,
18351,
1012,
288,
11068,
275,
1824,
288,
1824,
275,
291,
14,
964,
63,
533,
8,
277,
14,
1069,
14,
2970,
9,
267,
372,
291,
14,
3352
] |
[
1639,
14,
3351,
492,
1824,
2193,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
199,
504,
10093,
492,
627,
199,
504,
5283,
492,
627,
199,
504,
366,
1235,
14,
5555,
14,
1208,
492,
627,
421,
199,
533,
8730,
2821,
2768,
4256,
8,
1563,
2821,
2768,
304,
272,
3686,
63,
362,
63,
1612,
275,
2097,
1606,
937,
339,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
408,
1803,
314,
4252,
2368,
367,
2727,
290,
559,
1958,
314,
1824,
14,
408,
267,
519,
275,
291,
14,
1069,
267,
2074,
275,
1211,
8,
2747,
29,
277,
14,
362,
63,
2747,
1012,
267,
340,
519,
14,
765,
315,
1689,
4030,
401,
298,
4013,
2349,
288,
2074,
14,
873,
8,
807,
8,
576,
29,
82,
14,
4030,
12,
1584,
29,
82,
14,
9472,
430,
267,
916,
519,
14,
2970,
26,
288,
327,
886,
664,
1824,
6661,
340,
2337,
1159,
664,
666,
626,
1159,
440,
315,
3686,
769,
288,
340,
359,
75,
367,
1022,
315,
519,
14,
2970,
14,
1612,
342,
340,
1022,
440,
315,
291,
14,
4247,
63,
362,
63,
1612,
2189,
355,
2074,
14,
873,
8,
807,
8,
576,
29,
82,
14,
2970,
430,
267,
372,
2074,
339,
347,
664,
8,
277,
12,
1056,
304,
267,
1824,
275,
291,
14,
362,
63,
964,
342,
267,
340,
291,
14,
1069,
14,
2970,
26,
288,
340,
1824,
14,
374,
63,
1078,
837,
355,
291,
14,
1412,
63,
964,
8,
964,
9,
288,
587,
26,
355,
372,
291,
14,
964,
63,
3197,
8,
964,
9,
267,
372,
291,
14,
3352,
63,
475,
63,
1310,
8,
277,
14,
362,
63,
1100,
63,
576,
8,
964,
29,
964,
430,
421,
199,
533,
8730,
2821,
2768,
8,
2821,
2768,
12,
8730,
2821,
2768,
4256,
304,
272,
408,
2821,
2768,
367,
2754,
6497,
1041,
421,
199,
533,
6162,
2768,
18,
8,
4152,
2768,
304,
272,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
291,
14,
785,
14,
362,
63,
6116,
63,
633,
342,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
286,
275,
1613,
8,
4152,
2768,
18,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
286,
14,
873,
8,
277,
14,
525,
63,
1100,
1012,
267,
372,
286,
339,
347,
1050,
63,
1100,
8,
277,
304,
267,
372,
1052,
421,
199,
533,
2876,
4152,
2768,
8,
4152,
2768,
18,
304,
272,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
366,
275,
1613,
8,
4152,
2768,
18,
12,
291,
680,
362,
63,
964,
63,
958,
342,
267,
366,
14,
873,
8,
807,
8,
751,
29,
277,
14,
1069,
14,
751,
430,
267,
372,
366,
421,
199,
533,
2790,
2768,
18,
8,
2499,
2768,
304,
272,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
286,
275,
1613,
8,
2499,
2768,
18,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
340,
2688,
8,
277,
12,
298,
525,
63,
1100,
2349,
288,
286,
14,
873,
8,
277,
14,
525,
63,
1100,
1012,
267,
372,
286,
339,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
366,
275,
1613,
8,
2499,
2768,
18,
12,
291,
680,
362,
63,
964,
63,
958,
342,
267,
366,
14,
873,
8,
807,
8,
751,
29,
277,
14,
1069,
14,
751,
430,
267,
372,
366,
421,
199,
533,
593,
3501,
5665,
4256,
8,
7200,
1692,
4256,
304,
272,
408,
3946,
909,
12,
7907,
626,
652,
15006,
370,
1453,
922,
1041,
272,
1242,
63,
354,
263,
275,
488,
420,
327,
1202,
315,
3443,
1125,
1245,
272,
5771,
63,
698,
420,
275,
298,
9986,
2,
327,
909,
1159,
901,
370,
6540,
370,
1453,
922,
370,
1104,
4983,
339,
347,
10869,
63,
705,
8,
277,
304,
267,
372,
6183,
480,
5556,
2793,
1133,
1172,
3443,
370,
2879,
642,
450,
83,
2122,
450,
291,
14,
1053,
63,
354,
9,
339,
347,
4107,
8,
277,
12,
1559,
304,
267,
340,
2519,
8,
1113,
12,
291,
14,
4597,
63,
698,
9,
508,
291,
14,
1069,
14,
751,
26,
288,
372,
715,
339,
347,
664,
63,
785,
8,
277,
12,
7594,
29,
403,
304,
267,
1559,
275,
1613,
8,
28492,
5665,
4256,
12,
291,
680,
362,
63,
785,
8,
7924,
9,
267,
340,
440,
291,
14,
3502,
8,
1113,
304,
372,
488,
267,
372,
1559,
421,
199,
533,
8496,
28492,
5665,
2768,
8,
28492,
5665,
4256,
12,
8496,
2768,
304,
272,
408,
5392,
909,
12,
7907,
626,
652,
15006,
370,
1453,
922,
1041,
421,
199,
533,
6162,
28492,
5665,
2768,
8,
28492,
5665,
4256,
12,
6162,
2768,
18,
304,
272,
408,
4152,
909,
12,
7907,
626,
652,
15006,
370,
1453,
922,
1041,
421,
199,
533,
8730,
4685,
2821,
409,
8,
5278,
2821,
2768,
304,
272,
408,
5278,
1824,
14545,
282,
11068,
402,
2974,
370,
506,
4588,
1041,
272,
1402,
260,
275,
488,
272,
11068,
63,
533,
275,
488,
272,
1824,
63,
533,
259,
275,
488,
339,
347,
664,
63,
964,
63,
533,
8,
277,
304,
267,
340,
291,
14,
1069,
14,
765,
508,
298,
2970,
582,
372,
291,
14,
964,
63,
533,
267,
587,
26,
372,
291,
14,
10724,
63,
533,
339,
347,
664,
63,
7924,
8,
277,
12,
1824,
29,
403,
304,
267,
372,
291,
14,
1238,
14,
1462,
14,
1541,
8,
277,
14,
362,
63,
1131,
8,
964,
430,
339,
347,
664,
63,
1131,
8,
277,
12,
1824,
304,
267,
408,
2765,
1083,
1077,
3544,
506,
10087,
12,
18876,
2754,
687,
314,
658,
964,
17105,
267,
372,
1413,
342,
339,
347,
1824,
63,
1078,
8,
277,
12,
1824,
304,
267,
11068,
275,
488,
267,
340,
291,
14,
1069,
14,
765,
508,
298,
2970,
582,
288,
11068,
275,
291,
14,
10724,
63,
533,
8,
7924,
29,
277,
14,
362,
63,
7924,
8,
964,
430,
267,
587,
26,
288,
1824,
14,
2117,
342,
288,
3788,
14,
3742,
8,
277,
14,
1069,
12,
2071,
83,
8,
83,
9,
4898,
4588,
8792,
2,
450,
291,
14,
1238,
855,
354,
4343,
18351,
1012,
288,
11068,
275,
1824,
288,
1824,
275,
291,
14,
964,
63,
533,
8,
277,
14,
1069,
14,
2970,
9,
267,
372,
291,
14,
3352,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
import os
import re
import signal as _signal
import sys
import time
import threading
from cherrypy._cpcompat import basestring, get_daemon, get_thread_ident, ntob, set, Timer, SetDaemonProperty
# _module__file__base is used by Autoreload to make
# absolute any filenames retrieved from sys.modules which are not
# already absolute paths. This is to work around Python's quirk
# of importing the startup script and using a relative filename
# for it in sys.modules.
#
# Autoreload examines sys.modules afresh every time it runs. If an application
# changes the current directory by executing os.chdir(), then the next time
# Autoreload runs, it will not be able to find any filenames which are
# not absolute paths, because the current directory is not the same as when the
# module was first imported. Autoreload will then wrongly conclude the file has
# "changed", and initiate the shutdown/re-exec sequence.
# See ticket #917.
# For this workaround to have a decent probability of success, this module
# needs to be imported as early as possible, before the app has much chance
# to change the working directory.
_module__file__base = os.getcwd()
class SimplePlugin(object):
"""Plugin base class which auto-subscribes methods for known channels."""
bus = None
"""A :class:`Bus <cherrypy.process.wspbus.Bus>`, usually cherrypy.engine."""
def __init__(self, bus):
self.bus = bus
def subscribe(self):
"""Register this object as a (multi-channel) listener on the bus."""
for channel in self.bus.listeners:
# Subscribe self.start, self.exit, etc. if present.
method = getattr(self, channel, None)
if method is not None:
self.bus.subscribe(channel, method)
def unsubscribe(self):
"""Unregister this object as a listener on the bus."""
for channel in self.bus.listeners:
# Unsubscribe self.start, self.exit, etc. if present.
method = getattr(self, channel, None)
if method is not None:
self.bus.unsubscribe(channel, method)
class SignalHandler(object):
"""Register bus channels (and listeners) for system signals.
You can modify what signals your application listens for, and what it does
when it receives signals, by modifying :attr:`SignalHandler.handlers`,
a dict of {signal name: callback} pairs. The default set is::
handlers = {'SIGTERM': self.bus.exit,
'SIGHUP': self.handle_SIGHUP,
'SIGUSR1': self.bus.graceful,
}
The :func:`SignalHandler.handle_SIGHUP`` method calls
:func:`bus.restart()<cherrypy.process.wspbus.Bus.restart>`
if the process is daemonized, but
:func:`bus.exit()<cherrypy.process.wspbus.Bus.exit>`
if the process is attached to a TTY. This is because Unix window
managers tend to send SIGHUP to terminal windows when the user closes them.
Feel free to add signals which are not available on every platform. The
:class:`SignalHandler` will ignore errors raised from attempting to register
handlers for unknown signals.
"""
handlers = {}
"""A map from signal names (e.g. 'SIGTERM') to handlers (e.g. bus.exit)."""
signals = {}
"""A map from signal numbers to names."""
for k, v in vars(_signal).items():
if k.startswith('SIG') and not k.startswith('SIG_'):
signals[v] = k
del k, v
def __init__(self, bus):
self.bus = bus
# Set default handlers
self.handlers = {'SIGTERM': self.bus.exit,
'SIGHUP': self.handle_SIGHUP,
'SIGUSR1': self.bus.graceful,
}
if sys.platform[:4] == 'java':
del self.handlers['SIGUSR1']
self.handlers['SIGUSR2'] = self.bus.graceful
self.bus.log("SIGUSR1 cannot be set on the JVM platform. "
"Using SIGUSR2 instead.")
self.handlers['SIGINT'] = self._jython_SIGINT_handler
self._previous_handlers = {}
def _jython_SIGINT_handler(self, signum=None, frame=None):
# See http://bugs.jython.org/issue1313
self.bus.log('Keyboard Interrupt: shutting down bus')
self.bus.exit()
def subscribe(self):
"""Subscribe self.handlers to signals."""
for sig, func in self.handlers.items():
try:
self.set_handler(sig, func)
except ValueError:
pass
def unsubscribe(self):
"""Unsubscribe self.handlers from signals."""
for signum, handler in self._previous_handlers.items():
signame = self.signals[signum]
if handler is None:
self.bus.log("Restoring %s handler to SIG_DFL." % signame)
handler = _signal.SIG_DFL
else:
self.bus.log("Restoring %s handler %r." % (signame, handler))
try:
our_handler = _signal.signal(signum, handler)
if our_handler is None:
self.bus.log("Restored old %s handler %r, but our "
"handler was not registered." %
(signame, handler), level=30)
except ValueError:
self.bus.log("Unable to restore %s handler %r." %
(signame, handler), level=40, traceback=True)
def set_handler(self, signal, listener=None):
"""Subscribe a handler for the given signal (number or name).
If the optional 'listener' argument is provided, it will be
subscribed as a listener for the given signal's channel.
If the given signal name or number is not available on the current
platform, ValueError is raised.
"""
if isinstance(signal, basestring):
signum = getattr(_signal, signal, None)
if signum is None:
raise ValueError("No such signal: %r" % signal)
signame = signal
else:
try:
signame = self.signals[signal]
except KeyError:
raise ValueError("No such signal: %r" % signal)
signum = signal
prev = _signal.signal(signum, self._handle_signal)
self._previous_handlers[signum] = prev
if listener is not None:
self.bus.log("Listening for %s." % signame)
self.bus.subscribe(signame, listener)
def _handle_signal(self, signum=None, frame=None):
"""Python signal handler (self.set_handler subscribes it for you)."""
signame = self.signals[signum]
self.bus.log("Caught signal %s." % signame)
self.bus.publish(signame)
def handle_SIGHUP(self):
"""Restart if daemonized, else exit."""
if os.isatty(sys.stdin.fileno()):
# not daemonized (may be foreground or background)
self.bus.log("SIGHUP caught but not daemonized. Exiting.")
self.bus.exit()
else:
self.bus.log("SIGHUP caught while daemonized. Restarting.")
self.bus.restart()
try:
import pwd, grp
except ImportError:
pwd, grp = None, None
class DropPrivileges(SimplePlugin):
"""Drop privileges. uid/gid arguments not available on Windows.
Special thanks to Gavin Baker: http://antonym.org/node/100.
"""
def __init__(self, bus, umask=None, uid=None, gid=None):
SimplePlugin.__init__(self, bus)
self.finalized = False
self.uid = uid
self.gid = gid
self.umask = umask
def _get_uid(self):
return self._uid
def _set_uid(self, val):
if val is not None:
if pwd is None:
self.bus.log("pwd module not available; ignoring uid.",
level=30)
val = None
elif isinstance(val, basestring):
val = pwd.getpwnam(val)[2]
self._uid = val
uid = property(_get_uid, _set_uid,
doc="The uid under which to run. Availability: Unix.")
def _get_gid(self):
return self._gid
def _set_gid(self, val):
if val is not None:
if grp is None:
self.bus.log("grp module not available; ignoring gid.",
level=30)
val = None
elif isinstance(val, basestring):
val = grp.getgrnam(val)[2]
self._gid = val
gid = property(_get_gid, _set_gid,
doc="The gid under which to run. Availability: Unix.")
def _get_umask(self):
return self._umask
def _set_umask(self, val):
if val is not None:
try:
os.umask
except AttributeError:
self.bus.log("umask function not available; ignoring umask.",
level=30)
val = None
self._umask = val
umask = property(_get_umask, _set_umask,
doc="""The default permission mode for newly created files and directories.
Usually expressed in octal format, for example, ``0644``.
Availability: Unix, Windows.
""")
def start(self):
# uid/gid
def current_ids():
"""Return the current (uid, gid) if available."""
name, group = None, None
if pwd:
name = pwd.getpwuid(os.getuid())[0]
if grp:
group = grp.getgrgid(os.getgid())[0]
return name, group
if self.finalized:
if not (self.uid is None and self.gid is None):
self.bus.log('Already running as uid: %r gid: %r' %
current_ids())
else:
if self.uid is None and self.gid is None:
if pwd or grp:
self.bus.log('uid/gid not set', level=30)
else:
self.bus.log('Started as uid: %r gid: %r' % current_ids())
if self.gid is not None:
os.setgid(self.gid)
os.setgroups([])
if self.uid is not None:
os.setuid(self.uid)
self.bus.log('Running as uid: %r gid: %r' % current_ids())
# umask
if self.finalized:
if self.umask is not None:
self.bus.log('umask already set to: %03o' % self.umask)
else:
if self.umask is None:
self.bus.log('umask not set', level=30)
else:
old_umask = os.umask(self.umask)
self.bus.log('umask old: %03o, new: %03o' %
(old_umask, self.umask))
self.finalized = True
# This is slightly higher than the priority for server.start
# in order to facilitate the most common use: starting on a low
# port (which requires root) and then dropping to another user.
start.priority = 77
class Daemonizer(SimplePlugin):
"""Daemonize the running script.
Use this with a Web Site Process Bus via::
Daemonizer(bus).subscribe()
When this component finishes, the process is completely decoupled from
the parent environment. Please note that when this component is used,
the return code from the parent process will still be 0 if a startup
error occurs in the forked children. Errors in the initial daemonizing
process still return proper exit codes. Therefore, if you use this
plugin to daemonize, don't use the return code as an accurate indicator
of whether the process fully started. In fact, that return code only
indicates if the process succesfully finished the first fork.
"""
def __init__(self, bus, stdin='/dev/null', stdout='/dev/null',
stderr='/dev/null'):
SimplePlugin.__init__(self, bus)
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.finalized = False
def start(self):
if self.finalized:
self.bus.log('Already deamonized.')
# forking has issues with threads:
# http://www.opengroup.org/onlinepubs/000095399/functions/fork.html
# "The general problem with making fork() work in a multi-threaded
# world is what to do with all of the threads..."
# So we check for active threads:
if threading.activeCount() != 1:
self.bus.log('There are %r active threads. '
'Daemonizing now may cause strange failures.' %
threading.enumerate(), level=30)
# See http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
# (or http://www.faqs.org/faqs/unix-faq/programmer/faq/ section 1.7)
# and http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012
# Finish up with the current stdout/stderr
sys.stdout.flush()
sys.stderr.flush()
# Do first fork.
try:
pid = os.fork()
if pid == 0:
# This is the child process. Continue.
pass
else:
# This is the first parent. Exit, now that we've forked.
self.bus.log('Forking once.')
os._exit(0)
except OSError:
# Python raises OSError rather than returning negative numbers.
exc = sys.exc_info()[1]
sys.exit("%s: fork #1 failed: (%d) %s\n"
% (sys.argv[0], exc.errno, exc.strerror))
os.setsid()
# Do second fork
try:
pid = os.fork()
if pid > 0:
self.bus.log('Forking twice.')
os._exit(0) # Exit second parent
except OSError:
exc = sys.exc_info()[1]
sys.exit("%s: fork #2 failed: (%d) %s\n"
% (sys.argv[0], exc.errno, exc.strerror))
os.chdir("/")
os.umask(0)
si = open(self.stdin, "r")
so = open(self.stdout, "a+")
se = open(self.stderr, "a+")
# os.dup2(fd, fd2) will close fd2 if necessary,
# so we don't explicitly close stdin/out/err.
# See http://docs.python.org/lib/os-fd-ops.html
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
self.bus.log('Daemonized to PID: %s' % os.getpid())
self.finalized = True
start.priority = 65
class PIDFile(SimplePlugin):
"""Maintain a PID file via a WSPBus."""
def __init__(self, bus, pidfile):
SimplePlugin.__init__(self, bus)
self.pidfile = pidfile
self.finalized = False
def start(self):
pid = os.getpid()
if self.finalized:
self.bus.log('PID %r already written to %r.' % (pid, self.pidfile))
else:
open(self.pidfile, "wb").write(ntob("%s" % pid, 'utf8'))
self.bus.log('PID %r written to %r.' % (pid, self.pidfile))
self.finalized = True
start.priority = 70
def exit(self):
try:
os.remove(self.pidfile)
self.bus.log('PID file removed: %r.' % self.pidfile)
except (KeyboardInterrupt, SystemExit):
raise
except:
pass
class PerpetualTimer(Timer):
"""A responsive subclass of threading.Timer whose run() method repeats.
Use this timer only when you really need a very interruptible timer;
this checks its 'finished' condition up to 20 times a second, which can
results in pretty high CPU usage
"""
def __init__(self, *args, **kwargs):
"Override parent constructor to allow 'bus' to be provided."
self.bus = kwargs.pop('bus', None)
super(PerpetualTimer, self).__init__(*args, **kwargs)
def run(self):
while True:
self.finished.wait(self.interval)
if self.finished.isSet():
return
try:
self.function(*self.args, **self.kwargs)
except Exception:
if self.bus:
self.bus.log(
"Error in perpetual timer thread function %r." %
self.function, level=40, traceback=True)
# Quit on first error to avoid massive logs.
raise
class BackgroundTask(SetDaemonProperty, threading.Thread):
"""A subclass of threading.Thread whose run() method repeats.
Use this class for most repeating tasks. It uses time.sleep() to wait
for each interval, which isn't very responsive; that is, even if you call
self.cancel(), you'll have to wait until the sleep() call finishes before
the thread stops. To compensate, it defaults to being daemonic, which means
it won't delay stopping the whole process.
"""
def __init__(self, interval, function, args=[], kwargs={}, bus=None):
threading.Thread.__init__(self)
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.running = False
self.bus = bus
# default to daemonic
self.daemon = True
def cancel(self):
self.running = False
def run(self):
self.running = True
while self.running:
time.sleep(self.interval)
if not self.running:
return
try:
self.function(*self.args, **self.kwargs)
except Exception:
if self.bus:
self.bus.log("Error in background task thread function %r."
% self.function, level=40, traceback=True)
# Quit on first error to avoid massive logs.
raise
class Monitor(SimplePlugin):
"""WSPBus listener to periodically run a callback in its own thread."""
callback = None
"""The function to call at intervals."""
frequency = 60
"""The time in seconds between callback runs."""
thread = None
"""A :class:`BackgroundTask<cherrypy.process.plugins.BackgroundTask>` thread."""
def __init__(self, bus, callback, frequency=60, name=None):
SimplePlugin.__init__(self, bus)
self.callback = callback
self.frequency = frequency
self.thread = None
self.name = name
def start(self):
"""Start our callback in its own background thread."""
if self.frequency > 0:
threadname = self.name or self.__class__.__name__
if self.thread is None:
self.thread = BackgroundTask(self.frequency, self.callback,
bus = self.bus)
self.thread.setName(threadname)
self.thread.start()
self.bus.log("Started monitor thread %r." % threadname)
else:
self.bus.log("Monitor thread %r already started." % threadname)
start.priority = 70
def stop(self):
"""Stop our callback's background task thread."""
if self.thread is None:
self.bus.log("No thread running for %s." % self.name or self.__class__.__name__)
else:
if self.thread is not threading.currentThread():
name = self.thread.getName()
self.thread.cancel()
if not get_daemon(self.thread):
self.bus.log("Joining %r" % name)
self.thread.join()
self.bus.log("Stopped thread %r." % name)
self.thread = None
def graceful(self):
"""Stop the callback's background task thread and restart it."""
self.stop()
self.start()
class Autoreloader(Monitor):
"""Monitor which re-executes the process when files change.
This :ref:`plugin<plugins>` restarts the process (via :func:`os.execv`)
if any of the files it monitors change (or is deleted). By default, the
autoreloader monitors all imported modules; you can add to the
set by adding to ``autoreload.files``::
cherrypy.engine.autoreload.files.add(myFile)
If there are imported files you do *not* wish to monitor, you can adjust the
``match`` attribute, a regular expression. For example, to stop monitoring
cherrypy itself::
cherrypy.engine.autoreload.match = r'^(?!cherrypy).+'
Like all :class:`Monitor<cherrypy.process.plugins.Monitor>` plugins,
the autoreload plugin takes a ``frequency`` argument. The default is
1 second; that is, the autoreloader will examine files once each second.
"""
files = None
"""The set of files to poll for modifications."""
frequency = 1
"""The interval in seconds at which to poll for modified files."""
match = '.*'
"""A regular expression by which to match filenames."""
def __init__(self, bus, frequency=1, match='.*'):
self.mtimes = {}
self.files = set()
self.match = match
Monitor.__init__(self, bus, self.run, frequency)
def start(self):
"""Start our own background task thread for self.run."""
if self.thread is None:
self.mtimes = {}
Monitor.start(self)
start.priority = 70
def sysfiles(self):
"""Return a Set of sys.modules filenames to monitor."""
files = set()
for k, m in sys.modules.items():
if re.match(self.match, k):
if hasattr(m, '__loader__') and hasattr(m.__loader__, 'archive'):
f = m.__loader__.archive
else:
f = getattr(m, '__file__', None)
if f is not None and not os.path.isabs(f):
# ensure absolute paths so a os.chdir() in the app doesn't break me
f = os.path.normpath(os.path.join(_module__file__base, f))
files.add(f)
return files
def run(self):
"""Reload the process if registered files have been modified."""
for filename in self.sysfiles() | self.files:
if filename:
if filename.endswith('.pyc'):
filename = filename[:-1]
oldtime = self.mtimes.get(filename, 0)
if oldtime is None:
# Module with no .py file. Skip it.
continue
try:
mtime = os.stat(filename).st_mtime
except OSError:
# Either a module with no .py file, or it's been deleted.
mtime = None
if filename not in self.mtimes:
# If a module has no .py file, this will be None.
self.mtimes[filename] = mtime
else:
if mtime is None or mtime > oldtime:
# The file has been deleted or modified.
self.bus.log("Restarting because %s changed." % filename)
self.thread.cancel()
self.bus.log("Stopped thread %r." % self.thread.getName())
self.bus.restart()
return
class ThreadManager(SimplePlugin):
"""Manager for HTTP request threads.
If you have control over thread creation and destruction, publish to
the 'acquire_thread' and 'release_thread' channels (for each thread).
This will register/unregister the current thread and publish to
'start_thread' and 'stop_thread' listeners in the bus as needed.
If threads are created and destroyed by code you do not control
(e.g., Apache), then, at the beginning of every HTTP request,
publish to 'acquire_thread' only. You should not publish to
'release_thread' in this case, since you do not know whether
the thread will be re-used or not. The bus will call
'stop_thread' listeners for you when it stops.
"""
threads = None
"""A map of {thread ident: index number} pairs."""
def __init__(self, bus):
self.threads = {}
SimplePlugin.__init__(self, bus)
self.bus.listeners.setdefault('acquire_thread', set())
self.bus.listeners.setdefault('start_thread', set())
self.bus.listeners.setdefault('release_thread', set())
self.bus.listeners.setdefault('stop_thread', set())
def acquire_thread(self):
"""Run 'start_thread' listeners for the current thread.
If the current thread has already been seen, any 'start_thread'
listeners will not be run again.
"""
thread_ident = get_thread_ident()
if thread_ident not in self.threads:
# We can't just use get_ident as the thread ID
# because some platforms reuse thread ID's.
i = len(self.threads) + 1
self.threads[thread_ident] = i
self.bus.publish('start_thread', i)
def release_thread(self):
"""Release the current thread and run 'stop_thread' listeners."""
thread_ident = get_thread_ident()
i = self.threads.pop(thread_ident, None)
if i is not None:
self.bus.publish('stop_thread', i)
def stop(self):
"""Release all threads and run all 'stop_thread' listeners."""
for thread_ident, i in self.threads.items():
self.bus.publish('stop_thread', i)
self.threads.clear()
graceful = stop
|
mit
|
[
624,
8972,
8500,
367,
675,
543,
282,
6001,
11666,
7132,
18573,
1041,
199,
199,
646,
747,
199,
646,
295,
199,
646,
4673,
465,
485,
4653,
199,
646,
984,
199,
646,
900,
199,
646,
5796,
199,
199,
504,
13397,
423,
1850,
5819,
492,
7116,
12,
664,
63,
10824,
12,
664,
63,
2671,
63,
5425,
12,
302,
475,
66,
12,
663,
12,
22287,
12,
2494,
20555,
3697,
199,
199,
3,
485,
578,
363,
493,
363,
1095,
365,
1202,
701,
27722,
720,
912,
370,
1852,
199,
3,
3679,
1263,
6203,
12396,
687,
984,
14,
3112,
1314,
787,
440,
199,
3,
2575,
3679,
3792,
14,
221,
961,
365,
370,
1736,
6818,
2018,
1159,
2173,
723,
75,
199,
3,
402,
16306,
314,
14210,
2884,
436,
1808,
282,
3847,
1788,
199,
3,
367,
652,
315,
984,
14,
3112,
14,
199,
3,
199,
3,
27722,
720,
912,
15735,
3746,
984,
14,
3112,
15871,
2107,
4036,
900,
652,
7858,
14,
982,
376,
4223,
199,
3,
4493,
314,
1453,
2082,
701,
14043,
747,
14,
8563,
1062,
2066,
314,
2163,
900,
199,
3,
27722,
720,
912,
7858,
12,
652,
911,
440,
506,
7688,
370,
2342,
1263,
6203,
1314,
787,
199,
3,
440,
3679,
3792,
12,
2952,
314,
1453,
2082,
365,
440,
314,
2011,
465,
1380,
314,
199,
3,
859,
1990,
1642,
8439,
14,
221,
27722,
720,
912,
911,
2066,
6835,
590,
406,
1285,
314,
570,
965,
199,
3,
298,
2489,
401,
436,
11023,
323,
314,
12842,
15,
264,
13,
1628,
3414,
14,
199,
3,
1666,
12052,
327,
29702,
14,
199,
3,
2104,
642,
18092,
370,
1172,
282,
477,
2946,
12224,
402,
3182,
12,
642,
859,
199,
3,
4839,
370,
506,
8439,
465,
14670,
465,
3962,
12,
2544,
314,
1145,
965,
8298,
22044,
199,
3,
370,
1570,
314,
6449,
2082,
14,
199,
63,
578,
363,
493,
363,
1095,
275,
747,
14,
9458,
342,
421,
199,
533,
5870,
5061,
8,
785,
304,
272,
408,
5061,
1300,
1021,
1314,
2599,
13,
954,
729,
11562,
3102,
367,
6040,
9245,
1041,
339,
10414,
275,
488,
272,
408,
33,
520,
533,
1705,
12106,
665,
23438,
14,
1412,
14,
87,
681,
5610,
14,
12106,
30,
3559,
9987,
13397,
14,
3908,
1041,
339,
347,
636,
826,
721,
277,
12,
10414,
304,
267,
291,
14,
5610,
275,
10414,
339,
347,
23421,
8,
277,
304,
267,
408,
7099,
642,
909,
465,
282,
334,
3029,
13,
2775,
9,
11647,
641,
314,
10414,
1041,
267,
367,
3623,
315,
291,
14,
5610,
14,
17301,
26,
288,
327,
4804,
5355,
291,
14,
928,
12,
291,
14,
2224,
12,
5423,
14,
340,
3451,
14,
288,
1083,
275,
2519,
8,
277,
12,
3623,
12,
488,
9,
288,
340,
1083,
365,
440,
488,
26,
355,
291,
14,
5610,
14,
10108,
8,
2775,
12,
1083,
9,
339,
347,
625,
10108,
8,
277,
304,
267,
408,
27419,
642,
909,
465,
282,
11647,
641,
314,
10414,
1041,
267,
367,
3623,
315,
291,
14,
5610,
14,
17301,
26,
288,
327,
15254,
456,
5355,
291,
14,
928,
12,
291,
14,
2224,
12,
5423,
14,
340,
3451,
14,
288,
1083,
275,
2519,
8,
277,
12,
3623,
12,
488,
9,
288,
340,
1083,
365,
440,
488,
26,
355,
291,
14,
5610,
14,
25592,
8,
2775,
12,
1083,
9,
4388,
199,
533,
18288,
2461,
8,
785,
304,
272,
408,
7099,
10414,
9245,
334,
460,
19946,
9,
367,
2656,
10166,
14,
339,
2047,
883,
2811,
4052,
10166,
2195,
4223,
1212,
1597,
561,
367,
12,
436,
4052,
652,
1630,
272,
1380,
652,
23192,
10166,
12,
701,
24662,
520,
962,
1705,
11274,
2461,
14,
5586,
3559,
272,
282,
1211,
402,
469,
4653,
536,
26,
3233,
93,
6342,
14,
710,
849,
663,
365,
447,
398,
8297,
275,
791,
29190,
356,
291,
14,
5610,
14,
2224,
12,
490,
283,
7864,
40,
2160,
356,
291,
14,
2479,
63,
7864,
40,
2160,
12,
490,
283,
7864,
22592,
17,
356,
291,
14,
5610,
14,
20631,
1893,
12,
673,
789,
339,
710,
520,
1532,
1705,
11274,
2461,
14,
2479,
63,
7864,
40,
2160,
1040,
1083,
4882,
272,
520,
1532,
1705,
5610,
14,
10506,
342,
28,
23438,
14,
1412,
14,
87,
681,
5610,
14,
12106,
14,
10506,
8637,
272,
340,
314,
2112,
365,
11128,
1759,
12,
1325,
272,
520,
1532,
1705,
5610,
14,
2224,
342,
28,
23438,
14,
1412,
14,
87,
681,
5610,
14,
12106,
14,
2224,
8637,
272,
340,
314,
2112,
365,
10102,
370,
282,
377,
2099,
14,
961,
365,
2952,
13074,
4353,
272,
19680,
221,
7169,
370,
3222,
428,
13454,
2160,
370,
11167,
10061,
1380,
314,
922,
27811,
3062,
14,
339,
7949,
352,
2867,
370,
1050,
10166,
1314,
787,
440,
2808,
641,
4036,
4298,
14,
710,
272,
520,
533,
1705,
11274,
2461,
64,
911,
3686,
2552,
4915,
687,
19595,
370,
2274,
272,
8297,
367,
5809,
10166,
14,
272,
408,
339,
8297,
275,
1052,
272,
408,
33,
2341,
687,
4673,
1561,
334,
69,
14,
71,
14,
283,
29190,
358,
370,
8297,
334,
69,
14,
71,
14,
10414,
14,
2224,
10477,
339,
10166,
275,
1052,
272,
408,
33,
2341,
687,
4673,
5579,
370,
1561,
1041,
339,
367,
1022,
12,
373,
315,
6802,
1547,
4653,
680,
1744,
837,
267,
340,
1022,
14,
2460,
360,
7864,
358,
436,
440,
1022,
14,
2460,
360,
7864,
25865,
288,
10166,
59,
86,
61,
275,
1022,
272,
2150,
1022,
12,
373,
339,
347,
636,
826,
721,
277,
12,
10414,
304,
267,
291,
14,
5610,
275,
10414,
267,
327,
2494,
849,
8297,
267,
291,
14,
5586,
275,
791,
29190,
356,
291,
14,
5610,
14,
2224,
12,
586,
283,
7864,
40,
2160,
356,
291,
14,
2479,
63,
7864,
40,
2160,
12,
586,
283,
7864,
22592,
17,
356,
291,
14,
5610,
14,
20631,
1893,
12,
586,
789,
398,
340,
984,
14,
3246,
1491,
20,
61,
508,
283,
6138,
356,
288,
2150,
291,
14,
5586,
459,
7864,
22592,
17,
418,
288,
291,
14,
5586,
459,
7864,
22592,
18,
418,
275,
291,
14,
5610,
14,
20631,
1893,
288,
291,
14,
5610,
14,
793,
480,
7864,
22592,
17,
3913,
506,
663,
641,
314,
1603,
6849,
4298,
14,
298,
586,
298,
10369,
15522,
22592,
18,
3140,
2685,
288,
291,
14,
5586,
459,
21223,
418,
275,
291,
423,
27179,
63,
21223,
63,
2232,
398,
291,
423,
6352,
63,
5586,
275,
1052,
339,
347,
485,
27179,
63,
21223,
63,
2232,
8,
277,
12,
2070
] |
[
8972,
8500,
367,
675,
543,
282,
6001,
11666,
7132,
18573,
1041,
199,
199,
646,
747,
199,
646,
295,
199,
646,
4673,
465,
485,
4653,
199,
646,
984,
199,
646,
900,
199,
646,
5796,
199,
199,
504,
13397,
423,
1850,
5819,
492,
7116,
12,
664,
63,
10824,
12,
664,
63,
2671,
63,
5425,
12,
302,
475,
66,
12,
663,
12,
22287,
12,
2494,
20555,
3697,
199,
199,
3,
485,
578,
363,
493,
363,
1095,
365,
1202,
701,
27722,
720,
912,
370,
1852,
199,
3,
3679,
1263,
6203,
12396,
687,
984,
14,
3112,
1314,
787,
440,
199,
3,
2575,
3679,
3792,
14,
221,
961,
365,
370,
1736,
6818,
2018,
1159,
2173,
723,
75,
199,
3,
402,
16306,
314,
14210,
2884,
436,
1808,
282,
3847,
1788,
199,
3,
367,
652,
315,
984,
14,
3112,
14,
199,
3,
199,
3,
27722,
720,
912,
15735,
3746,
984,
14,
3112,
15871,
2107,
4036,
900,
652,
7858,
14,
982,
376,
4223,
199,
3,
4493,
314,
1453,
2082,
701,
14043,
747,
14,
8563,
1062,
2066,
314,
2163,
900,
199,
3,
27722,
720,
912,
7858,
12,
652,
911,
440,
506,
7688,
370,
2342,
1263,
6203,
1314,
787,
199,
3,
440,
3679,
3792,
12,
2952,
314,
1453,
2082,
365,
440,
314,
2011,
465,
1380,
314,
199,
3,
859,
1990,
1642,
8439,
14,
221,
27722,
720,
912,
911,
2066,
6835,
590,
406,
1285,
314,
570,
965,
199,
3,
298,
2489,
401,
436,
11023,
323,
314,
12842,
15,
264,
13,
1628,
3414,
14,
199,
3,
1666,
12052,
327,
29702,
14,
199,
3,
2104,
642,
18092,
370,
1172,
282,
477,
2946,
12224,
402,
3182,
12,
642,
859,
199,
3,
4839,
370,
506,
8439,
465,
14670,
465,
3962,
12,
2544,
314,
1145,
965,
8298,
22044,
199,
3,
370,
1570,
314,
6449,
2082,
14,
199,
63,
578,
363,
493,
363,
1095,
275,
747,
14,
9458,
342,
421,
199,
533,
5870,
5061,
8,
785,
304,
272,
408,
5061,
1300,
1021,
1314,
2599,
13,
954,
729,
11562,
3102,
367,
6040,
9245,
1041,
339,
10414,
275,
488,
272,
408,
33,
520,
533,
1705,
12106,
665,
23438,
14,
1412,
14,
87,
681,
5610,
14,
12106,
30,
3559,
9987,
13397,
14,
3908,
1041,
339,
347,
636,
826,
721,
277,
12,
10414,
304,
267,
291,
14,
5610,
275,
10414,
339,
347,
23421,
8,
277,
304,
267,
408,
7099,
642,
909,
465,
282,
334,
3029,
13,
2775,
9,
11647,
641,
314,
10414,
1041,
267,
367,
3623,
315,
291,
14,
5610,
14,
17301,
26,
288,
327,
4804,
5355,
291,
14,
928,
12,
291,
14,
2224,
12,
5423,
14,
340,
3451,
14,
288,
1083,
275,
2519,
8,
277,
12,
3623,
12,
488,
9,
288,
340,
1083,
365,
440,
488,
26,
355,
291,
14,
5610,
14,
10108,
8,
2775,
12,
1083,
9,
339,
347,
625,
10108,
8,
277,
304,
267,
408,
27419,
642,
909,
465,
282,
11647,
641,
314,
10414,
1041,
267,
367,
3623,
315,
291,
14,
5610,
14,
17301,
26,
288,
327,
15254,
456,
5355,
291,
14,
928,
12,
291,
14,
2224,
12,
5423,
14,
340,
3451,
14,
288,
1083,
275,
2519,
8,
277,
12,
3623,
12,
488,
9,
288,
340,
1083,
365,
440,
488,
26,
355,
291,
14,
5610,
14,
25592,
8,
2775,
12,
1083,
9,
4388,
199,
533,
18288,
2461,
8,
785,
304,
272,
408,
7099,
10414,
9245,
334,
460,
19946,
9,
367,
2656,
10166,
14,
339,
2047,
883,
2811,
4052,
10166,
2195,
4223,
1212,
1597,
561,
367,
12,
436,
4052,
652,
1630,
272,
1380,
652,
23192,
10166,
12,
701,
24662,
520,
962,
1705,
11274,
2461,
14,
5586,
3559,
272,
282,
1211,
402,
469,
4653,
536,
26,
3233,
93,
6342,
14,
710,
849,
663,
365,
447,
398,
8297,
275,
791,
29190,
356,
291,
14,
5610,
14,
2224,
12,
490,
283,
7864,
40,
2160,
356,
291,
14,
2479,
63,
7864,
40,
2160,
12,
490,
283,
7864,
22592,
17,
356,
291,
14,
5610,
14,
20631,
1893,
12,
673,
789,
339,
710,
520,
1532,
1705,
11274,
2461,
14,
2479,
63,
7864,
40,
2160,
1040,
1083,
4882,
272,
520,
1532,
1705,
5610,
14,
10506,
342,
28,
23438,
14,
1412,
14,
87,
681,
5610,
14,
12106,
14,
10506,
8637,
272,
340,
314,
2112,
365,
11128,
1759,
12,
1325,
272,
520,
1532,
1705,
5610,
14,
2224,
342,
28,
23438,
14,
1412,
14,
87,
681,
5610,
14,
12106,
14,
2224,
8637,
272,
340,
314,
2112,
365,
10102,
370,
282,
377,
2099,
14,
961,
365,
2952,
13074,
4353,
272,
19680,
221,
7169,
370,
3222,
428,
13454,
2160,
370,
11167,
10061,
1380,
314,
922,
27811,
3062,
14,
339,
7949,
352,
2867,
370,
1050,
10166,
1314,
787,
440,
2808,
641,
4036,
4298,
14,
710,
272,
520,
533,
1705,
11274,
2461,
64,
911,
3686,
2552,
4915,
687,
19595,
370,
2274,
272,
8297,
367,
5809,
10166,
14,
272,
408,
339,
8297,
275,
1052,
272,
408,
33,
2341,
687,
4673,
1561,
334,
69,
14,
71,
14,
283,
29190,
358,
370,
8297,
334,
69,
14,
71,
14,
10414,
14,
2224,
10477,
339,
10166,
275,
1052,
272,
408,
33,
2341,
687,
4673,
5579,
370,
1561,
1041,
339,
367,
1022,
12,
373,
315,
6802,
1547,
4653,
680,
1744,
837,
267,
340,
1022,
14,
2460,
360,
7864,
358,
436,
440,
1022,
14,
2460,
360,
7864,
25865,
288,
10166,
59,
86,
61,
275,
1022,
272,
2150,
1022,
12,
373,
339,
347,
636,
826,
721,
277,
12,
10414,
304,
267,
291,
14,
5610,
275,
10414,
267,
327,
2494,
849,
8297,
267,
291,
14,
5586,
275,
791,
29190,
356,
291,
14,
5610,
14,
2224,
12,
586,
283,
7864,
40,
2160,
356,
291,
14,
2479,
63,
7864,
40,
2160,
12,
586,
283,
7864,
22592,
17,
356,
291,
14,
5610,
14,
20631,
1893,
12,
586,
789,
398,
340,
984,
14,
3246,
1491,
20,
61,
508,
283,
6138,
356,
288,
2150,
291,
14,
5586,
459,
7864,
22592,
17,
418,
288,
291,
14,
5586,
459,
7864,
22592,
18,
418,
275,
291,
14,
5610,
14,
20631,
1893,
288,
291,
14,
5610,
14,
793,
480,
7864,
22592,
17,
3913,
506,
663,
641,
314,
1603,
6849,
4298,
14,
298,
586,
298,
10369,
15522,
22592,
18,
3140,
2685,
288,
291,
14,
5586,
459,
21223,
418,
275,
291,
423,
27179,
63,
21223,
63,
2232,
398,
291,
423,
6352,
63,
5586,
275,
1052,
339,
347,
485,
27179,
63,
21223,
63,
2232,
8,
277,
12,
2070,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Tatsh-ansible/ansible
|
lib/ansible/modules/net_tools/omapi_host.py
|
9
|
11915
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Loic Blot <loic.blot@unix-experience.fr>
# Sponsored by Infopro Digital. http://www.infopro-digital.com/
# Sponsored by E.T.A.I. http://www.etai.fr/
#
# 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.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: omapi_host
short_description: Setup OMAPI hosts.
description:
- Create, update and remove OMAPI hosts into compatible DHCPd servers.
version_added: "2.3"
requirements:
- pypureomapi
author: "Loic Blot (@nerzhul)"
options:
state:
description:
- Create or remove OMAPI host.
required: true
choices: ['present', 'absent']
name:
description:
- Sets the host lease hostname (mandatory if state=present).
default: None
host:
description:
- Sets OMAPI server host to interact with.
default: localhost
port:
description:
- Sets the OMAPI server port to interact with.
default: 7911
key_name:
description:
- Sets the TSIG key name for authenticating against OMAPI server.
required: true
key:
description:
- Sets the TSIG key content for authenticating against OMAPI server.
required: true
macaddr:
description:
- Sets the lease host MAC address.
required: true
ip:
description:
- Sets the lease host IP address.
required: false
default: None
statements:
description:
- Attach a list of OMAPI DHCP statements with host lease (without ending semicolon).
required: false
default: []
ddns:
description:
- Enable dynamic DNS updates for this host.
required: false
default: false
'''
EXAMPLES = '''
- name: Remove a host using OMAPI
omapi_host:
key_name: "defomapi"
key: "+bFQtBCta6j2vWkjPkNFtgA=="
host: "10.1.1.1"
macaddr: "00:66:ab:dd:11:44"
state: absent
- name: Add a host using OMAPI
omapi_host:
key_name: "defomapi"
key: "+bFQtBCta6j2vWkjPkNFtgA=="
host: "10.98.4.55"
macaddr: "44:dd:ab:dd:11:44"
name: "server01"
ip: "192.168.88.99"
ddns: yes
statements:
- 'filename "pxelinux.0"'
- 'next-server 1.1.1.1'
state: present
'''
RETURN = '''
changed:
description: If module has modified a host
returned: success
type: string
lease:
description: dictionary containing host information
returned: success
type: complex
contains:
ip-address:
description: IP address, if there is.
returned: success
type: string
sample: '192.168.1.5'
hardware-address:
description: MAC address
returned: success
type: string
sample: '00:11:22:33:44:55'
hardware-type:
description: hardware type, generally '1'
returned: success
type: int
sample: 1
name:
description: hostname
returned: success
type: string
sample: 'mydesktop'
'''
import binascii
import socket
import struct
import traceback
try:
from pypureomapi import Omapi, OmapiMessage, OmapiError, OmapiErrorNotFound
from pypureomapi import pack_ip, unpack_ip, pack_mac, unpack_mac
from pypureomapi import OMAPI_OP_STATUS, OMAPI_OP_UPDATE
pureomapi_found = True
except ImportError:
pureomapi_found = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native
class OmapiHostManager:
def __init__(self, module):
self.module = module
self.omapi = None
self.connect()
def connect(self):
try:
self.omapi = Omapi(self.module.params['host'], self.module.params['port'], self.module.params['key_name'],
self.module.params['key'])
except binascii.Error:
self.module.fail_json(msg="Unable to open OMAPI connection. 'key' is not a valid base64 key.")
except OmapiError as e:
self.module.fail_json(msg="Unable to open OMAPI connection. Ensure 'host', 'port', 'key' and 'key_name' "
"are valid. Exception was: %s" % to_native(e))
except socket.error as e:
self.module.fail_json(msg="Unable to connect to OMAPI server: %s" % to_native(e))
def get_host(self, macaddr):
msg = OmapiMessage.open(to_bytes("host", errors='surrogate_or_strict'))
msg.obj.append((to_bytes("hardware-address", errors='surrogate_or_strict'), pack_mac(macaddr)))
msg.obj.append((to_bytes("hardware-type", errors='surrogate_or_strict'), struct.pack("!I", 1)))
response = self.omapi.query_server(msg)
if response.opcode != OMAPI_OP_UPDATE:
return None
return response
@staticmethod
def unpack_facts(obj):
result = dict(obj)
if 'hardware-address' in result:
result['hardware-address'] = unpack_mac(result['hardware-address'])
if 'ip-address' in result:
result['ip-address'] = unpack_ip(result['ip-address'])
if 'hardware-type' in result:
result['hardware-type'] = struct.unpack("!I", result['hardware-type'])
return result
def setup_host(self):
if self.module.params['hostname'] is None or len(self.module.params['hostname']) == 0:
self.module.fail_json(msg="name attribute could not be empty when adding or modifying host.")
msg = None
host_response = self.get_host(self.module.params['macaddr'])
# If host was not found using macaddr, add create message
if host_response is None:
msg = OmapiMessage.open(to_bytes('host', errors='surrogate_or_strict'))
msg.message.append(('create', struct.pack('!I', 1)))
msg.message.append(('exclusive', struct.pack('!I', 1)))
msg.obj.append(('hardware-address', pack_mac(self.module.params['macaddr'])))
msg.obj.append(('hardware-type', struct.pack('!I', 1)))
msg.obj.append(('name', self.module.params['hostname']))
if self.module.params['ip'] is not None:
msg.obj.append((to_bytes("ip-address", errors='surrogate_or_strict'), pack_ip(self.module.params['ip'])))
stmt_join = ""
if self.module.params['ddns']:
stmt_join += 'ddns-hostname "{0}"; '.format(self.module.params['hostname'])
try:
if len(self.module.params['statements']) > 0:
stmt_join += "; ".join(self.module.params['statements'])
stmt_join += "; "
except TypeError as e:
self.module.fail_json(msg="Invalid statements found: %s" % to_native(e),
exception=traceback.format_exc())
if len(stmt_join) > 0:
msg.obj.append(('statements', stmt_join))
try:
response = self.omapi.query_server(msg)
if response.opcode != OMAPI_OP_UPDATE:
self.module.fail_json(msg="Failed to add host, ensure authentication and host parameters "
"are valid.")
self.module.exit_json(changed=True, lease=self.unpack_facts(response.obj))
except OmapiError as e:
self.module.fail_json(msg="OMAPI error: %s" % to_native(e), exception=traceback.format_exc())
# Forge update message
else:
response_obj = self.unpack_facts(host_response.obj)
fields_to_update = {}
if to_bytes('ip-address', errors='surrogate_or_strict') not in response_obj or \
unpack_ip(response_obj[to_bytes('ip-address', errors='surrogate_or_strict')]) != self.module.params['ip']:
fields_to_update['ip-address'] = pack_ip(self.module.params['ip'])
# Name cannot be changed
if 'name' not in response_obj or response_obj['name'] != self.module.params['hostname']:
self.module.fail_json(msg="Changing hostname is not supported. Old was %s, new is %s. "
"Please delete host and add new." %
(response_obj['name'], self.module.params['hostname']))
"""
# It seems statements are not returned by OMAPI, then we cannot modify them at this moment.
if 'statements' not in response_obj and len(self.module.params['statements']) > 0 or \
response_obj['statements'] != self.module.params['statements']:
with open('/tmp/omapi', 'w') as fb:
for (k,v) in iteritems(response_obj):
fb.writelines('statements: %s %s\n' % (k, v))
"""
if len(fields_to_update) == 0:
self.module.exit_json(changed=False, lease=response_obj)
else:
msg = OmapiMessage.update(host_response.handle)
msg.update_object(fields_to_update)
try:
response = self.omapi.query_server(msg)
if response.opcode != OMAPI_OP_STATUS:
self.module.fail_json(msg="Failed to modify host, ensure authentication and host parameters "
"are valid.")
self.module.exit_json(changed=True)
except OmapiError as e:
self.module.fail_json(msg="OMAPI error: %s" % to_native(e), exception=traceback.format_exc())
def remove_host(self):
try:
self.omapi.del_host(self.module.params['macaddr'])
self.module.exit_json(changed=True)
except OmapiErrorNotFound:
self.module.exit_json()
except OmapiError as e:
self.module.fail_json(msg="OMAPI error: %s" % to_native(e), exception=traceback.format_exc())
def main():
module = AnsibleModule(
argument_spec=dict(
state=dict(required=True, type='str', choices=['present', 'absent']),
host=dict(type='str', default="localhost"),
port=dict(type='int', default=7911),
key_name=dict(required=True, type='str', default=None),
key=dict(required=True, type='str', default=None, no_log=True),
macaddr=dict(required=True, type='str', default=None),
hostname=dict(type='str', default=None, aliases=['name']),
ip=dict(type='str', default=None),
ddns=dict(type='bool', default=False),
statements=dict(type='list', default=[])
),
supports_check_mode=False
)
if not pureomapi_found:
module.fail_json(msg="pypureomapi library is required by this module.")
if module.params['key'] is None or len(module.params["key"]) == 0:
module.fail_json(msg="'key' parameter cannot be empty.")
if module.params['key_name'] is None or len(module.params["key_name"]) == 0:
module.fail_json(msg="'key_name' parameter cannot be empty.")
host_manager = OmapiHostManager(module)
try:
if module.params['state'] == 'present':
host_manager.setup_host()
elif module.params['state'] == 'absent':
host_manager.remove_host()
except ValueError as e:
module.fail_json(msg="OMAPI input value error: %s" % to_native(e), exception=traceback.format_exc())
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
7800,
12,
3835,
530,
699,
1653,
665,
320,
530,
14,
66,
1653,
32,
11864,
13,
476,
24242,
14,
4391,
30,
199,
3,
428,
678,
1152,
581,
701,
1010,
70,
11340,
29979,
14,
1455,
921,
1544,
14,
4904,
11340,
13,
25888,
14,
957,
15,
199,
3,
428,
678,
1152,
581,
701,
662,
14,
52,
14,
33,
14,
41,
14,
1455,
921,
1544,
14,
1841,
73,
14,
4391,
15,
199,
3,
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,
16,
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,
312,
391,
1038,
63,
1102,
199,
199,
3612,
63,
1802,
26,
12439,
593,
45,
3735,
7057,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
2813,
593,
45,
3735,
7057,
1901,
9025,
26821,
68,
8037,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
7538,
26,
523,
446,
1134,
5115,
79,
391,
1038,
199,
2502,
26,
298,
2041,
530,
699,
1653,
8593,
1372,
3951,
348,
2924,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
2790,
503,
2813,
593,
45,
3735,
1591,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
536,
26,
267,
1369,
26,
288,
446,
10729,
314,
1591,
31199,
6246,
334,
19900,
340,
1174,
29,
1881,
680,
267,
849,
26,
488,
272,
1591,
26,
267,
1369,
26,
288,
446,
10729,
593,
45,
3735,
1654,
1591,
370,
17232,
543,
14,
267,
849,
26,
11667,
272,
1844,
26,
267,
1369,
26,
288,
446,
10729,
314,
593,
45,
3735,
1654,
1844,
370,
17232,
543,
14,
267,
849,
26,
13734,
845,
272,
790,
63,
354,
26,
267,
1369,
26,
288,
446,
10729,
314,
377,
7864,
790,
536,
367,
28532,
1958,
6169,
593,
45,
3735,
1654,
14,
267,
1415,
26,
2549,
272,
790,
26,
267,
1369,
26,
288,
446,
10729,
314,
377,
7864,
790,
1564,
367,
28532,
1958,
6169,
593,
45,
3735,
1654,
14,
267,
1415,
26,
2549,
272,
4497,
2697,
26,
267,
1369,
26,
288,
446,
10729,
314,
31199,
1591,
13347,
2287,
14,
267,
1415,
26,
2549,
272,
3384,
26,
267,
1369,
26,
288,
446,
10729,
314,
31199,
1591,
3531,
2287,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
9834,
26,
267,
1369,
26,
288,
446,
21328,
282,
769,
402,
593,
45,
3735,
26821,
9834,
543,
1591,
31199,
334,
7395,
13401,
18734,
12167,
680,
267,
1415,
26,
3055,
267,
849,
26,
942,
272,
366,
5797,
26,
267,
1369,
26,
288,
446,
12030,
8336,
10237,
7029,
367,
642,
1591,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
199,
199,
2344,
199,
8918,
275,
1449,
199,
13,
536,
26,
5852,
282,
1591,
1808,
593,
45,
3735,
523,
312,
391,
1038,
63,
1102,
26,
272,
790,
63,
354,
26,
298,
318,
79,
391,
1038,
2,
272,
790,
26,
7210,
66,
38,
4238,
6265,
502,
22,
74,
18,
86,
55,
25775,
29619,
19749,
84,
14993,
11800,
272,
1591,
26,
298,
709,
14,
17,
14,
17,
14,
17,
2,
272,
4497,
2697,
26,
298,
383,
26,
1272,
26,
371,
26,
617,
26,
845,
26,
1602,
2,
272,
1174,
26,
9552,
199,
199,
13,
536,
26,
2654,
282,
1591,
1808,
593,
45,
3735,
523,
312,
391,
1038,
63,
1102,
26,
272,
790,
63,
354,
26,
298,
318,
79,
391,
1038,
2,
272,
790,
26,
7210,
66,
38,
4238,
6265,
502,
22,
74,
18,
86,
55,
25775,
29619,
19749,
84,
14993,
11800,
272,
1591,
26,
298,
709,
14,
2905,
14,
20,
14,
1229,
2,
272,
4497,
2697,
26,
298,
1602,
26,
617,
26,
371,
26,
617,
26,
845,
26,
1602,
2,
272,
536,
26,
298,
1000,
614,
2,
272,
3384,
26,
298,
5756,
14,
6568,
14,
1299,
14,
1020,
2,
272,
366,
5797,
26,
9456,
272,
9834,
26,
489,
446,
283,
1501,
298,
5326,
352,
7226,
14,
16,
4507,
489,
446,
283,
2184,
13,
1000,
413,
14,
17,
14,
17,
14,
17,
7,
272,
1174,
26,
3451,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2489,
26,
272,
1369,
26,
982,
859,
965,
6042,
282,
1591,
272,
2138,
26,
3182,
272,
730,
26,
1059,
199,
1756,
26,
272,
1369,
26,
2600,
3035,
1591,
2556,
272,
2138,
26,
3182,
272,
730,
26,
6114,
272,
3509,
26,
267,
3384,
13,
1562,
26,
288,
1369,
26,
3531,
2287,
12,
340,
2337,
365,
14,
288,
2138,
26,
3182,
288,
730,
26,
1059,
288,
2690,
26,
283,
5756,
14,
6568,
14,
17,
14,
21,
7,
267,
14991,
13,
1562,
26,
288,
1369,
26,
13347,
2287,
288,
2138,
26,
3182,
288,
730,
26,
1059,
288,
2690,
26,
283,
383,
26,
845,
26,
1081,
26,
1153,
26,
1602,
26,
1229,
7,
267,
14991,
13,
466,
26,
288,
1369,
26,
14991,
730,
12,
16711,
283,
17,
7,
288,
2138,
26,
3182,
288,
730,
26,
1109,
288,
2690,
26,
413,
267,
536,
26,
288,
1369,
26,
6246,
288,
2138,
26,
3182,
288,
730,
26,
1059,
288,
2690,
26,
283,
1662,
14487,
7,
199,
2344,
199,
199,
646,
14755,
199,
646,
2838,
199,
646,
2702,
199,
646,
5190,
199,
199,
893,
26,
272,
687,
1134,
5115,
79,
391,
1038,
492,
593,
391,
1038,
12,
593,
391,
1038,
2209,
12,
593,
391,
1038,
547,
12,
593,
391,
1038,
547,
4667,
272,
687,
1134,
5115,
79,
391,
1038,
492,
1706,
63,
711,
12,
7787,
63,
711,
12,
1706,
63,
3088,
12,
7787,
63,
3088,
272,
687,
1134,
5115,
79,
391,
1038,
492,
593,
45,
3735,
63,
1938,
63,
6305,
12,
593,
45,
3735,
63,
1938,
63,
10383,
272,
15111,
79,
391,
1038,
63,
4214,
275,
715,
199,
2590,
3545,
26,
272,
15111,
79,
391,
1038,
63,
4214,
275,
756,
199,
199,
504
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
7800,
12,
3835,
530,
699,
1653,
665,
320,
530,
14,
66,
1653,
32,
11864,
13,
476,
24242,
14,
4391,
30,
199,
3,
428,
678,
1152,
581,
701,
1010,
70,
11340,
29979,
14,
1455,
921,
1544,
14,
4904,
11340,
13,
25888,
14,
957,
15,
199,
3,
428,
678,
1152,
581,
701,
662,
14,
52,
14,
33,
14,
41,
14,
1455,
921,
1544,
14,
1841,
73,
14,
4391,
15,
199,
3,
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,
16,
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,
312,
391,
1038,
63,
1102,
199,
199,
3612,
63,
1802,
26,
12439,
593,
45,
3735,
7057,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
2813,
593,
45,
3735,
7057,
1901,
9025,
26821,
68,
8037,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
7538,
26,
523,
446,
1134,
5115,
79,
391,
1038,
199,
2502,
26,
298,
2041,
530,
699,
1653,
8593,
1372,
3951,
348,
2924,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
2790,
503,
2813,
593,
45,
3735,
1591,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
536,
26,
267,
1369,
26,
288,
446,
10729,
314,
1591,
31199,
6246,
334,
19900,
340,
1174,
29,
1881,
680,
267,
849,
26,
488,
272,
1591,
26,
267,
1369,
26,
288,
446,
10729,
593,
45,
3735,
1654,
1591,
370,
17232,
543,
14,
267,
849,
26,
11667,
272,
1844,
26,
267,
1369,
26,
288,
446,
10729,
314,
593,
45,
3735,
1654,
1844,
370,
17232,
543,
14,
267,
849,
26,
13734,
845,
272,
790,
63,
354,
26,
267,
1369,
26,
288,
446,
10729,
314,
377,
7864,
790,
536,
367,
28532,
1958,
6169,
593,
45,
3735,
1654,
14,
267,
1415,
26,
2549,
272,
790,
26,
267,
1369,
26,
288,
446,
10729,
314,
377,
7864,
790,
1564,
367,
28532,
1958,
6169,
593,
45,
3735,
1654,
14,
267,
1415,
26,
2549,
272,
4497,
2697,
26,
267,
1369,
26,
288,
446,
10729,
314,
31199,
1591,
13347,
2287,
14,
267,
1415,
26,
2549,
272,
3384,
26,
267,
1369,
26,
288,
446,
10729,
314,
31199,
1591,
3531,
2287,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
9834,
26,
267,
1369,
26,
288,
446,
21328,
282,
769,
402,
593,
45,
3735,
26821,
9834,
543,
1591,
31199,
334,
7395,
13401,
18734,
12167,
680,
267,
1415,
26,
3055,
267,
849,
26,
942,
272,
366,
5797,
26,
267,
1369,
26,
288,
446,
12030,
8336,
10237,
7029,
367,
642,
1591,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
199,
199,
2344,
199,
8918,
275,
1449,
199,
13,
536,
26,
5852,
282,
1591,
1808,
593,
45,
3735,
523,
312,
391,
1038,
63,
1102,
26,
272,
790,
63,
354,
26,
298,
318,
79,
391,
1038,
2,
272,
790,
26,
7210,
66,
38,
4238,
6265,
502,
22,
74,
18,
86,
55,
25775,
29619,
19749,
84,
14993,
11800,
272,
1591,
26,
298,
709,
14,
17,
14,
17,
14,
17,
2,
272,
4497,
2697,
26,
298,
383,
26,
1272,
26,
371,
26,
617,
26,
845,
26,
1602,
2,
272,
1174,
26,
9552,
199,
199,
13,
536,
26,
2654,
282,
1591,
1808,
593,
45,
3735,
523,
312,
391,
1038,
63,
1102,
26,
272,
790,
63,
354,
26,
298,
318,
79,
391,
1038,
2,
272,
790,
26,
7210,
66,
38,
4238,
6265,
502,
22,
74,
18,
86,
55,
25775,
29619,
19749,
84,
14993,
11800,
272,
1591,
26,
298,
709,
14,
2905,
14,
20,
14,
1229,
2,
272,
4497,
2697,
26,
298,
1602,
26,
617,
26,
371,
26,
617,
26,
845,
26,
1602,
2,
272,
536,
26,
298,
1000,
614,
2,
272,
3384,
26,
298,
5756,
14,
6568,
14,
1299,
14,
1020,
2,
272,
366,
5797,
26,
9456,
272,
9834,
26,
489,
446,
283,
1501,
298,
5326,
352,
7226,
14,
16,
4507,
489,
446,
283,
2184,
13,
1000,
413,
14,
17,
14,
17,
14,
17,
7,
272,
1174,
26,
3451,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2489,
26,
272,
1369,
26,
982,
859,
965,
6042,
282,
1591,
272,
2138,
26,
3182,
272,
730,
26,
1059,
199,
1756,
26,
272,
1369,
26,
2600,
3035,
1591,
2556,
272,
2138,
26,
3182,
272,
730,
26,
6114,
272,
3509,
26,
267,
3384,
13,
1562,
26,
288,
1369,
26,
3531,
2287,
12,
340,
2337,
365,
14,
288,
2138,
26,
3182,
288,
730,
26,
1059,
288,
2690,
26,
283,
5756,
14,
6568,
14,
17,
14,
21,
7,
267,
14991,
13,
1562,
26,
288,
1369,
26,
13347,
2287,
288,
2138,
26,
3182,
288,
730,
26,
1059,
288,
2690,
26,
283,
383,
26,
845,
26,
1081,
26,
1153,
26,
1602,
26,
1229,
7,
267,
14991,
13,
466,
26,
288,
1369,
26,
14991,
730,
12,
16711,
283,
17,
7,
288,
2138,
26,
3182,
288,
730,
26,
1109,
288,
2690,
26,
413,
267,
536,
26,
288,
1369,
26,
6246,
288,
2138,
26,
3182,
288,
730,
26,
1059,
288,
2690,
26,
283,
1662,
14487,
7,
199,
2344,
199,
199,
646,
14755,
199,
646,
2838,
199,
646,
2702,
199,
646,
5190,
199,
199,
893,
26,
272,
687,
1134,
5115,
79,
391,
1038,
492,
593,
391,
1038,
12,
593,
391,
1038,
2209,
12,
593,
391,
1038,
547,
12,
593,
391,
1038,
547,
4667,
272,
687,
1134,
5115,
79,
391,
1038,
492,
1706,
63,
711,
12,
7787,
63,
711,
12,
1706,
63,
3088,
12,
7787,
63,
3088,
272,
687,
1134,
5115,
79,
391,
1038,
492,
593,
45,
3735,
63,
1938,
63,
6305,
12,
593,
45,
3735,
63,
1938,
63,
10383,
272,
15111,
79,
391,
1038,
63,
4214,
275,
715,
199,
2590,
3545,
26,
272,
15111,
79,
391,
1038,
63,
4214,
275,
756,
199,
199,
504,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nwalters512/the-blue-alliance
|
tests/test_team_manipulator.py
|
8
|
2481
|
import unittest2
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from helpers.team_manipulator import TeamManipulator
from models.team import Team
class TestTeamManipulator(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.old_team = Team(
id="frc177",
team_number=177,
rookie_year=1996,
first_tpid=61771,
first_tpid_year=2012,
)
self.new_team = Team(
id="frc177",
team_number=177,
rookie_year=1995,
website="http://www.bobcatrobotics.org",
)
def tearDown(self):
self.testbed.deactivate()
def assertMergedTeam(self, team):
self.assertOldTeam(team)
self.assertEqual(team.website, "http://www.bobcatrobotics.org")
self.assertEqual(team.rookie_year, 1995)
def assertOldTeam(self, team):
self.assertEqual(team.first_tpid, 61771)
self.assertEqual(team.first_tpid_year, 2012)
self.assertEqual(team.key_name, "frc177")
self.assertEqual(team.team_number, 177)
def test_createOrUpdate(self):
TeamManipulator.createOrUpdate(self.old_team)
self.assertOldTeam(Team.get_by_id("frc177"))
TeamManipulator.createOrUpdate(self.new_team)
self.assertMergedTeam(Team.get_by_id("frc177"))
def test_findOrSpawn(self):
self.old_team.put()
self.assertMergedTeam(TeamManipulator.findOrSpawn(self.new_team))
def test_updateMerge(self):
self.assertMergedTeam(TeamManipulator.updateMerge(self.new_team, self.old_team))
def test_create_lots_of_teams(self):
number = 500
teams = [Team(
id="frc%s" % team_number,
team_number=team_number)
for team_number in range(number)]
TeamManipulator.createOrUpdate(teams)
team = Team.get_by_id("frc177")
self.assertEqual(team.key_name, "frc177")
self.assertEqual(team.team_number, 177)
team = Team.get_by_id("frc%s" % (number - 1))
self.assertEqual(team.key_name, "frc%s" % (number - 1))
self.assertEqual(team.team_number, number - 1)
|
mit
|
[
646,
2882,
18,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
199,
199,
504,
10897,
14,
5969,
63,
29798,
6109,
492,
11682,
2395,
711,
6109,
199,
504,
1709,
14,
5969,
492,
11682,
421,
199,
533,
1379,
13126,
2395,
711,
6109,
8,
2796,
18,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
267,
291,
14,
396,
6123,
14,
8222,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
11450,
63,
86,
19,
63,
5811,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
25835,
63,
5811,
342,
267,
23788,
14,
362,
63,
1100,
1252,
3584,
63,
1637,
342,
221,
327,
29861,
666,
687,
1026,
11124,
3382,
2295,
398,
291,
14,
396,
6123,
14,
826,
63,
1765,
1825,
63,
5811,
8,
1231,
63,
515,
628,
2685,
398,
291,
14,
1753,
63,
5969,
275,
11682,
8,
288,
1305,
628,
32309,
8881,
401,
288,
8099,
63,
1955,
29,
8881,
12,
288,
882,
2887,
63,
3403,
29,
7155,
22,
12,
288,
1642,
63,
683,
344,
29,
2976,
19371,
12,
288,
1642,
63,
683,
344,
63,
3403,
29,
7409,
12,
267,
776,
398,
291,
14,
1222,
63,
5969,
275,
11682,
8,
288,
1305,
628,
32309,
8881,
401,
288,
8099,
63,
1955,
29,
8881,
12,
288,
882,
2887,
63,
3403,
29,
7155,
21,
12,
288,
10691,
628,
1014,
921,
1544,
14,
7913,
3385,
293,
656,
7769,
14,
1308,
401,
267,
776,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
396,
6123,
14,
24891,
342,
339,
347,
702,
16797,
3046,
13126,
8,
277,
12,
8099,
304,
267,
291,
14,
479,
16411,
13126,
8,
5969,
9,
267,
291,
14,
629,
8,
5969,
14,
7360,
12,
298,
1014,
921,
1544,
14,
7913,
3385,
293,
656,
7769,
14,
1308,
531,
267,
291,
14,
629,
8,
5969,
14,
293,
2887,
63,
3403,
12,
9013,
21,
9,
339,
347,
702,
16411,
13126,
8,
277,
12,
8099,
304,
267,
291,
14,
629,
8,
5969,
14,
2246,
63,
683,
344,
12,
1227,
8881,
17,
9,
267,
291,
14,
629,
8,
5969,
14,
2246,
63,
683,
344,
63,
3403,
12,
6029,
9,
267,
291,
14,
629,
8,
5969,
14,
498,
63,
354,
12,
298,
32309,
8881,
531,
267,
291,
14,
629,
8,
5969,
14,
5969,
63,
1955,
12,
413,
1138,
9,
339,
347,
511,
63,
981,
2844,
4152,
8,
277,
304,
267,
11682,
2395,
711,
6109,
14,
981,
2844,
4152,
8,
277,
14,
1753,
63,
5969,
9,
267,
291,
14,
479,
16411,
13126,
8,
13126,
14,
362,
63,
991,
63,
344,
480,
32309,
8881,
2237,
267,
11682,
2395,
711,
6109,
14,
981,
2844,
4152,
8,
277,
14,
1222,
63,
5969,
9,
267,
291,
14,
479,
16797,
3046,
13126,
8,
13126,
14,
362,
63,
991,
63,
344,
480,
32309,
8881,
2237,
339,
347,
511,
63,
1623,
2844,
12739,
3501,
8,
277,
304,
267,
291,
14,
1753,
63,
5969,
14,
524,
342,
267,
291,
14,
479,
16797,
3046,
13126,
8,
13126,
2395,
711,
6109,
14,
1623,
2844,
12739,
3501,
8,
277,
14,
1222,
63,
5969,
430,
339,
347,
511,
63,
873,
11359,
8,
277,
304,
267,
291,
14,
479,
16797,
3046,
13126,
8,
13126,
2395,
711,
6109,
14,
873,
11359,
8,
277,
14,
1222,
63,
5969,
12,
291,
14,
1753,
63,
5969,
430,
339,
347,
511,
63,
981,
63,
4555,
63,
1618,
63,
19048,
8,
277,
304,
267,
1329,
275,
6891,
267,
25823,
275,
359,
13126,
8,
288,
1305,
628,
32309,
5,
83,
2,
450,
8099,
63,
1955,
12,
288,
8099,
63,
1955,
29,
5969,
63,
1955,
9,
288,
367,
8099,
63,
1955,
315,
1425,
8,
1955,
1874,
267,
11682,
2395,
711,
6109,
14,
981,
2844,
4152,
8,
19048,
9,
398,
8099,
275,
11682,
14,
362,
63,
991,
63,
344,
480,
32309,
8881,
531,
267,
291,
14,
629,
8,
5969,
14,
498,
63,
354,
12,
298,
32309,
8881,
531,
267,
291,
14,
629,
8,
5969,
14,
5969,
63,
1955,
12,
413,
1138,
9,
398,
8099,
275,
11682,
14,
362,
63,
991,
63,
344,
480,
32309,
5,
83,
2,
450,
334,
1955,
446,
413,
430,
267,
291,
14,
629,
8,
5969,
14,
498,
63,
354,
12,
298,
32309,
5,
83,
2,
450,
334,
1955,
446,
413,
430,
267,
291,
14,
629,
8,
5969,
14,
5969,
63,
1955,
12,
1329,
446,
413,
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
] |
[
2882,
18,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
199,
199,
504,
10897,
14,
5969,
63,
29798,
6109,
492,
11682,
2395,
711,
6109,
199,
504,
1709,
14,
5969,
492,
11682,
421,
199,
533,
1379,
13126,
2395,
711,
6109,
8,
2796,
18,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
267,
291,
14,
396,
6123,
14,
8222,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
11450,
63,
86,
19,
63,
5811,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
25835,
63,
5811,
342,
267,
23788,
14,
362,
63,
1100,
1252,
3584,
63,
1637,
342,
221,
327,
29861,
666,
687,
1026,
11124,
3382,
2295,
398,
291,
14,
396,
6123,
14,
826,
63,
1765,
1825,
63,
5811,
8,
1231,
63,
515,
628,
2685,
398,
291,
14,
1753,
63,
5969,
275,
11682,
8,
288,
1305,
628,
32309,
8881,
401,
288,
8099,
63,
1955,
29,
8881,
12,
288,
882,
2887,
63,
3403,
29,
7155,
22,
12,
288,
1642,
63,
683,
344,
29,
2976,
19371,
12,
288,
1642,
63,
683,
344,
63,
3403,
29,
7409,
12,
267,
776,
398,
291,
14,
1222,
63,
5969,
275,
11682,
8,
288,
1305,
628,
32309,
8881,
401,
288,
8099,
63,
1955,
29,
8881,
12,
288,
882,
2887,
63,
3403,
29,
7155,
21,
12,
288,
10691,
628,
1014,
921,
1544,
14,
7913,
3385,
293,
656,
7769,
14,
1308,
401,
267,
776,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
396,
6123,
14,
24891,
342,
339,
347,
702,
16797,
3046,
13126,
8,
277,
12,
8099,
304,
267,
291,
14,
479,
16411,
13126,
8,
5969,
9,
267,
291,
14,
629,
8,
5969,
14,
7360,
12,
298,
1014,
921,
1544,
14,
7913,
3385,
293,
656,
7769,
14,
1308,
531,
267,
291,
14,
629,
8,
5969,
14,
293,
2887,
63,
3403,
12,
9013,
21,
9,
339,
347,
702,
16411,
13126,
8,
277,
12,
8099,
304,
267,
291,
14,
629,
8,
5969,
14,
2246,
63,
683,
344,
12,
1227,
8881,
17,
9,
267,
291,
14,
629,
8,
5969,
14,
2246,
63,
683,
344,
63,
3403,
12,
6029,
9,
267,
291,
14,
629,
8,
5969,
14,
498,
63,
354,
12,
298,
32309,
8881,
531,
267,
291,
14,
629,
8,
5969,
14,
5969,
63,
1955,
12,
413,
1138,
9,
339,
347,
511,
63,
981,
2844,
4152,
8,
277,
304,
267,
11682,
2395,
711,
6109,
14,
981,
2844,
4152,
8,
277,
14,
1753,
63,
5969,
9,
267,
291,
14,
479,
16411,
13126,
8,
13126,
14,
362,
63,
991,
63,
344,
480,
32309,
8881,
2237,
267,
11682,
2395,
711,
6109,
14,
981,
2844,
4152,
8,
277,
14,
1222,
63,
5969,
9,
267,
291,
14,
479,
16797,
3046,
13126,
8,
13126,
14,
362,
63,
991,
63,
344,
480,
32309,
8881,
2237,
339,
347,
511,
63,
1623,
2844,
12739,
3501,
8,
277,
304,
267,
291,
14,
1753,
63,
5969,
14,
524,
342,
267,
291,
14,
479,
16797,
3046,
13126,
8,
13126,
2395,
711,
6109,
14,
1623,
2844,
12739,
3501,
8,
277,
14,
1222,
63,
5969,
430,
339,
347,
511,
63,
873,
11359,
8,
277,
304,
267,
291,
14,
479,
16797,
3046,
13126,
8,
13126,
2395,
711,
6109,
14,
873,
11359,
8,
277,
14,
1222,
63,
5969,
12,
291,
14,
1753,
63,
5969,
430,
339,
347,
511,
63,
981,
63,
4555,
63,
1618,
63,
19048,
8,
277,
304,
267,
1329,
275,
6891,
267,
25823,
275,
359,
13126,
8,
288,
1305,
628,
32309,
5,
83,
2,
450,
8099,
63,
1955,
12,
288,
8099,
63,
1955,
29,
5969,
63,
1955,
9,
288,
367,
8099,
63,
1955,
315,
1425,
8,
1955,
1874,
267,
11682,
2395,
711,
6109,
14,
981,
2844,
4152,
8,
19048,
9,
398,
8099,
275,
11682,
14,
362,
63,
991,
63,
344,
480,
32309,
8881,
531,
267,
291,
14,
629,
8,
5969,
14,
498,
63,
354,
12,
298,
32309,
8881,
531,
267,
291,
14,
629,
8,
5969,
14,
5969,
63,
1955,
12,
413,
1138,
9,
398,
8099,
275,
11682,
14,
362,
63,
991,
63,
344,
480,
32309,
5,
83,
2,
450,
334,
1955,
446,
413,
430,
267,
291,
14,
629,
8,
5969,
14,
498,
63,
354,
12,
298,
32309,
5,
83,
2,
450,
334,
1955,
446,
413,
430,
267,
291,
14,
629,
8,
5969,
14,
5969,
63,
1955,
12,
1329,
446,
413,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sparkprime/helm
|
expansion/schema_validation_test.py
|
2
|
22296
|
# Copyright 2015 The Kubernetes 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.
import os
import unittest
import schema_validation
import yaml
INVALID_PROPERTIES = "Invalid properties for 'template.py'"
def GetFilePath():
"""Find our source and data files."""
return os.path.dirname(os.path.abspath(__file__))
def ReadTestFile(filename):
"""Returns contents of a file from the testdata/ directory."""
full_path = os.path.join(GetFilePath(), '..', 'test', 'schemas', filename)
return open(full_path, 'r').read()
def RawValidate(raw_properties, schema_name, raw_schema):
return ImportsRawValidate(raw_properties, schema_name,
{schema_name: raw_schema})
def ImportsRawValidate(raw_properties, schema_name, import_map):
"""Takes raw properties, calls validate and returns yaml properties."""
properties = yaml.safe_load(raw_properties)
return schema_validation.Validate(properties, schema_name, 'template.py',
import_map)
class SchemaValidationTest(unittest.TestCase):
"""Tests of the schema portion of the template expansion library."""
def testDefaults(self):
schema_name = 'defaults.jinja.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
expected_properties = """
alpha: alpha
one: 1
"""
self.assertEqual(yaml.safe_load(expected_properties),
RawValidate(empty_properties, schema_name, schema))
def testNestedDefaults(self):
schema_name = 'nested_defaults.py.schema'
schema = ReadTestFile(schema_name)
properties = """
zone: us-central1-a
disks:
- name: backup # diskType and sizeGb set by default
- name: cache # sizeGb set by default
diskType: pd-ssd
- name: data # Nothing set by default
diskType: pd-ssd
sizeGb: 150
- name: swap # diskType set by default
sizeGb: 200
"""
expected_properties = """
zone: us-central1-a
disks:
- sizeGb: 100
diskType: pd-standard
name: backup
- sizeGb: 100
diskType: pd-ssd
name: cache
- sizeGb: 150
diskType: pd-ssd
name: data
- sizeGb: 200
diskType: pd-standard
name: swap
"""
self.assertEqual(yaml.safe_load(expected_properties),
RawValidate(properties, schema_name, schema))
def testNestedRefDefaults(self):
schema_name = 'ref_nested_defaults.py.schema'
schema = ReadTestFile(schema_name)
properties = """
zone: us-central1-a
disks:
- name: backup # diskType and sizeGb set by default
- name: cache # sizeGb set by default
diskType: pd-ssd
- name: data # Nothing set by default
diskType: pd-ssd
sizeGb: 150
- name: swap # diskType set by default
sizeGb: 200
"""
expected_properties = """
zone: us-central1-a
disks:
- sizeGb: 100
diskType: pd-standard
name: backup
- sizeGb: 100
diskType: pd-ssd
name: cache
- sizeGb: 150
diskType: pd-ssd
name: data
- sizeGb: 200
diskType: pd-standard
name: swap
"""
self.assertEqual(yaml.safe_load(expected_properties),
RawValidate(properties, schema_name, schema))
def testInvalidDefault(self):
schema_name = 'invalid_default.jinja.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn(INVALID_PROPERTIES, e.message)
self.assertIn("'string' is not of type 'integer' at ['number']",
e.message)
def testRequiredDefault(self):
schema_name = 'required_default.jinja.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
expected_properties = """
name: my_name
"""
self.assertEqual(yaml.safe_load(expected_properties),
RawValidate(empty_properties, schema_name, schema))
def testRequiredDefaultReference(self):
schema_name = 'req_default_ref.py.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn(INVALID_PROPERTIES, e.message)
self.assertIn("'my_name' is not of type 'integer' at ['number']",
e.message)
def testDefaultReference(self):
schema_name = 'default_ref.jinja.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
expected_properties = 'number: 1'
self.assertEqual(yaml.safe_load(expected_properties),
RawValidate(empty_properties, schema_name, schema))
def testMissingQuoteInReference(self):
schema_name = 'missing_quote.py.schema'
schema = ReadTestFile(schema_name)
properties = 'number: 1'
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(2, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("type 'NoneType' is not iterable", e.message)
self.assertIn('around your reference', e.message)
def testRequiredPropertyMissing(self):
schema_name = 'required.jinja.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn(INVALID_PROPERTIES, e.message)
self.assertIn("'name' is a required property", e.errors[0].message)
def testRequiredPropertyValid(self):
schema_name = 'required.jinja.schema'
schema = ReadTestFile(schema_name)
properties = """
name: my-name
"""
self.assertEqual(yaml.safe_load(properties),
RawValidate(properties, schema_name, schema))
def testMultipleErrors(self):
schema_name = 'defaults.py.schema'
schema = ReadTestFile(schema_name)
properties = """
one: not a number
alpha: 12345
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(2, len(e.errors))
self.assertIn(INVALID_PROPERTIES, e.message)
self.assertIn("'not a number' is not of type 'integer' at ['one']",
e.message)
self.assertIn("12345 is not of type 'string' at ['alpha']",
e.message)
def testNumbersValid(self):
schema_name = 'numbers.py.schema'
schema = ReadTestFile(schema_name)
properties = """
minimum0: 0
exclusiveMin0: 1
maximum10: 10
exclusiveMax10: 9
even: 20
odd: 21
"""
self.assertEquals(yaml.safe_load(properties),
RawValidate(properties, schema_name, schema))
def testNumbersInvalid(self):
schema_name = 'numbers.py.schema'
schema = ReadTestFile(schema_name)
properties = """
minimum0: -1
exclusiveMin0: 0
maximum10: 11
exclusiveMax10: 10
even: 21
odd: 20
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(6, len(e.errors))
self.assertIn(INVALID_PROPERTIES, e.message)
self.assertIn("-1 is less than the minimum of 0 at ['minimum0']",
e.message)
self.assertIn(('0 is less than or equal to the minimum of 0'
" at ['exclusiveMin0']"), e.message)
self.assertIn("11 is greater than the maximum of 10 at \
['maximum10']", e.message)
self.assertIn(('10 is greater than or equal to the maximum of 10'
" at ['exclusiveMax10']"), e.message)
self.assertIn("21 is not a multiple of 2 at ['even']", e.message)
self.assertIn("{'multipleOf': 2} is not allowed for 20 at ['odd']",
e.message)
def testReference(self):
schema_name = 'reference.jinja.schema'
schema = ReadTestFile(schema_name)
properties = """
odd: 6
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn('even', e.message)
self.assertIn('is not allowed for 6', e.message)
def testBadSchema(self):
schema_name = 'bad.jinja.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(2, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("u'minimum' is a dependency of u'exclusiveMinimum'",
e.message)
self.assertIn("0 is not of type u'boolean'", e.message)
def testInvalidReference(self):
schema_name = 'invalid_reference.py.schema'
schema = ReadTestFile(schema_name)
properties = 'odd: 1'
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn('Unresolvable JSON pointer', e.message)
def testInvalidReferenceInSchema(self):
schema_name = 'invalid_reference_schema.py.schema'
schema = ReadTestFile(schema_name)
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn('Unresolvable JSON pointer', e.message)
def testMetadata(self):
schema_name = 'metadata.py.schema'
schema = ReadTestFile(schema_name)
properties = """
one: 2
alpha: beta
"""
self.assertEquals(yaml.safe_load(properties),
RawValidate(properties, schema_name, schema))
def testInvalidInput(self):
schema_name = 'schema'
schema = """
info:
title: Invalid Input
properties: invalid
"""
properties = """
one: 2
alpha: beta
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("'invalid' is not of type u'object'", e.message)
def testPattern(self):
schema_name = 'schema'
schema = r"""
properties:
bad-zone:
pattern: \w+-\w+-\w+
zone:
pattern: \w+-\w+-\w+
"""
properties = """
bad-zone: abc
zone: us-central1-a
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn('Invalid properties', e.message)
self.assertIn("'abc' does not match", e.message)
self.assertIn('bad-zone', e.message)
def testUniqueItems(self):
schema_name = 'schema'
schema = """
properties:
bad-list:
type: array
uniqueItems: true
list:
type: array
uniqueItems: true
"""
properties = """
bad-list:
- a
- b
- a
list:
- a
- b
- c
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn('Invalid properties', e.message)
self.assertIn('has non-unique elements', e.message)
self.assertIn('bad-list', e.message)
def testUniqueItemsOnString(self):
schema_name = 'schema'
schema = """
properties:
ok-string:
type: string
uniqueItems: true
string:
type: string
uniqueItems: true
"""
properties = """
ok-string: aaa
string: abc
"""
self.assertEquals(yaml.safe_load(properties),
RawValidate(properties, schema_name, schema))
def testRequiredTopLevel(self):
schema_name = 'schema'
schema = """
info:
title: Invalid Input
required:
- name
"""
properties = """
one: 2
alpha: beta
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn(INVALID_PROPERTIES, e.message)
self.assertIn("'name' is a required property", e.message)
def testEmptySchemaProperties(self):
schema_name = 'schema'
schema = """
info:
title: Empty Input
properties:
"""
properties = """
one: 2
alpha: beta
"""
try:
RawValidate(properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("None is not of type u'object' at [u'properties']",
e.message)
def testNoInput(self):
schema = """
info:
title: No other sections
"""
properties = """
one: 2
alpha: beta
"""
self.assertEquals(yaml.safe_load(properties),
RawValidate(properties, 'schema', schema))
def testEmptySchema(self):
schema = ''
properties = """
one: 2
alpha: beta
"""
self.assertEquals(yaml.safe_load(properties),
RawValidate(properties, 'schema', schema))
def testImportPathSchema(self):
schema = """
imports:
- path: a
- path: path/to/b
name: b
"""
properties = """
one: 2
alpha: beta
"""
import_map = {'schema': schema,
'a': '',
'b': ''}
self.assertEquals(yaml.safe_load(properties),
ImportsRawValidate(properties, 'schema', import_map))
def testImportSchemaMissing(self):
schema = ''
empty_properties = ''
try:
properties = yaml.safe_load(empty_properties)
schema_validation.Validate(properties, 'schema', 'template',
{'wrong_name': schema})
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Could not find schema file 'schema'", e.message)
def testImportsMalformedNotAList(self):
schema_name = 'schema'
schema = """
imports: not-a-list
"""
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("is not of type 'array' at ['imports']", e.message)
def testImportsMalformedMissingPath(self):
schema_name = 'schema'
schema = """
imports:
- name: no_path.yaml
"""
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("'path' is a required property", e.message)
def testImportsMalformedNonunique(self):
schema_name = 'schema'
schema = """
imports:
- path: a.yaml
name: a
- path: a.yaml
name: a
"""
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn('non-unique elements', e.message)
def testImportsMalformedAdditionalProperties(self):
schema_name = 'schema'
schema = """
imports:
- path: a.yaml
gnome: a
"""
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(1, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn('Additional properties are not allowed'
" ('gnome' was unexpected)", e.message)
def testImportAndInputErrors(self):
schema = """
imports:
- path: file
required:
- name
"""
empty_properties = ''
try:
RawValidate(empty_properties, 'schema', schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(2, len(e.errors))
self.assertIn("'file' requested in schema 'schema'", e.message)
self.assertIn("'name' is a required property", e.message)
def testImportAndInputSchemaErrors(self):
schema_name = 'schema'
schema = """
imports: not-a-list
required: not-a-list
"""
empty_properties = ''
try:
RawValidate(empty_properties, schema_name, schema)
self.fail('Validation should fail')
except schema_validation.ValidationErrors as e:
self.assertEqual(2, len(e.errors))
self.assertIn("Invalid schema '%s'" % schema_name, e.message)
self.assertIn("is not of type 'array' at ['imports']", e.message)
self.assertIn("is not of type u'array' at [u'required']",
e.message)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
3698,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
2882,
199,
646,
4177,
63,
6136,
199,
646,
8864,
199,
199,
9692,
63,
18858,
29807,
275,
298,
3364,
4382,
367,
283,
1160,
14,
647,
4065,
421,
199,
318,
2372,
14225,
837,
272,
408,
6591,
4154,
1350,
436,
666,
1584,
1041,
272,
372,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
421,
199,
318,
5574,
774,
1173,
8,
1501,
304,
272,
408,
3407,
4072,
402,
282,
570,
687,
314,
511,
576,
15,
2082,
1041,
339,
2615,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1002,
14225,
1062,
19155,
283,
396,
297,
283,
9482,
297,
1788,
9,
272,
372,
1551,
8,
2861,
63,
515,
12,
283,
82,
1959,
739,
342,
421,
199,
318,
13480,
12584,
8,
1773,
63,
3282,
12,
4177,
63,
354,
12,
3066,
63,
3629,
304,
272,
372,
24339,
7963,
12584,
8,
1773,
63,
3282,
12,
4177,
63,
354,
12,
2892,
469,
3629,
63,
354,
26,
3066,
63,
3629,
1552,
421,
199,
318,
24339,
7963,
12584,
8,
1773,
63,
3282,
12,
4177,
63,
354,
12,
492,
63,
1130,
304,
272,
408,
32488,
3066,
4382,
12,
4882,
4107,
436,
2529,
8864,
4382,
1041,
272,
4382,
275,
8864,
14,
3489,
63,
912,
8,
1773,
63,
3282,
9,
272,
372,
4177,
63,
6136,
14,
12584,
8,
3282,
12,
4177,
63,
354,
12,
283,
1160,
14,
647,
297,
4228,
492,
63,
1130,
9,
421,
199,
533,
13268,
13816,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
402,
314,
4177,
18046,
402,
314,
1978,
14819,
3555,
1041,
339,
347,
511,
16986,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
4322,
14,
12264,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
2701,
63,
3282,
275,
2125,
267,
1420,
63,
3282,
275,
408,
288,
5131,
26,
5131,
288,
1373,
26,
413,
267,
408,
267,
291,
14,
629,
8,
5963,
14,
3489,
63,
912,
8,
2062,
63,
3282,
395,
586,
13480,
12584,
8,
1667,
63,
3282,
12,
4177,
63,
354,
12,
4177,
430,
339,
347,
511,
13029,
16986,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
6376,
63,
4322,
14,
647,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
4382,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
536,
26,
6902,
3698,
327,
4543,
804,
436,
1568,
30271,
663,
701,
849,
355,
446,
536,
26,
2581,
3322,
327,
1568,
30271,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
355,
446,
536,
26,
666,
3777,
327,
20550,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
1568,
30271,
26,
14711,
355,
446,
536,
26,
11413,
3777,
327,
4543,
804,
663,
701,
849,
490,
1568,
30271,
26,
1926,
267,
408,
267,
1420,
63,
3282,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
6902,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
2581,
355,
446,
1568,
30271,
26,
14711,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
666,
355,
446,
1568,
30271,
26,
1926,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
11413,
267,
408,
267,
291,
14,
629,
8,
5963,
14,
3489,
63,
912,
8,
2062,
63,
3282,
395,
586,
13480,
12584,
8,
3282,
12,
4177,
63,
354,
12,
4177,
430,
339,
347,
511,
13029,
2891,
16986,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
1121,
63,
6376,
63,
4322,
14,
647,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
4382,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
536,
26,
6902,
3698,
327,
4543,
804,
436,
1568,
30271,
663,
701,
849,
355,
446,
536,
26,
2581,
3322,
327,
1568,
30271,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
355,
446,
536,
26,
666,
3777,
327,
20550,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
1568,
30271,
26,
14711,
355,
446,
536,
26,
11413,
3777,
327,
4543,
804,
663,
701,
849,
490,
1568,
30271,
26,
1926,
267,
408,
267,
1420,
63,
3282,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
6902,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
2581,
355,
446,
1568,
30271,
26,
14711,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
666,
355,
446,
1568,
30271,
26,
1926,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
11413,
267,
408,
267,
291,
14,
629,
8,
5963,
14,
3489,
63,
912,
8,
2062,
63,
3282,
395,
586,
13480,
12584,
8,
3282,
12,
4177,
63,
354,
12,
4177,
430,
339,
347,
511,
3364,
2698,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
3197,
63,
885,
14,
12264,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
2701,
63,
3282,
275,
2125,
267,
862,
26,
288,
13480,
12584,
8,
1667,
63,
3282,
12,
4177,
63,
354,
12,
4177
] |
[
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
3698,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
2882,
199,
646,
4177,
63,
6136,
199,
646,
8864,
199,
199,
9692,
63,
18858,
29807,
275,
298,
3364,
4382,
367,
283,
1160,
14,
647,
4065,
421,
199,
318,
2372,
14225,
837,
272,
408,
6591,
4154,
1350,
436,
666,
1584,
1041,
272,
372,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
421,
199,
318,
5574,
774,
1173,
8,
1501,
304,
272,
408,
3407,
4072,
402,
282,
570,
687,
314,
511,
576,
15,
2082,
1041,
339,
2615,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1002,
14225,
1062,
19155,
283,
396,
297,
283,
9482,
297,
1788,
9,
272,
372,
1551,
8,
2861,
63,
515,
12,
283,
82,
1959,
739,
342,
421,
199,
318,
13480,
12584,
8,
1773,
63,
3282,
12,
4177,
63,
354,
12,
3066,
63,
3629,
304,
272,
372,
24339,
7963,
12584,
8,
1773,
63,
3282,
12,
4177,
63,
354,
12,
2892,
469,
3629,
63,
354,
26,
3066,
63,
3629,
1552,
421,
199,
318,
24339,
7963,
12584,
8,
1773,
63,
3282,
12,
4177,
63,
354,
12,
492,
63,
1130,
304,
272,
408,
32488,
3066,
4382,
12,
4882,
4107,
436,
2529,
8864,
4382,
1041,
272,
4382,
275,
8864,
14,
3489,
63,
912,
8,
1773,
63,
3282,
9,
272,
372,
4177,
63,
6136,
14,
12584,
8,
3282,
12,
4177,
63,
354,
12,
283,
1160,
14,
647,
297,
4228,
492,
63,
1130,
9,
421,
199,
533,
13268,
13816,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
402,
314,
4177,
18046,
402,
314,
1978,
14819,
3555,
1041,
339,
347,
511,
16986,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
4322,
14,
12264,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
2701,
63,
3282,
275,
2125,
267,
1420,
63,
3282,
275,
408,
288,
5131,
26,
5131,
288,
1373,
26,
413,
267,
408,
267,
291,
14,
629,
8,
5963,
14,
3489,
63,
912,
8,
2062,
63,
3282,
395,
586,
13480,
12584,
8,
1667,
63,
3282,
12,
4177,
63,
354,
12,
4177,
430,
339,
347,
511,
13029,
16986,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
6376,
63,
4322,
14,
647,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
4382,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
536,
26,
6902,
3698,
327,
4543,
804,
436,
1568,
30271,
663,
701,
849,
355,
446,
536,
26,
2581,
3322,
327,
1568,
30271,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
355,
446,
536,
26,
666,
3777,
327,
20550,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
1568,
30271,
26,
14711,
355,
446,
536,
26,
11413,
3777,
327,
4543,
804,
663,
701,
849,
490,
1568,
30271,
26,
1926,
267,
408,
267,
1420,
63,
3282,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
6902,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
2581,
355,
446,
1568,
30271,
26,
14711,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
666,
355,
446,
1568,
30271,
26,
1926,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
11413,
267,
408,
267,
291,
14,
629,
8,
5963,
14,
3489,
63,
912,
8,
2062,
63,
3282,
395,
586,
13480,
12584,
8,
3282,
12,
4177,
63,
354,
12,
4177,
430,
339,
347,
511,
13029,
2891,
16986,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
1121,
63,
6376,
63,
4322,
14,
647,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
4382,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
536,
26,
6902,
3698,
327,
4543,
804,
436,
1568,
30271,
663,
701,
849,
355,
446,
536,
26,
2581,
3322,
327,
1568,
30271,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
355,
446,
536,
26,
666,
3777,
327,
20550,
663,
701,
849,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
1568,
30271,
26,
14711,
355,
446,
536,
26,
11413,
3777,
327,
4543,
804,
663,
701,
849,
490,
1568,
30271,
26,
1926,
267,
408,
267,
1420,
63,
3282,
275,
408,
288,
5718,
26,
2739,
13,
16067,
17,
13,
65,
288,
17602,
26,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
6902,
355,
446,
1568,
30271,
26,
2948,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
2581,
355,
446,
1568,
30271,
26,
14711,
490,
4543,
804,
26,
6454,
13,
385,
68,
490,
536,
26,
666,
355,
446,
1568,
30271,
26,
1926,
490,
4543,
804,
26,
6454,
13,
6807,
490,
536,
26,
11413,
267,
408,
267,
291,
14,
629,
8,
5963,
14,
3489,
63,
912,
8,
2062,
63,
3282,
395,
586,
13480,
12584,
8,
3282,
12,
4177,
63,
354,
12,
4177,
430,
339,
347,
511,
3364,
2698,
8,
277,
304,
267,
4177,
63,
354,
275,
283,
3197,
63,
885,
14,
12264,
14,
3629,
7,
267,
4177,
275,
5574,
774,
1173,
8,
3629,
63,
354,
9,
267,
2701,
63,
3282,
275,
2125,
267,
862,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
matejkloska/django-registration
|
registration/forms.py
|
28
|
3199
|
"""
Forms and validation code for user registration.
Note that all of these forms assume Django's bundle default ``User``
model; since it's not possible for a form to anticipate in advance the
needs of custom user models, you will need to write your own forms if
you're using a custom model.
"""
from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import UserCreationForm
from .users import UserModel, UsernameField
User = UserModel()
class RegistrationForm(UserCreationForm):
"""
Form for registering a new user account.
Validates that the requested username is not already in use, and
requires the password to be entered twice to catch typos.
Subclasses should feel free to add any additional validation they
need, but should avoid defining a ``save()`` method -- the actual
saving of collected user data is delegated to the active
registration backend.
"""
required_css_class = 'required'
email = forms.EmailField(label=_("E-mail"))
class Meta:
model = User
fields = (UsernameField(), "email")
class RegistrationFormTermsOfService(RegistrationForm):
"""
Subclass of ``RegistrationForm`` which adds a required checkbox
for agreeing to a site's Terms of Service.
"""
tos = forms.BooleanField(widget=forms.CheckboxInput,
label=_('I have read and agree to the Terms of Service'),
error_messages={'required': _("You must agree to the terms to register")})
class RegistrationFormUniqueEmail(RegistrationForm):
"""
Subclass of ``RegistrationForm`` which enforces uniqueness of
email addresses.
"""
def clean_email(self):
"""
Validate that the supplied email address is unique for the
site.
"""
if User.objects.filter(email__iexact=self.cleaned_data['email']):
raise forms.ValidationError(_("This email address is already in use. Please supply a different email address."))
return self.cleaned_data['email']
class RegistrationFormNoFreeEmail(RegistrationForm):
"""
Subclass of ``RegistrationForm`` which disallows registration with
email addresses from popular free webmail services; moderately
useful for preventing automated spam registrations.
To change the list of banned domains, subclass this form and
override the attribute ``bad_domains``.
"""
bad_domains = ['aim.com', 'aol.com', 'email.com', 'gmail.com',
'googlemail.com', 'hotmail.com', 'hushmail.com',
'msn.com', 'mail.ru', 'mailinator.com', 'live.com',
'yahoo.com']
def clean_email(self):
"""
Check the supplied email address against a list of known free
webmail domains.
"""
email_domain = self.cleaned_data['email'].split('@')[1]
if email_domain in self.bad_domains:
raise forms.ValidationError(_("Registration using free email addresses is prohibited. Please supply a different email address."))
return self.cleaned_data['email']
|
bsd-3-clause
|
[
624,
199,
26028,
436,
6411,
1233,
367,
922,
10991,
14,
199,
199,
7443,
626,
1006,
402,
3520,
4513,
5534,
5634,
1159,
8844,
849,
1124,
1899,
1040,
199,
1238,
27,
3967,
652,
1159,
440,
3962,
367,
282,
1824,
370,
376,
10479,
323,
315,
18695,
314,
199,
10065,
402,
3537,
922,
1709,
12,
1265,
911,
1929,
370,
2218,
2195,
5705,
4513,
340,
199,
13297,
3984,
1808,
282,
3537,
1402,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
421,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
2876,
13921,
2821,
199,
199,
504,
1275,
3707,
492,
2876,
1685,
12,
29739,
792,
199,
199,
1899,
275,
2876,
1685,
342,
421,
199,
533,
20764,
2821,
8,
1899,
13921,
2821,
304,
272,
408,
272,
8204,
367,
2274,
316,
282,
892,
922,
2933,
14,
339,
4821,
2335,
626,
314,
5839,
3434,
365,
440,
2575,
315,
675,
12,
436,
272,
5074,
314,
2505,
370,
506,
19138,
13373,
370,
8579,
10284,
1712,
14,
339,
20196,
1077,
23109,
2867,
370,
1050,
1263,
4722,
6411,
2985,
272,
1929,
12,
1325,
1077,
5126,
12669,
282,
1124,
2117,
8497,
1083,
1553,
314,
3503,
272,
13369,
402,
13736,
922,
666,
365,
29598,
370,
314,
4702,
272,
10991,
4865,
14,
339,
408,
272,
1415,
63,
3919,
63,
533,
275,
283,
2427,
7,
272,
3031,
275,
4513,
14,
16577,
8,
1302,
9384,
37,
13,
1198,
2237,
339,
1021,
6288,
26,
267,
1402,
275,
2876,
267,
1504,
275,
334,
13355,
792,
1062,
298,
2123,
531,
421,
199,
533,
20764,
2821,
8600,
706,
3466,
3167,
8,
11757,
2821,
304,
272,
408,
272,
30184,
402,
1124,
11757,
2821,
1040,
1314,
9584,
282,
1415,
24190,
272,
367,
10601,
316,
370,
282,
4770,
1159,
13861,
706,
402,
7591,
14,
339,
408,
272,
370,
83,
275,
4513,
14,
5036,
8,
3440,
29,
3351,
14,
26366,
3205,
12,
2490,
1768,
12397,
41,
1172,
1586,
436,
10601,
370,
314,
13861,
706,
402,
7591,
659,
2490,
1125,
63,
3431,
3713,
2427,
356,
3824,
5556,
1471,
10601,
370,
314,
2895,
370,
2274,
531,
1552,
421,
199,
533,
20764,
2821,
11427,
7035,
8,
11757,
2821,
304,
272,
408,
272,
30184,
402,
1124,
11757,
2821,
1040,
1314,
655,
509,
823,
15439,
31820,
402,
272,
3031,
7149,
14,
339,
408,
272,
347,
3633,
63,
2123,
8,
277,
304,
267,
408,
267,
12134,
626,
314,
6841,
3031,
2287,
365,
3747,
367,
314,
267,
4770,
14,
398,
408,
267,
340,
2876,
14,
1462,
14,
1541,
8,
2123,
363,
32344,
29,
277,
14,
8275,
63,
576,
459,
2123,
9090,
288,
746,
4513,
14,
8172,
6115,
2765,
3031,
2287,
365,
2575,
315,
675,
14,
7754,
17169,
282,
3365,
3031,
2287,
13853,
267,
372,
291,
14,
8275,
63,
576,
459,
2123,
418,
421,
199,
533,
20764,
2821,
1944,
10146,
7035,
8,
11757,
2821,
304,
272,
408,
272,
30184,
402,
1124,
11757,
2821,
1040,
1314,
2153,
24077,
10991,
543,
272,
3031,
7149,
687,
4560,
2238,
2867,
3330,
1198,
8500,
27,
818,
1866,
590,
272,
2997,
367,
7981,
316,
6384,
23513,
14909,
25483,
3801,
14,
339,
4005,
1570,
314,
769,
402,
330,
9386,
14006,
12,
5516,
642,
1824,
436,
272,
4278,
314,
2225,
1124,
4087,
63,
9756,
4345,
339,
408,
272,
4875,
63,
9756,
275,
788,
65,
1017,
14,
957,
297,
283,
65,
393,
14,
957,
297,
283,
2123,
14,
957,
297,
283,
6799,
14,
957,
297,
673,
283,
3098,
1198,
14,
957,
297,
283,
8885,
1198,
14,
957,
297,
283,
72,
2084,
1198,
14,
957,
297,
673,
283,
706,
78,
14,
957,
297,
283,
1198,
14,
6558,
297,
283,
1198,
8566,
14,
957,
297,
283,
6442,
14,
957,
297,
673,
283,
27231,
14,
957,
418,
339,
347,
3633,
63,
2123,
8,
277,
304,
267,
408,
267,
2670,
314,
6841,
3031,
2287,
6169,
282,
769,
402,
6040,
2867,
267,
3330,
1198,
14006,
14,
398,
408,
267,
3031,
63,
2261,
275,
291,
14,
8275,
63,
576,
459,
2123,
2278,
1294,
16591,
5832,
17,
61,
267,
340,
3031,
63,
2261,
315,
291,
14,
4087,
63,
9756,
26,
288,
746,
4513,
14,
8172,
6115,
11757,
1808,
2867,
3031,
7149,
365,
557,
20215,
5703,
14,
7754,
17169,
282,
3365,
3031,
2287,
13853,
267,
372,
291,
14,
8275,
63,
576,
459,
2123,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
26028,
436,
6411,
1233,
367,
922,
10991,
14,
199,
199,
7443,
626,
1006,
402,
3520,
4513,
5534,
5634,
1159,
8844,
849,
1124,
1899,
1040,
199,
1238,
27,
3967,
652,
1159,
440,
3962,
367,
282,
1824,
370,
376,
10479,
323,
315,
18695,
314,
199,
10065,
402,
3537,
922,
1709,
12,
1265,
911,
1929,
370,
2218,
2195,
5705,
4513,
340,
199,
13297,
3984,
1808,
282,
3537,
1402,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
421,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
2876,
13921,
2821,
199,
199,
504,
1275,
3707,
492,
2876,
1685,
12,
29739,
792,
199,
199,
1899,
275,
2876,
1685,
342,
421,
199,
533,
20764,
2821,
8,
1899,
13921,
2821,
304,
272,
408,
272,
8204,
367,
2274,
316,
282,
892,
922,
2933,
14,
339,
4821,
2335,
626,
314,
5839,
3434,
365,
440,
2575,
315,
675,
12,
436,
272,
5074,
314,
2505,
370,
506,
19138,
13373,
370,
8579,
10284,
1712,
14,
339,
20196,
1077,
23109,
2867,
370,
1050,
1263,
4722,
6411,
2985,
272,
1929,
12,
1325,
1077,
5126,
12669,
282,
1124,
2117,
8497,
1083,
1553,
314,
3503,
272,
13369,
402,
13736,
922,
666,
365,
29598,
370,
314,
4702,
272,
10991,
4865,
14,
339,
408,
272,
1415,
63,
3919,
63,
533,
275,
283,
2427,
7,
272,
3031,
275,
4513,
14,
16577,
8,
1302,
9384,
37,
13,
1198,
2237,
339,
1021,
6288,
26,
267,
1402,
275,
2876,
267,
1504,
275,
334,
13355,
792,
1062,
298,
2123,
531,
421,
199,
533,
20764,
2821,
8600,
706,
3466,
3167,
8,
11757,
2821,
304,
272,
408,
272,
30184,
402,
1124,
11757,
2821,
1040,
1314,
9584,
282,
1415,
24190,
272,
367,
10601,
316,
370,
282,
4770,
1159,
13861,
706,
402,
7591,
14,
339,
408,
272,
370,
83,
275,
4513,
14,
5036,
8,
3440,
29,
3351,
14,
26366,
3205,
12,
2490,
1768,
12397,
41,
1172,
1586,
436,
10601,
370,
314,
13861,
706,
402,
7591,
659,
2490,
1125,
63,
3431,
3713,
2427,
356,
3824,
5556,
1471,
10601,
370,
314,
2895,
370,
2274,
531,
1552,
421,
199,
533,
20764,
2821,
11427,
7035,
8,
11757,
2821,
304,
272,
408,
272,
30184,
402,
1124,
11757,
2821,
1040,
1314,
655,
509,
823,
15439,
31820,
402,
272,
3031,
7149,
14,
339,
408,
272,
347,
3633,
63,
2123,
8,
277,
304,
267,
408,
267,
12134,
626,
314,
6841,
3031,
2287,
365,
3747,
367,
314,
267,
4770,
14,
398,
408,
267,
340,
2876,
14,
1462,
14,
1541,
8,
2123,
363,
32344,
29,
277,
14,
8275,
63,
576,
459,
2123,
9090,
288,
746,
4513,
14,
8172,
6115,
2765,
3031,
2287,
365,
2575,
315,
675,
14,
7754,
17169,
282,
3365,
3031,
2287,
13853,
267,
372,
291,
14,
8275,
63,
576,
459,
2123,
418,
421,
199,
533,
20764,
2821,
1944,
10146,
7035,
8,
11757,
2821,
304,
272,
408,
272,
30184,
402,
1124,
11757,
2821,
1040,
1314,
2153,
24077,
10991,
543,
272,
3031,
7149,
687,
4560,
2238,
2867,
3330,
1198,
8500,
27,
818,
1866,
590,
272,
2997,
367,
7981,
316,
6384,
23513,
14909,
25483,
3801,
14,
339,
4005,
1570,
314,
769,
402,
330,
9386,
14006,
12,
5516,
642,
1824,
436,
272,
4278,
314,
2225,
1124,
4087,
63,
9756,
4345,
339,
408,
272,
4875,
63,
9756,
275,
788,
65,
1017,
14,
957,
297,
283,
65,
393,
14,
957,
297,
283,
2123,
14,
957,
297,
283,
6799,
14,
957,
297,
673,
283,
3098,
1198,
14,
957,
297,
283,
8885,
1198,
14,
957,
297,
283,
72,
2084,
1198,
14,
957,
297,
673,
283,
706,
78,
14,
957,
297,
283,
1198,
14,
6558,
297,
283,
1198,
8566,
14,
957,
297,
283,
6442,
14,
957,
297,
673,
283,
27231,
14,
957,
418,
339,
347,
3633,
63,
2123,
8,
277,
304,
267,
408,
267,
2670,
314,
6841,
3031,
2287,
6169,
282,
769,
402,
6040,
2867,
267,
3330,
1198,
14006,
14,
398,
408,
267,
3031,
63,
2261,
275,
291,
14,
8275,
63,
576,
459,
2123,
2278,
1294,
16591,
5832,
17,
61,
267,
340,
3031,
63,
2261,
315,
291,
14,
4087,
63,
9756,
26,
288,
746,
4513,
14,
8172,
6115,
11757,
1808,
2867,
3031,
7149,
365,
557,
20215,
5703,
14,
7754,
17169,
282,
3365,
3031,
2287,
13853,
267,
372,
291,
14,
8275,
63,
576,
459,
2123,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PoornimaNayak/autotest-client-tests
|
linux-tools/celt051/celt051.py
|
4
|
1244
|
#!/bin/python
import os, subprocess
import logging
from autotest.client import test
from autotest.client.shared import error
class celt051(test.test):
"""
Autotest module for testing basic functionality
of celt051
@author Gopal Kalita <gokalita@in.ibm.com> ##
"""
version = 1
nfail = 0
path = ''
def initialize(self):
"""
Sets the overall failure counter for the test.
"""
self.nfail = 0
logging.info('\n Test initialize successfully')
def run_once(self, test_path=''):
"""
Trigger test run
"""
try:
os.environ["LTPBIN"] = "%s/shared" %(test_path)
ret_val = subprocess.Popen(['./celt.sh'], cwd="%s/celt051" %(test_path))
ret_val.communicate()
if ret_val.returncode != 0:
self.nfail += 1
except error.CmdError, e:
self.nfail += 1
logging.error("Test Failed: %s", e)
def postprocess(self):
if self.nfail != 0:
logging.info('\n nfails is non-zero')
raise error.TestError('\nTest failed')
else:
logging.info('\n Test completed successfully ')
|
gpl-2.0
|
[
3381,
1393,
15,
1548,
199,
646,
747,
12,
3873,
199,
646,
2050,
199,
199,
504,
2599,
396,
14,
1258,
492,
511,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
199,
199,
533,
286,
15330,
21101,
8,
396,
14,
396,
304,
339,
408,
272,
9195,
396,
859,
367,
5343,
5678,
9330,
272,
402,
286,
15330,
21101,
339,
768,
2502,
598,
411,
279,
1804,
279,
21492,
665,
71,
745,
279,
21492,
32,
262,
14,
19870,
14,
957,
30,
2476,
925,
272,
408,
272,
1015,
275,
413,
272,
302,
1633,
275,
378,
272,
931,
275,
2125,
339,
347,
8265,
8,
277,
304,
267,
408,
267,
10729,
314,
20347,
5988,
7055,
367,
314,
511,
14,
267,
408,
267,
291,
14,
78,
1633,
275,
378,
267,
2050,
14,
815,
2258,
78,
1379,
8265,
8792,
358,
339,
347,
1255,
63,
5089,
8,
277,
12,
511,
63,
515,
9280,
267,
408,
267,
24015,
511,
1255,
267,
408,
267,
862,
26,
288,
747,
14,
2314,
905,
44,
6495,
9431,
937,
275,
2071,
83,
15,
5555,
2,
2818,
396,
63,
515,
9,
288,
2203,
63,
637,
275,
3873,
14,
7942,
2941,
13186,
301,
4116,
14,
609,
995,
8288,
5961,
83,
15,
301,
4116,
21101,
2,
2818,
396,
63,
515,
430,
288,
2203,
63,
637,
14,
10664,
342,
288,
340,
2203,
63,
637,
14,
9913,
1137,
378,
26,
355,
291,
14,
78,
1633,
847,
413,
398,
871,
1125,
14,
7874,
547,
12,
325,
26,
288,
291,
14,
78,
1633,
847,
413,
288,
2050,
14,
705,
480,
774,
16277,
26,
450,
83,
401,
325,
9,
339,
347,
2963,
1412,
8,
277,
304,
267,
340,
291,
14,
78,
1633,
1137,
378,
26,
288,
2050,
14,
815,
2258,
78,
302,
15762,
365,
2222,
13,
4262,
358,
288,
746,
1125,
14,
774,
547,
2258,
78,
774,
3405,
358,
267,
587,
26,
288,
2050,
14,
815,
2258,
78,
1379,
9709,
8792,
5320,
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
] |
[
1393,
15,
1548,
199,
646,
747,
12,
3873,
199,
646,
2050,
199,
199,
504,
2599,
396,
14,
1258,
492,
511,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
199,
199,
533,
286,
15330,
21101,
8,
396,
14,
396,
304,
339,
408,
272,
9195,
396,
859,
367,
5343,
5678,
9330,
272,
402,
286,
15330,
21101,
339,
768,
2502,
598,
411,
279,
1804,
279,
21492,
665,
71,
745,
279,
21492,
32,
262,
14,
19870,
14,
957,
30,
2476,
925,
272,
408,
272,
1015,
275,
413,
272,
302,
1633,
275,
378,
272,
931,
275,
2125,
339,
347,
8265,
8,
277,
304,
267,
408,
267,
10729,
314,
20347,
5988,
7055,
367,
314,
511,
14,
267,
408,
267,
291,
14,
78,
1633,
275,
378,
267,
2050,
14,
815,
2258,
78,
1379,
8265,
8792,
358,
339,
347,
1255,
63,
5089,
8,
277,
12,
511,
63,
515,
9280,
267,
408,
267,
24015,
511,
1255,
267,
408,
267,
862,
26,
288,
747,
14,
2314,
905,
44,
6495,
9431,
937,
275,
2071,
83,
15,
5555,
2,
2818,
396,
63,
515,
9,
288,
2203,
63,
637,
275,
3873,
14,
7942,
2941,
13186,
301,
4116,
14,
609,
995,
8288,
5961,
83,
15,
301,
4116,
21101,
2,
2818,
396,
63,
515,
430,
288,
2203,
63,
637,
14,
10664,
342,
288,
340,
2203,
63,
637,
14,
9913,
1137,
378,
26,
355,
291,
14,
78,
1633,
847,
413,
398,
871,
1125,
14,
7874,
547,
12,
325,
26,
288,
291,
14,
78,
1633,
847,
413,
288,
2050,
14,
705,
480,
774,
16277,
26,
450,
83,
401,
325,
9,
339,
347,
2963,
1412,
8,
277,
304,
267,
340,
291,
14,
78,
1633,
1137,
378,
26,
288,
2050,
14,
815,
2258,
78,
302,
15762,
365,
2222,
13,
4262,
358,
288,
746,
1125,
14,
774,
547,
2258,
78,
774,
3405,
358,
267,
587,
26,
288,
2050,
14,
815,
2258,
78,
1379,
9709,
8792,
5320,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CINPLA/expipe-dev
|
expipe-templates-cinpla/get_templates.py
|
1
|
1153
|
import expipe
import os.path as op
import os
import json
overwrite = True
base_dir = op.join(op.abspath(op.dirname(op.expanduser(__file__))), 'templates')
templates = expipe.core.FirebaseBackend("/templates").get()
for template, val in templates.items():
identifier = val.get('identifier')
if identifier is None:
continue
path = template.split('_')[0]
name = identifier.split('_')[1:]
if path == 'person':
continue
if len(name) == 0:
continue
raise ValueError('No grouping on template "' + template + '"')
fbase = '_'.join(name)
fname = op.join(base_dir, path, fbase + '.json')
result = expipe.get_template(template=template)
if op.exists(fname) and not overwrite:
raise FileExistsError('The filename "' + fname +
'" exists, set ovewrite to true.')
os.makedirs(op.dirname(fname), exist_ok=True)
print('Saving template "' + template + '" to "' + fname + '"')
with open(fname, 'w') as outfile:
result = expipe.core.convert_to_firebase(result)
json.dump(result, outfile,
sort_keys=True, indent=4)
|
gpl-3.0
|
[
646,
444,
4990,
199,
646,
747,
14,
515,
465,
1687,
199,
646,
747,
199,
646,
2022,
199,
199,
14658,
275,
715,
199,
199,
1095,
63,
694,
275,
1687,
14,
904,
8,
411,
14,
4832,
8,
411,
14,
3475,
8,
411,
14,
12131,
3460,
493,
8964,
395,
283,
5876,
358,
199,
199,
5876,
275,
444,
4990,
14,
1018,
14,
13081,
1095,
8447,
4769,
5876,
3471,
362,
342,
199,
509,
1978,
12,
1139,
315,
7009,
14,
1744,
837,
272,
5148,
275,
1139,
14,
362,
360,
5364,
358,
272,
340,
5148,
365,
488,
26,
267,
1980,
272,
931,
275,
1978,
14,
1294,
6412,
5832,
16,
61,
272,
536,
275,
5148,
14,
1294,
6412,
5832,
17,
2938,
272,
340,
931,
508,
283,
5484,
356,
267,
1980,
272,
340,
822,
8,
354,
9,
508,
378,
26,
267,
1980,
267,
746,
1722,
360,
1944,
17786,
641,
1978,
3546,
435,
1978,
435,
5522,
358,
272,
289,
1095,
275,
2513,
1370,
904,
8,
354,
9,
272,
6748,
275,
1687,
14,
904,
8,
1095,
63,
694,
12,
931,
12,
289,
1095,
435,
1987,
1001,
358,
272,
754,
275,
444,
4990,
14,
362,
63,
1160,
8,
1160,
29,
1160,
9,
272,
340,
1687,
14,
2444,
8,
5252,
9,
436,
440,
8970,
26,
267,
746,
3814,
23839,
360,
1918,
1788,
3546,
435,
6748,
435,
2892,
5522,
3495,
12,
663,
312,
432,
952,
370,
2549,
2659,
272,
747,
14,
8347,
8,
411,
14,
3475,
8,
5252,
395,
2187,
63,
745,
29,
549,
9,
272,
870,
360,
30125,
1978,
3546,
435,
1978,
435,
5522,
370,
3546,
435,
6748,
435,
5522,
358,
272,
543,
1551,
8,
5252,
12,
283,
87,
358,
465,
4386,
26,
267,
754,
275,
444,
4990,
14,
1018,
14,
3916,
63,
475,
63,
8935,
1095,
8,
1099,
9,
267,
2022,
14,
2724,
8,
1099,
12,
4386,
12,
2116,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
444,
4990,
199,
646,
747,
14,
515,
465,
1687,
199,
646,
747,
199,
646,
2022,
199,
199,
14658,
275,
715,
199,
199,
1095,
63,
694,
275,
1687,
14,
904,
8,
411,
14,
4832,
8,
411,
14,
3475,
8,
411,
14,
12131,
3460,
493,
8964,
395,
283,
5876,
358,
199,
199,
5876,
275,
444,
4990,
14,
1018,
14,
13081,
1095,
8447,
4769,
5876,
3471,
362,
342,
199,
509,
1978,
12,
1139,
315,
7009,
14,
1744,
837,
272,
5148,
275,
1139,
14,
362,
360,
5364,
358,
272,
340,
5148,
365,
488,
26,
267,
1980,
272,
931,
275,
1978,
14,
1294,
6412,
5832,
16,
61,
272,
536,
275,
5148,
14,
1294,
6412,
5832,
17,
2938,
272,
340,
931,
508,
283,
5484,
356,
267,
1980,
272,
340,
822,
8,
354,
9,
508,
378,
26,
267,
1980,
267,
746,
1722,
360,
1944,
17786,
641,
1978,
3546,
435,
1978,
435,
5522,
358,
272,
289,
1095,
275,
2513,
1370,
904,
8,
354,
9,
272,
6748,
275,
1687,
14,
904,
8,
1095,
63,
694,
12,
931,
12,
289,
1095,
435,
1987,
1001,
358,
272,
754,
275,
444,
4990,
14,
362,
63,
1160,
8,
1160,
29,
1160,
9,
272,
340,
1687,
14,
2444,
8,
5252,
9,
436,
440,
8970,
26,
267,
746,
3814,
23839,
360,
1918,
1788,
3546,
435,
6748,
435,
2892,
5522,
3495,
12,
663,
312,
432,
952,
370,
2549,
2659,
272,
747,
14,
8347,
8,
411,
14,
3475,
8,
5252,
395,
2187,
63,
745,
29,
549,
9,
272,
870,
360,
30125,
1978,
3546,
435,
1978,
435,
5522,
370,
3546,
435,
6748,
435,
5522,
358,
272,
543,
1551,
8,
5252,
12,
283,
87,
358,
465,
4386,
26,
267,
754,
275,
444,
4990,
14,
1018,
14,
3916,
63,
475,
63,
8935,
1095,
8,
1099,
9,
267,
2022,
14,
2724,
8,
1099,
12,
4386,
12,
2116,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
prontodev/stillwithus
|
stillwithus/clientsites/tests.py
|
1
|
6014
|
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase
from .models import ClientSite
from servers.models import Server
class ClientSiteTest(TestCase):
def test_create_new_clientsite(self):
clientsite = ClientSite()
clientsite.domain = 'www.atlasperformancechicago.com'
self.assertFalse(clientsite.id)
clientsite.save()
self.assertTrue(clientsite.id)
clientsite = ClientSite.objects.get(id=clientsite.id)
self.assertEqual(clientsite.domain, 'www.atlasperformancechicago.com')
class ClientSiteViewTest(TestCase):
def setUp(self):
self.url = reverse('clientsites')
def test_clientsite_should_be_accessible(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
def test_clientsite_should_use_correct_template(self):
response = self.client.get(self.url)
self.assertTemplateUsed(response, 'clientsites.html')
def test_clientsite_should_have_title(self):
response = self.client.get(self.url)
expected = '<title>Still with Us?</title>'
self.assertContains(response, expected, status_code=200)
def test_clientsite_should_render_html_for_clientsites_correctly(self):
response = self.client.get(self.url)
expected = '<h1>Client Sites</h1>'
self.assertContains(response, expected, status_code=200)
expected = '<thead><tr><th>Domain</th><th>Still with Us?'
expected += '</th><th>Note</th></tr></thead>'
self.assertContains(response, expected, status_code=200)
def test_clientsite_should_query_domains_and_check_if_still_with_us(self):
Server.objects.bulk_create([
Server(name='Pronto 1', ip='54.72.3.133'),
Server(name='Pronto 2', ip='54.72.3.103'),
Server(name='Pronto 3', ip='54.252.146.70'),
Server(name='Pronto 4', ip='54.67.50.151'),
Server(name='Pronto 5', ip='52.1.32.33'),
Server(name='Pronto 6', ip='27.254.65.18'),
Server(name='Pronto 7', ip='54.246.93.4'),
Server(name='Pronto 8', ip='54.228.219.35'),
Server(name='Pronto 9', ip='54.72.3.253'),
Server(name='Pronto 10', ip='54.171.171.172'),
Server(name='Pronto 11', ip='46.137.96.191'),
Server(name='Pronto 12', ip='54.194.28.91'),
Server(name='Pronto 13', ip='54.72.53.55'),
])
ClientSite.objects.bulk_create([
ClientSite(domain='www.prontomarketing.com'),
ClientSite(domain='www.atlasperformancechicago.com'),
])
response = self.client.get(self.url)
expected = '<tr><td><a href="http://www.prontomarketing.com" '
expected += 'target="_blank">www.prontomarketing.com</a></td>'
expected += '<td style="color: red;">No</td><td>---</td></tr>'
self.assertContains(response, expected, count=1, status_code=200)
expected = '<td><a href="http://www.prontomarketing.com" '
expected += 'target="_blank">www.prontomarketing.com</a></td>'
self.assertContains(response, expected, count=1, status_code=200)
expected = '<tr><td><a href="http://www.atlasperformancechicago.com" '
expected += 'target="_blank">www.atlasperformancechicago.com</a></td>'
expected += '<td>Yes</td><td>---</td></tr>'
self.assertContains(response, expected, count=1, status_code=200)
expected = '<td><a href="http://www.atlasperformancechicago.com" '
expected += 'target="_blank">www.atlasperformancechicago.com</a></td>'
self.assertContains(response, expected, count=1, status_code=200)
def test_clientsite_should_add_note_if_cannot_get_ip(self):
ClientSite.objects.create(
domain='dayton.kaiafit.com'
)
response = self.client.get(self.url)
expected = '<tr><td><a href="http://dayton.kaiafit.com" '
expected += 'target="_blank">dayton.kaiafit.com</a></td>'
expected += '<td>---</td><td>Cannot get IP</td></tr>'
self.assertContains(response, expected, count=1, status_code=200)
def test_clientsite_should_render_html_for_servers_correctly(self):
response = self.client.get(self.url)
expected = '<h1>Servers</h1>'
self.assertContains(response, expected, status_code=200)
expected = '<thead><tr><th>Name</th><th>IP</th></tr></thead>'
self.assertContains(response, expected, status_code=200)
def test_clientsite_should_query_server_name_and_ip_correctly(self):
Server.objects.create(
name='AWS ELB',
ip='54.72.3.133'
)
Server.objects.create(
name='Bypronto',
ip='54.171.171.172'
)
response = self.client.get(self.url)
expected = '<tr><td>AWS ELB</td><td>54.72.3.133</td></tr>'
self.assertContains(response, expected, status_code=200)
expected = '<tr><td>Bypronto</td><td>54.171.171.172</td></tr>'
self.assertContains(response, expected, status_code=200)
class ClientSiteAdminTest(TestCase):
def setUp(self):
admin = User.objects.create_superuser(
'admin',
'admin@test.com',
'password'
)
self.client.login(
username='admin',
password='password'
)
self.url = '/admin/clientsites/clientsite/'
def test_clientsite_admin_page_should_be_accessible(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
def test_clientsite_admin_page_should_name_and_domain_columns(self):
ClientSite.objects.create(
domain='www.prontomarketing.com'
)
response = self.client.get(self.url)
expected = '<div class="text"><a href="?o=1">Domain</a></div>'
self.assertContains(response, expected, status_code=200)
|
mit
|
[
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
6810,
8972,
199,
504,
8037,
14,
992,
492,
7146,
421,
199,
533,
6810,
8972,
774,
8,
1746,
304,
272,
347,
511,
63,
981,
63,
1222,
63,
1258,
2124,
8,
277,
304,
267,
1890,
2124,
275,
6810,
8972,
342,
267,
1890,
2124,
14,
2261,
275,
283,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
7,
398,
291,
14,
3334,
8,
1258,
2124,
14,
344,
9,
267,
1890,
2124,
14,
2117,
342,
267,
291,
14,
1815,
8,
1258,
2124,
14,
344,
9,
398,
1890,
2124,
275,
6810,
8972,
14,
1462,
14,
362,
8,
344,
29,
1258,
2124,
14,
344,
9,
267,
291,
14,
629,
8,
1258,
2124,
14,
2261,
12,
283,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
358,
421,
199,
533,
6810,
8972,
2768,
774,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
633,
275,
3837,
360,
1258,
8619,
358,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
1235,
63,
24669,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
1180,
63,
4525,
63,
1160,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
267,
291,
14,
19661,
8,
1310,
12,
283,
1258,
8619,
14,
1360,
358,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
7804,
63,
1213,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
398,
1420,
275,
2650,
1213,
30,
51,
12587,
543,
18482,
31,
1108,
1213,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2004,
63,
600,
29,
1840,
9,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
3352,
63,
1360,
63,
509,
63,
1258,
8619,
63,
4525,
590,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
398,
1420,
275,
2650,
72,
17,
30,
3041,
428,
4033,
1108,
72,
17,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
21519,
2535,
454,
2535,
273,
30,
7705,
1108,
273,
2535,
273,
30,
51,
12587,
543,
18482,
14069,
267,
1420,
847,
11936,
273,
2535,
273,
30,
7443,
1108,
273,
2957,
454,
2957,
21519,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2004,
63,
600,
29,
1840,
9,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
1131,
63,
9756,
63,
460,
63,
1074,
63,
692,
63,
32310,
63,
1045,
63,
527,
8,
277,
304,
267,
7146,
14,
1462,
14,
9377,
63,
981,
779,
288,
7146,
8,
354,
534,
48,
2641,
475,
413,
297,
3384,
534,
1477,
14,
2819,
14,
19,
14,
10456,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
499,
297,
3384,
534,
1477,
14,
2819,
14,
19,
14,
8845,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
650,
297,
3384,
534,
1477,
14,
6390,
14,
11432,
14,
2760,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
841,
297,
3384,
534,
1477,
14,
1822,
14,
1400,
14,
12768,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
959,
297,
3384,
534,
2528,
14,
17,
14,
708,
14,
1153,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1227,
297,
3384,
534,
1465,
14,
8306,
14,
2182,
14,
1085,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1520,
297,
3384,
534,
1477,
14,
11440,
14,
3129,
14,
20,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1695,
297,
3384,
534,
1477,
14,
12048,
14,
8867,
14,
1276,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1749,
297,
3384,
534,
1477,
14,
2819,
14,
19,
14,
3781,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1616,
297,
3384,
534,
1477,
14,
13593,
14,
13593,
14,
10419,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
4119,
297,
3384,
534,
2466,
14,
7498,
14,
2534,
14,
12632,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
3144,
297,
3384,
534,
1477,
14,
10860,
14,
1651,
14,
3328,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
4944,
297,
3384,
534,
1477,
14,
2819,
14,
2481,
14,
1229,
659,
267,
4794,
398,
6810,
8972,
14,
1462,
14,
9377,
63,
981,
779,
288,
6810,
8972,
8,
2261,
534,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
659,
288,
6810,
8972,
8,
2261,
534,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
659,
267,
4794,
398,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
398,
1420,
275,
2650,
454,
2535,
2076,
2535,
65,
4369,
628,
1014,
921,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
2,
283,
267,
1420,
847,
283,
1375,
19667,
2500,
1743,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
1108,
65,
2957,
2076,
3524,
267,
1420,
847,
2650,
2076,
3449,
628,
2326,
26,
8992,
31328,
1944,
1108,
2076,
2535,
2076,
30,
2595,
1108,
2076,
2957,
454,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2338,
29,
17,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
2076,
2535,
65,
4369,
628,
1014,
921,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
2,
283,
267,
1420,
847,
283,
1375,
19667,
2500,
1743,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
1108,
65,
2957,
2076,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2338,
29,
17,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
454,
2535,
2076,
2535,
65,
4369,
628,
1014,
921,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
2,
283,
267,
1420,
847,
283,
1375,
19667,
2500,
1743,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
1108,
65,
2957,
2076,
3524,
267,
1420,
847,
2650,
2076,
30,
12555,
1108,
2076,
2535,
2076,
30,
2595,
1108,
2076,
2957,
454,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2338,
29,
17,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650
] |
[
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
6810,
8972,
199,
504,
8037,
14,
992,
492,
7146,
421,
199,
533,
6810,
8972,
774,
8,
1746,
304,
272,
347,
511,
63,
981,
63,
1222,
63,
1258,
2124,
8,
277,
304,
267,
1890,
2124,
275,
6810,
8972,
342,
267,
1890,
2124,
14,
2261,
275,
283,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
7,
398,
291,
14,
3334,
8,
1258,
2124,
14,
344,
9,
267,
1890,
2124,
14,
2117,
342,
267,
291,
14,
1815,
8,
1258,
2124,
14,
344,
9,
398,
1890,
2124,
275,
6810,
8972,
14,
1462,
14,
362,
8,
344,
29,
1258,
2124,
14,
344,
9,
267,
291,
14,
629,
8,
1258,
2124,
14,
2261,
12,
283,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
358,
421,
199,
533,
6810,
8972,
2768,
774,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
633,
275,
3837,
360,
1258,
8619,
358,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
1235,
63,
24669,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
1180,
63,
4525,
63,
1160,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
267,
291,
14,
19661,
8,
1310,
12,
283,
1258,
8619,
14,
1360,
358,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
7804,
63,
1213,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
398,
1420,
275,
2650,
1213,
30,
51,
12587,
543,
18482,
31,
1108,
1213,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2004,
63,
600,
29,
1840,
9,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
3352,
63,
1360,
63,
509,
63,
1258,
8619,
63,
4525,
590,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
398,
1420,
275,
2650,
72,
17,
30,
3041,
428,
4033,
1108,
72,
17,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
21519,
2535,
454,
2535,
273,
30,
7705,
1108,
273,
2535,
273,
30,
51,
12587,
543,
18482,
14069,
267,
1420,
847,
11936,
273,
2535,
273,
30,
7443,
1108,
273,
2957,
454,
2957,
21519,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2004,
63,
600,
29,
1840,
9,
339,
347,
511,
63,
1258,
2124,
63,
5626,
63,
1131,
63,
9756,
63,
460,
63,
1074,
63,
692,
63,
32310,
63,
1045,
63,
527,
8,
277,
304,
267,
7146,
14,
1462,
14,
9377,
63,
981,
779,
288,
7146,
8,
354,
534,
48,
2641,
475,
413,
297,
3384,
534,
1477,
14,
2819,
14,
19,
14,
10456,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
499,
297,
3384,
534,
1477,
14,
2819,
14,
19,
14,
8845,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
650,
297,
3384,
534,
1477,
14,
6390,
14,
11432,
14,
2760,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
841,
297,
3384,
534,
1477,
14,
1822,
14,
1400,
14,
12768,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
959,
297,
3384,
534,
2528,
14,
17,
14,
708,
14,
1153,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1227,
297,
3384,
534,
1465,
14,
8306,
14,
2182,
14,
1085,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1520,
297,
3384,
534,
1477,
14,
11440,
14,
3129,
14,
20,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1695,
297,
3384,
534,
1477,
14,
12048,
14,
8867,
14,
1276,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1749,
297,
3384,
534,
1477,
14,
2819,
14,
19,
14,
3781,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
1616,
297,
3384,
534,
1477,
14,
13593,
14,
13593,
14,
10419,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
4119,
297,
3384,
534,
2466,
14,
7498,
14,
2534,
14,
12632,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
3144,
297,
3384,
534,
1477,
14,
10860,
14,
1651,
14,
3328,
659,
288,
7146,
8,
354,
534,
48,
2641,
475,
4944,
297,
3384,
534,
1477,
14,
2819,
14,
2481,
14,
1229,
659,
267,
4794,
398,
6810,
8972,
14,
1462,
14,
9377,
63,
981,
779,
288,
6810,
8972,
8,
2261,
534,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
659,
288,
6810,
8972,
8,
2261,
534,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
659,
267,
4794,
398,
1177,
275,
291,
14,
1258,
14,
362,
8,
277,
14,
633,
9,
398,
1420,
275,
2650,
454,
2535,
2076,
2535,
65,
4369,
628,
1014,
921,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
2,
283,
267,
1420,
847,
283,
1375,
19667,
2500,
1743,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
1108,
65,
2957,
2076,
3524,
267,
1420,
847,
2650,
2076,
3449,
628,
2326,
26,
8992,
31328,
1944,
1108,
2076,
2535,
2076,
30,
2595,
1108,
2076,
2957,
454,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2338,
29,
17,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
2076,
2535,
65,
4369,
628,
1014,
921,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
2,
283,
267,
1420,
847,
283,
1375,
19667,
2500,
1743,
1544,
14,
80,
2641,
475,
1657,
13800,
14,
957,
1108,
65,
2957,
2076,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2338,
29,
17,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
454,
2535,
2076,
2535,
65,
4369,
628,
1014,
921,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
2,
283,
267,
1420,
847,
283,
1375,
19667,
2500,
1743,
1544,
14,
24935,
20576,
335,
25751,
14,
957,
1108,
65,
2957,
2076,
3524,
267,
1420,
847,
2650,
2076,
30,
12555,
1108,
2076,
2535,
2076,
30,
2595,
1108,
2076,
2957,
454,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
12,
2338,
29,
17,
12,
2004,
63,
600,
29,
1840,
9,
398,
1420,
275,
2650,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
archifix/settings
|
sublime/Packages/mdpopups/st3/mdpopups/mdx/highlight.py
|
3
|
15749
|
"""
Highlight.
A library for managing code highlighting.
All Changes Copyright 2014-2017 Isaac Muse.
---
CodeHilite Extension for Python-Markdown
========================================
Adds code/syntax highlighting to standard Python-Markdown code blocks.
See <https://pythonhosted.org/Markdown/extensions/code_hilite.html>
for documentation.
Original code Copyright 2006-2008 [Waylan Limberg](http://achinghead.com/).
All changes Copyright 2008-2014 The Python Markdown Project
License: [BSD](http://www.opensource.org/licenses/bsd-license.php)
"""
from __future__ import absolute_import
from __future__ import unicode_literals
from markdown import Extension
from markdown.treeprocessors import Treeprocessor
from markdown import util as md_util
import copy
from collections import OrderedDict
import re
try:
from pygments import highlight
from pygments.lexers import get_lexer_by_name, guess_lexer
from pygments.formatters import find_formatter_class
HtmlFormatter = find_formatter_class('html')
pygments = True
except ImportError: # pragma: no cover
pygments = False
try:
from markdown.extensions.codehilite import CodeHiliteExtension
except Exception: # pragma: no cover
CodeHiliteExtension = None
CODE_WRAP = '<pre%s><code%s>%s</code></pre>'
CLASS_ATTR = ' class="%s"'
DEFAULT_CONFIG = {
'use_pygments': [
True,
'Use Pygments to highlight code blocks. '
'Disable if using a JavaScript library. '
'Default: True'
],
'guess_lang': [
False,
"Automatic language detection - Default: True"
],
'css_class': [
'highlight',
"CSS class to apply to wrapper element."
],
'pygments_style': [
'default',
'Pygments HTML Formatter Style '
'(color scheme) - Default: default'
],
'noclasses': [
False,
'Use inline styles instead of CSS classes - '
'Default false'
],
'linenums': [
False,
'Display line numbers in block code output (not inline) - Default: False'
],
'extend_pygments_lang': [
[],
'Extend pygments language with special language entry - Default: {}'
]
}
multi_space = re.compile(r'(?<= ) {2,}')
def replace_nbsp(m):
"""Replace spaces with nbsp."""
return ' ' * len(m.group(0))
if pygments:
html_re = re.compile(
r'''(?x)
(?P<start><span [^<>]+>)|(?P<content>[^<>]+)|(?P<end></span>)
'''
)
class InlineHtmlFormatter(HtmlFormatter):
"""Format the code blocks."""
def wrap(self, source, outfile):
"""Overload wrap."""
return self._wrap_code(source)
def _wrap_code(self, source):
"""Return source, but do not wrap in inline <code> block."""
yield 0, ''
for i, t in source:
yield i, t.strip()
yield 0, ''
class SublimeInlineHtmlFormatter(HtmlFormatter):
"""Format the code blocks."""
def wrap(self, source, outfile):
"""Overload wrap."""
return self._wrap_code(source)
def _wrap_code(self, source):
"""
Wrap the pygmented code.
Sublime popups don't really support 'code', but since it doesn't
hurt anything, we leave it in for the possiblity of future support.
We get around the lack of proper 'code' support by converting any
spaces after the intial space to nbsp. We go ahead and convert tabs
to 4 spaces as well.
"""
yield 0, ''
for i, t in source:
text = ''
matched = False
for m in html_re.finditer(t):
matched = True
if m.group(1):
text += m.group(1)
elif m.group(3):
text += m.group(3)
else:
text += multi_space.sub(
replace_nbsp, m.group(2).replace('\t', ' ' * 4)
)
if not matched:
text = multi_space.sub(
replace_nbsp, t.replace('\t', ' ' * 4)
)
yield i, text
yield 0, ''
class SublimeBlockFormatter(HtmlFormatter):
"""Format the code blocks."""
def wrap(self, source, outfile):
"""Overload wrap."""
return self._wrap_code(source)
def _wrap_code(self, source):
"""
Wrap the pygmented code.
Sublime popups don't really support 'pre', but since it doesn't
hurt anything, we leave it in for the possiblity of future support.
We get around the lack of proper 'pre' suppurt by converting any
spaces after the intial space to nbsp. We go ahead and convert tabs
to 4 spaces as well. We also manually inject line breaks.
"""
yield 0, '<div class="%s"><pre>' % self.cssclass
for i, t in source:
text = ''
matched = False
for m in html_re.finditer(t):
matched = True
if m.group(1):
text += m.group(1)
elif m.group(3):
text += m.group(3)
else:
text += m.group(2).replace('\t', ' ' * 4).replace(' ', ' ')
if not matched:
text = t.replace('\t', ' ' * 4).replace(' ', ' ')
if i == 1:
# it's a line of formatted code
text += '<br>'
yield i, text
yield 0, '</pre></div>'
class SublimeWrapBlockFormatter(HtmlFormatter):
"""Format the code blocks."""
def wrap(self, source, outfile):
"""Overload wrap."""
return self._wrap_code(source)
def _wrap_code(self, source):
"""
Wrap the pygmented code.
Sublime popups don't really support 'pre', but since it doesn't
hurt anything, we leave it in for the possiblity of future support.
We get around the lack of proper 'pre' suppurt by converting any
spaces after the intial space to nbsp. We go ahead and convert tabs
to 4 spaces as well. We also manually inject line breaks.
"""
yield 0, '<div class="%s"><pre>' % self.cssclass
for i, t in source:
text = ''
matched = False
for m in html_re.finditer(t):
matched = True
if m.group(1):
text += m.group(1)
elif m.group(3):
text += m.group(3)
else:
text += multi_space.sub(
replace_nbsp, m.group(2).replace('\t', ' ' * 4)
)
if not matched:
text = multi_space.sub(
replace_nbsp, t.replace('\t', ' ' * 4)
)
if i == 1:
# it's a line of formatted code
text += '<br>'
yield i, text
yield 0, '</pre></div>'
class Highlight(object):
"""Highlight class."""
def __init__(
self, guess_lang=True, pygments_style='default', use_pygments=True,
noclasses=False, extend_pygments_lang=None, linenums=False
):
"""Initialize."""
self.guess_lang = guess_lang
self.pygments_style = pygments_style
self.use_pygments = use_pygments
self.noclasses = noclasses
self.linenums = linenums
self.linenums_style = 'table'
self.sublime_hl = Highlight.sublime_hl
self.sublime_wrap = Highlight.sublime_wrap
if extend_pygments_lang is None:
extend_pygments_lang = []
self.extend_pygments_lang = {}
for language in extend_pygments_lang:
if isinstance(language, (dict, OrderedDict)):
name = language.get('name')
if name is not None and name not in self.extend_pygments_lang:
self.extend_pygments_lang[name] = [
language.get('lang'),
language.get('options', {})
]
@classmethod
def set_sublime_vars(cls, sublime_hl, sublime_wrap):
"""Set Sublime_vars."""
cls.sublime_hl = sublime_hl
cls.sublime_wrap = sublime_wrap
def get_extended_language(self, language):
"""Get extended language."""
return self.extend_pygments_lang.get(language, (language, {}))
def get_lexer(self, src, language):
"""Get the Pygments lexer."""
if language:
language, lexer_options = self.get_extended_language(language)
else:
lexer_options = {}
# Try and get lexer by the name given.
try:
lexer = get_lexer_by_name(language, **lexer_options)
except Exception:
lexer = None
if lexer is None:
if self.guess_lang:
lexer = guess_lexer(src)
else:
lexer = get_lexer_by_name('text')
return lexer
def escape(self, txt, code_wrap):
"""Basic html escaping."""
txt = txt.replace('&', '&')
txt = txt.replace('<', '<')
txt = txt.replace('>', '>')
txt = txt.replace('"', '"')
# Special format for sublime.
if code_wrap:
txt = multi_space.sub(replace_nbsp, txt.replace('\t', ' ' * 4))
else:
txt = txt.replace('\t', ' ' * 4)
txt = txt.replace(' ', ' ')
return txt
def highlight(
self, src, language, css_class='highlight', hl_lines=None,
linestart=-1, linestep=-1, linespecial=-1, inline=False
):
"""Highlight code."""
# Convert with Pygments.
if self.sublime_hl[0]:
# Sublime highlight
code = self.sublime_hl[1].syntax_highlight(
src, language, inline=inline, no_wrap=inline, code_wrap=(not inline and self.sublime_wrap)
)
if inline:
class_str = css_class
elif pygments and self.use_pygments:
# Setup language lexer.
lexer = self.get_lexer(src, language)
# Setup line specific settings.
linenums = self.linenums_style if (self.linenums or linestart >= 0) and not inline > 0 else False
if not linenums or linestep < 1:
linestep = 1
if not linenums or linestart < 1:
linestart = 1
if not linenums or linespecial < 0:
linespecial = 0
if hl_lines is None or inline:
hl_lines = []
# Setup formatter
if inline:
html_formatter = SublimeInlineHtmlFormatter
elif self.sublime_wrap:
html_formatter = SublimeWrapBlockFormatter
else:
html_formatter = SublimeBlockFormatter
formatter = html_formatter(
cssclass=css_class,
linenos=linenums,
linenostart=linestart,
linenostep=linestep,
linenospecial=linespecial,
style=self.pygments_style,
noclasses=self.noclasses,
hl_lines=hl_lines
)
# Convert
code = highlight(src, lexer, formatter)
if inline:
class_str = css_class
elif inline:
# Format inline code for a JavaScript Syntax Highlighter by specifying language.
code = self.escape(src, True)
classes = [css_class] if css_class else []
if language:
classes.append('language-%s' % language)
class_str = ''
if len(classes):
class_str = ' '.join(classes)
else:
# Format block code for a JavaScript Syntax Highlighter by specifying language.
classes = []
linenums = self.linenums_style if (self.linenums or linestart >= 0) and not inline > 0 else False
if language:
classes.append('language-%s' % language)
if linenums:
classes.append('linenums')
class_str = ''
if classes:
class_str = CLASS_ATTR % ' '.join(classes)
higlight_class = (CLASS_ATTR % css_class) if css_class else ''
code = CODE_WRAP % (higlight_class, class_str, self.escape(src, self.sublime_wrap))
if inline:
el = md_util.etree.Element('code', {'class': class_str} if class_str else {})
el.text = code
return el
else:
return code.strip()
def get_hl_settings(md):
"""Get the specified extension."""
target = None
for ext in md.registeredExtensions:
if isinstance(ext, HighlightExtension):
target = ext.getConfigs()
break
if target is None:
for ext in md.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
target = ext.getConfigs()
break
if target is None:
target = {}
config_clone = copy.deepcopy(DEFAULT_CONFIG)
for k, v in config_clone.items():
target[k] = config_clone[k][0]
return target
class HighlightTreeprocessor(Treeprocessor):
"""Highlight source code in code blocks."""
def run(self, root):
"""Find code blocks and store in `htmlStash`."""
blocks = root.iter('pre')
for block in blocks:
if len(block) == 1 and block[0].tag == 'code':
code = Highlight(
guess_lang=self.config['guess_lang'],
pygments_style=self.config['pygments_style'],
use_pygments=self.config['use_pygments'],
noclasses=self.config['noclasses'],
linenums=self.config['linenums'],
extend_pygments_lang=self.config['extend_pygments_lang']
)
placeholder = self.markdown.htmlStash.store(
code.highlight(
block[0].text,
'',
self.config['css_class']
),
safe=True
)
# Clear codeblock in etree instance
block.clear()
# Change to p element which will later
# be removed when inserting raw html
block.tag = 'p'
block.text = placeholder
class HighlightExtension(Extension):
"""Configure highlight settings globally."""
def __init__(self, *args, **kwargs):
"""Initialize."""
self.config = copy.deepcopy(DEFAULT_CONFIG)
super(HighlightExtension, self).__init__(*args, **kwargs)
def extendMarkdown(self, md, md_globals):
"""Add support for code highlighting."""
Highlight.set_sublime_vars(md.sublime_hl, md.sublime_wrap)
ht = HighlightTreeprocessor(md)
ht.config = self.getConfigs()
md.treeprocessors.add("indent-highlight", ht, "<inline")
md.registerExtension(self)
def makeExtension(*args, **kwargs):
"""Return extension."""
return HighlightExtension(*args, **kwargs)
|
mit
|
[
624,
199,
11688,
4040,
14,
199,
199,
33,
3555,
367,
28453,
1233,
22437,
14,
199,
199,
2422,
18784,
1898,
6927,
13,
10680,
473,
2231,
645,
603,
1180,
14,
199,
199,
2595,
199,
199,
3034,
40,
1638,
266,
13282,
367,
2018,
13,
30916,
199,
2486,
763,
199,
199,
14995,
1233,
15,
7093,
22437,
370,
4465,
2018,
13,
30916,
1233,
5664,
14,
199,
199,
9295,
665,
2859,
921,
1548,
24127,
14,
1308,
15,
30916,
15,
5359,
15,
600,
63,
72,
1638,
266,
14,
1360,
30,
199,
509,
3794,
14,
199,
199,
17286,
1233,
1898,
8315,
13,
9300,
359,
25544,
1502,
24157,
976,
71,
8738,
1014,
921,
23302,
2993,
14,
957,
15,
680,
199,
199,
2422,
4493,
1898,
9079,
13,
7280,
710,
2018,
24537,
7290,
199,
199,
3761,
26,
359,
15400,
8738,
1014,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
9,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
18502,
492,
13282,
199,
504,
18502,
14,
2350,
10547,
492,
12178,
6459,
199,
504,
18502,
492,
4884,
465,
6128,
63,
1974,
199,
646,
1331,
199,
504,
5055,
492,
8773,
199,
646,
295,
199,
893,
26,
272,
687,
13277,
492,
11850,
272,
687,
13277,
14,
12245,
492,
664,
63,
11729,
63,
991,
63,
354,
12,
9519,
63,
11729,
272,
687,
13277,
14,
24270,
492,
2342,
63,
8911,
63,
533,
272,
20880,
7772,
275,
2342,
63,
8911,
63,
533,
360,
1360,
358,
272,
13277,
275,
715,
199,
2590,
3545,
26,
221,
327,
11942,
26,
949,
8486,
272,
13277,
275,
756,
199,
893,
26,
272,
687,
18502,
14,
5359,
14,
600,
72,
1638,
266,
492,
5495,
40,
1638,
266,
6382,
199,
2590,
2186,
26,
221,
327,
11942,
26,
949,
8486,
272,
5495,
40,
1638,
266,
6382,
275,
488,
199,
199,
6012,
63,
23824,
275,
2650,
657,
5,
83,
2535,
600,
5,
83,
6598,
83,
1108,
600,
2957,
657,
3524,
199,
6885,
63,
5280,
275,
283,
1021,
5961,
83,
4507,
199,
3472,
63,
5569,
275,
469,
272,
283,
1180,
63,
12173,
356,
359,
267,
715,
12,
267,
283,
6119,
14493,
370,
11850,
1233,
5664,
14,
283,
267,
283,
13707,
340,
1808,
282,
15250,
3555,
14,
283,
267,
283,
2698,
26,
715,
7,
272,
2156,
272,
283,
11636,
63,
4159,
356,
359,
267,
756,
12,
267,
298,
3358,
3889,
2637,
15212,
446,
3758,
26,
715,
2,
272,
2156,
272,
283,
3919,
63,
533,
356,
359,
267,
283,
14337,
297,
267,
298,
14391,
1021,
370,
4838,
370,
4975,
1819,
2122,
272,
2156,
272,
283,
12173,
63,
2487,
356,
359,
267,
283,
885,
297,
267,
283,
2713,
4664,
4163,
31084,
19442,
283,
267,
8189,
2326,
5687,
9,
446,
3758,
26,
849,
7,
272,
2156,
272,
283,
889,
2888,
356,
359,
267,
756,
12,
267,
283,
6119,
8308,
15725,
3140,
402,
15750,
3992,
446,
283,
267,
283,
2698,
3055,
7,
272,
2156,
272,
283,
19466,
83,
356,
359,
267,
756,
12,
267,
283,
7687,
1004,
5579,
315,
1853,
1233,
1072,
334,
1397,
8308,
9,
446,
3758,
26,
756,
7,
272,
2156,
272,
283,
2880,
63,
12173,
63,
4159,
356,
359,
267,
990,
267,
283,
30775,
13277,
2637,
543,
4539,
2637,
2397,
446,
3758,
26,
1052,
7,
272,
1622,
199,
93,
199,
199,
3029,
63,
2638,
275,
295,
14,
2014,
8,
82,
10120,
12932,
776,
469,
18,
12,
12216,
421,
199,
318,
3350,
63,
10758,
8,
77,
304,
272,
408,
11328,
7883,
543,
8526,
681,
1041,
339,
372,
7673,
10758,
8942,
627,
822,
8,
77,
14,
923,
8,
16,
430,
421,
199,
692,
13277,
26,
272,
3517,
63,
264,
275,
295,
14,
2014,
8,
267,
519,
2344,
2229,
88,
9,
267,
7558,
48,
28,
928,
2535,
3751,
359,
62,
16137,
2807,
30,
25963,
48,
28,
1317,
13489,
16137,
2807,
25963,
48,
28,
500,
2957,
3751,
18956,
267,
1449,
272,
776,
339,
1021,
24789,
12957,
7772,
8,
12957,
7772,
304,
267,
408,
3484,
314,
1233,
5664,
1041,
398,
347,
4816,
8,
277,
12,
1350,
12,
4386,
304,
288,
408,
5674,
912,
4816,
1041,
953,
372,
291,
423,
3823,
63,
600,
8,
1365,
9,
398,
347,
485,
3823,
63,
600,
8,
277,
12,
1350,
304,
288,
408,
1767,
1350,
12,
1325,
886,
440,
4816,
315,
8308,
665,
600,
30,
1853,
1041,
953,
1995,
378,
12,
2125,
288,
367,
284,
12,
307,
315,
1350,
26,
355,
1995,
284,
12,
307,
14,
1913,
342,
288,
1995,
378,
12,
2125,
339,
1021,
4804,
18687,
10307,
12957,
7772,
8,
12957,
7772,
304,
267,
408,
3484,
314,
1233,
5664,
1041,
398,
347,
4816,
8,
277,
12,
1350,
12,
4386,
304,
288,
408,
5674,
912,
4816,
1041,
953,
372,
291,
423,
3823,
63,
600,
8,
1365,
9,
398,
347,
485,
3823,
63,
600,
8,
277,
12,
1350,
304,
288,
408,
288,
20322,
314,
1134,
71,
2509,
1233,
14,
953,
4804,
18687,
4560,
15203,
2793,
1133,
7710,
2291,
283,
600,
297,
1325,
3967,
652,
3181,
1133,
288,
394,
20471,
7003,
12,
781,
10137,
652,
315,
367,
314,
2086,
6637,
5075,
402,
6466,
2291,
14,
288,
2136,
664,
6818,
314,
29098,
402,
5576,
283,
600,
7,
2291,
701,
13806,
1263,
288,
7883,
2410,
314,
315,
1009,
4601,
370,
8526,
681,
14,
221,
2136,
2621,
23417,
436,
3957,
12187,
288,
370,
841,
7883,
465,
5521,
14,
288,
408,
953,
1995,
378,
12,
2125,
288,
367,
284,
12,
307,
315,
1350,
26,
355,
1318,
275,
2125,
355,
7838,
275,
756,
355,
367,
333,
315,
3517,
63,
264,
14,
19373,
8,
84,
304,
490,
7838,
275,
715,
490,
340,
333,
14,
923,
8,
17,
304,
717,
1318,
847,
333,
14,
923,
8,
17,
9,
490,
916,
333,
14,
923,
8,
19,
304,
717,
1318,
847,
333,
14,
923,
8,
19,
9,
490,
587,
26,
717,
1318,
847,
3510,
63,
2638,
14,
954,
8,
1169,
3350,
63,
10758,
12,
333,
14,
923,
8,
18,
680,
1814,
2258,
84,
297,
283,
283,
627,
841,
9,
717,
776,
355,
340,
440,
7838,
26,
490,
1318,
275,
3510,
63,
2638,
14,
954,
8,
717,
3350,
63,
10758,
12,
307,
14,
1814,
2258,
84,
297,
283,
283,
627,
841,
9,
490,
776,
355,
1995,
284,
12,
1318,
288,
1995,
378,
12,
2125,
339,
1021
] |
[
199,
11688,
4040,
14,
199,
199,
33,
3555,
367,
28453,
1233,
22437,
14,
199,
199,
2422,
18784,
1898,
6927,
13,
10680,
473,
2231,
645,
603,
1180,
14,
199,
199,
2595,
199,
199,
3034,
40,
1638,
266,
13282,
367,
2018,
13,
30916,
199,
2486,
763,
199,
199,
14995,
1233,
15,
7093,
22437,
370,
4465,
2018,
13,
30916,
1233,
5664,
14,
199,
199,
9295,
665,
2859,
921,
1548,
24127,
14,
1308,
15,
30916,
15,
5359,
15,
600,
63,
72,
1638,
266,
14,
1360,
30,
199,
509,
3794,
14,
199,
199,
17286,
1233,
1898,
8315,
13,
9300,
359,
25544,
1502,
24157,
976,
71,
8738,
1014,
921,
23302,
2993,
14,
957,
15,
680,
199,
199,
2422,
4493,
1898,
9079,
13,
7280,
710,
2018,
24537,
7290,
199,
199,
3761,
26,
359,
15400,
8738,
1014,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
9,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
18502,
492,
13282,
199,
504,
18502,
14,
2350,
10547,
492,
12178,
6459,
199,
504,
18502,
492,
4884,
465,
6128,
63,
1974,
199,
646,
1331,
199,
504,
5055,
492,
8773,
199,
646,
295,
199,
893,
26,
272,
687,
13277,
492,
11850,
272,
687,
13277,
14,
12245,
492,
664,
63,
11729,
63,
991,
63,
354,
12,
9519,
63,
11729,
272,
687,
13277,
14,
24270,
492,
2342,
63,
8911,
63,
533,
272,
20880,
7772,
275,
2342,
63,
8911,
63,
533,
360,
1360,
358,
272,
13277,
275,
715,
199,
2590,
3545,
26,
221,
327,
11942,
26,
949,
8486,
272,
13277,
275,
756,
199,
893,
26,
272,
687,
18502,
14,
5359,
14,
600,
72,
1638,
266,
492,
5495,
40,
1638,
266,
6382,
199,
2590,
2186,
26,
221,
327,
11942,
26,
949,
8486,
272,
5495,
40,
1638,
266,
6382,
275,
488,
199,
199,
6012,
63,
23824,
275,
2650,
657,
5,
83,
2535,
600,
5,
83,
6598,
83,
1108,
600,
2957,
657,
3524,
199,
6885,
63,
5280,
275,
283,
1021,
5961,
83,
4507,
199,
3472,
63,
5569,
275,
469,
272,
283,
1180,
63,
12173,
356,
359,
267,
715,
12,
267,
283,
6119,
14493,
370,
11850,
1233,
5664,
14,
283,
267,
283,
13707,
340,
1808,
282,
15250,
3555,
14,
283,
267,
283,
2698,
26,
715,
7,
272,
2156,
272,
283,
11636,
63,
4159,
356,
359,
267,
756,
12,
267,
298,
3358,
3889,
2637,
15212,
446,
3758,
26,
715,
2,
272,
2156,
272,
283,
3919,
63,
533,
356,
359,
267,
283,
14337,
297,
267,
298,
14391,
1021,
370,
4838,
370,
4975,
1819,
2122,
272,
2156,
272,
283,
12173,
63,
2487,
356,
359,
267,
283,
885,
297,
267,
283,
2713,
4664,
4163,
31084,
19442,
283,
267,
8189,
2326,
5687,
9,
446,
3758,
26,
849,
7,
272,
2156,
272,
283,
889,
2888,
356,
359,
267,
756,
12,
267,
283,
6119,
8308,
15725,
3140,
402,
15750,
3992,
446,
283,
267,
283,
2698,
3055,
7,
272,
2156,
272,
283,
19466,
83,
356,
359,
267,
756,
12,
267,
283,
7687,
1004,
5579,
315,
1853,
1233,
1072,
334,
1397,
8308,
9,
446,
3758,
26,
756,
7,
272,
2156,
272,
283,
2880,
63,
12173,
63,
4159,
356,
359,
267,
990,
267,
283,
30775,
13277,
2637,
543,
4539,
2637,
2397,
446,
3758,
26,
1052,
7,
272,
1622,
199,
93,
199,
199,
3029,
63,
2638,
275,
295,
14,
2014,
8,
82,
10120,
12932,
776,
469,
18,
12,
12216,
421,
199,
318,
3350,
63,
10758,
8,
77,
304,
272,
408,
11328,
7883,
543,
8526,
681,
1041,
339,
372,
7673,
10758,
8942,
627,
822,
8,
77,
14,
923,
8,
16,
430,
421,
199,
692,
13277,
26,
272,
3517,
63,
264,
275,
295,
14,
2014,
8,
267,
519,
2344,
2229,
88,
9,
267,
7558,
48,
28,
928,
2535,
3751,
359,
62,
16137,
2807,
30,
25963,
48,
28,
1317,
13489,
16137,
2807,
25963,
48,
28,
500,
2957,
3751,
18956,
267,
1449,
272,
776,
339,
1021,
24789,
12957,
7772,
8,
12957,
7772,
304,
267,
408,
3484,
314,
1233,
5664,
1041,
398,
347,
4816,
8,
277,
12,
1350,
12,
4386,
304,
288,
408,
5674,
912,
4816,
1041,
953,
372,
291,
423,
3823,
63,
600,
8,
1365,
9,
398,
347,
485,
3823,
63,
600,
8,
277,
12,
1350,
304,
288,
408,
1767,
1350,
12,
1325,
886,
440,
4816,
315,
8308,
665,
600,
30,
1853,
1041,
953,
1995,
378,
12,
2125,
288,
367,
284,
12,
307,
315,
1350,
26,
355,
1995,
284,
12,
307,
14,
1913,
342,
288,
1995,
378,
12,
2125,
339,
1021,
4804,
18687,
10307,
12957,
7772,
8,
12957,
7772,
304,
267,
408,
3484,
314,
1233,
5664,
1041,
398,
347,
4816,
8,
277,
12,
1350,
12,
4386,
304,
288,
408,
5674,
912,
4816,
1041,
953,
372,
291,
423,
3823,
63,
600,
8,
1365,
9,
398,
347,
485,
3823,
63,
600,
8,
277,
12,
1350,
304,
288,
408,
288,
20322,
314,
1134,
71,
2509,
1233,
14,
953,
4804,
18687,
4560,
15203,
2793,
1133,
7710,
2291,
283,
600,
297,
1325,
3967,
652,
3181,
1133,
288,
394,
20471,
7003,
12,
781,
10137,
652,
315,
367,
314,
2086,
6637,
5075,
402,
6466,
2291,
14,
288,
2136,
664,
6818,
314,
29098,
402,
5576,
283,
600,
7,
2291,
701,
13806,
1263,
288,
7883,
2410,
314,
315,
1009,
4601,
370,
8526,
681,
14,
221,
2136,
2621,
23417,
436,
3957,
12187,
288,
370,
841,
7883,
465,
5521,
14,
288,
408,
953,
1995,
378,
12,
2125,
288,
367,
284,
12,
307,
315,
1350,
26,
355,
1318,
275,
2125,
355,
7838,
275,
756,
355,
367,
333,
315,
3517,
63,
264,
14,
19373,
8,
84,
304,
490,
7838,
275,
715,
490,
340,
333,
14,
923,
8,
17,
304,
717,
1318,
847,
333,
14,
923,
8,
17,
9,
490,
916,
333,
14,
923,
8,
19,
304,
717,
1318,
847,
333,
14,
923,
8,
19,
9,
490,
587,
26,
717,
1318,
847,
3510,
63,
2638,
14,
954,
8,
1169,
3350,
63,
10758,
12,
333,
14,
923,
8,
18,
680,
1814,
2258,
84,
297,
283,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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
] |
konefalg/whylog
|
whylog/tests/test_regex_assistant/__init__.py
|
5
|
5707
|
import re
from unittest import TestCase
from whylog.assistant.regex_assistant import RegexAssistant
from whylog.assistant.regex_assistant.exceptions import NotMatchingRegexError
from whylog.assistant.regex_assistant.regex import (
create_date_regex, create_obvious_regex, regex_from_group_spans, regex_groups, verify_regex
)
from whylog.assistant.span import Span
from whylog.assistant.span_list import SpanList
from whylog.assistant.spans_finding import (
_find_date_spans_by_force, find_date_spans, find_spans_by_regex
)
from whylog.front.utils import FrontInput
class TestBase(TestCase):
def verify_regex_match(self, regex, line, wanted_groups=None):
try:
groups = regex_groups(regex, line)
if wanted_groups is not None:
assert groups == wanted_groups
except NotMatchingRegexError as e:
self.fail(e)
def verify_regex_not_match(self, regex, line):
self.assertRaises(NotMatchingRegexError, verify_regex, regex, line)
class TestRegexAssistant(TestBase):
def test_guess_pattern_matches(self):
line = r'2015-12-03 or [10/Oct/1999 21:15:05 +0500] "GET /index.html HTTP/1.0" 200 1043'
front_input = FrontInput(0, line, 0)
line_id = 1
ra = RegexAssistant()
ra.add_line(line_id, front_input)
pattern_matches = ra.guess_pattern_matches(line_id)
assert pattern_matches
guessed_regexes = [pattern_match.pattern for pattern_match in pattern_matches.values()]
for guessed_regex in guessed_regexes:
self.verify_regex_match(guessed_regex, line)
def test_update_by_pattern(self):
ra = RegexAssistant()
line = "Hello, Whylog guy!"
line_id = 1
ra.add_line(line_id, FrontInput(0, line, 0))
unlikely_regex = r'^Hello, (Whylog (team|guy)!)$'
assert not ra.regex_matches[line_id].regex == unlikely_regex
ra.update_by_pattern(line_id, unlikely_regex)
assert ra.regex_matches[line_id].regex == unlikely_regex
class TestBasic(TestBase):
def test_verify_regex_success(self):
line = r"2015-12-03 12:11:00 Data is missing on comp21"
regex = r"^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d) Data is missing on (.*)$"
self.verify_regex_match(regex, line, ('2015-12-03 12:11:00', 'comp21'))
def test_verify_regex_fail(self):
line = r"2015-12-03 12:11:00 Data is missing"
regex = r"^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d) Data is missing on (.*)$"
self.verify_regex_not_match(regex, line)
def test_create_obvious_regex(self):
line = r".^$*x+x{5}?\*[x]x|y(x)(?iLmsux)(?:x)(?P<name>x)(?#x)(?<!x)\4\b\A"
obvious_regex = create_obvious_regex(line)
assert (
obvious_regex == r"\.\^\$\*x\+x\{5\}\?\\\*\[x\]x\|y\(x\)\(\?iLmsux\)\(\?:x\)"
r"\(\?P<name>x\)\(\?#x\)\(\?<!x\)\\4\\b\\A"
)
self.verify_regex_match(obvious_regex, line, ())
def test_create_date_regex(self):
date = '10/Oct/1999:21:15:05'
regex = create_date_regex(date)
self.verify_regex_match(regex, date, ())
not_matching_dates = [
date + " ", date + ":", "1" + date, '10/10/1999:21:15:05', '10/Oct/199:21:15:05',
'10/Oct1/1999:21:15:05', '10/Oct/1999:21:15:05PM', '10/Oct/1999:021:15:05',
'10\Oct\1999:21:15:05'
]
for not_matching_date in not_matching_dates:
self.verify_regex_not_match(regex, not_matching_date)
matching_dates = [
'1/Oct/1999:21:15:05', '10/October/1999:21:15:05', '10/Octyyy/1999:21:15:05',
'10/O/1999:21:15:05', '1/Oct/1999:2:1:0'
]
for matching_date in matching_dates:
self.verify_regex_match(regex, matching_date)
def test_find_spans_by_regex(self):
regexes = dict((re.compile(regex), regex) for regex in [r"\d+-\d+-\d\d", r"comp\d\d"])
text = r"2015-12-03 Data migration from comp36 to comp21 failed"
spans = find_spans_by_regex(regexes, text)
assert len(spans) == 3
spans = SpanList(spans).sort_by_start_and_end()
groups = [text[s.start:s.end] for s in spans]
assert groups[0] == '2015-12-03'
assert groups[1] == 'comp36'
assert groups[2] == 'comp21'
def test_find_date_spans_by_force(self):
text = r'2015-12-03 or [10/Oct/1999:21:15:05 +0500] "GET /index.html HTTP/1.0" 200 1043'
spans = _find_date_spans_by_force(text)
assert len(spans) == 3
spans = SpanList(spans).sort_by_start_and_end()
dates = [text[s.start:s.end] for s in spans]
assert dates[0] == '2015-12-03'
assert dates[1] == '10/Oct/1999'
assert dates[2] == '21:15:05 +0500'
def test_find_date_spans(self):
raw_date_regex = r"\d+/[a-zA-z]+/\d+:\d+:\d+:\d+ \+\d+"
date_regexes = {re.compile(raw_date_regex): raw_date_regex}
text = r'2015-12-03 or [10/Oct/1999:21:15:05 +0500] "GET /index.html HTTP/1.0" 200 1043'
spans = find_date_spans(text, date_regexes)
assert len(spans) == 2
spans = spans.sort_by_start_and_end()
dates = [text[s.start:s.end] for s in spans]
assert dates[0] == '2015-12-03'
assert dates[1] == '10/Oct/1999:21:15:05 +0500'
def test_regex_from_group_spans(self):
text = r'Error on comp21'
regex = r'Error on (comp(\d\d))'
span_comp = Span(9, 15, pattern=r'comp(\d\d)')
span_number = Span(13, 15, pattern=r'\d\d')
group_spans = SpanList([span_comp, span_number])
regex_from_groups = regex_from_group_spans(group_spans, text)
assert regex == regex_from_groups
|
bsd-3-clause
|
[
646,
295,
199,
504,
2882,
492,
7640,
199,
199,
504,
10842,
793,
14,
7310,
14,
3821,
63,
7310,
492,
12939,
24486,
199,
504,
10842,
793,
14,
7310,
14,
3821,
63,
7310,
14,
3924,
492,
2832,
14215,
5103,
547,
199,
504,
10842,
793,
14,
7310,
14,
3821,
63,
7310,
14,
3821,
492,
334,
272,
1218,
63,
602,
63,
3821,
12,
1218,
63,
2873,
2971,
63,
3821,
12,
5163,
63,
504,
63,
923,
63,
681,
796,
12,
5163,
63,
2634,
12,
4911,
63,
3821,
199,
9,
199,
504,
10842,
793,
14,
7310,
14,
3751,
492,
32091,
199,
504,
10842,
793,
14,
7310,
14,
3751,
63,
513,
492,
32091,
1296,
199,
504,
10842,
793,
14,
7310,
14,
681,
796,
63,
1623,
316,
492,
334,
272,
485,
1623,
63,
602,
63,
681,
796,
63,
991,
63,
3990,
12,
2342,
63,
602,
63,
681,
796,
12,
2342,
63,
681,
796,
63,
991,
63,
3821,
199,
9,
199,
504,
10842,
793,
14,
14708,
14,
1208,
492,
481,
82,
1888,
3205,
421,
199,
533,
1379,
1563,
8,
1746,
304,
272,
347,
4911,
63,
3821,
63,
1431,
8,
277,
12,
5163,
12,
1004,
12,
13632,
63,
2634,
29,
403,
304,
267,
862,
26,
288,
4652,
275,
5163,
63,
2634,
8,
3821,
12,
1004,
9,
288,
340,
13632,
63,
2634,
365,
440,
488,
26,
355,
702,
4652,
508,
13632,
63,
2634,
267,
871,
2832,
14215,
5103,
547,
465,
325,
26,
288,
291,
14,
1633,
8,
69,
9,
339,
347,
4911,
63,
3821,
63,
1397,
63,
1431,
8,
277,
12,
5163,
12,
1004,
304,
267,
291,
14,
1855,
8,
1763,
14215,
5103,
547,
12,
4911,
63,
3821,
12,
5163,
12,
1004,
9,
421,
199,
533,
1379,
5103,
24486,
8,
14440,
304,
272,
347,
511,
63,
11636,
63,
3401,
63,
6742,
8,
277,
304,
267,
1004,
275,
519,
7,
7806,
13,
713,
13,
1644,
503,
359,
709,
15,
17584,
15,
16278,
7829,
26,
1046,
26,
1717,
435,
1717,
383,
61,
298,
2970,
1182,
1080,
14,
1360,
3101,
15,
17,
14,
16,
2,
1926,
413,
5882,
7,
267,
13738,
63,
1210,
275,
481,
82,
1888,
3205,
8,
16,
12,
1004,
12,
378,
9,
267,
1004,
63,
344,
275,
413,
267,
660,
275,
12939,
24486,
342,
267,
660,
14,
525,
63,
604,
8,
604,
63,
344,
12,
13738,
63,
1210,
9,
267,
3851,
63,
6742,
275,
660,
14,
11636,
63,
3401,
63,
6742,
8,
604,
63,
344,
9,
267,
702,
3851,
63,
6742,
267,
29950,
63,
29283,
275,
359,
3401,
63,
1431,
14,
3401,
367,
3851,
63,
1431,
315,
3851,
63,
6742,
14,
1459,
5106,
267,
367,
29950,
63,
3821,
315,
29950,
63,
29283,
26,
288,
291,
14,
4712,
63,
3821,
63,
1431,
8,
71,
10138,
939,
63,
3821,
12,
1004,
9,
339,
347,
511,
63,
873,
63,
991,
63,
3401,
8,
277,
304,
267,
660,
275,
12939,
24486,
342,
267,
1004,
275,
298,
6257,
12,
6827,
793,
8129,
89,
9539,
267,
1004,
63,
344,
275,
413,
267,
660,
14,
525,
63,
604,
8,
604,
63,
344,
12,
481,
82,
1888,
3205,
8,
16,
12,
1004,
12,
378,
430,
267,
625,
24227,
63,
3821,
275,
519,
4289,
6257,
12,
334,
55,
3577,
793,
334,
5969,
92,
6051,
89,
9,
21866,
12913,
267,
702,
440,
660,
14,
3821,
63,
6742,
59,
604,
63,
344,
1055,
3821,
508,
625,
24227,
63,
3821,
267,
660,
14,
873,
63,
991,
63,
3401,
8,
604,
63,
344,
12,
625,
24227,
63,
3821,
9,
267,
702,
660,
14,
3821,
63,
6742,
59,
604,
63,
344,
1055,
3821,
508,
625,
24227,
63,
3821,
421,
199,
533,
1379,
6845,
8,
14440,
304,
272,
347,
511,
63,
4712,
63,
3821,
63,
3742,
8,
277,
304,
267,
1004,
275,
519,
2,
7806,
13,
713,
13,
1644,
3144,
26,
845,
26,
383,
3918,
365,
4124,
641,
1013,
2025,
2,
267,
5163,
275,
519,
16136,
2961,
68,
60,
68,
60,
68,
60,
68,
2696,
68,
60,
68,
2696,
68,
60,
68,
971,
68,
60,
68,
3427,
68,
60,
68,
3427,
68,
60,
68,
9,
3918,
365,
4124,
641,
334,
12432,
17351,
267,
291,
14,
4712,
63,
3821,
63,
1431,
8,
3821,
12,
1004,
12,
661,
7806,
13,
713,
13,
1644,
3144,
26,
845,
26,
383,
297,
283,
863,
2025,
1333,
339,
347,
511,
63,
4712,
63,
3821,
63,
1633,
8,
277,
304,
267,
1004,
275,
519,
2,
7806,
13,
713,
13,
1644,
3144,
26,
845,
26,
383,
3918,
365,
4124,
2,
267,
5163,
275,
519,
16136,
2961,
68,
60,
68,
60,
68,
60,
68,
2696,
68,
60,
68,
2696,
68,
60,
68,
971,
68,
60,
68,
3427,
68,
60,
68,
3427,
68,
60,
68,
9,
3918,
365,
4124,
641,
334,
12432,
17351,
267,
291,
14,
4712,
63,
3821,
63,
1397,
63,
1431,
8,
3821,
12,
1004,
9,
339,
347,
511,
63,
981,
63,
2873,
2971,
63,
3821,
8,
277,
304,
267,
1004,
275,
519,
1674,
62,
4,
10,
88,
11,
88,
91,
21,
93,
8995,
23033,
88,
61,
88,
92,
89,
8,
88,
18168,
73,
44,
706,
2521,
9,
5169,
88,
18168,
48,
28,
354,
30,
88,
18168,
3,
88,
18168,
11230,
88,
2862,
20,
60,
66,
60,
33,
2,
267,
25259,
63,
3821,
275,
1218,
63,
2873,
2971,
63,
3821,
8,
604,
9,
267,
702,
334,
288,
25259,
63,
3821,
508,
519,
3212,
3134,
12773,
16827,
10,
88,
60,
11,
88,
60,
91,
21,
60,
4988,
31,
9780,
7590,
59,
88,
32174,
88,
60,
92,
89,
24805,
88,
13670,
2961,
31,
73,
44,
706,
2521,
13670,
2961,
31,
26,
88,
60,
2924,
288,
519,
3212,
2961,
31,
48,
28,
354,
30,
88,
13670,
2961,
31,
3,
88,
13670,
2961,
31,
11230,
88,
60,
22532,
20,
1103,
66,
1103,
33,
2,
267,
776,
398,
291,
14,
4712,
63,
3821,
63,
1431,
8,
2873,
2971,
63,
3821,
12,
1004,
12,
14515,
339,
347,
511,
63,
981,
63,
602,
63,
3821,
8,
277,
304,
267,
1434,
275,
283,
709,
15,
17584,
15,
16278,
26,
2025,
26,
1046,
26,
1717,
7,
267,
5163,
275,
1218,
63,
602,
63,
3821,
8,
602,
9,
267,
291,
14,
4712,
63,
3821,
63,
1431,
8,
3821,
12,
1434,
12,
14515,
398,
440,
63,
9467,
63,
9356,
275,
359,
288,
1434,
435,
298,
3872,
1434,
435,
298
] |
[
295,
199,
504,
2882,
492,
7640,
199,
199,
504,
10842,
793,
14,
7310,
14,
3821,
63,
7310,
492,
12939,
24486,
199,
504,
10842,
793,
14,
7310,
14,
3821,
63,
7310,
14,
3924,
492,
2832,
14215,
5103,
547,
199,
504,
10842,
793,
14,
7310,
14,
3821,
63,
7310,
14,
3821,
492,
334,
272,
1218,
63,
602,
63,
3821,
12,
1218,
63,
2873,
2971,
63,
3821,
12,
5163,
63,
504,
63,
923,
63,
681,
796,
12,
5163,
63,
2634,
12,
4911,
63,
3821,
199,
9,
199,
504,
10842,
793,
14,
7310,
14,
3751,
492,
32091,
199,
504,
10842,
793,
14,
7310,
14,
3751,
63,
513,
492,
32091,
1296,
199,
504,
10842,
793,
14,
7310,
14,
681,
796,
63,
1623,
316,
492,
334,
272,
485,
1623,
63,
602,
63,
681,
796,
63,
991,
63,
3990,
12,
2342,
63,
602,
63,
681,
796,
12,
2342,
63,
681,
796,
63,
991,
63,
3821,
199,
9,
199,
504,
10842,
793,
14,
14708,
14,
1208,
492,
481,
82,
1888,
3205,
421,
199,
533,
1379,
1563,
8,
1746,
304,
272,
347,
4911,
63,
3821,
63,
1431,
8,
277,
12,
5163,
12,
1004,
12,
13632,
63,
2634,
29,
403,
304,
267,
862,
26,
288,
4652,
275,
5163,
63,
2634,
8,
3821,
12,
1004,
9,
288,
340,
13632,
63,
2634,
365,
440,
488,
26,
355,
702,
4652,
508,
13632,
63,
2634,
267,
871,
2832,
14215,
5103,
547,
465,
325,
26,
288,
291,
14,
1633,
8,
69,
9,
339,
347,
4911,
63,
3821,
63,
1397,
63,
1431,
8,
277,
12,
5163,
12,
1004,
304,
267,
291,
14,
1855,
8,
1763,
14215,
5103,
547,
12,
4911,
63,
3821,
12,
5163,
12,
1004,
9,
421,
199,
533,
1379,
5103,
24486,
8,
14440,
304,
272,
347,
511,
63,
11636,
63,
3401,
63,
6742,
8,
277,
304,
267,
1004,
275,
519,
7,
7806,
13,
713,
13,
1644,
503,
359,
709,
15,
17584,
15,
16278,
7829,
26,
1046,
26,
1717,
435,
1717,
383,
61,
298,
2970,
1182,
1080,
14,
1360,
3101,
15,
17,
14,
16,
2,
1926,
413,
5882,
7,
267,
13738,
63,
1210,
275,
481,
82,
1888,
3205,
8,
16,
12,
1004,
12,
378,
9,
267,
1004,
63,
344,
275,
413,
267,
660,
275,
12939,
24486,
342,
267,
660,
14,
525,
63,
604,
8,
604,
63,
344,
12,
13738,
63,
1210,
9,
267,
3851,
63,
6742,
275,
660,
14,
11636,
63,
3401,
63,
6742,
8,
604,
63,
344,
9,
267,
702,
3851,
63,
6742,
267,
29950,
63,
29283,
275,
359,
3401,
63,
1431,
14,
3401,
367,
3851,
63,
1431,
315,
3851,
63,
6742,
14,
1459,
5106,
267,
367,
29950,
63,
3821,
315,
29950,
63,
29283,
26,
288,
291,
14,
4712,
63,
3821,
63,
1431,
8,
71,
10138,
939,
63,
3821,
12,
1004,
9,
339,
347,
511,
63,
873,
63,
991,
63,
3401,
8,
277,
304,
267,
660,
275,
12939,
24486,
342,
267,
1004,
275,
298,
6257,
12,
6827,
793,
8129,
89,
9539,
267,
1004,
63,
344,
275,
413,
267,
660,
14,
525,
63,
604,
8,
604,
63,
344,
12,
481,
82,
1888,
3205,
8,
16,
12,
1004,
12,
378,
430,
267,
625,
24227,
63,
3821,
275,
519,
4289,
6257,
12,
334,
55,
3577,
793,
334,
5969,
92,
6051,
89,
9,
21866,
12913,
267,
702,
440,
660,
14,
3821,
63,
6742,
59,
604,
63,
344,
1055,
3821,
508,
625,
24227,
63,
3821,
267,
660,
14,
873,
63,
991,
63,
3401,
8,
604,
63,
344,
12,
625,
24227,
63,
3821,
9,
267,
702,
660,
14,
3821,
63,
6742,
59,
604,
63,
344,
1055,
3821,
508,
625,
24227,
63,
3821,
421,
199,
533,
1379,
6845,
8,
14440,
304,
272,
347,
511,
63,
4712,
63,
3821,
63,
3742,
8,
277,
304,
267,
1004,
275,
519,
2,
7806,
13,
713,
13,
1644,
3144,
26,
845,
26,
383,
3918,
365,
4124,
641,
1013,
2025,
2,
267,
5163,
275,
519,
16136,
2961,
68,
60,
68,
60,
68,
60,
68,
2696,
68,
60,
68,
2696,
68,
60,
68,
971,
68,
60,
68,
3427,
68,
60,
68,
3427,
68,
60,
68,
9,
3918,
365,
4124,
641,
334,
12432,
17351,
267,
291,
14,
4712,
63,
3821,
63,
1431,
8,
3821,
12,
1004,
12,
661,
7806,
13,
713,
13,
1644,
3144,
26,
845,
26,
383,
297,
283,
863,
2025,
1333,
339,
347,
511,
63,
4712,
63,
3821,
63,
1633,
8,
277,
304,
267,
1004,
275,
519,
2,
7806,
13,
713,
13,
1644,
3144,
26,
845,
26,
383,
3918,
365,
4124,
2,
267,
5163,
275,
519,
16136,
2961,
68,
60,
68,
60,
68,
60,
68,
2696,
68,
60,
68,
2696,
68,
60,
68,
971,
68,
60,
68,
3427,
68,
60,
68,
3427,
68,
60,
68,
9,
3918,
365,
4124,
641,
334,
12432,
17351,
267,
291,
14,
4712,
63,
3821,
63,
1397,
63,
1431,
8,
3821,
12,
1004,
9,
339,
347,
511,
63,
981,
63,
2873,
2971,
63,
3821,
8,
277,
304,
267,
1004,
275,
519,
1674,
62,
4,
10,
88,
11,
88,
91,
21,
93,
8995,
23033,
88,
61,
88,
92,
89,
8,
88,
18168,
73,
44,
706,
2521,
9,
5169,
88,
18168,
48,
28,
354,
30,
88,
18168,
3,
88,
18168,
11230,
88,
2862,
20,
60,
66,
60,
33,
2,
267,
25259,
63,
3821,
275,
1218,
63,
2873,
2971,
63,
3821,
8,
604,
9,
267,
702,
334,
288,
25259,
63,
3821,
508,
519,
3212,
3134,
12773,
16827,
10,
88,
60,
11,
88,
60,
91,
21,
60,
4988,
31,
9780,
7590,
59,
88,
32174,
88,
60,
92,
89,
24805,
88,
13670,
2961,
31,
73,
44,
706,
2521,
13670,
2961,
31,
26,
88,
60,
2924,
288,
519,
3212,
2961,
31,
48,
28,
354,
30,
88,
13670,
2961,
31,
3,
88,
13670,
2961,
31,
11230,
88,
60,
22532,
20,
1103,
66,
1103,
33,
2,
267,
776,
398,
291,
14,
4712,
63,
3821,
63,
1431,
8,
2873,
2971,
63,
3821,
12,
1004,
12,
14515,
339,
347,
511,
63,
981,
63,
602,
63,
3821,
8,
277,
304,
267,
1434,
275,
283,
709,
15,
17584,
15,
16278,
26,
2025,
26,
1046,
26,
1717,
7,
267,
5163,
275,
1218,
63,
602,
63,
3821,
8,
602,
9,
267,
291,
14,
4712,
63,
3821,
63,
1431,
8,
3821,
12,
1434,
12,
14515,
398,
440,
63,
9467,
63,
9356,
275,
359,
288,
1434,
435,
298,
3872,
1434,
435,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
peterbe/bramble
|
vendor-local/lib/python/redis/client.py
|
2
|
60782
|
from __future__ import with_statement
import datetime
import time
import warnings
from itertools import imap, izip, starmap
from redis.connection import ConnectionPool, UnixDomainSocketConnection
from redis.exceptions import (
ConnectionError,
DataError,
RedisError,
ResponseError,
WatchError,
)
def list_or_args(keys, args):
# returns a single list combining keys and args
try:
i = iter(keys)
# a string can be iterated, but indicates
# keys wasn't passed as a list
if isinstance(keys, basestring):
keys = [keys]
except TypeError:
keys = [keys]
if args:
keys.extend(args)
return keys
def timestamp_to_datetime(response):
"Converts a unix timestamp to a Python datetime object"
if not response:
return None
try:
response = int(response)
except ValueError:
return None
return datetime.datetime.fromtimestamp(response)
def string_keys_to_dict(key_string, callback):
return dict.fromkeys(key_string.split(), callback)
def dict_merge(*dicts):
merged = {}
[merged.update(d) for d in dicts]
return merged
def parse_debug_object(response):
"Parse the results of Redis's DEBUG OBJECT command into a Python dict"
# The 'type' of the object is the first item in the response, but isn't
# prefixed with a name
response = 'type:' + response
response = dict([kv.split(':') for kv in response.split()])
# parse some expected int values from the string response
# note: this cmd isn't spec'd so these may not appear in all redis versions
int_fields = ('refcount', 'serializedlength', 'lru', 'lru_seconds_idle')
for field in int_fields:
if field in response:
response[field] = int(response[field])
return response
def parse_object(response, infotype):
"Parse the results of an OBJECT command"
if infotype in ('idletime', 'refcount'):
return int(response)
return response
def parse_info(response):
"Parse the result of Redis's INFO command into a Python dict"
info = {}
def get_value(value):
if ',' not in value or '=' not in value:
return value
sub_dict = {}
for item in value.split(','):
k, v = item.rsplit('=', 1)
try:
sub_dict[k] = int(v)
except ValueError:
sub_dict[k] = v
return sub_dict
for line in response.splitlines():
if line and not line.startswith('#'):
key, value = line.split(':')
try:
if '.' in value:
info[key] = float(value)
else:
info[key] = int(value)
except ValueError:
info[key] = get_value(value)
return info
def pairs_to_dict(response):
"Create a dict given a list of key/value pairs"
it = iter(response)
return dict(izip(it, it))
def zset_score_pairs(response, **options):
"""
If ``withscores`` is specified in the options, return the response as
a list of (value, score) pairs
"""
if not response or not options['withscores']:
return response
score_cast_func = options.get('score_cast_func', float)
it = iter(response)
return zip(it, imap(score_cast_func, it))
def int_or_none(response):
if response is None:
return None
return int(response)
def float_or_none(response):
if response is None:
return None
return float(response)
def parse_config(response, **options):
# this is stupid, but don't have a better option right now
if options['parse'] == 'GET':
return response and pairs_to_dict(response) or {}
return response == 'OK'
class StrictRedis(object):
"""
Implementation of the Redis protocol.
This abstract class provides a Python interface to all Redis commands
and an implementation of the Redis protocol.
Connection and Pipeline derive from this, implementing how
the commands are sent and received to the Redis server
"""
RESPONSE_CALLBACKS = dict_merge(
string_keys_to_dict(
'AUTH DEL EXISTS EXPIRE EXPIREAT HDEL HEXISTS HMSET MOVE MSETNX '
'PERSIST RENAMENX SISMEMBER SMOVE SETEX SETNX SREM ZREM',
bool
),
string_keys_to_dict(
'DECRBY GETBIT HLEN INCRBY LINSERT LLEN LPUSHX RPUSHX SADD SCARD '
'SDIFFSTORE SETBIT SETRANGE SINTERSTORE STRLEN SUNIONSTORE ZADD '
'ZCARD ZREMRANGEBYRANK ZREMRANGEBYSCORE',
int
),
string_keys_to_dict(
# these return OK, or int if redis-server is >=1.3.4
'LPUSH RPUSH',
lambda r: isinstance(r, long) and r or r == 'OK'
),
string_keys_to_dict('ZSCORE ZINCRBY', float_or_none),
string_keys_to_dict(
'FLUSHALL FLUSHDB LSET LTRIM MSET RENAME '
'SAVE SELECT SET SHUTDOWN SLAVEOF WATCH UNWATCH',
lambda r: r == 'OK'
),
string_keys_to_dict('BLPOP BRPOP', lambda r: r and tuple(r) or None),
string_keys_to_dict('SDIFF SINTER SMEMBERS SUNION',
lambda r: r and set(r) or set()
),
string_keys_to_dict('ZRANGE ZRANGEBYSCORE ZREVRANGE ZREVRANGEBYSCORE',
zset_score_pairs
),
string_keys_to_dict('ZRANK ZREVRANK', int_or_none),
{
'BGREWRITEAOF': lambda r: \
r == 'Background rewriting of AOF file started',
'BGSAVE': lambda r: r == 'Background saving started',
'BRPOPLPUSH': lambda r: r and r or None,
'CONFIG': parse_config,
'DEBUG': parse_debug_object,
'HGETALL': lambda r: r and pairs_to_dict(r) or {},
'INFO': parse_info,
'LASTSAVE': timestamp_to_datetime,
'OBJECT': parse_object,
'PING': lambda r: r == 'PONG',
'RANDOMKEY': lambda r: r and r or None,
}
)
def __init__(self, host='localhost', port=6379,
db=0, password=None, socket_timeout=None,
connection_pool=None,
charset='utf-8', errors='strict', unix_socket_path=None):
if not connection_pool:
kwargs = {
'db': db,
'password': password,
'socket_timeout': socket_timeout,
'encoding': charset,
'encoding_errors': errors
}
# based on input, setup appropriate connection args
if unix_socket_path:
kwargs.update({
'path': unix_socket_path,
'connection_class': UnixDomainSocketConnection
})
else:
kwargs.update({
'host': host,
'port': port
})
connection_pool = ConnectionPool(**kwargs)
self.connection_pool = connection_pool
self.response_callbacks = self.__class__.RESPONSE_CALLBACKS.copy()
def set_response_callback(self, command, callback):
"Set a custom Response Callback"
self.response_callbacks[command] = callback
def pipeline(self, transaction=True, shard_hint=None):
"""
Return a new pipeline object that can queue multiple commands for
later execution. ``transaction`` indicates whether all commands
should be executed atomically. Apart from making a group of operations
atomic, pipelines are useful for reducing the back-and-forth overhead
between the client and server.
"""
return StrictPipeline(
self.connection_pool,
self.response_callbacks,
transaction,
shard_hint)
def transaction(self, func, *watches, **kwargs):
"""
Convenience method for executing the callable `func` as a transaction
while watching all keys specified in `watches`. The 'func' callable
should expect a single arguement which is a Pipeline object.
"""
shard_hint = kwargs.pop('shard_hint', None)
with self.pipeline(True, shard_hint) as pipe:
while 1:
try:
pipe.watch(*watches)
func(pipe)
return pipe.execute()
except WatchError:
continue
def lock(self, name, timeout=None, sleep=0.1):
"""
Return a new Lock object using key ``name`` that mimics
the behavior of threading.Lock.
If specified, ``timeout`` indicates a maximum life for the lock.
By default, it will remain locked until release() is called.
``sleep`` indicates the amount of time to sleep per loop iteration
when the lock is in blocking mode and another client is currently
holding the lock.
"""
return Lock(self, name, timeout=timeout, sleep=sleep)
def pubsub(self, shard_hint=None):
"""
Return a Publish/Subscribe object. With this object, you can
subscribe to channels and listen for messages that get published to
them.
"""
return PubSub(self.connection_pool, shard_hint)
#### COMMAND EXECUTION AND PROTOCOL PARSING ####
def execute_command(self, *args, **options):
"Execute a command and return a parsed response"
pool = self.connection_pool
command_name = args[0]
connection = pool.get_connection(command_name, **options)
try:
connection.send_command(*args)
return self.parse_response(connection, command_name, **options)
except ConnectionError:
connection.disconnect()
connection.send_command(*args)
return self.parse_response(connection, command_name, **options)
finally:
pool.release(connection)
def parse_response(self, connection, command_name, **options):
"Parses a response from the Redis server"
response = connection.read_response()
if command_name in self.response_callbacks:
return self.response_callbacks[command_name](response, **options)
return response
#### SERVER INFORMATION ####
def bgrewriteaof(self):
"Tell the Redis server to rewrite the AOF file from data in memory."
return self.execute_command('BGREWRITEAOF')
def bgsave(self):
"""
Tell the Redis server to save its data to disk. Unlike save(),
this method is asynchronous and returns immediately.
"""
return self.execute_command('BGSAVE')
def config_get(self, pattern="*"):
"Return a dictionary of configuration based on the ``pattern``"
return self.execute_command('CONFIG', 'GET', pattern, parse='GET')
def config_set(self, name, value):
"Set config item ``name`` with ``value``"
return self.execute_command('CONFIG', 'SET', name, value, parse='SET')
def dbsize(self):
"Returns the number of keys in the current database"
return self.execute_command('DBSIZE')
def debug_object(self, key):
"Returns version specific metainformation about a give key"
return self.execute_command('DEBUG', 'OBJECT', key)
def delete(self, *names):
"Delete one or more keys specified by ``names``"
return self.execute_command('DEL', *names)
__delitem__ = delete
def echo(self, value):
"Echo the string back from the server"
return self.execute_command('ECHO', value)
def flushall(self):
"Delete all keys in all databases on the current host"
return self.execute_command('FLUSHALL')
def flushdb(self):
"Delete all keys in the current database"
return self.execute_command('FLUSHDB')
def info(self):
"Returns a dictionary containing information about the Redis server"
return self.execute_command('INFO')
def lastsave(self):
"""
Return a Python datetime object representing the last time the
Redis database was saved to disk
"""
return self.execute_command('LASTSAVE')
def object(self, infotype, key):
"Return the encoding, idletime, or refcount about the key"
return self.execute_command('OBJECT', infotype, key, infotype=infotype)
def ping(self):
"Ping the Redis server"
return self.execute_command('PING')
def save(self):
"""
Tell the Redis server to save its data to disk,
blocking until the save is complete
"""
return self.execute_command('SAVE')
def shutdown(self):
"Shutdown the server"
try:
self.execute_command('SHUTDOWN')
except ConnectionError:
# a ConnectionError here is expected
return
raise RedisError("SHUTDOWN seems to have failed.")
def slaveof(self, host=None, port=None):
"""
Set the server to be a replicated slave of the instance identified
by the ``host`` and ``port``. If called without arguements, the
instance is promoted to a master instead.
"""
if host is None and port is None:
return self.execute_command("SLAVEOF", "NO", "ONE")
return self.execute_command("SLAVEOF", host, port)
#### BASIC KEY COMMANDS ####
def append(self, key, value):
"""
Appends the string ``value`` to the value at ``key``. If ``key``
doesn't already exist, create it with a value of ``value``.
Returns the new length of the value at ``key``.
"""
return self.execute_command('APPEND', key, value)
def decr(self, name, amount=1):
"""
Decrements the value of ``key`` by ``amount``. If no key exists,
the value will be initialized as 0 - ``amount``
"""
return self.execute_command('DECRBY', name, amount)
def exists(self, name):
"Returns a boolean indicating whether key ``name`` exists"
return self.execute_command('EXISTS', name)
__contains__ = exists
def expire(self, name, time):
"Set an expire flag on key ``name`` for ``time`` seconds"
return self.execute_command('EXPIRE', name, time)
def expireat(self, name, when):
"""
Set an expire flag on key ``name``. ``when`` can be represented
as an integer indicating unix time or a Python datetime object.
"""
if isinstance(when, datetime.datetime):
when = int(time.mktime(when.timetuple()))
return self.execute_command('EXPIREAT', name, when)
def get(self, name):
"""
Return the value at key ``name``, or None if the key doesn't exist
"""
return self.execute_command('GET', name)
def __getitem__(self, name):
"""
Return the value at key ``name``, raises a KeyError if the key
doesn't exist.
"""
value = self.get(name)
if value:
return value
raise KeyError(name)
def getbit(self, name, offset):
"Returns a boolean indicating the value of ``offset`` in ``name``"
return self.execute_command('GETBIT', name, offset)
def getset(self, name, value):
"""
Set the value at key ``name`` to ``value`` if key doesn't exist
Return the value at key ``name`` atomically
"""
return self.execute_command('GETSET', name, value)
def incr(self, name, amount=1):
"""
Increments the value of ``key`` by ``amount``. If no key exists,
the value will be initialized as ``amount``
"""
return self.execute_command('INCRBY', name, amount)
def keys(self, pattern='*'):
"Returns a list of keys matching ``pattern``"
return self.execute_command('KEYS', pattern)
def mget(self, keys, *args):
"""
Returns a list of values ordered identically to ``keys``
"""
keys = list_or_args(keys, args)
return self.execute_command('MGET', *keys)
def mset(self, mapping):
"Sets each key in the ``mapping`` dict to its corresponding value"
items = []
for pair in mapping.iteritems():
items.extend(pair)
return self.execute_command('MSET', *items)
def msetnx(self, mapping):
"""
Sets each key in the ``mapping`` dict to its corresponding value if
none of the keys are already set
"""
items = []
for pair in mapping.iteritems():
items.extend(pair)
return self.execute_command('MSETNX', *items)
def move(self, name, db):
"Moves the key ``name`` to a different Redis database ``db``"
return self.execute_command('MOVE', name, db)
def persist(self, name):
"Removes an expiration on ``name``"
return self.execute_command('PERSIST', name)
def randomkey(self):
"Returns the name of a random key"
return self.execute_command('RANDOMKEY')
def rename(self, src, dst):
"""
Rename key ``src`` to ``dst``
"""
return self.execute_command('RENAME', src, dst)
def renamenx(self, src, dst):
"Rename key ``src`` to ``dst`` if ``dst`` doesn't already exist"
return self.execute_command('RENAMENX', src, dst)
def set(self, name, value):
"Set the value at key ``name`` to ``value``"
return self.execute_command('SET', name, value)
__setitem__ = set
def setbit(self, name, offset, value):
"""
Flag the ``offset`` in ``name`` as ``value``. Returns a boolean
indicating the previous value of ``offset``.
"""
value = value and 1 or 0
return self.execute_command('SETBIT', name, offset, value)
def setex(self, name, time, value):
"""
Set the value of key ``name`` to ``value``
that expires in ``time`` seconds
"""
return self.execute_command('SETEX', name, time, value)
def setnx(self, name, value):
"Set the value of key ``name`` to ``value`` if key doesn't exist"
return self.execute_command('SETNX', name, value)
def setrange(self, name, offset, value):
"""
Overwrite bytes in the value of ``name`` starting at ``offset`` with
``value``. If ``offset`` plus the length of ``value`` exceeds the
length of the original value, the new value will be larger than before.
If ``offset`` exceeds the length of the original value, null bytes
will be used to pad between the end of the previous value and the start
of what's being injected.
Returns the length of the new string.
"""
return self.execute_command('SETRANGE', name, offset, value)
def strlen(self, name):
"Return the number of bytes stored in the value of ``name``"
return self.execute_command('STRLEN', name)
def substr(self, name, start, end=-1):
"""
Return a substring of the string at key ``name``. ``start`` and ``end``
are 0-based integers specifying the portion of the string to return.
"""
return self.execute_command('SUBSTR', name, start, end)
def ttl(self, name):
"Returns the number of seconds until the key ``name`` will expire"
return self.execute_command('TTL', name)
def type(self, name):
"Returns the type of key ``name``"
return self.execute_command('TYPE', name)
def watch(self, *names):
"""
Watches the values at keys ``names``, or None if the key doesn't exist
"""
warnings.warn(DeprecationWarning('Call WATCH from a Pipeline object'))
def unwatch(self):
"""
Unwatches the value at key ``name``, or None of the key doesn't exist
"""
warnings.warn(DeprecationWarning('Call UNWATCH from a Pipeline object'))
#### LIST COMMANDS ####
def blpop(self, keys, timeout=0):
"""
LPOP a value off of the first non-empty list
named in the ``keys`` list.
If none of the lists in ``keys`` has a value to LPOP, then block
for ``timeout`` seconds, or until a value gets pushed on to one
of the lists.
If timeout is 0, then block indefinitely.
"""
if timeout is None:
timeout = 0
if isinstance(keys, basestring):
keys = [keys]
else:
keys = list(keys)
keys.append(timeout)
return self.execute_command('BLPOP', *keys)
def brpop(self, keys, timeout=0):
"""
RPOP a value off of the first non-empty list
named in the ``keys`` list.
If none of the lists in ``keys`` has a value to LPOP, then block
for ``timeout`` seconds, or until a value gets pushed on to one
of the lists.
If timeout is 0, then block indefinitely.
"""
if timeout is None:
timeout = 0
if isinstance(keys, basestring):
keys = [keys]
else:
keys = list(keys)
keys.append(timeout)
return self.execute_command('BRPOP', *keys)
def brpoplpush(self, src, dst, timeout=0):
"""
Pop a value off the tail of ``src``, push it on the head of ``dst``
and then return it.
This command blocks until a value is in ``src`` or until ``timeout``
seconds elapse, whichever is first. A ``timeout`` value of 0 blocks
forever.
"""
if timeout is None:
timeout = 0
return self.execute_command('BRPOPLPUSH', src, dst, timeout)
def lindex(self, name, index):
"""
Return the item from list ``name`` at position ``index``
Negative indexes are supported and will return an item at the
end of the list
"""
return self.execute_command('LINDEX', name, index)
def linsert(self, name, where, refvalue, value):
"""
Insert ``value`` in list ``name`` either immediately before or after
[``where``] ``refvalue``
Returns the new length of the list on success or -1 if ``refvalue``
is not in the list.
"""
return self.execute_command('LINSERT', name, where, refvalue, value)
def llen(self, name):
"Return the length of the list ``name``"
return self.execute_command('LLEN', name)
def lpop(self, name):
"Remove and return the first item of the list ``name``"
return self.execute_command('LPOP', name)
def lpush(self, name, *values):
"Push ``values`` onto the head of the list ``name``"
return self.execute_command('LPUSH', name, *values)
def lpushx(self, name, value):
"Push ``value`` onto the head of the list ``name`` if ``name`` exists"
return self.execute_command('LPUSHX', name, value)
def lrange(self, name, start, end):
"""
Return a slice of the list ``name`` between
position ``start`` and ``end``
``start`` and ``end`` can be negative numbers just like
Python slicing notation
"""
return self.execute_command('LRANGE', name, start, end)
def lrem(self, name, count, value):
"""
Remove the first ``count`` occurrences of elements equal to ``value``
from the list stored at ``name``.
The count argument influences the operation in the following ways:
count > 0: Remove elements equal to value moving from head to tail.
count < 0: Remove elements equal to value moving from tail to head.
count = 0: Remove all elements equal to value.
"""
return self.execute_command('LREM', name, count, value)
def lset(self, name, index, value):
"Set ``position`` of list ``name`` to ``value``"
return self.execute_command('LSET', name, index, value)
def ltrim(self, name, start, end):
"""
Trim the list ``name``, removing all values not within the slice
between ``start`` and ``end``
``start`` and ``end`` can be negative numbers just like
Python slicing notation
"""
return self.execute_command('LTRIM', name, start, end)
def rpop(self, name):
"Remove and return the last item of the list ``name``"
return self.execute_command('RPOP', name)
def rpoplpush(self, src, dst):
"""
RPOP a value off of the ``src`` list and atomically LPUSH it
on to the ``dst`` list. Returns the value.
"""
return self.execute_command('RPOPLPUSH', src, dst)
def rpush(self, name, *values):
"Push ``values`` onto the tail of the list ``name``"
return self.execute_command('RPUSH', name, *values)
def rpushx(self, name, value):
"Push ``value`` onto the tail of the list ``name`` if ``name`` exists"
return self.execute_command('RPUSHX', name, value)
def sort(self, name, start=None, num=None, by=None, get=None,
desc=False, alpha=False, store=None):
"""
Sort and return the list, set or sorted set at ``name``.
``start`` and ``num`` allow for paging through the sorted data
``by`` allows using an external key to weight and sort the items.
Use an "*" to indicate where in the key the item value is located
``get`` allows for returning items from external keys rather than the
sorted data itself. Use an "*" to indicate where int he key
the item value is located
``desc`` allows for reversing the sort
``alpha`` allows for sorting lexicographically rather than numerically
``store`` allows for storing the result of the sort into
the key ``store``
"""
if (start is not None and num is None) or \
(num is not None and start is None):
raise RedisError("``start`` and ``num`` must both be specified")
pieces = [name]
if by is not None:
pieces.append('BY')
pieces.append(by)
if start is not None and num is not None:
pieces.append('LIMIT')
pieces.append(start)
pieces.append(num)
if get is not None:
# If get is a string assume we want to get a single value.
# Otherwise assume it's an interable and we want to get multiple
# values. We can't just iterate blindly because strings are
# iterable.
if isinstance(get, basestring):
pieces.append('GET')
pieces.append(get)
else:
for g in get:
pieces.append('GET')
pieces.append(g)
if desc:
pieces.append('DESC')
if alpha:
pieces.append('ALPHA')
if store is not None:
pieces.append('STORE')
pieces.append(store)
return self.execute_command('SORT', *pieces)
#### SET COMMANDS ####
def sadd(self, name, *values):
"Add ``value(s)`` to set ``name``"
return self.execute_command('SADD', name, *values)
def scard(self, name):
"Return the number of elements in set ``name``"
return self.execute_command('SCARD', name)
def sdiff(self, keys, *args):
"Return the difference of sets specified by ``keys``"
keys = list_or_args(keys, args)
return self.execute_command('SDIFF', *keys)
def sdiffstore(self, dest, keys, *args):
"""
Store the difference of sets specified by ``keys`` into a new
set named ``dest``. Returns the number of keys in the new set.
"""
keys = list_or_args(keys, args)
return self.execute_command('SDIFFSTORE', dest, *keys)
def sinter(self, keys, *args):
"Return the intersection of sets specified by ``keys``"
keys = list_or_args(keys, args)
return self.execute_command('SINTER', *keys)
def sinterstore(self, dest, keys, *args):
"""
Store the intersection of sets specified by ``keys`` into a new
set named ``dest``. Returns the number of keys in the new set.
"""
keys = list_or_args(keys, args)
return self.execute_command('SINTERSTORE', dest, *keys)
def sismember(self, name, value):
"Return a boolean indicating if ``value`` is a member of set ``name``"
return self.execute_command('SISMEMBER', name, value)
def smembers(self, name):
"Return all members of the set ``name``"
return self.execute_command('SMEMBERS', name)
def smove(self, src, dst, value):
"Move ``value`` from set ``src`` to set ``dst`` atomically"
return self.execute_command('SMOVE', src, dst, value)
def spop(self, name):
"Remove and return a random member of set ``name``"
return self.execute_command('SPOP', name)
def srandmember(self, name):
"Return a random member of set ``name``"
return self.execute_command('SRANDMEMBER', name)
def srem(self, name, *values):
"Remove ``values`` from set ``name``"
return self.execute_command('SREM', name, *values)
def sunion(self, keys, *args):
"Return the union of sets specifiued by ``keys``"
keys = list_or_args(keys, args)
return self.execute_command('SUNION', *keys)
def sunionstore(self, dest, keys, *args):
"""
Store the union of sets specified by ``keys`` into a new
set named ``dest``. Returns the number of keys in the new set.
"""
keys = list_or_args(keys, args)
return self.execute_command('SUNIONSTORE', dest, *keys)
#### SORTED SET COMMANDS ####
def zadd(self, name, *args, **kwargs):
"""
Set any number of score, element-name pairs to the key ``name``. Pairs
can be specified in two ways:
As *args, in the form of: score1, name1, score2, name2, ...
or as **kwargs, in the form of: name1=score1, name2=score2, ...
The following example would add four values to the 'my-key' key:
redis.zadd('my-key', 1.1, 'name1', 2.2, 'name2', name3=3.3, name4=4.4)
"""
pieces = []
if args:
if len(args) % 2 != 0:
raise RedisError("ZADD requires an equal number of "
"values and scores")
pieces.extend(args)
for pair in kwargs.iteritems():
pieces.append(pair[1])
pieces.append(pair[0])
return self.execute_command('ZADD', name, *pieces)
def zcard(self, name):
"Return the number of elements in the sorted set ``name``"
return self.execute_command('ZCARD', name)
def zcount(self, name, min, max):
return self.execute_command('ZCOUNT', name, min, max)
def zincrby(self, name, value, amount=1):
"Increment the score of ``value`` in sorted set ``name`` by ``amount``"
return self.execute_command('ZINCRBY', name, amount, value)
def zinterstore(self, dest, keys, aggregate=None):
"""
Intersect multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided.
"""
return self._zaggregate('ZINTERSTORE', dest, keys, aggregate)
def zrange(self, name, start, end, desc=False, withscores=False,
score_cast_func=float):
"""
Return a range of values from sorted set ``name`` between
``start`` and ``end`` sorted in ascending order.
``start`` and ``end`` can be negative, indicating the end of the range.
``desc`` a boolean indicating whether to sort the results descendingly
``withscores`` indicates to return the scores along with the values.
The return type is a list of (value, score) pairs
``score_cast_func`` a callable used to cast the score return value
"""
if desc:
return self.zrevrange(name, start, end, withscores)
pieces = ['ZRANGE', name, start, end]
if withscores:
pieces.append('withscores')
options = {'withscores': withscores, 'score_cast_func': score_cast_func}
return self.execute_command(*pieces, **options)
def zrangebyscore(self, name, min, max,
start=None, num=None, withscores=False, score_cast_func=float):
"""
Return a range of values from the sorted set ``name`` with scores
between ``min`` and ``max``.
If ``start`` and ``num`` are specified, then return a slice
of the range.
``withscores`` indicates to return the scores along with the values.
The return type is a list of (value, score) pairs
`score_cast_func`` a callable used to cast the score return value
"""
if (start is not None and num is None) or \
(num is not None and start is None):
raise RedisError("``start`` and ``num`` must both be specified")
pieces = ['ZRANGEBYSCORE', name, min, max]
if start is not None and num is not None:
pieces.extend(['LIMIT', start, num])
if withscores:
pieces.append('withscores')
options = {'withscores': withscores, 'score_cast_func': score_cast_func}
return self.execute_command(*pieces, **options)
def zrank(self, name, value):
"""
Returns a 0-based value indicating the rank of ``value`` in sorted set
``name``
"""
return self.execute_command('ZRANK', name, value)
def zrem(self, name, *values):
"Remove member ``values`` from sorted set ``name``"
return self.execute_command('ZREM', name, *values)
def zremrangebyrank(self, name, min, max):
"""
Remove all elements in the sorted set ``name`` with ranks between
``min`` and ``max``. Values are 0-based, ordered from smallest score
to largest. Values can be negative indicating the highest scores.
Returns the number of elements removed
"""
return self.execute_command('ZREMRANGEBYRANK', name, min, max)
def zremrangebyscore(self, name, min, max):
"""
Remove all elements in the sorted set ``name`` with scores
between ``min`` and ``max``. Returns the number of elements removed.
"""
return self.execute_command('ZREMRANGEBYSCORE', name, min, max)
def zrevrange(self, name, start, num, withscores=False,
score_cast_func=float):
"""
Return a range of values from sorted set ``name`` between
``start`` and ``num`` sorted in descending order.
``start`` and ``num`` can be negative, indicating the end of the range.
``withscores`` indicates to return the scores along with the values
The return type is a list of (value, score) pairs
``score_cast_func`` a callable used to cast the score return value
"""
pieces = ['ZREVRANGE', name, start, num]
if withscores:
pieces.append('withscores')
options = {'withscores': withscores, 'score_cast_func': score_cast_func}
return self.execute_command(*pieces, **options)
def zrevrangebyscore(self, name, max, min,
start=None, num=None, withscores=False, score_cast_func=float):
"""
Return a range of values from the sorted set ``name`` with scores
between ``min`` and ``max`` in descending order.
If ``start`` and ``num`` are specified, then return a slice
of the range.
``withscores`` indicates to return the scores along with the values.
The return type is a list of (value, score) pairs
``score_cast_func`` a callable used to cast the score return value
"""
if (start is not None and num is None) or \
(num is not None and start is None):
raise RedisError("``start`` and ``num`` must both be specified")
pieces = ['ZREVRANGEBYSCORE', name, max, min]
if start is not None and num is not None:
pieces.extend(['LIMIT', start, num])
if withscores:
pieces.append('withscores')
options = {'withscores': withscores, 'score_cast_func': score_cast_func}
return self.execute_command(*pieces, **options)
def zrevrank(self, name, value):
"""
Returns a 0-based value indicating the descending rank of
``value`` in sorted set ``name``
"""
return self.execute_command('ZREVRANK', name, value)
def zscore(self, name, value):
"Return the score of element ``value`` in sorted set ``name``"
return self.execute_command('ZSCORE', name, value)
def zunionstore(self, dest, keys, aggregate=None):
"""
Union multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided.
"""
return self._zaggregate('ZUNIONSTORE', dest, keys, aggregate)
def _zaggregate(self, command, dest, keys, aggregate=None):
pieces = [command, dest, len(keys)]
if isinstance(keys, dict):
keys, weights = keys.keys(), keys.values()
else:
weights = None
pieces.extend(keys)
if weights:
pieces.append('WEIGHTS')
pieces.extend(weights)
if aggregate:
pieces.append('AGGREGATE')
pieces.append(aggregate)
return self.execute_command(*pieces)
#### HASH COMMANDS ####
def hdel(self, name, *keys):
"Delete ``keys`` from hash ``name``"
return self.execute_command('HDEL', name, *keys)
def hexists(self, name, key):
"Returns a boolean indicating if ``key`` exists within hash ``name``"
return self.execute_command('HEXISTS', name, key)
def hget(self, name, key):
"Return the value of ``key`` within the hash ``name``"
return self.execute_command('HGET', name, key)
def hgetall(self, name):
"Return a Python dict of the hash's name/value pairs"
return self.execute_command('HGETALL', name)
def hincrby(self, name, key, amount=1):
"Increment the value of ``key`` in hash ``name`` by ``amount``"
return self.execute_command('HINCRBY', name, key, amount)
def hkeys(self, name):
"Return the list of keys within hash ``name``"
return self.execute_command('HKEYS', name)
def hlen(self, name):
"Return the number of elements in hash ``name``"
return self.execute_command('HLEN', name)
def hset(self, name, key, value):
"""
Set ``key`` to ``value`` within hash ``name``
Returns 1 if HSET created a new field, otherwise 0
"""
return self.execute_command('HSET', name, key, value)
def hsetnx(self, name, key, value):
"""
Set ``key`` to ``value`` within hash ``name`` if ``key`` does not
exist. Returns 1 if HSETNX created a field, otherwise 0.
"""
return self.execute_command("HSETNX", name, key, value)
def hmset(self, name, mapping):
"""
Sets each key in the ``mapping`` dict to its corresponding value
in the hash ``name``
"""
if not mapping:
raise DataError("'hmset' with 'mapping' of length 0")
items = []
for pair in mapping.iteritems():
items.extend(pair)
return self.execute_command('HMSET', name, *items)
def hmget(self, name, keys):
"Returns a list of values ordered identically to ``keys``"
return self.execute_command('HMGET', name, *keys)
def hvals(self, name):
"Return the list of values within hash ``name``"
return self.execute_command('HVALS', name)
def publish(self, channel, message):
"""
Publish ``message`` on ``channel``.
Returns the number of subscribers the message was delivered to.
"""
return self.execute_command('PUBLISH', channel, message)
class Redis(StrictRedis):
"""
Provides backwards compatibility with older versions of redis-py that
changed arguments to some commands to be more Pythonic, sane, or by
accident.
"""
# Overridden callbacks
RESPONSE_CALLBACKS = dict_merge(
StrictRedis.RESPONSE_CALLBACKS,
{
'TTL': lambda r: r != -1 and r or None,
}
)
def pipeline(self, transaction=True, shard_hint=None):
"""
Return a new pipeline object that can queue multiple commands for
later execution. ``transaction`` indicates whether all commands
should be executed atomically. Apart from making a group of operations
atomic, pipelines are useful for reducing the back-and-forth overhead
between the client and server.
"""
return Pipeline(
self.connection_pool,
self.response_callbacks,
transaction,
shard_hint)
def setex(self, name, value, time):
"""
Set the value of key ``name`` to ``value``
that expires in ``time`` seconds
"""
return self.execute_command('SETEX', name, time, value)
def lrem(self, name, value, num=0):
"""
Remove the first ``num`` occurrences of elements equal to ``value``
from the list stored at ``name``.
The ``num`` argument influences the operation in the following ways:
num > 0: Remove elements equal to value moving from head to tail.
num < 0: Remove elements equal to value moving from tail to head.
num = 0: Remove all elements equal to value.
"""
return self.execute_command('LREM', name, num, value)
def zadd(self, name, *args, **kwargs):
"""
NOTE: The order of arguments differs from that of the official ZADD
command. For backwards compatability, this method accepts arguments
in the form of name1, score1, name2, score2, while the official Redis
documents expects score1, name1, score2, name2.
If you're looking to use the standard syntax, consider using the
StrictRedis class. See the API Reference section of the docs for more
information.
Set any number of element-name, score pairs to the key ``name``. Pairs
can be specified in two ways:
As *args, in the form of: name1, score1, name2, score2, ...
or as **kwargs, in the form of: name1=score1, name2=score2, ...
The following example would add four values to the 'my-key' key:
redis.zadd('my-key', 'name1', 1.1, 'name2', 2.2, name3=3.3, name4=4.4)
"""
pieces = []
if args:
if len(args) % 2 != 0:
raise RedisError("ZADD requires an equal number of "
"values and scores")
pieces.extend(reversed(args))
for pair in kwargs.iteritems():
pieces.append(pair[1])
pieces.append(pair[0])
return self.execute_command('ZADD', name, *pieces)
class PubSub(object):
"""
PubSub provides publish, subscribe and listen support to Redis channels.
After subscribing to one or more channels, the listen() method will block
until a message arrives on one of the subscribed channels. That message
will be returned and it's safe to start listening again.
"""
def __init__(self, connection_pool, shard_hint=None):
self.connection_pool = connection_pool
self.shard_hint = shard_hint
self.connection = None
self.channels = set()
self.patterns = set()
self.subscription_count = 0
self.subscribe_commands = set(
('subscribe', 'psubscribe', 'unsubscribe', 'punsubscribe')
)
def __del__(self):
try:
# if this object went out of scope prior to shutting down
# subscriptions, close the connection manually before
# returning it to the connection pool
if self.connection and (self.channels or self.patterns):
self.connection.disconnect()
self.reset()
except:
pass
def reset(self):
if self.connection:
self.connection_pool.release(self.connection)
self.connection = None
def execute_command(self, *args, **kwargs):
"Execute a publish/subscribe command"
if self.connection is None:
self.connection = self.connection_pool.get_connection(
'pubsub',
self.shard_hint
)
connection = self.connection
try:
connection.send_command(*args)
return self.parse_response()
except ConnectionError:
connection.disconnect()
# Connect manually here. If the Redis server is down, this will
# fail and raise a ConnectionError as desired.
connection.connect()
# resubscribe to all channels and patterns before
# resending the current command
for channel in self.channels:
self.subscribe(channel)
for pattern in self.patterns:
self.psubscribe(pattern)
connection.send_command(*args)
return self.parse_response()
def parse_response(self):
"Parse the response from a publish/subscribe command"
response = self.connection.read_response()
if response[0] in self.subscribe_commands:
self.subscription_count = response[2]
# if we've just unsubscribed from the remaining channels,
# release the connection back to the pool
if not self.subscription_count:
self.reset()
return response
def psubscribe(self, patterns):
"Subscribe to all channels matching any pattern in ``patterns``"
if isinstance(patterns, basestring):
patterns = [patterns]
for pattern in patterns:
self.patterns.add(pattern)
return self.execute_command('PSUBSCRIBE', *patterns)
def punsubscribe(self, patterns=[]):
"""
Unsubscribe from any channel matching any pattern in ``patterns``.
If empty, unsubscribe from all channels.
"""
if isinstance(patterns, basestring):
patterns = [patterns]
for pattern in patterns:
try:
self.patterns.remove(pattern)
except KeyError:
pass
return self.execute_command('PUNSUBSCRIBE', *patterns)
def subscribe(self, channels):
"Subscribe to ``channels``, waiting for messages to be published"
if isinstance(channels, basestring):
channels = [channels]
for channel in channels:
self.channels.add(channel)
return self.execute_command('SUBSCRIBE', *channels)
def unsubscribe(self, channels=[]):
"""
Unsubscribe from ``channels``. If empty, unsubscribe
from all channels
"""
if isinstance(channels, basestring):
channels = [channels]
for channel in channels:
try:
self.channels.remove(channel)
except KeyError:
pass
return self.execute_command('UNSUBSCRIBE', *channels)
def listen(self):
"Listen for messages on channels this client has been subscribed to"
while self.subscription_count:
r = self.parse_response()
if r[0] == 'pmessage':
msg = {
'type': r[0],
'pattern': r[1],
'channel': r[2],
'data': r[3]
}
else:
msg = {
'type': r[0],
'pattern': None,
'channel': r[1],
'data': r[2]
}
yield msg
class BasePipeline(object):
"""
Pipelines provide a way to transmit multiple commands to the Redis server
in one transmission. This is convenient for batch processing, such as
saving all the values in a list to Redis.
All commands executed within a pipeline are wrapped with MULTI and EXEC
calls. This guarantees all commands executed in the pipeline will be
executed atomically.
Any command raising an exception does *not* halt the execution of
subsequent commands in the pipeline. Instead, the exception is caught
and its instance is placed into the response list returned by execute().
Code iterating over the response list should be able to deal with an
instance of an exception as a potential value. In general, these will be
ResponseError exceptions, such as those raised when issuing a command
on a key of a different datatype.
"""
UNWATCH_COMMANDS = set(('DISCARD', 'EXEC', 'UNWATCH'))
def __init__(self, connection_pool, response_callbacks, transaction,
shard_hint):
self.connection_pool = connection_pool
self.connection = None
self.response_callbacks = response_callbacks
self.transaction = transaction
self.shard_hint = shard_hint
self.watching = False
self.reset()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.reset()
def __del__(self):
try:
self.reset()
except:
pass
def reset(self):
self.command_stack = []
# make sure to reset the connection state in the event that we were
# watching something
if self.watching and self.connection:
try:
# call this manually since our unwatch or
# immediate_execute_command methods can call reset()
self.connection.send_command('UNWATCH')
self.connection.read_response()
except ConnectionError:
# disconnect will also remove any previous WATCHes
self.connection.disconnect()
# clean up the other instance attributes
self.watching = False
self.explicit_transaction = False
# we can safely return the connection to the pool here since we're
# sure we're no longer WATCHing anything
if self.connection:
self.connection_pool.release(self.connection)
self.connection = None
def multi(self):
"""
Start a transactional block of the pipeline after WATCH commands
are issued. End the transactional block with `execute`.
"""
if self.explicit_transaction:
raise RedisError('Cannot issue nested calls to MULTI')
if self.command_stack:
raise RedisError('Commands without an initial WATCH have already '
'been issued')
self.explicit_transaction = True
def execute_command(self, *args, **kwargs):
if (self.watching or args[0] == 'WATCH') and \
not self.explicit_transaction:
return self.immediate_execute_command(*args, **kwargs)
return self.pipeline_execute_command(*args, **kwargs)
def immediate_execute_command(self, *args, **options):
"""
Execute a command immediately, but don't auto-retry on a
ConnectionError if we're already WATCHing a variable. Used when
issuing WATCH or subsequent commands retrieving their values but before
MULTI is called.
"""
command_name = args[0]
conn = self.connection
# if this is the first call, we need a connection
if not conn:
conn = self.connection_pool.get_connection(command_name,
self.shard_hint)
self.connection = conn
try:
conn.send_command(*args)
return self.parse_response(conn, command_name, **options)
except ConnectionError:
conn.disconnect()
# if we're not already watching, we can safely retry the command
# assuming it was a connection timeout
if not self.watching:
conn.send_command(*args)
return self.parse_response(conn, command_name, **options)
self.reset()
raise
def pipeline_execute_command(self, *args, **options):
"""
Stage a command to be executed when execute() is next called
Returns the current Pipeline object back so commands can be
chained together, such as:
pipe = pipe.set('foo', 'bar').incr('baz').decr('bang')
At some other point, you can then run: pipe.execute(),
which will execute all commands queued in the pipe.
"""
self.command_stack.append((args, options))
return self
def _execute_transaction(self, connection, commands):
all_cmds = ''.join(starmap(connection.pack_command,
[args for args, options in commands]))
connection.send_packed_command(all_cmds)
# we don't care about the multi/exec any longer
commands = commands[1:-1]
# parse off the response for MULTI and all commands prior to EXEC.
# the only data we care about is the response the EXEC
# which is the last command
for i in range(len(commands)+1):
self.parse_response(connection, '_')
# parse the EXEC.
response = self.parse_response(connection, '_')
if response is None:
raise WatchError("Watched variable changed.")
if len(response) != len(commands):
raise ResponseError("Wrong number of response items from "
"pipeline execution")
# We have to run response callbacks manually
data = []
for r, cmd in izip(response, commands):
if not isinstance(r, Exception):
args, options = cmd
command_name = args[0]
if command_name in self.response_callbacks:
r = self.response_callbacks[command_name](r, **options)
data.append(r)
return data
def _execute_pipeline(self, connection, commands):
# build up all commands into a single request to increase network perf
all_cmds = ''.join(starmap(connection.pack_command,
[args for args, options in commands]))
connection.send_packed_command(all_cmds)
return [self.parse_response(connection, args[0], **options)
for args, options in commands]
def parse_response(self, connection, command_name, **options):
result = StrictRedis.parse_response(
self, connection, command_name, **options)
if command_name in self.UNWATCH_COMMANDS:
self.watching = False
elif command_name == 'WATCH':
self.watching = True
return result
def execute(self):
"Execute all the commands in the current pipeline"
stack = self.command_stack
if self.transaction or self.explicit_transaction:
stack = [(('MULTI', ), {})] + stack + [(('EXEC', ), {})]
execute = self._execute_transaction
else:
execute = self._execute_pipeline
conn = self.connection
if not conn:
conn = self.connection_pool.get_connection('MULTI', self.shard_hint)
# assign to self.connection so reset() releases the connection
# back to the pool after we're done
self.connection = conn
try:
return execute(conn, stack)
except ConnectionError:
conn.disconnect()
# if we were watching a variable, the watch is no longer valid since
# this connection has died. raise a WatchError, which indicates
# the user should retry his transaction. If this is more than a
# temporary failure, the WATCH that the user next issue will fail,
# propegating the real ConnectionError
if self.watching:
raise WatchError("A ConnectionError occured on while watching "
"one or more keys")
# otherwise, it's safe to retry since the transaction isn't
# predicated on any state
return execute(conn, stack)
finally:
self.reset()
def watch(self, *names):
"""
Watches the values at keys ``names``
"""
if self.explicit_transaction:
raise RedisError('Cannot issue a WATCH after a MULTI')
return self.execute_command('WATCH', *names)
def unwatch(self):
"""
Unwatches all previously specified keys
"""
return self.watching and self.execute_command('UNWATCH') or True
class StrictPipeline(BasePipeline, StrictRedis):
"Pipeline for the StrictRedis class"
pass
class Pipeline(BasePipeline, Redis):
"Pipeline for the Redis class"
pass
class LockError(RedisError):
"Errors thrown from the Lock"
pass
class Lock(object):
"""
A shared, distributed Lock. Using Redis for locking allows the Lock
to be shared across processes and/or machines.
It's left to the user to resolve deadlock issues and make sure
multiple clients play nicely together.
"""
LOCK_FOREVER = float(2**31+1) # 1 past max unix time
def __init__(self, redis, name, timeout=None, sleep=0.1):
"""
Create a new Lock instnace named ``name`` using the Redis client
supplied by ``redis``.
``timeout`` indicates a maximum life for the lock.
By default, it will remain locked until release() is called.
``sleep`` indicates the amount of time to sleep per loop iteration
when the lock is in blocking mode and another client is currently
holding the lock.
Note: If using ``timeout``, you should make sure all the hosts
that are running clients have their time synchronized with a network time
service like ntp.
"""
self.redis = redis
self.name = name
self.acquired_until = None
self.timeout = timeout
self.sleep = sleep
if self.timeout and self.sleep > self.timeout:
raise LockError("'sleep' must be less than 'timeout'")
def __enter__(self):
return self.acquire()
def __exit__(self, exc_type, exc_value, traceback):
self.release()
def acquire(self, blocking=True):
"""
Use Redis to hold a shared, distributed lock named ``name``.
Returns True once the lock is acquired.
If ``blocking`` is False, always return immediately. If the lock
was acquired, return True, otherwise return False.
"""
sleep = self.sleep
timeout = self.timeout
while 1:
unixtime = int(time.time())
if timeout:
timeout_at = unixtime + timeout
else:
timeout_at = Lock.LOCK_FOREVER
timeout_at = float(timeout_at)
if self.redis.setnx(self.name, timeout_at):
self.acquired_until = timeout_at
return True
# We want blocking, but didn't acquire the lock
# check to see if the current lock is expired
existing = float(self.redis.get(self.name) or 1)
if existing < unixtime:
# the previous lock is expired, attempt to overwrite it
existing = float(self.redis.getset(self.name, timeout_at) or 1)
if existing < unixtime:
# we successfully acquired the lock
self.acquired_until = timeout_at
return True
if not blocking:
return False
time.sleep(sleep)
def release(self):
"Releases the already acquired lock"
if self.acquired_until is None:
raise ValueError("Cannot release an unlocked lock")
existing = float(self.redis.get(self.name) or 1)
# if the lock time is in the future, delete the lock
if existing >= self.acquired_until:
self.redis.delete(self.name)
self.acquired_until = None
|
mpl-2.0
|
[
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
2197,
199,
646,
900,
199,
646,
3598,
199,
504,
7975,
492,
23646,
12,
28697,
12,
14664,
1130,
199,
504,
16967,
14,
2105,
492,
8113,
5453,
12,
13074,
7705,
3869,
3225,
199,
504,
16967,
14,
3924,
492,
334,
272,
25417,
12,
272,
3918,
547,
12,
272,
25496,
547,
12,
272,
7232,
547,
12,
272,
29075,
547,
12,
199,
9,
199,
199,
318,
769,
63,
269,
63,
589,
8,
1612,
12,
1249,
304,
272,
327,
2529,
282,
2849,
769,
29391,
2883,
436,
1249,
272,
862,
26,
267,
284,
275,
2740,
8,
1612,
9,
267,
327,
282,
1059,
883,
506,
27924,
12,
1325,
9126,
267,
327,
2883,
17373,
1133,
3032,
465,
282,
769,
267,
340,
1228,
8,
1612,
12,
7116,
304,
288,
2883,
275,
359,
1612,
61,
272,
871,
3146,
26,
267,
2883,
275,
359,
1612,
61,
272,
340,
1249,
26,
267,
2883,
14,
2880,
8,
589,
9,
272,
372,
2883,
199,
199,
318,
4913,
63,
475,
63,
2083,
8,
1310,
304,
272,
298,
17729,
282,
16572,
4913,
370,
282,
2018,
2197,
909,
2,
272,
340,
440,
1177,
26,
267,
372,
488,
272,
862,
26,
267,
1177,
275,
1109,
8,
1310,
9,
272,
871,
1722,
26,
267,
372,
488,
272,
372,
2197,
14,
2083,
14,
18531,
8,
1310,
9,
199,
199,
318,
1059,
63,
1612,
63,
475,
63,
807,
8,
498,
63,
875,
12,
3233,
304,
272,
372,
1211,
14,
19164,
8,
498,
63,
875,
14,
1294,
1062,
3233,
9,
199,
199,
318,
1211,
63,
5628,
2031,
7892,
304,
272,
9545,
275,
1052,
272,
359,
15269,
14,
873,
8,
68,
9,
367,
366,
315,
10809,
61,
272,
372,
9545,
199,
199,
318,
2198,
63,
1757,
63,
785,
8,
1310,
304,
272,
298,
4003,
314,
2058,
402,
25496,
1159,
10990,
28652,
5550,
1414,
1901,
282,
2018,
1211,
2,
272,
327,
710,
283,
466,
7,
402,
314,
909,
365,
314,
1642,
1242,
315,
314,
1177,
12,
1325,
5712,
1133,
272,
327,
18239,
543,
282,
536,
272,
1177,
275,
283,
466,
4881,
435,
1177,
272,
1177,
275,
1211,
779,
11475,
14,
1294,
11633,
367,
16616,
315,
1177,
14,
1294,
9383,
339,
327,
2198,
2005,
1420,
1109,
1338,
687,
314,
1059,
1177,
272,
327,
5317,
26,
642,
2088,
5712,
1133,
3158,
5121,
880,
3520,
1443,
440,
7468,
315,
1006,
16967,
5459,
272,
1109,
63,
955,
275,
661,
16497,
297,
283,
8397,
1267,
297,
283,
25003,
297,
283,
25003,
63,
4515,
63,
12000,
358,
272,
367,
901,
315,
1109,
63,
955,
26,
267,
340,
901,
315,
1177,
26,
288,
1177,
59,
698,
61,
275,
1109,
8,
1310,
59,
698,
566,
339,
372,
1177,
199,
199,
318,
2198,
63,
785,
8,
1310,
12,
10739,
7818,
304,
272,
298,
4003,
314,
2058,
402,
376,
28652,
5550,
1414,
2,
272,
340,
10739,
7818,
315,
661,
12000,
521,
297,
283,
16497,
735,
267,
372,
1109,
8,
1310,
9,
272,
372,
1177,
199,
199,
318,
2198,
63,
815,
8,
1310,
304,
272,
298,
4003,
314,
754,
402,
25496,
1159,
24008,
1414,
1901,
282,
2018,
1211,
2,
272,
2256,
275,
1052,
339,
347,
664,
63,
585,
8,
585,
304,
267,
340,
13647,
440,
315,
574,
503,
14051,
440,
315,
574,
26,
288,
372,
574,
398,
1007,
63,
807,
275,
1052,
267,
367,
1242,
315,
574,
14,
1294,
25908,
288,
1022,
12,
373,
275,
1242,
14,
13490,
25283,
413,
9,
288,
862,
26,
355,
1007,
63,
807,
59,
75,
61,
275,
1109,
8,
86,
9,
288,
871,
1722,
26,
355,
1007,
63,
807,
59,
75,
61,
275,
373,
267,
372,
1007,
63,
807,
339,
367,
1004,
315,
1177,
14,
7644,
837,
267,
340,
1004,
436,
440,
1004,
14,
2460,
7863,
735,
288,
790,
12,
574,
275,
1004,
14,
1294,
11633,
288,
862,
26,
355,
340,
7815,
315,
574,
26,
490,
2256,
59,
498,
61,
275,
2069,
8,
585,
9,
355,
587,
26,
490,
2256,
59,
498,
61,
275,
1109,
8,
585,
9,
288,
871,
1722,
26,
355,
2256,
59,
498,
61,
275,
664,
63,
585,
8,
585,
9,
272,
372,
2256,
199,
199,
318,
6342,
63,
475,
63,
807,
8,
1310,
304,
272,
298,
2499,
282,
1211,
1627,
282,
769,
402,
790,
15,
585,
6342,
2,
272,
652,
275,
2740,
8,
1310,
9,
272,
372,
1211,
8,
565,
711,
8,
390,
12,
652,
430,
199,
199,
318,
1315,
409,
63,
3397,
63,
7322,
8,
1310,
12,
1011,
1419,
304,
272,
408,
272,
982,
1124,
1045,
7107,
1040,
365,
2013,
315,
314,
1511,
12,
372,
314,
1177,
465,
272,
282,
769,
402,
334,
585,
12,
5396,
9,
6342,
272,
408,
272,
340,
440,
1177,
503,
440,
1511,
459,
1045,
7107,
2565,
267,
372,
1177,
272,
5396,
63,
2931,
63,
1532,
275,
1511,
14,
362,
360,
3397,
63,
2931,
63,
1532,
297,
2069,
9,
272,
652,
275,
2740,
8,
1310,
9,
272,
372,
3482,
8,
390,
12,
23646,
8,
3397,
63,
2931,
63,
1532,
12,
652,
430,
199,
199,
318,
1109,
63,
269,
63,
3592,
8,
1310,
304,
272,
340,
1177,
365,
488,
26,
267,
372,
488,
272,
372,
1109,
8,
1310,
9,
199,
199,
318,
2069,
63,
269,
63,
3592,
8,
1310,
304,
272,
340,
1177,
365,
488,
26,
267,
372,
488,
272,
372,
2069,
8,
1310,
9,
199,
199,
318,
2198,
63,
888,
8,
1310,
12,
1011,
1419,
304,
272,
327,
642,
365,
410,
31596,
12,
1325,
2793,
1133,
1172,
282,
8034,
945,
2451,
3063,
272,
340,
1511,
459,
1122,
418,
508,
283,
2970,
356,
267,
372,
1177,
436,
6342,
63,
475,
63,
807,
8,
1310,
9,
503,
1052,
272,
372,
1177,
508,
283,
3593,
7,
199,
199,
533,
23052,
29605,
8,
785,
304,
272,
408,
272,
24425,
402,
314,
25496,
4113,
14,
339,
961,
9006,
1021,
6571,
282,
2018,
3217,
370,
1006,
25496,
3718,
272,
436,
376,
4514,
402,
314,
25496,
4113,
14,
339,
8113,
436,
19090,
23519,
687,
642,
12,
18234,
4212,
272,
314,
3718,
787,
4847,
436,
3086,
370,
314,
25496,
1654,
272,
408,
272,
820,
7613,
11827,
63,
28100,
51,
275,
1211,
63,
5628,
8,
267,
1059,
63,
1612,
63,
475,
63,
807,
8,
288,
283,
5580,
12355,
23875,
3651,
2252,
907,
3651,
2252,
907,
619,
869,
4424,
869,
23558,
869,
3053,
775,
10362,
2524
] |
[
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
2197,
199,
646,
900,
199,
646,
3598,
199,
504,
7975,
492,
23646,
12,
28697,
12,
14664,
1130,
199,
504,
16967,
14,
2105,
492,
8113,
5453,
12,
13074,
7705,
3869,
3225,
199,
504,
16967,
14,
3924,
492,
334,
272,
25417,
12,
272,
3918,
547,
12,
272,
25496,
547,
12,
272,
7232,
547,
12,
272,
29075,
547,
12,
199,
9,
199,
199,
318,
769,
63,
269,
63,
589,
8,
1612,
12,
1249,
304,
272,
327,
2529,
282,
2849,
769,
29391,
2883,
436,
1249,
272,
862,
26,
267,
284,
275,
2740,
8,
1612,
9,
267,
327,
282,
1059,
883,
506,
27924,
12,
1325,
9126,
267,
327,
2883,
17373,
1133,
3032,
465,
282,
769,
267,
340,
1228,
8,
1612,
12,
7116,
304,
288,
2883,
275,
359,
1612,
61,
272,
871,
3146,
26,
267,
2883,
275,
359,
1612,
61,
272,
340,
1249,
26,
267,
2883,
14,
2880,
8,
589,
9,
272,
372,
2883,
199,
199,
318,
4913,
63,
475,
63,
2083,
8,
1310,
304,
272,
298,
17729,
282,
16572,
4913,
370,
282,
2018,
2197,
909,
2,
272,
340,
440,
1177,
26,
267,
372,
488,
272,
862,
26,
267,
1177,
275,
1109,
8,
1310,
9,
272,
871,
1722,
26,
267,
372,
488,
272,
372,
2197,
14,
2083,
14,
18531,
8,
1310,
9,
199,
199,
318,
1059,
63,
1612,
63,
475,
63,
807,
8,
498,
63,
875,
12,
3233,
304,
272,
372,
1211,
14,
19164,
8,
498,
63,
875,
14,
1294,
1062,
3233,
9,
199,
199,
318,
1211,
63,
5628,
2031,
7892,
304,
272,
9545,
275,
1052,
272,
359,
15269,
14,
873,
8,
68,
9,
367,
366,
315,
10809,
61,
272,
372,
9545,
199,
199,
318,
2198,
63,
1757,
63,
785,
8,
1310,
304,
272,
298,
4003,
314,
2058,
402,
25496,
1159,
10990,
28652,
5550,
1414,
1901,
282,
2018,
1211,
2,
272,
327,
710,
283,
466,
7,
402,
314,
909,
365,
314,
1642,
1242,
315,
314,
1177,
12,
1325,
5712,
1133,
272,
327,
18239,
543,
282,
536,
272,
1177,
275,
283,
466,
4881,
435,
1177,
272,
1177,
275,
1211,
779,
11475,
14,
1294,
11633,
367,
16616,
315,
1177,
14,
1294,
9383,
339,
327,
2198,
2005,
1420,
1109,
1338,
687,
314,
1059,
1177,
272,
327,
5317,
26,
642,
2088,
5712,
1133,
3158,
5121,
880,
3520,
1443,
440,
7468,
315,
1006,
16967,
5459,
272,
1109,
63,
955,
275,
661,
16497,
297,
283,
8397,
1267,
297,
283,
25003,
297,
283,
25003,
63,
4515,
63,
12000,
358,
272,
367,
901,
315,
1109,
63,
955,
26,
267,
340,
901,
315,
1177,
26,
288,
1177,
59,
698,
61,
275,
1109,
8,
1310,
59,
698,
566,
339,
372,
1177,
199,
199,
318,
2198,
63,
785,
8,
1310,
12,
10739,
7818,
304,
272,
298,
4003,
314,
2058,
402,
376,
28652,
5550,
1414,
2,
272,
340,
10739,
7818,
315,
661,
12000,
521,
297,
283,
16497,
735,
267,
372,
1109,
8,
1310,
9,
272,
372,
1177,
199,
199,
318,
2198,
63,
815,
8,
1310,
304,
272,
298,
4003,
314,
754,
402,
25496,
1159,
24008,
1414,
1901,
282,
2018,
1211,
2,
272,
2256,
275,
1052,
339,
347,
664,
63,
585,
8,
585,
304,
267,
340,
13647,
440,
315,
574,
503,
14051,
440,
315,
574,
26,
288,
372,
574,
398,
1007,
63,
807,
275,
1052,
267,
367,
1242,
315,
574,
14,
1294,
25908,
288,
1022,
12,
373,
275,
1242,
14,
13490,
25283,
413,
9,
288,
862,
26,
355,
1007,
63,
807,
59,
75,
61,
275,
1109,
8,
86,
9,
288,
871,
1722,
26,
355,
1007,
63,
807,
59,
75,
61,
275,
373,
267,
372,
1007,
63,
807,
339,
367,
1004,
315,
1177,
14,
7644,
837,
267,
340,
1004,
436,
440,
1004,
14,
2460,
7863,
735,
288,
790,
12,
574,
275,
1004,
14,
1294,
11633,
288,
862,
26,
355,
340,
7815,
315,
574,
26,
490,
2256,
59,
498,
61,
275,
2069,
8,
585,
9,
355,
587,
26,
490,
2256,
59,
498,
61,
275,
1109,
8,
585,
9,
288,
871,
1722,
26,
355,
2256,
59,
498,
61,
275,
664,
63,
585,
8,
585,
9,
272,
372,
2256,
199,
199,
318,
6342,
63,
475,
63,
807,
8,
1310,
304,
272,
298,
2499,
282,
1211,
1627,
282,
769,
402,
790,
15,
585,
6342,
2,
272,
652,
275,
2740,
8,
1310,
9,
272,
372,
1211,
8,
565,
711,
8,
390,
12,
652,
430,
199,
199,
318,
1315,
409,
63,
3397,
63,
7322,
8,
1310,
12,
1011,
1419,
304,
272,
408,
272,
982,
1124,
1045,
7107,
1040,
365,
2013,
315,
314,
1511,
12,
372,
314,
1177,
465,
272,
282,
769,
402,
334,
585,
12,
5396,
9,
6342,
272,
408,
272,
340,
440,
1177,
503,
440,
1511,
459,
1045,
7107,
2565,
267,
372,
1177,
272,
5396,
63,
2931,
63,
1532,
275,
1511,
14,
362,
360,
3397,
63,
2931,
63,
1532,
297,
2069,
9,
272,
652,
275,
2740,
8,
1310,
9,
272,
372,
3482,
8,
390,
12,
23646,
8,
3397,
63,
2931,
63,
1532,
12,
652,
430,
199,
199,
318,
1109,
63,
269,
63,
3592,
8,
1310,
304,
272,
340,
1177,
365,
488,
26,
267,
372,
488,
272,
372,
1109,
8,
1310,
9,
199,
199,
318,
2069,
63,
269,
63,
3592,
8,
1310,
304,
272,
340,
1177,
365,
488,
26,
267,
372,
488,
272,
372,
2069,
8,
1310,
9,
199,
199,
318,
2198,
63,
888,
8,
1310,
12,
1011,
1419,
304,
272,
327,
642,
365,
410,
31596,
12,
1325,
2793,
1133,
1172,
282,
8034,
945,
2451,
3063,
272,
340,
1511,
459,
1122,
418,
508,
283,
2970,
356,
267,
372,
1177,
436,
6342,
63,
475,
63,
807,
8,
1310,
9,
503,
1052,
272,
372,
1177,
508,
283,
3593,
7,
199,
199,
533,
23052,
29605,
8,
785,
304,
272,
408,
272,
24425,
402,
314,
25496,
4113,
14,
339,
961,
9006,
1021,
6571,
282,
2018,
3217,
370,
1006,
25496,
3718,
272,
436,
376,
4514,
402,
314,
25496,
4113,
14,
339,
8113,
436,
19090,
23519,
687,
642,
12,
18234,
4212,
272,
314,
3718,
787,
4847,
436,
3086,
370,
314,
25496,
1654,
272,
408,
272,
820,
7613,
11827,
63,
28100,
51,
275,
1211,
63,
5628,
8,
267,
1059,
63,
1612,
63,
475,
63,
807,
8,
288,
283,
5580,
12355,
23875,
3651,
2252,
907,
3651,
2252,
907,
619,
869,
4424,
869,
23558,
869,
3053,
775,
10362,
2524,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
manazhao/tf_recsys
|
tensorflow/python/ops/distributions/dirichlet_multinomial.py
|
39
|
13187
|
# 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.
# ==============================================================================
"""The DirichletMultinomial distribution class."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import check_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import special_math_ops
from tensorflow.python.ops.distributions import distribution
from tensorflow.python.ops.distributions import util as distribution_util
__all__ = [
"DirichletMultinomial",
]
_dirichlet_multinomial_sample_note = """For each batch of counts,
`value = [n_0, ..., n_{K-1}]`, `P[value]` is the probability that after
sampling `self.total_count` draws from this Dirichlet-Multinomial distribution,
the number of draws falling in class `j` is `n_j`. Since this definition is
[exchangeable](https://en.wikipedia.org/wiki/Exchangeable_random_variables);
different sequences have the same counts so the probability includes a
combinatorial coefficient.
Note: `value` must be a non-negative tensor with dtype `self.dtype`, have no
fractional components, and such that
`tf.reduce_sum(value, -1) = self.total_count`. Its shape must be broadcastable
with `self.concentration` and `self.total_count`."""
class DirichletMultinomial(distribution.Distribution):
"""Dirichlet-Multinomial compound distribution.
The Dirichlet-Multinomial distribution is parameterized by a (batch of)
length-`K` `concentration` vectors (`K > 1`) and a `total_count` number of
trials, i.e., the number of trials per draw from the DirichletMultinomial. It
is defined over a (batch of) length-`K` vector `counts` such that
`tf.reduce_sum(counts, -1) = total_count`. The Dirichlet-Multinomial is
identically the Beta-Binomial distribution when `K = 2`.
#### Mathematical Details
The Dirichlet-Multinomial is a distribution over `K`-class counts, i.e., a
length-`K` vector of non-negative integer `counts = n = [n_0, ..., n_{K-1}]`.
The probability mass function (pmf) is,
```none
pmf(n; alpha, N) = Beta(alpha + n) / (prod_j n_j!) / Z
Z = Beta(alpha) / N!
```
where:
* `concentration = alpha = [alpha_0, ..., alpha_{K-1}]`, `alpha_j > 0`,
* `total_count = N`, `N` a positive integer,
* `N!` is `N` factorial, and,
* `Beta(x) = prod_j Gamma(x_j) / Gamma(sum_j x_j)` is the
[multivariate beta function](
https://en.wikipedia.org/wiki/Beta_function#Multivariate_beta_function),
and,
* `Gamma` is the [gamma function](
https://en.wikipedia.org/wiki/Gamma_function).
Dirichlet-Multinomial is a [compound distribution](
https://en.wikipedia.org/wiki/Compound_probability_distribution), i.e., its
samples are generated as follows.
1. Choose class probabilities:
`probs = [p_0,...,p_{K-1}] ~ Dir(concentration)`
2. Draw integers:
`counts = [n_0,...,n_{K-1}] ~ Multinomial(total_count, probs)`
The last `concentration` dimension parametrizes a single Dirichlet-Multinomial
distribution. When calling distribution functions (e.g., `dist.prob(counts)`),
`concentration`, `total_count` and `counts` are broadcast to the same shape.
The last dimension of `counts` corresponds single Dirichlet-Multinomial
distributions.
Distribution parameters are automatically broadcast in all functions; see
examples for details.
#### Pitfalls
The number of classes, `K`, must not exceed:
- the largest integer representable by `self.dtype`, i.e.,
`2**(mantissa_bits+1)` (IEE754),
- the maximum `Tensor` index, i.e., `2**31-1`.
In other words,
```python
K <= min(2**31-1, {
tf.float16: 2**11,
tf.float32: 2**24,
tf.float64: 2**53 }[param.dtype])
```
Note: This condition is validated only when `self.validate_args = True`.
#### Examples
```python
alpha = [1, 2, 3]
n = 2
dist = DirichletMultinomial(n, alpha)
```
Creates a 3-class distribution, with the 3rd class is most likely to be drawn.
The distribution functions can be evaluated on counts.
```python
# counts same shape as alpha.
counts = [0, 0, 2]
dist.prob(counts) # Shape []
# alpha will be broadcast to [[1, 2, 3], [1, 2, 3]] to match counts.
counts = [[1, 1, 0], [1, 0, 1]]
dist.prob(counts) # Shape [2]
# alpha will be broadcast to shape [5, 7, 3] to match counts.
counts = [[...]] # Shape [5, 7, 3]
dist.prob(counts) # Shape [5, 7]
```
Creates a 2-batch of 3-class distributions.
```python
alpha = [[1, 2, 3], [4, 5, 6]] # Shape [2, 3]
n = [3, 3]
dist = DirichletMultinomial(n, alpha)
# counts will be broadcast to [[2, 1, 0], [2, 1, 0]] to match alpha.
counts = [2, 1, 0]
dist.prob(counts) # Shape [2]
```
"""
# TODO(b/27419586) Change docstring for dtype of concentration once int
# allowed.
def __init__(self,
total_count,
concentration,
validate_args=False,
allow_nan_stats=True,
name="DirichletMultinomial"):
"""Initialize a batch of DirichletMultinomial distributions.
Args:
total_count: Non-negative floating point tensor, whose dtype is the same
as `concentration`. The shape is broadcastable to `[N1,..., Nm]` with
`m >= 0`. Defines this as a batch of `N1 x ... x Nm` different
Dirichlet multinomial distributions. Its components should be equal to
integer values.
concentration: Positive floating point tensor, whose dtype is the
same as `n` with shape broadcastable to `[N1,..., Nm, K]` `m >= 0`.
Defines this as a batch of `N1 x ... x Nm` different `K` class Dirichlet
multinomial distributions.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
(e.g., mean, mode, variance) use the value "`NaN`" to indicate the
result is undefined. When `False`, an exception is raised if one or
more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.
"""
parameters = locals()
with ops.name_scope(name, values=[total_count, concentration]):
# Broadcasting works because:
# * The broadcasting convention is to prepend dimensions of size [1], and
# we use the last dimension for the distribution, whereas
# the batch dimensions are the leading dimensions, which forces the
# distribution dimension to be defined explicitly (i.e. it cannot be
# created automatically by prepending). This forces enough explicitness.
# * All calls involving `counts` eventually require a broadcast between
# `counts` and concentration.
self._total_count = ops.convert_to_tensor(total_count, name="total_count")
if validate_args:
self._total_count = (
distribution_util.embed_check_nonnegative_integer_form(
self._total_count))
self._concentration = self._maybe_assert_valid_concentration(
ops.convert_to_tensor(concentration,
name="concentration"),
validate_args)
self._total_concentration = math_ops.reduce_sum(self._concentration, -1)
super(DirichletMultinomial, self).__init__(
dtype=self._concentration.dtype,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
reparameterization_type=distribution.NOT_REPARAMETERIZED,
parameters=parameters,
graph_parents=[self._total_count,
self._concentration],
name=name)
@property
def total_count(self):
"""Number of trials used to construct a sample."""
return self._total_count
@property
def concentration(self):
"""Concentration parameter; expected prior counts for that coordinate."""
return self._concentration
@property
def total_concentration(self):
"""Sum of last dim of concentration parameter."""
return self._total_concentration
def _batch_shape_tensor(self):
return array_ops.shape(self.total_concentration)
def _batch_shape(self):
return self.total_concentration.get_shape()
def _event_shape_tensor(self):
return array_ops.shape(self.concentration)[-1:]
def _event_shape(self):
# Event shape depends only on total_concentration, not "n".
return self.concentration.get_shape().with_rank_at_least(1)[-1:]
def _sample_n(self, n, seed=None):
n_draws = math_ops.cast(self.total_count, dtype=dtypes.int32)
k = self.event_shape_tensor()[0]
unnormalized_logits = array_ops.reshape(
math_ops.log(random_ops.random_gamma(
shape=[n],
alpha=self.concentration,
dtype=self.dtype,
seed=seed)),
shape=[-1, k])
draws = random_ops.multinomial(
logits=unnormalized_logits,
num_samples=n_draws,
seed=distribution_util.gen_new_seed(seed, salt="dirichlet_multinomial"))
x = math_ops.reduce_sum(array_ops.one_hot(draws, depth=k), -2)
final_shape = array_ops.concat([[n], self.batch_shape_tensor(), [k]], 0)
x = array_ops.reshape(x, final_shape)
return math_ops.cast(x, self.dtype)
@distribution_util.AppendDocstring(_dirichlet_multinomial_sample_note)
def _log_prob(self, counts):
counts = self._maybe_assert_valid_sample(counts)
ordered_prob = (
special_math_ops.lbeta(self.concentration + counts)
- special_math_ops.lbeta(self.concentration))
return ordered_prob + distribution_util.log_combinations(
self.total_count, counts)
@distribution_util.AppendDocstring(_dirichlet_multinomial_sample_note)
def _prob(self, counts):
return math_ops.exp(self._log_prob(counts))
def _mean(self):
return self.total_count * (self.concentration /
self.total_concentration[..., array_ops.newaxis])
@distribution_util.AppendDocstring(
"""The covariance for each batch member is defined as the following:
```none
Var(X_j) = n * alpha_j / alpha_0 * (1 - alpha_j / alpha_0) *
(n + alpha_0) / (1 + alpha_0)
```
where `concentration = alpha` and
`total_concentration = alpha_0 = sum_j alpha_j`.
The covariance between elements in a batch is defined as:
```none
Cov(X_i, X_j) = -n * alpha_i * alpha_j / alpha_0 ** 2 *
(n + alpha_0) / (1 + alpha_0)
```
""")
def _covariance(self):
x = self._variance_scale_term() * self._mean()
return array_ops.matrix_set_diag(
-math_ops.matmul(x[..., array_ops.newaxis],
x[..., array_ops.newaxis, :]), # outer prod
self._variance())
def _variance(self):
scale = self._variance_scale_term()
x = scale * self._mean()
return x * (self.total_count * scale - x)
def _variance_scale_term(self):
"""Helper to `_covariance` and `_variance` which computes a shared scale."""
# We must take care to expand back the last dim whenever we use the
# total_concentration.
c0 = self.total_concentration[..., array_ops.newaxis]
return math_ops.sqrt((1. + c0 / self.total_count) / (1. + c0))
def _maybe_assert_valid_concentration(self, concentration, validate_args):
"""Checks the validity of the concentration parameter."""
if not validate_args:
return concentration
concentration = distribution_util.embed_check_categorical_event_shape(
concentration)
return control_flow_ops.with_dependencies([
check_ops.assert_positive(
concentration,
message="Concentration parameter must be positive."),
], concentration)
def _maybe_assert_valid_sample(self, counts):
"""Check counts for proper shape, values, then return tensor version."""
if not self.validate_args:
return counts
counts = distribution_util.embed_check_nonnegative_integer_form(counts)
return control_flow_ops.with_dependencies([
check_ops.assert_equal(
self.total_count, math_ops.reduce_sum(counts, -1),
message="counts last-dimension must sum to `self.total_count`"),
], counts)
|
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,
1918,
3757,
19683,
30233,
16956,
4084,
1021,
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,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4539,
63,
3442,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4084,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4884,
465,
4084,
63,
1974,
421,
199,
363,
452,
363,
275,
359,
272,
298,
1341,
19683,
30233,
16956,
401,
199,
61,
421,
199,
63,
328,
19683,
63,
28265,
63,
3271,
63,
4610,
275,
408,
1858,
1924,
3522,
402,
8242,
12,
199,
64,
585,
275,
359,
78,
63,
16,
12,
14263,
302,
7348,
43,
13,
17,
11049,
3559,
658,
48,
59,
585,
16090,
365,
314,
12224,
626,
2410,
199,
17376,
658,
277,
14,
2923,
63,
835,
64,
5954,
83,
687,
642,
3757,
19683,
13,
30233,
16956,
4084,
12,
199,
1589,
1329,
402,
5954,
83,
32039,
315,
1021,
658,
74,
64,
365,
658,
78,
63,
74,
2313,
9336,
642,
5492,
365,
199,
59,
14197,
461,
8738,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
13188,
461,
63,
2355,
63,
3669,
2736,
199,
14020,
8013,
1172,
314,
2011,
8242,
880,
314,
12224,
6952,
282,
199,
6560,
8566,
2380,
9421,
14,
199,
199,
7443,
26,
658,
585,
64,
1471,
506,
282,
2222,
13,
7371,
2345,
543,
2152,
658,
277,
14,
2271,
3559,
1172,
949,
199,
13054,
279,
7323,
12,
436,
4066,
626,
199,
64,
3249,
14,
5270,
63,
1838,
8,
585,
12,
446,
17,
9,
275,
291,
14,
2923,
63,
835,
2313,
22940,
2215,
1471,
506,
11180,
461,
199,
1045,
658,
277,
14,
26823,
64,
436,
658,
277,
14,
2923,
63,
835,
17105,
421,
199,
533,
3757,
19683,
30233,
16956,
8,
4972,
14,
8580,
304,
523,
408,
1341,
19683,
13,
30233,
16956,
16487,
4084,
14,
819,
710,
3757,
19683,
13,
30233,
16956,
4084,
365,
29526,
701,
282,
334,
2912,
402,
9,
523,
2582,
13,
64,
43,
64,
658,
26823,
64,
11102,
13493,
43,
690,
413,
10522,
436,
282,
658,
2923,
63,
835,
64,
1329,
402,
523,
16324,
83,
12,
284,
14,
69,
2020,
314,
1329,
402,
16324,
83,
1126,
5954,
687,
314,
3757,
19683,
30233,
16956,
14,
2779,
523,
365,
3247,
1806,
282,
334,
2912,
402,
9,
2582,
13,
64,
43,
64,
5477,
658,
6851,
64,
4066,
626,
523,
658,
3249,
14,
5270,
63,
1838,
8,
6851,
12,
446,
17,
9,
275,
3141,
63,
835,
2313,
710,
3757,
19683,
13,
30233,
16956,
365,
523,
6120,
17269,
314,
29521,
13,
13394,
6471,
4084,
1380,
658,
43,
275,
499,
2313,
819,
14055,
16593,
28491,
15621,
819,
710,
3757,
19683,
13,
30233,
16956,
365,
282,
4084,
1806,
658,
43,
64,
13,
533,
8242,
12,
284,
14,
69,
2020,
282,
523,
2582,
13,
64,
43,
64,
5477,
402,
2222,
13,
7371,
3000,
658,
6851,
275,
302,
275,
359,
78,
63,
16,
12,
14263,
302,
7348,
43,
13,
17,
11049,
2313,
819,
710,
12224,
12250,
805,
334,
31842,
9,
365,
12,
819,
10841,
3592,
523,
299,
11821,
8,
78,
27,
5131,
12,
653,
9,
275,
29521,
8,
4468,
435,
302,
9,
1182,
334,
8788,
63,
74,
302,
63,
74,
21866,
1182,
3107,
523,
3107,
275,
29521,
8,
4468,
9,
1182,
653,
1,
523,
10841,
819,
2382,
26,
819,
627,
658,
26823,
275,
5131,
275,
359,
4468,
63,
16,
12,
14263,
5131,
7348,
43,
13,
17,
11049,
3559,
658,
4468,
63,
74,
690,
378,
3559,
523,
627,
658,
2923,
63,
835,
275,
653,
3559,
658,
46,
64,
282,
7317,
3000,
12,
523,
627,
658,
46,
1,
64,
365,
658,
46,
64,
32618,
12,
436,
12,
523,
627,
658,
21732,
8,
88,
9,
275,
12441,
63,
74,
598,
4746,
8,
88,
63,
74,
9,
1182,
598,
4746,
8,
1838,
63,
74,
671,
63,
74,
12544,
365,
314,
272,
359,
3029,
13805,
8201,
805,
8738,
272,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
21732,
63,
1593,
3,
3947,
13805,
63,
5683,
63,
1593,
395,
272,
436,
12,
523,
627,
658,
15091,
64,
365,
314,
359,
7325,
805,
8738,
272,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
15091,
63,
1593,
680,
819,
3757,
19683,
13,
30233,
16956,
365,
282,
359,
15278,
4084,
8738,
523,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
26552,
63,
17210,
63,
4972,
395,
284,
14,
69,
2020,
2399,
523,
5845,
787,
4046,
465,
11924,
14,
339,
413,
14,
29826,
1021,
19555,
26,
2126,
658,
15349,
275,
359,
80,
63,
16,
32699,
80,
7348,
43,
13,
17,
11049,
6146,
25866,
8,
26823,
12544,
272,
499,
14,
17813,
9446,
26,
2126,
658,
6851,
275,
359,
78,
63,
16,
32699,
78,
7348,
43,
13,
17,
11049,
6146,
603,
427,
16956,
8,
2923,
63,
835,
12,
24329,
12544,
819,
710,
2061,
658,
26823,
64,
6240
] |
[
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,
1918,
3757,
19683,
30233,
16956,
4084,
1021,
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,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4539,
63,
3442,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4084,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4884,
465,
4084,
63,
1974,
421,
199,
363,
452,
363,
275,
359,
272,
298,
1341,
19683,
30233,
16956,
401,
199,
61,
421,
199,
63,
328,
19683,
63,
28265,
63,
3271,
63,
4610,
275,
408,
1858,
1924,
3522,
402,
8242,
12,
199,
64,
585,
275,
359,
78,
63,
16,
12,
14263,
302,
7348,
43,
13,
17,
11049,
3559,
658,
48,
59,
585,
16090,
365,
314,
12224,
626,
2410,
199,
17376,
658,
277,
14,
2923,
63,
835,
64,
5954,
83,
687,
642,
3757,
19683,
13,
30233,
16956,
4084,
12,
199,
1589,
1329,
402,
5954,
83,
32039,
315,
1021,
658,
74,
64,
365,
658,
78,
63,
74,
2313,
9336,
642,
5492,
365,
199,
59,
14197,
461,
8738,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
13188,
461,
63,
2355,
63,
3669,
2736,
199,
14020,
8013,
1172,
314,
2011,
8242,
880,
314,
12224,
6952,
282,
199,
6560,
8566,
2380,
9421,
14,
199,
199,
7443,
26,
658,
585,
64,
1471,
506,
282,
2222,
13,
7371,
2345,
543,
2152,
658,
277,
14,
2271,
3559,
1172,
949,
199,
13054,
279,
7323,
12,
436,
4066,
626,
199,
64,
3249,
14,
5270,
63,
1838,
8,
585,
12,
446,
17,
9,
275,
291,
14,
2923,
63,
835,
2313,
22940,
2215,
1471,
506,
11180,
461,
199,
1045,
658,
277,
14,
26823,
64,
436,
658,
277,
14,
2923,
63,
835,
17105,
421,
199,
533,
3757,
19683,
30233,
16956,
8,
4972,
14,
8580,
304,
523,
408,
1341,
19683,
13,
30233,
16956,
16487,
4084,
14,
819,
710,
3757,
19683,
13,
30233,
16956,
4084,
365,
29526,
701,
282,
334,
2912,
402,
9,
523,
2582,
13,
64,
43,
64,
658,
26823,
64,
11102,
13493,
43,
690,
413,
10522,
436,
282,
658,
2923,
63,
835,
64,
1329,
402,
523,
16324,
83,
12,
284,
14,
69,
2020,
314,
1329,
402,
16324,
83,
1126,
5954,
687,
314,
3757,
19683,
30233,
16956,
14,
2779,
523,
365,
3247,
1806,
282,
334,
2912,
402,
9,
2582,
13,
64,
43,
64,
5477,
658,
6851,
64,
4066,
626,
523,
658,
3249,
14,
5270,
63,
1838,
8,
6851,
12,
446,
17,
9,
275,
3141,
63,
835,
2313,
710,
3757,
19683,
13,
30233,
16956,
365,
523,
6120,
17269,
314,
29521,
13,
13394,
6471,
4084,
1380,
658,
43,
275,
499,
2313,
819,
14055,
16593,
28491,
15621,
819,
710,
3757,
19683,
13,
30233,
16956,
365,
282,
4084,
1806,
658,
43,
64,
13,
533,
8242,
12,
284,
14,
69,
2020,
282,
523,
2582,
13,
64,
43,
64,
5477,
402,
2222,
13,
7371,
3000,
658,
6851,
275,
302,
275,
359,
78,
63,
16,
12,
14263,
302,
7348,
43,
13,
17,
11049,
2313,
819,
710,
12224,
12250,
805,
334,
31842,
9,
365,
12,
819,
10841,
3592,
523,
299,
11821,
8,
78,
27,
5131,
12,
653,
9,
275,
29521,
8,
4468,
435,
302,
9,
1182,
334,
8788,
63,
74,
302,
63,
74,
21866,
1182,
3107,
523,
3107,
275,
29521,
8,
4468,
9,
1182,
653,
1,
523,
10841,
819,
2382,
26,
819,
627,
658,
26823,
275,
5131,
275,
359,
4468,
63,
16,
12,
14263,
5131,
7348,
43,
13,
17,
11049,
3559,
658,
4468,
63,
74,
690,
378,
3559,
523,
627,
658,
2923,
63,
835,
275,
653,
3559,
658,
46,
64,
282,
7317,
3000,
12,
523,
627,
658,
46,
1,
64,
365,
658,
46,
64,
32618,
12,
436,
12,
523,
627,
658,
21732,
8,
88,
9,
275,
12441,
63,
74,
598,
4746,
8,
88,
63,
74,
9,
1182,
598,
4746,
8,
1838,
63,
74,
671,
63,
74,
12544,
365,
314,
272,
359,
3029,
13805,
8201,
805,
8738,
272,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
21732,
63,
1593,
3,
3947,
13805,
63,
5683,
63,
1593,
395,
272,
436,
12,
523,
627,
658,
15091,
64,
365,
314,
359,
7325,
805,
8738,
272,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
15091,
63,
1593,
680,
819,
3757,
19683,
13,
30233,
16956,
365,
282,
359,
15278,
4084,
8738,
523,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
26552,
63,
17210,
63,
4972,
395,
284,
14,
69,
2020,
2399,
523,
5845,
787,
4046,
465,
11924,
14,
339,
413,
14,
29826,
1021,
19555,
26,
2126,
658,
15349,
275,
359,
80,
63,
16,
32699,
80,
7348,
43,
13,
17,
11049,
6146,
25866,
8,
26823,
12544,
272,
499,
14,
17813,
9446,
26,
2126,
658,
6851,
275,
359,
78,
63,
16,
32699,
78,
7348,
43,
13,
17,
11049,
6146,
603,
427,
16956,
8,
2923,
63,
835,
12,
24329,
12544,
819,
710,
2061,
658,
26823,
64,
6240,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sudheesh001/oh-mainline
|
vendor/packages/PyYaml/examples/yaml-highlight/yaml_hl.py
|
95
|
4429
|
#!/usr/bin/python
import yaml, codecs, sys, os.path, optparse
class Style:
def __init__(self, header=None, footer=None,
tokens=None, events=None, replaces=None):
self.header = header
self.footer = footer
self.replaces = replaces
self.substitutions = {}
for domain, Class in [(tokens, 'Token'), (events, 'Event')]:
if not domain:
continue
for key in domain:
name = ''.join([part.capitalize() for part in key.split('-')])
cls = getattr(yaml, '%s%s' % (name, Class))
value = domain[key]
if not value:
continue
start = value.get('start')
end = value.get('end')
if start:
self.substitutions[cls, -1] = start
if end:
self.substitutions[cls, +1] = end
def __setstate__(self, state):
self.__init__(**state)
yaml.add_path_resolver(u'tag:yaml.org,2002:python/object:__main__.Style',
[None], dict)
yaml.add_path_resolver(u'tag:yaml.org,2002:pairs',
[None, u'replaces'], list)
class YAMLHighlight:
def __init__(self, options):
config = yaml.load(file(options.config, 'rb').read())
self.style = config[options.style]
if options.input:
self.input = file(options.input, 'rb')
else:
self.input = sys.stdin
if options.output:
self.output = file(options.output, 'wb')
else:
self.output = sys.stdout
def highlight(self):
input = self.input.read()
if input.startswith(codecs.BOM_UTF16_LE):
input = unicode(input, 'utf-16-le')
elif input.startswith(codecs.BOM_UTF16_BE):
input = unicode(input, 'utf-16-be')
else:
input = unicode(input, 'utf-8')
substitutions = self.style.substitutions
tokens = yaml.scan(input)
events = yaml.parse(input)
markers = []
number = 0
for token in tokens:
number += 1
if token.start_mark.index != token.end_mark.index:
cls = token.__class__
if (cls, -1) in substitutions:
markers.append([token.start_mark.index, +2, number, substitutions[cls, -1]])
if (cls, +1) in substitutions:
markers.append([token.end_mark.index, -2, number, substitutions[cls, +1]])
number = 0
for event in events:
number += 1
cls = event.__class__
if (cls, -1) in substitutions:
markers.append([event.start_mark.index, +1, number, substitutions[cls, -1]])
if (cls, +1) in substitutions:
markers.append([event.end_mark.index, -1, number, substitutions[cls, +1]])
markers.sort()
markers.reverse()
chunks = []
position = len(input)
for index, weight1, weight2, substitution in markers:
if index < position:
chunk = input[index:position]
for substring, replacement in self.style.replaces:
chunk = chunk.replace(substring, replacement)
chunks.append(chunk)
position = index
chunks.append(substitution)
chunks.reverse()
result = u''.join(chunks)
if self.style.header:
self.output.write(self.style.header)
self.output.write(result.encode('utf-8'))
if self.style.footer:
self.output.write(self.style.footer)
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option('-s', '--style', dest='style', default='ascii',
help="specify the highlighting style", metavar='STYLE')
parser.add_option('-c', '--config', dest='config',
default=os.path.join(os.path.dirname(sys.argv[0]), 'yaml_hl.cfg'),
help="set an alternative configuration file", metavar='CONFIG')
parser.add_option('-i', '--input', dest='input', default=None,
help="set the input file (default: stdin)", metavar='FILE')
parser.add_option('-o', '--output', dest='output', default=None,
help="set the output file (default: stdout)", metavar='FILE')
(options, args) = parser.parse_args()
hl = YAMLHighlight(options)
hl.highlight()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
8864,
12,
6010,
12,
984,
12,
747,
14,
515,
12,
8691,
199,
199,
533,
19442,
26,
339,
347,
636,
826,
721,
277,
12,
1406,
29,
403,
12,
14178,
29,
403,
12,
288,
4645,
29,
403,
12,
4474,
29,
403,
12,
19058,
29,
403,
304,
267,
291,
14,
1291,
275,
1406,
267,
291,
14,
12781,
275,
14178,
267,
291,
14,
1155,
5862,
275,
19058,
267,
291,
14,
14340,
8653,
275,
1052,
267,
367,
2881,
12,
8089,
315,
3842,
4504,
12,
283,
3264,
659,
334,
4368,
12,
283,
2390,
358,
2189,
288,
340,
440,
2881,
26,
355,
1980,
288,
367,
790,
315,
2881,
26,
355,
536,
275,
6522,
904,
779,
2064,
14,
18351,
342,
367,
1777,
315,
790,
14,
1294,
3654,
2023,
355,
843,
275,
2519,
8,
5963,
12,
1543,
83,
5,
83,
7,
450,
334,
354,
12,
8089,
430,
355,
574,
275,
2881,
59,
498,
61,
355,
340,
440,
574,
26,
490,
1980,
355,
1343,
275,
574,
14,
362,
360,
928,
358,
355,
1284,
275,
574,
14,
362,
360,
500,
358,
355,
340,
1343,
26,
490,
291,
14,
14340,
8653,
59,
1886,
12,
446,
17,
61,
275,
1343,
355,
340,
1284,
26,
490,
291,
14,
14340,
8653,
59,
1886,
12,
435,
17,
61,
275,
1284,
339,
347,
636,
17212,
721,
277,
12,
1174,
304,
267,
291,
855,
826,
14155,
929,
9,
199,
199,
5963,
14,
525,
63,
515,
63,
7717,
8,
85,
1133,
643,
26,
5963,
14,
1308,
12,
15135,
26,
1548,
15,
785,
21363,
973,
4343,
6609,
297,
267,
359,
403,
467,
1211,
9,
199,
5963,
14,
525,
63,
515,
63,
7717,
8,
85,
1133,
643,
26,
5963,
14,
1308,
12,
15135,
26,
7322,
297,
267,
359,
403,
12,
399,
3984,
10696,
995,
769,
9,
199,
199,
533,
18916,
11688,
4040,
26,
339,
347,
636,
826,
721,
277,
12,
1511,
304,
267,
1101,
275,
8864,
14,
912,
8,
493,
8,
1419,
14,
888,
12,
283,
4848,
1959,
739,
1012,
267,
291,
14,
2487,
275,
1101,
59,
1419,
14,
2487,
61,
267,
340,
1511,
14,
1210,
26,
288,
291,
14,
1210,
275,
570,
8,
1419,
14,
1210,
12,
283,
4848,
358,
267,
587,
26,
288,
291,
14,
1210,
275,
984,
14,
6626,
267,
340,
1511,
14,
1199,
26,
288,
291,
14,
1199,
275,
570,
8,
1419,
14,
1199,
12,
283,
6603,
358,
267,
587,
26,
288,
291,
14,
1199,
275,
984,
14,
2703,
339,
347,
11850,
8,
277,
304,
267,
1324,
275,
291,
14,
1210,
14,
739,
342,
267,
340,
1324,
14,
2460,
8,
8933,
14,
19550,
63,
6610,
975,
63,
906,
304,
288,
1324,
275,
2649,
8,
1210,
12,
283,
1624,
13,
975,
13,
274,
358,
267,
916,
1324,
14,
2460,
8,
8933,
14,
19550,
63,
6610,
975,
63,
6773,
304,
288,
1324,
275,
2649,
8,
1210,
12,
283,
1624,
13,
975,
13,
1235,
358,
267,
587,
26,
288,
1324,
275,
2649,
8,
1210,
12,
283,
1624,
13,
24,
358,
267,
20873,
275,
291,
14,
2487,
14,
14340,
8653,
267,
4645,
275,
8864,
14,
6282,
8,
1210,
9,
267,
4474,
275,
8864,
14,
1122,
8,
1210,
9,
267,
14327,
275,
942,
267,
1329,
275,
378,
267,
367,
1526,
315,
4645,
26,
288,
1329,
847,
413,
288,
340,
1526,
14,
928,
63,
1657,
14,
1080,
1137,
1526,
14,
500,
63,
1657,
14,
1080,
26,
355,
843,
275,
1526,
855,
533,
363,
355,
340,
334,
1886,
12,
446,
17,
9,
315,
20873,
26,
490,
14327,
14,
740,
779,
1418,
14,
928,
63,
1657,
14,
1080,
12,
435,
18,
12,
1329,
12,
20873,
59,
1886,
12,
446,
17,
3934,
355,
340,
334,
1886,
12,
435,
17,
9,
315,
20873,
26,
490,
14327,
14,
740,
779,
1418,
14,
500,
63,
1657,
14,
1080,
12,
446,
18,
12,
1329,
12,
20873,
59,
1886,
12,
435,
17,
3934,
267,
1329,
275,
378,
267,
367,
1566,
315,
4474,
26,
288,
1329,
847,
413,
288,
843,
275,
1566,
855,
533,
363,
288,
340,
334,
1886,
12,
446,
17,
9,
315,
20873,
26,
355,
14327,
14,
740,
779,
1430,
14,
928,
63,
1657,
14,
1080,
12,
435,
17,
12,
1329,
12,
20873,
59,
1886,
12,
446,
17,
3934,
288,
340,
334,
1886,
12,
435,
17,
9,
315,
20873,
26,
355,
14327,
14,
740,
779,
1430,
14,
500,
63,
1657,
14,
1080,
12,
446,
17,
12,
1329,
12,
20873,
59,
1886,
12,
435,
17,
3934,
267,
14327,
14,
3191,
342,
267,
14327,
14,
4471,
342,
267,
8291,
275,
942,
267,
3421,
275,
822,
8,
1210,
9,
267,
367,
1478,
12,
5401,
17,
12,
5401,
18,
12,
20584,
315,
14327,
26,
288,
340,
1478,
665,
3421,
26,
355,
3728,
275,
1324,
59,
1080,
26,
3124,
61,
355,
367,
20597,
12,
8343,
315,
291,
14,
2487,
14,
1155,
5862,
26,
490,
3728,
275,
3728,
14,
1814,
8,
954,
875,
12,
8343,
9,
355,
8291,
14,
740,
8,
4604,
9,
355,
3421,
275,
1478,
288,
8291,
14,
740,
8,
30809,
9,
267,
8291,
14,
4471,
342,
267,
754,
275,
399,
17067,
904,
8,
10660,
9,
267,
340,
291,
14,
2487,
14,
1291,
26,
288,
291,
14,
1199,
14,
952,
8,
277,
14,
2487,
14,
1291,
9,
267,
291,
14,
1199,
14,
952,
8,
1099,
14,
2143,
360,
1624,
13,
24,
1333,
267,
340,
291,
14,
2487,
14,
12781,
26,
288,
291,
14,
1199,
14,
952,
8,
277,
14,
2487,
14,
12781,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1798,
275,
8691,
14,
14553,
342,
272,
1798,
14,
525,
63,
1422,
3654,
83,
297,
2850,
2487,
297,
2053,
534,
2487,
297,
849,
534,
4371,
297,
288,
1720,
628,
26164,
314,
22437,
3449,
401,
8214,
534,
18466,
358,
272,
1798,
14,
525,
63,
1422,
3654,
67,
297,
2850,
888,
297,
2053,
534,
888,
297,
288,
849,
29,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
283,
5963,
63,
15544,
14,
4128,
659,
288,
1720,
628,
409,
376,
13943,
2897,
570,
401,
8214,
534,
5569,
358,
272,
1798,
14,
525,
63,
1422,
3654,
73,
297,
2850,
1210,
297,
2053,
534,
1210,
297,
849,
29,
403,
12,
288,
1720,
628,
409,
314,
1324,
570,
334,
885,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
8864,
12,
6010,
12,
984,
12,
747,
14,
515,
12,
8691,
199,
199,
533,
19442,
26,
339,
347,
636,
826,
721,
277,
12,
1406,
29,
403,
12,
14178,
29,
403,
12,
288,
4645,
29,
403,
12,
4474,
29,
403,
12,
19058,
29,
403,
304,
267,
291,
14,
1291,
275,
1406,
267,
291,
14,
12781,
275,
14178,
267,
291,
14,
1155,
5862,
275,
19058,
267,
291,
14,
14340,
8653,
275,
1052,
267,
367,
2881,
12,
8089,
315,
3842,
4504,
12,
283,
3264,
659,
334,
4368,
12,
283,
2390,
358,
2189,
288,
340,
440,
2881,
26,
355,
1980,
288,
367,
790,
315,
2881,
26,
355,
536,
275,
6522,
904,
779,
2064,
14,
18351,
342,
367,
1777,
315,
790,
14,
1294,
3654,
2023,
355,
843,
275,
2519,
8,
5963,
12,
1543,
83,
5,
83,
7,
450,
334,
354,
12,
8089,
430,
355,
574,
275,
2881,
59,
498,
61,
355,
340,
440,
574,
26,
490,
1980,
355,
1343,
275,
574,
14,
362,
360,
928,
358,
355,
1284,
275,
574,
14,
362,
360,
500,
358,
355,
340,
1343,
26,
490,
291,
14,
14340,
8653,
59,
1886,
12,
446,
17,
61,
275,
1343,
355,
340,
1284,
26,
490,
291,
14,
14340,
8653,
59,
1886,
12,
435,
17,
61,
275,
1284,
339,
347,
636,
17212,
721,
277,
12,
1174,
304,
267,
291,
855,
826,
14155,
929,
9,
199,
199,
5963,
14,
525,
63,
515,
63,
7717,
8,
85,
1133,
643,
26,
5963,
14,
1308,
12,
15135,
26,
1548,
15,
785,
21363,
973,
4343,
6609,
297,
267,
359,
403,
467,
1211,
9,
199,
5963,
14,
525,
63,
515,
63,
7717,
8,
85,
1133,
643,
26,
5963,
14,
1308,
12,
15135,
26,
7322,
297,
267,
359,
403,
12,
399,
3984,
10696,
995,
769,
9,
199,
199,
533,
18916,
11688,
4040,
26,
339,
347,
636,
826,
721,
277,
12,
1511,
304,
267,
1101,
275,
8864,
14,
912,
8,
493,
8,
1419,
14,
888,
12,
283,
4848,
1959,
739,
1012,
267,
291,
14,
2487,
275,
1101,
59,
1419,
14,
2487,
61,
267,
340,
1511,
14,
1210,
26,
288,
291,
14,
1210,
275,
570,
8,
1419,
14,
1210,
12,
283,
4848,
358,
267,
587,
26,
288,
291,
14,
1210,
275,
984,
14,
6626,
267,
340,
1511,
14,
1199,
26,
288,
291,
14,
1199,
275,
570,
8,
1419,
14,
1199,
12,
283,
6603,
358,
267,
587,
26,
288,
291,
14,
1199,
275,
984,
14,
2703,
339,
347,
11850,
8,
277,
304,
267,
1324,
275,
291,
14,
1210,
14,
739,
342,
267,
340,
1324,
14,
2460,
8,
8933,
14,
19550,
63,
6610,
975,
63,
906,
304,
288,
1324,
275,
2649,
8,
1210,
12,
283,
1624,
13,
975,
13,
274,
358,
267,
916,
1324,
14,
2460,
8,
8933,
14,
19550,
63,
6610,
975,
63,
6773,
304,
288,
1324,
275,
2649,
8,
1210,
12,
283,
1624,
13,
975,
13,
1235,
358,
267,
587,
26,
288,
1324,
275,
2649,
8,
1210,
12,
283,
1624,
13,
24,
358,
267,
20873,
275,
291,
14,
2487,
14,
14340,
8653,
267,
4645,
275,
8864,
14,
6282,
8,
1210,
9,
267,
4474,
275,
8864,
14,
1122,
8,
1210,
9,
267,
14327,
275,
942,
267,
1329,
275,
378,
267,
367,
1526,
315,
4645,
26,
288,
1329,
847,
413,
288,
340,
1526,
14,
928,
63,
1657,
14,
1080,
1137,
1526,
14,
500,
63,
1657,
14,
1080,
26,
355,
843,
275,
1526,
855,
533,
363,
355,
340,
334,
1886,
12,
446,
17,
9,
315,
20873,
26,
490,
14327,
14,
740,
779,
1418,
14,
928,
63,
1657,
14,
1080,
12,
435,
18,
12,
1329,
12,
20873,
59,
1886,
12,
446,
17,
3934,
355,
340,
334,
1886,
12,
435,
17,
9,
315,
20873,
26,
490,
14327,
14,
740,
779,
1418,
14,
500,
63,
1657,
14,
1080,
12,
446,
18,
12,
1329,
12,
20873,
59,
1886,
12,
435,
17,
3934,
267,
1329,
275,
378,
267,
367,
1566,
315,
4474,
26,
288,
1329,
847,
413,
288,
843,
275,
1566,
855,
533,
363,
288,
340,
334,
1886,
12,
446,
17,
9,
315,
20873,
26,
355,
14327,
14,
740,
779,
1430,
14,
928,
63,
1657,
14,
1080,
12,
435,
17,
12,
1329,
12,
20873,
59,
1886,
12,
446,
17,
3934,
288,
340,
334,
1886,
12,
435,
17,
9,
315,
20873,
26,
355,
14327,
14,
740,
779,
1430,
14,
500,
63,
1657,
14,
1080,
12,
446,
17,
12,
1329,
12,
20873,
59,
1886,
12,
435,
17,
3934,
267,
14327,
14,
3191,
342,
267,
14327,
14,
4471,
342,
267,
8291,
275,
942,
267,
3421,
275,
822,
8,
1210,
9,
267,
367,
1478,
12,
5401,
17,
12,
5401,
18,
12,
20584,
315,
14327,
26,
288,
340,
1478,
665,
3421,
26,
355,
3728,
275,
1324,
59,
1080,
26,
3124,
61,
355,
367,
20597,
12,
8343,
315,
291,
14,
2487,
14,
1155,
5862,
26,
490,
3728,
275,
3728,
14,
1814,
8,
954,
875,
12,
8343,
9,
355,
8291,
14,
740,
8,
4604,
9,
355,
3421,
275,
1478,
288,
8291,
14,
740,
8,
30809,
9,
267,
8291,
14,
4471,
342,
267,
754,
275,
399,
17067,
904,
8,
10660,
9,
267,
340,
291,
14,
2487,
14,
1291,
26,
288,
291,
14,
1199,
14,
952,
8,
277,
14,
2487,
14,
1291,
9,
267,
291,
14,
1199,
14,
952,
8,
1099,
14,
2143,
360,
1624,
13,
24,
1333,
267,
340,
291,
14,
2487,
14,
12781,
26,
288,
291,
14,
1199,
14,
952,
8,
277,
14,
2487,
14,
12781,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1798,
275,
8691,
14,
14553,
342,
272,
1798,
14,
525,
63,
1422,
3654,
83,
297,
2850,
2487,
297,
2053,
534,
2487,
297,
849,
534,
4371,
297,
288,
1720,
628,
26164,
314,
22437,
3449,
401,
8214,
534,
18466,
358,
272,
1798,
14,
525,
63,
1422,
3654,
67,
297,
2850,
888,
297,
2053,
534,
888,
297,
288,
849,
29,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
283,
5963,
63,
15544,
14,
4128,
659,
288,
1720,
628,
409,
376,
13943,
2897,
570,
401,
8214,
534,
5569,
358,
272,
1798,
14,
525,
63,
1422,
3654,
73,
297,
2850,
1210,
297,
2053,
534,
1210,
297,
849,
29,
403,
12,
288,
1720,
628,
409,
314,
1324,
570,
334,
885,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
pedro2d10/SickRage-FR
|
lib/hachoir_parser/file_system/ntfs.py
|
86
|
11594
|
"""
New Technology File System (NTFS) file system parser.
Sources:
- The NTFS documentation
http://www.linux-ntfs.org/
- NTFS-3G driver
http://www.ntfs-3g.org/
Creation date: 3rd january 2007
Author: Victor Stinner
"""
SECTOR_SIZE = 512
from hachoir_parser import Parser
from hachoir_core.field import (FieldSet, Enum,
UInt8, UInt16, UInt32, UInt64, TimestampWin64,
String, Bytes, Bit,
NullBits, NullBytes, PaddingBytes, RawBytes)
from hachoir_core.endian import LITTLE_ENDIAN
from hachoir_core.text_handler import textHandler, hexadecimal, filesizeHandler
from hachoir_core.tools import humanFilesize, createDict
from hachoir_parser.common.msdos import MSDOSFileAttr32
class BiosParameterBlock(FieldSet):
"""
BIOS parameter block (bpb) structure
"""
static_size = 25 * 8
MEDIA_TYPE = {0xf8: "Hard disk"}
def createFields(self):
yield UInt16(self, "bytes_per_sector", "Size of a sector in bytes")
yield UInt8(self, "sectors_per_cluster", "Size of a cluster in sectors")
yield NullBytes(self, "reserved_sectors", 2)
yield NullBytes(self, "fats", 1)
yield NullBytes(self, "root_entries", 2)
yield NullBytes(self, "sectors", 2)
yield Enum(UInt8(self, "media_type"), self.MEDIA_TYPE)
yield NullBytes(self, "sectors_per_fat", 2)
yield UInt16(self, "sectors_per_track")
yield UInt16(self, "heads")
yield UInt32(self, "hidden_sectors")
yield NullBytes(self, "large_sectors", 4)
def validate(self):
if self["bytes_per_sector"].value not in (256, 512, 1024, 2048, 4096):
return "Invalid sector size (%u bytes)" % \
self["bytes_per_sector"].value
if self["sectors_per_cluster"].value not in (1, 2, 4, 8, 16, 32, 64, 128):
return "Invalid cluster size (%u sectors)" % \
self["sectors_per_cluster"].value
return ""
class MasterBootRecord(FieldSet):
static_size = 512*8
def createFields(self):
yield Bytes(self, "jump", 3, "Intel x86 jump instruction")
yield String(self, "name", 8)
yield BiosParameterBlock(self, "bios", "BIOS parameters")
yield textHandler(UInt8(self, "physical_drive", "(0x80)"), hexadecimal)
yield NullBytes(self, "current_head", 1)
yield textHandler(UInt8(self, "ext_boot_sig", "Extended boot signature (0x80)"), hexadecimal)
yield NullBytes(self, "unused", 1)
yield UInt64(self, "nb_sectors")
yield UInt64(self, "mft_cluster", "Cluster location of MFT data")
yield UInt64(self, "mftmirr_cluster", "Cluster location of copy of MFT")
yield UInt8(self, "cluster_per_mft", "MFT record size in clusters")
yield NullBytes(self, "reserved[]", 3)
yield UInt8(self, "cluster_per_index", "Index block size in clusters")
yield NullBytes(self, "reserved[]", 3)
yield textHandler(UInt64(self, "serial_number"), hexadecimal)
yield textHandler(UInt32(self, "checksum", "Boot sector checksum"), hexadecimal)
yield Bytes(self, "boot_code", 426)
yield Bytes(self, "mbr_magic", 2, r"Master boot record magic number (\x55\xAA)")
def createDescription(self):
size = self["nb_sectors"].value * self["bios/bytes_per_sector"].value
return "NTFS Master Boot Record (%s)" % humanFilesize(size)
class MFT_Flags(FieldSet):
static_size = 16
def createFields(self):
yield Bit(self, "in_use")
yield Bit(self, "is_directory")
yield NullBits(self, "padding", 14)
class Attribute(FieldSet):
# --- Common code ---
def __init__(self, *args):
FieldSet.__init__(self, *args)
self._size = self["size"].value * 8
type = self["type"].value
if type in self.ATTR_INFO:
self._name = self.ATTR_INFO[type][0]
self._parser = self.ATTR_INFO[type][2]
def createFields(self):
yield Enum(textHandler(UInt32(self, "type"), hexadecimal), self.ATTR_NAME)
yield UInt32(self, "size")
yield UInt8(self, "non_resident", "Non-resident flag")
yield UInt8(self, "name_length", "Name length in bytes")
yield UInt16(self, "name_offset", "Name offset")
yield UInt16(self, "flags")
yield textHandler(UInt16(self, "attribute_id"), hexadecimal)
yield UInt32(self, "length_attr", "Length of the Attribute")
yield UInt16(self, "offset_attr", "Offset of the Attribute")
yield UInt8(self, "indexed_flag")
yield NullBytes(self, "padding", 1)
if self._parser:
for field in self._parser(self):
yield field
else:
size = self["length_attr"].value
if size:
yield RawBytes(self, "data", size)
size = (self.size - self.current_size) // 8
if size:
yield PaddingBytes(self, "end_padding", size)
def createDescription(self):
return "Attribute %s" % self["type"].display
FILENAME_NAMESPACE = {
0: "POSIX",
1: "Win32",
2: "DOS",
3: "Win32 & DOS",
}
# --- Parser specific to a type ---
def parseStandardInfo(self):
yield TimestampWin64(self, "ctime", "File Creation")
yield TimestampWin64(self, "atime", "File Altered")
yield TimestampWin64(self, "mtime", "MFT Changed")
yield TimestampWin64(self, "rtime", "File Read")
yield MSDOSFileAttr32(self, "file_attr", "DOS File Permissions")
yield UInt32(self, "max_version", "Maximum Number of Versions")
yield UInt32(self, "version", "Version Number")
yield UInt32(self, "class_id")
yield UInt32(self, "owner_id")
yield UInt32(self, "security_id")
yield filesizeHandler(UInt64(self, "quota_charged", "Quota Charged"))
yield UInt64(self, "usn", "Update Sequence Number (USN)")
def parseFilename(self):
yield UInt64(self, "ref", "File reference to the parent directory")
yield TimestampWin64(self, "ctime", "File Creation")
yield TimestampWin64(self, "atime", "File Altered")
yield TimestampWin64(self, "mtime", "MFT Changed")
yield TimestampWin64(self, "rtime", "File Read")
yield filesizeHandler(UInt64(self, "alloc_size", "Allocated size of the file"))
yield filesizeHandler(UInt64(self, "real_size", "Real size of the file"))
yield UInt32(self, "file_flags")
yield UInt32(self, "file_flags2", "Used by EAs and Reparse")
yield UInt8(self, "filename_length", "Filename length in characters")
yield Enum(UInt8(self, "filename_namespace"), self.FILENAME_NAMESPACE)
size = self["filename_length"].value * 2
if size:
yield String(self, "filename", size, charset="UTF-16-LE")
def parseData(self):
size = (self.size - self.current_size) // 8
if size:
yield Bytes(self, "data", size)
def parseBitmap(self):
size = (self.size - self.current_size)
for index in xrange(size):
yield Bit(self, "bit[]")
# --- Type information ---
ATTR_INFO = {
0x10: ('standard_info', 'STANDARD_INFORMATION ', parseStandardInfo),
0x20: ('attr_list', 'ATTRIBUTE_LIST ', None),
0x30: ('filename', 'FILE_NAME ', parseFilename),
0x40: ('vol_ver', 'VOLUME_VERSION', None),
0x40: ('obj_id', 'OBJECT_ID ', None),
0x50: ('security', 'SECURITY_DESCRIPTOR ', None),
0x60: ('vol_name', 'VOLUME_NAME ', None),
0x70: ('vol_info', 'VOLUME_INFORMATION ', None),
0x80: ('data', 'DATA ', parseData),
0x90: ('index_root', 'INDEX_ROOT ', None),
0xA0: ('index_alloc', 'INDEX_ALLOCATION ', None),
0xB0: ('bitmap', 'BITMAP ', parseBitmap),
0xC0: ('sym_link', 'SYMBOLIC_LINK', None),
0xC0: ('reparse', 'REPARSE_POINT ', None),
0xD0: ('ea_info', 'EA_INFORMATION ', None),
0xE0: ('ea', 'EA ', None),
0xF0: ('prop_set', 'PROPERTY_SET', None),
0x100: ('log_util', 'LOGGED_UTILITY_STREAM', None),
}
ATTR_NAME = createDict(ATTR_INFO, 1)
class File(FieldSet):
# static_size = 48*8
def __init__(self, *args):
FieldSet.__init__(self, *args)
self._size = self["bytes_allocated"].value * 8
def createFields(self):
yield Bytes(self, "signature", 4, "Usually the magic is 'FILE'")
yield UInt16(self, "usa_ofs", "Update Sequence Array offset")
yield UInt16(self, "usa_count", "Update Sequence Array count")
yield UInt64(self, "lsn", "$LogFile sequence number for this record")
yield UInt16(self, "sequence_number", "Number of times this mft record has been reused")
yield UInt16(self, "link_count", "Number of hard links")
yield UInt16(self, "attrs_offset", "Byte offset to the first attribute")
yield MFT_Flags(self, "flags")
yield UInt32(self, "bytes_in_use", "Number of bytes used in this record")
yield UInt32(self, "bytes_allocated", "Number of bytes allocated for this record")
yield UInt64(self, "base_mft_record")
yield UInt16(self, "next_attr_instance")
# The below fields are specific to NTFS 3.1+ (Windows XP and above)
yield NullBytes(self, "reserved", 2)
yield UInt32(self, "mft_record_number", "Number of this mft record")
padding = self.seekByte(self["attrs_offset"].value, relative=True)
if padding:
yield padding
while not self.eof:
addr = self.absolute_address + self.current_size
if self.stream.readBytes(addr, 4) == "\xFF\xFF\xFF\xFF":
yield Bytes(self, "attr_end_marker", 8)
break
yield Attribute(self, "attr[]")
size = self["bytes_in_use"].value - self.current_size//8
if size:
yield RawBytes(self, "end_rawdata", size)
size = (self.size - self.current_size) // 8
if size:
yield RawBytes(self, "end_padding", size, "Unused but allocated bytes")
def createDescription(self):
text = "File"
if "filename/filename" in self:
text += ' "%s"' % self["filename/filename"].value
if "filename/real_size" in self:
text += ' (%s)' % self["filename/real_size"].display
if "standard_info/file_attr" in self:
text += ', %s' % self["standard_info/file_attr"].display
return text
class NTFS(Parser):
MAGIC = "\xEB\x52\x90NTFS "
PARSER_TAGS = {
"id": "ntfs",
"category": "file_system",
"description": "NTFS file system",
"min_size": 1024*8,
"magic": ((MAGIC, 0),),
}
endian = LITTLE_ENDIAN
_cluster_size = None
def validate(self):
if self.stream.readBytes(0, len(self.MAGIC)) != self.MAGIC:
return "Invalid magic string"
err = self["mbr/bios"].validate()
if err:
return err
return True
def createFields(self):
yield MasterBootRecord(self, "mbr")
bios = self["mbr/bios"]
cluster_size = bios["sectors_per_cluster"].value * bios["bytes_per_sector"].value
offset = self["mbr/mft_cluster"].value * cluster_size
padding = self.seekByte(offset, relative=False)
if padding:
yield padding
for index in xrange(1000):
yield File(self, "file[]")
size = (self.size - self.current_size) // 8
if size:
yield RawBytes(self, "end", size)
|
gpl-3.0
|
[
624,
199,
4665,
21580,
3814,
6187,
334,
46,
6145,
51,
9,
570,
2656,
1798,
14,
199,
199,
13959,
26,
199,
13,
710,
653,
6145,
51,
3794,
523,
1455,
921,
1544,
14,
5135,
13,
343,
2319,
14,
1308,
15,
199,
13,
653,
6145,
51,
13,
19,
39,
5253,
523,
1455,
921,
1544,
14,
343,
2319,
13,
19,
71,
14,
1308,
15,
199,
199,
13921,
1434,
26,
650,
6883,
1335,
290,
20527,
10219,
199,
5949,
26,
6561,
630,
428,
1346,
1372,
199,
624,
199,
199,
32379,
726,
63,
4305,
275,
10574,
199,
199,
504,
394,
21301,
63,
2087,
492,
10191,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
334,
23532,
12,
11305,
12,
272,
10666,
24,
12,
10666,
975,
12,
10666,
708,
12,
10666,
772,
12,
18267,
8886,
772,
12,
272,
2624,
12,
9879,
12,
10199,
12,
272,
12119,
10787,
12,
12119,
5571,
12,
510,
4095,
5571,
12,
13480,
5571,
9,
199,
504,
394,
21301,
63,
1018,
14,
15009,
492,
491,
31783,
63,
21046,
199,
504,
394,
21301,
63,
1018,
14,
505,
63,
2232,
492,
1318,
2461,
12,
20379,
12,
23858,
2461,
199,
504,
394,
21301,
63,
1018,
14,
2537,
492,
11779,
1173,
890,
12,
1218,
2141,
199,
504,
394,
21301,
63,
2087,
14,
2330,
14,
706,
18339,
492,
14282,
32735,
1173,
7144,
708,
199,
199,
533,
699,
9207,
4720,
3142,
8,
23532,
304,
272,
408,
272,
699,
13532,
2725,
1853,
334,
66,
3317,
9,
5523,
272,
408,
272,
2955,
63,
890,
275,
5661,
627,
1695,
272,
31460,
63,
2711,
275,
469,
16,
1949,
24,
26,
298,
16464,
4543,
3570,
339,
347,
24828,
8,
277,
304,
267,
1995,
10666,
975,
8,
277,
12,
298,
2394,
63,
529,
63,
22029,
401,
298,
2320,
402,
282,
27935,
315,
2783,
531,
267,
1995,
10666,
24,
8,
277,
12,
298,
261,
13451,
63,
529,
63,
4201,
401,
298,
2320,
402,
282,
4350,
315,
542,
13451,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
10421,
63,
261,
13451,
401,
499,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
70,
1956,
401,
413,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
1231,
63,
3189,
401,
499,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
261,
13451,
401,
499,
9,
267,
1995,
11305,
8,
13304,
24,
8,
277,
12,
298,
4603,
63,
466,
1288,
291,
14,
13669,
63,
2711,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
261,
13451,
63,
529,
63,
23156,
401,
499,
9,
267,
1995,
10666,
975,
8,
277,
12,
298,
261,
13451,
63,
529,
63,
3885,
531,
267,
1995,
10666,
975,
8,
277,
12,
298,
17033,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
5642,
63,
261,
13451,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
9629,
63,
261,
13451,
401,
841,
9,
339,
347,
4107,
8,
277,
304,
267,
340,
291,
905,
2394,
63,
529,
63,
22029,
4140,
585,
440,
315,
334,
3912,
12,
10574,
12,
6619,
12,
18427,
12,
17125,
304,
288,
372,
298,
3364,
27935,
1568,
4366,
85,
2783,
2924,
450,
971,
355,
291,
905,
2394,
63,
529,
63,
22029,
4140,
585,
267,
340,
291,
905,
261,
13451,
63,
529,
63,
4201,
4140,
585,
440,
315,
334,
17,
12,
499,
12,
841,
12,
1695,
12,
3193,
12,
4337,
12,
5049,
12,
7960,
304,
288,
372,
298,
3364,
4350,
1568,
4366,
85,
542,
13451,
2924,
450,
971,
355,
291,
905,
261,
13451,
63,
529,
63,
4201,
4140,
585,
267,
372,
3087,
199,
199,
533,
26728,
17989,
5433,
8,
23532,
304,
272,
2955,
63,
890,
275,
10574,
10,
24,
272,
347,
24828,
8,
277,
304,
267,
1995,
9879,
8,
277,
12,
298,
11126,
401,
650,
12,
298,
27528,
671,
1184,
14882,
16329,
531,
267,
1995,
2624,
8,
277,
12,
298,
354,
401,
1695,
9,
267,
1995,
699,
9207,
4720,
3142,
8,
277,
12,
298,
29673,
401,
298,
34,
13532,
2633,
531,
398,
1995,
1318,
2461,
8,
13304,
24,
8,
277,
12,
298,
15020,
63,
9541,
401,
7340,
16,
88,
1257,
13185,
20379,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
1818,
63,
2993,
401,
413,
9,
267,
1995,
1318,
2461,
8,
13304,
24,
8,
277,
12,
298,
832,
63,
4930,
63,
4093,
401,
298,
14107,
8498,
4955,
334,
16,
88,
1257,
13185,
20379,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
8618,
401,
413,
9,
398,
1995,
10666,
772,
8,
277,
12,
298,
4994,
63,
261,
13451,
531,
267,
1995,
10666,
772,
8,
277,
12,
298,
77,
856,
63,
4201,
401,
298,
9581,
2909,
402,
603,
2161,
666,
531,
267,
1995,
10666,
772,
8,
277,
12,
298,
77,
856,
77,
723,
82,
63,
4201,
401,
298,
9581,
2909,
402,
1331,
402,
603,
2161,
531,
267,
1995,
10666,
24,
8,
277,
12,
298,
4201,
63,
529,
63,
77,
856,
401,
298,
45,
2161,
2777,
1568,
315,
13865,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
10421,
20204,
650,
9,
267,
1995,
10666,
24,
8,
277,
12,
298,
4201,
63,
529,
63,
1080,
401,
298,
2681,
1853,
1568,
315,
13865,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
10421,
20204,
650,
9,
267,
1995,
1318,
2461,
8,
13304,
772,
8,
277,
12,
298,
2171,
63,
1955,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
8928,
401,
298,
17989,
27935,
9040,
1288,
20379,
9,
267,
1995,
9879,
8,
277,
12,
298,
4930,
63,
600,
401,
841,
1479,
9,
267,
1995,
9879,
8,
277,
12,
298,
887,
82,
63,
11523,
401,
499,
12,
519,
2,
12288,
8498,
2777,
10628,
1329,
14749,
88,
1229,
60,
31234,
6320,
339,
347,
1218,
5831,
8,
277,
304,
267,
1568,
275,
291,
905,
4994,
63,
261,
13451,
4140,
585,
627,
291,
905,
29673,
15,
2394,
63,
529,
63,
22029,
4140,
585,
267,
372,
298,
46,
6145,
51,
26728,
27324,
12651,
4366,
83,
2924,
450,
11779,
1173,
890,
8,
890,
9,
199,
199,
533,
603,
2161,
63,
6381,
8,
23532,
304,
272,
2955,
63,
890,
275,
3193,
272,
347,
24828,
8,
277,
304,
267,
1995,
10199,
8,
277,
12,
298,
262,
63,
1180,
531,
267,
1995,
10199,
8,
277,
12,
298,
374,
63,
3619,
531,
267,
1995,
12119,
10787,
8,
277,
12,
298,
8358,
401,
4329,
9,
199,
199,
533
] |
[
199,
4665,
21580,
3814,
6187,
334,
46,
6145,
51,
9,
570,
2656,
1798,
14,
199,
199,
13959,
26,
199,
13,
710,
653,
6145,
51,
3794,
523,
1455,
921,
1544,
14,
5135,
13,
343,
2319,
14,
1308,
15,
199,
13,
653,
6145,
51,
13,
19,
39,
5253,
523,
1455,
921,
1544,
14,
343,
2319,
13,
19,
71,
14,
1308,
15,
199,
199,
13921,
1434,
26,
650,
6883,
1335,
290,
20527,
10219,
199,
5949,
26,
6561,
630,
428,
1346,
1372,
199,
624,
199,
199,
32379,
726,
63,
4305,
275,
10574,
199,
199,
504,
394,
21301,
63,
2087,
492,
10191,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
334,
23532,
12,
11305,
12,
272,
10666,
24,
12,
10666,
975,
12,
10666,
708,
12,
10666,
772,
12,
18267,
8886,
772,
12,
272,
2624,
12,
9879,
12,
10199,
12,
272,
12119,
10787,
12,
12119,
5571,
12,
510,
4095,
5571,
12,
13480,
5571,
9,
199,
504,
394,
21301,
63,
1018,
14,
15009,
492,
491,
31783,
63,
21046,
199,
504,
394,
21301,
63,
1018,
14,
505,
63,
2232,
492,
1318,
2461,
12,
20379,
12,
23858,
2461,
199,
504,
394,
21301,
63,
1018,
14,
2537,
492,
11779,
1173,
890,
12,
1218,
2141,
199,
504,
394,
21301,
63,
2087,
14,
2330,
14,
706,
18339,
492,
14282,
32735,
1173,
7144,
708,
199,
199,
533,
699,
9207,
4720,
3142,
8,
23532,
304,
272,
408,
272,
699,
13532,
2725,
1853,
334,
66,
3317,
9,
5523,
272,
408,
272,
2955,
63,
890,
275,
5661,
627,
1695,
272,
31460,
63,
2711,
275,
469,
16,
1949,
24,
26,
298,
16464,
4543,
3570,
339,
347,
24828,
8,
277,
304,
267,
1995,
10666,
975,
8,
277,
12,
298,
2394,
63,
529,
63,
22029,
401,
298,
2320,
402,
282,
27935,
315,
2783,
531,
267,
1995,
10666,
24,
8,
277,
12,
298,
261,
13451,
63,
529,
63,
4201,
401,
298,
2320,
402,
282,
4350,
315,
542,
13451,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
10421,
63,
261,
13451,
401,
499,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
70,
1956,
401,
413,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
1231,
63,
3189,
401,
499,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
261,
13451,
401,
499,
9,
267,
1995,
11305,
8,
13304,
24,
8,
277,
12,
298,
4603,
63,
466,
1288,
291,
14,
13669,
63,
2711,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
261,
13451,
63,
529,
63,
23156,
401,
499,
9,
267,
1995,
10666,
975,
8,
277,
12,
298,
261,
13451,
63,
529,
63,
3885,
531,
267,
1995,
10666,
975,
8,
277,
12,
298,
17033,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
5642,
63,
261,
13451,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
9629,
63,
261,
13451,
401,
841,
9,
339,
347,
4107,
8,
277,
304,
267,
340,
291,
905,
2394,
63,
529,
63,
22029,
4140,
585,
440,
315,
334,
3912,
12,
10574,
12,
6619,
12,
18427,
12,
17125,
304,
288,
372,
298,
3364,
27935,
1568,
4366,
85,
2783,
2924,
450,
971,
355,
291,
905,
2394,
63,
529,
63,
22029,
4140,
585,
267,
340,
291,
905,
261,
13451,
63,
529,
63,
4201,
4140,
585,
440,
315,
334,
17,
12,
499,
12,
841,
12,
1695,
12,
3193,
12,
4337,
12,
5049,
12,
7960,
304,
288,
372,
298,
3364,
4350,
1568,
4366,
85,
542,
13451,
2924,
450,
971,
355,
291,
905,
261,
13451,
63,
529,
63,
4201,
4140,
585,
267,
372,
3087,
199,
199,
533,
26728,
17989,
5433,
8,
23532,
304,
272,
2955,
63,
890,
275,
10574,
10,
24,
272,
347,
24828,
8,
277,
304,
267,
1995,
9879,
8,
277,
12,
298,
11126,
401,
650,
12,
298,
27528,
671,
1184,
14882,
16329,
531,
267,
1995,
2624,
8,
277,
12,
298,
354,
401,
1695,
9,
267,
1995,
699,
9207,
4720,
3142,
8,
277,
12,
298,
29673,
401,
298,
34,
13532,
2633,
531,
398,
1995,
1318,
2461,
8,
13304,
24,
8,
277,
12,
298,
15020,
63,
9541,
401,
7340,
16,
88,
1257,
13185,
20379,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
1818,
63,
2993,
401,
413,
9,
267,
1995,
1318,
2461,
8,
13304,
24,
8,
277,
12,
298,
832,
63,
4930,
63,
4093,
401,
298,
14107,
8498,
4955,
334,
16,
88,
1257,
13185,
20379,
9,
267,
1995,
12119,
5571,
8,
277,
12,
298,
8618,
401,
413,
9,
398,
1995,
10666,
772,
8,
277,
12,
298,
4994,
63,
261,
13451,
531,
267,
1995,
10666,
772,
8,
277,
12,
298,
77,
856,
63,
4201,
401,
298,
9581,
2909,
402,
603,
2161,
666,
531,
267,
1995,
10666,
772,
8,
277,
12,
298,
77,
856,
77,
723,
82,
63,
4201,
401,
298,
9581,
2909,
402,
1331,
402,
603,
2161,
531,
267,
1995,
10666,
24,
8,
277,
12,
298,
4201,
63,
529,
63,
77,
856,
401,
298,
45,
2161,
2777,
1568,
315,
13865,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
10421,
20204,
650,
9,
267,
1995,
10666,
24,
8,
277,
12,
298,
4201,
63,
529,
63,
1080,
401,
298,
2681,
1853,
1568,
315,
13865,
531,
267,
1995,
12119,
5571,
8,
277,
12,
298,
10421,
20204,
650,
9,
267,
1995,
1318,
2461,
8,
13304,
772,
8,
277,
12,
298,
2171,
63,
1955,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
8928,
401,
298,
17989,
27935,
9040,
1288,
20379,
9,
267,
1995,
9879,
8,
277,
12,
298,
4930,
63,
600,
401,
841,
1479,
9,
267,
1995,
9879,
8,
277,
12,
298,
887,
82,
63,
11523,
401,
499,
12,
519,
2,
12288,
8498,
2777,
10628,
1329,
14749,
88,
1229,
60,
31234,
6320,
339,
347,
1218,
5831,
8,
277,
304,
267,
1568,
275,
291,
905,
4994,
63,
261,
13451,
4140,
585,
627,
291,
905,
29673,
15,
2394,
63,
529,
63,
22029,
4140,
585,
267,
372,
298,
46,
6145,
51,
26728,
27324,
12651,
4366,
83,
2924,
450,
11779,
1173,
890,
8,
890,
9,
199,
199,
533,
603,
2161,
63,
6381,
8,
23532,
304,
272,
2955,
63,
890,
275,
3193,
272,
347,
24828,
8,
277,
304,
267,
1995,
10199,
8,
277,
12,
298,
262,
63,
1180,
531,
267,
1995,
10199,
8,
277,
12,
298,
374,
63,
3619,
531,
267,
1995,
12119,
10787,
8,
277,
12,
298,
8358,
401,
4329,
9,
199,
199,
533,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
holygits/incubator-airflow
|
airflow/executors/sequential_executor.py
|
46
|
1862
|
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from builtins import str
import subprocess
from airflow.executors.base_executor import BaseExecutor
from airflow.utils.state import State
class SequentialExecutor(BaseExecutor):
"""
This executor will only run one task instance at a time, can be used
for debugging. It is also the only executor that can be used with sqlite
since sqlite doesn't support multiple connections.
Since we want airflow to work out of the box, it defaults to this
SequentialExecutor alongside sqlite as you first install it.
"""
def __init__(self):
super(SequentialExecutor, self).__init__()
self.commands_to_run = []
def execute_async(self, key, command, queue=None):
self.commands_to_run.append((key, command,))
def sync(self):
for key, command in self.commands_to_run:
self.logger.info("Executing command: {}".format(command))
try:
subprocess.check_call(command, shell=True)
self.change_state(key, State.SUCCESS)
except subprocess.CalledProcessError as e:
self.change_state(key, State.FAILED)
self.logger.error("Failed to execute task {}:".format(str(e)))
self.commands_to_run = []
def end(self):
self.heartbeat()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
12963,
492,
620,
199,
646,
3873,
199,
199,
504,
16321,
14,
1628,
6622,
14,
1095,
63,
13471,
492,
3523,
16752,
199,
504,
16321,
14,
1208,
14,
929,
492,
8511,
421,
199,
533,
3240,
9092,
16752,
8,
1563,
16752,
304,
272,
408,
272,
961,
13270,
911,
1454,
1255,
1373,
2120,
1256,
737,
282,
900,
12,
883,
506,
1202,
272,
367,
10201,
14,
2779,
365,
2597,
314,
1454,
13270,
626,
883,
506,
1202,
543,
11723,
272,
3967,
11723,
3181,
1133,
2291,
3663,
6947,
14,
339,
9336,
781,
2934,
16321,
370,
1736,
734,
402,
314,
5689,
12,
652,
4243,
370,
642,
272,
3240,
9092,
16752,
3180,
2441,
11723,
465,
1265,
1642,
3907,
652,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
18509,
16752,
12,
291,
2843,
826,
4533,
267,
291,
14,
4405,
63,
475,
63,
1065,
275,
942,
339,
347,
5341,
63,
4146,
8,
277,
12,
790,
12,
1414,
12,
4126,
29,
403,
304,
267,
291,
14,
4405,
63,
475,
63,
1065,
14,
740,
1332,
498,
12,
1414,
4641,
339,
347,
7604,
8,
277,
304,
267,
367,
790,
12,
1414,
315,
291,
14,
4405,
63,
475,
63,
1065,
26,
288,
291,
14,
2921,
14,
815,
480,
4858,
4655,
1414,
26,
8352,
908,
8,
1531,
430,
953,
862,
26,
355,
3873,
14,
1074,
63,
1250,
8,
1531,
12,
5218,
29,
549,
9,
355,
291,
14,
1461,
63,
929,
8,
498,
12,
8511,
14,
12779,
9,
288,
871,
3873,
14,
24691,
465,
325,
26,
355,
291,
14,
1461,
63,
929,
8,
498,
12,
8511,
14,
12299,
9,
355,
291,
14,
2921,
14,
705,
480,
4276,
370,
5341,
2120,
24702,
1674,
908,
8,
495,
8,
69,
1724,
398,
291,
14,
4405,
63,
475,
63,
1065,
275,
942,
339,
347,
1284,
8,
277,
304,
267,
291,
14,
22685,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
12963,
492,
620,
199,
646,
3873,
199,
199,
504,
16321,
14,
1628,
6622,
14,
1095,
63,
13471,
492,
3523,
16752,
199,
504,
16321,
14,
1208,
14,
929,
492,
8511,
421,
199,
533,
3240,
9092,
16752,
8,
1563,
16752,
304,
272,
408,
272,
961,
13270,
911,
1454,
1255,
1373,
2120,
1256,
737,
282,
900,
12,
883,
506,
1202,
272,
367,
10201,
14,
2779,
365,
2597,
314,
1454,
13270,
626,
883,
506,
1202,
543,
11723,
272,
3967,
11723,
3181,
1133,
2291,
3663,
6947,
14,
339,
9336,
781,
2934,
16321,
370,
1736,
734,
402,
314,
5689,
12,
652,
4243,
370,
642,
272,
3240,
9092,
16752,
3180,
2441,
11723,
465,
1265,
1642,
3907,
652,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
18509,
16752,
12,
291,
2843,
826,
4533,
267,
291,
14,
4405,
63,
475,
63,
1065,
275,
942,
339,
347,
5341,
63,
4146,
8,
277,
12,
790,
12,
1414,
12,
4126,
29,
403,
304,
267,
291,
14,
4405,
63,
475,
63,
1065,
14,
740,
1332,
498,
12,
1414,
4641,
339,
347,
7604,
8,
277,
304,
267,
367,
790,
12,
1414,
315,
291,
14,
4405,
63,
475,
63,
1065,
26,
288,
291,
14,
2921,
14,
815,
480,
4858,
4655,
1414,
26,
8352,
908,
8,
1531,
430,
953,
862,
26,
355,
3873,
14,
1074,
63,
1250,
8,
1531,
12,
5218,
29,
549,
9,
355,
291,
14,
1461,
63,
929,
8,
498,
12,
8511,
14,
12779,
9,
288,
871,
3873,
14,
24691,
465,
325,
26,
355,
291,
14,
1461,
63,
929,
8,
498,
12,
8511,
14,
12299,
9,
355,
291,
14,
2921,
14,
705,
480,
4276,
370,
5341,
2120,
24702,
1674,
908,
8,
495,
8,
69,
1724,
398,
291,
14,
4405,
63,
475,
63,
1065,
275,
942,
339,
347,
1284,
8,
277,
304,
267,
291,
14,
22685,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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|
2577
|
8813
|
#!/usr/bin/env python
#
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""fuse_gtest_files.py v0.2.0
Fuses Google Test source code into a .h file and a .cc file.
SYNOPSIS
fuse_gtest_files.py [GTEST_ROOT_DIR] OUTPUT_DIR
Scans GTEST_ROOT_DIR for Google Test source code, and generates
two files: OUTPUT_DIR/gtest/gtest.h and OUTPUT_DIR/gtest/gtest-all.cc.
Then you can build your tests by adding OUTPUT_DIR to the include
search path and linking with OUTPUT_DIR/gtest/gtest-all.cc. These
two files contain everything you need to use Google Test. Hence
you can "install" Google Test by copying them to wherever you want.
GTEST_ROOT_DIR can be omitted and defaults to the parent
directory of the directory holding this script.
EXAMPLES
./fuse_gtest_files.py fused_gtest
./fuse_gtest_files.py path/to/unpacked/gtest fused_gtest
This tool is experimental. In particular, it assumes that there is no
conditional inclusion of Google Test headers. Please report any
problems to googletestframework@googlegroups.com. You can read
http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide for
more information.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
import sets
import sys
# We assume that this file is in the scripts/ directory in the Google
# Test root directory.
DEFAULT_GTEST_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
# Regex for matching '#include "gtest/..."'.
INCLUDE_GTEST_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(gtest/.+)"')
# Regex for matching '#include "src/..."'.
INCLUDE_SRC_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(src/.+)"')
# Where to find the source seed files.
GTEST_H_SEED = 'include/gtest/gtest.h'
GTEST_SPI_H_SEED = 'include/gtest/gtest-spi.h'
GTEST_ALL_CC_SEED = 'src/gtest-all.cc'
# Where to put the generated files.
GTEST_H_OUTPUT = 'gtest/gtest.h'
GTEST_ALL_CC_OUTPUT = 'gtest/gtest-all.cc'
def VerifyFileExists(directory, relative_path):
"""Verifies that the given file exists; aborts on failure.
relative_path is the file path relative to the given directory.
"""
if not os.path.isfile(os.path.join(directory, relative_path)):
print 'ERROR: Cannot find %s in directory %s.' % (relative_path,
directory)
print ('Please either specify a valid project root directory '
'or omit it on the command line.')
sys.exit(1)
def ValidateGTestRootDir(gtest_root):
"""Makes sure gtest_root points to a valid gtest root directory.
The function aborts the program on failure.
"""
VerifyFileExists(gtest_root, GTEST_H_SEED)
VerifyFileExists(gtest_root, GTEST_ALL_CC_SEED)
def VerifyOutputFile(output_dir, relative_path):
"""Verifies that the given output file path is valid.
relative_path is relative to the output_dir directory.
"""
# Makes sure the output file either doesn't exist or can be overwritten.
output_file = os.path.join(output_dir, relative_path)
if os.path.exists(output_file):
# TODO(wan@google.com): The following user-interaction doesn't
# work with automated processes. We should provide a way for the
# Makefile to force overwriting the files.
print ('%s already exists in directory %s - overwrite it? (y/N) ' %
(relative_path, output_dir))
answer = sys.stdin.readline().strip()
if answer not in ['y', 'Y']:
print 'ABORTED.'
sys.exit(1)
# Makes sure the directory holding the output file exists; creates
# it and all its ancestors if necessary.
parent_directory = os.path.dirname(output_file)
if not os.path.isdir(parent_directory):
os.makedirs(parent_directory)
def ValidateOutputDir(output_dir):
"""Makes sure output_dir points to a valid output directory.
The function aborts the program on failure.
"""
VerifyOutputFile(output_dir, GTEST_H_OUTPUT)
VerifyOutputFile(output_dir, GTEST_ALL_CC_OUTPUT)
def FuseGTestH(gtest_root, output_dir):
"""Scans folder gtest_root to generate gtest/gtest.h in output_dir."""
output_file = file(os.path.join(output_dir, GTEST_H_OUTPUT), 'w')
processed_files = sets.Set() # Holds all gtest headers we've processed.
def ProcessFile(gtest_header_path):
"""Processes the given gtest header file."""
# We don't process the same header twice.
if gtest_header_path in processed_files:
return
processed_files.add(gtest_header_path)
# Reads each line in the given gtest header.
for line in file(os.path.join(gtest_root, gtest_header_path), 'r'):
m = INCLUDE_GTEST_FILE_REGEX.match(line)
if m:
# It's '#include "gtest/..."' - let's process it recursively.
ProcessFile('include/' + m.group(1))
else:
# Otherwise we copy the line unchanged to the output file.
output_file.write(line)
ProcessFile(GTEST_H_SEED)
output_file.close()
def FuseGTestAllCcToFile(gtest_root, output_file):
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_file."""
processed_files = sets.Set()
def ProcessFile(gtest_source_file):
"""Processes the given gtest source file."""
# We don't process the same #included file twice.
if gtest_source_file in processed_files:
return
processed_files.add(gtest_source_file)
# Reads each line in the given gtest source file.
for line in file(os.path.join(gtest_root, gtest_source_file), 'r'):
m = INCLUDE_GTEST_FILE_REGEX.match(line)
if m:
if 'include/' + m.group(1) == GTEST_SPI_H_SEED:
# It's '#include "gtest/gtest-spi.h"'. This file is not
# #included by "gtest/gtest.h", so we need to process it.
ProcessFile(GTEST_SPI_H_SEED)
else:
# It's '#include "gtest/foo.h"' where foo is not gtest-spi.
# We treat it as '#include "gtest/gtest.h"', as all other
# gtest headers are being fused into gtest.h and cannot be
# #included directly.
# There is no need to #include "gtest/gtest.h" more than once.
if not GTEST_H_SEED in processed_files:
processed_files.add(GTEST_H_SEED)
output_file.write('#include "%s"\n' % (GTEST_H_OUTPUT,))
else:
m = INCLUDE_SRC_FILE_REGEX.match(line)
if m:
# It's '#include "src/foo"' - let's process it recursively.
ProcessFile(m.group(1))
else:
output_file.write(line)
ProcessFile(GTEST_ALL_CC_SEED)
def FuseGTestAllCc(gtest_root, output_dir):
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir."""
output_file = file(os.path.join(output_dir, GTEST_ALL_CC_OUTPUT), 'w')
FuseGTestAllCcToFile(gtest_root, output_file)
output_file.close()
def FuseGTest(gtest_root, output_dir):
"""Fuses gtest.h and gtest-all.cc."""
ValidateGTestRootDir(gtest_root)
ValidateOutputDir(output_dir)
FuseGTestH(gtest_root, output_dir)
FuseGTestAllCc(gtest_root, output_dir)
def main():
argc = len(sys.argv)
if argc == 2:
# fuse_gtest_files.py OUTPUT_DIR
FuseGTest(DEFAULT_GTEST_ROOT_DIR, sys.argv[1])
elif argc == 3:
# fuse_gtest_files.py GTEST_ROOT_DIR OUTPUT_DIR
FuseGTest(sys.argv[1], sys.argv[2])
else:
print __doc__
sys.exit(1)
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
70,
1180,
63,
8385,
63,
1725,
14,
647,
373,
16,
14,
18,
14,
16,
199,
38,
5589,
4475,
1379,
1350,
1233,
1901,
282,
1275,
72,
570,
436,
282,
1275,
2055,
570,
14,
199,
199,
31802,
21665,
1311,
2126,
289,
1180,
63,
8385,
63,
1725,
14,
647,
359,
16151,
63,
5441,
63,
3022,
61,
18746,
63,
3022,
10817,
13916,
796,
18652,
63,
5441,
63,
3022,
367,
4475,
1379,
1350,
1233,
12,
436,
12821,
2126,
2877,
1584,
26,
18746,
63,
3022,
15,
8385,
15,
8385,
14,
72,
436,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
2126,
9442,
1265,
883,
1900,
2195,
2295,
701,
7791,
18746,
63,
3022,
370,
314,
2387,
2126,
2754,
931,
436,
25833,
543,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
221,
5723,
2126,
2877,
1584,
1395,
8137,
1265,
1929,
370,
675,
4475,
1379,
14,
221,
869,
4894,
2126,
1265,
883,
298,
3174,
2,
4475,
1379,
701,
16743,
3062,
370,
2382,
422,
1265,
2934,
14,
10817,
18652,
63,
5441,
63,
3022,
883,
506,
11684,
436,
4243,
370,
314,
1676,
2126,
2082,
402,
314,
2082,
17573,
642,
2884,
14,
199,
199,
8918,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
28580,
63,
8385,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
931,
15,
475,
15,
24497,
15,
8385,
28580,
63,
8385,
199,
199,
2765,
4744,
365,
22820,
14,
221,
1010,
6770,
12,
652,
15194,
626,
2337,
365,
949,
199,
14353,
20396,
402,
4475,
1379,
2323,
14,
221,
7754,
3622,
1263,
199,
22959,
370,
31141,
4857,
32,
3098,
2634,
14,
957,
14,
221,
2047,
883,
1586,
199,
1014,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
3098,
396,
15,
6797,
15,
13266,
774,
23613,
4324,
271,
367,
199,
6878,
2556,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5951,
199,
646,
984,
199,
199,
3,
2136,
5534,
626,
642,
570,
365,
315,
314,
10554,
15,
2082,
315,
314,
4475,
199,
3,
1379,
1738,
2082,
14,
199,
3472,
63,
16151,
63,
5441,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
8385,
15,
11500,
1370,
199,
18171,
63,
16151,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
8385,
15,
6977,
2924,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
2164,
15,
11500,
1370,
199,
18171,
63,
12447,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
2164,
15,
6977,
2924,
358,
199,
199,
3,
17685,
370,
2342,
314,
1350,
6347,
1584,
14,
199,
16151,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
20495,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
13,
8721,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
25508,
275,
283,
2164,
15,
8385,
13,
452,
14,
2055,
7,
199,
199,
3,
17685,
370,
5324,
314,
4046,
1584,
14,
199,
16151,
63,
40,
63,
8414,
275,
283,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
8414,
275,
283,
8385,
15,
8385,
13,
452,
14,
2055,
7,
421,
199,
318,
7635,
1173,
7965,
8,
3619,
12,
3847,
63,
515,
304,
523,
408,
21168,
626,
314,
1627,
570,
3495,
27,
12004,
83,
641,
5988,
14,
819,
3847,
63,
515,
365,
314,
570,
931,
3847,
370,
314,
1627,
2082,
14,
523,
408,
819,
340,
440,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
3619,
12,
3847,
63,
515,
2298,
272,
870,
283,
3170,
26,
18435,
2342,
450,
83,
315,
2082,
450,
83,
3530,
450,
334,
6188,
63,
515,
12,
10028,
2082,
9,
272,
870,
661,
8254,
1902,
4165,
282,
1686,
2199,
1738,
2082,
283,
1779,
283,
269,
19413,
652,
641,
314,
1414,
1004,
2659,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
12134,
39,
774
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
70,
1180,
63,
8385,
63,
1725,
14,
647,
373,
16,
14,
18,
14,
16,
199,
38,
5589,
4475,
1379,
1350,
1233,
1901,
282,
1275,
72,
570,
436,
282,
1275,
2055,
570,
14,
199,
199,
31802,
21665,
1311,
2126,
289,
1180,
63,
8385,
63,
1725,
14,
647,
359,
16151,
63,
5441,
63,
3022,
61,
18746,
63,
3022,
10817,
13916,
796,
18652,
63,
5441,
63,
3022,
367,
4475,
1379,
1350,
1233,
12,
436,
12821,
2126,
2877,
1584,
26,
18746,
63,
3022,
15,
8385,
15,
8385,
14,
72,
436,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
2126,
9442,
1265,
883,
1900,
2195,
2295,
701,
7791,
18746,
63,
3022,
370,
314,
2387,
2126,
2754,
931,
436,
25833,
543,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
221,
5723,
2126,
2877,
1584,
1395,
8137,
1265,
1929,
370,
675,
4475,
1379,
14,
221,
869,
4894,
2126,
1265,
883,
298,
3174,
2,
4475,
1379,
701,
16743,
3062,
370,
2382,
422,
1265,
2934,
14,
10817,
18652,
63,
5441,
63,
3022,
883,
506,
11684,
436,
4243,
370,
314,
1676,
2126,
2082,
402,
314,
2082,
17573,
642,
2884,
14,
199,
199,
8918,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
28580,
63,
8385,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
931,
15,
475,
15,
24497,
15,
8385,
28580,
63,
8385,
199,
199,
2765,
4744,
365,
22820,
14,
221,
1010,
6770,
12,
652,
15194,
626,
2337,
365,
949,
199,
14353,
20396,
402,
4475,
1379,
2323,
14,
221,
7754,
3622,
1263,
199,
22959,
370,
31141,
4857,
32,
3098,
2634,
14,
957,
14,
221,
2047,
883,
1586,
199,
1014,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
3098,
396,
15,
6797,
15,
13266,
774,
23613,
4324,
271,
367,
199,
6878,
2556,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5951,
199,
646,
984,
199,
199,
3,
2136,
5534,
626,
642,
570,
365,
315,
314,
10554,
15,
2082,
315,
314,
4475,
199,
3,
1379,
1738,
2082,
14,
199,
3472,
63,
16151,
63,
5441,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
8385,
15,
11500,
1370,
199,
18171,
63,
16151,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
8385,
15,
6977,
2924,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
2164,
15,
11500,
1370,
199,
18171,
63,
12447,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
2164,
15,
6977,
2924,
358,
199,
199,
3,
17685,
370,
2342,
314,
1350,
6347,
1584,
14,
199,
16151,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
20495,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
13,
8721,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
25508,
275,
283,
2164,
15,
8385,
13,
452,
14,
2055,
7,
199,
199,
3,
17685,
370,
5324,
314,
4046,
1584,
14,
199,
16151,
63,
40,
63,
8414,
275,
283,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
8414,
275,
283,
8385,
15,
8385,
13,
452,
14,
2055,
7,
421,
199,
318,
7635,
1173,
7965,
8,
3619,
12,
3847,
63,
515,
304,
523,
408,
21168,
626,
314,
1627,
570,
3495,
27,
12004,
83,
641,
5988,
14,
819,
3847,
63,
515,
365,
314,
570,
931,
3847,
370,
314,
1627,
2082,
14,
523,
408,
819,
340,
440,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
3619,
12,
3847,
63,
515,
2298,
272,
870,
283,
3170,
26,
18435,
2342,
450,
83,
315,
2082,
450,
83,
3530,
450,
334,
6188,
63,
515,
12,
10028,
2082,
9,
272,
870,
661,
8254,
1902,
4165,
282,
1686,
2199,
1738,
2082,
283,
1779,
283,
269,
19413,
652,
641,
314,
1414,
1004,
2659,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
12134,
39,
774,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Evervolv/android_external_chromium_org
|
build/gyp_helper.py
|
57
|
1598
|
# 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.
# This file helps gyp_chromium and landmines correctly set up the gyp
# environment from chromium.gyp_env on disk
import os
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
CHROME_SRC = os.path.dirname(SCRIPT_DIR)
def apply_gyp_environment_from_file(file_path):
"""Reads in a *.gyp_env file and applies the valid keys to os.environ."""
if not os.path.exists(file_path):
return
with open(file_path, 'rU') as f:
file_contents = f.read()
try:
file_data = eval(file_contents, {'__builtins__': None}, None)
except SyntaxError, e:
e.filename = os.path.abspath(file_path)
raise
supported_vars = (
'CC',
'CC_wrapper',
'CHROMIUM_GYP_FILE',
'CHROMIUM_GYP_SYNTAX_CHECK',
'CXX',
'CXX_wrapper',
'GYP_DEFINES',
'GYP_GENERATOR_FLAGS',
'GYP_CROSSCOMPILE',
'GYP_GENERATOR_OUTPUT',
'GYP_GENERATORS',
)
for var in supported_vars:
file_val = file_data.get(var)
if file_val:
if var in os.environ:
print 'INFO: Environment value for "%s" overrides value in %s.' % (
var, os.path.abspath(file_path)
)
else:
os.environ[var] = file_val
def apply_chromium_gyp_env():
if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
# Update the environment based on chromium.gyp_env
path = os.path.join(os.path.dirname(CHROME_SRC), 'chromium.gyp_env')
apply_gyp_environment_from_file(path)
|
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,
3,
961,
570,
22577,
4902,
63,
13211,
436,
20078,
827,
397,
6657,
663,
1536,
314,
4902,
199,
3,
3734,
687,
682,
7419,
14,
6179,
63,
1813,
641,
4543,
199,
199,
646,
747,
199,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
199,
1244,
31364,
63,
12447,
275,
747,
14,
515,
14,
3475,
8,
10484,
63,
3022,
9,
421,
199,
318,
4838,
63,
6179,
63,
5418,
63,
504,
63,
493,
8,
493,
63,
515,
304,
523,
408,
23614,
315,
282,
23588,
6179,
63,
1813,
570,
436,
12966,
314,
1686,
2883,
370,
747,
14,
2314,
1041,
523,
340,
440,
747,
14,
515,
14,
2444,
8,
493,
63,
515,
304,
272,
372,
523,
543,
1551,
8,
493,
63,
515,
12,
283,
28978,
358,
465,
289,
26,
272,
570,
63,
4407,
275,
289,
14,
739,
342,
523,
862,
26,
272,
570,
63,
576,
275,
3468,
8,
493,
63,
4407,
12,
791,
363,
10372,
3706,
488,
1386,
488,
9,
523,
871,
12053,
12,
325,
26,
272,
325,
14,
1501,
275,
747,
14,
515,
14,
4832,
8,
493,
63,
515,
9,
272,
746,
523,
3748,
63,
2936,
275,
334,
489,
283,
2571,
297,
489,
283,
2571,
63,
5029,
297,
489,
283,
30334,
24967,
63,
14884,
63,
3817,
297,
489,
283,
30334,
24967,
63,
14884,
63,
20763,
63,
8936,
297,
489,
283,
12206,
297,
489,
283,
12206,
63,
5029,
297,
489,
283,
14884,
63,
27196,
297,
489,
283,
14884,
63,
12795,
6467,
63,
4831,
297,
489,
283,
14884,
63,
28368,
29911,
297,
489,
283,
14884,
63,
12795,
6467,
63,
8414,
297,
489,
283,
14884,
63,
12795,
19033,
297,
523,
776,
523,
367,
2729,
315,
3748,
63,
2936,
26,
272,
570,
63,
637,
275,
570,
63,
576,
14,
362,
8,
1391,
9,
272,
340,
570,
63,
637,
26,
489,
340,
2729,
315,
747,
14,
2314,
26,
267,
870,
283,
4531,
26,
9711,
574,
367,
2071,
83,
2,
10580,
574,
315,
450,
83,
3530,
450,
334,
288,
2729,
12,
747,
14,
515,
14,
4832,
8,
493,
63,
515,
9,
267,
776,
489,
587,
26,
267,
747,
14,
2314,
59,
1391,
61,
275,
570,
63,
637,
421,
199,
318,
4838,
63,
13211,
63,
6179,
63,
1813,
837,
523,
340,
283,
13525,
63,
30334,
24967,
63,
14884,
63,
9984,
7,
440,
315,
747,
14,
2314,
26,
272,
327,
6162,
314,
3734,
4079,
641,
682,
7419,
14,
6179,
63,
1813,
272,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1244,
31364,
63,
12447,
395,
283,
13211,
14,
6179,
63,
1813,
358,
272,
4838,
63,
6179,
63,
5418,
63,
504,
63,
493,
8,
515,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
3,
961,
570,
22577,
4902,
63,
13211,
436,
20078,
827,
397,
6657,
663,
1536,
314,
4902,
199,
3,
3734,
687,
682,
7419,
14,
6179,
63,
1813,
641,
4543,
199,
199,
646,
747,
199,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
199,
1244,
31364,
63,
12447,
275,
747,
14,
515,
14,
3475,
8,
10484,
63,
3022,
9,
421,
199,
318,
4838,
63,
6179,
63,
5418,
63,
504,
63,
493,
8,
493,
63,
515,
304,
523,
408,
23614,
315,
282,
23588,
6179,
63,
1813,
570,
436,
12966,
314,
1686,
2883,
370,
747,
14,
2314,
1041,
523,
340,
440,
747,
14,
515,
14,
2444,
8,
493,
63,
515,
304,
272,
372,
523,
543,
1551,
8,
493,
63,
515,
12,
283,
28978,
358,
465,
289,
26,
272,
570,
63,
4407,
275,
289,
14,
739,
342,
523,
862,
26,
272,
570,
63,
576,
275,
3468,
8,
493,
63,
4407,
12,
791,
363,
10372,
3706,
488,
1386,
488,
9,
523,
871,
12053,
12,
325,
26,
272,
325,
14,
1501,
275,
747,
14,
515,
14,
4832,
8,
493,
63,
515,
9,
272,
746,
523,
3748,
63,
2936,
275,
334,
489,
283,
2571,
297,
489,
283,
2571,
63,
5029,
297,
489,
283,
30334,
24967,
63,
14884,
63,
3817,
297,
489,
283,
30334,
24967,
63,
14884,
63,
20763,
63,
8936,
297,
489,
283,
12206,
297,
489,
283,
12206,
63,
5029,
297,
489,
283,
14884,
63,
27196,
297,
489,
283,
14884,
63,
12795,
6467,
63,
4831,
297,
489,
283,
14884,
63,
28368,
29911,
297,
489,
283,
14884,
63,
12795,
6467,
63,
8414,
297,
489,
283,
14884,
63,
12795,
19033,
297,
523,
776,
523,
367,
2729,
315,
3748,
63,
2936,
26,
272,
570,
63,
637,
275,
570,
63,
576,
14,
362,
8,
1391,
9,
272,
340,
570,
63,
637,
26,
489,
340,
2729,
315,
747,
14,
2314,
26,
267,
870,
283,
4531,
26,
9711,
574,
367,
2071,
83,
2,
10580,
574,
315,
450,
83,
3530,
450,
334,
288,
2729,
12,
747,
14,
515,
14,
4832,
8,
493,
63,
515,
9,
267,
776,
489,
587,
26,
267,
747,
14,
2314,
59,
1391,
61,
275,
570,
63,
637,
421,
199,
318,
4838,
63,
13211,
63,
6179,
63,
1813,
837,
523,
340,
283,
13525,
63,
30334,
24967,
63,
14884,
63,
9984,
7,
440,
315,
747,
14,
2314,
26,
272,
327,
6162,
314,
3734,
4079,
641,
682,
7419,
14,
6179,
63,
1813,
272,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1244,
31364,
63,
12447,
395,
283,
13211,
14,
6179,
63,
1813,
358,
272,
4838,
63,
6179,
63,
5418,
63,
504,
63,
493,
8,
515,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yubo/lxc
|
src/python-lxc/examples/pyconsole.py
|
29
|
1653
|
#!/usr/bin/python3
#
# pyconsole: Example program showing use of console functions
# in the lxc python binding
#
# (C) Copyright Oracle. 2013
#
# Authors:
# Dwight Engen <dwight.engen@oracle.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; 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 Street, Fifth Floor, Boston, MA 02110-1301
# USA
#
import lxc
import sys
import time
if __name__ == '__main__':
ttynum = -1
escape = 1
if len(sys.argv) < 2:
sys.exit("Usage: %s container-name [ttynum [escape]]" % sys.argv[0])
if len(sys.argv) > 2:
ttynum = int(sys.argv[2])
if len(sys.argv) > 3:
escape = ord(sys.argv[3]) - ord('a') + 1
ct = lxc.Container(sys.argv[1])
print("Container:%s tty:%d Ctrl-%c q to quit" %
(ct.name, ttynum, ord('a') + escape-1))
time.sleep(1)
if not ct.defined:
sys.exit("Container %s not defined" % ct.name)
if not ct.running:
sys.exit("Container %s not running" % ct.name)
ct.console(ttynum, 0, 1, 2, escape)
print("Console done")
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
199,
3,
1134,
6614,
26,
5679,
2240,
21207,
675,
402,
8559,
3423,
199,
3,
3322,
315,
314,
634,
1812,
2366,
11696,
199,
3,
199,
3,
334,
35,
9,
1898,
15309,
14,
6171,
199,
3,
199,
3,
6642,
26,
199,
3,
577,
87,
1070,
3447,
2268,
665,
10772,
1070,
14,
287,
2268,
32,
16404,
14,
957,
30,
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,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
199,
3,
8217,
199,
3,
199,
199,
646,
634,
1812,
199,
646,
984,
199,
646,
900,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
21862,
1507,
275,
446,
17,
272,
4772,
275,
413,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
984,
14,
2224,
480,
7692,
26,
450,
83,
3970,
13,
354,
359,
4707,
1507,
359,
3765,
2677,
2,
450,
984,
14,
3020,
59,
16,
566,
272,
340,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
267,
21862,
1507,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
272,
340,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
267,
4772,
275,
6206,
8,
1274,
14,
3020,
59,
19,
566,
446,
6206,
360,
65,
358,
435,
413,
339,
9428,
275,
634,
1812,
14,
4076,
8,
1274,
14,
3020,
59,
17,
566,
339,
870,
480,
4076,
2689,
83,
21862,
2689,
68,
445,
7245,
3295,
67,
1894,
370,
17242,
2,
450,
881,
334,
319,
14,
354,
12,
21862,
1507,
12,
6206,
360,
65,
358,
435,
4772,
13,
17,
430,
272,
900,
14,
4532,
8,
17,
9,
272,
340,
440,
9428,
14,
4037,
26,
267,
984,
14,
2224,
480,
4076,
450,
83,
440,
3247,
2,
450,
9428,
14,
354,
9,
272,
340,
440,
9428,
14,
5720,
26,
267,
984,
14,
2224,
480,
4076,
450,
83,
440,
3879,
2,
450,
9428,
14,
354,
9,
339,
9428,
14,
6614,
8,
4707,
1507,
12,
378,
12,
413,
12,
499,
12,
4772,
9,
272,
870,
480,
9270,
4224,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
199,
3,
1134,
6614,
26,
5679,
2240,
21207,
675,
402,
8559,
3423,
199,
3,
3322,
315,
314,
634,
1812,
2366,
11696,
199,
3,
199,
3,
334,
35,
9,
1898,
15309,
14,
6171,
199,
3,
199,
3,
6642,
26,
199,
3,
577,
87,
1070,
3447,
2268,
665,
10772,
1070,
14,
287,
2268,
32,
16404,
14,
957,
30,
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,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
199,
3,
8217,
199,
3,
199,
199,
646,
634,
1812,
199,
646,
984,
199,
646,
900,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
21862,
1507,
275,
446,
17,
272,
4772,
275,
413,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
984,
14,
2224,
480,
7692,
26,
450,
83,
3970,
13,
354,
359,
4707,
1507,
359,
3765,
2677,
2,
450,
984,
14,
3020,
59,
16,
566,
272,
340,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
267,
21862,
1507,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
272,
340,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
267,
4772,
275,
6206,
8,
1274,
14,
3020,
59,
19,
566,
446,
6206,
360,
65,
358,
435,
413,
339,
9428,
275,
634,
1812,
14,
4076,
8,
1274,
14,
3020,
59,
17,
566,
339,
870,
480,
4076,
2689,
83,
21862,
2689,
68,
445,
7245,
3295,
67,
1894,
370,
17242,
2,
450,
881,
334,
319,
14,
354,
12,
21862,
1507,
12,
6206,
360,
65,
358,
435,
4772,
13,
17,
430,
272,
900,
14,
4532,
8,
17,
9,
272,
340,
440,
9428,
14,
4037,
26,
267,
984,
14,
2224,
480,
4076,
450,
83,
440,
3247,
2,
450,
9428,
14,
354,
9,
272,
340,
440,
9428,
14,
5720,
26,
267,
984,
14,
2224,
480,
4076,
450,
83,
440,
3879,
2,
450,
9428,
14,
354,
9,
339,
9428,
14,
6614,
8,
4707,
1507,
12,
378,
12,
413,
12,
499,
12,
4772,
9,
272,
870,
480,
9270,
4224,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wxiang7/airflow
|
airflow/utils/dates.py
|
21
|
7078
|
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from datetime import datetime, date, timedelta
from dateutil.relativedelta import relativedelta # for doctest
import six
from croniter import croniter
cron_presets = {
'@hourly': '0 * * * *',
'@daily': '0 0 * * *',
'@weekly': '0 0 * * 0',
'@monthly': '0 0 1 * *',
'@yearly': '0 0 1 1 *',
}
def date_range(
start_date,
end_date=None,
num=None,
delta=None):
"""
Get a set of dates as a list based on a start, end and delta, delta
can be something that can be added to ``datetime.datetime``
or a cron expression as a ``str``
:param start_date: anchor date to start the series from
:type start_date: datetime.datetime
:param end_date: right boundary for the date range
:type end_date: datetime.datetime
:param num: alternatively to end_date, you can specify the number of
number of entries you want in the range. This number can be negative,
output will always be sorted regardless
:type num: int
>>> date_range(datetime(2016, 1, 1), datetime(2016, 1, 3), delta=timedelta(1))
[datetime.datetime(2016, 1, 1, 0, 0), datetime.datetime(2016, 1, 2, 0, 0), datetime.datetime(2016, 1, 3, 0, 0)]
>>> date_range(datetime(2016, 1, 1), datetime(2016, 1, 3), delta='0 0 * * *')
[datetime.datetime(2016, 1, 1, 0, 0), datetime.datetime(2016, 1, 2, 0, 0), datetime.datetime(2016, 1, 3, 0, 0)]
>>> date_range(datetime(2016, 1, 1), datetime(2016, 3, 3), delta="0 0 0 * *")
[datetime.datetime(2016, 1, 1, 0, 0), datetime.datetime(2016, 2, 1, 0, 0), datetime.datetime(2016, 3, 1, 0, 0)]
"""
if not delta:
return []
if end_date and start_date > end_date:
raise Exception("Wait. start_date needs to be before end_date")
if end_date and num:
raise Exception("Wait. Either specify end_date OR num")
if not end_date and not num:
end_date = datetime.now()
delta_iscron = False
if isinstance(delta, six.string_types):
delta_iscron = True
cron = croniter(delta, start_date)
elif isinstance(delta, timedelta):
delta = abs(delta)
l = []
if end_date:
while start_date <= end_date:
l.append(start_date)
if delta_iscron:
start_date = cron.get_next(datetime)
else:
start_date += delta
else:
for i in range(abs(num)):
l.append(start_date)
if delta_iscron:
if num > 0:
start_date = cron.get_next(datetime)
else:
start_date = cron.get_prev(datetime)
else:
if num > 0:
start_date += delta
else:
start_date -= delta
return sorted(l)
def round_time(dt, delta, start_date=datetime.min):
"""
Returns the datetime of the form start_date + i * delta
which is closest to dt for any non-negative integer i.
Note that delta may be a datetime.timedelta or a dateutil.relativedelta
>>> round_time(datetime(2015, 1, 1, 6), timedelta(days=1))
datetime.datetime(2015, 1, 1, 0, 0)
>>> round_time(datetime(2015, 1, 2), relativedelta(months=1))
datetime.datetime(2015, 1, 1, 0, 0)
>>> round_time(datetime(2015, 9, 16, 0, 0), timedelta(1), datetime(2015, 9, 14, 0, 0))
datetime.datetime(2015, 9, 16, 0, 0)
>>> round_time(datetime(2015, 9, 15, 0, 0), timedelta(1), datetime(2015, 9, 14, 0, 0))
datetime.datetime(2015, 9, 15, 0, 0)
>>> round_time(datetime(2015, 9, 14, 0, 0), timedelta(1), datetime(2015, 9, 14, 0, 0))
datetime.datetime(2015, 9, 14, 0, 0)
>>> round_time(datetime(2015, 9, 13, 0, 0), timedelta(1), datetime(2015, 9, 14, 0, 0))
datetime.datetime(2015, 9, 14, 0, 0)
"""
if isinstance(delta, six.string_types):
# It's cron based, so it's easy
cron = croniter(delta, start_date)
prev = cron.get_prev(datetime)
if prev == start_date:
return start_date
else:
return prev
# Ignore the microseconds of dt
dt -= timedelta(microseconds=dt.microsecond)
# We are looking for a datetime in the form start_date + i * delta
# which is as close as possible to dt. Since delta could be a relative
# delta we don't know it's exact length in seconds so we cannot rely on
# division to find i. Instead we employ a binary search algorithm, first
# finding an upper and lower limit and then disecting the interval until
# we have found the closest match.
# We first search an upper limit for i for which start_date + upper * delta
# exceeds dt.
upper = 1
while start_date + upper*delta < dt:
# To speed up finding an upper limit we grow this exponentially by a
# factor of 2
upper *= 2
# Since upper is the first value for which start_date + upper * delta
# exceeds dt, upper // 2 is below dt and therefore forms a lower limited
# for the i we are looking for
lower = upper // 2
# We now continue to intersect the interval between
# start_date + lower * delta and start_date + upper * delta
# until we find the closest value
while True:
# Invariant: start + lower * delta < dt <= start + upper * delta
# If start_date + (lower + 1)*delta exceeds dt, then either lower or
# lower+1 has to be the solution we are searching for
if start_date + (lower + 1)*delta >= dt:
# Check if start_date + (lower + 1)*delta or
# start_date + lower*delta is closer to dt and return the solution
if (
(start_date + (lower + 1) * delta) - dt <=
dt - (start_date + lower * delta)):
return start_date + (lower + 1)*delta
else:
return start_date + lower * delta
# We intersect the interval and either replace the lower or upper
# limit with the candidate
candidate = lower + (upper - lower) // 2
if start_date + candidate*delta >= dt:
upper = candidate
else:
lower = candidate
# in the special case when start_date > dt the search for upper will
# immediately stop for upper == 1 which results in lower = upper // 2 = 0
# and this function returns start_date.
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
2197,
492,
2197,
12,
1434,
12,
6871,
199,
504,
22208,
14,
32300,
492,
20599,
221,
327,
367,
8868,
199,
646,
3816,
199,
199,
504,
19818,
1661,
492,
19818,
1661,
421,
199,
14829,
63,
657,
2193,
275,
469,
272,
10267,
5180,
590,
356,
283,
16,
627,
627,
627,
6039,
272,
10267,
18621,
356,
283,
16,
378,
627,
627,
6039,
272,
10267,
6419,
590,
356,
283,
16,
378,
627,
627,
378,
297,
272,
10267,
30517,
356,
283,
16,
378,
413,
627,
6039,
272,
10267,
16785,
356,
283,
16,
378,
413,
413,
6039,
199,
93,
421,
199,
318,
1434,
63,
1842,
8,
267,
1343,
63,
602,
12,
267,
1284,
63,
602,
29,
403,
12,
267,
1967,
29,
403,
12,
267,
5762,
29,
403,
304,
272,
408,
272,
2372,
282,
663,
402,
10831,
465,
282,
769,
4079,
641,
282,
1343,
12,
1284,
436,
5762,
12,
5762,
272,
883,
506,
6020,
626,
883,
506,
3483,
370,
1124,
2083,
14,
2083,
1040,
272,
503,
282,
19818,
3965,
465,
282,
1124,
495,
1040,
339,
520,
635,
1343,
63,
602,
26,
12514,
1434,
370,
1343,
314,
6779,
687,
272,
520,
466,
1343,
63,
602,
26,
2197,
14,
2083,
272,
520,
635,
1284,
63,
602,
26,
2451,
8424,
367,
314,
1434,
1425,
272,
520,
466,
1284,
63,
602,
26,
2197,
14,
2083,
272,
520,
635,
1967,
26,
8679,
17330,
370,
1284,
63,
602,
12,
1265,
883,
4165,
314,
1329,
402,
267,
1329,
402,
4811,
1265,
2934,
315,
314,
1425,
14,
961,
1329,
883,
506,
6946,
12,
267,
1072,
911,
3544,
506,
3355,
15270,
272,
520,
466,
1967,
26,
1109,
339,
1306,
1434,
63,
1842,
8,
2083,
8,
9261,
12,
413,
12,
413,
395,
2197,
8,
9261,
12,
413,
12,
650,
395,
5762,
29,
7473,
8,
17,
430,
272,
359,
2083,
14,
2083,
8,
9261,
12,
413,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
499,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
650,
12,
378,
12,
378,
1874,
272,
1306,
1434,
63,
1842,
8,
2083,
8,
9261,
12,
413,
12,
413,
395,
2197,
8,
9261,
12,
413,
12,
650,
395,
5762,
534,
16,
378,
627,
627,
627,
358,
272,
359,
2083,
14,
2083,
8,
9261,
12,
413,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
499,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
650,
12,
378,
12,
378,
1874,
272,
1306,
1434,
63,
1842,
8,
2083,
8,
9261,
12,
413,
12,
413,
395,
2197,
8,
9261,
12,
650,
12,
650,
395,
5762,
628,
16,
378,
378,
627,
627,
531,
272,
359,
2083,
14,
2083,
8,
9261,
12,
413,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
499,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
650,
12,
413,
12,
378,
12,
378,
1874,
272,
408,
272,
340,
440,
5762,
26,
267,
372,
942,
272,
340,
1284,
63,
602,
436,
1343,
63,
602,
690,
1284,
63,
602,
26,
267,
746,
2186,
480,
7536,
14,
1343,
63,
602,
4839,
370,
506,
2544,
1284,
63,
602,
531,
272,
340,
1284,
63,
602,
436,
1967,
26,
267,
746,
2186,
480,
7536,
14,
13083,
4165,
1284,
63,
602,
1549,
1967,
531,
272,
340,
440,
1284,
63,
602,
436,
440,
1967,
26,
267,
1284,
63,
602,
275,
2197,
14,
2131,
342,
339,
5762,
63,
374,
14829,
275,
756,
272,
340,
1228,
8,
3136,
12,
3816,
14,
875,
63,
1313,
304,
267,
5762,
63,
374,
14829,
275,
715,
267,
19818,
275,
19818,
1661,
8,
3136,
12,
1343,
63,
602,
9,
272,
916,
1228,
8,
3136,
12,
6871,
304,
267,
5762,
275,
2853,
8,
3136,
9,
272,
634,
275,
942,
272,
340,
1284,
63,
602,
26,
267,
1830,
1343,
63,
602,
2695,
1284,
63,
602,
26,
288,
634,
14,
740,
8,
928,
63,
602,
9,
288,
340,
5762,
63,
374,
14829,
26,
355,
1343,
63,
602,
275,
19818,
14,
362,
63,
2184,
8,
2083,
9,
288,
587,
26,
355,
1343,
63,
602,
847,
5762,
272,
587,
26,
267,
367,
284,
315,
1425,
8,
2101,
8,
1507,
2298,
288,
634,
14,
740,
8,
928,
63,
602,
9,
288,
340,
5762,
63,
374,
14829,
26,
355,
340,
1967,
690,
378,
26,
490,
1343,
63,
602,
275,
19818,
14,
362,
63,
2184,
8,
2083,
9,
355,
587,
26,
490,
1343,
63,
602,
275,
19818,
14,
362,
63,
5701,
8,
2083,
9,
288,
587,
26,
355,
340,
1967,
690,
378,
26,
490,
1343,
63,
602,
847,
5762,
355,
587,
26,
490,
1343,
63,
602,
4862,
5762,
272,
372,
3355,
8,
76,
9,
421,
199,
318,
6168,
63,
521,
8,
3583,
12,
5762,
12,
1343,
63,
602,
29,
2083,
14,
827,
304,
272,
408,
272,
1803,
314,
2197,
402,
314,
1824,
1343,
63,
602,
435,
284,
627,
5762,
272,
1314,
365,
18284,
370,
4487,
367,
1263,
2222,
13,
7371,
3000,
284,
14,
339,
3390,
626,
5762,
1443,
506,
282,
2197,
14,
7473,
503,
282,
22208,
14,
32300,
339,
1306,
6168,
63,
521,
8,
2083,
8,
7806,
12,
413,
12,
413,
12,
1227,
395
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
2197,
492,
2197,
12,
1434,
12,
6871,
199,
504,
22208,
14,
32300,
492,
20599,
221,
327,
367,
8868,
199,
646,
3816,
199,
199,
504,
19818,
1661,
492,
19818,
1661,
421,
199,
14829,
63,
657,
2193,
275,
469,
272,
10267,
5180,
590,
356,
283,
16,
627,
627,
627,
6039,
272,
10267,
18621,
356,
283,
16,
378,
627,
627,
6039,
272,
10267,
6419,
590,
356,
283,
16,
378,
627,
627,
378,
297,
272,
10267,
30517,
356,
283,
16,
378,
413,
627,
6039,
272,
10267,
16785,
356,
283,
16,
378,
413,
413,
6039,
199,
93,
421,
199,
318,
1434,
63,
1842,
8,
267,
1343,
63,
602,
12,
267,
1284,
63,
602,
29,
403,
12,
267,
1967,
29,
403,
12,
267,
5762,
29,
403,
304,
272,
408,
272,
2372,
282,
663,
402,
10831,
465,
282,
769,
4079,
641,
282,
1343,
12,
1284,
436,
5762,
12,
5762,
272,
883,
506,
6020,
626,
883,
506,
3483,
370,
1124,
2083,
14,
2083,
1040,
272,
503,
282,
19818,
3965,
465,
282,
1124,
495,
1040,
339,
520,
635,
1343,
63,
602,
26,
12514,
1434,
370,
1343,
314,
6779,
687,
272,
520,
466,
1343,
63,
602,
26,
2197,
14,
2083,
272,
520,
635,
1284,
63,
602,
26,
2451,
8424,
367,
314,
1434,
1425,
272,
520,
466,
1284,
63,
602,
26,
2197,
14,
2083,
272,
520,
635,
1967,
26,
8679,
17330,
370,
1284,
63,
602,
12,
1265,
883,
4165,
314,
1329,
402,
267,
1329,
402,
4811,
1265,
2934,
315,
314,
1425,
14,
961,
1329,
883,
506,
6946,
12,
267,
1072,
911,
3544,
506,
3355,
15270,
272,
520,
466,
1967,
26,
1109,
339,
1306,
1434,
63,
1842,
8,
2083,
8,
9261,
12,
413,
12,
413,
395,
2197,
8,
9261,
12,
413,
12,
650,
395,
5762,
29,
7473,
8,
17,
430,
272,
359,
2083,
14,
2083,
8,
9261,
12,
413,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
499,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
650,
12,
378,
12,
378,
1874,
272,
1306,
1434,
63,
1842,
8,
2083,
8,
9261,
12,
413,
12,
413,
395,
2197,
8,
9261,
12,
413,
12,
650,
395,
5762,
534,
16,
378,
627,
627,
627,
358,
272,
359,
2083,
14,
2083,
8,
9261,
12,
413,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
499,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
413,
12,
650,
12,
378,
12,
378,
1874,
272,
1306,
1434,
63,
1842,
8,
2083,
8,
9261,
12,
413,
12,
413,
395,
2197,
8,
9261,
12,
650,
12,
650,
395,
5762,
628,
16,
378,
378,
627,
627,
531,
272,
359,
2083,
14,
2083,
8,
9261,
12,
413,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
499,
12,
413,
12,
378,
12,
378,
395,
2197,
14,
2083,
8,
9261,
12,
650,
12,
413,
12,
378,
12,
378,
1874,
272,
408,
272,
340,
440,
5762,
26,
267,
372,
942,
272,
340,
1284,
63,
602,
436,
1343,
63,
602,
690,
1284,
63,
602,
26,
267,
746,
2186,
480,
7536,
14,
1343,
63,
602,
4839,
370,
506,
2544,
1284,
63,
602,
531,
272,
340,
1284,
63,
602,
436,
1967,
26,
267,
746,
2186,
480,
7536,
14,
13083,
4165,
1284,
63,
602,
1549,
1967,
531,
272,
340,
440,
1284,
63,
602,
436,
440,
1967,
26,
267,
1284,
63,
602,
275,
2197,
14,
2131,
342,
339,
5762,
63,
374,
14829,
275,
756,
272,
340,
1228,
8,
3136,
12,
3816,
14,
875,
63,
1313,
304,
267,
5762,
63,
374,
14829,
275,
715,
267,
19818,
275,
19818,
1661,
8,
3136,
12,
1343,
63,
602,
9,
272,
916,
1228,
8,
3136,
12,
6871,
304,
267,
5762,
275,
2853,
8,
3136,
9,
272,
634,
275,
942,
272,
340,
1284,
63,
602,
26,
267,
1830,
1343,
63,
602,
2695,
1284,
63,
602,
26,
288,
634,
14,
740,
8,
928,
63,
602,
9,
288,
340,
5762,
63,
374,
14829,
26,
355,
1343,
63,
602,
275,
19818,
14,
362,
63,
2184,
8,
2083,
9,
288,
587,
26,
355,
1343,
63,
602,
847,
5762,
272,
587,
26,
267,
367,
284,
315,
1425,
8,
2101,
8,
1507,
2298,
288,
634,
14,
740,
8,
928,
63,
602,
9,
288,
340,
5762,
63,
374,
14829,
26,
355,
340,
1967,
690,
378,
26,
490,
1343,
63,
602,
275,
19818,
14,
362,
63,
2184,
8,
2083,
9,
355,
587,
26,
490,
1343,
63,
602,
275,
19818,
14,
362,
63,
5701,
8,
2083,
9,
288,
587,
26,
355,
340,
1967,
690,
378,
26,
490,
1343,
63,
602,
847,
5762,
355,
587,
26,
490,
1343,
63,
602,
4862,
5762,
272,
372,
3355,
8,
76,
9,
421,
199,
318,
6168,
63,
521,
8,
3583,
12,
5762,
12,
1343,
63,
602,
29,
2083,
14,
827,
304,
272,
408,
272,
1803,
314,
2197,
402,
314,
1824,
1343,
63,
602,
435,
284,
627,
5762,
272,
1314,
365,
18284,
370,
4487,
367,
1263,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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
] |
mmazanec22/too-windy
|
env/lib/python3.5/site-packages/requests/packages/urllib3/contrib/ntlmpool.py
|
312
|
4478
|
"""
NTLM authenticating pool, contributed by erikcederstran
Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
"""
from __future__ import absolute_import
from logging import getLogger
from ntlm import ntlm
from .. import HTTPSConnectionPool
from ..packages.six.moves.http_client import HTTPSConnection
log = getLogger(__name__)
class NTLMConnectionPool(HTTPSConnectionPool):
"""
Implements an NTLM authentication version of an urllib3 connection pool
"""
scheme = 'https'
def __init__(self, user, pw, authurl, *args, **kwargs):
"""
authurl is a random URL on the server that is protected by NTLM.
user is the Windows user, probably in the DOMAIN\\username format.
pw is the password for the user.
"""
super(NTLMConnectionPool, self).__init__(*args, **kwargs)
self.authurl = authurl
self.rawuser = user
user_parts = user.split('\\', 1)
self.domain = user_parts[0].upper()
self.user = user_parts[1]
self.pw = pw
def _new_conn(self):
# Performs the NTLM handshake that secures the connection. The socket
# must be kept open while requests are performed.
self.num_connections += 1
log.debug('Starting NTLM HTTPS connection no. %d: https://%s%s',
self.num_connections, self.host, self.authurl)
headers = {}
headers['Connection'] = 'Keep-Alive'
req_header = 'Authorization'
resp_header = 'www-authenticate'
conn = HTTPSConnection(host=self.host, port=self.port)
# Send negotiation message
headers[req_header] = (
'NTLM %s' % ntlm.create_NTLM_NEGOTIATE_MESSAGE(self.rawuser))
log.debug('Request headers: %s', headers)
conn.request('GET', self.authurl, None, headers)
res = conn.getresponse()
reshdr = dict(res.getheaders())
log.debug('Response status: %s %s', res.status, res.reason)
log.debug('Response headers: %s', reshdr)
log.debug('Response data: %s [...]', res.read(100))
# Remove the reference to the socket, so that it can not be closed by
# the response object (we want to keep the socket open)
res.fp = None
# Server should respond with a challenge message
auth_header_values = reshdr[resp_header].split(', ')
auth_header_value = None
for s in auth_header_values:
if s[:5] == 'NTLM ':
auth_header_value = s[5:]
if auth_header_value is None:
raise Exception('Unexpected %s response header: %s' %
(resp_header, reshdr[resp_header]))
# Send authentication message
ServerChallenge, NegotiateFlags = \
ntlm.parse_NTLM_CHALLENGE_MESSAGE(auth_header_value)
auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(ServerChallenge,
self.user,
self.domain,
self.pw,
NegotiateFlags)
headers[req_header] = 'NTLM %s' % auth_msg
log.debug('Request headers: %s', headers)
conn.request('GET', self.authurl, None, headers)
res = conn.getresponse()
log.debug('Response status: %s %s', res.status, res.reason)
log.debug('Response headers: %s', dict(res.getheaders()))
log.debug('Response data: %s [...]', res.read()[:100])
if res.status != 200:
if res.status == 401:
raise Exception('Server rejected request: wrong '
'username or password')
raise Exception('Wrong server response: %s %s' %
(res.status, res.reason))
res.fp = None
log.debug('Connection established')
return conn
def urlopen(self, method, url, body=None, headers=None, retries=3,
redirect=True, assert_same_host=True):
if headers is None:
headers = {}
headers['Connection'] = 'Keep-Alive'
return super(NTLMConnectionPool, self).urlopen(method, url, body,
headers, retries,
redirect,
assert_same_host)
|
gpl-3.0
|
[
624,
199,
46,
25112,
28532,
1958,
4203,
12,
406,
24855,
701,
9266,
3258,
301,
424,
495,
290,
199,
199,
17106,
327,
709,
12,
1937,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
4078,
19,
15,
10115,
15,
5506,
31,
344,
29,
709,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
2050,
492,
28138,
199,
504,
302,
5019,
77,
492,
302,
5019,
77,
199,
199,
504,
2508,
492,
14147,
23929,
199,
504,
2508,
5154,
14,
4174,
14,
4912,
14,
1014,
63,
1258,
492,
14147,
3225,
421,
199,
793,
275,
28138,
3460,
354,
3368,
421,
199,
533,
653,
25112,
23929,
8,
14921,
23929,
304,
272,
408,
272,
24664,
376,
653,
25112,
6299,
1015,
402,
376,
4011,
19,
1950,
4203,
272,
408,
339,
5687,
275,
283,
2859,
7,
339,
347,
636,
826,
721,
277,
12,
922,
12,
19206,
12,
1790,
633,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
1790,
633,
365,
282,
2196,
2851,
641,
314,
1654,
626,
365,
17819,
701,
653,
25112,
14,
267,
922,
365,
314,
5417,
922,
12,
8646,
315,
314,
15265,
1103,
2473,
1475,
14,
267,
19206,
365,
314,
2505,
367,
314,
922,
14,
267,
408,
267,
1613,
8,
46,
25112,
23929,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1178,
633,
275,
1790,
633,
267,
291,
14,
1773,
751,
275,
922,
267,
922,
63,
4181,
275,
922,
14,
1294,
20786,
413,
9,
267,
291,
14,
2261,
275,
922,
63,
4181,
59,
16,
1055,
4142,
342,
267,
291,
14,
751,
275,
922,
63,
4181,
59,
17,
61,
267,
291,
14,
8796,
275,
19206,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
327,
29822,
314,
653,
25112,
14305,
626,
6513,
1482,
314,
1950,
14,
710,
2838,
267,
327,
1471,
506,
16204,
1551,
1830,
4145,
787,
10585,
14,
267,
291,
14,
1507,
63,
7995,
847,
413,
267,
943,
14,
1757,
360,
14139,
653,
25112,
14147,
1950,
949,
14,
450,
68,
26,
4178,
13827,
83,
5,
83,
297,
2116,
291,
14,
1507,
63,
7995,
12,
291,
14,
1102,
12,
291,
14,
1178,
633,
9,
398,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
2648,
63,
1291,
275,
283,
11626,
7,
267,
3085,
63,
1291,
275,
283,
1544,
13,
13975,
7,
398,
2557,
275,
14147,
3225,
8,
1102,
29,
277,
14,
1102,
12,
1844,
29,
277,
14,
719,
9,
398,
327,
10217,
29184,
425,
1245,
267,
2323,
59,
2103,
63,
1291,
61,
275,
334,
288,
283,
46,
25112,
450,
83,
7,
450,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
31254,
1387,
41,
1951,
63,
8272,
8,
277,
14,
1773,
751,
430,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
522,
11244,
275,
1211,
8,
470,
14,
19958,
83,
1012,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
522,
11244,
9,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
8,
1960,
430,
398,
327,
5852,
314,
3659,
370,
314,
2838,
12,
880,
626,
652,
883,
440,
506,
6876,
701,
267,
327,
314,
1177,
909,
334,
1129,
2934,
370,
4215,
314,
2838,
1551,
9,
267,
522,
14,
3997,
275,
488,
398,
327,
7146,
1077,
22722,
543,
282,
14929,
1245,
267,
1790,
63,
1291,
63,
1459,
275,
522,
11244,
59,
4518,
63,
1291,
1055,
1294,
5102,
5320,
267,
1790,
63,
1291,
63,
585,
275,
488,
267,
367,
308,
315,
1790,
63,
1291,
63,
1459,
26,
288,
340,
308,
1491,
21,
61,
508,
283,
46,
25112,
7596,
355,
1790,
63,
1291,
63,
585,
275,
308,
59,
21,
2938,
267,
340,
1790,
63,
1291,
63,
585,
365,
488,
26,
288,
746,
2186,
360,
8708,
450,
83,
1177,
1406,
26,
450,
83,
7,
450,
1169,
334,
4518,
63,
1291,
12,
522,
11244,
59,
4518,
63,
1291,
2459,
398,
327,
10217,
6299,
1245,
267,
7146,
30531,
12,
5612,
14727,
323,
6381,
275,
971,
288,
302,
5019,
77,
14,
1122,
63,
46,
25112,
63,
1244,
1761,
742,
4962,
63,
8272,
8,
1178,
63,
1291,
63,
585,
9,
267,
1790,
63,
1328,
275,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
22923,
1951,
63,
8272,
8,
3120,
30531,
12,
12740,
291,
14,
751,
12,
12740,
291,
14,
2261,
12,
12740,
291,
14,
8796,
12,
12740,
5612,
14727,
323,
6381,
9,
267,
2323,
59,
2103,
63,
1291,
61,
275,
283,
46,
25112,
450,
83,
7,
450,
1790,
63,
1328,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
1211,
8,
470,
14,
19958,
83,
4059,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
20523,
1960,
566,
267,
340,
522,
14,
1205,
1137,
1926,
26,
288,
340,
522,
14,
1205,
508,
13952,
26,
355,
746,
2186,
360,
3120,
18935,
1056,
26,
6835,
283,
1816,
283,
2473,
503,
2505,
358,
288,
746,
2186,
360,
14858,
1654,
1177,
26,
450,
83,
450,
83,
7,
450,
1169,
334,
470,
14,
1205,
12,
522,
14,
5764,
430,
398,
522,
14,
3997,
275,
488,
267,
943,
14,
1757,
360,
3225,
23594,
358,
267,
372,
2557,
339,
347,
18279,
8,
277,
12,
1083,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
10086,
29,
19,
12,
355,
4660,
29,
549,
12,
702,
63,
7191,
63,
1102,
29,
549,
304,
267,
340,
2323,
365,
488,
26,
288,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
372,
1613,
8,
46,
25112,
23929,
12,
291,
680,
10890,
8,
765,
12,
1166
] |
[
199,
46,
25112,
28532,
1958,
4203,
12,
406,
24855,
701,
9266,
3258,
301,
424,
495,
290,
199,
199,
17106,
327,
709,
12,
1937,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
4078,
19,
15,
10115,
15,
5506,
31,
344,
29,
709,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
2050,
492,
28138,
199,
504,
302,
5019,
77,
492,
302,
5019,
77,
199,
199,
504,
2508,
492,
14147,
23929,
199,
504,
2508,
5154,
14,
4174,
14,
4912,
14,
1014,
63,
1258,
492,
14147,
3225,
421,
199,
793,
275,
28138,
3460,
354,
3368,
421,
199,
533,
653,
25112,
23929,
8,
14921,
23929,
304,
272,
408,
272,
24664,
376,
653,
25112,
6299,
1015,
402,
376,
4011,
19,
1950,
4203,
272,
408,
339,
5687,
275,
283,
2859,
7,
339,
347,
636,
826,
721,
277,
12,
922,
12,
19206,
12,
1790,
633,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
1790,
633,
365,
282,
2196,
2851,
641,
314,
1654,
626,
365,
17819,
701,
653,
25112,
14,
267,
922,
365,
314,
5417,
922,
12,
8646,
315,
314,
15265,
1103,
2473,
1475,
14,
267,
19206,
365,
314,
2505,
367,
314,
922,
14,
267,
408,
267,
1613,
8,
46,
25112,
23929,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1178,
633,
275,
1790,
633,
267,
291,
14,
1773,
751,
275,
922,
267,
922,
63,
4181,
275,
922,
14,
1294,
20786,
413,
9,
267,
291,
14,
2261,
275,
922,
63,
4181,
59,
16,
1055,
4142,
342,
267,
291,
14,
751,
275,
922,
63,
4181,
59,
17,
61,
267,
291,
14,
8796,
275,
19206,
339,
347,
485,
1222,
63,
1631,
8,
277,
304,
267,
327,
29822,
314,
653,
25112,
14305,
626,
6513,
1482,
314,
1950,
14,
710,
2838,
267,
327,
1471,
506,
16204,
1551,
1830,
4145,
787,
10585,
14,
267,
291,
14,
1507,
63,
7995,
847,
413,
267,
943,
14,
1757,
360,
14139,
653,
25112,
14147,
1950,
949,
14,
450,
68,
26,
4178,
13827,
83,
5,
83,
297,
2116,
291,
14,
1507,
63,
7995,
12,
291,
14,
1102,
12,
291,
14,
1178,
633,
9,
398,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
2648,
63,
1291,
275,
283,
11626,
7,
267,
3085,
63,
1291,
275,
283,
1544,
13,
13975,
7,
398,
2557,
275,
14147,
3225,
8,
1102,
29,
277,
14,
1102,
12,
1844,
29,
277,
14,
719,
9,
398,
327,
10217,
29184,
425,
1245,
267,
2323,
59,
2103,
63,
1291,
61,
275,
334,
288,
283,
46,
25112,
450,
83,
7,
450,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
31254,
1387,
41,
1951,
63,
8272,
8,
277,
14,
1773,
751,
430,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
522,
11244,
275,
1211,
8,
470,
14,
19958,
83,
1012,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
522,
11244,
9,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
8,
1960,
430,
398,
327,
5852,
314,
3659,
370,
314,
2838,
12,
880,
626,
652,
883,
440,
506,
6876,
701,
267,
327,
314,
1177,
909,
334,
1129,
2934,
370,
4215,
314,
2838,
1551,
9,
267,
522,
14,
3997,
275,
488,
398,
327,
7146,
1077,
22722,
543,
282,
14929,
1245,
267,
1790,
63,
1291,
63,
1459,
275,
522,
11244,
59,
4518,
63,
1291,
1055,
1294,
5102,
5320,
267,
1790,
63,
1291,
63,
585,
275,
488,
267,
367,
308,
315,
1790,
63,
1291,
63,
1459,
26,
288,
340,
308,
1491,
21,
61,
508,
283,
46,
25112,
7596,
355,
1790,
63,
1291,
63,
585,
275,
308,
59,
21,
2938,
267,
340,
1790,
63,
1291,
63,
585,
365,
488,
26,
288,
746,
2186,
360,
8708,
450,
83,
1177,
1406,
26,
450,
83,
7,
450,
1169,
334,
4518,
63,
1291,
12,
522,
11244,
59,
4518,
63,
1291,
2459,
398,
327,
10217,
6299,
1245,
267,
7146,
30531,
12,
5612,
14727,
323,
6381,
275,
971,
288,
302,
5019,
77,
14,
1122,
63,
46,
25112,
63,
1244,
1761,
742,
4962,
63,
8272,
8,
1178,
63,
1291,
63,
585,
9,
267,
1790,
63,
1328,
275,
302,
5019,
77,
14,
981,
63,
46,
25112,
63,
22923,
1951,
63,
8272,
8,
3120,
30531,
12,
12740,
291,
14,
751,
12,
12740,
291,
14,
2261,
12,
12740,
291,
14,
8796,
12,
12740,
5612,
14727,
323,
6381,
9,
267,
2323,
59,
2103,
63,
1291,
61,
275,
283,
46,
25112,
450,
83,
7,
450,
1790,
63,
1328,
267,
943,
14,
1757,
360,
2017,
2323,
26,
450,
83,
297,
2323,
9,
267,
2557,
14,
1069,
360,
2970,
297,
291,
14,
1178,
633,
12,
488,
12,
2323,
9,
267,
522,
275,
2557,
14,
25006,
342,
267,
943,
14,
1757,
360,
2364,
2004,
26,
450,
83,
450,
83,
297,
522,
14,
1205,
12,
522,
14,
5764,
9,
267,
943,
14,
1757,
360,
2364,
2323,
26,
450,
83,
297,
1211,
8,
470,
14,
19958,
83,
4059,
267,
943,
14,
1757,
360,
2364,
666,
26,
450,
83,
359,
1396,
4300,
522,
14,
739,
20523,
1960,
566,
267,
340,
522,
14,
1205,
1137,
1926,
26,
288,
340,
522,
14,
1205,
508,
13952,
26,
355,
746,
2186,
360,
3120,
18935,
1056,
26,
6835,
283,
1816,
283,
2473,
503,
2505,
358,
288,
746,
2186,
360,
14858,
1654,
1177,
26,
450,
83,
450,
83,
7,
450,
1169,
334,
470,
14,
1205,
12,
522,
14,
5764,
430,
398,
522,
14,
3997,
275,
488,
267,
943,
14,
1757,
360,
3225,
23594,
358,
267,
372,
2557,
339,
347,
18279,
8,
277,
12,
1083,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
10086,
29,
19,
12,
355,
4660,
29,
549,
12,
702,
63,
7191,
63,
1102,
29,
549,
304,
267,
340,
2323,
365,
488,
26,
288,
2323,
275,
1052,
267,
2323,
459,
3225,
418,
275,
283,
18567,
13,
23692,
7,
267,
372,
1613,
8,
46,
25112,
23929,
12,
291,
680,
10890,
8,
765,
12,
1166,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alianmohammad/gem5-linux-kernel
|
tools/perf/scripts/python/netdev-times.py
|
11271
|
15048
|
# Display a process of packets and processed time.
# It helps us to investigate networking or network device.
#
# options
# tx: show only tx chart
# rx: show only rx chart
# dev=: show only thing related to specified device
# debug: work with debug mode. It shows buffer status.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
all_event_list = []; # insert all tracepoint event related with this script
irq_dic = {}; # key is cpu and value is a list which stacks irqs
# which raise NET_RX softirq
net_rx_dic = {}; # key is cpu and value include time of NET_RX softirq-entry
# and a list which stacks receive
receive_hunk_list = []; # a list which include a sequence of receive events
rx_skb_list = []; # received packet list for matching
# skb_copy_datagram_iovec
buffer_budget = 65536; # the budget of rx_skb_list, tx_queue_list and
# tx_xmit_list
of_count_rx_skb_list = 0; # overflow count
tx_queue_list = []; # list of packets which pass through dev_queue_xmit
of_count_tx_queue_list = 0; # overflow count
tx_xmit_list = []; # list of packets which pass through dev_hard_start_xmit
of_count_tx_xmit_list = 0; # overflow count
tx_free_list = []; # list of packets which is freed
# options
show_tx = 0;
show_rx = 0;
dev = 0; # store a name of device specified by option "dev="
debug = 0;
# indices of event_info tuple
EINFO_IDX_NAME= 0
EINFO_IDX_CONTEXT=1
EINFO_IDX_CPU= 2
EINFO_IDX_TIME= 3
EINFO_IDX_PID= 4
EINFO_IDX_COMM= 5
# Calculate a time interval(msec) from src(nsec) to dst(nsec)
def diff_msec(src, dst):
return (dst - src) / 1000000.0
# Display a process of transmitting a packet
def print_transmit(hunk):
if dev != 0 and hunk['dev'].find(dev) < 0:
return
print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \
(hunk['dev'], hunk['len'],
nsecs_secs(hunk['queue_t']),
nsecs_nsecs(hunk['queue_t'])/1000,
diff_msec(hunk['queue_t'], hunk['xmit_t']),
diff_msec(hunk['xmit_t'], hunk['free_t']))
# Format for displaying rx packet processing
PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)"
PF_SOFT_ENTRY=" softirq_entry(+%.3fmsec)"
PF_NAPI_POLL= " napi_poll_exit(+%.3fmsec %s)"
PF_JOINT= " |"
PF_WJOINT= " | |"
PF_NET_RECV= " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)"
PF_NET_RX= " |---netif_rx(+%.3fmsec skb=%x)"
PF_CPY_DGRAM= " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)"
PF_KFREE_SKB= " | kfree_skb(+%.3fmsec location=%x)"
PF_CONS_SKB= " | consume_skb(+%.3fmsec)"
# Display a process of received packets and interrputs associated with
# a NET_RX softirq
def print_receive(hunk):
show_hunk = 0
irq_list = hunk['irq_list']
cpu = irq_list[0]['cpu']
base_t = irq_list[0]['irq_ent_t']
# check if this hunk should be showed
if dev != 0:
for i in range(len(irq_list)):
if irq_list[i]['name'].find(dev) >= 0:
show_hunk = 1
break
else:
show_hunk = 1
if show_hunk == 0:
return
print "%d.%06dsec cpu=%d" % \
(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)
for i in range(len(irq_list)):
print PF_IRQ_ENTRY % \
(diff_msec(base_t, irq_list[i]['irq_ent_t']),
irq_list[i]['irq'], irq_list[i]['name'])
print PF_JOINT
irq_event_list = irq_list[i]['event_list']
for j in range(len(irq_event_list)):
irq_event = irq_event_list[j]
if irq_event['event'] == 'netif_rx':
print PF_NET_RX % \
(diff_msec(base_t, irq_event['time']),
irq_event['skbaddr'])
print PF_JOINT
print PF_SOFT_ENTRY % \
diff_msec(base_t, hunk['sirq_ent_t'])
print PF_JOINT
event_list = hunk['event_list']
for i in range(len(event_list)):
event = event_list[i]
if event['event_name'] == 'napi_poll':
print PF_NAPI_POLL % \
(diff_msec(base_t, event['event_t']), event['dev'])
if i == len(event_list) - 1:
print ""
else:
print PF_JOINT
else:
print PF_NET_RECV % \
(diff_msec(base_t, event['event_t']), event['skbaddr'],
event['len'])
if 'comm' in event.keys():
print PF_WJOINT
print PF_CPY_DGRAM % \
(diff_msec(base_t, event['comm_t']),
event['pid'], event['comm'])
elif 'handle' in event.keys():
print PF_WJOINT
if event['handle'] == "kfree_skb":
print PF_KFREE_SKB % \
(diff_msec(base_t,
event['comm_t']),
event['location'])
elif event['handle'] == "consume_skb":
print PF_CONS_SKB % \
diff_msec(base_t,
event['comm_t'])
print PF_JOINT
def trace_begin():
global show_tx
global show_rx
global dev
global debug
for i in range(len(sys.argv)):
if i == 0:
continue
arg = sys.argv[i]
if arg == 'tx':
show_tx = 1
elif arg =='rx':
show_rx = 1
elif arg.find('dev=',0, 4) >= 0:
dev = arg[4:]
elif arg == 'debug':
debug = 1
if show_tx == 0 and show_rx == 0:
show_tx = 1
show_rx = 1
def trace_end():
# order all events in time
all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME],
b[EINFO_IDX_TIME]))
# process all events
for i in range(len(all_event_list)):
event_info = all_event_list[i]
name = event_info[EINFO_IDX_NAME]
if name == 'irq__softirq_exit':
handle_irq_softirq_exit(event_info)
elif name == 'irq__softirq_entry':
handle_irq_softirq_entry(event_info)
elif name == 'irq__softirq_raise':
handle_irq_softirq_raise(event_info)
elif name == 'irq__irq_handler_entry':
handle_irq_handler_entry(event_info)
elif name == 'irq__irq_handler_exit':
handle_irq_handler_exit(event_info)
elif name == 'napi__napi_poll':
handle_napi_poll(event_info)
elif name == 'net__netif_receive_skb':
handle_netif_receive_skb(event_info)
elif name == 'net__netif_rx':
handle_netif_rx(event_info)
elif name == 'skb__skb_copy_datagram_iovec':
handle_skb_copy_datagram_iovec(event_info)
elif name == 'net__net_dev_queue':
handle_net_dev_queue(event_info)
elif name == 'net__net_dev_xmit':
handle_net_dev_xmit(event_info)
elif name == 'skb__kfree_skb':
handle_kfree_skb(event_info)
elif name == 'skb__consume_skb':
handle_consume_skb(event_info)
# display receive hunks
if show_rx:
for i in range(len(receive_hunk_list)):
print_receive(receive_hunk_list[i])
# display transmit hunks
if show_tx:
print " dev len Qdisc " \
" netdevice free"
for i in range(len(tx_free_list)):
print_transmit(tx_free_list[i])
if debug:
print "debug buffer status"
print "----------------------------"
print "xmit Qdisc:remain:%d overflow:%d" % \
(len(tx_queue_list), of_count_tx_queue_list)
print "xmit netdevice:remain:%d overflow:%d" % \
(len(tx_xmit_list), of_count_tx_xmit_list)
print "receive:remain:%d overflow:%d" % \
(len(rx_skb_list), of_count_rx_skb_list)
# called from perf, when it finds a correspoinding event
def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_exit(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_raise(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__irq_handler_entry(name, context, cpu, sec, nsec, pid, comm,
irq, irq_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
irq, irq_name)
all_event_list.append(event_info)
def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, irq, ret):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret)
all_event_list.append(event_info)
def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, napi, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
napi, dev_name)
all_event_list.append(event_info)
def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__netif_rx(name, context, cpu, sec, nsec, pid, comm, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_queue(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_xmit(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen, rc, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, rc ,dev_name)
all_event_list.append(event_info)
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm,
skbaddr, protocol, location):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, protocol, location)
all_event_list.append(event_info)
def skb__consume_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr)
all_event_list.append(event_info)
def skb__skb_copy_datagram_iovec(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen)
all_event_list.append(event_info)
def handle_irq_handler_entry(event_info):
(name, context, cpu, time, pid, comm, irq, irq_name) = event_info
if cpu not in irq_dic.keys():
irq_dic[cpu] = []
irq_record = {'irq':irq, 'name':irq_name, 'cpu':cpu, 'irq_ent_t':time}
irq_dic[cpu].append(irq_record)
def handle_irq_handler_exit(event_info):
(name, context, cpu, time, pid, comm, irq, ret) = event_info
if cpu not in irq_dic.keys():
return
irq_record = irq_dic[cpu].pop()
if irq != irq_record['irq']:
return
irq_record.update({'irq_ext_t':time})
# if an irq doesn't include NET_RX softirq, drop.
if 'event_list' in irq_record.keys():
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_raise(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'sirq_raise'})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_entry(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
net_rx_dic[cpu] = {'sirq_ent_t':time, 'event_list':[]}
def handle_irq_softirq_exit(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
irq_list = []
event_list = 0
if cpu in irq_dic.keys():
irq_list = irq_dic[cpu]
del irq_dic[cpu]
if cpu in net_rx_dic.keys():
sirq_ent_t = net_rx_dic[cpu]['sirq_ent_t']
event_list = net_rx_dic[cpu]['event_list']
del net_rx_dic[cpu]
if irq_list == [] or event_list == 0:
return
rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time,
'irq_list':irq_list, 'event_list':event_list}
# merge information realted to a NET_RX softirq
receive_hunk_list.append(rec_data)
def handle_napi_poll(event_info):
(name, context, cpu, time, pid, comm, napi, dev_name) = event_info
if cpu in net_rx_dic.keys():
event_list = net_rx_dic[cpu]['event_list']
rec_data = {'event_name':'napi_poll',
'dev':dev_name, 'event_t':time}
event_list.append(rec_data)
def handle_netif_rx(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'netif_rx',
'skbaddr':skbaddr, 'skblen':skblen, 'dev_name':dev_name})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_netif_receive_skb(event_info):
global of_count_rx_skb_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu in net_rx_dic.keys():
rec_data = {'event_name':'netif_receive_skb',
'event_t':time, 'skbaddr':skbaddr, 'len':skblen}
event_list = net_rx_dic[cpu]['event_list']
event_list.append(rec_data)
rx_skb_list.insert(0, rec_data)
if len(rx_skb_list) > buffer_budget:
rx_skb_list.pop()
of_count_rx_skb_list += 1
def handle_net_dev_queue(event_info):
global of_count_tx_queue_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
skb = {'dev':dev_name, 'skbaddr':skbaddr, 'len':skblen, 'queue_t':time}
tx_queue_list.insert(0, skb)
if len(tx_queue_list) > buffer_budget:
tx_queue_list.pop()
of_count_tx_queue_list += 1
def handle_net_dev_xmit(event_info):
global of_count_tx_xmit_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, rc, dev_name) = event_info
if rc == 0: # NETDEV_TX_OK
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
skb['xmit_t'] = time
tx_xmit_list.insert(0, skb)
del tx_queue_list[i]
if len(tx_xmit_list) > buffer_budget:
tx_xmit_list.pop()
of_count_tx_xmit_list += 1
return
def handle_kfree_skb(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, protocol, location) = event_info
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
del tx_queue_list[i]
return
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if rec_data['skbaddr'] == skbaddr:
rec_data.update({'handle':"kfree_skb",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
def handle_consume_skb(event_info):
(name, context, cpu, time, pid, comm, skbaddr) = event_info
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
def handle_skb_copy_datagram_iovec(event_info):
(name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if skbaddr == rec_data['skbaddr']:
rec_data.update({'handle':"skb_copy_datagram_iovec",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
|
gpl-2.0
|
[
3,
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,
198,
3,
1104,
340,
642,
19988,
1077,
506,
2498,
379,
199,
198,
692,
4866,
1137,
378,
26,
507,
198,
509,
284,
315,
1425,
8,
552,
8,
7277,
63,
513,
2298,
686,
198,
692,
10476,
63,
513
] |
[
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
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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
] |
unnikrishnankgs/va
|
venv/lib/python3.5/site-packages/numpy/distutils/msvccompiler.py
|
26
|
1991
|
from __future__ import division, absolute_import, print_function
import os
from distutils.msvccompiler import MSVCCompiler as _MSVCCompiler
from .system_info import platform_bits
def _merge(old, new):
"""Concatenate two environment paths avoiding repeats.
Here `old` is the environment string before the base class initialize
function is called and `new` is the string after the call. The new string
will be a fixed string if it is not obtained from the current enviroment,
or the same as the old string if obtained from the same enviroment. The aim
here is not to append the new string if it is already contained in the old
string so as to limit the growth of the environment string.
Parameters
----------
old : string
Previous enviroment string.
new : string
New environment string.
Returns
-------
ret : string
Updated environment string.
"""
if new in old:
return old
if not old:
return new
# Neither new nor old is empty. Give old priority.
return ';'.join([old, new])
class MSVCCompiler(_MSVCCompiler):
def __init__(self, verbose=0, dry_run=0, force=0):
_MSVCCompiler.__init__(self, verbose, dry_run, force)
def initialize(self):
# The 'lib' and 'include' variables may be overwritten
# by MSVCCompiler.initialize, so save them for later merge.
environ_lib = os.getenv('lib', '')
environ_include = os.getenv('include', '')
_MSVCCompiler.initialize(self)
# Merge current and previous values of 'lib' and 'include'
os.environ['lib'] = _merge(environ_lib, os.environ['lib'])
os.environ['include'] = _merge(environ_include, os.environ['include'])
# msvc9 building for 32 bits requires SSE2 to work around a
# compiler bug.
if platform_bits == 32:
self.compile_options += ['/arch:SSE2']
self.compile_options_debug += ['/arch:SSE2']
|
bsd-2-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
504,
7065,
14,
19875,
5772,
492,
11694,
30926,
465,
485,
3053,
9454,
9131,
199,
199,
504,
1275,
2253,
63,
815,
492,
4298,
63,
5609,
421,
199,
318,
485,
5628,
8,
1753,
12,
892,
304,
272,
408,
714,
10592,
2877,
3734,
3792,
5126,
316,
28908,
14,
339,
11842,
658,
1753,
64,
365,
314,
3734,
1059,
2544,
314,
1300,
1021,
8265,
272,
805,
365,
2797,
436,
658,
1222,
64,
365,
314,
1059,
2410,
314,
1240,
14,
710,
892,
1059,
272,
911,
506,
282,
6317,
1059,
340,
652,
365,
440,
15884,
687,
314,
1453,
655,
433,
293,
434,
12,
272,
503,
314,
2011,
465,
314,
2269,
1059,
340,
15884,
687,
314,
2011,
655,
433,
293,
434,
14,
710,
282,
1017,
272,
2348,
365,
440,
370,
5666,
314,
892,
1059,
340,
652,
365,
2575,
10470,
315,
314,
2269,
272,
1059,
880,
465,
370,
2304,
314,
20772,
273,
402,
314,
3734,
1059,
14,
339,
3897,
272,
4143,
272,
2269,
520,
1059,
267,
26902,
655,
433,
293,
434,
1059,
14,
272,
892,
520,
1059,
267,
7053,
3734,
1059,
14,
339,
1803,
272,
5514,
272,
2203,
520,
1059,
267,
6162,
68,
3734,
1059,
14,
339,
408,
272,
340,
892,
315,
2269,
26,
267,
372,
2269,
272,
340,
440,
2269,
26,
267,
372,
892,
339,
327,
11443,
892,
6590,
2269,
365,
2701,
14,
25495,
2269,
7464,
14,
272,
372,
30955,
904,
779,
1753,
12,
892,
566,
421,
199,
533,
11694,
30926,
1547,
3053,
9454,
9131,
304,
272,
347,
636,
826,
721,
277,
12,
3376,
29,
16,
12,
9951,
63,
1065,
29,
16,
12,
3542,
29,
16,
304,
267,
485,
3053,
9454,
9131,
855,
826,
721,
277,
12,
3376,
12,
9951,
63,
1065,
12,
3542,
9,
339,
347,
8265,
8,
277,
304,
267,
327,
710,
283,
773,
7,
436,
283,
2613,
7,
2860,
1443,
506,
20200,
267,
327,
701,
11694,
30926,
14,
8489,
12,
880,
3354,
3062,
367,
2945,
5389,
14,
267,
6160,
63,
773,
275,
747,
14,
12959,
360,
773,
297,
4074,
267,
6160,
63,
2613,
275,
747,
14,
12959,
360,
2613,
297,
4074,
267,
485,
3053,
9454,
9131,
14,
8489,
8,
277,
9,
398,
327,
14076,
1453,
436,
4136,
1338,
402,
283,
773,
7,
436,
283,
2613,
7,
267,
747,
14,
2314,
459,
773,
418,
275,
485,
5628,
8,
2314,
63,
773,
12,
747,
14,
2314,
459,
773,
1105,
267,
747,
14,
2314,
459,
2613,
418,
275,
485,
5628,
8,
2314,
63,
2613,
12,
747,
14,
2314,
459,
2613,
1105,
398,
327,
333,
10599,
25,
10015,
367,
4337,
5821,
5074,
428,
899,
18,
370,
1736,
6818,
282,
267,
327,
6365,
6519,
14,
267,
340,
4298,
63,
5609,
508,
4337,
26,
288,
291,
14,
2014,
63,
1419,
847,
18744,
1047,
26,
24932,
18,
418,
288,
291,
14,
2014,
63,
1419,
63,
1757,
847,
18744,
1047,
26,
24932,
18,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
504,
7065,
14,
19875,
5772,
492,
11694,
30926,
465,
485,
3053,
9454,
9131,
199,
199,
504,
1275,
2253,
63,
815,
492,
4298,
63,
5609,
421,
199,
318,
485,
5628,
8,
1753,
12,
892,
304,
272,
408,
714,
10592,
2877,
3734,
3792,
5126,
316,
28908,
14,
339,
11842,
658,
1753,
64,
365,
314,
3734,
1059,
2544,
314,
1300,
1021,
8265,
272,
805,
365,
2797,
436,
658,
1222,
64,
365,
314,
1059,
2410,
314,
1240,
14,
710,
892,
1059,
272,
911,
506,
282,
6317,
1059,
340,
652,
365,
440,
15884,
687,
314,
1453,
655,
433,
293,
434,
12,
272,
503,
314,
2011,
465,
314,
2269,
1059,
340,
15884,
687,
314,
2011,
655,
433,
293,
434,
14,
710,
282,
1017,
272,
2348,
365,
440,
370,
5666,
314,
892,
1059,
340,
652,
365,
2575,
10470,
315,
314,
2269,
272,
1059,
880,
465,
370,
2304,
314,
20772,
273,
402,
314,
3734,
1059,
14,
339,
3897,
272,
4143,
272,
2269,
520,
1059,
267,
26902,
655,
433,
293,
434,
1059,
14,
272,
892,
520,
1059,
267,
7053,
3734,
1059,
14,
339,
1803,
272,
5514,
272,
2203,
520,
1059,
267,
6162,
68,
3734,
1059,
14,
339,
408,
272,
340,
892,
315,
2269,
26,
267,
372,
2269,
272,
340,
440,
2269,
26,
267,
372,
892,
339,
327,
11443,
892,
6590,
2269,
365,
2701,
14,
25495,
2269,
7464,
14,
272,
372,
30955,
904,
779,
1753,
12,
892,
566,
421,
199,
533,
11694,
30926,
1547,
3053,
9454,
9131,
304,
272,
347,
636,
826,
721,
277,
12,
3376,
29,
16,
12,
9951,
63,
1065,
29,
16,
12,
3542,
29,
16,
304,
267,
485,
3053,
9454,
9131,
855,
826,
721,
277,
12,
3376,
12,
9951,
63,
1065,
12,
3542,
9,
339,
347,
8265,
8,
277,
304,
267,
327,
710,
283,
773,
7,
436,
283,
2613,
7,
2860,
1443,
506,
20200,
267,
327,
701,
11694,
30926,
14,
8489,
12,
880,
3354,
3062,
367,
2945,
5389,
14,
267,
6160,
63,
773,
275,
747,
14,
12959,
360,
773,
297,
4074,
267,
6160,
63,
2613,
275,
747,
14,
12959,
360,
2613,
297,
4074,
267,
485,
3053,
9454,
9131,
14,
8489,
8,
277,
9,
398,
327,
14076,
1453,
436,
4136,
1338,
402,
283,
773,
7,
436,
283,
2613,
7,
267,
747,
14,
2314,
459,
773,
418,
275,
485,
5628,
8,
2314,
63,
773,
12,
747,
14,
2314,
459,
773,
1105,
267,
747,
14,
2314,
459,
2613,
418,
275,
485,
5628,
8,
2314,
63,
2613,
12,
747,
14,
2314,
459,
2613,
1105,
398,
327,
333,
10599,
25,
10015,
367,
4337,
5821,
5074,
428,
899,
18,
370,
1736,
6818,
282,
267,
327,
6365,
6519,
14,
267,
340,
4298,
63,
5609,
508,
4337,
26,
288,
291,
14,
2014,
63,
1419,
847,
18744,
1047,
26,
24932,
18,
418,
288,
291,
14,
2014,
63,
1419,
63,
1757,
847,
18744,
1047,
26,
24932,
18,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hsuantien/scikit-learn
|
doc/tutorial/text_analytics/solutions/exercise_01_language_train_model.py
|
254
|
2253
|
"""Build a language detector model
The goal of this exercise is to train a linear classifier on text features
that represent sequences of up to 3 consecutive characters so as to be
recognize natural languages by using the frequencies of short character
sequences as 'fingerprints'.
"""
# Author: Olivier Grisel <olivier.grisel@ensta.org>
# License: Simplified BSD
import sys
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import Perceptron
from sklearn.pipeline import Pipeline
from sklearn.datasets import load_files
from sklearn.cross_validation import train_test_split
from sklearn import metrics
# The training data folder must be passed as first argument
languages_data_folder = sys.argv[1]
dataset = load_files(languages_data_folder)
# Split the dataset in training and test set:
docs_train, docs_test, y_train, y_test = train_test_split(
dataset.data, dataset.target, test_size=0.5)
# TASK: Build a an vectorizer that splits strings into sequence of 1 to 3
# characters instead of word tokens
vectorizer = TfidfVectorizer(ngram_range=(1, 3), analyzer='char',
use_idf=False)
# TASK: Build a vectorizer / classifier pipeline using the previous analyzer
# the pipeline instance should stored in a variable named clf
clf = Pipeline([
('vec', vectorizer),
('clf', Perceptron()),
])
# TASK: Fit the pipeline on the training set
clf.fit(docs_train, y_train)
# TASK: Predict the outcome on the testing set in a variable named y_predicted
y_predicted = clf.predict(docs_test)
# Print the classification report
print(metrics.classification_report(y_test, y_predicted,
target_names=dataset.target_names))
# Plot the confusion matrix
cm = metrics.confusion_matrix(y_test, y_predicted)
print(cm)
#import pylab as pl
#pl.matshow(cm, cmap=pl.cm.jet)
#pl.show()
# Predict the result on some short new sentences:
sentences = [
u'This is a language detection test.',
u'Ceci est un test de d\xe9tection de la langue.',
u'Dies ist ein Test, um die Sprache zu erkennen.',
]
predicted = clf.predict(sentences)
for s, p in zip(sentences, predicted):
print(u'The language of "%s" is "%s"' % (s, dataset.target_names[p]))
|
bsd-3-clause
|
[
624,
3425,
282,
2637,
17842,
1402,
199,
199,
1918,
14850,
402,
642,
26511,
365,
370,
3560,
282,
7798,
12429,
641,
1318,
4534,
199,
9099,
2954,
8013,
402,
1536,
370,
650,
23376,
4110,
880,
465,
370,
506,
199,
29324,
794,
19981,
10815,
701,
1808,
314,
22411,
402,
3974,
4528,
199,
13436,
465,
283,
15077,
83,
1370,
199,
199,
624,
199,
3,
6529,
26,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
844,
26,
29094,
30200,
6289,
199,
199,
646,
984,
199,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
377,
23274,
26165,
199,
504,
6357,
14,
6676,
63,
1238,
492,
3492,
301,
4695,
265,
199,
504,
6357,
14,
7379,
492,
19090,
199,
504,
6357,
14,
12281,
492,
2248,
63,
1725,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
504,
6357,
492,
7186,
421,
199,
3,
710,
6093,
666,
4922,
1471,
506,
3032,
465,
1642,
1423,
199,
13209,
63,
576,
63,
3741,
275,
984,
14,
3020,
59,
17,
61,
199,
5214,
275,
2248,
63,
1725,
8,
13209,
63,
576,
63,
3741,
9,
199,
199,
3,
11740,
314,
4789,
315,
6093,
436,
511,
663,
26,
199,
4757,
63,
2834,
12,
9149,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
272,
4789,
14,
576,
12,
4789,
14,
1375,
12,
511,
63,
890,
29,
16,
14,
21,
9,
421,
199,
3,
377,
7946,
26,
6516,
282,
376,
5477,
1793,
626,
19115,
3326,
1901,
3414,
402,
413,
370,
650,
199,
3,
4110,
3140,
402,
4349,
4645,
199,
4106,
1793,
275,
377,
23274,
26165,
8,
78,
1679,
63,
1842,
2687,
17,
12,
650,
395,
24608,
534,
1560,
297,
2490,
675,
63,
24003,
29,
797,
9,
199,
199,
3,
377,
7946,
26,
6516,
282,
5477,
1793,
1182,
12429,
7679,
1808,
314,
4136,
24608,
199,
3,
314,
7679,
1256,
1077,
5489,
315,
282,
1750,
4310,
6975,
199,
9694,
275,
19090,
779,
272,
661,
6046,
297,
5477,
1793,
395,
272,
661,
9694,
297,
3492,
301,
4695,
265,
4000,
199,
566,
199,
199,
3,
377,
7946,
26,
25971,
314,
7679,
641,
314,
6093,
663,
199,
9694,
14,
3269,
8,
4757,
63,
2834,
12,
612,
63,
2834,
9,
199,
199,
3,
377,
7946,
26,
5543,
807,
314,
15955,
641,
314,
5343,
663,
315,
282,
1750,
4310,
612,
63,
21118,
199,
89,
63,
21118,
275,
6975,
14,
6892,
8,
4757,
63,
396,
9,
199,
199,
3,
9101,
314,
12505,
3622,
199,
1361,
8,
6759,
14,
14368,
63,
3070,
8,
89,
63,
396,
12,
612,
63,
21118,
12,
2511,
1347,
63,
1247,
29,
5214,
14,
1375,
63,
1247,
430,
199,
199,
3,
14794,
314,
26314,
3634,
199,
4400,
275,
7186,
14,
2190,
12444,
63,
3642,
8,
89,
63,
396,
12,
612,
63,
21118,
9,
199,
1361,
8,
4400,
9,
199,
199,
3,
646,
19199,
465,
1620,
199,
3,
1168,
14,
569,
2384,
8,
4400,
12,
14920,
29,
1168,
14,
4400,
14,
74,
386,
9,
199,
3,
1168,
14,
2384,
342,
199,
199,
3,
5543,
807,
314,
754,
641,
2005,
3974,
892,
24256,
26,
199,
25669,
275,
359,
272,
399,
7,
2765,
365,
282,
2637,
15212,
511,
3130,
272,
399,
7,
24417,
559,
4347,
625,
511,
477,
366,
60,
1845,
25,
5860,
477,
1127,
6339,
310,
3130,
272,
399,
7,
1341,
397,
284,
270,
325,
262,
1379,
12,
28236,
18833,
8360,
345,
595,
1315,
85,
9266,
917,
78,
287,
3130,
199,
61,
199,
21118,
275,
6975,
14,
6892,
8,
25669,
9,
199,
199,
509,
308,
12,
299,
315,
3482,
8,
25669,
12,
14746,
304,
272,
870,
8,
85,
7,
1918,
2637,
402,
2071,
83,
2,
365,
2071,
83,
4507,
450,
334,
83,
12,
4789,
14,
1375,
63,
1247,
59,
80,
2459,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3425,
282,
2637,
17842,
1402,
199,
199,
1918,
14850,
402,
642,
26511,
365,
370,
3560,
282,
7798,
12429,
641,
1318,
4534,
199,
9099,
2954,
8013,
402,
1536,
370,
650,
23376,
4110,
880,
465,
370,
506,
199,
29324,
794,
19981,
10815,
701,
1808,
314,
22411,
402,
3974,
4528,
199,
13436,
465,
283,
15077,
83,
1370,
199,
199,
624,
199,
3,
6529,
26,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
844,
26,
29094,
30200,
6289,
199,
199,
646,
984,
199,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
377,
23274,
26165,
199,
504,
6357,
14,
6676,
63,
1238,
492,
3492,
301,
4695,
265,
199,
504,
6357,
14,
7379,
492,
19090,
199,
504,
6357,
14,
12281,
492,
2248,
63,
1725,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
504,
6357,
492,
7186,
421,
199,
3,
710,
6093,
666,
4922,
1471,
506,
3032,
465,
1642,
1423,
199,
13209,
63,
576,
63,
3741,
275,
984,
14,
3020,
59,
17,
61,
199,
5214,
275,
2248,
63,
1725,
8,
13209,
63,
576,
63,
3741,
9,
199,
199,
3,
11740,
314,
4789,
315,
6093,
436,
511,
663,
26,
199,
4757,
63,
2834,
12,
9149,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
272,
4789,
14,
576,
12,
4789,
14,
1375,
12,
511,
63,
890,
29,
16,
14,
21,
9,
421,
199,
3,
377,
7946,
26,
6516,
282,
376,
5477,
1793,
626,
19115,
3326,
1901,
3414,
402,
413,
370,
650,
199,
3,
4110,
3140,
402,
4349,
4645,
199,
4106,
1793,
275,
377,
23274,
26165,
8,
78,
1679,
63,
1842,
2687,
17,
12,
650,
395,
24608,
534,
1560,
297,
2490,
675,
63,
24003,
29,
797,
9,
199,
199,
3,
377,
7946,
26,
6516,
282,
5477,
1793,
1182,
12429,
7679,
1808,
314,
4136,
24608,
199,
3,
314,
7679,
1256,
1077,
5489,
315,
282,
1750,
4310,
6975,
199,
9694,
275,
19090,
779,
272,
661,
6046,
297,
5477,
1793,
395,
272,
661,
9694,
297,
3492,
301,
4695,
265,
4000,
199,
566,
199,
199,
3,
377,
7946,
26,
25971,
314,
7679,
641,
314,
6093,
663,
199,
9694,
14,
3269,
8,
4757,
63,
2834,
12,
612,
63,
2834,
9,
199,
199,
3,
377,
7946,
26,
5543,
807,
314,
15955,
641,
314,
5343,
663,
315,
282,
1750,
4310,
612,
63,
21118,
199,
89,
63,
21118,
275,
6975,
14,
6892,
8,
4757,
63,
396,
9,
199,
199,
3,
9101,
314,
12505,
3622,
199,
1361,
8,
6759,
14,
14368,
63,
3070,
8,
89,
63,
396,
12,
612,
63,
21118,
12,
2511,
1347,
63,
1247,
29,
5214,
14,
1375,
63,
1247,
430,
199,
199,
3,
14794,
314,
26314,
3634,
199,
4400,
275,
7186,
14,
2190,
12444,
63,
3642,
8,
89,
63,
396,
12,
612,
63,
21118,
9,
199,
1361,
8,
4400,
9,
199,
199,
3,
646,
19199,
465,
1620,
199,
3,
1168,
14,
569,
2384,
8,
4400,
12,
14920,
29,
1168,
14,
4400,
14,
74,
386,
9,
199,
3,
1168,
14,
2384,
342,
199,
199,
3,
5543,
807,
314,
754,
641,
2005,
3974,
892,
24256,
26,
199,
25669,
275,
359,
272,
399,
7,
2765,
365,
282,
2637,
15212,
511,
3130,
272,
399,
7,
24417,
559,
4347,
625,
511,
477,
366,
60,
1845,
25,
5860,
477,
1127,
6339,
310,
3130,
272,
399,
7,
1341,
397,
284,
270,
325,
262,
1379,
12,
28236,
18833,
8360,
345,
595,
1315,
85,
9266,
917,
78,
287,
3130,
199,
61,
199,
21118,
275,
6975,
14,
6892,
8,
25669,
9,
199,
199,
509,
308,
12,
299,
315,
3482,
8,
25669,
12,
14746,
304,
272,
870,
8,
85,
7,
1918,
2637,
402,
2071,
83,
2,
365,
2071,
83,
4507,
450,
334,
83,
12,
4789,
14,
1375,
63,
1247,
59,
80,
2459,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MMohan1/dwitter
|
dwitter_app/models.py
|
1
|
1342
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
import hashlib
class Dweet(models.Model):
content = models.CharField(max_length=140)
user = models.ForeignKey(User)
creation_date = models.DateTimeField(auto_now=True, blank=True)
class UserProfile(models.Model):
user = models.ForeignKey(User)
# follows = models.ManyToManyField('self', related_name='followed_by', symmetrical=False)
def gravatar_url(self):
return "http://www.gravatar.com/avatar/%s?s=50" % hashlib.md5(self.user.email).hexdigest()
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
class Follow(models.Model):
follower = models.ForeignKey(User, related_name='follower')
following = models.ForeignKey(User, related_name='following')
follow_date = models.DateTimeField(auto_now=True)
class Likes(models.Model):
dwitte = models.ForeignKey(Dweet)
likes = models.ForeignKey(User)
creation_date = models.DateTimeField(auto_now=True)
class Meta:
unique_together = ("dwitte", "likes")
class Comments(models.Model):
dwitte = models.ForeignKey(Dweet)
comment_by = models.ForeignKey(User)
comment = models.TextField()
creation_date = models.DateTimeField(auto_now=True)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
646,
8337,
421,
199,
533,
577,
11554,
8,
992,
14,
1685,
304,
272,
1564,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
10037,
9,
272,
922,
275,
1709,
14,
3190,
8,
1899,
9,
272,
7143,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
12,
4596,
29,
549,
9,
421,
199,
533,
19037,
8,
992,
14,
1685,
304,
272,
922,
275,
1709,
14,
3190,
8,
1899,
9,
272,
327,
11924,
275,
1709,
14,
7624,
360,
277,
297,
4048,
63,
354,
534,
7207,
379,
63,
991,
297,
30091,
29,
797,
9,
339,
347,
1999,
28694,
63,
633,
8,
277,
304,
267,
372,
298,
1014,
921,
1544,
14,
926,
28694,
14,
957,
15,
14584,
3149,
83,
31,
83,
29,
1400,
2,
450,
8337,
14,
1064,
21,
8,
277,
14,
751,
14,
2123,
680,
11453,
342,
421,
199,
1899,
14,
2913,
275,
3324,
8,
2734,
399,
26,
19037,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
751,
29,
85,
2788,
16,
566,
421,
199,
533,
21876,
8,
992,
14,
1685,
304,
272,
30971,
275,
1709,
14,
3190,
8,
1899,
12,
4048,
63,
354,
534,
25615,
358,
272,
2569,
275,
1709,
14,
3190,
8,
1899,
12,
4048,
63,
354,
534,
21589,
358,
272,
2035,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
421,
199,
533,
491,
3258,
397,
8,
992,
14,
1685,
304,
272,
366,
2503,
266,
275,
1709,
14,
3190,
8,
36,
11554,
9,
272,
1212,
9246,
275,
1709,
14,
3190,
8,
1899,
9,
272,
7143,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
1689,
68,
2503,
266,
401,
298,
29572,
531,
421,
199,
533,
5429,
1470,
8,
992,
14,
1685,
304,
272,
366,
2503,
266,
275,
1709,
14,
3190,
8,
36,
11554,
9,
272,
3721,
63,
991,
275,
1709,
14,
3190,
8,
1899,
9,
272,
3721,
275,
1709,
14,
6254,
342,
272,
7143,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
646,
8337,
421,
199,
533,
577,
11554,
8,
992,
14,
1685,
304,
272,
1564,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
10037,
9,
272,
922,
275,
1709,
14,
3190,
8,
1899,
9,
272,
7143,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
12,
4596,
29,
549,
9,
421,
199,
533,
19037,
8,
992,
14,
1685,
304,
272,
922,
275,
1709,
14,
3190,
8,
1899,
9,
272,
327,
11924,
275,
1709,
14,
7624,
360,
277,
297,
4048,
63,
354,
534,
7207,
379,
63,
991,
297,
30091,
29,
797,
9,
339,
347,
1999,
28694,
63,
633,
8,
277,
304,
267,
372,
298,
1014,
921,
1544,
14,
926,
28694,
14,
957,
15,
14584,
3149,
83,
31,
83,
29,
1400,
2,
450,
8337,
14,
1064,
21,
8,
277,
14,
751,
14,
2123,
680,
11453,
342,
421,
199,
1899,
14,
2913,
275,
3324,
8,
2734,
399,
26,
19037,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
751,
29,
85,
2788,
16,
566,
421,
199,
533,
21876,
8,
992,
14,
1685,
304,
272,
30971,
275,
1709,
14,
3190,
8,
1899,
12,
4048,
63,
354,
534,
25615,
358,
272,
2569,
275,
1709,
14,
3190,
8,
1899,
12,
4048,
63,
354,
534,
21589,
358,
272,
2035,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
421,
199,
533,
491,
3258,
397,
8,
992,
14,
1685,
304,
272,
366,
2503,
266,
275,
1709,
14,
3190,
8,
36,
11554,
9,
272,
1212,
9246,
275,
1709,
14,
3190,
8,
1899,
9,
272,
7143,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
1689,
68,
2503,
266,
401,
298,
29572,
531,
421,
199,
533,
5429,
1470,
8,
992,
14,
1685,
304,
272,
366,
2503,
266,
275,
1709,
14,
3190,
8,
36,
11554,
9,
272,
3721,
63,
991,
275,
1709,
14,
3190,
8,
1899,
9,
272,
3721,
275,
1709,
14,
6254,
342,
272,
7143,
63,
602,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
pyzaba/pyzaba
|
lib/requests/packages/urllib3/exceptions.py
|
374
|
3274
|
# urllib3/exceptions.py
# Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
#
# This module is part of urllib3 and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
## Base Exceptions
class HTTPError(Exception):
"Base exception used by this module."
pass
class PoolError(HTTPError):
"Base exception for errors caused within a pool."
def __init__(self, pool, message):
self.pool = pool
HTTPError.__init__(self, "%s: %s" % (pool, message))
def __reduce__(self):
# For pickling purposes.
return self.__class__, (None, None)
class RequestError(PoolError):
"Base exception for PoolErrors that have associated URLs."
def __init__(self, pool, url, message):
self.url = url
PoolError.__init__(self, pool, message)
def __reduce__(self):
# For pickling purposes.
return self.__class__, (None, self.url, None)
class SSLError(HTTPError):
"Raised when SSL certificate fails in an HTTPS connection."
pass
class ProxyError(HTTPError):
"Raised when the connection to a proxy fails."
pass
class DecodeError(HTTPError):
"Raised when automatic decoding based on Content-Type fails."
pass
## Leaf Exceptions
class MaxRetryError(RequestError):
"Raised when the maximum number of retries is exceeded."
def __init__(self, pool, url, reason=None):
self.reason = reason
message = "Max retries exceeded with url: %s" % url
if reason:
message += " (Caused by %s: %s)" % (type(reason), reason)
else:
message += " (Caused by redirect)"
RequestError.__init__(self, pool, url, message)
class HostChangedError(RequestError):
"Raised when an existing pool gets a request for a foreign host."
def __init__(self, pool, url, retries=3):
message = "Tried to open a foreign host with url: %s" % url
RequestError.__init__(self, pool, url, message)
self.retries = retries
class TimeoutStateError(HTTPError):
""" Raised when passing an invalid state to a timeout """
pass
class TimeoutError(HTTPError):
""" Raised when a socket timeout error occurs.
Catching this error will catch both :exc:`ReadTimeoutErrors
<ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.
"""
pass
class ReadTimeoutError(TimeoutError, RequestError):
"Raised when a socket timeout occurs while receiving data from a server"
pass
# This timeout error does not have a URL attached and needs to inherit from the
# base HTTPError
class ConnectTimeoutError(TimeoutError):
"Raised when a socket timeout occurs while connecting to a server"
pass
class EmptyPoolError(PoolError):
"Raised when a pool runs out of connections and no more are allowed."
pass
class ClosedPoolError(PoolError):
"Raised when a request enters a pool after the pool has been closed."
pass
class LocationParseError(ValueError, HTTPError):
"Raised when get_host or similar fails to parse the URL input."
def __init__(self, location):
message = "Failed to parse: %s" % location
HTTPError.__init__(self, message)
self.location = location
|
bsd-3-clause
|
[
3,
4011,
19,
15,
3924,
14,
647,
199,
3,
1898,
9079,
13,
6965,
6061,
17885,
31449,
293,
86,
436,
8417,
334,
3239,
6483,
14,
2424,
9,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
4011,
19,
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,
421,
199,
309,
3523,
24873,
199,
199,
533,
15050,
8,
1726,
304,
272,
298,
1563,
1919,
1202,
701,
642,
859,
2122,
272,
986,
421,
199,
533,
15553,
547,
8,
12815,
304,
272,
298,
1563,
1919,
367,
2552,
18104,
4453,
282,
4203,
2122,
272,
347,
636,
826,
721,
277,
12,
4203,
12,
1245,
304,
267,
291,
14,
2293,
275,
4203,
267,
15050,
855,
826,
721,
277,
12,
2071,
83,
26,
450,
83,
2,
450,
334,
2293,
12,
1245,
430,
339,
347,
636,
5270,
721,
277,
304,
267,
327,
2104,
24394,
12901,
14,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
488,
9,
421,
199,
533,
4784,
547,
8,
5453,
547,
304,
272,
298,
1563,
1919,
367,
15553,
9298,
626,
1172,
4568,
10867,
2122,
272,
347,
636,
826,
721,
277,
12,
4203,
12,
1166,
12,
1245,
304,
267,
291,
14,
633,
275,
1166,
267,
15553,
547,
855,
826,
721,
277,
12,
4203,
12,
1245,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
327,
2104,
24394,
12901,
14,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
633,
12,
488,
9,
421,
199,
533,
7799,
547,
8,
12815,
304,
272,
298,
16894,
1380,
7799,
5897,
6918,
315,
376,
14147,
1950,
2122,
272,
986,
421,
199,
533,
12373,
547,
8,
12815,
304,
272,
298,
16894,
1380,
314,
1950,
370,
282,
4566,
6918,
2122,
272,
986,
421,
199,
533,
22462,
547,
8,
12815,
304,
272,
298,
16894,
1380,
4834,
15952,
4079,
641,
6646,
13,
804,
6918,
2122,
272,
986,
421,
199,
309,
27836,
24873,
199,
199,
533,
8228,
12989,
547,
8,
19261,
304,
272,
298,
16894,
1380,
314,
5696,
1329,
402,
10086,
365,
22007,
2122,
339,
347,
636,
826,
721,
277,
12,
4203,
12,
1166,
12,
4499,
29,
403,
304,
267,
291,
14,
5764,
275,
4499,
398,
1245,
275,
298,
4261,
10086,
22007,
543,
1166,
26,
450,
83,
2,
450,
1166,
267,
340,
4499,
26,
288,
1245,
847,
298,
334,
3630,
2972,
701,
450,
83,
26,
450,
83,
2924,
450,
334,
466,
8,
5764,
395,
4499,
9,
267,
587,
26,
288,
1245,
847,
298,
334,
3630,
2972,
701,
4660,
2924,
398,
4784,
547,
855,
826,
721,
277,
12,
4203,
12,
1166,
12,
1245,
9,
421,
199,
533,
10891,
6970,
547,
8,
19261,
304,
272,
298,
16894,
1380,
376,
3411,
4203,
7545,
282,
1056,
367,
282,
11608,
1591,
2122,
339,
347,
636,
826,
721,
277,
12,
4203,
12,
1166,
12,
10086,
29,
19,
304,
267,
1245,
275,
298,
6948,
379,
370,
1551,
282,
11608,
1591,
543,
1166,
26,
450,
83,
2,
450,
1166,
267,
4784,
547,
855,
826,
721,
277,
12,
4203,
12,
1166,
12,
1245,
9,
267,
291,
14,
10937,
275,
10086,
421,
199,
533,
12878,
2223,
547,
8,
12815,
304,
272,
408,
24997,
1380,
9476,
376,
3866,
1174,
370,
282,
2653,
408,
272,
986,
421,
199,
533,
31886,
8,
12815,
304,
272,
408,
24997,
1380,
282,
2838,
2653,
1125,
11058,
14,
339,
32754,
316,
642,
1125,
911,
8579,
3865,
520,
2804,
1705,
3284,
6372,
9298,
272,
665,
3284,
19382,
8637,
436,
520,
2804,
1705,
8631,
6372,
9298,
665,
8631,
19382,
14943,
272,
408,
272,
986,
421,
199,
533,
5574,
19382,
8,
19382,
12,
4784,
547,
304,
272,
298,
16894,
1380,
282,
2838,
2653,
11058,
1830,
18390,
666,
687,
282,
1654,
2,
272,
986,
421,
199,
3,
961,
2653,
1125,
1630,
440,
1172,
282,
2851,
10102,
436,
4839,
370,
8287,
687,
314,
199,
3,
1300,
15050,
199,
533,
15175,
19382,
8,
19382,
304,
272,
298,
16894,
1380,
282,
2838,
2653,
11058,
1830,
18170,
370,
282,
1654,
2,
272,
986,
421,
199,
533,
9630,
5453,
547,
8,
5453,
547,
304,
272,
298,
16894,
1380,
282,
4203,
7858,
734,
402,
6947,
436,
949,
1655,
787,
4370,
2122,
272,
986,
421,
199,
533,
5980,
939,
5453,
547,
8,
5453,
547,
304,
272,
298,
16894,
1380,
282,
1056,
655,
878,
282,
4203,
2410,
314,
4203,
965,
2757,
6876,
2122,
272,
986,
421,
199,
533,
12625,
9123,
8,
3393,
12,
15050,
304,
272,
298,
16894,
1380,
664,
63,
1102,
503,
8545,
6918,
370,
2198,
314,
2851,
1324,
2122,
339,
347,
636,
826,
721,
277,
12,
2909,
304,
267,
1245,
275,
298,
4276,
370,
2198,
26,
450,
83,
2,
450,
2909,
267,
15050,
855,
826,
721,
277,
12,
1245,
9,
398,
291,
14,
1985,
275,
2909,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4011,
19,
15,
3924,
14,
647,
199,
3,
1898,
9079,
13,
6965,
6061,
17885,
31449,
293,
86,
436,
8417,
334,
3239,
6483,
14,
2424,
9,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
4011,
19,
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,
421,
199,
309,
3523,
24873,
199,
199,
533,
15050,
8,
1726,
304,
272,
298,
1563,
1919,
1202,
701,
642,
859,
2122,
272,
986,
421,
199,
533,
15553,
547,
8,
12815,
304,
272,
298,
1563,
1919,
367,
2552,
18104,
4453,
282,
4203,
2122,
272,
347,
636,
826,
721,
277,
12,
4203,
12,
1245,
304,
267,
291,
14,
2293,
275,
4203,
267,
15050,
855,
826,
721,
277,
12,
2071,
83,
26,
450,
83,
2,
450,
334,
2293,
12,
1245,
430,
339,
347,
636,
5270,
721,
277,
304,
267,
327,
2104,
24394,
12901,
14,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
488,
9,
421,
199,
533,
4784,
547,
8,
5453,
547,
304,
272,
298,
1563,
1919,
367,
15553,
9298,
626,
1172,
4568,
10867,
2122,
272,
347,
636,
826,
721,
277,
12,
4203,
12,
1166,
12,
1245,
304,
267,
291,
14,
633,
275,
1166,
267,
15553,
547,
855,
826,
721,
277,
12,
4203,
12,
1245,
9,
339,
347,
636,
5270,
721,
277,
304,
267,
327,
2104,
24394,
12901,
14,
267,
372,
291,
855,
533,
3108,
334,
403,
12,
291,
14,
633,
12,
488,
9,
421,
199,
533,
7799,
547,
8,
12815,
304,
272,
298,
16894,
1380,
7799,
5897,
6918,
315,
376,
14147,
1950,
2122,
272,
986,
421,
199,
533,
12373,
547,
8,
12815,
304,
272,
298,
16894,
1380,
314,
1950,
370,
282,
4566,
6918,
2122,
272,
986,
421,
199,
533,
22462,
547,
8,
12815,
304,
272,
298,
16894,
1380,
4834,
15952,
4079,
641,
6646,
13,
804,
6918,
2122,
272,
986,
421,
199,
309,
27836,
24873,
199,
199,
533,
8228,
12989,
547,
8,
19261,
304,
272,
298,
16894,
1380,
314,
5696,
1329,
402,
10086,
365,
22007,
2122,
339,
347,
636,
826,
721,
277,
12,
4203,
12,
1166,
12,
4499,
29,
403,
304,
267,
291,
14,
5764,
275,
4499,
398,
1245,
275,
298,
4261,
10086,
22007,
543,
1166,
26,
450,
83,
2,
450,
1166,
267,
340,
4499,
26,
288,
1245,
847,
298,
334,
3630,
2972,
701,
450,
83,
26,
450,
83,
2924,
450,
334,
466,
8,
5764,
395,
4499,
9,
267,
587,
26,
288,
1245,
847,
298,
334,
3630,
2972,
701,
4660,
2924,
398,
4784,
547,
855,
826,
721,
277,
12,
4203,
12,
1166,
12,
1245,
9,
421,
199,
533,
10891,
6970,
547,
8,
19261,
304,
272,
298,
16894,
1380,
376,
3411,
4203,
7545,
282,
1056,
367,
282,
11608,
1591,
2122,
339,
347,
636,
826,
721,
277,
12,
4203,
12,
1166,
12,
10086,
29,
19,
304,
267,
1245,
275,
298,
6948,
379,
370,
1551,
282,
11608,
1591,
543,
1166,
26,
450,
83,
2,
450,
1166,
267,
4784,
547,
855,
826,
721,
277,
12,
4203,
12,
1166,
12,
1245,
9,
267,
291,
14,
10937,
275,
10086,
421,
199,
533,
12878,
2223,
547,
8,
12815,
304,
272,
408,
24997,
1380,
9476,
376,
3866,
1174,
370,
282,
2653,
408,
272,
986,
421,
199,
533,
31886,
8,
12815,
304,
272,
408,
24997,
1380,
282,
2838,
2653,
1125,
11058,
14,
339,
32754,
316,
642,
1125,
911,
8579,
3865,
520,
2804,
1705,
3284,
6372,
9298,
272,
665,
3284,
19382,
8637,
436,
520,
2804,
1705,
8631,
6372,
9298,
665,
8631,
19382,
14943,
272,
408,
272,
986,
421,
199,
533,
5574,
19382,
8,
19382,
12,
4784,
547,
304,
272,
298,
16894,
1380,
282,
2838,
2653,
11058,
1830,
18390,
666,
687,
282,
1654,
2,
272,
986,
421,
199,
3,
961,
2653,
1125,
1630,
440,
1172,
282,
2851,
10102,
436,
4839,
370,
8287,
687,
314,
199,
3,
1300,
15050,
199,
533,
15175,
19382,
8,
19382,
304,
272,
298,
16894,
1380,
282,
2838,
2653,
11058,
1830,
18170,
370,
282,
1654,
2,
272,
986,
421,
199,
533,
9630,
5453,
547,
8,
5453,
547,
304,
272,
298,
16894,
1380,
282,
4203,
7858,
734,
402,
6947,
436,
949,
1655,
787,
4370,
2122,
272,
986,
421,
199,
533,
5980,
939,
5453,
547,
8,
5453,
547,
304,
272,
298,
16894,
1380,
282,
1056,
655,
878,
282,
4203,
2410,
314,
4203,
965,
2757,
6876,
2122,
272,
986,
421,
199,
533,
12625,
9123,
8,
3393,
12,
15050,
304,
272,
298,
16894,
1380,
664,
63,
1102,
503,
8545,
6918,
370,
2198,
314,
2851,
1324,
2122,
339,
347,
636,
826,
721,
277,
12,
2909,
304,
267,
1245,
275,
298,
4276,
370,
2198,
26,
450,
83,
2,
450,
2909,
267,
15050,
855,
826,
721,
277,
12,
1245,
9,
398,
291,
14,
1985,
275,
2909,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
domeger/SplunkTAforPuppetEnterprise
|
bin/splunktaforpuppetenterprise/requests/exceptions.py
|
155
|
2976
|
# -*- coding: utf-8 -*-
"""
requests.exceptions
~~~~~~~~~~~~~~~~~~~
This module contains the set of Requests' exceptions.
"""
from .packages.urllib3.exceptions import HTTPError as BaseHTTPError
class RequestException(IOError):
"""There was an ambiguous exception that occurred while handling your
request.
"""
def __init__(self, *args, **kwargs):
"""Initialize RequestException with `request` and `response` objects."""
response = kwargs.pop('response', None)
self.response = response
self.request = kwargs.pop('request', None)
if (response is not None and not self.request and
hasattr(response, 'request')):
self.request = self.response.request
super(RequestException, self).__init__(*args, **kwargs)
class HTTPError(RequestException):
"""An HTTP error occurred."""
class ConnectionError(RequestException):
"""A Connection error occurred."""
class ProxyError(ConnectionError):
"""A proxy error occurred."""
class SSLError(ConnectionError):
"""An SSL error occurred."""
class Timeout(RequestException):
"""The request timed out.
Catching this error will catch both
:exc:`~requests.exceptions.ConnectTimeout` and
:exc:`~requests.exceptions.ReadTimeout` errors.
"""
class ConnectTimeout(ConnectionError, Timeout):
"""The request timed out while trying to connect to the remote server.
Requests that produced this error are safe to retry.
"""
class ReadTimeout(Timeout):
"""The server did not send any data in the allotted amount of time."""
class URLRequired(RequestException):
"""A valid URL is required to make a request."""
class TooManyRedirects(RequestException):
"""Too many redirects."""
class MissingSchema(RequestException, ValueError):
"""The URL schema (e.g. http or https) is missing."""
class InvalidSchema(RequestException, ValueError):
"""See defaults.py for valid schemas."""
class InvalidURL(RequestException, ValueError):
"""The URL provided was somehow invalid."""
class InvalidHeader(RequestException, ValueError):
"""The header value provided was somehow invalid."""
class ChunkedEncodingError(RequestException):
"""The server declared chunked encoding but sent an invalid chunk."""
class ContentDecodingError(RequestException, BaseHTTPError):
"""Failed to decode response content"""
class StreamConsumedError(RequestException, TypeError):
"""The content for this response was already consumed"""
class RetryError(RequestException):
"""Custom retries logic failed"""
class UnrewindableBodyError(RequestException):
"""Requests encountered an error when trying to rewind a body"""
# Warnings
class RequestsWarning(Warning):
"""Base warning for Requests."""
pass
class FileModeWarning(RequestsWarning, DeprecationWarning):
"""A file was opened in text mode, but Requests determined its binary length."""
pass
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
6615,
14,
3924,
199,
9753,
23597,
199,
199,
2765,
859,
3509,
314,
663,
402,
20260,
7,
4967,
14,
199,
624,
199,
504,
1275,
5154,
14,
4078,
19,
14,
3924,
492,
15050,
465,
3523,
12815,
421,
199,
533,
4784,
1726,
8,
13760,
304,
272,
408,
10924,
1990,
376,
26711,
1919,
626,
8920,
1830,
7252,
2195,
272,
1056,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9345,
4784,
1726,
543,
658,
1069,
64,
436,
658,
1310,
64,
2251,
1041,
267,
1177,
275,
2074,
14,
1935,
360,
1310,
297,
488,
9,
267,
291,
14,
1310,
275,
1177,
267,
291,
14,
1069,
275,
2074,
14,
1935,
360,
1069,
297,
488,
9,
267,
340,
334,
1310,
365,
440,
488,
436,
440,
291,
14,
1069,
436,
355,
2688,
8,
1310,
12,
283,
1069,
8109,
288,
291,
14,
1069,
275,
291,
14,
1310,
14,
1069,
267,
1613,
8,
28724,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
421,
199,
533,
15050,
8,
28724,
304,
272,
408,
2493,
3101,
1125,
8920,
1041,
421,
199,
533,
25417,
8,
28724,
304,
272,
408,
33,
8113,
1125,
8920,
1041,
421,
199,
533,
12373,
547,
8,
20349,
304,
272,
408,
33,
4566,
1125,
8920,
1041,
421,
199,
533,
7799,
547,
8,
20349,
304,
272,
408,
2493,
7799,
1125,
8920,
1041,
421,
199,
533,
12878,
8,
28724,
304,
272,
408,
1918,
1056,
18590,
734,
14,
339,
32754,
316,
642,
1125,
911,
8579,
3865,
272,
520,
2804,
6054,
6615,
14,
3924,
14,
8631,
6372,
64,
436,
272,
520,
2804,
6054,
6615,
14,
3924,
14,
3284,
6372,
64,
2552,
14,
272,
408,
421,
199,
533,
15175,
6372,
8,
20349,
12,
12878,
304,
272,
408,
1918,
1056,
18590,
734,
1830,
9936,
370,
4907,
370,
314,
3982,
1654,
14,
339,
20260,
626,
13584,
642,
1125,
787,
5048,
370,
7269,
14,
272,
408,
421,
199,
533,
5574,
6372,
8,
6372,
304,
272,
408,
1918,
1654,
8103,
440,
3222,
1263,
666,
315,
314,
741,
1653,
471,
5982,
402,
900,
1041,
421,
199,
533,
2851,
8030,
8,
28724,
304,
272,
408,
33,
1686,
2851,
365,
1415,
370,
1852,
282,
1056,
1041,
421,
199,
533,
22893,
4089,
16032,
8,
28724,
304,
272,
408,
13749,
5002,
17784,
1041,
421,
199,
533,
15626,
6700,
8,
28724,
12,
1722,
304,
272,
408,
1918,
2851,
4177,
334,
69,
14,
71,
14,
1455,
503,
4178,
9,
365,
4124,
1041,
421,
199,
533,
6378,
6700,
8,
28724,
12,
1722,
304,
272,
408,
9295,
4243,
14,
647,
367,
1686,
32536,
1041,
421,
199,
533,
6378,
2632,
8,
28724,
12,
1722,
304,
272,
408,
1918,
2851,
2741,
1990,
29437,
3866,
1041,
421,
199,
533,
6378,
2567,
8,
28724,
12,
1722,
304,
272,
408,
1918,
1406,
574,
2741,
1990,
29437,
3866,
1041,
421,
199,
533,
25246,
379,
7630,
547,
8,
28724,
304,
272,
408,
1918,
1654,
14290,
22180,
2644,
1325,
4847,
376,
3866,
3728,
1041,
421,
199,
533,
6646,
872,
1523,
547,
8,
28724,
12,
3523,
12815,
304,
272,
408,
4276,
370,
4849,
1177,
1564,
624,
421,
199,
533,
8271,
21042,
68,
547,
8,
28724,
12,
3146,
304,
272,
408,
1918,
1564,
367,
642,
1177,
1990,
2575,
16949,
624,
421,
199,
533,
20506,
547,
8,
28724,
304,
272,
408,
7223,
10086,
9661,
3405,
624,
199,
199,
533,
1910,
5257,
688,
461,
8173,
547,
8,
28724,
304,
272,
408,
16272,
14556,
376,
1125,
1380,
9936,
370,
295,
11530,
282,
2396,
624,
199,
199,
3,
644,
2627,
421,
199,
533,
20260,
3849,
8,
3849,
304,
272,
408,
1563,
5721,
367,
20260,
1041,
272,
986,
421,
199,
533,
3814,
1385,
3849,
8,
16272,
3849,
12,
13413,
304,
272,
408,
33,
570,
1990,
12123,
315,
1318,
818,
12,
1325,
20260,
12037,
2399,
3366,
2582,
1041,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
6615,
14,
3924,
199,
9753,
23597,
199,
199,
2765,
859,
3509,
314,
663,
402,
20260,
7,
4967,
14,
199,
624,
199,
504,
1275,
5154,
14,
4078,
19,
14,
3924,
492,
15050,
465,
3523,
12815,
421,
199,
533,
4784,
1726,
8,
13760,
304,
272,
408,
10924,
1990,
376,
26711,
1919,
626,
8920,
1830,
7252,
2195,
272,
1056,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9345,
4784,
1726,
543,
658,
1069,
64,
436,
658,
1310,
64,
2251,
1041,
267,
1177,
275,
2074,
14,
1935,
360,
1310,
297,
488,
9,
267,
291,
14,
1310,
275,
1177,
267,
291,
14,
1069,
275,
2074,
14,
1935,
360,
1069,
297,
488,
9,
267,
340,
334,
1310,
365,
440,
488,
436,
440,
291,
14,
1069,
436,
355,
2688,
8,
1310,
12,
283,
1069,
8109,
288,
291,
14,
1069,
275,
291,
14,
1310,
14,
1069,
267,
1613,
8,
28724,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
421,
199,
533,
15050,
8,
28724,
304,
272,
408,
2493,
3101,
1125,
8920,
1041,
421,
199,
533,
25417,
8,
28724,
304,
272,
408,
33,
8113,
1125,
8920,
1041,
421,
199,
533,
12373,
547,
8,
20349,
304,
272,
408,
33,
4566,
1125,
8920,
1041,
421,
199,
533,
7799,
547,
8,
20349,
304,
272,
408,
2493,
7799,
1125,
8920,
1041,
421,
199,
533,
12878,
8,
28724,
304,
272,
408,
1918,
1056,
18590,
734,
14,
339,
32754,
316,
642,
1125,
911,
8579,
3865,
272,
520,
2804,
6054,
6615,
14,
3924,
14,
8631,
6372,
64,
436,
272,
520,
2804,
6054,
6615,
14,
3924,
14,
3284,
6372,
64,
2552,
14,
272,
408,
421,
199,
533,
15175,
6372,
8,
20349,
12,
12878,
304,
272,
408,
1918,
1056,
18590,
734,
1830,
9936,
370,
4907,
370,
314,
3982,
1654,
14,
339,
20260,
626,
13584,
642,
1125,
787,
5048,
370,
7269,
14,
272,
408,
421,
199,
533,
5574,
6372,
8,
6372,
304,
272,
408,
1918,
1654,
8103,
440,
3222,
1263,
666,
315,
314,
741,
1653,
471,
5982,
402,
900,
1041,
421,
199,
533,
2851,
8030,
8,
28724,
304,
272,
408,
33,
1686,
2851,
365,
1415,
370,
1852,
282,
1056,
1041,
421,
199,
533,
22893,
4089,
16032,
8,
28724,
304,
272,
408,
13749,
5002,
17784,
1041,
421,
199,
533,
15626,
6700,
8,
28724,
12,
1722,
304,
272,
408,
1918,
2851,
4177,
334,
69,
14,
71,
14,
1455,
503,
4178,
9,
365,
4124,
1041,
421,
199,
533,
6378,
6700,
8,
28724,
12,
1722,
304,
272,
408,
9295,
4243,
14,
647,
367,
1686,
32536,
1041,
421,
199,
533,
6378,
2632,
8,
28724,
12,
1722,
304,
272,
408,
1918,
2851,
2741,
1990,
29437,
3866,
1041,
421,
199,
533,
6378,
2567,
8,
28724,
12,
1722,
304,
272,
408,
1918,
1406,
574,
2741,
1990,
29437,
3866,
1041,
421,
199,
533,
25246,
379,
7630,
547,
8,
28724,
304,
272,
408,
1918,
1654,
14290,
22180,
2644,
1325,
4847,
376,
3866,
3728,
1041,
421,
199,
533,
6646,
872,
1523,
547,
8,
28724,
12,
3523,
12815,
304,
272,
408,
4276,
370,
4849,
1177,
1564,
624,
421,
199,
533,
8271,
21042,
68,
547,
8,
28724,
12,
3146,
304,
272,
408,
1918,
1564,
367,
642,
1177,
1990,
2575,
16949,
624,
421,
199,
533,
20506,
547,
8,
28724,
304,
272,
408,
7223,
10086,
9661,
3405,
624,
199,
199,
533,
1910,
5257,
688,
461,
8173,
547,
8,
28724,
304,
272,
408,
16272,
14556,
376,
1125,
1380,
9936,
370,
295,
11530,
282,
2396,
624,
199,
199,
3,
644,
2627,
421,
199,
533,
20260,
3849,
8,
3849,
304,
272,
408,
1563,
5721,
367,
20260,
1041,
272,
986,
421,
199,
533,
3814,
1385,
3849,
8,
16272,
3849,
12,
13413,
304,
272,
408,
33,
570,
1990,
12123,
315,
1318,
818,
12,
1325,
20260,
12037,
2399,
3366,
2582,
1041,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
moreati/django
|
django/http/multipartparser.py
|
332
|
24331
|
"""
Multi-part parsing for file uploads.
Exposes one class, ``MultiPartParser``, which feeds chunks of uploaded data to
file upload handlers for processing.
"""
from __future__ import unicode_literals
import base64
import binascii
import cgi
import sys
from django.conf import settings
from django.core.exceptions import SuspiciousMultipartForm
from django.core.files.uploadhandler import (
SkipFile, StopFutureHandlers, StopUpload,
)
from django.utils import six
from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_text
from django.utils.six.moves.urllib.parse import unquote
from django.utils.text import unescape_entities
__all__ = ('MultiPartParser', 'MultiPartParserError', 'InputStreamExhausted')
class MultiPartParserError(Exception):
pass
class InputStreamExhausted(Exception):
"""
No more reads are allowed from this device.
"""
pass
RAW = "raw"
FILE = "file"
FIELD = "field"
_BASE64_DECODE_ERROR = TypeError if six.PY2 else binascii.Error
class MultiPartParser(object):
"""
A rfc2388 multipart/form-data parser.
``MultiValueDict.parse()`` reads the input stream in ``chunk_size`` chunks
and returns a tuple of ``(MultiValueDict(POST), MultiValueDict(FILES))``.
"""
def __init__(self, META, input_data, upload_handlers, encoding=None):
"""
Initialize the MultiPartParser object.
:META:
The standard ``META`` dictionary in Django request objects.
:input_data:
The raw post data, as a file-like object.
:upload_handlers:
A list of UploadHandler instances that perform operations on the uploaded
data.
:encoding:
The encoding with which to treat the incoming data.
"""
#
# Content-Type should contain multipart and the boundary information.
#
content_type = META.get('HTTP_CONTENT_TYPE', META.get('CONTENT_TYPE', ''))
if not content_type.startswith('multipart/'):
raise MultiPartParserError('Invalid Content-Type: %s' % content_type)
# Parse the header to get the boundary to split the parts.
ctypes, opts = parse_header(content_type.encode('ascii'))
boundary = opts.get('boundary')
if not boundary or not cgi.valid_boundary(boundary):
raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
# Content-Length should contain the length of the body we are about
# to receive.
try:
content_length = int(META.get('HTTP_CONTENT_LENGTH', META.get('CONTENT_LENGTH', 0)))
except (ValueError, TypeError):
content_length = 0
if content_length < 0:
# This means we shouldn't continue...raise an error.
raise MultiPartParserError("Invalid content length: %r" % content_length)
if isinstance(boundary, six.text_type):
boundary = boundary.encode('ascii')
self._boundary = boundary
self._input_data = input_data
# For compatibility with low-level network APIs (with 32-bit integers),
# the chunk size should be < 2^31, but still divisible by 4.
possible_sizes = [x.chunk_size for x in upload_handlers if x.chunk_size]
self._chunk_size = min([2 ** 31 - 4] + possible_sizes)
self._meta = META
self._encoding = encoding or settings.DEFAULT_CHARSET
self._content_length = content_length
self._upload_handlers = upload_handlers
def parse(self):
"""
Parse the POST data and break it into a FILES MultiValueDict and a POST
MultiValueDict.
Returns a tuple containing the POST and FILES dictionary, respectively.
"""
# We have to import QueryDict down here to avoid a circular import.
from django.http import QueryDict
encoding = self._encoding
handlers = self._upload_handlers
# HTTP spec says that Content-Length >= 0 is valid
# handling content-length == 0 before continuing
if self._content_length == 0:
return QueryDict('', encoding=self._encoding), MultiValueDict()
# See if any of the handlers take care of the parsing.
# This allows overriding everything if need be.
for handler in handlers:
result = handler.handle_raw_input(self._input_data,
self._meta,
self._content_length,
self._boundary,
encoding)
# Check to see if it was handled
if result is not None:
return result[0], result[1]
# Create the data structures to be used later.
self._post = QueryDict('', mutable=True)
self._files = MultiValueDict()
# Instantiate the parser and stream:
stream = LazyStream(ChunkIter(self._input_data, self._chunk_size))
# Whether or not to signal a file-completion at the beginning of the loop.
old_field_name = None
counters = [0] * len(handlers)
try:
for item_type, meta_data, field_stream in Parser(stream, self._boundary):
if old_field_name:
# We run this at the beginning of the next loop
# since we cannot be sure a file is complete until
# we hit the next boundary/part of the multipart content.
self.handle_file_complete(old_field_name, counters)
old_field_name = None
try:
disposition = meta_data['content-disposition'][1]
field_name = disposition['name'].strip()
except (KeyError, IndexError, AttributeError):
continue
transfer_encoding = meta_data.get('content-transfer-encoding')
if transfer_encoding is not None:
transfer_encoding = transfer_encoding[0].strip()
field_name = force_text(field_name, encoding, errors='replace')
if item_type == FIELD:
# This is a post field, we can just set it in the post
if transfer_encoding == 'base64':
raw_data = field_stream.read()
try:
data = base64.b64decode(raw_data)
except _BASE64_DECODE_ERROR:
data = raw_data
else:
data = field_stream.read()
self._post.appendlist(field_name,
force_text(data, encoding, errors='replace'))
elif item_type == FILE:
# This is a file, use the handler...
file_name = disposition.get('filename')
if not file_name:
continue
file_name = force_text(file_name, encoding, errors='replace')
file_name = self.IE_sanitize(unescape_entities(file_name))
content_type, content_type_extra = meta_data.get('content-type', ('', {}))
content_type = content_type.strip()
charset = content_type_extra.get('charset')
try:
content_length = int(meta_data.get('content-length')[0])
except (IndexError, TypeError, ValueError):
content_length = None
counters = [0] * len(handlers)
try:
for handler in handlers:
try:
handler.new_file(field_name, file_name,
content_type, content_length,
charset, content_type_extra)
except StopFutureHandlers:
break
for chunk in field_stream:
if transfer_encoding == 'base64':
# We only special-case base64 transfer encoding
# We should always decode base64 chunks by multiple of 4,
# ignoring whitespace.
stripped_chunk = b"".join(chunk.split())
remaining = len(stripped_chunk) % 4
while remaining != 0:
over_chunk = field_stream.read(4 - remaining)
stripped_chunk += b"".join(over_chunk.split())
remaining = len(stripped_chunk) % 4
try:
chunk = base64.b64decode(stripped_chunk)
except Exception as e:
# Since this is only a chunk, any error is an unfixable error.
msg = "Could not decode base64 data: %r" % e
six.reraise(MultiPartParserError, MultiPartParserError(msg), sys.exc_info()[2])
for i, handler in enumerate(handlers):
chunk_length = len(chunk)
chunk = handler.receive_data_chunk(chunk,
counters[i])
counters[i] += chunk_length
if chunk is None:
# If the chunk received by the handler is None, then don't continue.
break
except SkipFile:
self._close_files()
# Just use up the rest of this file...
exhaust(field_stream)
else:
# Handle file upload completions on next iteration.
old_field_name = field_name
else:
# If this is neither a FIELD or a FILE, just exhaust the stream.
exhaust(stream)
except StopUpload as e:
self._close_files()
if not e.connection_reset:
exhaust(self._input_data)
else:
# Make sure that the request data is all fed
exhaust(self._input_data)
# Signal that the upload has completed.
for handler in handlers:
retval = handler.upload_complete()
if retval:
break
return self._post, self._files
def handle_file_complete(self, old_field_name, counters):
"""
Handle all the signaling that takes place when a file is complete.
"""
for i, handler in enumerate(self._upload_handlers):
file_obj = handler.file_complete(counters[i])
if file_obj:
# If it returns a file object, then set the files dict.
self._files.appendlist(
force_text(old_field_name, self._encoding, errors='replace'),
file_obj)
break
def IE_sanitize(self, filename):
"""Cleanup filename from Internet Explorer full paths."""
return filename and filename[filename.rfind("\\") + 1:].strip()
def _close_files(self):
# Free up all file handles.
# FIXME: this currently assumes that upload handlers store the file as 'file'
# We should document that... (Maybe add handler.free_file to complement new_file)
for handler in self._upload_handlers:
if hasattr(handler, 'file'):
handler.file.close()
class LazyStream(six.Iterator):
"""
The LazyStream wrapper allows one to get and "unget" bytes from a stream.
Given a producer object (an iterator that yields bytestrings), the
LazyStream object will support iteration, reading, and keeping a "look-back"
variable in case you need to "unget" some bytes.
"""
def __init__(self, producer, length=None):
"""
Every LazyStream must have a producer when instantiated.
A producer is an iterable that returns a string each time it
is called.
"""
self._producer = producer
self._empty = False
self._leftover = b''
self.length = length
self.position = 0
self._remaining = length
self._unget_history = []
def tell(self):
return self.position
def read(self, size=None):
def parts():
remaining = self._remaining if size is None else size
# do the whole thing in one shot if no limit was provided.
if remaining is None:
yield b''.join(self)
return
# otherwise do some bookkeeping to return exactly enough
# of the stream and stashing any extra content we get from
# the producer
while remaining != 0:
assert remaining > 0, 'remaining bytes to read should never go negative'
try:
chunk = next(self)
except StopIteration:
return
else:
emitting = chunk[:remaining]
self.unget(chunk[remaining:])
remaining -= len(emitting)
yield emitting
out = b''.join(parts())
return out
def __next__(self):
"""
Used when the exact number of bytes to read is unimportant.
This procedure just returns whatever is chunk is conveniently returned
from the iterator instead. Useful to avoid unnecessary bookkeeping if
performance is an issue.
"""
if self._leftover:
output = self._leftover
self._leftover = b''
else:
output = next(self._producer)
self._unget_history = []
self.position += len(output)
return output
def close(self):
"""
Used to invalidate/disable this lazy stream.
Replaces the producer with an empty list. Any leftover bytes that have
already been read will still be reported upon read() and/or next().
"""
self._producer = []
def __iter__(self):
return self
def unget(self, bytes):
"""
Places bytes back onto the front of the lazy stream.
Future calls to read() will return those bytes first. The
stream position and thus tell() will be rewound.
"""
if not bytes:
return
self._update_unget_history(len(bytes))
self.position -= len(bytes)
self._leftover = b''.join([bytes, self._leftover])
def _update_unget_history(self, num_bytes):
"""
Updates the unget history as a sanity check to see if we've pushed
back the same number of bytes in one chunk. If we keep ungetting the
same number of bytes many times (here, 50), we're mostly likely in an
infinite loop of some sort. This is usually caused by a
maliciously-malformed MIME request.
"""
self._unget_history = [num_bytes] + self._unget_history[:49]
number_equal = len([current_number for current_number in self._unget_history
if current_number == num_bytes])
if number_equal > 40:
raise SuspiciousMultipartForm(
"The multipart parser got stuck, which shouldn't happen with"
" normal uploaded files. Check for malicious upload activity;"
" if there is none, report this to the Django developers."
)
class ChunkIter(six.Iterator):
"""
An iterable that will yield chunks of data. Given a file-like object as the
constructor, this object will yield chunks of read operations from that
object.
"""
def __init__(self, flo, chunk_size=64 * 1024):
self.flo = flo
self.chunk_size = chunk_size
def __next__(self):
try:
data = self.flo.read(self.chunk_size)
except InputStreamExhausted:
raise StopIteration()
if data:
return data
else:
raise StopIteration()
def __iter__(self):
return self
class InterBoundaryIter(six.Iterator):
"""
A Producer that will iterate over boundaries.
"""
def __init__(self, stream, boundary):
self._stream = stream
self._boundary = boundary
def __iter__(self):
return self
def __next__(self):
try:
return LazyStream(BoundaryIter(self._stream, self._boundary))
except InputStreamExhausted:
raise StopIteration()
class BoundaryIter(six.Iterator):
"""
A Producer that is sensitive to boundaries.
Will happily yield bytes until a boundary is found. Will yield the bytes
before the boundary, throw away the boundary bytes themselves, and push the
post-boundary bytes back on the stream.
The future calls to next() after locating the boundary will raise a
StopIteration exception.
"""
def __init__(self, stream, boundary):
self._stream = stream
self._boundary = boundary
self._done = False
# rollback an additional six bytes because the format is like
# this: CRLF<boundary>[--CRLF]
self._rollback = len(boundary) + 6
# Try to use mx fast string search if available. Otherwise
# use Python find. Wrap the latter for consistency.
unused_char = self._stream.read(1)
if not unused_char:
raise InputStreamExhausted()
self._stream.unget(unused_char)
def __iter__(self):
return self
def __next__(self):
if self._done:
raise StopIteration()
stream = self._stream
rollback = self._rollback
bytes_read = 0
chunks = []
for bytes in stream:
bytes_read += len(bytes)
chunks.append(bytes)
if bytes_read > rollback:
break
if not bytes:
break
else:
self._done = True
if not chunks:
raise StopIteration()
chunk = b''.join(chunks)
boundary = self._find_boundary(chunk, len(chunk) < self._rollback)
if boundary:
end, next = boundary
stream.unget(chunk[next:])
self._done = True
return chunk[:end]
else:
# make sure we don't treat a partial boundary (and
# its separators) as data
if not chunk[:-rollback]: # and len(chunk) >= (len(self._boundary) + 6):
# There's nothing left, we should just return and mark as done.
self._done = True
return chunk
else:
stream.unget(chunk[-rollback:])
return chunk[:-rollback]
def _find_boundary(self, data, eof=False):
"""
Finds a multipart boundary in data.
Should no boundary exist in the data None is returned instead. Otherwise
a tuple containing the indices of the following are returned:
* the end of current encapsulation
* the start of the next encapsulation
"""
index = data.find(self._boundary)
if index < 0:
return None
else:
end = index
next = index + len(self._boundary)
# backup over CRLF
last = max(0, end - 1)
if data[last:last + 1] == b'\n':
end -= 1
last = max(0, end - 1)
if data[last:last + 1] == b'\r':
end -= 1
return end, next
def exhaust(stream_or_iterable):
"""
Completely exhausts an iterator or stream.
Raise a MultiPartParserError if the argument is not a stream or an iterable.
"""
iterator = None
try:
iterator = iter(stream_or_iterable)
except TypeError:
iterator = ChunkIter(stream_or_iterable, 16384)
if iterator is None:
raise MultiPartParserError('multipartparser.exhaust() was passed a non-iterable or stream parameter')
for __ in iterator:
pass
def parse_boundary_stream(stream, max_header_size):
"""
Parses one and exactly one stream that encapsulates a boundary.
"""
# Stream at beginning of header, look for end of header
# and parse it if found. The header must fit within one
# chunk.
chunk = stream.read(max_header_size)
# 'find' returns the top of these four bytes, so we'll
# need to munch them later to prevent them from polluting
# the payload.
header_end = chunk.find(b'\r\n\r\n')
def _parse_header(line):
main_value_pair, params = parse_header(line)
try:
name, value = main_value_pair.split(':', 1)
except ValueError:
raise ValueError("Invalid header: %r" % line)
return name, (value, params)
if header_end == -1:
# we find no header, so we just mark this fact and pass on
# the stream verbatim
stream.unget(chunk)
return (RAW, {}, stream)
header = chunk[:header_end]
# here we place any excess chunk back onto the stream, as
# well as throwing away the CRLFCRLF bytes from above.
stream.unget(chunk[header_end + 4:])
TYPE = RAW
outdict = {}
# Eliminate blank lines
for line in header.split(b'\r\n'):
# This terminology ("main value" and "dictionary of
# parameters") is from the Python docs.
try:
name, (value, params) = _parse_header(line)
except ValueError:
continue
if name == 'content-disposition':
TYPE = FIELD
if params.get('filename'):
TYPE = FILE
outdict[name] = value, params
if TYPE == RAW:
stream.unget(chunk)
return (TYPE, outdict, stream)
class Parser(object):
def __init__(self, stream, boundary):
self._stream = stream
self._separator = b'--' + boundary
def __iter__(self):
boundarystream = InterBoundaryIter(self._stream, self._separator)
for sub_stream in boundarystream:
# Iterate over each part
yield parse_boundary_stream(sub_stream, 1024)
def parse_header(line):
""" Parse the header into a key-value.
Input (line): bytes, output: unicode for key/name, bytes for value which
will be decoded later
"""
plist = _parse_header_params(b';' + line)
key = plist.pop(0).lower().decode('ascii')
pdict = {}
for p in plist:
i = p.find(b'=')
if i >= 0:
has_encoding = False
name = p[:i].strip().lower().decode('ascii')
if name.endswith('*'):
# Lang/encoding embedded in the value (like "filename*=UTF-8''file.ext")
# http://tools.ietf.org/html/rfc2231#section-4
name = name[:-1]
if p.count(b"'") == 2:
has_encoding = True
value = p[i + 1:].strip()
if has_encoding:
encoding, lang, value = value.split(b"'")
if six.PY3:
value = unquote(value.decode(), encoding=encoding.decode())
else:
value = unquote(value).decode(encoding)
if len(value) >= 2 and value[:1] == value[-1:] == b'"':
value = value[1:-1]
value = value.replace(b'\\\\', b'\\').replace(b'\\"', b'"')
pdict[name] = value
return key, pdict
def _parse_header_params(s):
plist = []
while s[:1] == b';':
s = s[1:]
end = s.find(b';')
while end > 0 and s.count(b'"', 0, end) % 2:
end = s.find(b';', end + 1)
if end < 0:
end = len(s)
f = s[:end]
plist.append(f.strip())
s = s[end:]
return plist
|
bsd-3-clause
|
[
624,
199,
3947,
13,
2064,
6057,
367,
570,
26598,
14,
199,
199,
920,
10553,
1373,
1021,
12,
1124,
3947,
8416,
2842,
4542,
1314,
22295,
8291,
402,
14238,
666,
370,
199,
493,
5802,
8297,
367,
6661,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
646,
14755,
199,
646,
16004,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
428,
28651,
27242,
2821,
199,
504,
1639,
14,
1018,
14,
1725,
14,
5064,
2232,
492,
334,
272,
8232,
1173,
12,
8015,
14224,
25096,
12,
8015,
10301,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
23004,
492,
6879,
24811,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
14342,
199,
504,
1639,
14,
1208,
14,
505,
492,
22221,
63,
8327,
199,
199,
363,
452,
363,
275,
661,
3947,
8416,
2842,
297,
283,
3947,
8416,
21811,
297,
283,
27611,
920,
2411,
7274,
358,
421,
199,
533,
6879,
8416,
21811,
8,
1726,
304,
272,
986,
421,
199,
533,
6924,
3296,
920,
2411,
7274,
8,
1726,
304,
272,
408,
272,
3091,
1655,
11597,
787,
4370,
687,
642,
2243,
14,
272,
408,
272,
986,
199,
199,
4307,
275,
298,
1773,
2,
199,
3817,
275,
298,
493,
2,
199,
8609,
275,
298,
698,
2,
199,
199,
63,
5825,
772,
63,
1093,
6012,
63,
3170,
275,
3146,
340,
3816,
14,
4521,
18,
587,
14755,
14,
547,
421,
199,
533,
6879,
8416,
2842,
8,
785,
304,
272,
408,
272,
437,
18158,
1789,
1299,
15193,
15,
964,
13,
576,
1798,
14,
339,
1124,
3947,
24811,
14,
1122,
8497,
11597,
314,
1324,
2547,
315,
1124,
4604,
63,
890,
1040,
8291,
272,
436,
2529,
282,
2008,
402,
15475,
3947,
24811,
8,
4030,
395,
6879,
24811,
8,
9472,
430,
4345,
272,
408,
272,
347,
636,
826,
721,
277,
12,
603,
15808,
12,
1324,
63,
576,
12,
5802,
63,
5586,
12,
2644,
29,
403,
304,
267,
408,
267,
11578,
314,
6879,
8416,
2842,
909,
14,
398,
520,
10614,
26,
288,
710,
4465,
1124,
10614,
1040,
2600,
315,
5634,
1056,
2251,
14,
267,
520,
1210,
63,
576,
26,
288,
710,
3066,
2963,
666,
12,
465,
282,
570,
13,
2930,
909,
14,
267,
520,
5064,
63,
5586,
26,
288,
437,
769,
402,
19149,
2461,
4454,
626,
5147,
5331,
641,
314,
14238,
288,
666,
14,
267,
520,
2991,
26,
288,
710,
2644,
543,
1314,
370,
14312,
314,
12467,
666,
14,
267,
408,
398,
327,
267,
327,
6646,
13,
804,
1077,
1395,
15193,
436,
314,
8424,
2556,
14,
267,
327,
398,
1564,
63,
466,
275,
603,
15808,
14,
362,
360,
2856,
63,
9663,
63,
2711,
297,
603,
15808,
14,
362,
360,
9663,
63,
2711,
297,
12381,
267,
340,
440,
1564,
63,
466,
14,
2460,
360,
10123,
26985,
288,
746,
6879,
8416,
21811,
360,
3364,
6646,
13,
804,
26,
450,
83,
7,
450,
1564,
63,
466,
9,
398,
327,
6077,
314,
1406,
370,
664,
314,
8424,
370,
3715,
314,
4184,
14,
267,
5577,
12,
3999,
275,
2198,
63,
1291,
8,
1317,
63,
466,
14,
2143,
360,
4371,
1333,
267,
8424,
275,
3999,
14,
362,
360,
9891,
358,
267,
340,
440,
8424,
503,
440,
16004,
14,
1078,
63,
9891,
8,
9891,
304,
288,
746,
6879,
8416,
21811,
360,
3364,
8424,
315,
15193,
26,
450,
83,
7,
450,
8424,
9,
398,
327,
6646,
13,
4625,
1077,
1395,
314,
2582,
402,
314,
2396,
781,
787,
3595,
267,
327,
370,
9128,
14,
267,
862,
26,
288,
1564,
63,
1267,
275,
1109,
8,
10614,
14,
362,
360,
2856,
63,
9663,
63,
9127,
297,
603,
15808,
14,
362,
360,
9663,
63,
9127,
297,
378,
1724,
267,
871,
334,
3393,
12,
3146,
304,
288,
1564,
63,
1267,
275,
378,
398,
340,
1564,
63,
1267,
665,
378,
26,
288,
327,
961,
4910,
781,
9296,
1133,
1980,
1396,
3730,
376,
1125,
14,
288,
746,
6879,
8416,
21811,
480,
3364,
1564,
2582,
26,
450,
82,
2,
450,
1564,
63,
1267,
9,
398,
340,
1228,
8,
9891,
12,
3816,
14,
505,
63,
466,
304,
288,
8424,
275,
8424,
14,
2143,
360,
4371,
358,
267,
291,
423,
9891,
275,
8424,
267,
291,
423,
1210,
63,
576,
275,
1324,
63,
576,
398,
327,
2104,
7163,
543,
6465,
13,
1896,
2784,
15913,
334,
1045,
4337,
13,
2075,
9446,
395,
267,
327,
314,
3728,
1568,
1077,
506,
665,
499,
62,
2192,
12,
1325,
5139,
487,
6604,
701,
841,
14,
267,
3962,
63,
7723,
275,
359,
88,
14,
4604,
63,
890,
367,
671,
315,
5802,
63,
5586,
340,
671,
14,
4604,
63,
890,
61,
267,
291,
423,
4604,
63,
890,
275,
1748,
779,
18,
1011,
7105,
446,
841,
61,
435,
3962,
63,
7723,
9,
398,
291,
423,
2024,
275,
603,
15808,
267,
291,
423,
2991,
275,
2644,
503,
2202,
14,
3472,
63,
23969,
267,
291,
423,
1317,
63,
1267,
275,
1564,
63,
1267,
267,
291,
423,
5064,
63,
5586,
275,
5802,
63,
5586,
339,
347,
2198,
8,
277,
304,
267,
408,
267,
6077,
314,
8761,
666,
436,
2059,
652,
1901,
282,
16444,
654,
6879,
24811,
436,
282,
8761,
267,
6879,
24811,
14,
398,
1803,
282,
2008,
3035,
314,
8761,
436,
16444,
654,
2600,
12,
17342,
14,
267,
408,
267,
327,
2136,
1172,
370,
492,
8133,
2141,
3224,
2348,
370,
5126,
282,
15032,
492,
14,
267,
687,
1639,
14,
1014,
492,
8133,
2141,
398,
2644,
275,
291,
423,
2991,
267,
8297,
275,
291,
423,
5064,
63,
5586,
398,
327,
3101,
3158,
20065,
626,
6646,
13,
4625,
2356,
378,
365,
1686,
267,
327,
7252,
1564,
13,
1267,
508,
378,
2544,
32620,
267,
340,
291,
423,
1317,
63,
1267,
508,
378,
26,
288,
372,
8133,
2141,
8594,
2644,
29,
277,
423,
2991,
395,
6879,
24811,
342,
398,
327,
1666,
340,
1263,
402,
314,
8297,
5452,
10296,
402,
314,
6057,
14,
267,
327,
961,
6127,
18972,
8137,
340,
1929,
506,
14,
267,
367,
3016,
315,
8297,
26,
288,
754,
275,
3016,
14,
2479,
63,
1773,
63,
1210,
8,
277,
423,
1210,
63,
576,
12,
6343,
291,
423,
2024,
12,
6343,
291,
423,
1317,
63,
1267,
12,
6343,
291,
423,
9891,
12
] |
[
199,
3947,
13,
2064,
6057,
367,
570,
26598,
14,
199,
199,
920,
10553,
1373,
1021,
12,
1124,
3947,
8416,
2842,
4542,
1314,
22295,
8291,
402,
14238,
666,
370,
199,
493,
5802,
8297,
367,
6661,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
646,
14755,
199,
646,
16004,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
428,
28651,
27242,
2821,
199,
504,
1639,
14,
1018,
14,
1725,
14,
5064,
2232,
492,
334,
272,
8232,
1173,
12,
8015,
14224,
25096,
12,
8015,
10301,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
23004,
492,
6879,
24811,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
14342,
199,
504,
1639,
14,
1208,
14,
505,
492,
22221,
63,
8327,
199,
199,
363,
452,
363,
275,
661,
3947,
8416,
2842,
297,
283,
3947,
8416,
21811,
297,
283,
27611,
920,
2411,
7274,
358,
421,
199,
533,
6879,
8416,
21811,
8,
1726,
304,
272,
986,
421,
199,
533,
6924,
3296,
920,
2411,
7274,
8,
1726,
304,
272,
408,
272,
3091,
1655,
11597,
787,
4370,
687,
642,
2243,
14,
272,
408,
272,
986,
199,
199,
4307,
275,
298,
1773,
2,
199,
3817,
275,
298,
493,
2,
199,
8609,
275,
298,
698,
2,
199,
199,
63,
5825,
772,
63,
1093,
6012,
63,
3170,
275,
3146,
340,
3816,
14,
4521,
18,
587,
14755,
14,
547,
421,
199,
533,
6879,
8416,
2842,
8,
785,
304,
272,
408,
272,
437,
18158,
1789,
1299,
15193,
15,
964,
13,
576,
1798,
14,
339,
1124,
3947,
24811,
14,
1122,
8497,
11597,
314,
1324,
2547,
315,
1124,
4604,
63,
890,
1040,
8291,
272,
436,
2529,
282,
2008,
402,
15475,
3947,
24811,
8,
4030,
395,
6879,
24811,
8,
9472,
430,
4345,
272,
408,
272,
347,
636,
826,
721,
277,
12,
603,
15808,
12,
1324,
63,
576,
12,
5802,
63,
5586,
12,
2644,
29,
403,
304,
267,
408,
267,
11578,
314,
6879,
8416,
2842,
909,
14,
398,
520,
10614,
26,
288,
710,
4465,
1124,
10614,
1040,
2600,
315,
5634,
1056,
2251,
14,
267,
520,
1210,
63,
576,
26,
288,
710,
3066,
2963,
666,
12,
465,
282,
570,
13,
2930,
909,
14,
267,
520,
5064,
63,
5586,
26,
288,
437,
769,
402,
19149,
2461,
4454,
626,
5147,
5331,
641,
314,
14238,
288,
666,
14,
267,
520,
2991,
26,
288,
710,
2644,
543,
1314,
370,
14312,
314,
12467,
666,
14,
267,
408,
398,
327,
267,
327,
6646,
13,
804,
1077,
1395,
15193,
436,
314,
8424,
2556,
14,
267,
327,
398,
1564,
63,
466,
275,
603,
15808,
14,
362,
360,
2856,
63,
9663,
63,
2711,
297,
603,
15808,
14,
362,
360,
9663,
63,
2711,
297,
12381,
267,
340,
440,
1564,
63,
466,
14,
2460,
360,
10123,
26985,
288,
746,
6879,
8416,
21811,
360,
3364,
6646,
13,
804,
26,
450,
83,
7,
450,
1564,
63,
466,
9,
398,
327,
6077,
314,
1406,
370,
664,
314,
8424,
370,
3715,
314,
4184,
14,
267,
5577,
12,
3999,
275,
2198,
63,
1291,
8,
1317,
63,
466,
14,
2143,
360,
4371,
1333,
267,
8424,
275,
3999,
14,
362,
360,
9891,
358,
267,
340,
440,
8424,
503,
440,
16004,
14,
1078,
63,
9891,
8,
9891,
304,
288,
746,
6879,
8416,
21811,
360,
3364,
8424,
315,
15193,
26,
450,
83,
7,
450,
8424,
9,
398,
327,
6646,
13,
4625,
1077,
1395,
314,
2582,
402,
314,
2396,
781,
787,
3595,
267,
327,
370,
9128,
14,
267,
862,
26,
288,
1564,
63,
1267,
275,
1109,
8,
10614,
14,
362,
360,
2856,
63,
9663,
63,
9127,
297,
603,
15808,
14,
362,
360,
9663,
63,
9127,
297,
378,
1724,
267,
871,
334,
3393,
12,
3146,
304,
288,
1564,
63,
1267,
275,
378,
398,
340,
1564,
63,
1267,
665,
378,
26,
288,
327,
961,
4910,
781,
9296,
1133,
1980,
1396,
3730,
376,
1125,
14,
288,
746,
6879,
8416,
21811,
480,
3364,
1564,
2582,
26,
450,
82,
2,
450,
1564,
63,
1267,
9,
398,
340,
1228,
8,
9891,
12,
3816,
14,
505,
63,
466,
304,
288,
8424,
275,
8424,
14,
2143,
360,
4371,
358,
267,
291,
423,
9891,
275,
8424,
267,
291,
423,
1210,
63,
576,
275,
1324,
63,
576,
398,
327,
2104,
7163,
543,
6465,
13,
1896,
2784,
15913,
334,
1045,
4337,
13,
2075,
9446,
395,
267,
327,
314,
3728,
1568,
1077,
506,
665,
499,
62,
2192,
12,
1325,
5139,
487,
6604,
701,
841,
14,
267,
3962,
63,
7723,
275,
359,
88,
14,
4604,
63,
890,
367,
671,
315,
5802,
63,
5586,
340,
671,
14,
4604,
63,
890,
61,
267,
291,
423,
4604,
63,
890,
275,
1748,
779,
18,
1011,
7105,
446,
841,
61,
435,
3962,
63,
7723,
9,
398,
291,
423,
2024,
275,
603,
15808,
267,
291,
423,
2991,
275,
2644,
503,
2202,
14,
3472,
63,
23969,
267,
291,
423,
1317,
63,
1267,
275,
1564,
63,
1267,
267,
291,
423,
5064,
63,
5586,
275,
5802,
63,
5586,
339,
347,
2198,
8,
277,
304,
267,
408,
267,
6077,
314,
8761,
666,
436,
2059,
652,
1901,
282,
16444,
654,
6879,
24811,
436,
282,
8761,
267,
6879,
24811,
14,
398,
1803,
282,
2008,
3035,
314,
8761,
436,
16444,
654,
2600,
12,
17342,
14,
267,
408,
267,
327,
2136,
1172,
370,
492,
8133,
2141,
3224,
2348,
370,
5126,
282,
15032,
492,
14,
267,
687,
1639,
14,
1014,
492,
8133,
2141,
398,
2644,
275,
291,
423,
2991,
267,
8297,
275,
291,
423,
5064,
63,
5586,
398,
327,
3101,
3158,
20065,
626,
6646,
13,
4625,
2356,
378,
365,
1686,
267,
327,
7252,
1564,
13,
1267,
508,
378,
2544,
32620,
267,
340,
291,
423,
1317,
63,
1267,
508,
378,
26,
288,
372,
8133,
2141,
8594,
2644,
29,
277,
423,
2991,
395,
6879,
24811,
342,
398,
327,
1666,
340,
1263,
402,
314,
8297,
5452,
10296,
402,
314,
6057,
14,
267,
327,
961,
6127,
18972,
8137,
340,
1929,
506,
14,
267,
367,
3016,
315,
8297,
26,
288,
754,
275,
3016,
14,
2479,
63,
1773,
63,
1210,
8,
277,
423,
1210,
63,
576,
12,
6343,
291,
423,
2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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CCI-MOC/nova
|
nova/tests/unit/virt/ironic/test_client_wrapper.py
|
26
|
8277
|
# Copyright 2014 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ironicclient import client as ironic_client
from ironicclient import exc as ironic_exception
import mock
from oslo_config import cfg
from nova import exception
from nova import test
from nova.tests.unit.virt.ironic import utils as ironic_utils
from nova.virt.ironic import client_wrapper
CONF = cfg.CONF
FAKE_CLIENT = ironic_utils.FakeClient()
def get_new_fake_client(*args, **kwargs):
return ironic_utils.FakeClient()
class IronicClientWrapperTestCase(test.NoDBTestCase):
def setUp(self):
super(IronicClientWrapperTestCase, self).setUp()
self.ironicclient = client_wrapper.IronicClientWrapper()
# Do not waste time sleeping
cfg.CONF.set_override('api_retry_interval', 0, 'ironic')
@mock.patch.object(client_wrapper.IronicClientWrapper, '_multi_getattr')
@mock.patch.object(client_wrapper.IronicClientWrapper, '_get_client')
def test_call_good_no_args(self, mock_get_client, mock_multi_getattr):
mock_get_client.return_value = FAKE_CLIENT
self.ironicclient.call("node.list")
mock_get_client.assert_called_once_with()
mock_multi_getattr.assert_called_once_with(FAKE_CLIENT, "node.list")
mock_multi_getattr.return_value.assert_called_once_with()
@mock.patch.object(client_wrapper.IronicClientWrapper, '_multi_getattr')
@mock.patch.object(client_wrapper.IronicClientWrapper, '_get_client')
def test_call_good_with_args(self, mock_get_client, mock_multi_getattr):
mock_get_client.return_value = FAKE_CLIENT
self.ironicclient.call("node.list", 'test', associated=True)
mock_get_client.assert_called_once_with()
mock_multi_getattr.assert_called_once_with(FAKE_CLIENT, "node.list")
mock_multi_getattr.return_value.assert_called_once_with(
'test', associated=True)
@mock.patch.object(ironic_client, 'get_client')
def test__get_client_no_auth_token(self, mock_ir_cli):
self.flags(admin_auth_token=None, group='ironic')
ironicclient = client_wrapper.IronicClientWrapper()
# dummy call to have _get_client() called
ironicclient.call("node.list")
expected = {'os_username': CONF.ironic.admin_username,
'os_password': CONF.ironic.admin_password,
'os_auth_url': CONF.ironic.admin_url,
'os_tenant_name': CONF.ironic.admin_tenant_name,
'os_service_type': 'baremetal',
'os_endpoint_type': 'public',
'ironic_url': CONF.ironic.api_endpoint,
'max_retries': CONF.ironic.api_max_retries,
'retry_interval': CONF.ironic.api_retry_interval}
mock_ir_cli.assert_called_once_with(CONF.ironic.api_version,
**expected)
@mock.patch.object(ironic_client, 'get_client')
def test__get_client_with_auth_token(self, mock_ir_cli):
self.flags(admin_auth_token='fake-token', group='ironic')
ironicclient = client_wrapper.IronicClientWrapper()
# dummy call to have _get_client() called
ironicclient.call("node.list")
expected = {'os_auth_token': 'fake-token',
'ironic_url': CONF.ironic.api_endpoint,
'max_retries': CONF.ironic.api_max_retries,
'retry_interval': CONF.ironic.api_retry_interval}
mock_ir_cli.assert_called_once_with(CONF.ironic.api_version,
**expected)
@mock.patch.object(client_wrapper.IronicClientWrapper, '_multi_getattr')
@mock.patch.object(client_wrapper.IronicClientWrapper, '_get_client')
def test_call_fail(self, mock_get_client, mock_multi_getattr):
cfg.CONF.set_override('api_max_retries', 2, 'ironic')
test_obj = mock.Mock()
test_obj.side_effect = ironic_exception.HTTPServiceUnavailable
mock_multi_getattr.return_value = test_obj
mock_get_client.return_value = FAKE_CLIENT
self.assertRaises(exception.NovaException, self.ironicclient.call,
"node.list")
self.assertEqual(3, test_obj.call_count)
@mock.patch.object(client_wrapper.IronicClientWrapper, '_multi_getattr')
@mock.patch.object(client_wrapper.IronicClientWrapper, '_get_client')
def test_call_with_api_max_retries_neg_conf_val(self, mock_get_client,
mock_multi_getattr):
cfg.CONF.set_default('api_max_retries', -1, 'ironic')
test_obj = mock.Mock()
test_obj.side_effect = ironic_exception.HTTPServiceUnavailable
mock_multi_getattr.return_value = test_obj
mock_get_client.return_value = FAKE_CLIENT
self.assertRaises(exception.NovaException, self.ironicclient.call,
"node.list")
self.assertEqual(1, test_obj.call_count)
@mock.patch.object(client_wrapper.IronicClientWrapper, '_multi_getattr')
@mock.patch.object(client_wrapper.IronicClientWrapper, '_get_client')
def test_call_fail_unexpected_exception(self, mock_get_client,
mock_multi_getattr):
test_obj = mock.Mock()
test_obj.side_effect = ironic_exception.HTTPNotFound
mock_multi_getattr.return_value = test_obj
mock_get_client.return_value = FAKE_CLIENT
self.assertRaises(ironic_exception.HTTPNotFound,
self.ironicclient.call, "node.list")
@mock.patch.object(ironic_client, 'get_client')
def test__get_client_unauthorized(self, mock_get_client):
mock_get_client.side_effect = ironic_exception.Unauthorized
self.assertRaises(exception.NovaException,
self.ironicclient._get_client)
@mock.patch.object(ironic_client, 'get_client')
def test__get_client_unexpected_exception(self, mock_get_client):
mock_get_client.side_effect = ironic_exception.ConnectionRefused
self.assertRaises(ironic_exception.ConnectionRefused,
self.ironicclient._get_client)
def test__multi_getattr_good(self):
response = self.ironicclient._multi_getattr(FAKE_CLIENT, "node.list")
self.assertEqual(FAKE_CLIENT.node.list, response)
def test__multi_getattr_fail(self):
self.assertRaises(AttributeError, self.ironicclient._multi_getattr,
FAKE_CLIENT, "nonexistent")
@mock.patch.object(ironic_client, 'get_client')
def test__client_is_cached(self, mock_get_client):
mock_get_client.side_effect = get_new_fake_client
ironicclient = client_wrapper.IronicClientWrapper()
first_client = ironicclient._get_client()
second_client = ironicclient._get_client()
self.assertEqual(id(first_client), id(second_client))
@mock.patch.object(ironic_client, 'get_client')
def test__invalidate_cached_client(self, mock_get_client):
mock_get_client.side_effect = get_new_fake_client
ironicclient = client_wrapper.IronicClientWrapper()
first_client = ironicclient._get_client()
ironicclient._invalidate_cached_client()
second_client = ironicclient._get_client()
self.assertNotEqual(id(first_client), id(second_client))
@mock.patch.object(ironic_client, 'get_client')
def test_call_uses_cached_client(self, mock_get_client):
mock_get_client.side_effect = get_new_fake_client
ironicclient = client_wrapper.IronicClientWrapper()
for n in range(0, 4):
ironicclient.call("node.list")
self.assertEqual(1, mock_get_client.call_count)
|
apache-2.0
|
[
3,
1898,
6927,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
28372,
1258,
492,
1890,
465,
28372,
63,
1258,
199,
504,
28372,
1258,
492,
3178,
465,
28372,
63,
1971,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
4549,
14,
723,
12732,
492,
3778,
465,
28372,
63,
1208,
199,
504,
5913,
14,
4549,
14,
723,
12732,
492,
1890,
63,
5029,
199,
199,
3103,
275,
4810,
14,
3103,
199,
199,
14623,
63,
9901,
275,
28372,
63,
1208,
14,
8249,
3041,
342,
421,
199,
318,
664,
63,
1222,
63,
3183,
63,
1258,
2031,
589,
12,
1011,
958,
304,
272,
372,
28372,
63,
1208,
14,
8249,
3041,
342,
421,
199,
533,
473,
20410,
3041,
4590,
1746,
8,
396,
14,
32437,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
41,
20410,
3041,
4590,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
723,
12732,
1258,
275,
1890,
63,
5029,
14,
41,
20410,
3041,
4590,
342,
267,
327,
4226,
440,
1990,
266,
900,
9435,
316,
267,
4810,
14,
3103,
14,
409,
63,
4415,
360,
1246,
63,
7154,
63,
4284,
297,
378,
12,
283,
723,
12732,
358,
339,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
3029,
63,
5675,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
362,
63,
1258,
358,
272,
347,
511,
63,
1250,
63,
8302,
63,
889,
63,
589,
8,
277,
12,
1683,
63,
362,
63,
1258,
12,
1683,
63,
3029,
63,
5675,
304,
267,
1683,
63,
362,
63,
1258,
14,
1107,
63,
585,
275,
25699,
63,
9901,
267,
291,
14,
723,
12732,
1258,
14,
1250,
480,
932,
14,
513,
531,
267,
1683,
63,
362,
63,
1258,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
267,
1683,
63,
3029,
63,
5675,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
14623,
63,
9901,
12,
298,
932,
14,
513,
531,
267,
1683,
63,
3029,
63,
5675,
14,
1107,
63,
585,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
339,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
3029,
63,
5675,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
362,
63,
1258,
358,
272,
347,
511,
63,
1250,
63,
8302,
63,
1045,
63,
589,
8,
277,
12,
1683,
63,
362,
63,
1258,
12,
1683,
63,
3029,
63,
5675,
304,
267,
1683,
63,
362,
63,
1258,
14,
1107,
63,
585,
275,
25699,
63,
9901,
267,
291,
14,
723,
12732,
1258,
14,
1250,
480,
932,
14,
513,
401,
283,
396,
297,
4568,
29,
549,
9,
267,
1683,
63,
362,
63,
1258,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
267,
1683,
63,
3029,
63,
5675,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
14623,
63,
9901,
12,
298,
932,
14,
513,
531,
267,
1683,
63,
3029,
63,
5675,
14,
1107,
63,
585,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
283,
396,
297,
4568,
29,
549,
9,
339,
768,
1805,
14,
2068,
14,
785,
8,
723,
12732,
63,
1258,
12,
283,
362,
63,
1258,
358,
272,
347,
511,
363,
362,
63,
1258,
63,
889,
63,
1178,
63,
1418,
8,
277,
12,
1683,
63,
723,
63,
2764,
304,
267,
291,
14,
2469,
8,
2113,
63,
1178,
63,
1418,
29,
403,
12,
1572,
534,
723,
12732,
358,
267,
28372,
1258,
275,
1890,
63,
5029,
14,
41,
20410,
3041,
4590,
342,
267,
327,
7283,
1240,
370,
1172,
485,
362,
63,
1258,
342,
2797,
267,
28372,
1258,
14,
1250,
480,
932,
14,
513,
531,
267,
1420,
275,
791,
736,
63,
2473,
356,
6392,
14,
723,
12732,
14,
2113,
63,
2473,
12,
490,
283,
736,
63,
2060,
356,
6392,
14,
723,
12732,
14,
2113,
63,
2060,
12,
490,
283,
736,
63,
1178,
63,
633,
356,
6392,
14,
723,
12732,
14,
2113,
63,
633,
12,
490,
283,
736,
63,
4647,
63,
354,
356,
6392,
14,
723,
12732,
14,
2113,
63,
4647,
63,
354,
12,
490,
283,
736,
63,
1364,
63,
466,
356,
283,
14890,
22420,
297,
490,
283,
736,
63,
6520,
63,
466,
356,
283,
3455,
297,
490,
283,
723,
12732,
63,
633,
356,
6392,
14,
723,
12732,
14,
1246,
63,
6520,
12,
490,
283,
988,
63,
10937,
356,
6392,
14,
723,
12732,
14,
1246,
63,
988,
63,
10937,
12,
490,
283,
7154,
63,
4284,
356,
6392,
14,
723,
12732,
14,
1246,
63,
7154,
63,
4284,
93,
267,
1683,
63,
723,
63,
2764,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
3103,
14,
723,
12732,
14,
1246,
63,
1023,
12,
4490,
1011,
2062,
9,
339,
768,
1805,
14,
2068,
14,
785,
8,
723,
12732,
63,
1258,
12,
283,
362,
63,
1258,
358,
272,
347,
511,
363,
362,
63,
1258,
63,
1045,
63,
1178,
63,
1418,
8,
277,
12,
1683,
63,
723,
63,
2764,
304,
267,
291,
14,
2469,
8,
2113,
63,
1178,
63,
1418,
534,
3183,
13,
1418,
297,
1572,
534,
723,
12732,
358,
267,
28372,
1258,
275,
1890,
63,
5029,
14,
41,
20410,
3041,
4590,
342,
267,
327,
7283,
1240,
370,
1172,
485,
362,
63,
1258,
342,
2797,
267,
28372,
1258,
14
] |
[
1898,
6927,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
28372,
1258,
492,
1890,
465,
28372,
63,
1258,
199,
504,
28372,
1258,
492,
3178,
465,
28372,
63,
1971,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
4549,
14,
723,
12732,
492,
3778,
465,
28372,
63,
1208,
199,
504,
5913,
14,
4549,
14,
723,
12732,
492,
1890,
63,
5029,
199,
199,
3103,
275,
4810,
14,
3103,
199,
199,
14623,
63,
9901,
275,
28372,
63,
1208,
14,
8249,
3041,
342,
421,
199,
318,
664,
63,
1222,
63,
3183,
63,
1258,
2031,
589,
12,
1011,
958,
304,
272,
372,
28372,
63,
1208,
14,
8249,
3041,
342,
421,
199,
533,
473,
20410,
3041,
4590,
1746,
8,
396,
14,
32437,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
41,
20410,
3041,
4590,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
723,
12732,
1258,
275,
1890,
63,
5029,
14,
41,
20410,
3041,
4590,
342,
267,
327,
4226,
440,
1990,
266,
900,
9435,
316,
267,
4810,
14,
3103,
14,
409,
63,
4415,
360,
1246,
63,
7154,
63,
4284,
297,
378,
12,
283,
723,
12732,
358,
339,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
3029,
63,
5675,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
362,
63,
1258,
358,
272,
347,
511,
63,
1250,
63,
8302,
63,
889,
63,
589,
8,
277,
12,
1683,
63,
362,
63,
1258,
12,
1683,
63,
3029,
63,
5675,
304,
267,
1683,
63,
362,
63,
1258,
14,
1107,
63,
585,
275,
25699,
63,
9901,
267,
291,
14,
723,
12732,
1258,
14,
1250,
480,
932,
14,
513,
531,
267,
1683,
63,
362,
63,
1258,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
267,
1683,
63,
3029,
63,
5675,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
14623,
63,
9901,
12,
298,
932,
14,
513,
531,
267,
1683,
63,
3029,
63,
5675,
14,
1107,
63,
585,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
339,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
3029,
63,
5675,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1258,
63,
5029,
14,
41,
20410,
3041,
4590,
12,
2513,
362,
63,
1258,
358,
272,
347,
511,
63,
1250,
63,
8302,
63,
1045,
63,
589,
8,
277,
12,
1683,
63,
362,
63,
1258,
12,
1683,
63,
3029,
63,
5675,
304,
267,
1683,
63,
362,
63,
1258,
14,
1107,
63,
585,
275,
25699,
63,
9901,
267,
291,
14,
723,
12732,
1258,
14,
1250,
480,
932,
14,
513,
401,
283,
396,
297,
4568,
29,
549,
9,
267,
1683,
63,
362,
63,
1258,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
267,
1683,
63,
3029,
63,
5675,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
14623,
63,
9901,
12,
298,
932,
14,
513,
531,
267,
1683,
63,
3029,
63,
5675,
14,
1107,
63,
585,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
283,
396,
297,
4568,
29,
549,
9,
339,
768,
1805,
14,
2068,
14,
785,
8,
723,
12732,
63,
1258,
12,
283,
362,
63,
1258,
358,
272,
347,
511,
363,
362,
63,
1258,
63,
889,
63,
1178,
63,
1418,
8,
277,
12,
1683,
63,
723,
63,
2764,
304,
267,
291,
14,
2469,
8,
2113,
63,
1178,
63,
1418,
29,
403,
12,
1572,
534,
723,
12732,
358,
267,
28372,
1258,
275,
1890,
63,
5029,
14,
41,
20410,
3041,
4590,
342,
267,
327,
7283,
1240,
370,
1172,
485,
362,
63,
1258,
342,
2797,
267,
28372,
1258,
14,
1250,
480,
932,
14,
513,
531,
267,
1420,
275,
791,
736,
63,
2473,
356,
6392,
14,
723,
12732,
14,
2113,
63,
2473,
12,
490,
283,
736,
63,
2060,
356,
6392,
14,
723,
12732,
14,
2113,
63,
2060,
12,
490,
283,
736,
63,
1178,
63,
633,
356,
6392,
14,
723,
12732,
14,
2113,
63,
633,
12,
490,
283,
736,
63,
4647,
63,
354,
356,
6392,
14,
723,
12732,
14,
2113,
63,
4647,
63,
354,
12,
490,
283,
736,
63,
1364,
63,
466,
356,
283,
14890,
22420,
297,
490,
283,
736,
63,
6520,
63,
466,
356,
283,
3455,
297,
490,
283,
723,
12732,
63,
633,
356,
6392,
14,
723,
12732,
14,
1246,
63,
6520,
12,
490,
283,
988,
63,
10937,
356,
6392,
14,
723,
12732,
14,
1246,
63,
988,
63,
10937,
12,
490,
283,
7154,
63,
4284,
356,
6392,
14,
723,
12732,
14,
1246,
63,
7154,
63,
4284,
93,
267,
1683,
63,
723,
63,
2764,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
3103,
14,
723,
12732,
14,
1246,
63,
1023,
12,
4490,
1011,
2062,
9,
339,
768,
1805,
14,
2068,
14,
785,
8,
723,
12732,
63,
1258,
12,
283,
362,
63,
1258,
358,
272,
347,
511,
363,
362,
63,
1258,
63,
1045,
63,
1178,
63,
1418,
8,
277,
12,
1683,
63,
723,
63,
2764,
304,
267,
291,
14,
2469,
8,
2113,
63,
1178,
63,
1418,
534,
3183,
13,
1418,
297,
1572,
534,
723,
12732,
358,
267,
28372,
1258,
275,
1890,
63,
5029,
14,
41,
20410,
3041,
4590,
342,
267,
327,
7283,
1240,
370,
1172,
485,
362,
63,
1258,
342,
2797,
267,
28372,
1258,
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,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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
] |
barbuza/django
|
tests/model_formsets_regress/tests.py
|
25
|
20696
|
from __future__ import unicode_literals
from django import forms
from django.forms.formsets import DELETION_FIELD_NAME, BaseFormSet
from django.forms.models import (
BaseModelFormSet, inlineformset_factory, modelform_factory,
modelformset_factory,
)
from django.forms.utils import ErrorDict, ErrorList
from django.test import TestCase
from django.utils import six
from .models import (
Host, Manager, Network, ProfileNetwork, Restaurant, User, UserProfile,
UserSite,
)
class InlineFormsetTests(TestCase):
def test_formset_over_to_field(self):
"A formset over a ForeignKey with a to_field can be saved. Regression for #10243"
Form = modelform_factory(User, fields="__all__")
FormSet = inlineformset_factory(User, UserSite, fields="__all__")
# Instantiate the Form and FormSet to prove
# you can create a form with no data
form = Form()
form_set = FormSet(instance=User())
# Now create a new User and UserSite instance
data = {
'serial': '1',
'username': 'apollo13',
'usersite_set-TOTAL_FORMS': '1',
'usersite_set-INITIAL_FORMS': '0',
'usersite_set-MAX_NUM_FORMS': '0',
'usersite_set-0-data': '10',
'usersite_set-0-user': 'apollo13'
}
user = User()
form = Form(data)
if form.is_valid():
user = form.save()
else:
self.fail('Errors found on form:%s' % form_set)
form_set = FormSet(data, instance=user)
if form_set.is_valid():
form_set.save()
usersite = UserSite.objects.all().values()
self.assertEqual(usersite[0]['data'], 10)
self.assertEqual(usersite[0]['user_id'], 'apollo13')
else:
self.fail('Errors found on formset:%s' % form_set.errors)
# Now update the UserSite instance
data = {
'usersite_set-TOTAL_FORMS': '1',
'usersite_set-INITIAL_FORMS': '1',
'usersite_set-MAX_NUM_FORMS': '0',
'usersite_set-0-id': six.text_type(usersite[0]['id']),
'usersite_set-0-data': '11',
'usersite_set-0-user': 'apollo13'
}
form_set = FormSet(data, instance=user)
if form_set.is_valid():
form_set.save()
usersite = UserSite.objects.all().values()
self.assertEqual(usersite[0]['data'], 11)
self.assertEqual(usersite[0]['user_id'], 'apollo13')
else:
self.fail('Errors found on formset:%s' % form_set.errors)
# Now add a new UserSite instance
data = {
'usersite_set-TOTAL_FORMS': '2',
'usersite_set-INITIAL_FORMS': '1',
'usersite_set-MAX_NUM_FORMS': '0',
'usersite_set-0-id': six.text_type(usersite[0]['id']),
'usersite_set-0-data': '11',
'usersite_set-0-user': 'apollo13',
'usersite_set-1-data': '42',
'usersite_set-1-user': 'apollo13'
}
form_set = FormSet(data, instance=user)
if form_set.is_valid():
form_set.save()
usersite = UserSite.objects.all().values().order_by('data')
self.assertEqual(usersite[0]['data'], 11)
self.assertEqual(usersite[0]['user_id'], 'apollo13')
self.assertEqual(usersite[1]['data'], 42)
self.assertEqual(usersite[1]['user_id'], 'apollo13')
else:
self.fail('Errors found on formset:%s' % form_set.errors)
def test_formset_over_inherited_model(self):
"A formset over a ForeignKey with a to_field can be saved. Regression for #11120"
Form = modelform_factory(Restaurant, fields="__all__")
FormSet = inlineformset_factory(Restaurant, Manager, fields="__all__")
# Instantiate the Form and FormSet to prove
# you can create a form with no data
form = Form()
form_set = FormSet(instance=Restaurant())
# Now create a new Restaurant and Manager instance
data = {
'name': "Guido's House of Pasta",
'manager_set-TOTAL_FORMS': '1',
'manager_set-INITIAL_FORMS': '0',
'manager_set-MAX_NUM_FORMS': '0',
'manager_set-0-name': 'Guido Van Rossum'
}
restaurant = User()
form = Form(data)
if form.is_valid():
restaurant = form.save()
else:
self.fail('Errors found on form:%s' % form_set)
form_set = FormSet(data, instance=restaurant)
if form_set.is_valid():
form_set.save()
manager = Manager.objects.all().values()
self.assertEqual(manager[0]['name'], 'Guido Van Rossum')
else:
self.fail('Errors found on formset:%s' % form_set.errors)
# Now update the Manager instance
data = {
'manager_set-TOTAL_FORMS': '1',
'manager_set-INITIAL_FORMS': '1',
'manager_set-MAX_NUM_FORMS': '0',
'manager_set-0-id': six.text_type(manager[0]['id']),
'manager_set-0-name': 'Terry Gilliam'
}
form_set = FormSet(data, instance=restaurant)
if form_set.is_valid():
form_set.save()
manager = Manager.objects.all().values()
self.assertEqual(manager[0]['name'], 'Terry Gilliam')
else:
self.fail('Errors found on formset:%s' % form_set.errors)
# Now add a new Manager instance
data = {
'manager_set-TOTAL_FORMS': '2',
'manager_set-INITIAL_FORMS': '1',
'manager_set-MAX_NUM_FORMS': '0',
'manager_set-0-id': six.text_type(manager[0]['id']),
'manager_set-0-name': 'Terry Gilliam',
'manager_set-1-name': 'John Cleese'
}
form_set = FormSet(data, instance=restaurant)
if form_set.is_valid():
form_set.save()
manager = Manager.objects.all().values().order_by('name')
self.assertEqual(manager[0]['name'], 'John Cleese')
self.assertEqual(manager[1]['name'], 'Terry Gilliam')
else:
self.fail('Errors found on formset:%s' % form_set.errors)
def test_inline_model_with_to_field(self):
"""
#13794 --- An inline model with a to_field of a formset with instance
has working relations.
"""
FormSet = inlineformset_factory(User, UserSite, exclude=('is_superuser',))
user = User.objects.create(username="guido", serial=1337)
UserSite.objects.create(user=user, data=10)
formset = FormSet(instance=user)
# Testing the inline model's relation
self.assertEqual(formset[0].instance.user_id, "guido")
def test_inline_model_with_to_field_to_rel(self):
"""
#13794 --- An inline model with a to_field to a related field of a
formset with instance has working relations.
"""
FormSet = inlineformset_factory(UserProfile, ProfileNetwork, exclude=[])
user = User.objects.create(username="guido", serial=1337, pk=1)
self.assertEqual(user.pk, 1)
profile = UserProfile.objects.create(user=user, about="about", pk=2)
self.assertEqual(profile.pk, 2)
ProfileNetwork.objects.create(profile=profile, network=10, identifier=10)
formset = FormSet(instance=profile)
# Testing the inline model's relation
self.assertEqual(formset[0].instance.profile_id, 1)
def test_formset_with_none_instance(self):
"A formset with instance=None can be created. Regression for #11872"
Form = modelform_factory(User, fields="__all__")
FormSet = inlineformset_factory(User, UserSite, fields="__all__")
# Instantiate the Form and FormSet to prove
# you can create a formset with an instance of None
Form(instance=None)
FormSet(instance=None)
def test_empty_fields_on_modelformset(self):
"No fields passed to modelformset_factory should result in no fields on returned forms except for the id. See #14119."
UserFormSet = modelformset_factory(User, fields=())
formset = UserFormSet()
for form in formset.forms:
self.assertIn('id', form.fields)
self.assertEqual(len(form.fields), 1)
def test_save_as_new_with_new_inlines(self):
"""
Existing and new inlines are saved with save_as_new.
Regression for #14938.
"""
efnet = Network.objects.create(name="EFNet")
host1 = Host.objects.create(hostname="irc.he.net", network=efnet)
HostFormSet = inlineformset_factory(Network, Host, fields="__all__")
# Add a new host, modify previous host, and save-as-new
data = {
'host_set-TOTAL_FORMS': '2',
'host_set-INITIAL_FORMS': '1',
'host_set-MAX_NUM_FORMS': '0',
'host_set-0-id': six.text_type(host1.id),
'host_set-0-hostname': 'tranquility.hub.dal.net',
'host_set-1-hostname': 'matrix.de.eu.dal.net'
}
# To save a formset as new, it needs a new hub instance
dalnet = Network.objects.create(name="DALnet")
formset = HostFormSet(data, instance=dalnet, save_as_new=True)
self.assertTrue(formset.is_valid())
formset.save()
self.assertQuerysetEqual(
dalnet.host_set.order_by("hostname"),
["<Host: matrix.de.eu.dal.net>", "<Host: tranquility.hub.dal.net>"]
)
def test_initial_data(self):
user = User.objects.create(username="bibi", serial=1)
UserSite.objects.create(user=user, data=7)
FormSet = inlineformset_factory(User, UserSite, extra=2, fields="__all__")
formset = FormSet(instance=user, initial=[{'data': 41}, {'data': 42}])
self.assertEqual(formset.forms[0].initial['data'], 7)
self.assertEqual(formset.extra_forms[0].initial['data'], 41)
self.assertIn('value="42"', formset.extra_forms[1].as_p())
class FormsetTests(TestCase):
def test_error_class(self):
'''
Test the type of Formset and Form error attributes
'''
Formset = modelformset_factory(User, fields="__all__")
data = {
'form-TOTAL_FORMS': '2',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '0',
'form-0-id': '',
'form-0-username': 'apollo13',
'form-0-serial': '1',
'form-1-id': '',
'form-1-username': 'apollo13',
'form-1-serial': '2',
}
formset = Formset(data)
# check if the returned error classes are correct
# note: formset.errors returns a list as documented
self.assertIsInstance(formset.errors, list)
self.assertIsInstance(formset.non_form_errors(), ErrorList)
for form in formset.forms:
self.assertIsInstance(form.errors, ErrorDict)
self.assertIsInstance(form.non_field_errors(), ErrorList)
def test_initial_data(self):
User.objects.create(username="bibi", serial=1)
Formset = modelformset_factory(User, fields="__all__", extra=2)
formset = Formset(initial=[{'username': 'apollo11'}, {'username': 'apollo12'}])
self.assertEqual(formset.forms[0].initial['username'], "bibi")
self.assertEqual(formset.extra_forms[0].initial['username'], "apollo11")
self.assertIn('value="apollo12"', formset.extra_forms[1].as_p())
def test_extraneous_query_is_not_run(self):
Formset = modelformset_factory(Network, fields="__all__")
data = {'test-TOTAL_FORMS': '1',
'test-INITIAL_FORMS': '0',
'test-MAX_NUM_FORMS': '',
'test-0-name': 'Random Place', }
with self.assertNumQueries(1):
formset = Formset(data, prefix="test")
formset.save()
class CustomWidget(forms.widgets.TextInput):
pass
class UserSiteForm(forms.ModelForm):
class Meta:
model = UserSite
fields = "__all__"
widgets = {
'id': CustomWidget,
'data': CustomWidget,
}
localized_fields = ('data',)
class Callback(object):
def __init__(self):
self.log = []
def __call__(self, db_field, **kwargs):
self.log.append((db_field, kwargs))
return db_field.formfield(**kwargs)
class FormfieldCallbackTests(TestCase):
"""
Regression for #13095 and #17683: Using base forms with widgets
defined in Meta should not raise errors and BaseModelForm should respect
the specified pk widget.
"""
def test_inlineformset_factory_default(self):
Formset = inlineformset_factory(User, UserSite, form=UserSiteForm, fields="__all__")
form = Formset().forms[0]
self.assertIsInstance(form['id'].field.widget, CustomWidget)
self.assertIsInstance(form['data'].field.widget, CustomWidget)
self.assertFalse(form.fields['id'].localize)
self.assertTrue(form.fields['data'].localize)
def test_modelformset_factory_default(self):
Formset = modelformset_factory(UserSite, form=UserSiteForm)
form = Formset().forms[0]
self.assertIsInstance(form['id'].field.widget, CustomWidget)
self.assertIsInstance(form['data'].field.widget, CustomWidget)
self.assertFalse(form.fields['id'].localize)
self.assertTrue(form.fields['data'].localize)
def assertCallbackCalled(self, callback):
id_field, user_field, data_field = UserSite._meta.fields
expected_log = [
(id_field, {'widget': CustomWidget}),
(user_field, {}),
(data_field, {'widget': CustomWidget, 'localize': True}),
]
self.assertEqual(callback.log, expected_log)
def test_inlineformset_custom_callback(self):
callback = Callback()
inlineformset_factory(User, UserSite, form=UserSiteForm,
formfield_callback=callback, fields="__all__")
self.assertCallbackCalled(callback)
def test_modelformset_custom_callback(self):
callback = Callback()
modelformset_factory(UserSite, form=UserSiteForm,
formfield_callback=callback)
self.assertCallbackCalled(callback)
class BaseCustomDeleteFormSet(BaseFormSet):
"""
A formset mix-in that lets a form decide if it's to be deleted.
Works for BaseFormSets. Also works for ModelFormSets with #14099 fixed.
form.should_delete() is called. The formset delete field is also suppressed.
"""
def add_fields(self, form, index):
super(BaseCustomDeleteFormSet, self).add_fields(form, index)
self.can_delete = True
if DELETION_FIELD_NAME in form.fields:
del form.fields[DELETION_FIELD_NAME]
def _should_delete_form(self, form):
return hasattr(form, 'should_delete') and form.should_delete()
class FormfieldShouldDeleteFormTests(TestCase):
"""
Regression for #14099: BaseModelFormSet should use ModelFormSet method _should_delete_form
"""
class BaseCustomDeleteModelFormSet(BaseModelFormSet, BaseCustomDeleteFormSet):
""" Model FormSet with CustomDelete MixIn """
class CustomDeleteUserForm(forms.ModelForm):
""" A model form with a 'should_delete' method """
class Meta:
model = User
fields = "__all__"
def should_delete(self):
""" delete form if odd PK """
return self.instance.pk % 2 != 0
NormalFormset = modelformset_factory(User, form=CustomDeleteUserForm, can_delete=True)
DeleteFormset = modelformset_factory(User, form=CustomDeleteUserForm, formset=BaseCustomDeleteModelFormSet)
data = {
'form-TOTAL_FORMS': '4',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '4',
'form-0-username': 'John',
'form-0-serial': '1',
'form-1-username': 'Paul',
'form-1-serial': '2',
'form-2-username': 'George',
'form-2-serial': '3',
'form-3-username': 'Ringo',
'form-3-serial': '5',
}
delete_all_ids = {
'form-0-DELETE': '1',
'form-1-DELETE': '1',
'form-2-DELETE': '1',
'form-3-DELETE': '1',
}
def test_init_database(self):
""" Add test data to database via formset """
formset = self.NormalFormset(self.data)
self.assertTrue(formset.is_valid())
self.assertEqual(len(formset.save()), 4)
def test_no_delete(self):
""" Verify base formset doesn't modify database """
# reload database
self.test_init_database()
# pass standard data dict & see none updated
data = dict(self.data)
data['form-INITIAL_FORMS'] = 4
data.update({
'form-%d-id' % i: user.pk
for i, user in enumerate(User.objects.all())
})
formset = self.NormalFormset(data, queryset=User.objects.all())
self.assertTrue(formset.is_valid())
self.assertEqual(len(formset.save()), 0)
self.assertEqual(len(User.objects.all()), 4)
def test_all_delete(self):
""" Verify base formset honors DELETE field """
# reload database
self.test_init_database()
# create data dict with all fields marked for deletion
data = dict(self.data)
data['form-INITIAL_FORMS'] = 4
data.update({
'form-%d-id' % i: user.pk
for i, user in enumerate(User.objects.all())
})
data.update(self.delete_all_ids)
formset = self.NormalFormset(data, queryset=User.objects.all())
self.assertTrue(formset.is_valid())
self.assertEqual(len(formset.save()), 0)
self.assertEqual(len(User.objects.all()), 0)
def test_custom_delete(self):
""" Verify DeleteFormset ignores DELETE field and uses form method """
# reload database
self.test_init_database()
# Create formset with custom Delete function
# create data dict with all fields marked for deletion
data = dict(self.data)
data['form-INITIAL_FORMS'] = 4
data.update({
'form-%d-id' % i: user.pk
for i, user in enumerate(User.objects.all())
})
data.update(self.delete_all_ids)
formset = self.DeleteFormset(data, queryset=User.objects.all())
# verify two were deleted
self.assertTrue(formset.is_valid())
self.assertEqual(len(formset.save()), 0)
self.assertEqual(len(User.objects.all()), 2)
# verify no "odd" PKs left
odd_ids = [user.pk for user in User.objects.all() if user.pk % 2]
self.assertEqual(len(odd_ids), 0)
class RedeleteTests(TestCase):
def test_resubmit(self):
u = User.objects.create(username='foo', serial=1)
us = UserSite.objects.create(user=u, data=7)
formset_cls = inlineformset_factory(User, UserSite, fields="__all__")
data = {
'serial': '1',
'username': 'foo',
'usersite_set-TOTAL_FORMS': '1',
'usersite_set-INITIAL_FORMS': '1',
'usersite_set-MAX_NUM_FORMS': '1',
'usersite_set-0-id': six.text_type(us.pk),
'usersite_set-0-data': '7',
'usersite_set-0-user': 'foo',
'usersite_set-0-DELETE': '1'
}
formset = formset_cls(data, instance=u)
self.assertTrue(formset.is_valid())
formset.save()
self.assertEqual(UserSite.objects.count(), 0)
formset = formset_cls(data, instance=u)
# Even if the "us" object isn't in the DB any more, the form
# validates.
self.assertTrue(formset.is_valid())
formset.save()
self.assertEqual(UserSite.objects.count(), 0)
def test_delete_already_deleted(self):
u = User.objects.create(username='foo', serial=1)
us = UserSite.objects.create(user=u, data=7)
formset_cls = inlineformset_factory(User, UserSite, fields="__all__")
data = {
'serial': '1',
'username': 'foo',
'usersite_set-TOTAL_FORMS': '1',
'usersite_set-INITIAL_FORMS': '1',
'usersite_set-MAX_NUM_FORMS': '1',
'usersite_set-0-id': six.text_type(us.pk),
'usersite_set-0-data': '7',
'usersite_set-0-user': 'foo',
'usersite_set-0-DELETE': '1'
}
formset = formset_cls(data, instance=u)
us.delete()
self.assertTrue(formset.is_valid())
formset.save()
self.assertEqual(UserSite.objects.count(), 0)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
31033,
492,
12355,
31133,
63,
8609,
63,
2339,
12,
3523,
14736,
199,
504,
1639,
14,
3351,
14,
992,
492,
334,
272,
3523,
1685,
14736,
12,
8308,
10724,
63,
3702,
12,
29312,
63,
3702,
12,
272,
29312,
409,
63,
3702,
12,
199,
9,
199,
504,
1639,
14,
3351,
14,
1208,
492,
4520,
2141,
12,
4520,
1296,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
992,
492,
334,
272,
10891,
12,
13537,
12,
7220,
12,
14386,
4491,
12,
799,
14436,
12,
2876,
12,
19037,
12,
272,
2876,
8972,
12,
199,
9,
421,
199,
533,
24789,
2821,
409,
2925,
8,
1746,
304,
272,
347,
511,
63,
10724,
63,
1883,
63,
475,
63,
698,
8,
277,
304,
267,
298,
33,
11068,
1806,
282,
12718,
543,
282,
370,
63,
698,
883,
506,
6290,
14,
13262,
367,
327,
7727,
19,
2,
267,
8204,
275,
29312,
63,
3702,
8,
1899,
12,
1504,
628,
363,
452,
18617,
267,
25260,
275,
8308,
10724,
63,
3702,
8,
1899,
12,
2876,
8972,
12,
1504,
628,
363,
452,
18617,
398,
327,
32092,
314,
8204,
436,
25260,
370,
557,
432,
267,
327,
1265,
883,
1218,
282,
1824,
543,
949,
666,
267,
1824,
275,
8204,
342,
267,
1824,
63,
409,
275,
25260,
8,
842,
29,
1899,
1012,
398,
327,
7356,
1218,
282,
892,
2876,
436,
2876,
8972,
1256,
267,
666,
275,
469,
288,
283,
2171,
356,
283,
17,
297,
288,
283,
2473,
356,
283,
439,
393,
320,
969,
297,
288,
283,
30178,
63,
409,
13,
15386,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
13768,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
4283,
63,
7125,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
576,
356,
283,
709,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
751,
356,
283,
439,
393,
320,
969,
7,
267,
789,
267,
922,
275,
2876,
342,
267,
1824,
275,
8204,
8,
576,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
922,
275,
1824,
14,
2117,
342,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
1824,
2689,
83,
7,
450,
1824,
63,
409,
9,
398,
1824,
63,
409,
275,
25260,
8,
576,
12,
1256,
29,
751,
9,
267,
340,
1824,
63,
409,
14,
374,
63,
1078,
837,
288,
1824,
63,
409,
14,
2117,
342,
288,
922,
2124,
275,
2876,
8972,
14,
1462,
14,
452,
1252,
1459,
342,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
576,
995,
1616,
9,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
11068,
2689,
83,
7,
450,
1824,
63,
409,
14,
2550,
9,
398,
327,
7356,
1678,
314,
2876,
8972,
1256,
267,
666,
275,
469,
288,
283,
30178,
63,
409,
13,
15386,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
13768,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
4283,
63,
7125,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
344,
356,
3816,
14,
505,
63,
466,
8,
30178,
59,
16,
2733,
344,
3815,
288,
283,
30178,
63,
409,
13,
16,
13,
576,
356,
283,
845,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
751,
356,
283,
439,
393,
320,
969,
7,
267,
789,
267,
1824,
63,
409,
275,
25260,
8,
576,
12,
1256,
29,
751,
9,
267,
340,
1824,
63,
409,
14,
374,
63,
1078,
837,
288,
1824,
63,
409,
14,
2117,
342,
288,
922,
2124,
275,
2876,
8972,
14,
1462,
14,
452,
1252,
1459,
342,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
576,
995,
4119,
9,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
11068,
2689,
83,
7,
450,
1824,
63,
409,
14,
2550,
9,
398,
327,
7356,
1050,
282,
892,
2876,
8972,
1256,
267,
666,
275,
469,
288,
283,
30178,
63,
409,
13,
15386,
63,
11518,
356,
283,
18,
297,
288,
283,
30178,
63,
409,
13,
13768,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
4283,
63,
7125,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
344,
356,
3816,
14,
505,
63,
466,
8,
30178,
59,
16,
2733,
344,
3815,
288,
283,
30178,
63,
409,
13,
16,
13,
576,
356,
283,
845,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
751,
356,
283,
439,
393,
320,
969,
297,
288,
283,
30178,
63,
409,
13,
17,
13,
576,
356,
283,
2260,
297,
288,
283,
30178,
63,
409,
13,
17,
13,
751,
356,
283,
439,
393,
320,
969,
7,
267,
789,
267,
1824,
63,
409,
275,
25260,
8,
576,
12,
1256,
29,
751,
9,
267,
340,
1824,
63,
409,
14,
374,
63,
1078,
837,
288,
1824,
63,
409,
14,
2117,
342,
288,
922,
2124,
275,
2876,
8972,
14,
1462,
14,
452,
1252,
1459,
1252,
1648,
63,
991,
360,
576,
358,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
576,
995,
4119,
9,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
288,
291,
14,
629,
8,
30178,
59,
17,
2733,
576,
995,
5685,
9,
288,
291,
14,
629,
8,
30178,
59,
17,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
11068,
2689,
83,
7,
450,
1824,
63,
409,
14,
2550,
9,
339,
347,
511,
63,
10724,
63,
1883,
63,
17571,
63,
1238,
8,
277,
304,
267,
298,
33,
11068,
1806,
282,
12718,
543,
282,
370,
63,
698,
883,
506,
6290,
14,
13262,
367,
327,
845,
6708,
2,
267,
8204,
275,
29312,
63,
3702,
8,
32075,
12,
1504,
628,
363,
452,
18617,
267,
25260,
275,
8308,
10724,
63,
3702,
8,
32075,
12,
13537,
12,
1504,
628,
363,
452,
18617,
398,
327
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
31033,
492,
12355,
31133,
63,
8609,
63,
2339,
12,
3523,
14736,
199,
504,
1639,
14,
3351,
14,
992,
492,
334,
272,
3523,
1685,
14736,
12,
8308,
10724,
63,
3702,
12,
29312,
63,
3702,
12,
272,
29312,
409,
63,
3702,
12,
199,
9,
199,
504,
1639,
14,
3351,
14,
1208,
492,
4520,
2141,
12,
4520,
1296,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
992,
492,
334,
272,
10891,
12,
13537,
12,
7220,
12,
14386,
4491,
12,
799,
14436,
12,
2876,
12,
19037,
12,
272,
2876,
8972,
12,
199,
9,
421,
199,
533,
24789,
2821,
409,
2925,
8,
1746,
304,
272,
347,
511,
63,
10724,
63,
1883,
63,
475,
63,
698,
8,
277,
304,
267,
298,
33,
11068,
1806,
282,
12718,
543,
282,
370,
63,
698,
883,
506,
6290,
14,
13262,
367,
327,
7727,
19,
2,
267,
8204,
275,
29312,
63,
3702,
8,
1899,
12,
1504,
628,
363,
452,
18617,
267,
25260,
275,
8308,
10724,
63,
3702,
8,
1899,
12,
2876,
8972,
12,
1504,
628,
363,
452,
18617,
398,
327,
32092,
314,
8204,
436,
25260,
370,
557,
432,
267,
327,
1265,
883,
1218,
282,
1824,
543,
949,
666,
267,
1824,
275,
8204,
342,
267,
1824,
63,
409,
275,
25260,
8,
842,
29,
1899,
1012,
398,
327,
7356,
1218,
282,
892,
2876,
436,
2876,
8972,
1256,
267,
666,
275,
469,
288,
283,
2171,
356,
283,
17,
297,
288,
283,
2473,
356,
283,
439,
393,
320,
969,
297,
288,
283,
30178,
63,
409,
13,
15386,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
13768,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
4283,
63,
7125,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
576,
356,
283,
709,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
751,
356,
283,
439,
393,
320,
969,
7,
267,
789,
267,
922,
275,
2876,
342,
267,
1824,
275,
8204,
8,
576,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
922,
275,
1824,
14,
2117,
342,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
1824,
2689,
83,
7,
450,
1824,
63,
409,
9,
398,
1824,
63,
409,
275,
25260,
8,
576,
12,
1256,
29,
751,
9,
267,
340,
1824,
63,
409,
14,
374,
63,
1078,
837,
288,
1824,
63,
409,
14,
2117,
342,
288,
922,
2124,
275,
2876,
8972,
14,
1462,
14,
452,
1252,
1459,
342,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
576,
995,
1616,
9,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
11068,
2689,
83,
7,
450,
1824,
63,
409,
14,
2550,
9,
398,
327,
7356,
1678,
314,
2876,
8972,
1256,
267,
666,
275,
469,
288,
283,
30178,
63,
409,
13,
15386,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
13768,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
4283,
63,
7125,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
344,
356,
3816,
14,
505,
63,
466,
8,
30178,
59,
16,
2733,
344,
3815,
288,
283,
30178,
63,
409,
13,
16,
13,
576,
356,
283,
845,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
751,
356,
283,
439,
393,
320,
969,
7,
267,
789,
267,
1824,
63,
409,
275,
25260,
8,
576,
12,
1256,
29,
751,
9,
267,
340,
1824,
63,
409,
14,
374,
63,
1078,
837,
288,
1824,
63,
409,
14,
2117,
342,
288,
922,
2124,
275,
2876,
8972,
14,
1462,
14,
452,
1252,
1459,
342,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
576,
995,
4119,
9,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
11068,
2689,
83,
7,
450,
1824,
63,
409,
14,
2550,
9,
398,
327,
7356,
1050,
282,
892,
2876,
8972,
1256,
267,
666,
275,
469,
288,
283,
30178,
63,
409,
13,
15386,
63,
11518,
356,
283,
18,
297,
288,
283,
30178,
63,
409,
13,
13768,
63,
11518,
356,
283,
17,
297,
288,
283,
30178,
63,
409,
13,
4283,
63,
7125,
63,
11518,
356,
283,
16,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
344,
356,
3816,
14,
505,
63,
466,
8,
30178,
59,
16,
2733,
344,
3815,
288,
283,
30178,
63,
409,
13,
16,
13,
576,
356,
283,
845,
297,
288,
283,
30178,
63,
409,
13,
16,
13,
751,
356,
283,
439,
393,
320,
969,
297,
288,
283,
30178,
63,
409,
13,
17,
13,
576,
356,
283,
2260,
297,
288,
283,
30178,
63,
409,
13,
17,
13,
751,
356,
283,
439,
393,
320,
969,
7,
267,
789,
267,
1824,
63,
409,
275,
25260,
8,
576,
12,
1256,
29,
751,
9,
267,
340,
1824,
63,
409,
14,
374,
63,
1078,
837,
288,
1824,
63,
409,
14,
2117,
342,
288,
922,
2124,
275,
2876,
8972,
14,
1462,
14,
452,
1252,
1459,
1252,
1648,
63,
991,
360,
576,
358,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
576,
995,
4119,
9,
288,
291,
14,
629,
8,
30178,
59,
16,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
288,
291,
14,
629,
8,
30178,
59,
17,
2733,
576,
995,
5685,
9,
288,
291,
14,
629,
8,
30178,
59,
17,
2733,
751,
63,
344,
995,
283,
439,
393,
320,
969,
358,
267,
587,
26,
288,
291,
14,
1633,
360,
9298,
1911,
641,
11068,
2689,
83,
7,
450,
1824,
63,
409,
14,
2550,
9,
339,
347,
511,
63,
10724,
63,
1883,
63,
17571,
63,
1238,
8,
277,
304,
267,
298,
33,
11068,
1806,
282,
12718,
543,
282,
370,
63,
698,
883,
506,
6290,
14,
13262,
367,
327,
845,
6708,
2,
267,
8204,
275,
29312,
63,
3702,
8,
32075,
12,
1504,
628,
363,
452,
18617,
267,
25260,
275,
8308,
10724,
63,
3702,
8,
32075,
12,
13537,
12,
1504,
628,
363,
452,
18617,
398,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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/>.
#
# USAGE: {{ lookup('hashi_vault', 'secret=secret/hello:value token=c975b780-d1be-8016-866b-01d0f9b688a5 url=http://myvault:8200')}}
#
# You can skip setting the url if you set the VAULT_ADDR environment variable
# or if you want it to default to localhost:8200
#
# NOTE: Due to a current limitation in the HVAC library there won't
# necessarily be an error if a bad endpoint is specified.
#
# Requires hvac library. Install with pip.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
ANSIBLE_HASHI_VAULT_ADDR = 'http://127.0.0.1:8200'
if os.getenv('VAULT_ADDR') is not None:
ANSIBLE_HASHI_VAULT_ADDR = os.environ['VAULT_ADDR']
class HashiVault:
def __init__(self, **kwargs):
try:
import hvac
except ImportError:
raise AnsibleError("Please pip install hvac to use this module")
self.url = kwargs.get('url', ANSIBLE_HASHI_VAULT_ADDR)
self.token = kwargs.get('token')
if self.token==None:
raise AnsibleError("No Vault Token specified")
# split secret arg, which has format 'secret/hello:value' into secret='secret/hello' and secret_field='value'
s = kwargs.get('secret')
if s==None:
raise AnsibleError("No secret specified")
s_f = s.split(':')
self.secret = s_f[0]
if len(s_f)>=2:
self.secret_field = s_f[1]
else:
self.secret_field = 'value'
self.client = hvac.Client(url=self.url, token=self.token)
if self.client.is_authenticated():
pass
else:
raise AnsibleError("Invalid Hashicorp Vault Token Specified")
def get(self):
data = self.client.read(self.secret)
if data is None:
raise AnsibleError("The secret %s doesn't seem to exist" % self.secret)
if self.secret_field=='': # secret was specified with trailing ':'
return data['data']
if self.secret_field not in data['data']:
raise AnsibleError("The secret %s does not contain the field '%s'. " % (self.secret, self.secret_field))
return data['data'][self.secret_field]
class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
vault_args = terms[0].split(' ')
vault_dict = {}
ret = []
for param in vault_args:
try:
key, value = param.split('=')
except ValueError as e:
raise AnsibleError("hashi_vault plugin needs key=value pairs, but received %s" % terms)
vault_dict[key] = value
vault_conn = HashiVault(**vault_dict)
for term in terms:
key = term.split()[0]
value = vault_conn.get()
ret.append(value)
return ret
|
gpl-3.0
|
[
3,
334,
67,
9,
6900,
12,
1603,
265,
1619,
290,
577,
1214,
25330,
665,
74,
31496,
25330,
8,
292,
9,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
19635,
2962,
26,
8448,
4237,
360,
2227,
73,
63,
10077,
297,
283,
4731,
29,
4731,
15,
5006,
26,
585,
1526,
29,
67,
28947,
66,
31829,
13,
68,
17,
1235,
13,
24,
10882,
13,
13465,
66,
13,
614,
68,
16,
70,
25,
66,
27697,
65,
21,
1166,
29,
1014,
921,
1662,
10077,
26,
24,
1840,
358,
4863,
199,
3,
199,
3,
2047,
883,
3372,
4260,
314,
1166,
340,
1265,
663,
314,
812,
33,
2233,
63,
7803,
3734,
1750,
199,
3,
503,
340,
1265,
2934,
652,
370,
849,
370,
11667,
26,
24,
1840,
199,
3,
199,
3,
6944,
26,
25855,
370,
282,
1453,
12305,
315,
314,
869,
26780,
3555,
2337,
7859,
1133,
199,
3,
20513,
506,
376,
1125,
340,
282,
4875,
6037,
365,
2013,
14,
199,
3,
199,
3,
15127,
394,
15367,
3555,
14,
13276,
543,
7305,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
421,
199,
8490,
63,
14395,
41,
63,
15162,
2233,
63,
7803,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
24,
1840,
7,
199,
199,
692,
747,
14,
12959,
360,
15162,
2233,
63,
7803,
358,
365,
440,
488,
26,
272,
32271,
7187,
63,
14395,
41,
63,
15162,
2233,
63,
7803,
275,
747,
14,
2314,
459,
15162,
2233,
63,
7803,
418,
199,
199,
533,
16101,
73,
20229,
26,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
862,
26,
288,
492,
394,
15367,
267,
871,
3545,
26,
288,
746,
13358,
480,
8254,
7305,
3907,
394,
15367,
370,
675,
642,
859,
531,
398,
291,
14,
633,
275,
2074,
14,
362,
360,
633,
297,
32271,
7187,
63,
14395,
41,
63,
15162,
2233,
63,
7803,
9,
10631,
291,
14,
1418,
275,
2074,
14,
362,
360,
1418,
358,
267,
340,
291,
14,
1418,
389,
403,
26,
288,
746,
13358,
480,
1944,
812,
558,
8767,
2013,
531,
2728,
327,
3715,
7565,
1680,
12,
1314,
965,
1475,
283,
4731,
15,
5006,
26,
585,
7,
1901,
7565,
534,
4731,
15,
5006,
7,
436,
7565,
63,
698,
534,
585,
7,
267,
308,
275,
2074,
14,
362,
360,
4731,
358,
267,
340,
308,
389,
403,
26,
288,
746,
13358,
480,
1944,
7565,
2013,
531,
398,
308,
63,
70,
275,
308,
14,
1294,
11633,
267,
291,
14,
4731,
275,
308,
63,
70,
59,
16,
61,
267,
340,
822,
8,
83,
63,
70,
9,
8119,
18,
26,
288,
291,
14,
4731,
63,
698,
275,
308,
63,
70,
59,
17,
61,
267,
587,
26,
288,
291,
14,
4731,
63,
698,
275,
283,
585,
7,
398,
291,
14,
1258,
275,
394,
15367,
14,
3041,
8,
633,
29,
277,
14,
633,
12,
1526,
29,
277,
14,
1418,
9,
398,
340,
291,
14,
1258,
14,
374,
63,
12177,
837,
288,
986,
267,
587,
26,
288,
746,
13358,
480,
3364,
16101,
530,
269,
80,
812,
558,
8767,
5367,
1290,
531,
339,
347,
664,
8,
277,
304,
267,
666,
275,
291,
14,
1258,
14,
739,
8,
277,
14,
4731,
9,
267,
340,
666,
365,
488,
26,
288,
746,
13358,
480,
1918,
7565,
450,
83,
3181,
1133,
17021,
370,
2187,
2,
450,
291,
14,
4731,
9,
2728,
340,
291,
14,
4731,
63,
698,
6803,
356,
327,
7565,
1990,
2013,
543,
8520,
10871,
288,
372,
666,
459,
576,
418,
2728,
340,
291,
14,
4731,
63,
698,
440,
315,
666,
459,
576,
2565,
288,
746,
13358,
480,
1918,
7565,
450,
83,
1630,
440,
1395,
314,
901,
1543,
83,
1370,
298,
450,
334,
277,
14,
4731,
12,
291,
14,
4731,
63,
698,
430,
2728,
372,
666,
459,
576,
3488,
277,
14,
4731,
63,
698,
61,
421,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
272,
347,
1255,
8,
277,
12,
2895,
12,
2860,
12,
1011,
958,
304,
267,
12738,
63,
589,
275,
2895,
59,
16,
1055,
1294,
360,
5320,
267,
12738,
63,
807,
275,
1052,
267,
2203,
275,
942,
398,
367,
1215,
315,
12738,
63,
589,
26,
288,
862,
26,
355,
790,
12,
574,
275,
1215,
14,
1294,
23917,
288,
871,
1722,
465,
325,
26,
355,
746,
13358,
480,
2227,
73,
63,
10077,
3589,
4839,
790,
29,
585,
6342,
12,
1325,
3086,
450,
83,
2,
450,
2895,
9,
288,
12738,
63,
807,
59,
498,
61,
275,
574,
398,
12738,
63,
1631,
275,
16101,
73,
20229,
3682,
10077,
63,
807,
9,
398,
367,
6707,
315,
2895,
26,
1779,
790,
275,
6707,
14,
1294,
3430,
16,
61,
1779,
574,
275,
12738,
63,
1631,
14,
362,
342,
1779,
2203,
14,
740,
8,
585,
9,
288,
267,
372,
2203,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6900,
12,
1603,
265,
1619,
290,
577,
1214,
25330,
665,
74,
31496,
25330,
8,
292,
9,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
19635,
2962,
26,
8448,
4237,
360,
2227,
73,
63,
10077,
297,
283,
4731,
29,
4731,
15,
5006,
26,
585,
1526,
29,
67,
28947,
66,
31829,
13,
68,
17,
1235,
13,
24,
10882,
13,
13465,
66,
13,
614,
68,
16,
70,
25,
66,
27697,
65,
21,
1166,
29,
1014,
921,
1662,
10077,
26,
24,
1840,
358,
4863,
199,
3,
199,
3,
2047,
883,
3372,
4260,
314,
1166,
340,
1265,
663,
314,
812,
33,
2233,
63,
7803,
3734,
1750,
199,
3,
503,
340,
1265,
2934,
652,
370,
849,
370,
11667,
26,
24,
1840,
199,
3,
199,
3,
6944,
26,
25855,
370,
282,
1453,
12305,
315,
314,
869,
26780,
3555,
2337,
7859,
1133,
199,
3,
20513,
506,
376,
1125,
340,
282,
4875,
6037,
365,
2013,
14,
199,
3,
199,
3,
15127,
394,
15367,
3555,
14,
13276,
543,
7305,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
421,
199,
8490,
63,
14395,
41,
63,
15162,
2233,
63,
7803,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
24,
1840,
7,
199,
199,
692,
747,
14,
12959,
360,
15162,
2233,
63,
7803,
358,
365,
440,
488,
26,
272,
32271,
7187,
63,
14395,
41,
63,
15162,
2233,
63,
7803,
275,
747,
14,
2314,
459,
15162,
2233,
63,
7803,
418,
199,
199,
533,
16101,
73,
20229,
26,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
862,
26,
288,
492,
394,
15367,
267,
871,
3545,
26,
288,
746,
13358,
480,
8254,
7305,
3907,
394,
15367,
370,
675,
642,
859,
531,
398,
291,
14,
633,
275,
2074,
14,
362,
360,
633,
297,
32271,
7187,
63,
14395,
41,
63,
15162,
2233,
63,
7803,
9,
10631,
291,
14,
1418,
275,
2074,
14,
362,
360,
1418,
358,
267,
340,
291,
14,
1418,
389,
403,
26,
288,
746,
13358,
480,
1944,
812,
558,
8767,
2013,
531,
2728,
327,
3715,
7565,
1680,
12,
1314,
965,
1475,
283,
4731,
15,
5006,
26,
585,
7,
1901,
7565,
534,
4731,
15,
5006,
7,
436,
7565,
63,
698,
534,
585,
7,
267,
308,
275,
2074,
14,
362,
360,
4731,
358,
267,
340,
308,
389,
403,
26,
288,
746,
13358,
480,
1944,
7565,
2013,
531,
398,
308,
63,
70,
275,
308,
14,
1294,
11633,
267,
291,
14,
4731,
275,
308,
63,
70,
59,
16,
61,
267,
340,
822,
8,
83,
63,
70,
9,
8119,
18,
26,
288,
291,
14,
4731,
63,
698,
275,
308,
63,
70,
59,
17,
61,
267,
587,
26,
288,
291,
14,
4731,
63,
698,
275,
283,
585,
7,
398,
291,
14,
1258,
275,
394,
15367,
14,
3041,
8,
633,
29,
277,
14,
633,
12,
1526,
29,
277,
14,
1418,
9,
398,
340,
291,
14,
1258,
14,
374,
63,
12177,
837,
288,
986,
267,
587,
26,
288,
746,
13358,
480,
3364,
16101,
530,
269,
80,
812,
558,
8767,
5367,
1290,
531,
339,
347,
664,
8,
277,
304,
267,
666,
275,
291,
14,
1258,
14,
739,
8,
277,
14,
4731,
9,
267,
340,
666,
365,
488,
26,
288,
746,
13358,
480,
1918,
7565,
450,
83,
3181,
1133,
17021,
370,
2187,
2,
450,
291,
14,
4731,
9,
2728,
340,
291,
14,
4731,
63,
698,
6803,
356,
327,
7565,
1990,
2013,
543,
8520,
10871,
288,
372,
666,
459,
576,
418,
2728,
340,
291,
14,
4731,
63,
698,
440,
315,
666,
459,
576,
2565,
288,
746,
13358,
480,
1918,
7565,
450,
83,
1630,
440,
1395,
314,
901,
1543,
83,
1370,
298,
450,
334,
277,
14,
4731,
12,
291,
14,
4731,
63,
698,
430,
2728,
372,
666,
459,
576,
3488,
277,
14,
4731,
63,
698,
61,
421,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
272,
347,
1255,
8,
277,
12,
2895,
12,
2860,
12,
1011,
958,
304,
267,
12738,
63,
589,
275,
2895,
59,
16,
1055,
1294,
360,
5320,
267,
12738,
63,
807,
275,
1052,
267,
2203,
275,
942,
398,
367,
1215,
315,
12738,
63,
589,
26,
288,
862,
26,
355,
790,
12,
574,
275,
1215,
14,
1294,
23917,
288,
871,
1722,
465,
325,
26,
355,
746,
13358,
480,
2227,
73,
63,
10077,
3589,
4839,
790,
29,
585,
6342,
12,
1325,
3086,
450,
83,
2,
450,
2895,
9,
288,
12738,
63,
807,
59,
498,
61,
275,
574,
398,
12738,
63,
1631,
275,
16101,
73,
20229,
3682,
10077,
63,
807,
9,
398,
367,
6707,
315,
2895,
26,
1779,
790,
275,
6707,
14,
1294,
3430,
16,
61,
1779,
574,
275,
12738,
63,
1631,
14,
362,
342,
1779,
2203,
14,
740,
8,
585,
9,
288,
267,
372,
2203,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
PaulWay/spacewalk
|
client/solaris/rhnclient/rhn/actions/__init__.py
|
2
|
1886
|
"""Export allowable xmlrpc actions and do_call method"""
# RHN Action exporter
# Copyright (c) 1999--2013 Red Hat, Inc. Distributed under GPL.
def do_call(method, params):
"""Find and execute an allowable xmlrpc method.
<method> format is "ACTION_FILE.METHOD_NAME"."""
parts = method.split(".")
if len(parts) != 2:
raise AttributeError("Invalid action syntax: '%s'" % method)
try:
func = getattr(globals()[parts[0]], parts[1])
except:
raise AttributeError("Action '%s' not found" % method)
return apply(func, params)
class Action:
def __init__(self, module):
# Action module must contain __rhnexport__
for export in getattr(module, "__rhnexport__"):
setattr(self, export, getattr(module, export))
def setup():
import os, sys
actions_dir = os.path.dirname(sys.modules[__name__].__file__) or '.'
if actions_dir not in sys.path:
sys.path.append(actions_dir)
#if __debug__: print "actions_dir: %s" % actions_dir
for file in [x[:-3] for x in os.listdir(actions_dir) if x.endswith(".py")]:
if file == "__init__": continue
try:
# Import each python file
mod = __import__(file, globals())
del globals()[file]
# Create a namespace for it
globals()[file] = Action(mod)
#if __debug__: print "SUCCESS importing action module: %s" % file
except Exception, e:
# Remove incomplete imports
if file in globals():
del globals()[file]
#if __debug__: print "FAILURE importing action module: %s, %s" % (file, str(e))
continue
# Clean-up module namespace
del globals()["setup"]
del globals()["Action"]
# preload all available actions modules and action mehtods on import
if __name__ != "__main__":
setup()
|
gpl-2.0
|
[
624,
11399,
32518,
15432,
5445,
436,
886,
63,
1250,
1083,
624,
199,
199,
3,
820,
23084,
10033,
1437,
3968,
199,
3,
1898,
334,
67,
9,
21300,
306,
6965,
9572,
13002,
12,
3277,
14,
221,
17484,
1334,
14629,
14,
199,
199,
318,
886,
63,
1250,
8,
765,
12,
1862,
304,
272,
408,
6591,
436,
5341,
376,
32518,
15432,
1083,
14,
272,
665,
765,
30,
1475,
365,
298,
10052,
63,
3817,
14,
9977,
63,
2339,
2,
1041,
339,
4184,
275,
1083,
14,
1294,
15857,
272,
340,
822,
8,
4181,
9,
1137,
499,
26,
267,
746,
4281,
480,
3364,
1595,
6302,
26,
1543,
83,
4065,
450,
1083,
9,
272,
862,
26,
267,
2562,
275,
2519,
8,
8473,
3430,
4181,
59,
16,
2365,
4184,
59,
17,
566,
272,
871,
26,
267,
746,
4281,
480,
3310,
1543,
83,
7,
440,
1911,
2,
450,
1083,
9,
272,
372,
4838,
8,
1532,
12,
1862,
9,
421,
199,
533,
10033,
26,
272,
347,
636,
826,
721,
277,
12,
859,
304,
267,
327,
10033,
859,
1471,
1395,
636,
82,
6164,
3790,
363,
267,
367,
4843,
315,
2519,
8,
578,
12,
4396,
82,
6164,
3790,
363,
2349,
288,
5371,
8,
277,
12,
4843,
12,
2519,
8,
578,
12,
4843,
430,
421,
199,
318,
3272,
837,
272,
492,
747,
12,
984,
339,
5445,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3112,
28894,
354,
363,
17979,
493,
3368,
503,
7815,
272,
340,
5445,
63,
694,
440,
315,
984,
14,
515,
26,
267,
984,
14,
515,
14,
740,
8,
3723,
63,
694,
9,
272,
327,
692,
636,
1757,
10651,
870,
298,
3723,
63,
694,
26,
450,
83,
2,
450,
5445,
63,
694,
339,
367,
570,
315,
359,
88,
4439,
19,
61,
367,
671,
315,
747,
14,
7374,
8,
3723,
63,
694,
9,
340,
671,
14,
4130,
9520,
647,
531,
2189,
267,
340,
570,
508,
4396,
826,
5727,
1980,
267,
862,
26,
288,
327,
3161,
1924,
2366,
570,
288,
3413,
275,
636,
646,
721,
493,
12,
7992,
1012,
288,
2150,
7992,
3430,
493,
61,
288,
327,
2790,
282,
3231,
367,
652,
288,
7992,
3430,
493,
61,
275,
10033,
8,
1494,
9,
288,
327,
692,
636,
1757,
10651,
870,
298,
12779,
16306,
1595,
859,
26,
450,
83,
2,
450,
570,
267,
871,
2186,
12,
325,
26,
288,
327,
5852,
17110,
8925,
288,
340,
570,
315,
7992,
837,
355,
2150,
7992,
3430,
493,
61,
288,
327,
692,
636,
1757,
10651,
870,
298,
13989,
16306,
1595,
859,
26,
450,
83,
12,
450,
83,
2,
450,
334,
493,
12,
620,
8,
69,
430,
288,
1980,
339,
327,
12762,
13,
384,
859,
3231,
272,
2150,
7992,
22957,
2758,
937,
272,
2150,
7992,
22957,
3310,
937,
421,
199,
3,
32511,
1006,
2808,
5445,
4621,
436,
1595,
562,
517,
364,
83,
641,
492,
199,
692,
636,
354,
363,
1137,
4396,
973,
5727,
272,
3272,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11399,
32518,
15432,
5445,
436,
886,
63,
1250,
1083,
624,
199,
199,
3,
820,
23084,
10033,
1437,
3968,
199,
3,
1898,
334,
67,
9,
21300,
306,
6965,
9572,
13002,
12,
3277,
14,
221,
17484,
1334,
14629,
14,
199,
199,
318,
886,
63,
1250,
8,
765,
12,
1862,
304,
272,
408,
6591,
436,
5341,
376,
32518,
15432,
1083,
14,
272,
665,
765,
30,
1475,
365,
298,
10052,
63,
3817,
14,
9977,
63,
2339,
2,
1041,
339,
4184,
275,
1083,
14,
1294,
15857,
272,
340,
822,
8,
4181,
9,
1137,
499,
26,
267,
746,
4281,
480,
3364,
1595,
6302,
26,
1543,
83,
4065,
450,
1083,
9,
272,
862,
26,
267,
2562,
275,
2519,
8,
8473,
3430,
4181,
59,
16,
2365,
4184,
59,
17,
566,
272,
871,
26,
267,
746,
4281,
480,
3310,
1543,
83,
7,
440,
1911,
2,
450,
1083,
9,
272,
372,
4838,
8,
1532,
12,
1862,
9,
421,
199,
533,
10033,
26,
272,
347,
636,
826,
721,
277,
12,
859,
304,
267,
327,
10033,
859,
1471,
1395,
636,
82,
6164,
3790,
363,
267,
367,
4843,
315,
2519,
8,
578,
12,
4396,
82,
6164,
3790,
363,
2349,
288,
5371,
8,
277,
12,
4843,
12,
2519,
8,
578,
12,
4843,
430,
421,
199,
318,
3272,
837,
272,
492,
747,
12,
984,
339,
5445,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3112,
28894,
354,
363,
17979,
493,
3368,
503,
7815,
272,
340,
5445,
63,
694,
440,
315,
984,
14,
515,
26,
267,
984,
14,
515,
14,
740,
8,
3723,
63,
694,
9,
272,
327,
692,
636,
1757,
10651,
870,
298,
3723,
63,
694,
26,
450,
83,
2,
450,
5445,
63,
694,
339,
367,
570,
315,
359,
88,
4439,
19,
61,
367,
671,
315,
747,
14,
7374,
8,
3723,
63,
694,
9,
340,
671,
14,
4130,
9520,
647,
531,
2189,
267,
340,
570,
508,
4396,
826,
5727,
1980,
267,
862,
26,
288,
327,
3161,
1924,
2366,
570,
288,
3413,
275,
636,
646,
721,
493,
12,
7992,
1012,
288,
2150,
7992,
3430,
493,
61,
288,
327,
2790,
282,
3231,
367,
652,
288,
7992,
3430,
493,
61,
275,
10033,
8,
1494,
9,
288,
327,
692,
636,
1757,
10651,
870,
298,
12779,
16306,
1595,
859,
26,
450,
83,
2,
450,
570,
267,
871,
2186,
12,
325,
26,
288,
327,
5852,
17110,
8925,
288,
340,
570,
315,
7992,
837,
355,
2150,
7992,
3430,
493,
61,
288,
327,
692,
636,
1757,
10651,
870,
298,
13989,
16306,
1595,
859,
26,
450,
83,
12,
450,
83,
2,
450,
334,
493,
12,
620,
8,
69,
430,
288,
1980,
339,
327,
12762,
13,
384,
859,
3231,
272,
2150,
7992,
22957,
2758,
937,
272,
2150,
7992,
22957,
3310,
937,
421,
199,
3,
32511,
1006,
2808,
5445,
4621,
436,
1595,
562,
517,
364,
83,
641,
492,
199,
692,
636,
354,
363,
1137,
4396,
973,
5727,
272,
3272,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
scotthartbti/android_external_chromium_org
|
tools/telemetry/telemetry/core/backends/chrome/extension_dict_backend.py
|
23
|
2641
|
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
import re
import weakref
from telemetry.core import extension_page
from telemetry.core.backends.chrome import inspector_backend
class ExtensionNotFoundException(Exception):
pass
class ExtensionDictBackend(object):
def __init__(self, browser_backend):
self._browser_backend = browser_backend
# Maps extension ids to ExtensionPage objects.
self._extension_dict = weakref.WeakValueDictionary()
def __getitem__(self, extension_id):
extension_object = self._extension_dict.get(extension_id)
if not extension_object:
extension_object = self._CreateExtensionObject(extension_id)
assert extension_object
self._extension_dict[extension_id] = extension_object
return extension_object
def __contains__(self, extension_id):
return extension_id in self.GetExtensionIds()
@staticmethod
def _ExtractExtensionId(url):
m = re.match(r"(chrome-extension://)([^/]+)", url)
assert m
return m.group(2)
@staticmethod
def _GetExtensionId(extension_info):
if 'url' not in extension_info:
return None
return ExtensionDictBackend._ExtractExtensionId(extension_info['url'])
def _CreateExtensionObject(self, extension_id):
extension_info = self._FindExtensionInfo(extension_id)
if not extension_info or not 'webSocketDebuggerUrl' in extension_info:
raise ExtensionNotFoundException()
return extension_page.ExtensionPage(
extension_id,
extension_info['url'],
self._CreateInspectorBackendForDebuggerUrl(
extension_info['webSocketDebuggerUrl']))
def _CreateInspectorBackendForDebuggerUrl(self, debugger_url):
return inspector_backend.InspectorBackend(self._browser_backend.browser,
self._browser_backend,
debugger_url)
def _FindExtensionInfo(self, extension_id):
for extension_info in self.GetExtensionInfoList():
if self._GetExtensionId(extension_info) == extension_id:
return extension_info
return None
def GetExtensionInfoList(self, timeout=None):
data = self._browser_backend.Request('', timeout=timeout)
return self._FilterExtensions(json.loads(data))
def _FilterExtensions(self, all_pages):
return [page_info for page_info in all_pages
if page_info['url'].startswith('chrome-extension://')]
def GetExtensionIds(self):
return map(self._GetExtensionId, self.GetExtensionInfoList())
|
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,
646,
2022,
199,
646,
295,
199,
646,
13852,
199,
199,
504,
17298,
14,
1018,
492,
3329,
63,
1606,
199,
504,
17298,
14,
1018,
14,
7765,
14,
9887,
492,
5261,
15152,
63,
4620,
199,
199,
533,
13282,
22646,
8,
1726,
304,
523,
986,
199,
199,
533,
13282,
2141,
8447,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
7042,
63,
4620,
304,
272,
291,
423,
5750,
63,
4620,
275,
7042,
63,
4620,
272,
327,
23673,
3329,
2762,
370,
13282,
3276,
2251,
14,
272,
291,
423,
3435,
63,
807,
275,
13852,
14,
18889,
1110,
11728,
342,
819,
347,
636,
6095,
721,
277,
12,
3329,
63,
344,
304,
272,
3329,
63,
785,
275,
291,
423,
3435,
63,
807,
14,
362,
8,
3435,
63,
344,
9,
272,
340,
440,
3329,
63,
785,
26,
489,
3329,
63,
785,
275,
291,
423,
2499,
6382,
1692,
8,
3435,
63,
344,
9,
489,
702,
3329,
63,
785,
489,
291,
423,
3435,
63,
807,
59,
3435,
63,
344,
61,
275,
3329,
63,
785,
272,
372,
3329,
63,
785,
819,
347,
636,
6134,
721,
277,
12,
3329,
63,
344,
304,
272,
372,
3329,
63,
344,
315,
291,
14,
1002,
6382,
11506,
342,
819,
768,
4639,
523,
347,
485,
12147,
6382,
1304,
8,
633,
304,
272,
333,
275,
295,
14,
1431,
8,
82,
26507,
9887,
13,
3435,
921,
9,
7059,
15251,
4186,
1166,
9,
272,
702,
333,
272,
372,
333,
14,
923,
8,
18,
9,
819,
768,
4639,
523,
347,
485,
1002,
6382,
1304,
8,
3435,
63,
815,
304,
272,
340,
283,
633,
7,
440,
315,
3329,
63,
815,
26,
489,
372,
488,
272,
372,
13282,
2141,
8447,
423,
12147,
6382,
1304,
8,
3435,
63,
815,
459,
633,
1105,
819,
347,
485,
2499,
6382,
1692,
8,
277,
12,
3329,
63,
344,
304,
272,
3329,
63,
815,
275,
291,
423,
6591,
6382,
2354,
8,
3435,
63,
344,
9,
272,
340,
440,
3329,
63,
815,
503,
440,
283,
2520,
3869,
31521,
6417,
7,
315,
3329,
63,
815,
26,
489,
746,
13282,
22646,
342,
272,
372,
3329,
63,
1606,
14,
6382,
3276,
8,
267,
3329,
63,
344,
12,
267,
3329,
63,
815,
459,
633,
995,
267,
291,
423,
2499,
13962,
15152,
8447,
1858,
31521,
6417,
8,
288,
3329,
63,
815,
459,
2520,
3869,
31521,
6417,
5156,
819,
347,
485,
2499,
13962,
15152,
8447,
1858,
31521,
6417,
8,
277,
12,
14958,
63,
633,
304,
272,
372,
5261,
15152,
63,
4620,
14,
13962,
15152,
8447,
8,
277,
423,
5750,
63,
4620,
14,
5750,
12,
6343,
291,
423,
5750,
63,
4620,
12,
6343,
14958,
63,
633,
9,
819,
347,
485,
6591,
6382,
2354,
8,
277,
12,
3329,
63,
344,
304,
272,
367,
3329,
63,
815,
315,
291,
14,
1002,
6382,
2354,
1296,
837,
489,
340,
291,
423,
1002,
6382,
1304,
8,
3435,
63,
815,
9,
508,
3329,
63,
344,
26,
267,
372,
3329,
63,
815,
272,
372,
488,
819,
347,
2372,
6382,
2354,
1296,
8,
277,
12,
2653,
29,
403,
304,
272,
666,
275,
291,
423,
5750,
63,
4620,
14,
2017,
8594,
2653,
29,
2593,
9,
272,
372,
291,
423,
4131,
10597,
8,
1001,
14,
3640,
8,
576,
430,
819,
347,
485,
4131,
10597,
8,
277,
12,
1006,
63,
5856,
304,
272,
372,
359,
1606,
63,
815,
367,
2034,
63,
815,
315,
1006,
63,
5856,
288,
340,
2034,
63,
815,
459,
633,
2278,
2460,
360,
9887,
13,
3435,
921,
5440,
819,
347,
2372,
6382,
11506,
8,
277,
304,
272,
372,
2341,
8,
277,
423,
1002,
6382,
1304,
12,
291,
14,
1002,
6382,
2354,
1296,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
646,
2022,
199,
646,
295,
199,
646,
13852,
199,
199,
504,
17298,
14,
1018,
492,
3329,
63,
1606,
199,
504,
17298,
14,
1018,
14,
7765,
14,
9887,
492,
5261,
15152,
63,
4620,
199,
199,
533,
13282,
22646,
8,
1726,
304,
523,
986,
199,
199,
533,
13282,
2141,
8447,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
7042,
63,
4620,
304,
272,
291,
423,
5750,
63,
4620,
275,
7042,
63,
4620,
272,
327,
23673,
3329,
2762,
370,
13282,
3276,
2251,
14,
272,
291,
423,
3435,
63,
807,
275,
13852,
14,
18889,
1110,
11728,
342,
819,
347,
636,
6095,
721,
277,
12,
3329,
63,
344,
304,
272,
3329,
63,
785,
275,
291,
423,
3435,
63,
807,
14,
362,
8,
3435,
63,
344,
9,
272,
340,
440,
3329,
63,
785,
26,
489,
3329,
63,
785,
275,
291,
423,
2499,
6382,
1692,
8,
3435,
63,
344,
9,
489,
702,
3329,
63,
785,
489,
291,
423,
3435,
63,
807,
59,
3435,
63,
344,
61,
275,
3329,
63,
785,
272,
372,
3329,
63,
785,
819,
347,
636,
6134,
721,
277,
12,
3329,
63,
344,
304,
272,
372,
3329,
63,
344,
315,
291,
14,
1002,
6382,
11506,
342,
819,
768,
4639,
523,
347,
485,
12147,
6382,
1304,
8,
633,
304,
272,
333,
275,
295,
14,
1431,
8,
82,
26507,
9887,
13,
3435,
921,
9,
7059,
15251,
4186,
1166,
9,
272,
702,
333,
272,
372,
333,
14,
923,
8,
18,
9,
819,
768,
4639,
523,
347,
485,
1002,
6382,
1304,
8,
3435,
63,
815,
304,
272,
340,
283,
633,
7,
440,
315,
3329,
63,
815,
26,
489,
372,
488,
272,
372,
13282,
2141,
8447,
423,
12147,
6382,
1304,
8,
3435,
63,
815,
459,
633,
1105,
819,
347,
485,
2499,
6382,
1692,
8,
277,
12,
3329,
63,
344,
304,
272,
3329,
63,
815,
275,
291,
423,
6591,
6382,
2354,
8,
3435,
63,
344,
9,
272,
340,
440,
3329,
63,
815,
503,
440,
283,
2520,
3869,
31521,
6417,
7,
315,
3329,
63,
815,
26,
489,
746,
13282,
22646,
342,
272,
372,
3329,
63,
1606,
14,
6382,
3276,
8,
267,
3329,
63,
344,
12,
267,
3329,
63,
815,
459,
633,
995,
267,
291,
423,
2499,
13962,
15152,
8447,
1858,
31521,
6417,
8,
288,
3329,
63,
815,
459,
2520,
3869,
31521,
6417,
5156,
819,
347,
485,
2499,
13962,
15152,
8447,
1858,
31521,
6417,
8,
277,
12,
14958,
63,
633,
304,
272,
372,
5261,
15152,
63,
4620,
14,
13962,
15152,
8447,
8,
277,
423,
5750,
63,
4620,
14,
5750,
12,
6343,
291,
423,
5750,
63,
4620,
12,
6343,
14958,
63,
633,
9,
819,
347,
485,
6591,
6382,
2354,
8,
277,
12,
3329,
63,
344,
304,
272,
367,
3329,
63,
815,
315,
291,
14,
1002,
6382,
2354,
1296,
837,
489,
340,
291,
423,
1002,
6382,
1304,
8,
3435,
63,
815,
9,
508,
3329,
63,
344,
26,
267,
372,
3329,
63,
815,
272,
372,
488,
819,
347,
2372,
6382,
2354,
1296,
8,
277,
12,
2653,
29,
403,
304,
272,
666,
275,
291,
423,
5750,
63,
4620,
14,
2017,
8594,
2653,
29,
2593,
9,
272,
372,
291,
423,
4131,
10597,
8,
1001,
14,
3640,
8,
576,
430,
819,
347,
485,
4131,
10597,
8,
277,
12,
1006,
63,
5856,
304,
272,
372,
359,
1606,
63,
815,
367,
2034,
63,
815,
315,
1006,
63,
5856,
288,
340,
2034,
63,
815,
459,
633,
2278,
2460,
360,
9887,
13,
3435,
921,
5440,
819,
347,
2372,
6382,
11506,
8,
277,
304,
272,
372,
2341,
8,
277,
423,
1002,
6382,
1304,
12,
291,
14,
1002,
6382,
2354,
1296,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scrollback/kuma
|
settings.py
|
2
|
38287
|
# Django settings for kuma project.
from collections import namedtuple
import json
import logging
import os
import platform
import sys
from django.utils.functional import lazy
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse_lazy
_Language = namedtuple(u'Language', u'english native iso639_1')
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ROOT = os.path.dirname(os.path.abspath(__file__))
path = lambda *a: os.path.join(ROOT, *a)
ROOT_PACKAGE = os.path.basename(ROOT)
ADMINS = (
('MDN devs', 'mdn-dev@mozilla.com'),
)
PROTOCOL = 'https://'
DOMAIN = 'developer.mozilla.org'
SITE_URL = PROTOCOL + DOMAIN
PRODUCTION_URL = SITE_URL
STAGING_URL = PROTOCOL + 'developer.allizom.org'
USE_X_FORWARDED_HOST = True
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'kuma', # Or path to database file if using sqlite3.
'USER': 'kuma', # Not used with sqlite3.
'PASSWORD': 'kuma', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
'OPTIONS': {'init_command': 'SET storage_engine=InnoDB'},
},
}
# Cache Settings
CACHE_PREFIX = 'kuma'
CACHE_COUNT_TIMEOUT = 60 # in seconds
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'TIMEOUT': CACHE_COUNT_TIMEOUT,
'KEY_PREFIX': CACHE_PREFIX,
},
'memcache': {
'BACKEND': 'memcached_hashring.backend.MemcachedHashRingCache',
'TIMEOUT': CACHE_COUNT_TIMEOUT * 60,
'KEY_PREFIX': CACHE_PREFIX,
'LOCATION': ['127.0.0.1:11211'],
},
}
CACHEBACK_CACHE_ALIAS = 'memcache'
# Addresses email comes from
DEFAULT_FROM_EMAIL = 'notifications@developer.mozilla.org'
SERVER_EMAIL = 'server-error@developer.mozilla.org'
PLATFORM_NAME = platform.node()
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'US/Pacific'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-US'
# Accepted locales
MDN_LANGUAGES = (
'en-US',
'af',
'ar',
'az',
'bn-BD',
'bn-IN',
'cs',
'ca',
'de',
'ee',
'el',
'es',
'fa',
'ff',
'fi',
'fr',
'fy-NL',
'ga-IE',
'ha',
'he',
'hi-IN',
'hr',
'hu',
'id',
'ig',
'it',
'ja',
'ka',
'ko',
'ln',
'ml',
'ms',
'nl',
'pl',
'pt-BR',
'pt-PT',
'ro',
'ru',
'sq',
'sw',
'ta',
'th',
'tr',
'vi',
'wo',
'xh',
'yo',
'zh-CN',
'zh-TW',
'zu',
)
RTL_LANGUAGES = (
'ar',
'fa',
'fa-IR',
'he'
)
DEV_POOTLE_PRODUCT_DETAILS_MAP = {
'pt': 'pt-PT',
'fy': 'fy-NL',
'xx-testing': 'x-testing',
}
# Override generic locale handling with explicit mappings.
# Keys are the requested locale; values are the delivered locale.
LOCALE_ALIASES = {
# Treat "English (United States)" as the canonical "English".
'en': 'en-US',
# Create aliases for over-specific locales.
'bn': 'bn-BD',
'fy': 'fy-NL',
'ga': 'ga-IE',
'gu': 'gu-IN',
'hi': 'hi-IN',
'hy': 'hy-AM',
'pa': 'pa-IN',
'sv': 'sv-SE',
'ta': 'ta-LK',
# Map a prefix to one of its multiple specific locales.
'pt': 'pt-PT',
'sr': 'sr-Cyrl',
'zh': 'zh-CN',
# Create aliases for locales which do not share a prefix.
'nb-NO': 'no',
'nn-NO': 'no',
# Create aliases for locales which use region subtags to assume scripts.
'zh-Hans': 'zh-CN',
'zh-Hant': 'zh-TW',
}
try:
DEV_LANGUAGES = [
loc.replace('_', '-') for loc in os.listdir(path('locale'))
if (os.path.isdir(path('locale', loc)) and
loc not in ['.svn', '.git', 'templates'])
]
for pootle_dir in DEV_LANGUAGES:
if pootle_dir in DEV_POOTLE_PRODUCT_DETAILS_MAP:
DEV_LANGUAGES.remove(pootle_dir)
DEV_LANGUAGES.append(DEV_POOTLE_PRODUCT_DETAILS_MAP[pootle_dir])
except OSError:
DEV_LANGUAGES = ('en-US',)
PROD_LANGUAGES = MDN_LANGUAGES
LANGUAGE_URL_MAP = dict([(i.lower(), i) for i in PROD_LANGUAGES])
for requested_lang, delivered_lang in LOCALE_ALIASES.items():
if delivered_lang in PROD_LANGUAGES:
LANGUAGE_URL_MAP[requested_lang.lower()] = delivered_lang
def get_locales():
locales = {}
file = os.path.join(ROOT, 'kuma', 'languages.json')
json_locales = json.load(open(file, 'r'))
for locale, meta in json_locales.items():
locales[locale] = _Language(meta['English'],
meta['native'],
locale)
return locales
LOCALES = get_locales()
def lazy_langs():
"""Override Django's built-in with our native names"""
from product_details import product_details
# for bug 664330
# from django.conf import settings
# langs = DEV_LANGUAGES if (getattr(settings, 'DEV', False) or getattr(settings, 'STAGE', False)) else PROD_LANGUAGES
langs = PROD_LANGUAGES
return dict([(lang.lower(), product_details.languages[lang]['native'])
for lang in langs])
LANGUAGES_DICT = lazy(lazy_langs, dict)()
LANGUAGES = sorted(tuple([(i, LOCALES[i].native) for i in MDN_LANGUAGES]),
key=lambda lang:lang[0])
# DEKI uses different locale keys
def lazy_language_deki_map():
# for bug 664330
# from django.conf import settings
# langs = DEV_LANGUAGES if (getattr(settings, 'DEV', False) or getattr(settings, 'STAGE', False)) else PROD_LANGUAGES
langs = PROD_LANGUAGES
lang_deki_map = dict([(i, i) for i in langs])
lang_deki_map['en-US'] = 'en'
lang_deki_map['zh-CN'] = 'cn'
lang_deki_map['zh-TW'] = 'zh_tw'
return lang_deki_map
LANGUAGE_DEKI_MAP = lazy(lazy_language_deki_map, dict)()
# List of MindTouch locales mapped to Kuma locales.
#
# Language in MindTouch pages are first determined from the locale in the page
# title, with a fallback to the language in the page record.
#
# So, first MindTouch locales were inventoried like so:
#
# mysql --skip-column-names -uroot wikidb -B \
# -e 'select page_title from pages where page_namespace=0' \
# > page-titles.txt
#
# grep '/' page-titles.txt | cut -d'/' -f1 | sort -f | uniq -ci | sort -rn
#
# Then, the database languages were inventoried like so:
#
# select page_language, count(page_id) as ct
# from pages group by page_language order by ct desc;
#
# Also worth noting, these are locales configured in the prod Control Panel:
#
# en,ar,ca,cs,de,el,es,fa,fi,fr,he,hr,hu,it,ja,
# ka,ko,nl,pl,pt,ro,ru,th,tr,uk,vi,zh-cn,zh-tw
#
# The Kuma side was picked from elements of the MDN_LANGUAGES list in
# settings.py, and a few were added to match MindTouch locales.
#
# Most of these end up being direct mappings, but it's instructive to go
# through the mapping exercise.
MT_TO_KUMA_LOCALE_MAP = {
"en" : "en-US",
"ja" : "ja",
"pl" : "pl",
"fr" : "fr",
"es" : "es",
"" : "en-US",
"cn" : "zh-CN",
"zh_cn" : "zh-CN",
"zh-cn" : "zh-CN",
"zh_tw" : "zh-TW",
"zh-tw" : "zh-TW",
"ko" : "ko",
"pt" : "pt-PT",
"de" : "de",
"it" : "it",
"ca" : "ca",
"cs" : "cs",
"ru" : "ru",
"nl" : "nl",
"hu" : "hu",
"he" : "he",
"el" : "el",
"fi" : "fi",
"tr" : "tr",
"vi" : "vi",
"ro" : "ro",
"ar" : "ar",
"th" : "th",
"fa" : "fa",
"ka" : "ka",
}
TEXT_DOMAIN = 'messages'
SITE_ID = 1
PROD_DETAILS_DIR = path('../product_details_json')
MDC_PAGES_DIR = path('../mdc_pages')
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (
path('locale'),
)
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = path('media')
# Absolute path to the directory for the humans.txt file.
HUMANSTXT_ROOT = MEDIA_ROOT
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATIC_ROOT = path('static')
SERVE_MEDIA = False
# Paths that don't require a locale prefix.
LANGUAGE_URL_IGNORED_PATHS = (
'media',
'admin',
'robots.txt',
'contribute.json',
'services',
'static',
'1',
'files',
'@api',
'grappelli',
'__debug__',
'.well-known',
'users/persona/',
'users/github/login/callback/',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '#%tc(zja8j01!r#h_y)=hy!^k)9az74k+-ib&ij&+**s3-e^_z'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'jingo.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
JINGO_EXCLUDE_APPS = (
'admin',
'grappelli',
'waffle',
'registration',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.media',
'django.core.context_processors.request',
'django.core.context_processors.csrf',
'django.contrib.messages.context_processors.messages',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',
'kuma.core.context_processors.global_settings',
'kuma.core.context_processors.i18n',
'kuma.core.context_processors.next_url',
'jingo_minify.helpers.build_ids',
'constance.context_processors.config',
'kuma.search.context_processors.search_filters',
)
MIDDLEWARE_CLASSES = (
# This gives us atomic success or failure on multi-row writes. It does not
# give us a consistent per-transaction snapshot for reads; that would need
# the serializable isolation level (which InnoDB does support) and code to
# retry transactions that roll back due to serialization failures. It's a
# possibility for the future. Keep in mind that memcache defeats
# snapshotted reads where we don't explicitly use the "uncached" manager.
'django.middleware.transaction.TransactionMiddleware',
# LocaleURLMiddleware must be before any middleware that uses
# kuma.core.urlresolvers.reverse() to add locale prefixes to URLs:
'kuma.core.middleware.LocaleURLMiddleware',
'kuma.wiki.middleware.DocumentZoneMiddleware',
'kuma.wiki.middleware.ReadOnlyMiddleware',
'kuma.core.middleware.Forbidden403Middleware',
'django.middleware.common.CommonMiddleware',
'kuma.core.middleware.RemoveSlashMiddleware',
'commonware.middleware.NoVarySessionMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'kuma.core.anonymous.AnonymousIdentityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'kuma.users.middleware.BanMiddleware',
'badger.middleware.RecentBadgeAwardsMiddleware',
'kuma.wiki.badges.BadgeAwardingMiddleware',
)
# Auth
AUTHENTICATION_BACKENDS = (
'allauth.account.auth_backends.AuthenticationBackend',
'teamwork.backends.TeamworkBackend',
)
AUTH_PROFILE_MODULE = 'users.UserProfile'
PASSWORD_HASHERS = (
'kuma.users.backends.Sha256Hasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
'django.contrib.auth.hashers.MD5PasswordHasher',
'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher',
)
USER_AVATAR_PATH = 'uploads/avatars/'
DEFAULT_AVATAR = MEDIA_URL + 'img/avatar.png'
AVATAR_SIZE = 48 # in pixels
ACCOUNT_ACTIVATION_DAYS = 30
MAX_AVATAR_FILE_SIZE = 131072 # 100k, in bytes
ROOT_URLCONF = 'urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates"
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
path('templates'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
)
# TODO: Figure out why changing the order of apps (for example, moving taggit
# higher in the list) breaks tests.
INSTALLED_APPS = (
# django
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'grappelli.dashboard',
'grappelli',
'django.contrib.admin',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
# MDN
'kuma.core',
'kuma.feeder',
'kuma.landing',
'kuma.search',
'kuma.users',
'kuma.wiki',
'kuma.attachments',
'allauth',
'allauth.account',
'allauth.socialaccount',
'kuma.users.providers.persona',
'kuma.users.providers.github',
'kuma.events',
# DEMOS
'kuma.demos',
'kuma.contentflagging',
'kuma.actioncounters',
'threadedcomments',
# util
'jingo_minify',
'product_details',
'tower',
'smuggler',
'constance.backends.database',
'constance',
'waffle',
'soapbox',
'kuma.authkeys',
'tidings',
'teamwork',
'djcelery',
'taggit',
'dbgettext',
'honeypot',
'cacheback',
'kuma.dashboards',
'statici18n',
'rest_framework',
# migrations
'south',
# testing.
'django_nose',
# other
'kuma.humans',
'badger',
'cacheback',
)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
'--traverse-namespace', # make sure `./manage.py test kuma` works
]
# Feed fetcher config
FEEDER_TIMEOUT = 6 # in seconds
def JINJA_CONFIG():
import jinja2
from django.conf import settings
from django.core.cache.backends.memcached import CacheClass as MemcachedCacheClass
from django.core.cache import get_cache
cache = get_cache('memcache')
config = {'extensions': ['jinja2.ext.i18n', 'tower.template.i18n',
'jinja2.ext.with_', 'jinja2.ext.loopcontrols',
'jinja2.ext.autoescape'],
'finalize': lambda x: x if x is not None else ''}
if isinstance(cache, MemcachedCacheClass) and not settings.DEBUG:
# We're passing the _cache object directly to jinja because
# Django can't store binary directly; it enforces unicode on it.
# Details: http://jinja.pocoo.org/2/documentation/api#bytecode-cache
# and in the errors you get when you try it the other way.
bc = jinja2.MemcachedBytecodeCache(cache._cache,
"%s:j2:" % settings.CACHE_PREFIX)
config['cache_size'] = -1 # Never clear the cache
config['bytecode_cache'] = bc
return config
# Let Tower know about our additional keywords.
# DO NOT import an ngettext variant as _lazy.
TOWER_KEYWORDS = {
'_lazy': None,
}
# Tells the extract script what files to look for l10n in and what function
# handles the extraction. The Tower library expects this.
DOMAIN_METHODS = {
'messages': [
('vendor/**', 'ignore'),
('kuma/dashboards/**', 'ignore'),
('kuma/core/**', 'ignore'),
('kuma/**.py',
'tower.management.commands.extract.extract_tower_python'),
('**/templates/**.html',
'tower.management.commands.extract.extract_tower_template'),
('**/templates/**.ltxt',
'tower.management.commands.extract.extract_tower_template'),
],
'javascript': [
# We can't say **.js because that would dive into any libraries.
('media/js/libs/ckeditor/plugins/mdn-link/**.js', 'javascript')
],
}
# These domains will not be merged into messages.pot and will use separate PO
# files. See the following URL for an example of how to set these domains
# in DOMAIN_METHODS.
# http://github.com/jbalogh/zamboni/blob/d4c64239c24aa2f1e91276909823d1d1b290f0ee/settings.py#L254
STANDALONE_DOMAINS = [
'javascript',
]
# If you have trouble extracting strings with Tower, try setting this
# to True
TOWER_ADD_HEADERS = True
# Bundles for JS/CSS Minification
JINGO_MINIFY_USE_STATIC = False
CLEANCSS_BIN = '/usr/local/bin/cleancss'
UGLIFY_BIN = '/usr/bin/uglifyjs'
MINIFY_BUNDLES = {
'css': {
'mdn': (
'css/font-awesome.css',
'css/main.css',
'css/badges.css',
),
'jquery-ui': (
'js/libs/jquery-ui-1.10.3.custom/css/ui-lightness/jquery-ui-1.10.3.custom.min.css',
'css/jqueryui/moz-jquery-plugins.css',
'css/jquery-ui-customizations.css',
),
'demostudio': (
'css/demos.css',
),
'devderby': (
'css/devderby.css',
),
'home': (
'css/home.css',
'js/libs/owl.carousel/owl-carousel/owl.carousel.css',
'js/libs/owl.carousel/owl-carousel/owl.theme.css',
),
'search': (
'css/search.css',
),
'search-suggestions': (
'css/search-suggestions.css',
),
'wiki': (
'css/wiki.css',
'css/zones.css',
'css/diff.css',
'js/libs/prism/themes/prism.css',
'js/libs/prism/plugins/line-highlight/prism-line-highlight.css',
'js/libs/prism/plugins/ie8/prism-ie8.css',
'js/prism-mdn/plugins/line-numbering/prism-line-numbering.css',
'js/prism-mdn/components/prism-json.css',
'css/wiki-syntax.css',
),
'wiki-revisions': (
'css/wiki-revisions.css',
),
'wiki-edit': (
'css/wiki-edit.css',
),
'sphinx': (
'css/wiki.css',
'css/sphinx.css',
),
'users': (
'css/users.css',
),
'tagit': (
'css/libs/jquery.tagit.css',
),
'promote': (
'css/promote.css',
),
'error': (
'css/error.css',
),
'error-404': (
'css/error.css',
'css/error-404.css',
),
'calendar': (
'css/calendar.css',
),
'profile': (
'css/profile.css',
),
'dashboards': (
'css/dashboards.css',
'css/diff.css',
),
'newsletter': (
'css/newsletter.css',
),
'submission': (
'css/submission.css',
),
'user-banned': (
'css/user-banned.css',
),
'error-403-alternate': (
'css/error-403-alternate.css',
),
'fellowship': (
'css/fellowship.css',
),
},
'js': {
'main': (
'js/libs/jquery-2.1.0.js',
'js/components.js',
'js/analytics.js',
'js/main.js',
'js/auth.js',
'js/badges.js',
'js/social.js',
),
'home': (
'js/libs/owl.carousel/owl-carousel/owl.carousel.js',
'js/home.js'
),
'popup': (
'js/libs/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js',
'js/modal-control.js',
),
'profile': (
'js/profile.js',
'js/moz-jquery-plugins.js',
),
'events': (
'js/libs/jquery.gmap-1.1.0.js',
'js/calendar.js',
),
'demostudio': (
'js/libs/jquery.hoverIntent.minified.js',
'js/libs/jquery.scrollTo-1.4.2-min.js',
'js/demos.js',
'js/libs/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js',
'js/modal-control.js',
),
'demostudio_devderby_landing': (
'js/demos-devderby-landing.js',
),
'jquery-ui': (
'js/libs/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js',
'js/moz-jquery-plugins.js',
),
'libs/tagit': (
'js/libs/tag-it.js',
),
'search': (
'js/search.js',
'js/search-navigator.js',
),
'framebuster': (
'js/framebuster.js',
),
'syntax-prism': (
'js/libs/prism/prism.js',
'js/prism-mdn/components/prism-json.js',
'js/prism-mdn/plugins/line-numbering/prism-line-numbering.js',
'js/libs/prism/plugins/line-highlight/prism-line-highlight.js',
'js/syntax-prism.js',
),
'search-suggestions': (
'js/search-suggestions.js',
),
'wiki': (
'js/search-navigator.js',
'js/wiki.js',
),
'wiki-edit': (
'js/wiki-edit.js',
'js/libs/tag-it.js',
'js/wiki-tags-edit.js',
),
'wiki-move': (
'js/wiki-move.js',
),
'newsletter': (
'js/newsletter.js',
),
'fellowship': (
'js/fellowship.js',
),
},
}
#
# Session cookies
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
# Cookie prefix from PHPBB settings.
PHPBB_COOKIE_PREFIX = 'phpbb3_jzxvr'
# Maximum length of the filename. Forms should use this and raise
# ValidationError if the length is exceeded.
# @see http://code.djangoproject.com/ticket/9893
# Columns are 250 but this leaves 50 chars for the upload_to prefix
MAX_FILENAME_LENGTH = 200
MAX_FILEPATH_LENGTH = 250
ATTACHMENT_HOST = 'mdn.mozillademos.org'
# Video settings, hard coded here for now.
# TODO: figure out a way that doesn't need these values
WIKI_VIDEO_WIDTH = 640
WIKI_VIDEO_HEIGHT = 480
IMAGE_MAX_FILESIZE = 1048576 # 1 megabyte, in bytes
THUMBNAIL_SIZE = 120 # Thumbnail size, in pixels
THUMBNAIL_UPLOAD_PATH = 'uploads/images/thumbnails/'
IMAGE_UPLOAD_PATH = 'uploads/images/'
# A string listing image mime types to accept, comma separated.
# String must not contain double quotes!
IMAGE_ALLOWED_MIMETYPES = 'image/jpeg,image/png,image/gif'
# Email
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/tmp/kuma-messages'
# Celery
import djcelery
djcelery.setup_loader()
BROKER_URL = 'amqp://kuma:kuma@localhost:5672/kuma'
CELERY_ALWAYS_EAGER = True # For tests. Set to False for use.
CELERY_SEND_TASK_ERROR_EMAILS = True
CELERY_SEND_EVENTS = True
CELERY_SEND_TASK_SENT_EVENT = True
CELERY_TRACK_STARTED = True
CELERYD_LOG_LEVEL = logging.INFO
CELERYD_CONCURRENCY = 4
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_ACCEPT_CONTENT = ['pickle']
CELERY_IMPORTS = (
'tidings.events',
)
# Wiki rebuild settings
WIKI_REBUILD_TOKEN = 'kuma:wiki:full-rebuild'
WIKI_REBUILD_ON_DEMAND = False
# Anonymous user cookie
ANONYMOUS_COOKIE_NAME = 'KUMA_ANONID'
ANONYMOUS_COOKIE_MAX_AGE = 30 * 86400 # Seconds
# Top contributors cache settings
TOP_CONTRIBUTORS_CACHE_KEY = 'kuma:TopContributors'
TOP_CONTRIBUTORS_CACHE_TIMEOUT = 60 * 60 * 12
# Do not change this without also deleting all wiki documents:
WIKI_DEFAULT_LANGUAGE = LANGUAGE_CODE
TIDINGS_FROM_ADDRESS = 'notifications@developer.mozilla.org'
TIDINGS_CONFIRM_ANONYMOUS_WATCHES = True
# content flagging
DEMO_FLAG_REASONS = (
('notworking', _('This demo is not working for me')),
('inappropriate', _('This demo contains inappropriate content')),
('plagarised', _('This demo was not created by the author')),
)
WIKI_FLAG_REASONS = (
('bad', _('This article is spam/inappropriate')),
('unneeded', _('This article is obsolete/unneeded')),
('duplicate', _('This is a duplicate of another article')),
)
FLAG_REASONS = DEMO_FLAG_REASONS + WIKI_FLAG_REASONS
# bit.ly
BITLY_API_KEY = "SET ME IN SETTINGS_LOCAL"
BITLY_USERNAME = "SET ME IN SETTINGS_LOCAL"
GOOGLE_MAPS_API_KEY = "ABQIAAAAijZqBZcz-rowoXZC1tt9iRT5rHVQFKUGOHoyfP_4KyrflbHKcRTt9kQJVST5oKMRj8vKTQS2b7oNjQ"
# demo studio uploads
# Filesystem path where files uploaded for demos will be written
DEMO_UPLOADS_ROOT = path('media/uploads/demos')
# Base URL from where files uploaded for demos will be linked and served
DEMO_UPLOADS_URL = '/media/uploads/demos/'
# Make sure South stays out of the way during testing
SOUTH_TESTS_MIGRATE = False
SKIP_SOUTH_TESTS = True
# Provide migrations for third-party vendor apps
# TODO: Move migrations for our apps here, rather than living with the app?
SOUTH_MIGRATION_MODULES = {
'taggit': 'migrations.south.taggit',
}
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
# must be an entry in the CACHES setting!
CONSTANCE_DATABASE_CACHE_BACKEND = 'memcache'
# Settings and defaults controllable by Constance in admin
CONSTANCE_CONFIG = dict(
DEMO_BLACKLIST_OVERRIDE_EXTENSIONS = (
'jsgz datagz memgz',
'File extensions that override the mimetype blacklist in case of '
'an ambigous mimetype such as application/gzip',
),
DEMO_MAX_ZIP_FILESIZE = (
60 * 1024 * 1024,
"Max file size for zips uploaded to demo studio."
),
DEMO_MAX_FILESIZE_IN_ZIP = (
60 * 1024 * 1024,
"Max file size for files inside zip uploaded to demo studio."
),
DEMOS_DEVDERBY_CURRENT_CHALLENGE_TAG = (
"challenge:2011:september",
"Dev derby current challenge"
),
DEMOS_DEVDERBY_PREVIOUS_WINNER_TAG = (
"system:challenge:firstplace:2011:august",
"Tag used to find most recent winner for dev derby"
),
DEMOS_DEVDERBY_CHALLENGE_CHOICE_TAGS = (
' '.join([
"challenge:2011:september",
"challenge:2011:october",
"challenge:2011:november",
]),
"Dev derby choices displayed on submission form (space-separated tags)"
),
DEMOS_DEVDERBY_PREVIOUS_CHALLENGE_TAGS = (
' '.join([
"challenge:2013:june",
"challenge:2013:may",
"challenge:2013:april",
"challenge:2013:march",
"challenge:2013:february",
"challenge:2013:january",
"challenge:2012:december",
"challenge:2012:november",
"challenge:2012:october",
"challenge:2012:september",
"challenge:2012:august",
"challenge:2012:july",
"challenge:2012:june",
"challenge:2012:may",
"challenge:2012:april",
"challenge:2012:march",
"challenge:2012:february",
"challenge:2012:january",
"challenge:2011:december",
"challenge:2011:november",
"challenge:2011:october",
"challenge:2011:september",
"challenge:2011:august",
"challenge:2011:july",
"challenge:2011:june",
]),
"Dev derby tags for previous challenges (space-separated tags)"
),
DEMOS_DEVDERBY_HOMEPAGE_FEATURED_DEMO = (
0,
'The ID of the demo which should be featured on the new homepage structure'
),
BASKET_RETRIES = (
5,
'Number of time to retry basket post before giving up.'
),
BASKET_RETRY_WAIT = (
.5,
'How long to wait between basket api request retries. '
'We typically multiply this value by the retry number so, e.g., '
'the 4th retry waits 4*.5 = 2 seconds.'
),
BASKET_API_KEY = (
'',
'API Key to use for basket requests'
),
BETA_GROUP_NAME = (
'Beta Testers',
'Name of the django.contrib.auth.models.Group to use as beta testers'
),
KUMA_DOCUMENT_RENDER_TIMEOUT = (
180.0,
'Maximum seconds to wait before considering a rendering in progress or '
'scheduled as failed and allowing another attempt.'
),
KUMA_DOCUMENT_FORCE_DEFERRED_TIMEOUT = (
10.0,
'Maximum seconds to allow a document to spend rendering during the '
'response cycle before flagging it to be sent to the deferred rendering '
'queue for future renders.'
),
KUMASCRIPT_TIMEOUT = (
0.0,
'Maximum seconds to wait for a response from the kumascript service. '
'On timeout, the document gets served up as-is and without macro '
'evaluation as an attempt at graceful failure. NOTE: a value of 0 '
'disables kumascript altogether.'
),
KUMASCRIPT_MAX_AGE = (
600,
'Maximum acceptable age (in seconds) of a cached response from '
'kumascript. Passed along in a Cache-Control: max-age={value} header, '
'which tells kumascript whether or not to serve up a cached response.'
),
KUMA_CUSTOM_CSS_PATH = (
'/en-US/docs/Template:CustomCSS',
'Path to a wiki document whose raw content will be loaded as a CSS '
'stylesheet for the wiki base template. Will also cause the ?raw '
'parameter for this path to send a Content-Type: text/css header. Empty '
'value disables the feature altogether.',
),
KUMA_CUSTOM_SAMPLE_CSS_PATH = (
'/en-US/docs/Template:CustomSampleCSS',
'Path to a wiki document whose raw content will be loaded as a CSS '
'stylesheet for live sample template. Will also cause the ?raw '
'parameter for this path to send a Content-Type: text/css header. Empty '
'value disables the feature altogether.',
),
DIFF_CONTEXT_LINES = (
0,
'Number of lines of context to show in diff display.',
),
FEED_DIFF_CONTEXT_LINES = (
3,
'Number of lines of context to show in feed diff display.',
),
WIKI_ATTACHMENT_ALLOWED_TYPES = (
'image/gif image/jpeg image/png image/svg+xml text/html image/vnd.adobe.photoshop',
'Allowed file types for wiki file attachments',
),
KUMA_WIKI_IFRAME_ALLOWED_HOSTS = (
'^https?\:\/\/(developer-local.allizom.org|developer-dev.allizom.org|developer.allizom.org|mozillademos.org|testserver|localhost\:8000|(www.)?youtube.com\/embed\/(\.*))',
'Regex comprised of domain names that are allowed for IFRAME SRCs'
),
GOOGLE_ANALYTICS_ACCOUNT = (
'0',
'Google Analytics Tracking Account Number (0 to disable)',
),
OPTIMIZELY_PROJECT_ID = (
'',
'The ID value for optimizely Project Code script'
),
BLEACH_ALLOWED_TAGS = (
json.dumps([
'a', 'p', 'div',
]),
"JSON array of tags allowed through Bleach",
),
BLEACH_ALLOWED_ATTRIBUTES = (
json.dumps({
'*': ['id', 'class', 'style', 'lang'],
}),
"JSON object associating tags with lists of allowed attributes",
),
BLEACH_ALLOWED_STYLES = (
json.dumps([
'font-size', 'text-align',
]),
"JSON array listing CSS styles allowed on tags",
),
WIKI_DOCUMENT_TAG_SUGGESTIONS = (
json.dumps([
"Accessibility", "AJAX", "API", "Apps",
"Canvas", "CSS", "Device", "DOM", "Events",
"Extensions", "Firefox", "Firefox OS", "Games",
"Gecko", "Graphics", "Internationalization", "History", "HTML", "HTTP", "JavaScript", "Layout",
"Localization", "MDN", "Mobile", "Mozilla",
"Networking", "Persona", "Places", "Plugins", "Protocols",
"Reference", "Tutorial", "Landing",
"junk", "NeedsMarkupWork", "NeedsContent", "NeedsExample",
]),
"JSON array listing tag suggestions for documents"
),
SEARCH_FILTER_TAG_OPTIONS = (
json.dumps([
"Accessibility", "AJAX", "API", "Apps",
"Canvas", "CSS", "Device", "DOM", "Events",
"Extensions", "Firefox", "Firefox OS", "Games",
"Gecko", "Graphics", "Internationalization", "History", "HTML", "HTTP", "JavaScript", "Layout",
"Localization", "MDN", "Mobile", "Mozilla",
"Networking", "Persona", "Places", "Plugins", "Protocols",
"Reference", "Tutorial", "Landing",
"junk", "NeedsMarkupWork", "NeedsContent", "NeedsExample",
]),
"JSON array of tags that are enabled for search faceting"
),
SESSION_CLEANUP_CHUNK_SIZE = (
1000,
'Number of expired sessions to cleanup up in one go.',
),
WELCOME_EMAIL_FROM = (
"Janet Swisher <no-reply@mozilla.org>",
'Email address from which welcome emails will be sent',
),
EMAIL_LIST_FOR_FIRST_EDITS = (
"mdn-spam-watch@mozilla.com",
"Email address to which emails will be sent for users' first edits",
),
)
BASKET_URL = 'https://basket.mozilla.com'
BASKET_APPS_NEWSLETTER = 'app-dev'
KUMASCRIPT_URL_TEMPLATE = 'http://developer.mozilla.org:9080/docs/{path}'
# Elasticsearch related settings.
ES_DEFAULT_NUM_REPLICAS = 1
ES_DEFAULT_NUM_SHARDS = 5
ES_DEFAULT_REFRESH_INTERVAL = '5s'
ES_DISABLED = True
ES_INDEX_PREFIX = 'mdn'
ES_INDEXES = {'default': 'main_index'}
# Specify the extra timeout in seconds for the indexing ES connection.
ES_INDEXING_TIMEOUT = 30
ES_LIVE_INDEX = False
ES_URLS = ['localhost:9200']
LOG_LEVEL = logging.WARN
SYSLOG_TAG = 'http_app_kuma'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
},
'formatters': {
'default': {
'format': '{0}: %(asctime)s %(name)s:%(levelname)s %(message)s: '
'%(pathname)s:%(lineno)s'.format(SYSLOG_TAG),
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'default',
'level': LOG_LEVEL,
},
'mail_admins': {
'class': 'django.utils.log.AdminEmailHandler',
'filters': ['require_debug_false'],
'level': logging.ERROR,
},
},
'loggers': {
'kuma': {
'handlers': ['console'],
'propagate': True,
'level': logging.ERROR,
},
'django.request': {
'handlers': ['console'],
'propagate': True,
'level': logging.ERROR,
},
'elasticsearch': {
'handlers': ['console'],
'level': logging.ERROR,
},
'urllib3': {
'handlers': ['console'],
'level': logging.ERROR,
},
'cacheback': {
'handlers': ['console'],
'level': logging.ERROR,
}
},
}
CSRF_COOKIE_SECURE = True
X_FRAME_OPTIONS = 'DENY'
TEAMWORK_BASE_POLICIES = {
'anonymous': (
'wiki.view_document',),
'authenticated': (
'wiki.view_document', 'wiki.add_document', 'wiki.add_revision'),
}
GRAPPELLI_ADMIN_TITLE = 'Mozilla Developer Network - Admin'
GRAPPELLI_INDEX_DASHBOARD = 'admin_dashboard.CustomIndexDashboard'
DBGETTEXT_PATH = 'kuma/core/'
DBGETTEXT_ROOT = 'translations'
def get_user_url(user):
from kuma.core.urlresolvers import reverse
return reverse('users.profile', args=[user.username])
ABSOLUTE_URL_OVERRIDES = {
'auth.user': get_user_url
}
OBI_BASE_URL = 'https://backpack.openbadges.org/'
# Honor the X-Forwarded-Proto header for environments like local dev VM that
# uses Apache mod_proxy instead of mod_wsgi
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Auth and permissions related constants
LOGIN_URL = reverse_lazy('account_login')
LOGOUT_URL = reverse_lazy('account_logout')
LOGIN_REDIRECT_URL = reverse_lazy('home')
# django-allauth configuration
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_USERNAME_MIN_LENGTH = 3
ACCOUNT_ADAPTER = 'kuma.users.adapters.KumaAccountAdapter'
ACCOUNT_SIGNUP_FORM_CLASS = 'kuma.users.forms.NewsletterForm' # weird but needed
ACCOUNT_UNIQUE_EMAIL = False
SOCIALACCOUNT_ADAPTER = 'kuma.users.adapters.KumaSocialAccountAdapter'
SOCIALACCOUNT_EMAIL_VERIFICATION = 'mandatory'
SOCIALACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_AUTO_SIGNUP = False # forces the use of the signup view
SOCIALACCOUNT_QUERY_EMAIL = True # used by the custom github provider
SOCIALACCOUNT_PROVIDERS = {
'persona': {
'AUDIENCE': 'https://developer.mozilla.org',
'REQUEST_PARAMETERS': {
'siteName': 'Mozilla Developer Network',
'siteLogo': '/media/img/opengraph-logo.png',
}
}
}
PERSONA_VERIFIER_URL = 'https://verifier.login.persona.org/verify'
PERSONA_INCLUDE_URL = 'https://login.persona.org/include.js'
HONEYPOT_FIELD_NAME = 'website'
# TODO: Once using DRF more we need to make that exception handler more generic
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'kuma.search.utils.search_exception_handler'
}
|
mpl-2.0
|
[
3,
5634,
2202,
367,
1022,
85,
391,
2199,
14,
199,
504,
5055,
492,
12863,
199,
646,
2022,
199,
646,
2050,
199,
646,
747,
199,
646,
4298,
199,
646,
984,
199,
199,
504,
1639,
14,
1208,
14,
15481,
492,
9617,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
199,
63,
8493,
275,
12863,
8,
85,
7,
8493,
297,
399,
7,
17872,
5438,
11601,
26723,
63,
17,
358,
421,
199,
5287,
275,
756,
199,
7433,
63,
5287,
275,
10990,
199,
199,
5441,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
515,
275,
2400,
627,
65,
26,
747,
14,
515,
14,
904,
8,
5441,
12,
627,
65,
9,
199,
199,
5441,
63,
19265,
275,
747,
14,
515,
14,
4846,
8,
5441,
9,
199,
199,
14288,
51,
275,
334,
272,
661,
5127,
46,
477,
3122,
297,
283,
1064,
78,
13,
2374,
32,
12102,
14,
957,
659,
199,
9,
199,
199,
9583,
275,
283,
2859,
22399,
199,
7378,
275,
283,
11071,
14,
12102,
14,
1308,
7,
199,
7917,
63,
2632,
275,
3611,
2566,
3978,
435,
15265,
199,
2514,
4980,
5430,
63,
2632,
275,
428,
4427,
63,
2632,
199,
840,
1254,
1206,
63,
2632,
275,
3611,
2566,
3978,
435,
283,
11071,
14,
279,
19030,
676,
14,
1308,
7,
199,
4701,
63,
56,
63,
22371,
8280,
63,
5449,
275,
715,
199,
199,
20600,
3960,
275,
29948,
51,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
8644,
297,
221,
327,
2654,
283,
15437,
63,
20270,
18,
297,
283,
15437,
297,
283,
8644,
297,
283,
10659,
19,
7,
503,
283,
16404,
1370,
267,
283,
2339,
356,
283,
20661,
391,
297,
221,
327,
4236,
931,
370,
3050,
570,
340,
1808,
11723,
19,
14,
267,
283,
3791,
356,
283,
20661,
391,
297,
221,
327,
2832,
1202,
543,
11723,
19,
14,
267,
283,
9032,
356,
283,
20661,
391,
297,
221,
327,
2832,
1202,
543,
11723,
19,
14,
267,
283,
5449,
356,
283,
5967,
297,
221,
327,
2494,
370,
2701,
1059,
367,
11667,
14,
2832,
1202,
543,
11723,
19,
14,
267,
283,
3657,
356,
283,
1153,
1690,
297,
221,
327,
2494,
370,
2701,
1059,
367,
849,
14,
2832,
1202,
543,
11723,
19,
14,
267,
283,
8808,
356,
791,
826,
63,
1531,
356,
283,
3597,
4887,
63,
3908,
29,
607,
889,
2846,
2267,
272,
1660,
199,
93,
199,
199,
3,
11977,
13303,
199,
8677,
63,
6351,
275,
283,
20661,
391,
7,
199,
8677,
63,
8760,
63,
8899,
275,
5212,
221,
327,
315,
4696,
199,
199,
3263,
1244,
654,
275,
469,
272,
283,
885,
356,
469,
267,
283,
18145,
356,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
2102,
5286,
14,
3040,
14169,
4437,
297,
267,
283,
8899,
356,
7240,
4576,
63,
8760,
63,
8899,
12,
267,
283,
3078,
63,
6351,
356,
7240,
4576,
63,
6351,
12,
272,
1660,
272,
283,
25835,
356,
469,
267,
283,
18145,
356,
283,
32567,
63,
2227,
5985,
14,
4620,
14,
14169,
5245,
3476,
15420,
4437,
297,
267,
283,
8899,
356,
7240,
4576,
63,
8760,
63,
8899,
627,
5212,
12,
267,
283,
3078,
63,
6351,
356,
7240,
4576,
63,
6351,
12,
267,
283,
16575,
356,
788,
4195,
14,
16,
14,
16,
14,
17,
26,
6094,
845,
995,
272,
1660,
199,
93,
199,
199,
8677,
7111,
63,
8677,
63,
12644,
275,
283,
25835,
7,
199,
199,
3,
2654,
4357,
3031,
12477,
687,
199,
3472,
63,
12491,
63,
10089,
275,
283,
12782,
32,
11071,
14,
12102,
14,
1308,
7,
199,
6613,
63,
10089,
275,
283,
1000,
13,
705,
32,
11071,
14,
12102,
14,
1308,
7,
199,
199,
17805,
63,
2339,
275,
4298,
14,
932,
342,
199,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3,
982,
3879,
315,
282,
5417,
3734,
642,
1471,
506,
663,
370,
314,
2011,
465,
2195,
199,
3,
2656,
900,
5718,
14,
199,
4961,
63,
15353,
275,
283,
1668,
15,
20687,
7,
199,
199,
3,
8466,
1233,
367,
642,
12096,
14,
2900,
3415,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
1544,
14,
73,
1085,
2753,
29514,
14,
957,
15,
2975,
15,
3671,
13,
14227,
14,
1360,
199,
13947,
63,
6012,
275,
283,
287,
13,
1668,
7,
199,
199,
3,
4473,
7203,
24847,
199,
5127,
46,
63,
26886,
275,
334,
326,
283,
287,
13,
1668,
297,
326,
283,
2756,
297,
326,
283,
285,
297,
326,
283,
4651,
297,
326,
283,
10472,
13,
11156,
297,
326,
283,
10472,
13,
568,
297,
326,
283,
1259,
297,
326,
283,
696,
297,
326,
283,
271,
297,
326,
283,
1024,
297,
326,
283,
352,
297,
326,
283,
397,
297,
326,
283,
667,
297,
326,
283,
556,
297,
326,
283,
329,
297,
326,
283,
4391,
297,
326,
283,
1399,
13,
14176,
297,
326,
283,
5294,
13,
4332,
297,
326,
283,
2411,
297,
326,
283,
426,
297,
326,
283,
5812,
13,
568,
297,
326,
283,
6271,
297,
326,
283,
10616,
297,
326,
283,
344,
297,
326,
283,
528,
297,
326,
283,
390,
297,
326,
283,
3387,
297,
326,
283,
7351,
297,
326,
283,
7697,
297,
326,
283,
6066,
297,
326,
283,
757,
297,
326,
283,
706,
297,
326,
283,
7530,
297,
326,
283,
1168,
297,
326,
283,
541,
13,
7184,
297,
326,
283,
541,
13,
4189,
297,
326,
283,
293,
297,
326,
283,
6558,
297,
326,
283,
3526,
297,
326,
283,
3519,
297,
326,
283,
502,
297,
326,
283,
273,
297,
326,
283,
454,
297,
326,
283,
433,
297,
326,
283,
2027,
297,
326,
283,
29426,
297,
326,
283,
16540,
297,
326,
283,
3951,
13,
12874,
297,
326,
283,
3951,
13,
16491,
297,
326,
283,
90,
85,
297,
199,
9,
199,
199,
23259,
63,
26886,
275,
334,
326,
283,
285,
297,
326,
283,
667,
297,
326,
283,
667,
13,
3927,
297,
326,
283,
426,
7,
199,
9,
199,
199,
13260,
63,
1512,
1387
] |
[
5634,
2202,
367,
1022,
85,
391,
2199,
14,
199,
504,
5055,
492,
12863,
199,
646,
2022,
199,
646,
2050,
199,
646,
747,
199,
646,
4298,
199,
646,
984,
199,
199,
504,
1639,
14,
1208,
14,
15481,
492,
9617,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
199,
63,
8493,
275,
12863,
8,
85,
7,
8493,
297,
399,
7,
17872,
5438,
11601,
26723,
63,
17,
358,
421,
199,
5287,
275,
756,
199,
7433,
63,
5287,
275,
10990,
199,
199,
5441,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
515,
275,
2400,
627,
65,
26,
747,
14,
515,
14,
904,
8,
5441,
12,
627,
65,
9,
199,
199,
5441,
63,
19265,
275,
747,
14,
515,
14,
4846,
8,
5441,
9,
199,
199,
14288,
51,
275,
334,
272,
661,
5127,
46,
477,
3122,
297,
283,
1064,
78,
13,
2374,
32,
12102,
14,
957,
659,
199,
9,
199,
199,
9583,
275,
283,
2859,
22399,
199,
7378,
275,
283,
11071,
14,
12102,
14,
1308,
7,
199,
7917,
63,
2632,
275,
3611,
2566,
3978,
435,
15265,
199,
2514,
4980,
5430,
63,
2632,
275,
428,
4427,
63,
2632,
199,
840,
1254,
1206,
63,
2632,
275,
3611,
2566,
3978,
435,
283,
11071,
14,
279,
19030,
676,
14,
1308,
7,
199,
4701,
63,
56,
63,
22371,
8280,
63,
5449,
275,
715,
199,
199,
20600,
3960,
275,
29948,
51,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
8644,
297,
221,
327,
2654,
283,
15437,
63,
20270,
18,
297,
283,
15437,
297,
283,
8644,
297,
283,
10659,
19,
7,
503,
283,
16404,
1370,
267,
283,
2339,
356,
283,
20661,
391,
297,
221,
327,
4236,
931,
370,
3050,
570,
340,
1808,
11723,
19,
14,
267,
283,
3791,
356,
283,
20661,
391,
297,
221,
327,
2832,
1202,
543,
11723,
19,
14,
267,
283,
9032,
356,
283,
20661,
391,
297,
221,
327,
2832,
1202,
543,
11723,
19,
14,
267,
283,
5449,
356,
283,
5967,
297,
221,
327,
2494,
370,
2701,
1059,
367,
11667,
14,
2832,
1202,
543,
11723,
19,
14,
267,
283,
3657,
356,
283,
1153,
1690,
297,
221,
327,
2494,
370,
2701,
1059,
367,
849,
14,
2832,
1202,
543,
11723,
19,
14,
267,
283,
8808,
356,
791,
826,
63,
1531,
356,
283,
3597,
4887,
63,
3908,
29,
607,
889,
2846,
2267,
272,
1660,
199,
93,
199,
199,
3,
11977,
13303,
199,
8677,
63,
6351,
275,
283,
20661,
391,
7,
199,
8677,
63,
8760,
63,
8899,
275,
5212,
221,
327,
315,
4696,
199,
199,
3263,
1244,
654,
275,
469,
272,
283,
885,
356,
469,
267,
283,
18145,
356,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
2102,
5286,
14,
3040,
14169,
4437,
297,
267,
283,
8899,
356,
7240,
4576,
63,
8760,
63,
8899,
12,
267,
283,
3078,
63,
6351,
356,
7240,
4576,
63,
6351,
12,
272,
1660,
272,
283,
25835,
356,
469,
267,
283,
18145,
356,
283,
32567,
63,
2227,
5985,
14,
4620,
14,
14169,
5245,
3476,
15420,
4437,
297,
267,
283,
8899,
356,
7240,
4576,
63,
8760,
63,
8899,
627,
5212,
12,
267,
283,
3078,
63,
6351,
356,
7240,
4576,
63,
6351,
12,
267,
283,
16575,
356,
788,
4195,
14,
16,
14,
16,
14,
17,
26,
6094,
845,
995,
272,
1660,
199,
93,
199,
199,
8677,
7111,
63,
8677,
63,
12644,
275,
283,
25835,
7,
199,
199,
3,
2654,
4357,
3031,
12477,
687,
199,
3472,
63,
12491,
63,
10089,
275,
283,
12782,
32,
11071,
14,
12102,
14,
1308,
7,
199,
6613,
63,
10089,
275,
283,
1000,
13,
705,
32,
11071,
14,
12102,
14,
1308,
7,
199,
199,
17805,
63,
2339,
275,
4298,
14,
932,
342,
199,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3,
982,
3879,
315,
282,
5417,
3734,
642,
1471,
506,
663,
370,
314,
2011,
465,
2195,
199,
3,
2656,
900,
5718,
14,
199,
4961,
63,
15353,
275,
283,
1668,
15,
20687,
7,
199,
199,
3,
8466,
1233,
367,
642,
12096,
14,
2900,
3415,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
1544,
14,
73,
1085,
2753,
29514,
14,
957,
15,
2975,
15,
3671,
13,
14227,
14,
1360,
199,
13947,
63,
6012,
275,
283,
287,
13,
1668,
7,
199,
199,
3,
4473,
7203,
24847,
199,
5127,
46,
63,
26886,
275,
334,
326,
283,
287,
13,
1668,
297,
326,
283,
2756,
297,
326,
283,
285,
297,
326,
283,
4651,
297,
326,
283,
10472,
13,
11156,
297,
326,
283,
10472,
13,
568,
297,
326,
283,
1259,
297,
326,
283,
696,
297,
326,
283,
271,
297,
326,
283,
1024,
297,
326,
283,
352,
297,
326,
283,
397,
297,
326,
283,
667,
297,
326,
283,
556,
297,
326,
283,
329,
297,
326,
283,
4391,
297,
326,
283,
1399,
13,
14176,
297,
326,
283,
5294,
13,
4332,
297,
326,
283,
2411,
297,
326,
283,
426,
297,
326,
283,
5812,
13,
568,
297,
326,
283,
6271,
297,
326,
283,
10616,
297,
326,
283,
344,
297,
326,
283,
528,
297,
326,
283,
390,
297,
326,
283,
3387,
297,
326,
283,
7351,
297,
326,
283,
7697,
297,
326,
283,
6066,
297,
326,
283,
757,
297,
326,
283,
706,
297,
326,
283,
7530,
297,
326,
283,
1168,
297,
326,
283,
541,
13,
7184,
297,
326,
283,
541,
13,
4189,
297,
326,
283,
293,
297,
326,
283,
6558,
297,
326,
283,
3526,
297,
326,
283,
3519,
297,
326,
283,
502,
297,
326,
283,
273,
297,
326,
283,
454,
297,
326,
283,
433,
297,
326,
283,
2027,
297,
326,
283,
29426,
297,
326,
283,
16540,
297,
326,
283,
3951,
13,
12874,
297,
326,
283,
3951,
13,
16491,
297,
326,
283,
90,
85,
297,
199,
9,
199,
199,
23259,
63,
26886,
275,
334,
326,
283,
285,
297,
326,
283,
667,
297,
326,
283,
667,
13,
3927,
297,
326,
283,
426,
7,
199,
9,
199,
199,
13260,
63,
1512,
1387,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
opensemanticsearch/open-semantic-etl
|
src/opensemanticetl/enhance_extract_law.py
|
1
|
5028
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import etl_plugin_core
#
# get taxonomy for aggregated facets / filters
#
# example: '§ 153 Abs. 1 Satz 2' -> ['§ 153', '§ 153 Absatz 1', '§ 153 Absatz 1 Satz 2']
# todo:
def get_taxonomy(law_clause, law_code = None):
law_clauses = [law_clause]
return law_clauses
#1.a
#1(2)
#1 (2)
#
# extract law codes
#
class enhance_extract_law(etl_plugin_core.Plugin):
def process(self, parameters=None, data=None):
if parameters is None:
parameters = {}
if data is None:
data = {}
clause_prefixes = [
'§',
'Article',
'Artikel',
'Art',
'Section',
'Sec',
]
clause_subsections = [
'Abschnitt',
'Absatz',
'Abs',
'Sentence',
'Satz',
'S',
'Halbsatz',
'Number',
'Nummer',
'Nr',
'Buchstabe',
]
text = etl_plugin_core.get_text(data)
clauses = []
rule = '(' + '|'.join(clause_prefixes) + ')\W*((\d+\W\w(\W|\b))|(\d+\w?))(\W?(' + '|'.join(clause_subsections) + ')\W*(\d+\w?|\w(\W|\b)))*'
for match in re.finditer(rule, text, re.IGNORECASE):
clause = match.group(0)
clause = clause.strip()
clauses.append(clause)
# if "§123" normalize to "§ 123"
if clause[0] == '§' and not clause[1] == ' ':
clause = '§ ' + clause[1:]
etl_plugin_core.append(data, 'law_clause_ss', clause)
code_matchtexts = etl_plugin_core.get_all_matchtexts(data.get('law_code_ss_matchtext_ss', []))
code_matchtexts_with_clause = []
preflabels = {}
if 'law_code_ss_preflabel_and_uri_ss' in data:
preflabels = etl_plugin_core.get_preflabels(data['law_code_ss_preflabel_and_uri_ss'])
if len(clauses)>0 and len(code_matchtexts)>0:
text = text.replace("\n", " ")
for code_match_id in code_matchtexts:
#get only matchtext (without ID/URI of matching entity)
for code_matchtext in code_matchtexts[code_match_id]:
for clause in clauses:
if clause + " " + code_matchtext in text or code_matchtext + " " + clause in text:
code_matchtexts_with_clause.append(code_matchtext)
# if "§123" normalize to "§ 123"
if clause[0] == '§' and not clause[1] == ' ':
clause = '§ ' + clause[1:]
law_code_preflabel = code_match_id
if code_match_id in preflabels:
law_code_clause_normalized = clause + " " + preflabels[code_match_id]
else:
law_code_clause_normalized = clause + " " + code_match_id
etl_plugin_core.append(data, 'law_code_clause_ss', law_code_clause_normalized)
if len(code_matchtexts)>0:
blacklist = []
listfile = open('/etc/opensemanticsearch/blacklist/enhance_extract_law/blacklist-lawcode-if-no-clause')
for line in listfile:
line = line.strip()
if line and not line.startswith("#"):
blacklist.append(line)
listfile.close()
if not isinstance(data['law_code_ss_matchtext_ss'], list):
data['law_code_ss_matchtext_ss'] = [data['law_code_ss_matchtext_ss']]
blacklisted_code_ids = []
for code_match_id in code_matchtexts:
for code_matchtext in code_matchtexts[code_match_id]:
if code_matchtext in blacklist:
if code_matchtext not in code_matchtexts_with_clause:
blacklisted_code_ids.append(code_match_id)
data['law_code_ss_matchtext_ss'].remove(code_match_id + "\t" + code_matchtext)
code_matchtexts = etl_plugin_core.get_all_matchtexts(data.get('law_code_ss_matchtext_ss', []))
if not isinstance(data['law_code_ss'], list):
data['law_code_ss'] = [data['law_code_ss']]
if not isinstance(data['law_code_ss_preflabel_and_uri_ss'], list):
data['law_code_ss_preflabel_and_uri_ss'] = [data['law_code_ss_preflabel_and_uri_ss']]
for blacklisted_code_id in blacklisted_code_ids:
if blacklisted_code_id not in code_matchtexts:
data['law_code_ss'].remove(preflabels[blacklisted_code_id])
data['law_code_ss_preflabel_and_uri_ss'].remove(preflabels[blacklisted_code_id] + ' <' + blacklisted_code_id + '>')
return parameters, data
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
646,
325,
5019,
63,
2718,
63,
1018,
421,
199,
3,
199,
3,
664,
9067,
17293,
367,
26913,
8870,
1086,
1182,
4766,
199,
3,
199,
199,
3,
2893,
26,
283,
127,
101,
25828,
20319,
14,
413,
428,
10214,
499,
7,
1035,
788,
127,
101,
25828,
297,
283,
127,
101,
25828,
20319,
10214,
413,
297,
283,
127,
101,
25828,
20319,
10214,
413,
428,
10214,
499,
418,
199,
199,
3,
11386,
26,
199,
199,
318,
664,
63,
20243,
8,
22277,
63,
8501,
12,
4179,
63,
600,
275,
488,
304,
339,
4179,
63,
26089,
275,
359,
22277,
63,
8501,
61,
2286,
372,
4179,
63,
26089,
421,
199,
3,
17,
14,
65,
199,
3,
17,
8,
18,
9,
199,
3,
17,
334,
18,
9,
421,
199,
3,
199,
3,
5536,
4179,
9479,
199,
3,
199,
199,
533,
655,
14666,
63,
5005,
63,
22277,
8,
386,
76,
63,
2718,
63,
1018,
14,
5061,
304,
2286,
347,
2112,
8,
277,
12,
2633,
29,
403,
12,
666,
29,
403,
304,
2728,
340,
2633,
365,
488,
26,
288,
2633,
275,
1052,
267,
340,
666,
365,
488,
26,
288,
666,
275,
1052,
398,
8502,
63,
14124,
275,
359,
288,
283,
127,
101,
297,
288,
283,
7221,
297,
288,
283,
1596,
30298,
352,
297,
288,
283,
28922,
297,
288,
283,
8660,
297,
288,
283,
4933,
297,
267,
1622,
398,
8502,
63,
954,
7786,
275,
359,
288,
283,
15447,
11019,
390,
84,
297,
288,
283,
15447,
10214,
297,
288,
283,
15447,
297,
288,
283,
18569,
6692,
297,
288,
283,
51,
10214,
297,
288,
283,
51,
297,
288,
283,
40,
279,
1533,
10214,
297,
288,
283,
3259,
297,
288,
283,
5667,
2626,
297,
288,
283,
46,
82,
297,
288,
283,
1713,
335,
270,
7570,
297,
267,
1622,
398,
1318,
275,
325,
5019,
63,
2718,
63,
1018,
14,
362,
63,
505,
8,
576,
9,
7318,
25089,
275,
942,
398,
2332,
275,
16746,
435,
21590,
904,
8,
8501,
63,
14124,
9,
435,
283,
2862,
55,
10,
1332,
60,
68,
7896,
55,
60,
87,
2961,
55,
6113,
66,
430,
92,
2961,
68,
7896,
87,
31,
430,
2961,
55,
31,
360,
435,
21590,
904,
8,
8501,
63,
954,
7786,
9,
435,
283,
2862,
55,
22588,
68,
7896,
87,
31,
6113,
87,
2961,
55,
6113,
66,
1724,
10223,
267,
367,
1336,
315,
295,
14,
19373,
8,
2200,
12,
1318,
12,
295,
14,
15434,
304,
288,
8502,
275,
1336,
14,
923,
8,
16,
9,
953,
8502,
275,
8502,
14,
1913,
342,
953,
25089,
14,
740,
8,
8501,
9,
953,
327,
340,
298,
127,
101,
4288,
2,
7666,
370,
298,
127,
101,
11869,
2,
288,
340,
8502,
59,
16,
61,
508,
283,
127,
101,
7,
436,
440,
8502,
59,
17,
61,
508,
283,
7596,
355,
8502,
275,
283,
127,
101,
283,
435,
8502,
59,
17,
2938,
953,
325,
5019,
63,
2718,
63,
1018,
14,
740,
8,
576,
12,
283,
22277,
63,
8501,
63,
385,
297,
8502,
9,
398,
1233,
63,
1431,
19517,
275,
325,
5019,
63,
2718,
63,
1018,
14,
362,
63,
452,
63,
1431,
19517,
8,
576,
14,
362,
360,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
297,
15927,
267,
1233,
63,
1431,
19517,
63,
1045,
63,
8501,
275,
942,
398,
20491,
3512,
275,
1052,
267,
340,
283,
22277,
63,
600,
63,
385,
63,
13829,
1302,
63,
460,
63,
2302,
63,
385,
7,
315,
666,
26,
288,
20491,
3512,
275,
325,
5019,
63,
2718,
63,
1018,
14,
362,
63,
13829,
3512,
8,
576,
459,
22277,
63,
600,
63,
385,
63,
13829,
1302,
63,
460,
63,
2302,
63,
385,
1105,
398,
340,
822,
8,
26089,
13032,
16,
436,
822,
8,
600,
63,
1431,
19517,
13032,
16,
26,
953,
1318,
275,
1318,
14,
1814,
4582,
78,
401,
298,
6099,
953,
367,
1233,
63,
1431,
63,
344,
315,
1233,
63,
1431,
19517,
26,
2234,
327,
362,
1454,
1336,
505,
334,
7395,
2870,
15,
7639,
402,
4877,
4642,
9,
355,
367,
1233,
63,
1431,
505,
315,
1233,
63,
1431,
19517,
59,
600,
63,
1431,
63,
344,
2189,
1362,
490,
367,
8502,
315,
25089,
26,
717,
340,
8502,
435,
298,
298,
435,
1233,
63,
1431,
505,
315,
1318,
503,
1233,
63,
1431,
505,
435,
298,
298,
435,
8502,
315,
1318,
26,
2490,
1169,
1233,
63,
1431,
19517,
63,
1045,
63,
8501,
14,
740,
8,
600,
63,
1431,
505,
9,
2490,
1169,
327,
340,
298,
127,
101,
4288,
2,
7666,
370,
298,
127,
101,
11869,
2,
1169,
340,
8502,
59,
16,
61,
508,
283,
127,
101,
7,
436,
440,
8502,
59,
17,
61,
508,
283,
7596,
1816,
8502,
275,
283,
127,
101,
283,
435,
8502,
59,
17,
2938,
1362,
1169,
4179,
63,
600,
63,
13829,
1302,
275,
1233,
63,
1431,
63,
344,
1169,
340,
1233,
63,
1431,
63,
344,
315,
20491,
3512,
26,
1816,
4179,
63,
600,
63,
8501,
63,
12916,
275,
8502,
435,
298,
298,
435,
20491,
3512,
59,
600,
63,
1431,
63,
344,
61,
1169,
587,
26,
1816,
4179,
63,
600,
63,
8501,
63,
12916,
275,
8502,
435,
298,
298,
435,
1233,
63,
1431,
63,
344,
489,
1169,
325,
5019,
63,
2718,
63,
1018,
14,
740,
8,
576,
12,
283,
22277,
63,
600,
63,
8501,
63,
385,
297,
4179,
63,
600,
63,
8501,
63,
12916,
9,
398,
340,
822,
8,
600,
63,
1431,
19517,
13032,
16,
26,
7846,
23180,
275,
942,
288,
769,
493,
275,
1551,
2336,
6839,
15,
26158,
23127,
1733,
15,
22126,
15,
287,
14666,
63,
5005,
63,
22277,
15,
22126,
13,
22277,
600,
13,
692,
13,
889,
13,
8501,
358,
288,
367,
1004,
315,
769,
493,
26,
355,
1004,
275,
1004,
14,
1913,
342,
355,
340,
1004,
436,
440,
1004,
14,
2460,
10064,
2349,
490,
23180,
14,
740,
8,
604,
9,
288,
769,
493,
14,
1600,
342,
953,
340,
440,
1228,
8,
576,
459,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
995,
769,
304,
355,
666,
459,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
418,
275,
359,
576,
459,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
6538,
953,
12136,
15023,
63,
600,
63,
1580,
275,
942,
288,
367,
1233,
63,
1431,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
646,
325,
5019,
63,
2718,
63,
1018,
421,
199,
3,
199,
3,
664,
9067,
17293,
367,
26913,
8870,
1086,
1182,
4766,
199,
3,
199,
199,
3,
2893,
26,
283,
127,
101,
25828,
20319,
14,
413,
428,
10214,
499,
7,
1035,
788,
127,
101,
25828,
297,
283,
127,
101,
25828,
20319,
10214,
413,
297,
283,
127,
101,
25828,
20319,
10214,
413,
428,
10214,
499,
418,
199,
199,
3,
11386,
26,
199,
199,
318,
664,
63,
20243,
8,
22277,
63,
8501,
12,
4179,
63,
600,
275,
488,
304,
339,
4179,
63,
26089,
275,
359,
22277,
63,
8501,
61,
2286,
372,
4179,
63,
26089,
421,
199,
3,
17,
14,
65,
199,
3,
17,
8,
18,
9,
199,
3,
17,
334,
18,
9,
421,
199,
3,
199,
3,
5536,
4179,
9479,
199,
3,
199,
199,
533,
655,
14666,
63,
5005,
63,
22277,
8,
386,
76,
63,
2718,
63,
1018,
14,
5061,
304,
2286,
347,
2112,
8,
277,
12,
2633,
29,
403,
12,
666,
29,
403,
304,
2728,
340,
2633,
365,
488,
26,
288,
2633,
275,
1052,
267,
340,
666,
365,
488,
26,
288,
666,
275,
1052,
398,
8502,
63,
14124,
275,
359,
288,
283,
127,
101,
297,
288,
283,
7221,
297,
288,
283,
1596,
30298,
352,
297,
288,
283,
28922,
297,
288,
283,
8660,
297,
288,
283,
4933,
297,
267,
1622,
398,
8502,
63,
954,
7786,
275,
359,
288,
283,
15447,
11019,
390,
84,
297,
288,
283,
15447,
10214,
297,
288,
283,
15447,
297,
288,
283,
18569,
6692,
297,
288,
283,
51,
10214,
297,
288,
283,
51,
297,
288,
283,
40,
279,
1533,
10214,
297,
288,
283,
3259,
297,
288,
283,
5667,
2626,
297,
288,
283,
46,
82,
297,
288,
283,
1713,
335,
270,
7570,
297,
267,
1622,
398,
1318,
275,
325,
5019,
63,
2718,
63,
1018,
14,
362,
63,
505,
8,
576,
9,
7318,
25089,
275,
942,
398,
2332,
275,
16746,
435,
21590,
904,
8,
8501,
63,
14124,
9,
435,
283,
2862,
55,
10,
1332,
60,
68,
7896,
55,
60,
87,
2961,
55,
6113,
66,
430,
92,
2961,
68,
7896,
87,
31,
430,
2961,
55,
31,
360,
435,
21590,
904,
8,
8501,
63,
954,
7786,
9,
435,
283,
2862,
55,
22588,
68,
7896,
87,
31,
6113,
87,
2961,
55,
6113,
66,
1724,
10223,
267,
367,
1336,
315,
295,
14,
19373,
8,
2200,
12,
1318,
12,
295,
14,
15434,
304,
288,
8502,
275,
1336,
14,
923,
8,
16,
9,
953,
8502,
275,
8502,
14,
1913,
342,
953,
25089,
14,
740,
8,
8501,
9,
953,
327,
340,
298,
127,
101,
4288,
2,
7666,
370,
298,
127,
101,
11869,
2,
288,
340,
8502,
59,
16,
61,
508,
283,
127,
101,
7,
436,
440,
8502,
59,
17,
61,
508,
283,
7596,
355,
8502,
275,
283,
127,
101,
283,
435,
8502,
59,
17,
2938,
953,
325,
5019,
63,
2718,
63,
1018,
14,
740,
8,
576,
12,
283,
22277,
63,
8501,
63,
385,
297,
8502,
9,
398,
1233,
63,
1431,
19517,
275,
325,
5019,
63,
2718,
63,
1018,
14,
362,
63,
452,
63,
1431,
19517,
8,
576,
14,
362,
360,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
297,
15927,
267,
1233,
63,
1431,
19517,
63,
1045,
63,
8501,
275,
942,
398,
20491,
3512,
275,
1052,
267,
340,
283,
22277,
63,
600,
63,
385,
63,
13829,
1302,
63,
460,
63,
2302,
63,
385,
7,
315,
666,
26,
288,
20491,
3512,
275,
325,
5019,
63,
2718,
63,
1018,
14,
362,
63,
13829,
3512,
8,
576,
459,
22277,
63,
600,
63,
385,
63,
13829,
1302,
63,
460,
63,
2302,
63,
385,
1105,
398,
340,
822,
8,
26089,
13032,
16,
436,
822,
8,
600,
63,
1431,
19517,
13032,
16,
26,
953,
1318,
275,
1318,
14,
1814,
4582,
78,
401,
298,
6099,
953,
367,
1233,
63,
1431,
63,
344,
315,
1233,
63,
1431,
19517,
26,
2234,
327,
362,
1454,
1336,
505,
334,
7395,
2870,
15,
7639,
402,
4877,
4642,
9,
355,
367,
1233,
63,
1431,
505,
315,
1233,
63,
1431,
19517,
59,
600,
63,
1431,
63,
344,
2189,
1362,
490,
367,
8502,
315,
25089,
26,
717,
340,
8502,
435,
298,
298,
435,
1233,
63,
1431,
505,
315,
1318,
503,
1233,
63,
1431,
505,
435,
298,
298,
435,
8502,
315,
1318,
26,
2490,
1169,
1233,
63,
1431,
19517,
63,
1045,
63,
8501,
14,
740,
8,
600,
63,
1431,
505,
9,
2490,
1169,
327,
340,
298,
127,
101,
4288,
2,
7666,
370,
298,
127,
101,
11869,
2,
1169,
340,
8502,
59,
16,
61,
508,
283,
127,
101,
7,
436,
440,
8502,
59,
17,
61,
508,
283,
7596,
1816,
8502,
275,
283,
127,
101,
283,
435,
8502,
59,
17,
2938,
1362,
1169,
4179,
63,
600,
63,
13829,
1302,
275,
1233,
63,
1431,
63,
344,
1169,
340,
1233,
63,
1431,
63,
344,
315,
20491,
3512,
26,
1816,
4179,
63,
600,
63,
8501,
63,
12916,
275,
8502,
435,
298,
298,
435,
20491,
3512,
59,
600,
63,
1431,
63,
344,
61,
1169,
587,
26,
1816,
4179,
63,
600,
63,
8501,
63,
12916,
275,
8502,
435,
298,
298,
435,
1233,
63,
1431,
63,
344,
489,
1169,
325,
5019,
63,
2718,
63,
1018,
14,
740,
8,
576,
12,
283,
22277,
63,
600,
63,
8501,
63,
385,
297,
4179,
63,
600,
63,
8501,
63,
12916,
9,
398,
340,
822,
8,
600,
63,
1431,
19517,
13032,
16,
26,
7846,
23180,
275,
942,
288,
769,
493,
275,
1551,
2336,
6839,
15,
26158,
23127,
1733,
15,
22126,
15,
287,
14666,
63,
5005,
63,
22277,
15,
22126,
13,
22277,
600,
13,
692,
13,
889,
13,
8501,
358,
288,
367,
1004,
315,
769,
493,
26,
355,
1004,
275,
1004,
14,
1913,
342,
355,
340,
1004,
436,
440,
1004,
14,
2460,
10064,
2349,
490,
23180,
14,
740,
8,
604,
9,
288,
769,
493,
14,
1600,
342,
953,
340,
440,
1228,
8,
576,
459,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
995,
769,
304,
355,
666,
459,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
418,
275,
359,
576,
459,
22277,
63,
600,
63,
385,
63,
1431,
505,
63,
385,
6538,
953,
12136,
15023,
63,
600,
63,
1580,
275,
942,
288,
367,
1233,
63,
1431,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
chongtianfeiyu/kbengine
|
kbe/src/lib/python/Lib/test/test_pulldom.py
|
118
|
12467
|
import io
import unittest
import sys
import xml.sax
from xml.sax.xmlreader import AttributesImpl
from xml.dom import pulldom
from test.support import run_unittest, findfile
tstfile = findfile("test.xml", subdir="xmltestdata")
# A handy XML snippet, containing attributes, a namespace prefix, and a
# self-closing tag:
SMALL_SAMPLE = """<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xdc="http://www.xml.com/books">
<!-- A comment -->
<title>Introduction to XSL</title>
<hr/>
<p><xdc:author xdc:attrib="prefixed attribute" attrib="other attrib">A. Namespace</xdc:author></p>
</html>"""
class PullDOMTestCase(unittest.TestCase):
def test_parse(self):
"""Minimal test of DOMEventStream.parse()"""
# This just tests that parsing from a stream works. Actual parser
# semantics are tested using parseString with a more focused XML
# fragment.
# Test with a filename:
handler = pulldom.parse(tstfile)
self.addCleanup(handler.stream.close)
list(handler)
# Test with a file object:
with open(tstfile, "rb") as fin:
list(pulldom.parse(fin))
def test_parse_semantics(self):
"""Test DOMEventStream parsing semantics."""
items = pulldom.parseString(SMALL_SAMPLE)
evt, node = next(items)
# Just check the node is a Document:
self.assertTrue(hasattr(node, "createElement"))
self.assertEqual(pulldom.START_DOCUMENT, evt)
evt, node = next(items)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("html", node.tagName)
self.assertEqual(2, len(node.attributes))
self.assertEqual(node.attributes.getNamedItem("xmlns:xdc").value,
"http://www.xml.com/books")
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt) # Line break
evt, node = next(items)
# XXX - A comment should be reported here!
# self.assertEqual(pulldom.COMMENT, evt)
# Line break after swallowed comment:
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual("title", node.tagName)
title_node = node
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt)
self.assertEqual("Introduction to XSL", node.data)
evt, node = next(items)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("title", node.tagName)
self.assertTrue(title_node is node)
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("hr", node.tagName)
evt, node = next(items)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("hr", node.tagName)
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("p", node.tagName)
evt, node = next(items)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("xdc:author", node.tagName)
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("xdc:author", node.tagName)
evt, node = next(items)
self.assertEqual(pulldom.END_ELEMENT, evt)
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual(pulldom.END_ELEMENT, evt)
# XXX No END_DOCUMENT item is ever obtained:
#evt, node = next(items)
#self.assertEqual(pulldom.END_DOCUMENT, evt)
def test_expandItem(self):
"""Ensure expandItem works as expected."""
items = pulldom.parseString(SMALL_SAMPLE)
# Loop through the nodes until we get to a "title" start tag:
for evt, item in items:
if evt == pulldom.START_ELEMENT and item.tagName == "title":
items.expandNode(item)
self.assertEqual(1, len(item.childNodes))
break
else:
self.fail("No \"title\" element detected in SMALL_SAMPLE!")
# Loop until we get to the next start-element:
for evt, node in items:
if evt == pulldom.START_ELEMENT:
break
self.assertEqual("hr", node.tagName,
"expandNode did not leave DOMEventStream in the correct state.")
# Attempt to expand a standalone element:
items.expandNode(node)
self.assertEqual(next(items)[0], pulldom.CHARACTERS)
evt, node = next(items)
self.assertEqual(node.tagName, "p")
items.expandNode(node)
next(items) # Skip character data
evt, node = next(items)
self.assertEqual(node.tagName, "html")
with self.assertRaises(StopIteration):
next(items)
items.clear()
self.assertIsNone(items.parser)
self.assertIsNone(items.stream)
@unittest.expectedFailure
def test_comment(self):
"""PullDOM does not receive "comment" events."""
items = pulldom.parseString(SMALL_SAMPLE)
for evt, _ in items:
if evt == pulldom.COMMENT:
break
else:
self.fail("No comment was encountered")
@unittest.expectedFailure
def test_end_document(self):
"""PullDOM does not receive "end-document" events."""
items = pulldom.parseString(SMALL_SAMPLE)
# Read all of the nodes up to and including </html>:
for evt, node in items:
if evt == pulldom.END_ELEMENT and node.tagName == "html":
break
try:
# Assert that the next node is END_DOCUMENT:
evt, node = next(items)
self.assertEqual(pulldom.END_DOCUMENT, evt)
except StopIteration:
self.fail(
"Ran out of events, but should have received END_DOCUMENT")
class ThoroughTestCase(unittest.TestCase):
"""Test the hard-to-reach parts of pulldom."""
def test_thorough_parse(self):
"""Test some of the hard-to-reach parts of PullDOM."""
self._test_thorough(pulldom.parse(None, parser=SAXExerciser()))
@unittest.expectedFailure
def test_sax2dom_fail(self):
"""SAX2DOM can"t handle a PI before the root element."""
pd = SAX2DOMTestHelper(None, SAXExerciser(), 12)
self._test_thorough(pd)
def test_thorough_sax2dom(self):
"""Test some of the hard-to-reach parts of SAX2DOM."""
pd = SAX2DOMTestHelper(None, SAX2DOMExerciser(), 12)
self._test_thorough(pd, False)
def _test_thorough(self, pd, before_root=True):
"""Test some of the hard-to-reach parts of the parser, using a mock
parser."""
evt, node = next(pd)
self.assertEqual(pulldom.START_DOCUMENT, evt)
# Just check the node is a Document:
self.assertTrue(hasattr(node, "createElement"))
if before_root:
evt, node = next(pd)
self.assertEqual(pulldom.COMMENT, evt)
self.assertEqual("a comment", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.PROCESSING_INSTRUCTION, evt)
self.assertEqual("target", node.target)
self.assertEqual("data", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("html", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.COMMENT, evt)
self.assertEqual("a comment", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.PROCESSING_INSTRUCTION, evt)
self.assertEqual("target", node.target)
self.assertEqual("data", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.START_ELEMENT, evt)
self.assertEqual("p", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.CHARACTERS, evt)
self.assertEqual("text", node.data)
evt, node = next(pd)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("p", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.END_ELEMENT, evt)
self.assertEqual("html", node.tagName)
evt, node = next(pd)
self.assertEqual(pulldom.END_DOCUMENT, evt)
class SAXExerciser(object):
"""A fake sax parser that calls some of the harder-to-reach sax methods to
ensure it emits the correct events"""
def setContentHandler(self, handler):
self._handler = handler
def parse(self, _):
h = self._handler
h.startDocument()
# The next two items ensure that items preceding the first
# start_element are properly stored and emitted:
h.comment("a comment")
h.processingInstruction("target", "data")
h.startElement("html", AttributesImpl({}))
h.comment("a comment")
h.processingInstruction("target", "data")
h.startElement("p", AttributesImpl({"class": "paraclass"}))
h.characters("text")
h.endElement("p")
h.endElement("html")
h.endDocument()
def stub(self, *args, **kwargs):
"""Stub method. Does nothing."""
pass
setProperty = stub
setFeature = stub
class SAX2DOMExerciser(SAXExerciser):
"""The same as SAXExerciser, but without the processing instruction and
comment before the root element, because S2D can"t handle it"""
def parse(self, _):
h = self._handler
h.startDocument()
h.startElement("html", AttributesImpl({}))
h.comment("a comment")
h.processingInstruction("target", "data")
h.startElement("p", AttributesImpl({"class": "paraclass"}))
h.characters("text")
h.endElement("p")
h.endElement("html")
h.endDocument()
class SAX2DOMTestHelper(pulldom.DOMEventStream):
"""Allows us to drive SAX2DOM from a DOMEventStream."""
def reset(self):
self.pulldom = pulldom.SAX2DOM()
# This content handler relies on namespace support
self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
self.parser.setContentHandler(self.pulldom)
class SAX2DOMTestCase(unittest.TestCase):
def confirm(self, test, testname="Test"):
self.assertTrue(test, testname)
def test_basic(self):
"""Ensure SAX2DOM can parse from a stream."""
with io.StringIO(SMALL_SAMPLE) as fin:
sd = SAX2DOMTestHelper(fin, xml.sax.make_parser(),
len(SMALL_SAMPLE))
for evt, node in sd:
if evt == pulldom.START_ELEMENT and node.tagName == "html":
break
# Because the buffer is the same length as the XML, all the
# nodes should have been parsed and added:
self.assertGreater(len(node.childNodes), 0)
def testSAX2DOM(self):
"""Ensure SAX2DOM expands nodes as expected."""
sax2dom = pulldom.SAX2DOM()
sax2dom.startDocument()
sax2dom.startElement("doc", {})
sax2dom.characters("text")
sax2dom.startElement("subelm", {})
sax2dom.characters("text")
sax2dom.endElement("subelm")
sax2dom.characters("text")
sax2dom.endElement("doc")
sax2dom.endDocument()
doc = sax2dom.document
root = doc.documentElement
(text1, elm1, text2) = root.childNodes
text3 = elm1.childNodes[0]
self.assertIsNone(text1.previousSibling)
self.assertIs(text1.nextSibling, elm1)
self.assertIs(elm1.previousSibling, text1)
self.assertIs(elm1.nextSibling, text2)
self.assertIs(text2.previousSibling, elm1)
self.assertIsNone(text2.nextSibling)
self.assertIsNone(text3.previousSibling)
self.assertIsNone(text3.nextSibling)
self.assertIs(root.parentNode, doc)
self.assertIs(text1.parentNode, root)
self.assertIs(elm1.parentNode, root)
self.assertIs(text2.parentNode, root)
self.assertIs(text3.parentNode, elm1)
doc.unlink()
def test_main():
run_unittest(PullDOMTestCase, ThoroughTestCase, SAX2DOMTestCase)
if __name__ == "__main__":
test_main()
|
lgpl-3.0
|
[
646,
5890,
199,
646,
2882,
199,
646,
984,
199,
646,
2748,
14,
14338,
199,
199,
504,
2748,
14,
14338,
14,
1652,
5503,
492,
9382,
4748,
199,
504,
2748,
14,
4556,
492,
10299,
4556,
199,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
12,
2342,
493,
421,
199,
84,
270,
493,
275,
2342,
493,
480,
396,
14,
1652,
401,
15488,
628,
1652,
18481,
531,
199,
199,
3,
437,
4926,
89,
4692,
17440,
12,
3035,
3004,
12,
282,
3231,
2403,
12,
436,
282,
199,
3,
291,
13,
11707,
1947,
26,
199,
28570,
63,
15827,
275,
31501,
1652,
1015,
628,
17,
14,
16,
24327,
199,
28,
1360,
9604,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
12909,
2,
9604,
26,
10550,
628,
1014,
921,
1544,
14,
1652,
14,
957,
15,
8858,
1743,
199,
25273,
437,
3721,
10541,
199,
28,
1213,
30,
3241,
293,
5199,
370,
1323,
4929,
1108,
1213,
30,
199,
28,
6271,
3133,
199,
28,
80,
2535,
10550,
26,
2502,
671,
3833,
26,
6640,
628,
27833,
2225,
2,
14399,
628,
1848,
14399,
1743,
33,
14,
19317,
1108,
10550,
26,
2502,
2957,
80,
30,
199,
1108,
1360,
11193,
421,
199,
533,
27705,
10462,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1122,
8,
277,
304,
267,
408,
4649,
7265,
511,
402,
14316,
2390,
3296,
14,
1122,
32664,
398,
327,
961,
2951,
2295,
626,
6057,
687,
282,
2547,
5419,
14,
18982,
1061,
1798,
267,
327,
19002,
787,
12470,
1808,
2198,
1558,
543,
282,
1655,
289,
679,
2972,
4692,
267,
327,
7956,
14,
398,
327,
1379,
543,
282,
1788,
26,
267,
3016,
275,
10299,
4556,
14,
1122,
8,
84,
270,
493,
9,
267,
291,
14,
12808,
8,
2232,
14,
1745,
14,
1600,
9,
267,
769,
8,
2232,
9,
398,
327,
1379,
543,
282,
570,
909,
26,
267,
543,
1551,
8,
84,
270,
493,
12,
298,
4848,
531,
465,
2583,
26,
288,
769,
8,
9302,
4556,
14,
1122,
8,
2408,
430,
339,
347,
511,
63,
1122,
63,
261,
1237,
7769,
8,
277,
304,
267,
408,
774,
14316,
2390,
3296,
6057,
19002,
1041,
398,
2974,
275,
10299,
4556,
14,
14934,
8,
28570,
63,
15827,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
327,
13870,
1104,
314,
1031,
365,
282,
7543,
26,
267,
291,
14,
1815,
8,
11161,
8,
932,
12,
298,
20296,
2237,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
7884,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
1360,
401,
1031,
14,
20183,
9,
267,
291,
14,
629,
8,
18,
12,
822,
8,
932,
14,
2987,
430,
267,
291,
14,
629,
8,
932,
14,
2987,
14,
362,
7989,
2081,
480,
13991,
26,
10550,
3471,
585,
12,
1598,
298,
1014,
921,
1544,
14,
1652,
14,
957,
15,
8858,
531,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
327,
7030,
2059,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
327,
5787,
446,
437,
3721,
1077,
506,
14581,
2348,
1,
267,
327,
291,
14,
629,
8,
9302,
4556,
14,
10973,
12,
16330,
9,
267,
327,
7030,
2059,
2410,
5584,
6541,
3721,
26,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
480,
1213,
401,
1031,
14,
20183,
9,
267,
2538,
63,
932,
275,
1031,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
291,
14,
629,
480,
3241,
293,
5199,
370,
1323,
4929,
401,
1031,
14,
576,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
1213,
401,
1031,
14,
20183,
9,
267,
291,
14,
1815,
8,
1213,
63,
932,
365,
1031,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
6271,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
6271,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
80,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
10550,
26,
2502,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
10550,
26,
2502,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
327,
5787,
3091,
7729,
63,
7884,
1242,
365,
14433,
15884,
26,
267,
327,
19296,
12,
1031,
275,
2163,
8,
1744,
9,
267,
327,
277,
14,
629,
8,
9302,
4556,
14,
3902,
63,
7884,
12,
16330,
9,
339,
347,
511,
63,
4441
] |
[
5890,
199,
646,
2882,
199,
646,
984,
199,
646,
2748,
14,
14338,
199,
199,
504,
2748,
14,
14338,
14,
1652,
5503,
492,
9382,
4748,
199,
504,
2748,
14,
4556,
492,
10299,
4556,
199,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
12,
2342,
493,
421,
199,
84,
270,
493,
275,
2342,
493,
480,
396,
14,
1652,
401,
15488,
628,
1652,
18481,
531,
199,
199,
3,
437,
4926,
89,
4692,
17440,
12,
3035,
3004,
12,
282,
3231,
2403,
12,
436,
282,
199,
3,
291,
13,
11707,
1947,
26,
199,
28570,
63,
15827,
275,
31501,
1652,
1015,
628,
17,
14,
16,
24327,
199,
28,
1360,
9604,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
12909,
2,
9604,
26,
10550,
628,
1014,
921,
1544,
14,
1652,
14,
957,
15,
8858,
1743,
199,
25273,
437,
3721,
10541,
199,
28,
1213,
30,
3241,
293,
5199,
370,
1323,
4929,
1108,
1213,
30,
199,
28,
6271,
3133,
199,
28,
80,
2535,
10550,
26,
2502,
671,
3833,
26,
6640,
628,
27833,
2225,
2,
14399,
628,
1848,
14399,
1743,
33,
14,
19317,
1108,
10550,
26,
2502,
2957,
80,
30,
199,
1108,
1360,
11193,
421,
199,
533,
27705,
10462,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1122,
8,
277,
304,
267,
408,
4649,
7265,
511,
402,
14316,
2390,
3296,
14,
1122,
32664,
398,
327,
961,
2951,
2295,
626,
6057,
687,
282,
2547,
5419,
14,
18982,
1061,
1798,
267,
327,
19002,
787,
12470,
1808,
2198,
1558,
543,
282,
1655,
289,
679,
2972,
4692,
267,
327,
7956,
14,
398,
327,
1379,
543,
282,
1788,
26,
267,
3016,
275,
10299,
4556,
14,
1122,
8,
84,
270,
493,
9,
267,
291,
14,
12808,
8,
2232,
14,
1745,
14,
1600,
9,
267,
769,
8,
2232,
9,
398,
327,
1379,
543,
282,
570,
909,
26,
267,
543,
1551,
8,
84,
270,
493,
12,
298,
4848,
531,
465,
2583,
26,
288,
769,
8,
9302,
4556,
14,
1122,
8,
2408,
430,
339,
347,
511,
63,
1122,
63,
261,
1237,
7769,
8,
277,
304,
267,
408,
774,
14316,
2390,
3296,
6057,
19002,
1041,
398,
2974,
275,
10299,
4556,
14,
14934,
8,
28570,
63,
15827,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
327,
13870,
1104,
314,
1031,
365,
282,
7543,
26,
267,
291,
14,
1815,
8,
11161,
8,
932,
12,
298,
20296,
2237,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
7884,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
1360,
401,
1031,
14,
20183,
9,
267,
291,
14,
629,
8,
18,
12,
822,
8,
932,
14,
2987,
430,
267,
291,
14,
629,
8,
932,
14,
2987,
14,
362,
7989,
2081,
480,
13991,
26,
10550,
3471,
585,
12,
1598,
298,
1014,
921,
1544,
14,
1652,
14,
957,
15,
8858,
531,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
327,
7030,
2059,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
327,
5787,
446,
437,
3721,
1077,
506,
14581,
2348,
1,
267,
327,
291,
14,
629,
8,
9302,
4556,
14,
10973,
12,
16330,
9,
267,
327,
7030,
2059,
2410,
5584,
6541,
3721,
26,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
480,
1213,
401,
1031,
14,
20183,
9,
267,
2538,
63,
932,
275,
1031,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
291,
14,
629,
480,
3241,
293,
5199,
370,
1323,
4929,
401,
1031,
14,
576,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
1213,
401,
1031,
14,
20183,
9,
267,
291,
14,
1815,
8,
1213,
63,
932,
365,
1031,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
6271,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
6271,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
80,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
7363,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
10550,
26,
2502,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
291,
14,
629,
480,
10550,
26,
2502,
401,
1031,
14,
20183,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
5901,
3036,
3960,
12,
16330,
9,
267,
16330,
12,
1031,
275,
2163,
8,
1744,
9,
267,
291,
14,
629,
8,
9302,
4556,
14,
3902,
63,
12535,
12,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cloverstd/wechatpy
|
wechatpy/oauth/__init__.py
|
2
|
6592
|
# -*- coding: utf-8 -*-
"""
wechatpy.oauth
~~~~~~~~~~~~~~~
This module provides OAuth2 library for WeChat
:copyright: (c) 2014 by messense.
:license: MIT, see LICENSE for more details.
"""
from __future__ import absolute_import, unicode_literals
import requests
from six.moves.urllib.parse import quote
from wechatpy.utils import json
from wechatpy.exceptions import WeChatOAuthException
class WeChatOAuth(object):
"""微信公众平台 OAuth 网页授权 """
API_BASE_URL = 'https://api.weixin.qq.com/'
OAUTH_BASE_URL = 'https://open.weixin.qq.com/connect/'
def __init__(self, app_id, secret, redirect_uri,
scope='snsapi_base', state=''):
"""
:param app_id: 微信公众号 app_id
:param secret: 微信公众号 secret
:param redirect_uri: OAuth2 redirect URI
:param scope: 可选,微信公众号 OAuth2 scope,默认为 ``snsapi_base``
:param state: 可选,微信公众号 OAuth2 state
"""
self.app_id = app_id
self.secret = secret
self.redirect_uri = redirect_uri
self.scope = scope
self.state = state
self._http = requests.Session()
def _request(self, method, url_or_endpoint, **kwargs):
if not url_or_endpoint.startswith(('http://', 'https://')):
url = '{base}{endpoint}'.format(
base=self.API_BASE_URL,
endpoint=url_or_endpoint
)
else:
url = url_or_endpoint
if isinstance(kwargs.get('data', ''), dict):
body = json.dumps(kwargs['data'], ensure_ascii=False)
body = body.encode('utf-8')
kwargs['data'] = body
res = self._http.request(
method=method,
url=url,
**kwargs
)
try:
res.raise_for_status()
except requests.RequestException as reqe:
raise WeChatOAuthException(
errcode=None,
errmsg=None,
client=self,
request=reqe.request,
response=reqe.response
)
result = json.loads(res.content.decode('utf-8', 'ignore'), strict=False)
if 'errcode' in result and result['errcode'] != 0:
errcode = result['errcode']
errmsg = result['errmsg']
raise WeChatOAuthException(
errcode,
errmsg,
client=self,
request=res.request,
response=res
)
return result
def _get(self, url, **kwargs):
return self._request(
method='get',
url_or_endpoint=url,
**kwargs
)
@property
def authorize_url(self):
"""获取授权跳转地址
:return: URL 地址
"""
redirect_uri = quote(self.redirect_uri, safe='')
url_list = [
self.OAUTH_BASE_URL,
'oauth2/authorize?appid=',
self.app_id,
'&redirect_uri=',
redirect_uri,
'&response_type=code&scope=',
self.scope
]
if self.state:
url_list.extend(['&state=', self.state])
url_list.append('#wechat_redirect')
return ''.join(url_list)
@property
def qrconnect_url(self):
"""生成扫码登录地址
:return: URL 地址
"""
redirect_uri = quote(self.redirect_uri, safe='')
url_list = [
self.OAUTH_BASE_URL,
'qrconnect?appid=',
self.app_id,
'&redirect_uri=',
redirect_uri,
'&response_type=code&scope=',
'snsapi_login' # scope
]
if self.state:
url_list.extend(['&state=', self.state])
url_list.append('#wechat_redirect')
return ''.join(url_list)
def fetch_access_token(self, code):
"""获取 access_token
:param code: 授权完成跳转回来后 URL 中的 code 参数
:return: JSON 数据包
"""
res = self._get(
'sns/oauth2/access_token',
params={
'appid': self.app_id,
'secret': self.secret,
'code': code,
'grant_type': 'authorization_code'
}
)
self.access_token = res['access_token']
self.open_id = res['openid']
self.refresh_token = res['refresh_token']
self.expires_in = res['expires_in']
return res
def refresh_access_token(self, refresh_token):
"""刷新 access token
:param refresh_token: OAuth2 refresh token
:return: JSON 数据包
"""
res = self._get(
'sns/oauth2/refresh_token',
params={
'appid': self.app_id,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
)
self.access_token = res['access_token']
self.open_id = res['openid']
self.refresh_token = res['refresh_token']
self.expires_in = res['expires_in']
return res
def get_user_info(self, openid=None, access_token=None, lang='zh_CN'):
"""获取用户信息
:param openid: 可选,微信 openid,默认获取当前授权用户信息
:param access_token: 可选,access_token,默认使用当前授权用户的 access_token
:param lang: 可选,语言偏好, 默认为 ``zh_CN``
:return: JSON 数据包
"""
openid = openid or self.open_id
access_token = access_token or self.access_token
return self._get(
'sns/userinfo',
params={
'access_token': access_token,
'openid': openid,
'lang': lang
}
)
def check_access_token(self, openid=None, access_token=None):
"""检查 access_token 有效性
:param openid: 可选,微信 openid,默认获取当前授权用户信息
:param access_token: 可选,access_token,默认使用当前授权用户的 access_token
:return: 有效返回 True,否则 False
"""
openid = openid or self.open_id
access_token = access_token or self.access_token
res = self._get(
'sns/auth',
params={
'access_token': access_token,
'openid': openid
}
)
if res['errcode'] == 0:
return True
return False
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
781,
10289,
647,
14,
6126,
272,
32202,
23597,
339,
961,
859,
6571,
11715,
18,
3555,
367,
2136,
21954,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
26560,
16517,
14,
272,
520,
1682,
26,
10697,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
646,
4145,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
6313,
199,
199,
504,
781,
10289,
647,
14,
1208,
492,
2022,
199,
504,
781,
10289,
647,
14,
3924,
492,
2136,
21954,
12906,
1726,
421,
199,
533,
2136,
21954,
12906,
8,
785,
304,
272,
408,
19073,
107,
23305,
19150,
17848,
246,
25274,
6075,
109,
11715,
9112,
122,
240,
27513,
114,
17797,
231,
31038,
408,
339,
3261,
63,
5825,
63,
2632,
275,
283,
2859,
921,
1246,
14,
1129,
3774,
14,
16672,
14,
957,
4805,
272,
593,
5580,
63,
5825,
63,
2632,
275,
283,
2859,
921,
1490,
14,
1129,
3774,
14,
16672,
14,
957,
15,
2242,
4805,
339,
347,
636,
826,
721,
277,
12,
1145,
63,
344,
12,
7565,
12,
4660,
63,
2302,
12,
326,
4194,
534,
83,
561,
1246,
63,
1095,
297,
1174,
9280,
267,
408,
398,
520,
635,
1145,
63,
344,
26,
7094,
123,
107,
23305,
19150,
17848,
246,
12937,
1145,
63,
344,
267,
520,
635,
7565,
26,
7094,
123,
107,
23305,
19150,
17848,
246,
12937,
7565,
267,
520,
635,
4660,
63,
2302,
26,
11715,
18,
4660,
9022,
267,
520,
635,
4194,
26,
221,
25521,
14333,
232,
12356,
19073,
107,
23305,
19150,
17848,
246,
12937,
11715,
18,
4194,
12356,
28931,
247,
14082,
98,
24971,
1124,
83,
561,
1246,
63,
1095,
1040,
267,
520,
635,
1174,
26,
221,
25521,
14333,
232,
12356,
19073,
107,
23305,
19150,
17848,
246,
12937,
11715,
18,
1174,
267,
408,
267,
291,
14,
571,
63,
344,
275,
1145,
63,
344,
267,
291,
14,
4731,
275,
7565,
267,
291,
14,
4876,
63,
2302,
275,
4660,
63,
2302,
267,
291,
14,
2645,
275,
4194,
267,
291,
14,
929,
275,
1174,
267,
291,
423,
1014,
275,
4145,
14,
4434,
342,
339,
347,
485,
1069,
8,
277,
12,
1083,
12,
1166,
63,
269,
63,
6520,
12,
1011,
958,
304,
267,
340,
440,
1166,
63,
269,
63,
6520,
14,
2460,
4725,
1014,
921,
297,
283,
2859,
921,
8109,
288,
1166,
275,
5041,
1095,
8847,
6520,
5285,
908,
8,
355,
1300,
29,
277,
14,
3735,
63,
5825,
63,
2632,
12,
355,
6037,
29,
633,
63,
269,
63,
6520,
288,
776,
267,
587,
26,
288,
1166,
275,
1166,
63,
269,
63,
6520,
398,
340,
1228,
8,
958,
14,
362,
360,
576,
297,
9929,
1211,
304,
288,
2396,
275,
2022,
14,
4180,
8,
958,
459,
576,
995,
4868,
63,
4371,
29,
797,
9,
288,
2396,
275,
2396,
14,
2143,
360,
1624,
13,
24,
358,
288,
2074,
459,
576,
418,
275,
2396,
398,
522,
275,
291,
423,
1014,
14,
1069,
8,
288,
1083,
29,
765,
12,
288,
1166,
29,
633,
12,
288,
1011,
958,
267,
776,
267,
862,
26,
288,
522,
14,
3730,
63,
509,
63,
1205,
342,
267,
871,
4145,
14,
28724,
465,
2648,
69,
26,
288,
746,
2136,
21954,
12906,
1726,
8,
355,
30771,
29,
403,
12,
355,
22070,
29,
403,
12,
355,
1890,
29,
277,
12,
355,
1056,
29,
2103,
69,
14,
1069,
12,
355,
1177,
29,
2103,
69,
14,
1310,
288,
776,
267,
754,
275,
2022,
14,
3640,
8,
470,
14,
1317,
14,
2708,
360,
1624,
13,
24,
297,
283,
4247,
659,
7478,
29,
797,
9,
398,
340,
283,
1508,
600,
7,
315,
754,
436,
754,
459,
1508,
600,
418,
1137,
378,
26,
288,
30771,
275,
754,
459,
1508,
600,
418,
288,
22070,
275,
754,
459,
16024,
418,
288,
746,
2136,
21954,
12906,
1726,
8,
355,
30771,
12,
355,
22070,
12,
355,
1890,
29,
277,
12,
355,
1056,
29,
470,
14,
1069,
12,
355,
1177,
29,
470,
288,
776,
398,
372,
754,
339,
347,
485,
362,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
423,
1069,
8,
288,
1083,
534,
362,
297,
288,
1166,
63,
269,
63,
6520,
29,
633,
12,
288,
1011,
958,
267,
776,
339,
768,
1829,
272,
347,
20210,
63,
633,
8,
277,
304,
267,
408,
165,
237,
116,
22924,
17797,
231,
31038,
30987,
112,
30229,
27340,
30899,
223,
398,
520,
1107,
26,
2851,
7094,
251,
109,
30899,
223,
267,
408,
267,
4660,
63,
2302,
275,
6313,
8,
277,
14,
4876,
63,
2302,
12,
5048,
13275,
267,
1166,
63,
513,
275,
359,
288,
291,
14,
24041,
63,
5825,
63,
2632,
12,
288,
283,
6126,
18,
15,
14204,
31,
571,
344,
4009,
288,
291,
14,
571,
63,
344,
12,
288,
7673,
4876,
63,
2302,
4009,
288,
4660,
63,
2302,
12,
288,
7673,
1310,
63,
466,
29,
600,
6,
2645,
4009,
288,
291,
14,
2645,
267,
1622,
267,
340,
291,
14,
929,
26,
288,
1166,
63,
513,
14,
2880,
2941,
6,
929,
4009,
291,
14,
929,
566,
267,
1166,
63,
513,
14,
740,
7863,
1129,
10289,
63,
4876,
358,
267,
372,
6522,
904,
8,
633,
63,
513,
9,
339,
768,
1829,
272,
347,
29757,
2242,
63,
633,
8,
277,
304,
267,
408,
29319,
16888,
10862,
105,
8967,
23460,
8698,
122,
244,
27340,
30899,
223,
398,
520,
1107,
26,
2851,
7094,
251,
109,
30899,
223,
267,
408,
267,
4660,
63,
2302,
275,
6313,
8,
277,
14,
4876,
63,
2302,
12,
5048,
13275,
267,
1166,
63,
513,
275,
359,
288,
291,
14,
24041,
63,
5825,
63,
2632,
12,
288,
283,
16596,
2242,
31,
571,
344,
4009,
288,
291,
14,
571,
63,
344,
12,
288,
7673,
4876,
63,
2302,
4009,
288,
4660,
63,
2302,
12,
288,
7673,
1310,
63,
466,
29,
600,
6,
2645,
4009,
288,
283,
83,
561,
1246,
63,
2886,
7,
221,
327,
4194,
267,
1622,
267,
340,
291,
14,
929,
26,
288,
1166,
63,
513,
14,
2880,
2941,
6,
929,
4009,
291,
14,
929,
566,
267,
1166,
63,
513,
14,
740,
7863,
1129,
10289,
63,
4876,
358,
267,
372,
6522,
904,
8,
633,
63,
513,
9,
339,
347,
5267,
63,
2732,
63,
1418,
8,
277,
12,
1233,
304,
267,
408,
165,
237,
116,
22924,
2879,
63,
1418,
398,
520,
635,
1233
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
781,
10289,
647,
14,
6126,
272,
32202,
23597,
339,
961,
859,
6571,
11715,
18,
3555,
367,
2136,
21954,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
26560,
16517,
14,
272,
520,
1682,
26,
10697,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
646,
4145,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
6313,
199,
199,
504,
781,
10289,
647,
14,
1208,
492,
2022,
199,
504,
781,
10289,
647,
14,
3924,
492,
2136,
21954,
12906,
1726,
421,
199,
533,
2136,
21954,
12906,
8,
785,
304,
272,
408,
19073,
107,
23305,
19150,
17848,
246,
25274,
6075,
109,
11715,
9112,
122,
240,
27513,
114,
17797,
231,
31038,
408,
339,
3261,
63,
5825,
63,
2632,
275,
283,
2859,
921,
1246,
14,
1129,
3774,
14,
16672,
14,
957,
4805,
272,
593,
5580,
63,
5825,
63,
2632,
275,
283,
2859,
921,
1490,
14,
1129,
3774,
14,
16672,
14,
957,
15,
2242,
4805,
339,
347,
636,
826,
721,
277,
12,
1145,
63,
344,
12,
7565,
12,
4660,
63,
2302,
12,
326,
4194,
534,
83,
561,
1246,
63,
1095,
297,
1174,
9280,
267,
408,
398,
520,
635,
1145,
63,
344,
26,
7094,
123,
107,
23305,
19150,
17848,
246,
12937,
1145,
63,
344,
267,
520,
635,
7565,
26,
7094,
123,
107,
23305,
19150,
17848,
246,
12937,
7565,
267,
520,
635,
4660,
63,
2302,
26,
11715,
18,
4660,
9022,
267,
520,
635,
4194,
26,
221,
25521,
14333,
232,
12356,
19073,
107,
23305,
19150,
17848,
246,
12937,
11715,
18,
4194,
12356,
28931,
247,
14082,
98,
24971,
1124,
83,
561,
1246,
63,
1095,
1040,
267,
520,
635,
1174,
26,
221,
25521,
14333,
232,
12356,
19073,
107,
23305,
19150,
17848,
246,
12937,
11715,
18,
1174,
267,
408,
267,
291,
14,
571,
63,
344,
275,
1145,
63,
344,
267,
291,
14,
4731,
275,
7565,
267,
291,
14,
4876,
63,
2302,
275,
4660,
63,
2302,
267,
291,
14,
2645,
275,
4194,
267,
291,
14,
929,
275,
1174,
267,
291,
423,
1014,
275,
4145,
14,
4434,
342,
339,
347,
485,
1069,
8,
277,
12,
1083,
12,
1166,
63,
269,
63,
6520,
12,
1011,
958,
304,
267,
340,
440,
1166,
63,
269,
63,
6520,
14,
2460,
4725,
1014,
921,
297,
283,
2859,
921,
8109,
288,
1166,
275,
5041,
1095,
8847,
6520,
5285,
908,
8,
355,
1300,
29,
277,
14,
3735,
63,
5825,
63,
2632,
12,
355,
6037,
29,
633,
63,
269,
63,
6520,
288,
776,
267,
587,
26,
288,
1166,
275,
1166,
63,
269,
63,
6520,
398,
340,
1228,
8,
958,
14,
362,
360,
576,
297,
9929,
1211,
304,
288,
2396,
275,
2022,
14,
4180,
8,
958,
459,
576,
995,
4868,
63,
4371,
29,
797,
9,
288,
2396,
275,
2396,
14,
2143,
360,
1624,
13,
24,
358,
288,
2074,
459,
576,
418,
275,
2396,
398,
522,
275,
291,
423,
1014,
14,
1069,
8,
288,
1083,
29,
765,
12,
288,
1166,
29,
633,
12,
288,
1011,
958,
267,
776,
267,
862,
26,
288,
522,
14,
3730,
63,
509,
63,
1205,
342,
267,
871,
4145,
14,
28724,
465,
2648,
69,
26,
288,
746,
2136,
21954,
12906,
1726,
8,
355,
30771,
29,
403,
12,
355,
22070,
29,
403,
12,
355,
1890,
29,
277,
12,
355,
1056,
29,
2103,
69,
14,
1069,
12,
355,
1177,
29,
2103,
69,
14,
1310,
288,
776,
267,
754,
275,
2022,
14,
3640,
8,
470,
14,
1317,
14,
2708,
360,
1624,
13,
24,
297,
283,
4247,
659,
7478,
29,
797,
9,
398,
340,
283,
1508,
600,
7,
315,
754,
436,
754,
459,
1508,
600,
418,
1137,
378,
26,
288,
30771,
275,
754,
459,
1508,
600,
418,
288,
22070,
275,
754,
459,
16024,
418,
288,
746,
2136,
21954,
12906,
1726,
8,
355,
30771,
12,
355,
22070,
12,
355,
1890,
29,
277,
12,
355,
1056,
29,
470,
14,
1069,
12,
355,
1177,
29,
470,
288,
776,
398,
372,
754,
339,
347,
485,
362,
8,
277,
12,
1166,
12,
1011,
958,
304,
267,
372,
291,
423,
1069,
8,
288,
1083,
534,
362,
297,
288,
1166,
63,
269,
63,
6520,
29,
633,
12,
288,
1011,
958,
267,
776,
339,
768,
1829,
272,
347,
20210,
63,
633,
8,
277,
304,
267,
408,
165,
237,
116,
22924,
17797,
231,
31038,
30987,
112,
30229,
27340,
30899,
223,
398,
520,
1107,
26,
2851,
7094,
251,
109,
30899,
223,
267,
408,
267,
4660,
63,
2302,
275,
6313,
8,
277,
14,
4876,
63,
2302,
12,
5048,
13275,
267,
1166,
63,
513,
275,
359,
288,
291,
14,
24041,
63,
5825,
63,
2632,
12,
288,
283,
6126,
18,
15,
14204,
31,
571,
344,
4009,
288,
291,
14,
571,
63,
344,
12,
288,
7673,
4876,
63,
2302,
4009,
288,
4660,
63,
2302,
12,
288,
7673,
1310,
63,
466,
29,
600,
6,
2645,
4009,
288,
291,
14,
2645,
267,
1622,
267,
340,
291,
14,
929,
26,
288,
1166,
63,
513,
14,
2880,
2941,
6,
929,
4009,
291,
14,
929,
566,
267,
1166,
63,
513,
14,
740,
7863,
1129,
10289,
63,
4876,
358,
267,
372,
6522,
904,
8,
633,
63,
513,
9,
339,
768,
1829,
272,
347,
29757,
2242,
63,
633,
8,
277,
304,
267,
408,
29319,
16888,
10862,
105,
8967,
23460,
8698,
122,
244,
27340,
30899,
223,
398,
520,
1107,
26,
2851,
7094,
251,
109,
30899,
223,
267,
408,
267,
4660,
63,
2302,
275,
6313,
8,
277,
14,
4876,
63,
2302,
12,
5048,
13275,
267,
1166,
63,
513,
275,
359,
288,
291,
14,
24041,
63,
5825,
63,
2632,
12,
288,
283,
16596,
2242,
31,
571,
344,
4009,
288,
291,
14,
571,
63,
344,
12,
288,
7673,
4876,
63,
2302,
4009,
288,
4660,
63,
2302,
12,
288,
7673,
1310,
63,
466,
29,
600,
6,
2645,
4009,
288,
283,
83,
561,
1246,
63,
2886,
7,
221,
327,
4194,
267,
1622,
267,
340,
291,
14,
929,
26,
288,
1166,
63,
513,
14,
2880,
2941,
6,
929,
4009,
291,
14,
929,
566,
267,
1166,
63,
513,
14,
740,
7863,
1129,
10289,
63,
4876,
358,
267,
372,
6522,
904,
8,
633,
63,
513,
9,
339,
347,
5267,
63,
2732,
63,
1418,
8,
277,
12,
1233,
304,
267,
408,
165,
237,
116,
22924,
2879,
63,
1418,
398,
520,
635,
1233,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,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.py
|
12
|
1372
|
from __future__ import absolute_import
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from typing import Text
from zerver.models import UserProfile
from zerver.lib.emoji import check_emoji_admin, check_valid_emoji_name, check_valid_emoji
from zerver.lib.request import JsonableError, REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.actions import check_add_realm_emoji, do_remove_realm_emoji
def list_emoji(request, user_profile):
# type: (HttpRequest, UserProfile) -> HttpResponse
# We don't call check_emoji_admin here because the list of realm
# emoji is public.
return json_success({'emoji': user_profile.realm.get_emoji()})
@has_request_variables
def upload_emoji(request, user_profile, emoji_name, url=REQ()):
# type: (HttpRequest, UserProfile, Text, Text) -> HttpResponse
check_valid_emoji_name(emoji_name)
check_emoji_admin(user_profile)
check_add_realm_emoji(user_profile.realm, emoji_name, url, author=user_profile)
return json_success()
def delete_emoji(request, user_profile, emoji_name):
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
check_emoji_admin(user_profile)
check_valid_emoji(user_profile.realm, emoji_name)
do_remove_realm_emoji(user_profile.realm, emoji_name)
return json_success()
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1014,
492,
20730,
12,
6183,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
14090,
492,
4516,
199,
199,
504,
19959,
14,
992,
492,
19037,
199,
504,
19959,
14,
773,
14,
26445,
492,
1104,
63,
26445,
63,
2113,
12,
1104,
63,
1078,
63,
26445,
63,
354,
12,
1104,
63,
1078,
63,
26445,
199,
504,
19959,
14,
773,
14,
1069,
492,
14587,
461,
547,
12,
5363,
49,
12,
965,
63,
1069,
63,
3669,
199,
504,
19959,
14,
773,
14,
1310,
492,
2022,
63,
3742,
199,
504,
19959,
14,
773,
14,
3723,
492,
1104,
63,
525,
63,
7728,
63,
26445,
12,
886,
63,
2168,
63,
7728,
63,
26445,
199,
199,
318,
769,
63,
26445,
8,
1069,
12,
922,
63,
2913,
304,
272,
327,
730,
26,
334,
10441,
12,
19037,
9,
1035,
6183,
339,
327,
2136,
2793,
1133,
1240,
1104,
63,
26445,
63,
2113,
2348,
2952,
314,
769,
402,
10482,
272,
327,
325,
20452,
365,
4575,
14,
272,
372,
2022,
63,
3742,
3252,
26445,
356,
922,
63,
2913,
14,
7728,
14,
362,
63,
26445,
22804,
199,
199,
32,
1989,
63,
1069,
63,
3669,
199,
318,
5802,
63,
26445,
8,
1069,
12,
922,
63,
2913,
12,
325,
20452,
63,
354,
12,
1166,
29,
14583,
5109,
272,
327,
730,
26,
334,
10441,
12,
19037,
12,
4516,
12,
4516,
9,
1035,
6183,
272,
1104,
63,
1078,
63,
26445,
63,
354,
8,
26445,
63,
354,
9,
272,
1104,
63,
26445,
63,
2113,
8,
751,
63,
2913,
9,
272,
1104,
63,
525,
63,
7728,
63,
26445,
8,
751,
63,
2913,
14,
7728,
12,
325,
20452,
63,
354,
12,
1166,
12,
4132,
29,
751,
63,
2913,
9,
272,
372,
2022,
63,
3742,
342,
199,
199,
318,
3145,
63,
26445,
8,
1069,
12,
922,
63,
2913,
12,
325,
20452,
63,
354,
304,
272,
327,
730,
26,
334,
10441,
12,
19037,
12,
4516,
9,
1035,
6183,
272,
1104,
63,
26445,
63,
2113,
8,
751,
63,
2913,
9,
272,
1104,
63,
1078,
63,
26445,
8,
751,
63,
2913,
14,
7728,
12,
325,
20452,
63,
354,
9,
272,
886,
63,
2168,
63,
7728,
63,
26445,
8,
751,
63,
2913,
14,
7728,
12,
325,
20452,
63,
354,
9,
272,
372,
2022,
63,
3742,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1014,
492,
20730,
12,
6183,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
14090,
492,
4516,
199,
199,
504,
19959,
14,
992,
492,
19037,
199,
504,
19959,
14,
773,
14,
26445,
492,
1104,
63,
26445,
63,
2113,
12,
1104,
63,
1078,
63,
26445,
63,
354,
12,
1104,
63,
1078,
63,
26445,
199,
504,
19959,
14,
773,
14,
1069,
492,
14587,
461,
547,
12,
5363,
49,
12,
965,
63,
1069,
63,
3669,
199,
504,
19959,
14,
773,
14,
1310,
492,
2022,
63,
3742,
199,
504,
19959,
14,
773,
14,
3723,
492,
1104,
63,
525,
63,
7728,
63,
26445,
12,
886,
63,
2168,
63,
7728,
63,
26445,
199,
199,
318,
769,
63,
26445,
8,
1069,
12,
922,
63,
2913,
304,
272,
327,
730,
26,
334,
10441,
12,
19037,
9,
1035,
6183,
339,
327,
2136,
2793,
1133,
1240,
1104,
63,
26445,
63,
2113,
2348,
2952,
314,
769,
402,
10482,
272,
327,
325,
20452,
365,
4575,
14,
272,
372,
2022,
63,
3742,
3252,
26445,
356,
922,
63,
2913,
14,
7728,
14,
362,
63,
26445,
22804,
199,
199,
32,
1989,
63,
1069,
63,
3669,
199,
318,
5802,
63,
26445,
8,
1069,
12,
922,
63,
2913,
12,
325,
20452,
63,
354,
12,
1166,
29,
14583,
5109,
272,
327,
730,
26,
334,
10441,
12,
19037,
12,
4516,
12,
4516,
9,
1035,
6183,
272,
1104,
63,
1078,
63,
26445,
63,
354,
8,
26445,
63,
354,
9,
272,
1104,
63,
26445,
63,
2113,
8,
751,
63,
2913,
9,
272,
1104,
63,
525,
63,
7728,
63,
26445,
8,
751,
63,
2913,
14,
7728,
12,
325,
20452,
63,
354,
12,
1166,
12,
4132,
29,
751,
63,
2913,
9,
272,
372,
2022,
63,
3742,
342,
199,
199,
318,
3145,
63,
26445,
8,
1069,
12,
922,
63,
2913,
12,
325,
20452,
63,
354,
304,
272,
327,
730,
26,
334,
10441,
12,
19037,
12,
4516,
9,
1035,
6183,
272,
1104,
63,
26445,
63,
2113,
8,
751,
63,
2913,
9,
272,
1104,
63,
1078,
63,
26445,
8,
751,
63,
2913,
14,
7728,
12,
325,
20452,
63,
354,
9,
272,
886,
63,
2168,
63,
7728,
63,
26445,
8,
751,
63,
2913,
14,
7728,
12,
325,
20452,
63,
354,
9,
272,
372,
2022,
63,
3742,
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,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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
] |
gibiansky/tensorflow
|
tensorflow/contrib/learn/python/learn/ops/array_ops.py
|
7
|
2063
|
# 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.
# ==============================================================================
"""TensorFlow ops for array / tensor manipulation."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.framework import deprecated
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops as array_ops_
from tensorflow.python.ops import math_ops
@deprecated('2016-12-01', 'Use `tf.one_hot` instead.')
def one_hot_matrix(tensor_in, num_classes, on_value=1.0, off_value=0.0,
name=None):
"""Encodes indices from given tensor as one-hot tensor.
TODO(ilblackdragon): Ideally implementation should be
part of TensorFlow with Eigen-native operation.
Args:
tensor_in: Input `Tensor` of shape [N1, N2].
num_classes: Number of classes to expand index into.
on_value: `Tensor` or float, value to fill-in given index.
off_value: `Tensor` or float, value to fill-in everything else.
name: Name of the op.
Returns:
`Tensor` of shape `[N1, N2, num_classes]` with 1.0 for each id in original
tensor.
"""
with ops.name_scope(
name, 'one_hot_matrix',
[tensor_in, num_classes, on_value, off_value]) as name_scope:
return array_ops_.one_hot(
math_ops.cast(tensor_in, dtypes.int64), num_classes, on_value,
off_value, name=name_scope)
|
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,
199,
624,
26998,
4156,
367,
1625,
1182,
2345,
26212,
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,
504,
3228,
14,
2828,
14,
4857,
492,
5906,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
465,
1625,
63,
1483,
63,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
421,
199,
32,
6667,
360,
9261,
13,
713,
13,
614,
297,
283,
6119,
658,
3249,
14,
368,
63,
8885,
64,
3140,
2659,
199,
318,
1373,
63,
8885,
63,
3642,
8,
3128,
63,
262,
12,
1967,
63,
2888,
12,
641,
63,
585,
29,
17,
14,
16,
12,
2331,
63,
585,
29,
16,
14,
16,
12,
673,
536,
29,
403,
304,
523,
408,
1327,
6021,
4918,
687,
1627,
2345,
465,
1373,
13,
8885,
2345,
14,
819,
3254,
8,
382,
8399,
14479,
265,
304,
473,
271,
1183,
4514,
1077,
506,
523,
1777,
402,
9134,
543,
662,
8478,
13,
6106,
3439,
14,
819,
3033,
26,
272,
2345,
63,
262,
26,
6924,
658,
3861,
64,
402,
2215,
359,
46,
17,
12,
653,
18,
1055,
272,
1967,
63,
2888,
26,
4860,
402,
3992,
370,
6544,
1478,
1901,
14,
272,
641,
63,
585,
26,
658,
3861,
64,
503,
2069,
12,
574,
370,
5554,
13,
262,
1627,
1478,
14,
272,
2331,
63,
585,
26,
658,
3861,
64,
503,
2069,
12,
574,
370,
5554,
13,
262,
8137,
587,
14,
272,
536,
26,
2812,
402,
314,
1687,
14,
523,
1803,
26,
272,
658,
3861,
64,
402,
2215,
14505,
46,
17,
12,
653,
18,
12,
1967,
63,
2888,
16090,
543,
413,
14,
16,
367,
1924,
1305,
315,
3379,
272,
2345,
14,
523,
408,
523,
543,
4156,
14,
354,
63,
2645,
8,
489,
536,
12,
283,
368,
63,
8885,
63,
3642,
297,
489,
359,
3128,
63,
262,
12,
1967,
63,
2888,
12,
641,
63,
585,
12,
2331,
63,
585,
566,
465,
536,
63,
2645,
26,
272,
372,
1625,
63,
1483,
3754,
368,
63,
8885,
8,
267,
3473,
63,
1483,
14,
2931,
8,
3128,
63,
262,
12,
6674,
14,
442,
772,
395,
1967,
63,
2888,
12,
641,
63,
585,
12,
267,
2331,
63,
585,
12,
536,
29,
354,
63,
2645,
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
] |
[
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,
199,
624,
26998,
4156,
367,
1625,
1182,
2345,
26212,
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,
504,
3228,
14,
2828,
14,
4857,
492,
5906,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
465,
1625,
63,
1483,
63,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
421,
199,
32,
6667,
360,
9261,
13,
713,
13,
614,
297,
283,
6119,
658,
3249,
14,
368,
63,
8885,
64,
3140,
2659,
199,
318,
1373,
63,
8885,
63,
3642,
8,
3128,
63,
262,
12,
1967,
63,
2888,
12,
641,
63,
585,
29,
17,
14,
16,
12,
2331,
63,
585,
29,
16,
14,
16,
12,
673,
536,
29,
403,
304,
523,
408,
1327,
6021,
4918,
687,
1627,
2345,
465,
1373,
13,
8885,
2345,
14,
819,
3254,
8,
382,
8399,
14479,
265,
304,
473,
271,
1183,
4514,
1077,
506,
523,
1777,
402,
9134,
543,
662,
8478,
13,
6106,
3439,
14,
819,
3033,
26,
272,
2345,
63,
262,
26,
6924,
658,
3861,
64,
402,
2215,
359,
46,
17,
12,
653,
18,
1055,
272,
1967,
63,
2888,
26,
4860,
402,
3992,
370,
6544,
1478,
1901,
14,
272,
641,
63,
585,
26,
658,
3861,
64,
503,
2069,
12,
574,
370,
5554,
13,
262,
1627,
1478,
14,
272,
2331,
63,
585,
26,
658,
3861,
64,
503,
2069,
12,
574,
370,
5554,
13,
262,
8137,
587,
14,
272,
536,
26,
2812,
402,
314,
1687,
14,
523,
1803,
26,
272,
658,
3861,
64,
402,
2215,
14505,
46,
17,
12,
653,
18,
12,
1967,
63,
2888,
16090,
543,
413,
14,
16,
367,
1924,
1305,
315,
3379,
272,
2345,
14,
523,
408,
523,
543,
4156,
14,
354,
63,
2645,
8,
489,
536,
12,
283,
368,
63,
8885,
63,
3642,
297,
489,
359,
3128,
63,
262,
12,
1967,
63,
2888,
12,
641,
63,
585,
12,
2331,
63,
585,
566,
465,
536,
63,
2645,
26,
272,
372,
1625,
63,
1483,
3754,
368,
63,
8885,
8,
267,
3473,
63,
1483,
14,
2931,
8,
3128,
63,
262,
12,
6674,
14,
442,
772,
395,
1967,
63,
2888,
12,
641,
63,
585,
12,
267,
2331,
63,
585,
12,
536,
29,
354,
63,
2645,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
albertomurillo/ansible
|
lib/ansible/modules/windows/win_file.py
|
33
|
2185
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2015, Jon Hawkesworth (@jhawkesworth) <figs@unity.demon.co.uk>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = r'''
---
module: win_file
version_added: "1.9.2"
short_description: Creates, touches or removes files or directories
description:
- Creates (empty) files, updates file modification stamps of existing files,
and can create or remove directories.
- Unlike M(file), does not modify ownership, permissions or manipulate links.
- For non-Windows targets, use the M(file) module instead.
options:
path:
description:
- Path to the file being managed.
required: yes
type: path
aliases: [ dest, name ]
state:
description:
- If C(directory), all immediate subdirectories will be created if they
do not exist.
- If C(file), the file will NOT be created if it does not exist, see the M(copy)
or M(template) module if you want that behavior. If C(absent),
directories will be recursively deleted, and files will be removed.
- If C(touch), an empty file will be created if the C(path) does not
exist, while an existing file or directory will receive updated file access and
modification times (similar to the way C(touch) works from the command line).
type: str
choices: [ absent, directory, file, touch ]
seealso:
- module: file
- module: win_acl
- module: win_acl_inheritance
- module: win_owner
- module: win_stat
author:
- Jon Hawkesworth (@jhawkesworth)
'''
EXAMPLES = r'''
- name: Touch a file (creates if not present, updates modification time if present)
win_file:
path: C:\Temp\foo.conf
state: touch
- name: Remove a file, if present
win_file:
path: C:\Temp\foo.conf
state: absent
- name: Create directory structure
win_file:
path: C:\Temp\folder\subfolder
state: directory
- name: Remove directory structure
win_file:
path: C:\Temp
state: absent
'''
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
6900,
12,
1603,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
9,
665,
5513,
32,
6639,
14,
271,
2106,
14,
331,
14,
3210,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
4747,
63,
493,
199,
1023,
63,
3270,
26,
298,
17,
14,
25,
14,
18,
2,
199,
3612,
63,
1802,
26,
10560,
12,
12943,
397,
503,
14185,
1584,
503,
6602,
199,
1802,
26,
1362,
446,
10560,
334,
1667,
9,
1584,
12,
7029,
570,
7100,
2612,
13408,
402,
3411,
1584,
12,
2126,
436,
883,
1218,
503,
2813,
6602,
14,
1362,
446,
25059,
603,
8,
493,
395,
1630,
440,
2811,
12715,
12,
3443,
503,
27232,
6220,
14,
1362,
446,
2104,
2222,
13,
8647,
4545,
12,
675,
314,
603,
8,
493,
9,
859,
3140,
14,
199,
1419,
26,
523,
931,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
570,
3769,
12883,
14,
272,
1415,
26,
9456,
272,
730,
26,
931,
272,
5481,
26,
359,
2053,
12,
536,
1622,
523,
1174,
26,
272,
1369,
26,
489,
446,
982,
445,
8,
3619,
395,
1006,
8569,
24799,
911,
506,
2737,
340,
2985,
267,
886,
440,
2187,
14,
489,
446,
982,
445,
8,
493,
395,
314,
570,
911,
2845,
506,
2737,
340,
652,
1630,
440,
2187,
12,
1937,
314,
603,
8,
1574,
9,
267,
503,
603,
8,
1160,
9,
859,
340,
1265,
2934,
626,
5953,
14,
221,
982,
445,
8,
5575,
395,
267,
6602,
911,
506,
15035,
5463,
12,
436,
1584,
911,
506,
4829,
14,
489,
446,
982,
445,
8,
12376,
395,
376,
2701,
570,
911,
506,
2737,
340,
314,
445,
8,
515,
9,
1630,
440,
267,
2187,
12,
1830,
376,
3411,
570,
503,
2082,
911,
9128,
4588,
570,
2879,
436,
267,
7100,
5431,
334,
23079,
370,
314,
4340,
445,
8,
12376,
9,
5419,
687,
314,
1414,
1004,
680,
272,
730,
26,
620,
272,
3415,
26,
359,
9552,
12,
2082,
12,
570,
12,
12943,
1622,
199,
3239,
12344,
26,
199,
13,
859,
26,
570,
199,
13,
859,
26,
4747,
63,
5853,
199,
13,
859,
26,
4747,
63,
5853,
63,
13136,
199,
13,
859,
26,
4747,
63,
4597,
199,
13,
859,
26,
4747,
63,
3736,
199,
2502,
26,
199,
13,
1603,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
9,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
377,
13087,
282,
570,
334,
28219,
340,
440,
3451,
12,
7029,
7100,
900,
340,
3451,
9,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
60,
1421,
14,
2190,
272,
1174,
26,
12943,
199,
199,
13,
536,
26,
5852,
282,
570,
12,
340,
3451,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
60,
1421,
14,
2190,
272,
1174,
26,
9552,
199,
199,
13,
536,
26,
2790,
2082,
5523,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
60,
3741,
60,
954,
3741,
272,
1174,
26,
2082,
199,
199,
13,
536,
26,
5852,
2082,
5523,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
272,
1174,
26,
9552,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
6900,
12,
1603,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
9,
665,
5513,
32,
6639,
14,
271,
2106,
14,
331,
14,
3210,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
4747,
63,
493,
199,
1023,
63,
3270,
26,
298,
17,
14,
25,
14,
18,
2,
199,
3612,
63,
1802,
26,
10560,
12,
12943,
397,
503,
14185,
1584,
503,
6602,
199,
1802,
26,
1362,
446,
10560,
334,
1667,
9,
1584,
12,
7029,
570,
7100,
2612,
13408,
402,
3411,
1584,
12,
2126,
436,
883,
1218,
503,
2813,
6602,
14,
1362,
446,
25059,
603,
8,
493,
395,
1630,
440,
2811,
12715,
12,
3443,
503,
27232,
6220,
14,
1362,
446,
2104,
2222,
13,
8647,
4545,
12,
675,
314,
603,
8,
493,
9,
859,
3140,
14,
199,
1419,
26,
523,
931,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
570,
3769,
12883,
14,
272,
1415,
26,
9456,
272,
730,
26,
931,
272,
5481,
26,
359,
2053,
12,
536,
1622,
523,
1174,
26,
272,
1369,
26,
489,
446,
982,
445,
8,
3619,
395,
1006,
8569,
24799,
911,
506,
2737,
340,
2985,
267,
886,
440,
2187,
14,
489,
446,
982,
445,
8,
493,
395,
314,
570,
911,
2845,
506,
2737,
340,
652,
1630,
440,
2187,
12,
1937,
314,
603,
8,
1574,
9,
267,
503,
603,
8,
1160,
9,
859,
340,
1265,
2934,
626,
5953,
14,
221,
982,
445,
8,
5575,
395,
267,
6602,
911,
506,
15035,
5463,
12,
436,
1584,
911,
506,
4829,
14,
489,
446,
982,
445,
8,
12376,
395,
376,
2701,
570,
911,
506,
2737,
340,
314,
445,
8,
515,
9,
1630,
440,
267,
2187,
12,
1830,
376,
3411,
570,
503,
2082,
911,
9128,
4588,
570,
2879,
436,
267,
7100,
5431,
334,
23079,
370,
314,
4340,
445,
8,
12376,
9,
5419,
687,
314,
1414,
1004,
680,
272,
730,
26,
620,
272,
3415,
26,
359,
9552,
12,
2082,
12,
570,
12,
12943,
1622,
199,
3239,
12344,
26,
199,
13,
859,
26,
570,
199,
13,
859,
26,
4747,
63,
5853,
199,
13,
859,
26,
4747,
63,
5853,
63,
13136,
199,
13,
859,
26,
4747,
63,
4597,
199,
13,
859,
26,
4747,
63,
3736,
199,
2502,
26,
199,
13,
1603,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
9,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
377,
13087,
282,
570,
334,
28219,
340,
440,
3451,
12,
7029,
7100,
900,
340,
3451,
9,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
60,
1421,
14,
2190,
272,
1174,
26,
12943,
199,
199,
13,
536,
26,
5852,
282,
570,
12,
340,
3451,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
60,
1421,
14,
2190,
272,
1174,
26,
9552,
199,
199,
13,
536,
26,
2790,
2082,
5523,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
60,
3741,
60,
954,
3741,
272,
1174,
26,
2082,
199,
199,
13,
536,
26,
5852,
2082,
5523,
523,
4747,
63,
493,
26,
272,
931,
26,
445,
3427,
6530,
272,
1174,
26,
9552,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sjsucohort6/openstack
|
python/venv/lib/python2.7/site-packages/tablib/packages/openpyxl3/shared/password_hasher.py
|
118
|
1850
|
# file openpyxl/shared/password_hasher.py
# Copyright (c) 2010 openpyxl
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# @license: http://www.opensource.org/licenses/mit-license.php
# @author: Eric Gazoni
"""Basic password hashing."""
def hash_password(plaintext_password=''):
"""Create a password hash from a given string.
This method is based on the algorithm provided by
Daniel Rentz of OpenOffice and the PEAR package
Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
"""
password = 0x0000
i = 1
for char in plaintext_password:
value = ord(char) << i
rotated_bits = value >> 15
value &= 0x7fff
password ^= (value | rotated_bits)
i += 1
password ^= len(plaintext_password)
password ^= 0xCE4B
return str(hex(password)).upper()[2:]
|
mit
|
[
3,
570,
1551,
647,
15455,
15,
5555,
15,
2060,
63,
28885,
14,
647,
199,
199,
3,
1898,
334,
67,
9,
7129,
1551,
647,
15455,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
2334,
4141,
14,
199,
3,
199,
3,
768,
1682,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
3,
768,
2502,
26,
662,
1567,
598,
4651,
265,
73,
199,
199,
624,
6845,
2505,
25223,
1041,
421,
199,
318,
2631,
63,
2060,
8,
17426,
63,
2060,
9280,
272,
408,
2499,
282,
2505,
2631,
687,
282,
1627,
1059,
14,
339,
961,
1083,
365,
4079,
641,
314,
5563,
2741,
701,
272,
24747,
14769,
820,
484,
90,
402,
3232,
31166,
436,
314,
510,
15550,
2559,
272,
428,
12032,
63,
920,
6067,
63,
6261,
701,
1323,
7194,
281,
653,
974,
14262,
665,
88,
889,
6051,
281,
32,
264,
806,
7828,
14,
957,
10827,
339,
408,
272,
2505,
275,
378,
88,
993,
272,
284,
275,
413,
272,
367,
1495,
315,
18577,
63,
2060,
26,
267,
574,
275,
6206,
8,
1560,
9,
5213,
284,
267,
7513,
972,
63,
5609,
275,
574,
4331,
4114,
267,
574,
18415,
378,
88,
23,
18190,
267,
2505,
31753,
334,
585,
1204,
7513,
972,
63,
5609,
9,
267,
284,
847,
413,
272,
2505,
31753,
822,
8,
17426,
63,
2060,
9,
272,
2505,
31753,
378,
88,
2089,
20,
34,
272,
372,
620,
8,
4097,
8,
2060,
4992,
4142,
3430,
18,
2938,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
570,
1551,
647,
15455,
15,
5555,
15,
2060,
63,
28885,
14,
647,
199,
199,
3,
1898,
334,
67,
9,
7129,
1551,
647,
15455,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
2334,
4141,
14,
199,
3,
199,
3,
768,
1682,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
3,
768,
2502,
26,
662,
1567,
598,
4651,
265,
73,
199,
199,
624,
6845,
2505,
25223,
1041,
421,
199,
318,
2631,
63,
2060,
8,
17426,
63,
2060,
9280,
272,
408,
2499,
282,
2505,
2631,
687,
282,
1627,
1059,
14,
339,
961,
1083,
365,
4079,
641,
314,
5563,
2741,
701,
272,
24747,
14769,
820,
484,
90,
402,
3232,
31166,
436,
314,
510,
15550,
2559,
272,
428,
12032,
63,
920,
6067,
63,
6261,
701,
1323,
7194,
281,
653,
974,
14262,
665,
88,
889,
6051,
281,
32,
264,
806,
7828,
14,
957,
10827,
339,
408,
272,
2505,
275,
378,
88,
993,
272,
284,
275,
413,
272,
367,
1495,
315,
18577,
63,
2060,
26,
267,
574,
275,
6206,
8,
1560,
9,
5213,
284,
267,
7513,
972,
63,
5609,
275,
574,
4331,
4114,
267,
574,
18415,
378,
88,
23,
18190,
267,
2505,
31753,
334,
585,
1204,
7513,
972,
63,
5609,
9,
267,
284,
847,
413,
272,
2505,
31753,
822,
8,
17426,
63,
2060,
9,
272,
2505,
31753,
378,
88,
2089,
20,
34,
272,
372,
620,
8,
4097,
8,
2060,
4992,
4142,
3430,
18,
2938,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
irinabov/debian-qpid-dispatch
|
tests/system_test.py
|
1
|
46655
|
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
"""System test library, provides tools for tests that start multiple processes,
with special support for qdrouter processes.
Features:
- Create separate directories for each test.
- Save logs, sub-process output, core files etc.
- Automated clean-up after tests: kill sub-processes etc.
- Tools to manipulate qdrouter configuration files.
- Sundry other tools.
"""
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
import errno, os, time, socket, random, subprocess, shutil, unittest, __main__, re, sys
from datetime import datetime
from subprocess import PIPE, STDOUT
from copy import copy
try:
import queue as Queue # 3.x
except ImportError:
import Queue as Queue # 2.7
from threading import Thread
from threading import Event
import json
import uuid
is_python2 = sys.version_info[0] == 2
# DISPATCH-1443: for python < 2.7 use unittest2 since the default unittest for
# older versions lacks features we need:
#
if is_python2 and sys.version_info[1] < 7:
# python < 2.7:
try:
import unittest2 as unittest
except ImportError:
raise Exception("Python unittest2 not installed - see README")
else:
import unittest
import proton
from proton import Message
from proton import Delivery
from proton.handlers import MessagingHandler
from proton.utils import BlockingConnection
from proton.reactor import AtLeastOnce, Container
from proton.reactor import AtMostOnce
from qpid_dispatch.management.client import Node
from qpid_dispatch_internal.compat import dict_iteritems
# Optional modules
MISSING_MODULES = []
try:
import qpidtoollibs
except ImportError as err:
qpidtoollibs = None # pylint: disable=invalid-name
MISSING_MODULES.append(str(err))
try:
import qpid_messaging as qm
except ImportError as err:
qm = None # pylint: disable=invalid-name
MISSING_MODULES.append(str(err))
def find_exe(program):
"""Find an executable in the system PATH"""
def is_exe(fpath):
"""True if fpath is executable"""
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
mydir = os.path.split(program)[0]
if mydir:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
# The directory where this module lives. Used to locate static configuration files etc.
DIR = os.path.dirname(__file__)
def _check_requirements():
"""If requirements are missing, return a message, else return empty string."""
missing = MISSING_MODULES
required_exes = ['qdrouterd']
missing += ["No exectuable %s"%e for e in required_exes if not find_exe(e)]
if missing:
return "%s: %s"%(__name__, ", ".join(missing))
MISSING_REQUIREMENTS = _check_requirements()
def retry_delay(deadline, delay, max_delay):
"""For internal use in retry. Sleep as required
and return the new delay or None if retry should time out"""
remaining = deadline - time.time()
if remaining <= 0:
return None
time.sleep(min(delay, remaining))
return min(delay*2, max_delay)
# Valgrind significantly slows down the response time of the router, so use a
# long default timeout
TIMEOUT = float(os.environ.get("QPID_SYSTEM_TEST_TIMEOUT", 60))
def retry(function, timeout=TIMEOUT, delay=.001, max_delay=1):
"""Call function until it returns a true value or timeout expires.
Double the delay for each retry up to max_delay.
Returns what function returns or None if timeout expires.
"""
deadline = time.time() + timeout
while True:
ret = function()
if ret:
return ret
else:
delay = retry_delay(deadline, delay, max_delay)
if delay is None:
return None
def retry_exception(function, timeout=TIMEOUT, delay=.001, max_delay=1, exception_test=None):
"""Call function until it returns without exception or timeout expires.
Double the delay for each retry up to max_delay.
Calls exception_test with any exception raised by function, exception_test
may itself raise an exception to terminate the retry.
Returns what function returns if it succeeds before timeout.
Raises last exception raised by function on timeout.
"""
deadline = time.time() + timeout
while True:
try:
return function()
except Exception as e: # pylint: disable=broad-except
if exception_test:
exception_test(e)
delay = retry_delay(deadline, delay, max_delay)
if delay is None:
raise
def get_local_host_socket(protocol_family='IPv4'):
if protocol_family == 'IPv4':
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '127.0.0.1'
elif protocol_family == 'IPv6':
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
host = '::1'
return s, host
def port_available(port, protocol_family='IPv4'):
"""Return true if connecting to host:port gives 'connection refused'."""
s, host = get_local_host_socket(protocol_family)
available = False
try:
s.connect((host, port))
except socket.error as e:
available = e.errno == errno.ECONNREFUSED
except:
pass
s.close()
return available
def wait_port(port, protocol_family='IPv4', **retry_kwargs):
"""Wait up to timeout for port (on host) to be connectable.
Takes same keyword arguments as retry to control the timeout"""
def check(e):
"""Only retry on connection refused"""
if not isinstance(e, socket.error) or not e.errno == errno.ECONNREFUSED:
raise
host = None
def connect():
# macOS gives EINVAL for all connection attempts after a ECONNREFUSED
# man 3 connect: "If connect() fails, the state of the socket is unspecified. [...]"
s, host = get_local_host_socket(protocol_family)
try:
s.connect((host, port))
finally:
s.close()
try:
retry_exception(connect, exception_test=check, **retry_kwargs)
except Exception as e:
raise Exception("wait_port timeout on host %s port %s: %s" % (host, port, e))
def wait_ports(ports, **retry_kwargs):
"""Wait up to timeout for all ports (on host) to be connectable.
Takes same keyword arguments as retry to control the timeout"""
for port, protocol_family in dict_iteritems(ports):
wait_port(port=port, protocol_family=protocol_family, **retry_kwargs)
def message(**properties):
"""Convenience to create a proton.Message with properties set"""
m = Message()
for name, value in dict_iteritems(properties):
getattr(m, name) # Raise exception if not a valid message attribute.
setattr(m, name, value)
return m
class Process(subprocess.Popen):
"""
Popen that can be torn down at the end of a TestCase and stores its output.
"""
# Expected states of a Process at teardown
RUNNING = -1 # Still running
EXIT_OK = 0 # Exit status 0
EXIT_FAIL = 1 # Exit status 1
unique_id = 0
@classmethod
def unique(cls, name):
cls.unique_id += 1
return "%s-%s" % (name, cls.unique_id)
def __init__(self, args, name=None, expect=EXIT_OK, **kwargs):
"""
Takes same arguments as subprocess.Popen. Some additional/special args:
@param expect: Raise error if process staus not as expected at end of test:
L{RUNNING} - expect still running.
L{EXIT_OK} - expect proces to have terminated with 0 exit status.
L{EXIT_FAIL} - expect proces to have terminated with exit status 1.
integer - expected return code
@keyword stdout: Defaults to the file name+".out"
@keyword stderr: Defaults to be the same as stdout
"""
self.name = name or os.path.basename(args[0])
self.args, self.expect = args, expect
self.outdir = os.getcwd()
self.outfile = os.path.abspath(self.unique(self.name))
self.torndown = False
with open(self.outfile + '.out', 'w') as out:
kwargs.setdefault('stdout', out)
kwargs.setdefault('stderr', subprocess.STDOUT)
try:
super(Process, self).__init__(args, **kwargs)
with open(self.outfile + '.cmd', 'w') as f:
f.write("%s\npid=%s\n" % (' '.join(args), self.pid))
except Exception as e:
raise Exception("subprocess.Popen(%s, %s) failed: %s: %s" %
(args, kwargs, type(e).__name__, e))
def assert_running(self):
"""Assert that the process is still running"""
assert self.poll() is None, "%s: exited" % ' '.join(self.args)
def teardown(self):
"""Check process status and stop the process if necessary"""
if self.torndown:
return
self.torndown = True
def error(msg):
with open(self.outfile + '.out') as f:
raise RuntimeError("Process %s error: %s\n%s\n%s\n>>>>\n%s<<<<" % (
self.pid, msg, ' '.join(self.args),
self.outfile + '.cmd', f.read()));
status = self.poll()
if status is None: # Still running
self.terminate()
if self.expect != None and self.expect != Process.RUNNING:
error("still running")
self.expect = 0 # Expect clean exit after terminate
status = self.wait()
if self.expect != None and self.expect != status:
error("exit code %s, expected %s" % (status, self.expect))
def wait(self, timeout=None):
"""
Add support for a timeout when using Python 2
"""
if timeout is None:
return super(Process, self).wait()
if is_python2:
start = time.time()
while True:
rc = super(Process, self).poll()
if rc is not None:
return rc
if time.time() - start >= timeout:
raise Exception("Process did not terminate")
time.sleep(0.1)
else:
return super(Process, self).wait(timeout=timeout)
def communicate(self, input=None, timeout=None):
"""
Add support for a timeout when using Python 2
"""
if timeout is None:
return super(Process, self).communicate(input=input)
if is_python2:
self.wait(timeout=timeout)
return super(Process, self).communicate(input=input)
return super(Process, self).communicate(input=input,
timeout=timeout)
class Config(object):
"""Base class for configuration objects that provide a convenient
way to create content for configuration files."""
def write(self, name, suffix=".conf"):
"""Write the config object to file name.suffix. Returns name.suffix."""
name = name+suffix
with open(name, 'w') as f:
f.write(str(self))
return name
class Qdrouterd(Process):
"""Run a Qpid Dispatch Router Daemon"""
class Config(list, Config):
"""
List of ('section', {'name':'value', ...}).
Fills in some default values automatically, see Qdrouterd.DEFAULTS
"""
DEFAULTS = {
'listener': {'host':'0.0.0.0', 'saslMechanisms':'ANONYMOUS', 'idleTimeoutSeconds': '120',
'authenticatePeer': 'no', 'role': 'normal'},
'connector': {'host':'127.0.0.1', 'saslMechanisms':'ANONYMOUS', 'idleTimeoutSeconds': '120'},
'router': {'mode': 'standalone', 'id': 'QDR'}
}
def sections(self, name):
"""Return list of sections named name"""
return [p for n, p in self if n == name]
@property
def router_id(self): return self.sections("router")[0]["id"]
def defaults(self):
"""Fill in default values in gconfiguration"""
for name, props in self:
if name in Qdrouterd.Config.DEFAULTS:
for n,p in dict_iteritems(Qdrouterd.Config.DEFAULTS[name]):
props.setdefault(n,p)
def __str__(self):
"""Generate config file content. Calls default() first."""
def tabs(level):
return " " * level
def sub_elem(l, level):
return "".join(["%s%s: {\n%s%s}\n" % (tabs(level), n, props(p, level + 1), tabs(level)) for n, p in l])
def child(v, level):
return "{\n%s%s}" % (sub_elem(v, level), tabs(level - 1))
def props(p, level):
return "".join(
["%s%s: %s\n" % (tabs(level), k, v if not isinstance(v, list) else child(v, level + 1)) for k, v in
dict_iteritems(p)])
self.defaults()
return "".join(["%s {\n%s}\n"%(n, props(p, 1)) for n, p in self])
def __init__(self, name=None, config=Config(), pyinclude=None, wait=True,
perform_teardown=True, cl_args=None, expect=Process.RUNNING):
"""
@param name: name used for for output files, default to id from config.
@param config: router configuration
@keyword wait: wait for router to be ready (call self.wait_ready())
"""
cl_args = cl_args or []
self.config = copy(config)
self.perform_teardown = perform_teardown
if not name: name = self.config.router_id
assert name
# setup log and debug dump files
self.dumpfile = os.path.abspath('%s-qddebug.txt' % name)
self.config.sections('router')[0]['debugDumpFile'] = self.dumpfile
default_log = [l for l in config if (l[0] == 'log' and l[1]['module'] == 'DEFAULT')]
if not default_log:
config.append(
('log', {'module':'DEFAULT', 'enable':'trace+', 'includeSource': 'true', 'outputFile':name+'.log'}))
args = ['qdrouterd', '-c', config.write(name)] + cl_args
env_home = os.environ.get('QPID_DISPATCH_HOME')
if pyinclude:
args += ['-I', pyinclude]
elif env_home:
args += ['-I', os.path.join(env_home, 'python')]
args = os.environ.get('QPID_DISPATCH_RUNNER', '').split() + args
super(Qdrouterd, self).__init__(args, name=name, expect=expect)
self._management = None
self._wait_ready = False
if wait:
self.wait_ready()
@property
def management(self):
"""Return a management agent proxy for this router"""
if not self._management:
self._management = Node.connect(self.addresses[0], timeout=TIMEOUT)
return self._management
def teardown(self):
if self._management:
try:
self._management.close()
except: pass
self._management = None
if not self.perform_teardown:
return
super(Qdrouterd, self).teardown()
# check router's debug dump file for anything interesting (should be
# empty) and dump it to stderr for perusal by organic lifeforms
try:
if os.stat(self.dumpfile).st_size > 0:
with open(self.dumpfile) as f:
sys.stderr.write("\nRouter %s debug dump file:\n" % self.config.router_id)
sys.stderr.write(f.read())
sys.stderr.flush()
except OSError:
# failed to open file. This can happen when an individual test
# spawns a temporary router (i.e. not created as part of the
# TestCase setUpClass method) that gets cleaned up by the test.
pass
@property
def ports_family(self):
"""
Return a dict of listener ports and the respective port family
Example -
{ 23456: 'IPv4', 243455: 'IPv6' }
"""
ports_fam = {}
for l in self.config.sections('listener'):
if l.get('protocolFamily'):
ports_fam[l['port']] = l['protocolFamily']
else:
ports_fam[l['port']] = 'IPv4'
return ports_fam
@property
def ports(self):
"""Return list of configured ports for all listeners"""
return [l['port'] for l in self.config.sections('listener')]
def _cfg_2_host_port(self, c):
host = c['host']
port = c['port']
protocol_family = c.get('protocolFamily', 'IPv4')
if protocol_family == 'IPv6':
return "[%s]:%s" % (host, port)
elif protocol_family == 'IPv4':
return "%s:%s" % (host, port)
raise Exception("Unknown protocol family: %s" % protocol_family)
@property
def addresses(self):
"""Return amqp://host:port addresses for all listeners"""
cfg = self.config.sections('listener')
return ["amqp://%s" % self._cfg_2_host_port(l) for l in cfg]
@property
def connector_addresses(self):
"""Return list of amqp://host:port for all connectors"""
cfg = self.config.sections('connector')
return ["amqp://%s" % self._cfg_2_host_port(c) for c in cfg]
@property
def hostports(self):
"""Return host:port for all listeners"""
return [self._cfg_2_host_port(l) for l in self.config.sections('listener')]
def is_connected(self, port, host='127.0.0.1'):
"""If router has a connection to host:port:identity return the management info.
Otherwise return None"""
try:
ret_val = False
response = self.management.query(type="org.apache.qpid.dispatch.connection")
index_host = response.attribute_names.index('host')
for result in response.results:
outs = '%s:%s' % (host, port)
if result[index_host] == outs:
ret_val = True
return ret_val
except:
return False
def wait_address(self, address, subscribers=0, remotes=0, containers=0,
count=1, **retry_kwargs ):
"""
Wait for an address to be visible on the router.
@keyword subscribers: Wait till subscriberCount >= subscribers
@keyword remotes: Wait till remoteCount >= remotes
@keyword containers: Wait till containerCount >= remotes
@keyword count: Wait until >= count matching addresses are found
@param retry_kwargs: keyword args for L{retry}
"""
def check():
# TODO aconway 2014-06-12: this should be a request by name, not a query.
# Need to rationalize addresses in management attributes.
# endswith check is because of M0/L/R prefixes
addrs = self.management.query(
type='org.apache.qpid.dispatch.router.address',
attribute_names=[u'name', u'subscriberCount', u'remoteCount', u'containerCount']).get_entities()
addrs = [a for a in addrs if a['name'].endswith(address)]
return (len(addrs) >= count
and addrs[0]['subscriberCount'] >= subscribers
and addrs[0]['remoteCount'] >= remotes
and addrs[0]['containerCount'] >= containers)
assert retry(check, **retry_kwargs)
def get_host(self, protocol_family):
if protocol_family == 'IPv4':
return '127.0.0.1'
elif protocol_family == 'IPv6':
return '::1'
else:
return '127.0.0.1'
def wait_ports(self, **retry_kwargs):
wait_ports(self.ports_family, **retry_kwargs)
def wait_connectors(self, **retry_kwargs):
"""
Wait for all connectors to be connected
@param retry_kwargs: keyword args for L{retry}
"""
for c in self.config.sections('connector'):
assert retry(lambda: self.is_connected(port=c['port'], host=self.get_host(c.get('protocolFamily'))),
**retry_kwargs), "Port not connected %s" % c['port']
def wait_ready(self, **retry_kwargs):
"""Wait for ports and connectors to be ready"""
if not self._wait_ready:
self._wait_ready = True
self.wait_ports(**retry_kwargs)
self.wait_connectors(**retry_kwargs)
return self
def is_router_connected(self, router_id, **retry_kwargs):
try:
self.management.read(identity="router.node/%s" % router_id)
# TODO aconway 2015-01-29: The above check should be enough, we
# should not advertise a remote router in managment till it is fully
# connected. However we still get a race where the router is not
# actually ready for traffic. Investigate.
# Meantime the following actually tests send-thru to the router.
node = Node.connect(self.addresses[0], router_id, timeout=1)
return retry_exception(lambda: node.query('org.apache.qpid.dispatch.router'))
except:
return False
def wait_router_connected(self, router_id, **retry_kwargs):
retry(lambda: self.is_router_connected(router_id), **retry_kwargs)
class Tester(object):
"""Tools for use by TestCase
- Create a directory for the test.
- Utilities to create processes and servers, manage ports etc.
- Clean up processes on teardown"""
# Top level directory above any Tester directories.
# CMake-generated configuration may be found here.
top_dir = os.getcwd()
# The root directory for Tester directories, under top_dir
root_dir = os.path.abspath(__name__+'.dir')
def __init__(self, id):
"""
@param id: module.class.method or False if no directory should be created
"""
self.directory = os.path.join(self.root_dir, *id.split('.')) if id else None
self.cleanup_list = []
def rmtree(self):
"""Remove old test class results directory"""
if self.directory:
shutil.rmtree(os.path.dirname(self.directory), ignore_errors=True)
def setup(self):
"""Called from test setup and class setup."""
if self.directory:
os.makedirs(self.directory)
os.chdir(self.directory)
def teardown(self):
"""Clean up (tear-down, stop or close) objects recorded via cleanup()"""
self.cleanup_list.reverse()
errors = []
for obj in self.cleanup_list:
try:
for method in ["teardown", "tearDown", "stop", "close"]:
cleanup = getattr(obj, method, None)
if cleanup:
cleanup()
break
except Exception as exc:
errors.append(exc)
if errors:
raise RuntimeError("Errors during teardown: \n\n%s" % "\n\n".join([str(e) for e in errors]))
def cleanup(self, x):
"""Record object x for clean-up during tear-down.
x should have on of the methods teardown, tearDown, stop or close"""
self.cleanup_list.append(x)
return x
def popen(self, *args, **kwargs):
"""Start a Process that will be cleaned up on teardown"""
return self.cleanup(Process(*args, **kwargs))
def qdrouterd(self, *args, **kwargs):
"""Return a Qdrouterd that will be cleaned up on teardown"""
return self.cleanup(Qdrouterd(*args, **kwargs))
port_range = (20000, 30000)
next_port = random.randint(port_range[0], port_range[1])
@classmethod
def get_port(cls, protocol_family='IPv4'):
"""Get an unused port"""
def advance():
"""Advance with wrap-around"""
cls.next_port += 1
if cls.next_port >= cls.port_range[1]:
cls.next_port = cls.port_range[0]
start = cls.next_port
while not port_available(cls.next_port, protocol_family):
advance()
if cls.next_port == start:
raise Exception("No available ports in range %s", cls.port_range)
p = cls.next_port
advance()
return p
class TestCase(unittest.TestCase, Tester): # pylint: disable=too-many-public-methods
"""A TestCase that sets up its own working directory and is also a Tester."""
def __init__(self, test_method):
unittest.TestCase.__init__(self, test_method)
Tester.__init__(self, self.id())
@classmethod
def setUpClass(cls):
cls.maxDiff = None
cls.tester = Tester('.'.join([cls.__module__, cls.__name__, 'setUpClass']))
cls.tester.rmtree()
cls.tester.setup()
@classmethod
def tearDownClass(cls):
if hasattr(cls, 'tester'):
cls.tester.teardown()
del cls.tester
def setUp(self):
# Python < 2.7 will call setUp on the system_test.TestCase class
# itself as well as the subclasses. Ignore that.
if self.__class__ is TestCase: return
# Hack to support setUpClass on older python.
# If the class has not already been set up, do it now.
if not hasattr(self.__class__, 'tester'):
try:
self.setUpClass()
except:
if hasattr(self.__class__, 'tester'):
self.__class__.tester.teardown()
raise
Tester.setup(self)
def tearDown(self):
# Python < 2.7 will call tearDown on the system_test.TestCase class
# itself as well as the subclasses. Ignore that.
if self.__class__ is TestCase: return
Tester.teardown(self)
# Hack to support tearDownClass on older versions of python.
if hasattr(self.__class__, '_tear_down_class'):
self.tearDownClass()
def skipTest(self, reason):
"""Workaround missing unittest.TestCase.skipTest in python 2.6.
The caller must return in order to end the test"""
if hasattr(unittest.TestCase, 'skipTest'):
unittest.TestCase.skipTest(self, reason)
else:
print("Skipping test %s: %s" % (self.id(), reason))
# Hack to support tearDownClass on older versions of python.
# The default TestLoader sorts tests alphabetically so we insert
# a fake tests that will run last to call tearDownClass.
# NOTE: definitely not safe for a parallel test-runner.
if not hasattr(unittest.TestCase, 'tearDownClass'):
def test_zzzz_teardown_class(self):
"""Fake test to call tearDownClass"""
if self.__class__ is not TestCase:
self.__class__._tear_down_class = True
def assert_fair(self, seq):
avg = sum(seq)/len(seq)
for i in seq:
assert i > avg/2, "Work not fairly distributed: %s"%seq
def assertIn(self, item, items):
assert item in items, "%s not in %s" % (item, items)
if not hasattr(unittest.TestCase, 'assertRegexpMatches'):
def assertRegexpMatches(self, text, regexp, msg=None):
"""For python < 2.7: assert re.search(regexp, text)"""
assert re.search(regexp, text), msg or "Can't find %r in '%s'" %(regexp, text)
class SkipIfNeeded(object):
"""
Decorator class that can be used along with test methods
to provide skip test behavior when using both python2.6 or
a greater version.
This decorator can be used in test methods and a boolean
condition must be provided (skip parameter) to define whether
or not the test will be skipped.
"""
def __init__(self, skip, reason):
"""
:param skip: if True the method wont be called
:param reason: reason why test was skipped
"""
self.skip = skip
self.reason = reason
def __call__(self, f):
def wrap(*args, **kwargs):
"""
Wraps original test method's invocation and dictates whether or
not the test will be executed based on value (boolean) of the
skip parameter.
When running test with python < 2.7, if the "skip" parameter is
true, the original method won't be called. If running python >= 2.7, then
skipTest will be called with given "reason" and original method
will be invoked.
:param args:
:return:
"""
instance = args[0]
if self.skip:
if sys.version_info < (2, 7):
print("%s -> skipping (python<2.7) [%s] ..." % (f.__name__, self.reason))
return
else:
instance.skipTest(self.reason)
return f(*args, **kwargs)
return wrap
def main_module():
"""
Return the module name of the __main__ module - i.e. the filename with the
path and .py extension stripped. Useful to run the tests in the current file but
using the proper module prefix instead of '__main__', as follows:
if __name__ == '__main__':
unittest.main(module=main_module())
"""
return os.path.splitext(os.path.basename(__main__.__file__))[0]
class AsyncTestReceiver(MessagingHandler):
"""
A simple receiver that runs in the background and queues any received
messages. Messages can be retrieved from this thread via the queue member.
:param wait: block the constructor until the link has been fully
established.
:param recover_link: restart on remote link detach
"""
Empty = Queue.Empty
def __init__(self, address, source, conn_args=None, container_id=None,
wait=True, recover_link=False, msg_args={}):
super(AsyncTestReceiver, self).__init__(**msg_args)
self.address = address
self.source = source
self.conn_args = conn_args
self.queue = Queue.Queue()
self._conn = None
self._container = Container(self)
cid = container_id or "ATR-%s:%s" % (source, uuid.uuid4())
self._container.container_id = cid
self._ready = Event()
self._recover_link = recover_link
self._recover_count = 0
self._stop_thread = False
self._thread = Thread(target=self._main)
self._thread.daemon = True
self._thread.start()
if wait and self._ready.wait(timeout=TIMEOUT) is False:
raise Exception("Timed out waiting for receiver start")
def _main(self):
self._container.timeout = 5.0
self._container.start()
while self._container.process():
if self._stop_thread:
if self._conn:
self._conn.close()
self._conn = None
def stop(self, timeout=TIMEOUT):
self._stop_thread = True
self._container.wakeup()
self._thread.join(timeout=TIMEOUT)
if self._thread.is_alive():
raise Exception("AsyncTestReceiver did not exit")
def on_start(self, event):
kwargs = {'url': self.address}
if self.conn_args:
kwargs.update(self.conn_args)
self._conn = event.container.connect(**kwargs)
def on_connection_opened(self, event):
kwargs = {'source': self.source}
rcv = event.container.create_receiver(event.connection,
**kwargs)
def on_link_opened(self, event):
self._ready.set()
def on_link_closing(self, event):
event.link.close()
if self._recover_link and not self._stop_thread:
# lesson learned: the generated link name will be the same as the
# old link (which is bad) so we specify a new one
self._recover_count += 1
kwargs = {'source': self.source,
'name': "%s:%s" % (event.link.name, self._recover_count)}
rcv = event.container.create_receiver(event.connection,
**kwargs)
def on_message(self, event):
self.queue.put(event.message)
def on_disconnected(self, event):
# if remote terminates the connection kill the thread else it will spin
# on the cpu
if self._conn:
self._conn.close()
self._conn = None
class AsyncTestSender(MessagingHandler):
"""
A simple sender that runs in the background and sends 'count' messages to a
given target.
"""
class TestSenderException(Exception):
def __init__(self, error=None):
super(AsyncTestSender.TestSenderException, self).__init__(error)
def __init__(self, address, target, count=1, message=None,
container_id=None, presettle=False):
super(AsyncTestSender, self).__init__(auto_accept=False,
auto_settle=False)
self.address = address
self.target = target
self.total = count
self.presettle = presettle
self.accepted = 0
self.released = 0
self.modified = 0
self.rejected = 0
self.sent = 0
self.error = None
self.link_stats = None
self._message = message or Message(body="test")
self._container = Container(self)
cid = container_id or "ATS-%s:%s" % (target, uuid.uuid4())
self._container.container_id = cid
self._link_name = "%s-%s" % (cid, "tx")
self._thread = Thread(target=self._main)
self._thread.daemon = True
self._thread.start()
def _main(self):
self._container.timeout = 5.0
self._container.start()
while self._container.process():
self._check_if_done()
def wait(self):
# don't stop it - wait until everything is sent
self._thread.join(timeout=TIMEOUT)
assert not self._thread.is_alive(), "sender did not complete"
if self.error:
raise AsyncTestSender.TestSenderException(self.error)
def on_start(self, event):
self._conn = self._container.connect(self.address)
def on_connection_opened(self, event):
option = AtMostOnce if self.presettle else AtLeastOnce
self._sender = self._container.create_sender(self._conn,
target=self.target,
options=option(),
name=self._link_name)
def on_sendable(self, event):
if self.sent < self.total:
self._sender.send(self._message)
self.sent += 1
def _check_if_done(self):
done = (self.sent == self.total
and (self.presettle
or (self.accepted + self.released + self.modified
+ self.rejected == self.sent)))
if done and self._conn:
self.link_stats = get_link_info(self._link_name,
self.address)
self._conn.close()
self._conn = None
def on_accepted(self, event):
self.accepted += 1;
event.delivery.settle()
def on_released(self, event):
# for some reason Proton 'helpfully' calls on_released even though the
# delivery state is actually MODIFIED
if event.delivery.remote_state == Delivery.MODIFIED:
return self.on_modified(event)
self.released += 1
event.delivery.settle()
def on_modified(self, event):
self.modified += 1
event.delivery.settle()
def on_rejected(self, event):
self.rejected += 1
event.delivery.settle()
def on_link_error(self, event):
self.error = "link error:%s" % str(event.link.remote_condition)
if self._conn:
self._conn.close()
self._conn = None
def on_disconnected(self, event):
# if remote terminates the connection kill the thread else it will spin
# on the cpu
self.error = "connection to remote dropped"
if self._conn:
self._conn.close()
self._conn = None
class QdManager(object):
"""
A means to invoke qdmanage during a testcase
"""
def __init__(self, tester=None, address=None, timeout=TIMEOUT,
router_id=None,
edge_router_id=None):
# 'tester' - can be 'self' when called in a test,
# or an instance any class derived from Process (like Qdrouterd)
self._tester = tester or Tester(None)
self._timeout = timeout
self._address = address
self.router_id = router_id
self.edge_router_id = edge_router_id
self.router = []
if self.router_id:
self.router = self.router + ['--router', self.router_id]
elif self.edge_router_id:
self.router = self.router + ['--edge-router', self.edge_router_id]
def __call__(self, cmd, address=None, input=None, expect=Process.EXIT_OK,
timeout=None):
assert address or self._address, "address missing"
p = self._tester.popen(
['qdmanage'] + cmd.split(' ')
+ self.router + ['--bus', address or self._address,
'--indent=-1',
'--timeout', str(timeout or self._timeout)],
stdin=PIPE, stdout=PIPE, stderr=STDOUT, expect=expect,
universal_newlines=True)
out = p.communicate(input)[0]
try:
p.teardown()
except Exception as e:
raise Exception("%s\n%s" % (e, out))
return out
def create(self, long_type, kwargs):
cmd = "CREATE --type=%s" % long_type
for k, v in kwargs.items():
cmd += " %s=%s" % (k, v)
return json.loads(self(cmd))
def update(self, long_type, kwargs, name=None, identity=None):
cmd = 'UPDATE --type=%s' % long_type
if identity is not None:
cmd += " --identity=%s" % identity
elif name is not None:
cmd += " --name=%s" % name
for k, v in kwargs.items():
cmd += " %s=%s" % (k, v)
return json.loads(self(cmd))
def delete(self, long_type, name=None, identity=None):
cmd = 'DELETE --type=%s' % long_type
if identity is not None:
cmd += " --identity=%s" % identity
elif name is not None:
cmd += " --name=%s" % name
else:
assert False, "name or identity not supplied!"
self(cmd)
def query(self, long_type):
return json.loads(self('QUERY --type=%s' % long_type))
def get_log(self, limit=None):
cmd = 'GET-LOG'
if (limit):
cmd += " limit=%s" % limit
return json.loads(self(cmd))
class MgmtMsgProxy(object):
"""
Utility for creating and inspecting management messages
"""
class _Response(object):
def __init__(self, status_code, status_description, body):
self.status_code = status_code
self.status_description = status_description
if body.__class__ == dict and len(body.keys()) == 2 and 'attributeNames' in body.keys() and 'results' in body.keys():
results = []
names = body['attributeNames']
for result in body['results']:
result_map = {}
for i in range(len(names)):
result_map[names[i]] = result[i]
results.append(MgmtMsgProxy._Response(status_code, status_description, result_map))
self.attrs = {'results': results}
else:
self.attrs = body
def __getattr__(self, key):
return self.attrs[key]
def __init__(self, reply_addr):
self.reply_addr = reply_addr
def response(self, msg):
ap = msg.properties
return self._Response(ap['statusCode'], ap['statusDescription'], msg.body)
def query_router(self):
ap = {'operation': 'QUERY', 'type': 'org.apache.qpid.dispatch.router'}
return Message(properties=ap, reply_to=self.reply_addr)
def query_connections(self):
ap = {'operation': 'QUERY', 'type': 'org.apache.qpid.dispatch.connection'}
return Message(properties=ap, reply_to=self.reply_addr)
def query_links(self):
ap = {'operation': 'QUERY', 'type': 'org.apache.qpid.dispatch.router.link'}
return Message(properties=ap, reply_to=self.reply_addr)
def query_link_routes(self):
ap = {'operation': 'QUERY',
'type': 'org.apache.qpid.dispatch.router.config.linkRoute'}
return Message(properties=ap, reply_to=self.reply_addr)
def query_addresses(self):
ap = {'operation': 'QUERY',
'type': 'org.apache.qpid.dispatch.router.address'}
return Message(properties=ap, reply_to=self.reply_addr)
def create_link_route(self, name, kwargs):
ap = {'operation': 'CREATE',
'type': 'org.apache.qpid.dispatch.router.config.linkRoute',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr,
body=kwargs)
def delete_link_route(self, name):
ap = {'operation': 'DELETE',
'type': 'org.apache.qpid.dispatch.router.config.linkRoute',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr)
def create_connector(self, name, **kwargs):
ap = {'operation': 'CREATE',
'type': 'org.apache.qpid.dispatch.connector',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr,
body=kwargs)
def delete_connector(self, name):
ap = {'operation': 'DELETE',
'type': 'org.apache.qpid.dispatch.connector',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr)
def query_conn_link_routes(self):
ap = {'operation': 'QUERY',
'type': 'org.apache.qpid.dispatch.router.connection.linkRoute'}
return Message(properties=ap, reply_to=self.reply_addr)
def create_conn_link_route(self, name, kwargs):
ap = {'operation': 'CREATE',
'type': 'org.apache.qpid.dispatch.router.connection.linkRoute',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr,
body=kwargs)
def delete_conn_link_route(self, name):
ap = {'operation': 'DELETE',
'type': 'org.apache.qpid.dispatch.router.connection.linkRoute',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr)
def read_conn_link_route(self, name):
ap = {'operation': 'READ',
'type': 'org.apache.qpid.dispatch.router.connection.linkRoute',
'name': name}
return Message(properties=ap, reply_to=self.reply_addr)
class TestTimeout(object):
"""
A callback object for MessagingHandler class
parent: A MessagingHandler with a timeout() method
"""
def __init__(self, parent):
self.parent = parent
def on_timer_task(self, event):
self.parent.timeout()
class PollTimeout(object):
"""
A callback object for MessagingHandler scheduled timers
parent: A MessagingHandler with a poll_timeout() method
"""
def __init__(self, parent):
self.parent = parent
def on_timer_task(self, event):
self.parent.poll_timeout()
def get_link_info(name, address):
"""
Query the router at address for the status and statistics of the named link
"""
qdm = QdManager(address=address)
rc = qdm.query('org.apache.qpid.dispatch.router.link')
for item in rc:
if item.get('name') == name:
return item
return None
def has_mobile_dest_in_address_table(address, dest):
qdm = QdManager(address=address)
rc = qdm.query('org.apache.qpid.dispatch.router.address')
has_dest = False
for item in rc:
if dest in item.get("name"):
has_dest = True
break
return has_dest
def get_inter_router_links(address):
"""
Return a list of all links with type="inter-router
:param address:
"""
inter_router_links = []
qdm = QdManager(address=address)
rc = qdm.query('org.apache.qpid.dispatch.router.link')
for item in rc:
if item.get("linkType") == "inter-router":
inter_router_links.append(item)
return inter_router_links
class Timestamp(object):
"""
Time stamps for logging.
"""
def __init__(self):
self.ts = datetime.now()
def __str__(self):
return self.ts.strftime("%Y-%m-%d %H:%M:%S.%f")
class Logger(object):
"""
Record an event log for a self test.
May print per-event or save events to be printed later.
"""
def __init__(self, title="Logger", print_to_console=False, save_for_dump=True):
self.title = title
self.print_to_console = print_to_console
self.save_for_dump = save_for_dump
self.logs = []
def log(self, msg):
ts = Timestamp()
if self.save_for_dump:
self.logs.append( (ts, msg) )
if self.print_to_console:
print("%s %s" % (ts, msg))
sys.stdout.flush()
def dump(self):
print(self)
sys.stdout.flush()
def __str__(self):
lines = []
lines.append(self.title)
for ts, msg in self.logs:
lines.append("%s %s" % (ts, msg))
res = str('\n'.join(lines))
return res
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
3989,
511,
3555,
12,
6571,
7249,
367,
2295,
626,
1343,
3663,
10358,
12,
199,
1045,
4539,
2291,
367,
1894,
68,
4995,
10358,
14,
199,
199,
10807,
26,
199,
13,
2790,
7396,
6602,
367,
1924,
511,
14,
199,
13,
11063,
9610,
12,
1007,
13,
1412,
1072,
12,
6170,
1584,
5423,
14,
199,
13,
27722,
23513,
3633,
13,
384,
2410,
2295,
26,
14561,
1007,
13,
11816,
5423,
14,
199,
13,
23228,
370,
27232,
1894,
68,
4995,
2897,
1584,
14,
199,
13,
428,
725,
651,
1163,
7249,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7554,
12,
747,
12,
900,
12,
2838,
12,
2196,
12,
3873,
12,
5145,
12,
2882,
12,
636,
973,
3108,
295,
12,
984,
199,
504,
2197,
492,
2197,
199,
504,
3873,
492,
22773,
12,
4384,
12619,
199,
504,
1331,
492,
1331,
199,
893,
26,
272,
492,
4126,
465,
10703,
257,
327,
650,
14,
88,
199,
2590,
3545,
26,
272,
492,
10703,
465,
10703,
257,
327,
499,
14,
23,
199,
504,
5796,
492,
11086,
199,
504,
5796,
492,
6763,
199,
646,
2022,
199,
646,
5377,
199,
199,
374,
63,
1548,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
199,
3,
7587,
17073,
13,
1079,
2824,
26,
367,
2366,
665,
499,
14,
23,
675,
2882,
18,
3967,
314,
849,
2882,
367,
199,
3,
12731,
5459,
1127,
5618,
4534,
781,
1929,
26,
199,
3,
199,
692,
365,
63,
1548,
18,
436,
984,
14,
1023,
63,
815,
59,
17,
61,
665,
1520,
26,
272,
327,
2366,
665,
499,
14,
23,
26,
272,
862,
26,
267,
492,
2882,
18,
465,
2882,
272,
871,
3545,
26,
267,
746,
2186,
480,
4718,
2882,
18,
440,
4903,
446,
1937,
27781,
531,
199,
2836,
26,
272,
492,
2882,
199,
199,
646,
557,
1860,
199,
504,
557,
1860,
492,
6430,
199,
504,
557,
1860,
492,
1487,
317,
2588,
199,
504,
557,
1860,
14,
5586,
492,
3194,
385,
7407,
2461,
199,
504,
557,
1860,
14,
1208,
492,
8651,
316,
3225,
199,
504,
557,
1860,
14,
13544,
492,
2854,
2553,
1810,
25690,
12,
15395,
199,
504,
557,
1860,
14,
13544,
492,
2854,
24625,
25690,
199,
504,
1894,
3150,
63,
6052,
14,
8110,
14,
1258,
492,
5013,
199,
504,
1894,
3150,
63,
6052,
63,
4672,
14,
5819,
492,
1211,
63,
4611,
199,
199,
3,
4879,
4621,
199,
18701,
63,
21194,
275,
942,
199,
199,
893,
26,
272,
492,
1894,
3150,
3557,
8450,
199,
2590,
3545,
465,
2329,
26,
272,
1894,
3150,
3557,
8450,
275,
488,
260,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
603,
1311,
12567,
63,
21194,
14,
740,
8,
495,
8,
1508,
430,
199,
199,
893,
26,
272,
492,
1894,
3150,
63,
27782,
465,
1894,
77,
199,
2590,
3545,
465,
2329,
26,
272,
1894,
77,
275,
488,
7861,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
603,
1311,
12567,
63,
21194,
14,
740,
8,
495,
8,
1508,
430,
199,
199,
318,
2342,
63,
5803,
8,
6815,
304,
272,
408,
6591,
376,
7286,
315,
314,
2656,
15097,
624,
272,
347,
365,
63,
5803,
8,
23248,
304,
267,
408,
549,
340,
30540,
365,
7286,
624,
267,
372,
747,
14,
515,
14,
6292,
8,
23248,
9,
436,
747,
14,
2732,
8,
23248,
12,
747,
14,
56,
63,
3593,
9,
272,
3002,
694,
275,
747,
14,
515,
14,
1294,
8,
6815,
2788,
16,
61,
272,
340,
3002,
694,
26,
267,
340,
365,
63,
5803,
8,
6815,
304,
288,
372,
2240,
272,
587,
26,
267,
367,
931,
315,
747,
14,
2314,
905,
3243,
4140,
1294,
8,
736,
14,
17843,
304,
288,
14778,
63,
493,
275,
747,
14,
515,
14,
904,
8,
515,
12,
2240,
9,
288,
340,
365,
63,
5803,
8,
5803,
63,
493,
304,
355,
372,
14778,
63,
493,
272,
372,
488,
199,
199,
3,
710,
2082,
2382,
642,
859,
27576,
14,
8051,
370,
16592,
2955,
2897,
1584,
5423,
14,
199,
3022,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
318,
485,
1074,
63,
7538,
837,
272,
408,
3917,
9760,
787,
4124,
12,
372,
282,
1245,
12,
587,
372,
2701,
1059,
1041,
272,
4124,
275,
603,
1311,
12567,
63,
21194,
272,
1415,
63,
476,
397,
275,
788,
23097,
4995,
68,
418,
272,
4124,
847,
2097,
1944,
444,
449,
85,
461,
450,
83,
6808,
69,
367,
325,
315,
1415,
63,
476,
397,
340,
440,
2342,
63,
5803,
8,
69,
1874,
339,
340,
4124,
26,
267,
372,
2071,
83,
26,
450,
83,
14007,
363,
354,
3108,
3872,
3680,
904,
8,
4752,
430,
199,
199,
18701,
63,
29168,
20967,
275,
485,
1074,
63,
7538,
342,
199,
199,
318,
7269,
63,
5814,
8,
22357,
12,
7339,
12,
1390,
63,
5814,
304,
272,
408,
1858,
5007,
675,
315,
7269,
14,
428,
3614,
465,
1415,
272,
436,
372,
314,
892,
7339,
503,
488,
340,
7269,
1077,
900,
734,
624,
272,
7971,
275,
23081,
446,
900,
14,
521,
342,
272,
340,
7971,
2695,
378
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
624,
3989,
511,
3555,
12,
6571,
7249,
367,
2295,
626,
1343,
3663,
10358,
12,
199,
1045,
4539,
2291,
367,
1894,
68,
4995,
10358,
14,
199,
199,
10807,
26,
199,
13,
2790,
7396,
6602,
367,
1924,
511,
14,
199,
13,
11063,
9610,
12,
1007,
13,
1412,
1072,
12,
6170,
1584,
5423,
14,
199,
13,
27722,
23513,
3633,
13,
384,
2410,
2295,
26,
14561,
1007,
13,
11816,
5423,
14,
199,
13,
23228,
370,
27232,
1894,
68,
4995,
2897,
1584,
14,
199,
13,
428,
725,
651,
1163,
7249,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7554,
12,
747,
12,
900,
12,
2838,
12,
2196,
12,
3873,
12,
5145,
12,
2882,
12,
636,
973,
3108,
295,
12,
984,
199,
504,
2197,
492,
2197,
199,
504,
3873,
492,
22773,
12,
4384,
12619,
199,
504,
1331,
492,
1331,
199,
893,
26,
272,
492,
4126,
465,
10703,
257,
327,
650,
14,
88,
199,
2590,
3545,
26,
272,
492,
10703,
465,
10703,
257,
327,
499,
14,
23,
199,
504,
5796,
492,
11086,
199,
504,
5796,
492,
6763,
199,
646,
2022,
199,
646,
5377,
199,
199,
374,
63,
1548,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
199,
3,
7587,
17073,
13,
1079,
2824,
26,
367,
2366,
665,
499,
14,
23,
675,
2882,
18,
3967,
314,
849,
2882,
367,
199,
3,
12731,
5459,
1127,
5618,
4534,
781,
1929,
26,
199,
3,
199,
692,
365,
63,
1548,
18,
436,
984,
14,
1023,
63,
815,
59,
17,
61,
665,
1520,
26,
272,
327,
2366,
665,
499,
14,
23,
26,
272,
862,
26,
267,
492,
2882,
18,
465,
2882,
272,
871,
3545,
26,
267,
746,
2186,
480,
4718,
2882,
18,
440,
4903,
446,
1937,
27781,
531,
199,
2836,
26,
272,
492,
2882,
199,
199,
646,
557,
1860,
199,
504,
557,
1860,
492,
6430,
199,
504,
557,
1860,
492,
1487,
317,
2588,
199,
504,
557,
1860,
14,
5586,
492,
3194,
385,
7407,
2461,
199,
504,
557,
1860,
14,
1208,
492,
8651,
316,
3225,
199,
504,
557,
1860,
14,
13544,
492,
2854,
2553,
1810,
25690,
12,
15395,
199,
504,
557,
1860,
14,
13544,
492,
2854,
24625,
25690,
199,
504,
1894,
3150,
63,
6052,
14,
8110,
14,
1258,
492,
5013,
199,
504,
1894,
3150,
63,
6052,
63,
4672,
14,
5819,
492,
1211,
63,
4611,
199,
199,
3,
4879,
4621,
199,
18701,
63,
21194,
275,
942,
199,
199,
893,
26,
272,
492,
1894,
3150,
3557,
8450,
199,
2590,
3545,
465,
2329,
26,
272,
1894,
3150,
3557,
8450,
275,
488,
260,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
603,
1311,
12567,
63,
21194,
14,
740,
8,
495,
8,
1508,
430,
199,
199,
893,
26,
272,
492,
1894,
3150,
63,
27782,
465,
1894,
77,
199,
2590,
3545,
465,
2329,
26,
272,
1894,
77,
275,
488,
7861,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
603,
1311,
12567,
63,
21194,
14,
740,
8,
495,
8,
1508,
430,
199,
199,
318,
2342,
63,
5803,
8,
6815,
304,
272,
408,
6591,
376,
7286,
315,
314,
2656,
15097,
624,
272,
347,
365,
63,
5803,
8,
23248,
304,
267,
408,
549,
340,
30540,
365,
7286,
624,
267,
372,
747,
14,
515,
14,
6292,
8,
23248,
9,
436,
747,
14,
2732,
8,
23248,
12,
747,
14,
56,
63,
3593,
9,
272,
3002,
694,
275,
747,
14,
515,
14,
1294,
8,
6815,
2788,
16,
61,
272,
340,
3002,
694,
26,
267,
340,
365,
63,
5803,
8,
6815,
304,
288,
372,
2240,
272,
587,
26,
267,
367,
931,
315,
747,
14,
2314,
905,
3243,
4140,
1294,
8,
736,
14,
17843,
304,
288,
14778,
63,
493,
275,
747,
14,
515,
14,
904,
8,
515,
12,
2240,
9,
288,
340,
365,
63,
5803,
8,
5803,
63,
493,
304,
355,
372,
14778,
63,
493,
272,
372,
488,
199,
199,
3,
710,
2082,
2382,
642,
859,
27576,
14,
8051,
370,
16592,
2955,
2897,
1584,
5423,
14,
199,
3022,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
318,
485,
1074,
63,
7538,
837,
272,
408,
3917,
9760,
787,
4124,
12,
372,
282,
1245,
12,
587,
372,
2701,
1059,
1041,
272,
4124,
275,
603,
1311,
12567,
63,
21194,
272,
1415,
63,
476,
397,
275,
788,
23097,
4995,
68,
418,
272,
4124,
847,
2097,
1944,
444,
449,
85,
461,
450,
83,
6808,
69,
367,
325,
315,
1415,
63,
476,
397,
340,
440,
2342,
63,
5803,
8,
69,
1874,
339,
340,
4124,
26,
267,
372,
2071,
83,
26,
450,
83,
14007,
363,
354,
3108,
3872,
3680,
904,
8,
4752,
430,
199,
199,
18701,
63,
29168,
20967,
275,
485,
1074,
63,
7538,
342,
199,
199,
318,
7269,
63,
5814,
8,
22357,
12,
7339,
12,
1390,
63,
5814,
304,
272,
408,
1858,
5007,
675,
315,
7269,
14,
428,
3614,
465,
1415,
272,
436,
372,
314,
892,
7339,
503,
488,
340,
7269,
1077,
900,
734,
624,
272,
7971,
275,
23081,
446,
900,
14,
521,
342,
272,
340,
7971,
2695,
378,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
LeonidasAntoniou/dk-plus
|
test files/beacon.py
|
1
|
1799
|
"""
A simple program that sends/listens broadcast packets through UDP socket
Used to test the system if it is able to send/receive packets
"""
import time, math, sys, socket, threading, select, uuid
from collections import namedtuple
import cPickle as pickle
from params import Params
MAX_STAY = 5 #seconds until entry is removed from structure
Geo = namedtuple("Geo", "lat lon")
simple_msg = namedtuple("simple_msg", "ID text")
self_params = Params(dummy=True)
# Set the socket parameters
address = ('192.168.1.255', 54545) # host, port
sock_broad = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock_broad.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
# Create socket and bind to address
sock_listen = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock_listen.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock_listen.bind(address)
def broad():
while True:
#msg = simple_msg(self_id,"I am here")
msg = self_params
assert sock_broad.sendto(pickle.dumps(msg), address), "Message failed to send"
time.sleep(1)
def listen():
print "Waiting for message"
while True:
try:
ready = select.select([sock_listen], [], [], 1.0)
if ready[0]:
d = sock_listen.recvfrom(4096)
raw_msg = d[0]
try:
msg = pickle.loads(raw_msg)
if msg.ID == self_params.ID:
pass
else:
print "From addr: '%s', msg: '%s'" % (d[1], msg)
except Exception, e:
print "Error in receiving: ", e
except socket.timeout:
print "Reached timeout. Closing..."
t_listen.cancel()
sock_listen.close()
t_listen = threading.Thread(target=listen)
t_broad = threading.Thread(target=broad)
t_listen.daemon = True
t_broad.daemon = True
t_listen.start()
t_broad.start()
time.sleep(100) #test for 100s
print "Closing beacon"
|
gpl-3.0
|
[
624,
199,
33,
3486,
2240,
626,
16178,
15,
317,
1597,
561,
11180,
14593,
4012,
21802,
2838,
199,
9167,
370,
511,
314,
2656,
340,
652,
365,
7688,
370,
3222,
15,
9391,
14593,
199,
624,
199,
646,
900,
12,
3473,
12,
984,
12,
2838,
12,
5796,
12,
3504,
12,
5377,
199,
504,
5055,
492,
12863,
199,
646,
17572,
465,
5927,
199,
504,
1862,
492,
30370,
421,
199,
4283,
63,
840,
3448,
275,
959,
327,
4515,
5133,
2397,
365,
4829,
687,
5523,
199,
10748,
275,
12863,
480,
10748,
401,
298,
4452,
6132,
531,
199,
4129,
63,
1328,
275,
12863,
480,
4129,
63,
1328,
401,
298,
998,
1318,
531,
199,
277,
63,
1162,
275,
30370,
8,
5869,
29,
549,
9,
199,
199,
3,
2494,
314,
2838,
2633,
199,
1562,
275,
661,
5756,
14,
6568,
14,
17,
14,
2299,
297,
959,
12383,
21,
9,
221,
327,
1591,
12,
1844,
199,
5096,
63,
29047,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
2838,
14,
20130,
63,
17457,
9,
199,
5096,
63,
29047,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
199,
199,
3,
2790,
2838,
436,
5398,
370,
2287,
199,
5096,
63,
5859,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
199,
5096,
63,
5859,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
199,
5096,
63,
5859,
14,
3409,
8,
1562,
9,
199,
199,
318,
330,
5063,
837,
199,
198,
6710,
715,
26,
507,
198,
3,
1328,
275,
3486,
63,
1328,
8,
277,
63,
344,
4589,
41,
8140,
2348,
531,
507,
198,
1328,
275,
291,
63,
1162,
507,
198,
479,
6771,
63,
29047,
14,
23267,
8,
8092,
14,
4180,
8,
1328,
395,
2287,
395,
298,
2209,
3405,
370,
3222,
2,
507,
198,
521,
14,
4532,
8,
17,
9,
199,
199,
318,
6938,
837,
199,
198,
1361,
298,
19189,
367,
1245,
2,
199,
198,
6710,
715,
26,
507,
198,
893,
26,
686,
198,
2179,
275,
3504,
14,
2416,
779,
5096,
63,
5859,
467,
990,
990,
413,
14,
16,
9,
686,
198,
692,
10144,
59,
16,
2189,
1585,
198,
68,
275,
6771,
63,
5859,
14,
7637,
504,
8,
20579,
9,
1585,
198,
1773,
63,
1328,
275,
366,
59,
16,
61,
16737,
198,
893,
26,
1871,
198,
1328,
275,
5927,
14,
3640,
8,
1773,
63,
1328,
9,
1871,
198,
692,
1499,
14,
998,
508,
291,
63,
1162,
14,
998,
26,
4671,
198,
1529,
1871,
198,
2836,
26,
4671,
198,
1361,
298,
2532,
5552,
26,
1543,
83,
297,
1499,
26,
1543,
83,
4065,
450,
334,
68,
59,
17,
467,
1499,
9,
16737,
198,
2590,
2186,
12,
325,
26,
1871,
198,
1361,
298,
547,
315,
18390,
26,
3872,
325,
2742,
198,
2590,
2838,
14,
2593,
26,
686,
198,
1361,
298,
497,
4583,
2653,
14,
5980,
1044,
11500,
686,
198,
84,
63,
5859,
14,
6406,
342,
686,
198,
5096,
63,
5859,
14,
1600,
342,
199,
199,
84,
63,
5859,
275,
5796,
14,
4436,
8,
1375,
29,
5859,
9,
199,
84,
63,
29047,
275,
5796,
14,
4436,
8,
1375,
29,
29047,
9,
199,
199,
84,
63,
5859,
14,
10824,
275,
715,
199,
84,
63,
29047,
14,
10824,
275,
715,
199,
199,
84,
63,
5859,
14,
928,
342,
199,
84,
63,
29047,
14,
928,
342,
199,
199,
521,
14,
4532,
8,
1960,
9,
327,
396,
367,
2948,
83,
199,
1361,
298,
18433,
506,
16928,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
33,
3486,
2240,
626,
16178,
15,
317,
1597,
561,
11180,
14593,
4012,
21802,
2838,
199,
9167,
370,
511,
314,
2656,
340,
652,
365,
7688,
370,
3222,
15,
9391,
14593,
199,
624,
199,
646,
900,
12,
3473,
12,
984,
12,
2838,
12,
5796,
12,
3504,
12,
5377,
199,
504,
5055,
492,
12863,
199,
646,
17572,
465,
5927,
199,
504,
1862,
492,
30370,
421,
199,
4283,
63,
840,
3448,
275,
959,
327,
4515,
5133,
2397,
365,
4829,
687,
5523,
199,
10748,
275,
12863,
480,
10748,
401,
298,
4452,
6132,
531,
199,
4129,
63,
1328,
275,
12863,
480,
4129,
63,
1328,
401,
298,
998,
1318,
531,
199,
277,
63,
1162,
275,
30370,
8,
5869,
29,
549,
9,
199,
199,
3,
2494,
314,
2838,
2633,
199,
1562,
275,
661,
5756,
14,
6568,
14,
17,
14,
2299,
297,
959,
12383,
21,
9,
221,
327,
1591,
12,
1844,
199,
5096,
63,
29047,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
2838,
14,
20130,
63,
17457,
9,
199,
5096,
63,
29047,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
199,
199,
3,
2790,
2838,
436,
5398,
370,
2287,
199,
5096,
63,
5859,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
199,
5096,
63,
5859,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
199,
5096,
63,
5859,
14,
3409,
8,
1562,
9,
199,
199,
318,
330,
5063,
837,
199,
198,
6710,
715,
26,
507,
198,
3,
1328,
275,
3486,
63,
1328,
8,
277,
63,
344,
4589,
41,
8140,
2348,
531,
507,
198,
1328,
275,
291,
63,
1162,
507,
198,
479,
6771,
63,
29047,
14,
23267,
8,
8092,
14,
4180,
8,
1328,
395,
2287,
395,
298,
2209,
3405,
370,
3222,
2,
507,
198,
521,
14,
4532,
8,
17,
9,
199,
199,
318,
6938,
837,
199,
198,
1361,
298,
19189,
367,
1245,
2,
199,
198,
6710,
715,
26,
507,
198,
893,
26,
686,
198,
2179,
275,
3504,
14,
2416,
779,
5096,
63,
5859,
467,
990,
990,
413,
14,
16,
9,
686,
198,
692,
10144,
59,
16,
2189,
1585,
198,
68,
275,
6771,
63,
5859,
14,
7637,
504,
8,
20579,
9,
1585,
198,
1773,
63,
1328,
275,
366,
59,
16,
61,
16737,
198,
893,
26,
1871,
198,
1328,
275,
5927,
14,
3640,
8,
1773,
63,
1328,
9,
1871,
198,
692,
1499,
14,
998,
508,
291,
63,
1162,
14,
998,
26,
4671,
198,
1529,
1871,
198,
2836,
26,
4671,
198,
1361,
298,
2532,
5552,
26,
1543,
83,
297,
1499,
26,
1543,
83,
4065,
450,
334,
68,
59,
17,
467,
1499,
9,
16737,
198,
2590,
2186,
12,
325,
26,
1871,
198,
1361,
298,
547,
315,
18390,
26,
3872,
325,
2742,
198,
2590,
2838,
14,
2593,
26,
686,
198,
1361,
298,
497,
4583,
2653,
14,
5980,
1044,
11500,
686,
198,
84,
63,
5859,
14,
6406,
342,
686,
198,
5096,
63,
5859,
14,
1600,
342,
199,
199,
84,
63,
5859,
275,
5796,
14,
4436,
8,
1375,
29,
5859,
9,
199,
84,
63,
29047,
275,
5796,
14,
4436,
8,
1375,
29,
29047,
9,
199,
199,
84,
63,
5859,
14,
10824,
275,
715,
199,
84,
63,
29047,
14,
10824,
275,
715,
199,
199,
84,
63,
5859,
14,
928,
342,
199,
84,
63,
29047,
14,
928,
342,
199,
199,
521,
14,
4532,
8,
1960,
9,
327,
396,
367,
2948,
83,
199,
1361,
298,
18433,
506,
16928,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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